-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
ProtocolImplementationTests.js
165 lines (133 loc) · 4.76 KB
/
ProtocolImplementationTests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
describe(module.id, function () {
afterEach(function () {
TNSClearOutput();
});
it('Methods', function () {
var object = NSObject.extend({
baseProtocolMethod1: function () {
TNSLog('baseProtocolMethod1 called');
}
}, {
protocols: [TNSBaseProtocol1]
}).alloc().init();
var actual;
var expected = "baseProtocolMethod1 called";
object.baseProtocolMethod1();
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
TNSTestNativeCallbacks.protocolImplementationMethods(object);
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
});
it('Properties', function () {
var object = NSObject.extend({
get baseProtocolProperty1() {
TNSLog('baseProtocolProperty1 called');
},
set baseProtocolProperty1(x) {
TNSLog('setBaseProtocolProperty1: called');
},
get baseProtocolProperty1Optional() {
TNSLog('baseProtocolProperty1Optional called');
},
set baseProtocolProperty1Optional(x) {
TNSLog('setBaseProtocolProperty1Optional: called');
},
}, {
protocols: [TNSBaseProtocol1]
}).alloc().init();
var actual;
var expected =
"setBaseProtocolProperty1: called" +
"baseProtocolProperty1 called" +
"setBaseProtocolProperty1Optional: called" +
"baseProtocolProperty1Optional called";
object.baseProtocolProperty1 = 0;
UNUSED(object.baseProtocolProperty1);
object.baseProtocolProperty1Optional = 0;
UNUSED(object.baseProtocolProperty1Optional);
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
TNSTestNativeCallbacks.protocolImplementationProperties(object);
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
});
it("ProtocolInheritance", function () {
var object = NSObject.extend({
baseProtocolMethod1: function () {
TNSLog('baseProtocolMethod1 called');
},
baseProtocolMethod2: function () {
TNSLog('baseProtocolMethod2 called');
},
}, {
protocols: [TNSBaseProtocol2]
}).alloc().init();
var actual;
var expected =
"baseProtocolMethod1 called" +
"baseProtocolMethod2 called";
object.baseProtocolMethod1();
object.baseProtocolMethod2();
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
TNSTestNativeCallbacks.protocolImplementationProtocolInheritance(object);
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
});
it('OptionalMethods', function () {
var object = NSObject.extend({
baseProtocolMethod1Optional: function () {
TNSLog('baseProtocolMethod1Optional called');
},
}, {
protocols: [TNSBaseProtocol2]
}).alloc().init();
var actual;
var expected = "baseProtocolMethod1Optional called";
object.baseProtocolMethod1Optional();
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
TNSTestNativeCallbacks.protocolImplementationOptionalMethods(object);
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
});
it('AlreadyImplementedProtocol', function () {
TNSDerivedInterface.extend({}, {
protocols: [TNSBaseProtocol1]
});
});
it('Two protocols', function () {
var object = NSObject.extend({
baseProtocolMethod1: function () {
TNSLog('baseProtocolMethod1 called');
},
baseCategoryProtocolMethod1: function () {
TNSLog('baseCategoryProtocolMethod1 called');
}
}, {
protocols: [TNSBaseProtocol1, TNSBaseCategoryProtocol1]
}).alloc().init();
var actual;
var expected =
'baseProtocolMethod1 called' +
'baseCategoryProtocolMethod1 called';
object.baseProtocolMethod1();
object.baseCategoryProtocolMethod1();
actual = TNSGetOutput();
expect(actual).toBe(expected);
TNSClearOutput();
TNSTestNativeCallbacks.protocolImplementationMethods(object);
TNSTestNativeCallbacks.categoryProtocolImplementationMethods(object);
actual = TNSGetOutput();
expect(actual).toBe(expected);
});
});