Skip to content

Commit

Permalink
Adding iOS unit test for XMPPAutoTime
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Sep 1, 2011
1 parent 0a3b7f4 commit 2037d10
Show file tree
Hide file tree
Showing 16 changed files with 1,509 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
DC4173B913F1D3E200ED8D43 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
DC4173BB13F1E23B00ED8D43 /* libresolv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libresolv.dylib; path = usr/lib/libresolv.dylib; sourceTree = SDKROOT; };
DC4173BD13F1E24500ED8D43 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
DCE1127E140D62E6007A2A46 /* XMPPFramework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPFramework.h; path = AutoTimeTest/XMPPFramework.h; sourceTree = "<group>"; };
DC9CE2F4141017C100E92491 /* XMPPFramework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPFramework.h; path = ../../XMPPFramework.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -208,7 +208,7 @@
DC41734313F1D35100ED8D43 /* XMPP */ = {
isa = PBXGroup;
children = (
DCE1127E140D62E6007A2A46 /* XMPPFramework.h */,
DC9CE2F4141017C100E92491 /* XMPPFramework.h */,
DC41734413F1D37300ED8D43 /* Categories */,
DC41734B13F1D37300ED8D43 /* Core */,
DC4173AA13F1D39700ED8D43 /* Extensions */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import <Cocoa/Cocoa.h>
#import "XMPP.h"
#import "XMPPAutoTime.h"
#import "XMPPFramework.h"


@interface AutoTimeTestAppDelegate : NSObject <NSApplicationDelegate> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Log levels: off, error, warn, info, verbose
static const int ddLogLevel = LOG_LEVEL_VERBOSE;

#define MY_JID @"user@gmail.com/xmppFramework"
#define MY_PASSWORD @""
#define MY_JID @"" // <--- ENTER A JID HERE (e.g. user@gmail.com)
#define MY_PASSWORD @"" // <--- ENTER PASSWORD HERE


@implementation AutoTimeTestAppDelegate
Expand All @@ -20,6 +20,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);

xmppStream = [[XMPPStream alloc] init];

// xmppStream.hostName = @"";
xmppStream.myJID = [XMPPJID jidWithString:MY_JID];

xmppAutoTime = [[XMPPAutoTime alloc] init];
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Prefix header for all source files of the 'AutoTimeTest' target in the 'AutoTimeTest' 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import <UIKit/UIKit.h>
#import "XMPPFramework.h"

@class AutoTimeTestViewController;


@interface AutoTimeTestAppDelegate : NSObject <UIApplicationDelegate>
{
XMPPStream *xmppStream;
XMPPAutoTime *xmppAutoTime;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet AutoTimeTestViewController *viewController;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#import "AutoTimeTestAppDelegate.h"
#import "AutoTimeTestViewController.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 AutoTimeTestAppDelegate

@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];

xmppAutoTime = [[XMPPAutoTime alloc] init];
xmppAutoTime.recalibrationInterval = 60;
xmppAutoTime.targetJID = nil;

[xmppAutoTime activate:xmppStream];

[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppAutoTime 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)changeAutoTimeInterval:(NSTimer *)aTimer
{
DDLogVerbose(@"%@: %@", [self class], THIS_METHOD);

xmppAutoTime.recalibrationInterval = 30;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (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:130
target:self
selector:@selector(changeAutoTimeInterval:)
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, error);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (void)xmppAutoTime:(XMPPAutoTime *)sender didUpdateTimeDifference:(NSTimeInterval)timeDifference
{
DDLogVerbose(@"%@: %@ %f <<<<<<<============", [self class], THIS_METHOD, timeDifference);
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AutoTimeTestViewController.h
// AutoTimeTest
//
// Created by Robbie Hanson on 9/1/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AutoTimeTestViewController : UIViewController

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// AutoTimeTestViewController.m
// AutoTimeTest
//
// Created by Robbie Hanson on 9/1/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "AutoTimeTestViewController.h"

@implementation AutoTimeTestViewController

- (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
Loading

0 comments on commit 2037d10

Please sign in to comment.