This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29cad88
commit ad26be6
Showing
7 changed files
with
198 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: NullableInheritanceTestObjCLibrary | ||
description: 'Tests nullability of inherited Objective-C methods' | ||
language: objc | ||
output: 'nullable_inheritance_bindings.dart' | ||
exclude-all-by-default: true | ||
objc-interfaces: | ||
include: | ||
- NullableBase | ||
- NullableChild | ||
headers: | ||
entry-points: | ||
- 'nullable_inheritance_test.m' | ||
preamble: | | ||
// ignore_for_file: camel_case_types, non_constant_identifier_names, unused_element, unused_field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Objective C support is only available on mac. | ||
@TestOn('mac-os') | ||
|
||
import 'dart:ffi'; | ||
import 'dart:io'; | ||
|
||
import 'package:test/test.dart'; | ||
import '../test_utils.dart'; | ||
import 'nullable_inheritance_bindings.dart'; | ||
import 'util.dart'; | ||
|
||
void main() { | ||
late NullableInheritanceTestObjCLibrary lib; | ||
late NullableBase nullableBase; | ||
late NullableChild nullableChild; | ||
late NSObject obj; | ||
group('Nullable inheritance', () { | ||
setUpAll(() { | ||
logWarnings(); | ||
final dylib = File('test/native_objc_test/nullable_inheritance_test.dylib'); | ||
verifySetupFile(dylib); | ||
lib = NullableInheritanceTestObjCLibrary( | ||
DynamicLibrary.open(dylib.absolute.path)); | ||
nullableBase = NullableBase.new1(lib); | ||
nullableChild = NullableChild.new1(lib); | ||
obj = NSObject.new1(lib); | ||
generateBindingsForCoverage('nullable'); | ||
}); | ||
|
||
group('Base', () { | ||
test('Nullable arguments', () { | ||
expect(nullableBase.nullableArg_(obj), false); | ||
expect(nullableBase.nullableArg_(null), true); | ||
}); | ||
|
||
test('Non-null arguments', () { | ||
expect(nullableBase.nonNullArg_(obj), false); | ||
}); | ||
|
||
test('Nullable return', () { | ||
expect(nullableBase.nullableReturn_(false), isA<NSObject>()); | ||
expect(nullableBase.nullableReturn_(true), null); | ||
}); | ||
|
||
test('Non-null return', () { | ||
expect(nullableBase.nonNullReturn(), isA<NSObject>()); | ||
}); | ||
}); | ||
|
||
group('Child', () { | ||
test('Nullable arguments, changed to non-null', () { | ||
expect(nullableChild.nullableArg_(obj), false); | ||
}); | ||
|
||
test('Non-null arguments, changed to nullable', () { | ||
expect(nullableChild.nonNullArg_(obj), false); | ||
expect(nullableChild.nonNullArg_(null), true); | ||
}); | ||
|
||
test('Nullable return, changed to non-null', () { | ||
expect(nullableChild.nullableReturn_(false), isA<NSObject>()); | ||
}); | ||
|
||
test('Non-null return, changed to nullable', () { | ||
expect(nullableChild.nonNullReturn(), null); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#import <Foundation/NSObject.h> | ||
|
||
@interface NullableBase : NSObject {} | ||
|
||
-(BOOL) nullableArg:(nullable NSObject *)x; | ||
-(BOOL) nonNullArg:(NSObject *)x; | ||
-(nullable NSObject *) nullableReturn:(BOOL)r; | ||
-(NSObject*) nonNullReturn; | ||
|
||
@end | ||
|
||
@implementation NullableBase | ||
|
||
-(BOOL) nullableArg:(nullable NSObject *)x { | ||
return x == NULL; | ||
} | ||
|
||
-(BOOL) nonNullArg:(NSObject *)x { | ||
return x == NULL; | ||
} | ||
|
||
-(nullable NSObject *) nullableReturn:(BOOL)r { | ||
if (r) { | ||
return nil; | ||
} else { | ||
return [NSObject new]; | ||
} | ||
} | ||
|
||
-(NSObject *) nonNullReturn { | ||
return [NSObject new]; | ||
} | ||
|
||
@end | ||
|
||
@interface NullableIntermediate : NullableBase {} | ||
@end | ||
|
||
@interface NullableChild : NullableIntermediate {} | ||
|
||
// Redeclare the same methods with different nullability. | ||
-(BOOL) nullableArg:(NSObject *)x; | ||
-(BOOL) nonNullArg:(nullable NSObject *)x; | ||
-(NSObject *) nullableReturn:(BOOL)r; | ||
-(nullable NSObject *) nonNullReturn; | ||
|
||
@end | ||
|
||
@implementation NullableChild | ||
|
||
-(BOOL) nullableArg:(NSObject *)x { | ||
return x == NULL; | ||
} | ||
|
||
-(BOOL) nonNullArg:(nullable NSObject *)x { | ||
return x == NULL; | ||
} | ||
|
||
-(NSObject *) nullableReturn:(BOOL)r { | ||
return [NSObject new]; | ||
} | ||
|
||
-(nullable NSObject *) nonNullReturn { | ||
return nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters