SeqWrappers.m 2.5 KB

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