github.com/coming-chat/gomobile@v0.0.0-20220601074111-56995f7d7aba/bind/objc/SeqWrappers.m (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build ignore
     6  // +build ignore
     7  
     8  @import ObjectiveC.message;
     9  @import Foundation;
    10  @import XCTest;
    11  @import Objcpkg;
    12  
    13  @interface TestNSObject : NSObject
    14  
    15  - (NSString *)description;
    16  - (NSString *)super_description;
    17  
    18  @end
    19  
    20  @implementation TestNSObject
    21  
    22  - (NSString *)description {
    23  	return @"hej";
    24  }
    25  
    26  - (NSString *)super_description {
    27  	return [super description];
    28  }
    29  
    30  @end
    31  
    32  @interface wrappers : XCTestCase
    33  
    34  @end
    35  
    36  @implementation wrappers
    37  
    38  - (void)setUp {
    39  	[super setUp];
    40  	// Put setup code here. This method is called before the invocation of each test method in the class.
    41  }
    42  
    43  - (void)tearDown {
    44  	// Put teardown code here. This method is called after the invocation of each test method in the class.
    45  	[super tearDown];
    46  }
    47  
    48  - (void)testFunction {
    49  	ObjcpkgFunc();
    50  }
    51  
    52  - (void)testMethod {
    53  	ObjcpkgMethod();
    54  }
    55  
    56  - (void)testNew {
    57  	ObjcpkgNew();
    58  }
    59  
    60  - (void)testError {
    61  	ObjcpkgError();
    62  }
    63  
    64  - (void)testClass {
    65  	ObjcpkgGoNSDate *d = [[ObjcpkgGoNSDate alloc] init];
    66  	NSString *desc = [d description];
    67  	XCTAssertEqual(d, [d getSelf], "GoNSDate self not identical");
    68  	XCTAssertEqual(ObjcpkgHash, [d hash], "GoNSDate hash not identical");
    69  	XCTAssertTrue([desc isEqualToString:ObjcpkgDescriptionStr], "GoNSDate description mismatch: %@", desc);
    70  	ObjcpkgGoUIResponder *resp = [[ObjcpkgGoUIResponder alloc] init];
    71  	[resp pressesBegan:nil withEvent:nil];
    72  	XCTAssertTrue([resp called], "GoUIResponder.pressesBegan not called");
    73  }
    74  
    75  - (void)testSuper {
    76  	ObjcpkgGoNSObject *o = [[ObjcpkgGoNSObject alloc] init];
    77  	struct objc_super _super = {
    78  		.receiver = o,
    79  		.super_class = [NSObject class],
    80  	};
    81  	NSString *superDesc = ((NSString *(*)(struct objc_super*, SEL))objc_msgSendSuper)(&_super, @selector(description));
    82  	XCTAssertTrue([superDesc isEqualToString:[o description]], "GoNSObject description mismatch");
    83  	[o setUseSelf:TRUE];
    84  	XCTAssertTrue([ObjcpkgDescriptionStr isEqualToString:[o description]], "GoNSObject description mismatch");
    85  }
    86  
    87  - (void)testIdentity {
    88  	NSDate *d = [[NSDate alloc] init];
    89  	NSDate *d2 = ObjcpkgDupNSDate(d);
    90  	XCTAssertEqual(d, d2, @"ObjcpkgDupNSDate failed to duplicate ObjC instance");
    91  	ObjcpkgGoNSDate *gd = [[ObjcpkgGoNSDate alloc] init];
    92  	NSDate *gd2 = ObjcpkgDupNSDate(gd);
    93  	XCTAssertEqual(gd, gd2, @"ObjcpkgDupNSDate failed to duplicate Go instance");
    94  	NSDate *gd3 = ObjcpkgNewGoNSDate();
    95  	NSDate *gd4 = ObjcpkgDupNSDate(gd3);
    96  	XCTAssertEqual(gd4, gd3, @"ObjcpkgDupNSDate failed to duplicate instance created in Go");
    97  }
    98  @end