Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for uploading results to a database

Not exposed in the UI yet, though.
  • Loading branch information...
commit 97a0795d90480fd5191beb13cfe9e949e774f41d 1 parent b1da440
@snej snej authored
View
2  App/AppDelegate.m
@@ -35,6 +35,8 @@ - (BOOL)application:(UIApplication *)application
NSLog(@"------ application:didFinishLaunchingWithOptions:");
[_window addSubview:_navController.view];
[_window makeKeyAndVisible];
+
+ [UIDevice currentDevice].batteryMonitoringEnabled = YES;
// Create & configure a CouchbaseMobile instance:
CouchbaseMobile* cb = [[CouchbaseMobile alloc] init];
View
4 App/BeeCouchTest.h
@@ -13,6 +13,8 @@
/** Subclass of BeeTest for exercising CouchCocoa. */
@interface BeeCouchTest : BeeTest
+#pragma mark For subclasses to call:
+
/** The embedded Couchbase server. */
@property (readonly) CouchServer* server;
@@ -34,6 +36,8 @@
If this is YES you should not access the server. (Observable.) */
@property (readonly) BOOL suspended;
+#pragma mark For subclasses to override:
+
/** Called when the application enters the background.
You can override this to do extra work, but call the inherited method *at the end*. */
- (void)serverWillSuspend;
View
4 App/BeeCouchTest.m
@@ -49,7 +49,7 @@ - (NSURL*) serverURL {
- (NSString*) databaseName {
- return [[NSStringFromClass([self class]) lowercaseString] stringByAppendingString: @"-db"];
+ return [[[[self class] testName] lowercaseString] stringByAppendingString: @"-db"];
}
@@ -108,7 +108,7 @@ - (void) tearDown {
[_server release];
_server = nil;
self.suspended = NO;
-
+
[super tearDown];
}
View
9 App/BeeTest.h
@@ -17,7 +17,11 @@
/** Returns an array of Class objects for each available BeeTest subclass. */
+ (NSArray*) allTestClasses;
-/** The name to display for a test class. Defaults to the class's name. */
+/** Name of this test. Equal to the class name. Needs to be unique. */
++ (NSString*) testName;
+
+/** The name to display for a test class.
+ Defaults to the class's name with any "Test" suffix removed. */
+ (NSString*) displayName;
#pragma mark Instance properties
@@ -29,6 +33,9 @@
Set to YES to start it, NO to stop it. Observable. */
@property BOOL running;
+/** Set to YES if the test was stopped by the user (instead of finishing on its own.) */
+@property BOOL stoppedByUser;
+
/** Current user-visible status message set by the test.
Subclasses can set this. Observable. */
@property (copy) NSString* status;
View
15 App/BeeTest.m
@@ -7,6 +7,7 @@
//
#import "BeeTest.h"
+#import "SavedTestRun.h"
#import <objc/runtime.h>
@@ -56,15 +57,19 @@ + (NSArray*) allTestClasses {
}
free(classes);
[testClasses sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
- return [NSStringFromClass(obj1) caseInsensitiveCompare: NSStringFromClass(obj2)];
+ return [[obj1 displayName] caseInsensitiveCompare: [obj2 displayName]];
}];
sAllTestClasses = [testClasses copy];
}
return sAllTestClasses;
}
++ (NSString*) testName {
+ return NSStringFromClass(self);
+}
+
+ (NSString*) displayName {
- NSString* name = NSStringFromClass(self);
+ NSString* name = [self testName];
if ([name hasSuffix: @"Test"])
name = [name substringToIndex: name.length - 4];
return name;
@@ -72,7 +77,8 @@ + (NSString*) displayName {
@synthesize delegate=_delegate, status = _status, startTime = _startTime, endTime = _endTime,
- error = _error, messages = _messages, lastTimestamp = _lastTimestamp;
+ stoppedByUser = _stoppedByUser, error = _error, messages = _messages,
+ lastTimestamp = _lastTimestamp;
- (id)init {
@@ -184,6 +190,9 @@ - (void) tearDown {
[nctr removeObserver: self
name:UIApplicationWillEnterForegroundNotification
object: nil];
+
+ // Save test results to local database:
+ [[SavedTestRun forTest: self] save];
}
View
3  App/BeeTestController.m
@@ -8,6 +8,7 @@
#import "BeeTestController.h"
#import "BeeTest.h"
+#import "SavedTestRun.h"
@interface BeeTestController () <BeeTestDelegate>
@@ -108,6 +109,8 @@ - (void) beeTest: (BeeTest*)test isRunning: (BOOL)running {
}
- (IBAction) startStopTest:(id)sender {
+ if (![sender isOn])
+ _test.stoppedByUser = YES;
_test.running = [sender isOn];
}
View
26 App/SavedTestRun.h
@@ -0,0 +1,26 @@
+//
+// SavedTestRun.h
+// Worker Bee
+//
+// Created by Jens Alfke on 10/10/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import <CouchCocoa/CouchCocoa.h>
+@class BeeTest;
+
+
+@interface SavedTestRun : CouchModel
+
++ (SavedTestRun*) forTest: (BeeTest*)test;
++ (BOOL) uploadAllTo: (NSURL*)upstreamURL error: (NSError**)outError;
+
+@property (copy) NSDictionary* device;
+@property (copy) NSString* testName;
+@property (retain) NSDate* startTime, *endTime;
+@property BOOL stoppedByUser;
+@property (copy) NSString* status;
+@property (copy) NSString* error;
+@property (copy) NSString* log;
+
+@end
View
79 App/SavedTestRun.m
@@ -0,0 +1,79 @@
+//
+// SavedTestRun.m
+// Worker Bee
+//
+// Created by Jens Alfke on 10/10/11.
+// Copyright (c) 2011 Couchbase, Inc. All rights reserved.
+//
+
+#import "SavedTestRun.h"
+#import "AppDelegate.h"
+#import "BeeTest.h"
+
+
+@implementation SavedTestRun
+
+CouchDatabase* sDatabase;
+
++ (CouchDatabase*) database {
+ if (!sDatabase) {
+ NSURL* serverURL = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).serverURL;
+ NSAssert(serverURL, @"No server URL");
+ CouchServer* server = [[CouchServer alloc] initWithURL: serverURL];
+ sDatabase = [[server databaseNamed: @"workerbee-tests"] retain];
+ [server release];
+
+ RESTOperation* op = [sDatabase create];
+ if (![op wait]) {
+ if(op.httpStatus != 412)
+ NSAssert(NO, @"Error creating db: %@", op.error); // TODO: Real alert
+ }
+ }
+ return sDatabase;
+}
+
+@dynamic device, testName, startTime, endTime, stoppedByUser, status, error, log;
+
+- (void) recordTest: (BeeTest*)test {
+ UIDevice* deviceInfo = [UIDevice currentDevice];
+ self.device = [NSDictionary dictionaryWithObjectsAndKeys:
+ deviceInfo.name, @"name",
+ deviceInfo.model, @"model",
+ deviceInfo.systemVersion, @"system",
+ deviceInfo.uniqueIdentifier, @"UDID",
+ [NSNumber numberWithInt: deviceInfo.batteryState], @"batteryState",
+ [NSNumber numberWithFloat: deviceInfo.batteryLevel], @"batteryLevel",
+ nil];
+ self.testName = [[test class] testName];
+ self.startTime = test.startTime;
+ self.endTime = test.endTime;
+ if (test.stoppedByUser)
+ self.stoppedByUser = YES;
+ self.status = test.status;
+ self.error = test.errorMessage;
+ self.log = [test.messages componentsJoinedByString: @"\n"];
+}
+
++ (SavedTestRun*) forTest: (BeeTest*)test {
+ SavedTestRun* instance = [[self alloc] initWithNewDocumentInDatabase: [self database]];
+ [instance recordTest: test];
+ return [instance autorelease];
+}
+
++ (BOOL) uploadAllTo: (NSURL*)upstreamURL error: (NSError**)outError {
+ CouchReplication* repl = [[self database] pushToDatabaseAtURL: upstreamURL options: 0];
+ RESTOperation* op = [repl start];
+ if (![op wait]) {
+ if (outError) *outError = op.error;
+ return NO;
+ }
+ // After a successful push, delete the database because we don't need to keep the test
+ // results around anymore. (Just deleting the documents would leave tombstones behind,
+ // which would propagate to the server on the next push and delete them there too. Bad.)
+ [[sDatabase DELETE] wait];
+ [sDatabase release];
+ sDatabase = nil;
+ return YES;
+}
+
+@end
View
11 App/TestListController.m
@@ -149,7 +149,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
#pragma mark - Table view delegate
- (BeeTest*) testForClass: (Class)testClass {
- return [_activeTestByClass objectForKey: NSStringFromClass(testClass)];
+ return [_activeTestByClass objectForKey: [testClass testName]];
}
- (BeeTest*) makeTestForClass: (Class)testClass {
@@ -157,7 +157,7 @@ - (BeeTest*) makeTestForClass: (Class)testClass {
if (!test) {
test = [[[testClass alloc] init] autorelease];
if (test) {
- [_activeTestByClass setObject: test forKey: NSStringFromClass(testClass)];
+ [_activeTestByClass setObject: test forKey: [testClass testName]];
[test addObserver: self forKeyPath: @"running" options: 0 context: NULL];
}
}
@@ -194,8 +194,11 @@ - (void) observeValueForKeyPath:(NSString *)keyPath
- (IBAction) startStopTest:(id)sender {
Class testClass = [_testList objectAtIndex: [sender tag]];
BeeTest* test = [self makeTestForClass: testClass];
- NSLog(@"Setting %@ running=%i", test, [sender isOn]);
- test.running = [sender isOn];
+ BOOL running = [sender isOn];
+ NSLog(@"Setting %@ running=%i", test, running);
+ if (!running)
+ test.stoppedByUser = YES;
+ test.running = running;
}
@end
View
6 Worker Bee.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 270EA1ED1443C1AD0000AEA9 /* SavedTestRun.m in Sources */ = {isa = PBXBuildFile; fileRef = 270EA1EC1443C1AD0000AEA9 /* SavedTestRun.m */; };
27A07488143CCDCD0043BEB6 /* BeeCouchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A07487143CCDCD0043BEB6 /* BeeCouchTest.m */; };
27A0748C143CDE6B0043BEB6 /* CreateDocsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A0748B143CDE6B0043BEB6 /* CreateDocsTest.m */; };
27A37423143E5E85005A577D /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 27A37421143E5E85005A577D /* Icon.png */; };
@@ -35,6 +36,8 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 270EA1EB1443C1AD0000AEA9 /* SavedTestRun.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SavedTestRun.h; sourceTree = "<group>"; };
+ 270EA1EC1443C1AD0000AEA9 /* SavedTestRun.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SavedTestRun.m; sourceTree = "<group>"; };
27A07486143CCDCD0043BEB6 /* BeeCouchTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BeeCouchTest.h; sourceTree = "<group>"; };
27A07487143CCDCD0043BEB6 /* BeeCouchTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BeeCouchTest.m; sourceTree = "<group>"; };
27A0748A143CDE6B0043BEB6 /* CreateDocsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateDocsTest.h; sourceTree = "<group>"; };
@@ -156,6 +159,8 @@
27CB6569143B9B7E00EEA1F2 /* BeeTest.m */,
27A07486143CCDCD0043BEB6 /* BeeCouchTest.h */,
27A07487143CCDCD0043BEB6 /* BeeCouchTest.m */,
+ 270EA1EB1443C1AD0000AEA9 /* SavedTestRun.h */,
+ 270EA1EC1443C1AD0000AEA9 /* SavedTestRun.m */,
27B28FAC14314FB800B86F18 /* Supporting Files */,
);
path = App;
@@ -262,6 +267,7 @@
27CB6576143BAA2F00EEA1F2 /* BeeTestController.m in Sources */,
27A07488143CCDCD0043BEB6 /* BeeCouchTest.m in Sources */,
27A0748C143CDE6B0043BEB6 /* CreateDocsTest.m in Sources */,
+ 270EA1ED1443C1AD0000AEA9 /* SavedTestRun.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Please sign in to comment.
Something went wrong with that request. Please try again.