Permalink
Browse files

Add unit-test target/product to PhoneGapLib.

For issue #267.
  • Loading branch information...
buddydvd committed Sep 1, 2011
1 parent 5ebba48 commit 2f4018c5d220f497c2f98f19b603203e9c0357e6

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,22 @@
+<?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>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.phonegap.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+</dict>
+</plist>
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'PhoneGapLibTests' target in the 'PhoneGapLibTests' project
+//
+
+#ifdef __OBJC__
+ #import <UIKit/UIKit.h>
+#endif
@@ -0,0 +1,17 @@
+/*
+ * PhoneGap is available under *either* the terms of the modified BSD license *or* the
+ * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
+ *
+ * Created by David Hu on 9/1/11.
+ * Copyright (c) 2005-2011, Nitobi Software Inc.
+ */
+
+#import <SenTestingKit/SenTestingKit.h>
+
+
+@interface PluginResultJSONSerializationTests : SenTestCase {
+@private
+
+}
+
+@end
@@ -0,0 +1,67 @@
+/*
+ * PhoneGap is available under *either* the terms of the modified BSD license *or* the
+ * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
+ *
+ * Created by David Hu on 9/1/11.
+ * Copyright (c) 2005-2011, Nitobi Software Inc.
+ */
+
+#import <Foundation/Foundation.h>
+#import "PluginResultJSONSerializationTests.h"
+#import "PluginResult.h"
+#import "JSON.h"
+
+@implementation PluginResultJSONSerializationTests
+
+- (void)testSerializingMessageAsInt {
+ PluginResult *result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsInt:5];
+ NSDictionary *dic = [[result toJSONString] JSONFragmentValue];
+ NSNumber *message = [dic objectForKey:@"message"];
+ STAssertTrue([[NSNumber numberWithInt:5] isEqual:message], nil);
+}
+
+- (void)testSerializingMessageAsDouble {
+ PluginResult *result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsDouble:5.5];
+ NSDictionary *dic = [[result toJSONString] JSONFragmentValue];
+ NSNumber *message = [dic objectForKey:@"message"];
+ STAssertTrue([[NSNumber numberWithDouble:5.5] isEqual:message], nil);
+}
+
+- (void)testSerializingMessageAsArray {
+ NSArray *testValues = [NSArray arrayWithObjects:
+ [NSNull null],
+ @"string",
+ [NSNumber numberWithInt:5],
+ [NSNumber numberWithDouble:5.5],
+ [NSNumber numberWithBool:true],
+ nil];
+
+ PluginResult *result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsArray:testValues];
+ NSDictionary *dic = [[result toJSONString] JSONFragmentValue];
+ NSArray *message = [dic objectForKey:@"message"];
+
+ STAssertTrue([message isKindOfClass:[NSArray class]], nil);
+ STAssertTrue([testValues count] == [message count], nil);
+
+ for (NSInteger i = 0; i < [testValues count]; i++) {
+ STAssertTrue([[testValues objectAtIndex:i] isEqual:[message objectAtIndex:i]], nil);
+ }
+}
+
+- (void)testSerializingMessageAsStringContainingQuotes {
+ NSString *quotedString = @"\"quoted\"";
+ PluginResult *result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString:quotedString];
+ NSDictionary *dic = [[result toJSONString] JSONFragmentValue];
+ NSString *message = [dic objectForKey:@"message"];
+ STAssertTrue([quotedString isEqual:message], nil);
+}
+
+- (void)testSerializingMessageAsStringThatIsNil {
+ NSString *nilString = nil;
+ PluginResult *result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString:nilString];
+ NSDictionary *dic = [[result toJSONString] JSONFragmentValue];
+ NSString *message = [dic objectForKey:@"message"];
+ STAssertTrue([[NSNull null] isEqual:message], nil);
+}
+
+@end
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+

0 comments on commit 2f4018c

Please sign in to comment.