-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[J2KT] Add J2ObjC interop test to check that the names are compatible…
… with J2KT. PiperOrigin-RevId: 733066633
- Loading branch information
1 parent
228cce0
commit 56463fb
Showing
5 changed files
with
204 additions
and
5 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
transpiler/javatests/com/google/j2cl/integration/java/j2ktiosinterop/J2ObjCObjCInteropTest.m
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,104 @@ | ||
#import <XCTest/XCTest.h> | ||
|
||
#import "transpiler/javatests/com/google/j2cl/integration/java/j2ktiosinterop/CustomNames.h" | ||
#import "transpiler/javatests/com/google/j2cl/integration/java/j2ktiosinterop/DefaultNames.h" | ||
#import "transpiler/javatests/com/google/j2cl/integration/java/j2ktiosinterop/EnumNames.h" | ||
|
||
/** J2ObjC interop test for ObjC. */ | ||
@interface J2ObjCObjCInteropTest : XCTestCase | ||
@end | ||
|
||
@implementation J2ObjCObjCInteropTest | ||
|
||
- (void)testDefaultNames { | ||
J2ktiosinteropDefaultNames *obj; | ||
obj = [[J2ktiosinteropDefaultNames alloc] init]; | ||
obj = [[J2ktiosinteropDefaultNames alloc] initWithInt:1]; | ||
obj = [[J2ktiosinteropDefaultNames alloc] initWithInt:1 withNSString:@""]; | ||
|
||
obj = create_J2ktiosinteropDefaultNames_init(); | ||
obj = create_J2ktiosinteropDefaultNames_initWithInt_(1); | ||
obj = create_J2ktiosinteropDefaultNames_initWithInt_withNSString_(1, @""); | ||
|
||
obj = new_J2ktiosinteropDefaultNames_init(); | ||
obj = new_J2ktiosinteropDefaultNames_initWithInt_(1); | ||
obj = new_J2ktiosinteropDefaultNames_initWithInt_withNSString_(1, @""); | ||
|
||
[obj method]; | ||
[obj methodWithBoolean:YES]; | ||
[obj methodWithChar:'a']; | ||
[obj methodWithByte:1]; | ||
[obj methodWithShort:1]; | ||
[obj methodWithInt:1]; | ||
[obj methodWithLong:1]; | ||
[obj methodWithFloat:1]; | ||
[obj methodWithDouble:1]; | ||
[obj methodWithId:NULL]; | ||
[obj methodWithNSString:NULL]; | ||
[obj methodWithNSStringArray:NULL]; | ||
[obj methodWithNSStringArray2:NULL]; | ||
[obj methodWithNSCopying:NULL]; | ||
[obj methodWithNSNumber:NULL]; | ||
[obj methodWithIOSClass:NULL]; | ||
[obj methodWithJavaLangIterable:NULL]; | ||
[obj methodWithInt:1 withNSString:NULL]; | ||
|
||
[obj genericMethodWithId:NULL]; | ||
[obj genericMethodWithNSString:NULL]; | ||
|
||
obj->field_ = obj->field_ + 1; | ||
|
||
J2ktiosinteropDefaultNames_staticMethod(); | ||
J2ktiosinteropDefaultNames_staticMethodWithInt_(1); | ||
J2ktiosinteropDefaultNames_staticMethodWithInt_withNSString_(1, @""); | ||
} | ||
|
||
- (void)testCustomNames { | ||
Custom *obj; | ||
obj = [[Custom alloc] initWithIndex:1]; | ||
obj = [[Custom alloc] initWithIndex:1 name:@""]; | ||
|
||
obj = [[Custom alloc] init]; | ||
obj = [[Custom alloc] init2WithLong:1]; | ||
obj = [[Custom alloc] init3WithLong:1 withNSString:@""]; | ||
|
||
obj = create_Custom_initWithIndex_(1); | ||
obj = create_Custom_initWithIndex_name_(1, @""); | ||
|
||
obj = create_Custom_init(); | ||
obj = create_Custom_init2(1); | ||
obj = create_Custom_init3(1, @""); | ||
|
||
obj = new_Custom_initWithIndex_(1); | ||
obj = new_Custom_initWithIndex_name_(1, @""); | ||
|
||
obj = new_Custom_init(); | ||
obj = new_Custom_init2(1); | ||
obj = new_Custom_init3(1, @""); | ||
|
||
[obj custom]; | ||
[obj customWithIndex:1]; | ||
[obj customWithIndex:1 name:@""]; | ||
|
||
[obj customWithLong:1]; | ||
[obj customWithLong:1 withNSString:@""]; | ||
|
||
Custom_staticCustom(); | ||
Custom_staticCustomWithIndex_(1); | ||
Custom_staticCustomWithIndex_name_(1, @""); | ||
|
||
Custom_staticCustom2(1); | ||
Custom_staticCustom3(2, @""); | ||
} | ||
|
||
- (void)testEnumNames { | ||
J2ktiosinteropEnumNames *e; | ||
e = J2ktiosinteropEnumNames_get_ONE(); | ||
e = J2ktiosinteropEnumNames_get_TWO(); | ||
|
||
J2ktiosinteropEnumNames_Enum e2; | ||
e2 = J2ktiosinteropEnumNames_Enum_ONE; | ||
e2 = J2ktiosinteropEnumNames_Enum_TWO; | ||
} | ||
|
||
@end |
83 changes: 83 additions & 0 deletions
83
...er/javatests/com/google/j2cl/integration/java/j2ktiosinterop/J2ObjCSwiftInteropTest.swift
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,83 @@ | ||
/* | ||
* Copyright 2024 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
import XCTest | ||
import third_party_java_src_j2cl_transpiler_javatests_com_google_j2cl_integration_java_j2ktiosinterop_j2objc | ||
|
||
/// J2ObjC interop test for Swift. | ||
final class J2ObjCSwiftInteropTest: XCTestCase { | ||
func testDefaultNames() { | ||
var obj: J2ktiosinteropDefaultNames | ||
|
||
obj = J2ktiosinteropDefaultNames() | ||
obj = J2ktiosinteropDefaultNames(int: 1) | ||
obj = J2ktiosinteropDefaultNames(int: 1, with: "") | ||
|
||
obj.method() | ||
obj.method(withBoolean: true as jboolean) | ||
obj.method(withChar: 65 as jchar) | ||
obj.method(withByte: 1 as jbyte) | ||
obj.method(withShort: 1 as jshort) | ||
obj.method(with:1 as jint) | ||
obj.method(withLong: 1 as jlong) | ||
obj.method(with:1.0 as jfloat) | ||
obj.method(with:1.0 as jdouble) | ||
obj.method(withId: nil) | ||
obj.method(with: nil as String?) | ||
obj.method(withNSStringArray: nil) | ||
obj.method(withNSStringArray2: nil) | ||
//obj.methodWith(nil as NSCopying?) | ||
obj.method(with: 1 as NSNumber) | ||
obj.method(with: nil as IOSClass?) | ||
obj.method(with: nil as JavaLangIterable?) | ||
obj.method(with: 1, with: nil) | ||
|
||
obj.genericMethod(withId: nil as Any?) | ||
obj.genericMethod(with: nil as String?) | ||
|
||
// Not exposed in Swift | ||
//obj.field_ = obj.field_ | ||
} | ||
|
||
func testCustomNames() { | ||
var obj: Custom | ||
|
||
obj = Custom(index: 1 as jint) | ||
obj = Custom(index: 1 as jint, name: "") | ||
|
||
obj = Custom() | ||
// Not exposed on Swift | ||
//obj = Custom(long: 1 as jlong) | ||
//obj = Custom(long: 1 as jlong, withNSString: "") | ||
|
||
obj.custom() | ||
obj.custom(with: 1 as jint) | ||
obj.custom(with: 1 as jint, name: "") | ||
|
||
obj.custom(withLong: 1 as jlong) | ||
obj.custom(withLong: 1 as jlong, with: "") | ||
} | ||
|
||
func testEnumNames() { | ||
var e: J2ktiosinteropEnumNames | ||
e = J2ktiosinteropEnumNames_get_ONE() | ||
e = J2ktiosinteropEnumNames_get_TWO() | ||
|
||
var e2: J2ktiosinteropEnumNames_Enum | ||
// Not exposed on Swift | ||
//e2 = J2ktiosinteropEnumNames_Enum_ONE; | ||
//e2 = J2ktiosinteropEnumNames_Enum_TWO; | ||
} | ||
} |
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