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