Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from forcedotcom/bool_plugin_result
Browse files Browse the repository at this point in the history
Bool plugin result support
  • Loading branch information
khawkins committed Feb 9, 2012
2 parents 83d0eb2 + 952b382 commit 839c926
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions PhoneGapLib/Classes/PluginResult.h
Expand Up @@ -39,11 +39,13 @@ typedef enum {
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsString: (NSString*) theMessage;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsArray: (NSArray*) theMessage;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsBool: (BOOL) theMessage;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsInt: (int) theMessage;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsDouble: (double) theMessage;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsDictionary: (NSDictionary*) theMessage;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsString: (NSString*) theMessage cast: (NSString*) theCast;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsArray: (NSArray*) theMessage cast: (NSString*) theCast;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsBool: (BOOL) theMessage cast: (NSString*) theCast;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsInt: (int) theMessage cast: (NSString*) theCast;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsDouble: (double) theMessage cast: (NSString*) theCast;
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsDictionary: (NSDictionary*) theMessage cast: (NSString*) theCast;
Expand Down
8 changes: 8 additions & 0 deletions PhoneGapLib/Classes/PluginResult.m
Expand Up @@ -72,6 +72,10 @@ +(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsArra
{
return [[[self alloc] initWithStatus: statusOrdinal message: theMessage cast:nil] autorelease];
}
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsBool: (BOOL) theMessage
{
return [[[self alloc] initWithStatus: statusOrdinal message: [NSNumber numberWithBool: theMessage] cast:nil] autorelease];
}
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsInt: (int) theMessage
{
return [[[self alloc] initWithStatus: statusOrdinal message: [NSNumber numberWithInt: theMessage] cast:nil] autorelease];
Expand All @@ -94,6 +98,10 @@ +(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsArra
return [[[self alloc] initWithStatus: statusOrdinal message: theMessage cast:theCast] autorelease];
}

+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsBool: (BOOL) theMessage cast: (NSString*) theCast
{
return [[[self alloc] initWithStatus: statusOrdinal message: [NSNumber numberWithBool: theMessage] cast:theCast] autorelease];
}
+(PluginResult*) resultWithStatus: (PGCommandStatus) statusOrdinal messageAsInt: (int) theMessage cast: (NSString*) theCast
{
return [[[self alloc] initWithStatus: statusOrdinal message: [NSNumber numberWithInt: theMessage] cast:theCast] autorelease];
Expand Down
Expand Up @@ -13,6 +13,13 @@

@implementation PluginResultJSONSerializationTests

- (void)testSerializingMessageAsBool {
PluginResult *result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsBool:YES];
NSDictionary *dic = [[result toJSONString] objectFromJSONString];
NSNumber *message = [dic objectForKey:@"message"];
STAssertTrue([[NSNumber numberWithBool:YES] isEqual:message], nil);
}

- (void)testSerializingMessageAsInt {
PluginResult *result = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsInt:5];
NSDictionary *dic = [[result toJSONString] objectFromJSONString];
Expand Down

0 comments on commit 839c926

Please sign in to comment.