From b587fb759266a7dbddb028cfe8fc215b5574c4d4 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Sat, 24 Jan 2015 23:52:15 +0100 Subject: [PATCH] Migrate category into inherited LinphoneTestCase --- KifTests/ChatTester.m | 1 - KifTests/KIFTestCase+LinphoneExtras.h | 18 ------- KifTests/KIFTestCase+LinphoneExtras.m | 54 ------------------- KifTests/LinphoneTestCase.h | 6 +++ KifTests/LinphoneTestCase.m | 78 +++++++++++++++++++++++++++ KifTests/WizardTester.m | 1 - linphone.xcodeproj/project.pbxproj | 6 --- 7 files changed, 84 insertions(+), 80 deletions(-) delete mode 100644 KifTests/KIFTestCase+LinphoneExtras.h delete mode 100644 KifTests/KIFTestCase+LinphoneExtras.m diff --git a/KifTests/ChatTester.m b/KifTests/ChatTester.m index bf83d7b78..7640c2171 100644 --- a/KifTests/ChatTester.m +++ b/KifTests/ChatTester.m @@ -7,7 +7,6 @@ // #import "ChatTester.h" -#import "KIFTestCase+LinphoneExtras.h" @implementation ChatTester diff --git a/KifTests/KIFTestCase+LinphoneExtras.h b/KifTests/KIFTestCase+LinphoneExtras.h deleted file mode 100644 index ec45e82f3..000000000 --- a/KifTests/KIFTestCase+LinphoneExtras.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// KIFTestCase+LinphoneExtras.h -// linphone -// -// Created by Guillaume on 17/01/2015. -// -// - -#import - -@interface KIFTestCase (LinphoneExtras) - -@property BOOL invalidAccountSet; - -- (void)switchToValidAccountIfNeeded; -- (NSString*)accountUsername; - -@end diff --git a/KifTests/KIFTestCase+LinphoneExtras.m b/KifTests/KIFTestCase+LinphoneExtras.m deleted file mode 100644 index c428ce4cc..000000000 --- a/KifTests/KIFTestCase+LinphoneExtras.m +++ /dev/null @@ -1,54 +0,0 @@ -// -// KIFTestCase+LinphoneExtras.m -// linphone -// -// Created by Guillaume on 17/01/2015. -// -// - -#import "KIFTestCase+LinphoneExtras.h" - -@implementation KIFTestCase (LinphoneExtras) - -static bool invalidAccount = true; - -- (void)setInvalidAccountSet:(BOOL)invalidAccountSet { - invalidAccount = invalidAccountSet; -} - -- (BOOL)invalidAccountSet { - return invalidAccount; -} - -- (NSString *)accountUsername { - return @"testios"; -} - -- (void)switchToValidAccountIfNeeded { - [UIView setAnimationsEnabled:false]; - - if( invalidAccount ){ - - [tester tapViewWithAccessibilityLabel:@"Settings"]; - [tester tapViewWithAccessibilityLabel:@"Run assistant"]; - [tester waitForTimeInterval:0.5]; - if( [tester tryFindingViewWithAccessibilityLabel:@"Launch Wizard" error:nil]){ - [tester tapViewWithAccessibilityLabel:@"Launch Wizard"]; - [tester waitForTimeInterval:0.5]; - } - - NSLog(@"Switching to a valid account"); - - [tester tapViewWithAccessibilityLabel:@"Start"]; - [tester tapViewWithAccessibilityLabel:@"Sign in linphone.org account"]; - - [tester enterText:@"testios" intoViewWithAccessibilityLabel:@"Username"]; - [tester enterText:@"testtest" intoViewWithAccessibilityLabel:@"Password"]; - - [tester tapViewWithAccessibilityLabel:@"Sign in"]; - - invalidAccount = false; - } -} - -@end diff --git a/KifTests/LinphoneTestCase.h b/KifTests/LinphoneTestCase.h index 62b200bb3..c1d3d290e 100644 --- a/KifTests/LinphoneTestCase.h +++ b/KifTests/LinphoneTestCase.h @@ -9,5 +9,11 @@ #import @interface LinphoneTestCase : KIFTestCase +@property BOOL invalidAccountSet; + +- (void)switchToValidAccountIfNeeded; +- (NSString*)accountUsername; +- (NSString*)accountDomain; + @end diff --git a/KifTests/LinphoneTestCase.m b/KifTests/LinphoneTestCase.m index 9e9836b5e..d11dbd712 100644 --- a/KifTests/LinphoneTestCase.m +++ b/KifTests/LinphoneTestCase.m @@ -8,11 +8,89 @@ #import "LinphoneTestCase.h" +#import "LinphoneManager.h" + @implementation LinphoneTestCase + + +- (NSString *)accountUsername { + return @"testios"; +} + +- (NSString *)accountDomain { + return @"sip.linphone.org"; +} - (void)beforeAll{ [tester acknowledgeSystemAlert]; [super beforeAll]; } + +static bool invalidAccount = true; + +- (void)setInvalidAccountSet:(BOOL)invalidAccountSet { + invalidAccount = invalidAccountSet; +} + +- (BOOL)invalidAccountSet { + return invalidAccount; +} + +- (BOOL)hasValidProxyConfig { + LinphoneCore* lc = [LinphoneManager getLc]; + const MSList* proxies = linphone_core_get_proxy_config_list(lc); + BOOL isOK = false; + while(proxies){ + LinphoneProxyConfig* cfg = (LinphoneProxyConfig*)proxies->data; + const char* domain = linphone_proxy_config_get_domain(cfg); + const char* identity = linphone_proxy_config_get_identity(cfg); + LinphoneAddress* addr = linphone_core_interpret_url(lc, identity); + const char* username = linphone_address_get_username(addr); + + if( addr + && ( username && strcmp(username, [[self accountUsername] UTF8String]) == 0) + && ( domain && strcmp(domain, [[self accountDomain] UTF8String]) == 0 ) + && linphone_proxy_config_get_state(cfg) == LinphoneRegistrationOk ) + { + isOK = true; + linphone_address_destroy(addr); + break; + } else if( addr ) { + linphone_address_destroy(addr); + } + + proxies=proxies->next; + } + return isOK; +} + +- (void)switchToValidAccountIfNeeded { + [UIView setAnimationsEnabled:false]; + + if( invalidAccount && ! [self hasValidProxyConfig] ){ + + [tester tapViewWithAccessibilityLabel:@"Settings"]; + [tester tapViewWithAccessibilityLabel:@"Run assistant"]; + [tester waitForTimeInterval:0.5]; + if( [tester tryFindingViewWithAccessibilityLabel:@"Launch Wizard" error:nil]){ + [tester tapViewWithAccessibilityLabel:@"Launch Wizard"]; + [tester waitForTimeInterval:0.5]; + } + + NSLog(@"Switching to a valid account"); + + [tester tapViewWithAccessibilityLabel:@"Start"]; + [tester tapViewWithAccessibilityLabel:@"Sign in linphone.org account"]; + + [tester enterText:@"testios" intoViewWithAccessibilityLabel:@"Username"]; + [tester enterText:@"testtest" intoViewWithAccessibilityLabel:@"Password"]; + + [tester tapViewWithAccessibilityLabel:@"Sign in"]; + + invalidAccount = false; + } +} + + @end diff --git a/KifTests/WizardTester.m b/KifTests/WizardTester.m index 00f8b3381..4ac3c337c 100644 --- a/KifTests/WizardTester.m +++ b/KifTests/WizardTester.m @@ -9,7 +9,6 @@ #import "WizardTester.h" #import -#import "KIFTestCase+LinphoneExtras.h" @implementation WizardTester diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index f9c050e73..0a7ffbe6b 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -698,7 +698,6 @@ F08F11A019C0A6CB007D70C2 /* DTObjectBlockExecutor.m in Sources */ = {isa = PBXBuildFile; fileRef = F08F119F19C0A6CB007D70C2 /* DTObjectBlockExecutor.m */; }; F0938159188E629800A55DFA /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = F0938158188E629800A55DFA /* iTunesArtwork */; }; F0A1CE081A6B056E001CA2BE /* ChatTester.m in Sources */ = {isa = PBXBuildFile; fileRef = F0A1CE071A6B056E001CA2BE /* ChatTester.m */; }; - F0A1CE0C1A6B08FA001CA2BE /* KIFTestCase+LinphoneExtras.m in Sources */ = {isa = PBXBuildFile; fileRef = F0A1CE0B1A6B08FA001CA2BE /* KIFTestCase+LinphoneExtras.m */; }; F0B4FB5D1A65550B00637027 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F0B4FB5C1A65550B00637027 /* Images.xcassets */; }; F0B89C2218DC89E30050B60E /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F0B89C2118DC89E30050B60E /* MediaPlayer.framework */; }; F0B89C2818DC973E0050B60E /* wizard_external_sip.rc in Resources */ = {isa = PBXBuildFile; fileRef = F0B89C2418DC973E0050B60E /* wizard_external_sip.rc */; }; @@ -1703,8 +1702,6 @@ F0A1CE061A6B056E001CA2BE /* ChatTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChatTester.h; sourceTree = ""; }; F0A1CE071A6B056E001CA2BE /* ChatTester.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChatTester.m; sourceTree = ""; }; F0A1CE091A6B05A4001CA2BE /* WizardTester.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WizardTester.h; sourceTree = ""; }; - F0A1CE0A1A6B08FA001CA2BE /* KIFTestCase+LinphoneExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KIFTestCase+LinphoneExtras.h"; sourceTree = ""; }; - F0A1CE0B1A6B08FA001CA2BE /* KIFTestCase+LinphoneExtras.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KIFTestCase+LinphoneExtras.m"; sourceTree = ""; }; F0AF06F01A24BA760086C9C1 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/AboutViewController.strings; sourceTree = ""; }; F0AF06F11A24BA760086C9C1 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/ChatRoomViewController.strings; sourceTree = ""; }; F0AF06F21A24BA760086C9C1 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/ChatViewController.strings; sourceTree = ""; }; @@ -3023,8 +3020,6 @@ F0A1CE091A6B05A4001CA2BE /* WizardTester.h */, F0A1CE061A6B056E001CA2BE /* ChatTester.h */, F0A1CE071A6B056E001CA2BE /* ChatTester.m */, - F0A1CE0A1A6B08FA001CA2BE /* KIFTestCase+LinphoneExtras.h */, - F0A1CE0B1A6B08FA001CA2BE /* KIFTestCase+LinphoneExtras.m */, F85554461A6DA2F400A9F915 /* LinphoneTestCase.h */, F85554471A6DA2F400A9F915 /* LinphoneTestCase.m */, ); @@ -3999,7 +3994,6 @@ buildActionMask = 2147483647; files = ( F0A1CE081A6B056E001CA2BE /* ChatTester.m in Sources */, - F0A1CE0C1A6B08FA001CA2BE /* KIFTestCase+LinphoneExtras.m in Sources */, F85554481A6DA2F400A9F915 /* LinphoneTestCase.m in Sources */, F0F952121A6AECD300254160 /* WizardTester.m in Sources */, );