Permalink
Browse files

Adding iOS unit test for XMPPAutoPing

  • Loading branch information...
1 parent 2037d10 commit ae1d5dd60b0e62aa9f36f515a6b40c8aaabb9b82 @robbiehanson committed Sep 1, 2011
Showing with 1,731 additions and 216 deletions.
  1. +1 −4 Extensions/XEP-0054/CoreDataStorage/XMPPvCard.xcdatamodeld/.xccurrentversion
  2. +213 −202 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest.xcodeproj/project.pbxproj
  3. 0 ...ing/AutoPingTest/{ → Desktop}/AutoPingTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  4. 0 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/AutoPingTest-Info.plist
  5. 0 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/AutoPingTest-Prefix.pch
  6. 0 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/AutoPingTestAppDelegate.h
  7. +10 −8 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/AutoPingTestAppDelegate.m
  8. 0 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/en.lproj/Credits.rtf
  9. 0 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/en.lproj/InfoPlist.strings
  10. 0 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/en.lproj/MainMenu.xib
  11. 0 Xcode/Testing/AutoPingTest/{ → Desktop}/AutoPingTest/main.m
  12. +634 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest.xcodeproj/project.pbxproj
  13. +7 −0 ...e/Testing/AutoPingTest/Mobile/AutoPingTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  14. +38 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/AutoPingTest-Info.plist
  15. +14 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/AutoPingTest-Prefix.pch
  16. +15 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/AutoPingTestAppDelegate.h
  17. +121 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/AutoPingTestAppDelegate.m
  18. +13 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/AutoPingTestViewController.h
  19. +44 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/AutoPingTestViewController.m
  20. +156 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/en.lproj/AutoPingTestViewController.xib
  21. +2 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/en.lproj/InfoPlist.strings
  22. +444 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/en.lproj/MainWindow.xib
  23. +17 −0 Xcode/Testing/AutoPingTest/Mobile/AutoPingTest/main.m
  24. 0 Xcode/Testing/AutoPingTest/{AutoPingTest → }/XMPPFramework.h
  25. +2 −2 Xcode/Testing/AutoTimeTest/XMPPFramework.h
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
-<dict>
- <key>_XCCurrentVersionName</key>
- <string>XMPPvCard.xcdatamodel</string>
-</dict>
+<dict/>
</plist>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -13,8 +13,9 @@
// Log levels: off, error, warn, info, verbose
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
-#define MY_JID @"robbie@robbiehanson.com/rsrc"
-#define MY_PASSWORD @""
+#define MY_JID @"" // <--- ENTER A JID HERE (e.g. user@gmail.com)
+#define MY_PASSWORD @"" // <--- ENTER PASSWORD HERE
+
@implementation AutoPingTestAppDelegate
@@ -27,10 +28,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
xmppStream = [[XMPPStream alloc] init];
- [xmppStream setMyJID:[XMPPJID jidWithString:MY_JID]];
+
+// xmppStream.hostName = @"";
+ xmppStream.myJID = [XMPPJID jidWithString:MY_JID];
xmppAutoPing = [[XMPPAutoPing alloc] init];
- xmppAutoPing.pingInterval = 15;
+ xmppAutoPing.pingInterval = 30;
xmppAutoPing.pingTimeout = 5;
xmppAutoPing.targetJID = nil;
@@ -65,7 +68,7 @@ - (void)changeAutoPingInterval:(NSTimer *)aTimer
{
DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
- xmppAutoPing.pingInterval = 30;
+ xmppAutoPing.pingInterval = 60;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -86,9 +89,8 @@ - (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
{
DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
- [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(goOnline:) userInfo:nil repeats:NO];
- [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(goOffline:) userInfo:nil repeats:NO];
- [NSTimer scheduledTimerWithTimeInterval:35 target:self selector:@selector(changeAutoPingInterval:) userInfo:nil repeats:NO];
+ [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(goOnline:) userInfo:nil repeats:NO];
+ [NSTimer scheduledTimerWithTimeInterval:90 target:self selector:@selector(changeAutoPingInterval:) userInfo:nil repeats:NO];
}
- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.deusty.oss.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>NSMainNibFile</key>
+ <string>MainWindow</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
@@ -0,0 +1,14 @@
+//
+// Prefix header for all source files of the 'AutoPingTest' target in the 'AutoPingTest' project
+//
+
+#import <Availability.h>
+
+#ifndef __IPHONE_3_0
+#warning "This project uses features only available in iPhone SDK 3.0 and later."
+#endif
+
+#ifdef __OBJC__
+ #import <UIKit/UIKit.h>
+ #import <Foundation/Foundation.h>
+#endif
@@ -0,0 +1,15 @@
+#import <UIKit/UIKit.h>
+#import "XMPPFramework.h"
+
+@class AutoPingTestViewController;
+
+@interface AutoPingTestAppDelegate : NSObject <UIApplicationDelegate>
+{
+ XMPPStream *xmppStream;
+ XMPPAutoPing *xmppAutoPing;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) IBOutlet AutoPingTestViewController *viewController;
+
+@end
@@ -0,0 +1,121 @@
+#import "AutoPingTestAppDelegate.h"
+#import "AutoPingTestViewController.h"
+#import "DDLog.h"
+#import "DDTTYLogger.h"
+
+// Log levels: off, error, warn, info, verbose
+static const int ddLogLevel = LOG_LEVEL_VERBOSE;
+
+#define MY_JID @"" // <--- ENTER A JID HERE (e.g. user@gmail.com)
+#define MY_PASSWORD @"" // <--- ENTER PASSWORD HERE
+
+
+@implementation AutoPingTestAppDelegate
+
+@synthesize window = _window;
+@synthesize viewController = _viewController;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ [DDLog addLogger:[DDTTYLogger sharedInstance]];
+
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+
+ xmppStream = [[XMPPStream alloc] init];
+
+// xmppStream.hostName = @"";
+ xmppStream.myJID = [XMPPJID jidWithString:MY_JID];
+
+ xmppAutoPing = [[XMPPAutoPing alloc] init];
+ xmppAutoPing.pingInterval = 30;
+ xmppAutoPing.pingTimeout = 5;
+ xmppAutoPing.targetJID = nil;
+
+ [xmppAutoPing activate:xmppStream];
+
+ [xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
+ [xmppAutoPing addDelegate:self delegateQueue:dispatch_get_main_queue()];
+
+ NSError *error = nil;
+
+ if (![xmppStream connect:&error])
+ {
+ DDLogError(@"%@: Error connecting: %@", [self class], error);
+ }
+
+ self.window.rootViewController = self.viewController;
+ [self.window makeKeyAndVisible];
+ return YES;
+}
+
+- (void)goOnline:(NSTimer *)aTimer
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+
+ [xmppStream sendElement:[XMPPPresence presence]];
+}
+
+- (void)goOffline:(NSTimer *)aTimer
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+
+ [xmppStream sendElement:[XMPPPresence presenceWithType:@"unavailable"]];
+}
+
+- (void)changeAutoPingInterval:(NSTimer *)aTimer
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+
+ xmppAutoPing.pingInterval = 60;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)xmppStreamDidConnect:(XMPPStream *)sender
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+
+ NSError *error = nil;
+
+ if (![xmppStream authenticateWithPassword:MY_PASSWORD error:&error])
+ {
+ DDLogError(@"%@: Error authenticating: %@", [self class], error);
+ }
+}
+
+- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+
+ [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(goOnline:) userInfo:nil repeats:NO];
+ [NSTimer scheduledTimerWithTimeInterval:90 target:self selector:@selector(changeAutoPingInterval:) userInfo:nil repeats:NO];
+}
+
+- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+}
+
+- (void)xmppStreamDidDisconnect:(XMPPStream *)sender withError:(NSError *)error
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)xmppAutoPingDidSendPing:(XMPPAutoPing *)sender
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+}
+
+- (void)xmppAutoPingDidReceivePong:(XMPPAutoPing *)sender
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+}
+
+- (void)xmppAutoPingDidTimeout:(XMPPAutoPing *)sender
+{
+ DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);
+}
+
+@end
@@ -0,0 +1,13 @@
+//
+// AutoPingTestViewController.h
+// AutoPingTest
+//
+// Created by Robbie Hanson on 9/1/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface AutoPingTestViewController : UIViewController
+
+@end
@@ -0,0 +1,44 @@
+//
+// AutoPingTestViewController.m
+// AutoPingTest
+//
+// Created by Robbie Hanson on 9/1/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "AutoPingTestViewController.h"
+
+@implementation AutoPingTestViewController
+
+- (void)didReceiveMemoryWarning
+{
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Release any cached data, images, etc that aren't in use.
+}
+
+#pragma mark - View lifecycle
+
+/*
+// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+}
+*/
+
+- (void)viewDidUnload
+{
+ [super viewDidUnload];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ // Return YES for supported orientations
+ return (interfaceOrientation == UIInterfaceOrientationPortrait);
+}
+
+@end
Oops, something went wrong.

0 comments on commit ae1d5dd

Please sign in to comment.