Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions TestFixtures/Api/TNSApi.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
typedef NS_ENUM(NSInteger, TNSEnums) {
TNSEnum1 = -1,
TNSEnum2,
TNSEnum3,
TNSEnum1 = -1,
TNSEnum2,
TNSEnum3,
};

typedef NS_OPTIONS(NSInteger, TNSOptions) {
TNSOption1 = 1 << 0,
TNSOption2 = 1 << 1,
TNSOption3 = 1 << 2,
TNSOption1 = 1 << 0,
TNSOption2 = 1 << 1,
TNSOption3 = 1 << 2,
};

enum {
AnonymousEnumField = -1
};
enum { AnonymousEnumField = -1 };

extern NSString* const TNSConstant;

Expand All @@ -27,14 +25,15 @@ void functionThrowsException();
@property(getter=customGetter, setter=customSetter:) int property;

typedef UIColor NIKColor;
@property(strong, nonatomic) NIKColor* strokeColor; // ^{UIColor=#}
@property(strong, nonatomic) NIKColor* strokeColor; // ^{UIColor=#}

+ (void)methodThrowsException;
- (void)methodThrowsException;

- (void)methodCalledInDealloc;

- (BOOL)method:(NSInteger)errorCode error:(NSError**)outError;
- (BOOL)methodNullable:(NSInteger)errorCode error:(NSError* _Nullable* _Nullable)outError;
@end

@interface TNSConflictingSelectorTypes1 : NSObject
Expand Down Expand Up @@ -70,5 +69,5 @@ typedef UIColor NIKColor;
- (CGRect)getRect;
@end

@interface RectClass : NSObject<RectProtocol>
@interface RectClass : NSObject <RectProtocol>
@end
53 changes: 32 additions & 21 deletions TestFixtures/Api/TNSApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,57 @@
NSString* const TNSConstant = @"TNSConstant";

void functionThrowsException() {
@throw [NSException exceptionWithName:NSGenericException reason:@"No reason" userInfo:nil];
@throw [NSException exceptionWithName:NSGenericException reason:@"No reason" userInfo:nil];
}

@implementation TNSApi {
int _property;
int _property;
}

- (int)customGetter {
return _property;
return _property;
}
- (void)customSetter:(int)value {
_property = value;
_property = value;
}

+ (void)methodThrowsException {
@throw [NSException exceptionWithName:NSGenericException reason:@"No reason" userInfo:nil];
@throw [NSException exceptionWithName:NSGenericException reason:@"No reason" userInfo:nil];
}

- (void)methodThrowsException {
@throw [NSException exceptionWithName:NSGenericException reason:@"No reason" userInfo:nil];
@throw [NSException exceptionWithName:NSGenericException reason:@"No reason" userInfo:nil];
}

- (void)methodCalledInDealloc {
// TODO
// [TNSGetOutput() appendString:@"methodCalledInDealloc called"];
// TODO
// [TNSGetOutput() appendString:@"methodCalledInDealloc called"];
}

- (void)dealloc {
[self methodCalledInDealloc];
[self methodCalledInDealloc];
}

- (BOOL)method:(NSInteger)errorCode error:(NSError**)outError {
if (outError) {
if (errorCode != 0) {
*outError = [NSError errorWithDomain:@"TNSErrorDomain" code:errorCode userInfo:nil];
} else {
*outError = nil;
}
if (outError) {
if (errorCode != 0) {
*outError = [NSError errorWithDomain:@"TNSErrorDomain" code:errorCode userInfo:nil];
} else {
*outError = nil;
}
return errorCode == 0;
}
return errorCode == 0;
}

- (BOOL)methodNullable:(NSInteger)errorCode error:(NSError* _Nullable* _Nullable)outError {
if (outError) {
if (errorCode != 0) {
*outError = [NSError errorWithDomain:@"TNSErrorDomain" code:errorCode userInfo:nil];
} else {
*outError = nil;
}
}
return errorCode == 0;
}

@end
Expand All @@ -56,19 +67,19 @@ - (void)method:(long long)x {

@implementation TNSConflictingSelectorTypes2
+ (id)method:(id)x {
return nil;
return nil;
}
- (id)method:(id)x {
return nil;
return nil;
}
@end

@implementation TNSSwizzleKlass
+ (int)staticMethod:(int)x {
return x;
return x;
}
- (int)instanceMethod:(int)x {
return x;
return x;
}
@end

Expand All @@ -79,7 +90,7 @@ @implementation TNSPropertyMethodConflictClass
@implementation RectClass

- (CGRect)getRect {
return CGRectMake(1, 2, 3, 4);
return CGRectMake(1, 2, 3, 4);
}

@end
19 changes: 19 additions & 0 deletions TestRunner/app/tests/Marshalling/ObjCTypesTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,23 @@ describe(module.id, function () {
expect(typeof array.firstObject).toEqual("boolean");
expect(array.firstObject).toEqual(bool);
});

it("NSErrorOutParameterWithNullabilityAnnotations", function () {
expect(function () {
TNSApi.new().methodNullableError(0);
}).not.toThrow();

var isThrown = false;
try {
TNSApi.new().methodNullableError(1);
} catch (e) {
isThrown = true;
expect(e.stack).toEqual(jasmine.any(String));
}
expect(isThrown).toBe(true);

var errorRef = new interop.Reference();
TNSApi.new().methodNullableError(1, errorRef);
expect(errorRef.value instanceof NSError).toBe(true);
});
});
Loading
Loading