@@ -143,7 +143,7 @@ void main() {
143143 test ('Method implementation' , () {
144144 final consumer = ProtocolConsumer ();
145145
146- final MyProtocol myProtocol = MyProtocol .implement (
146+ final MyProtocol myProtocol = MyProtocol$Builder .implement (
147147 instanceMethod_withDouble_: (NSString s, double x) {
148148 return 'MyProtocol: ${s .toDartString ()}: $x ' .toNSString ();
149149 },
@@ -168,7 +168,7 @@ void main() {
168168 final consumer = ProtocolConsumer ();
169169
170170 final protocolBuilder = ObjCProtocolBuilder ();
171- MyProtocol .addToBuilder (
171+ MyProtocol$Builder .addToBuilder (
172172 protocolBuilder,
173173 instanceMethod_withDouble_: (NSString s, double x) {
174174 return 'ProtocolBuilder: ${s .toDartString ()}: $x ' .toNSString ();
@@ -177,7 +177,7 @@ void main() {
177177 return s.y - s.x;
178178 },
179179 );
180- SecondaryProtocol .addToBuilder (
180+ SecondaryProtocol$Builder .addToBuilder (
181181 protocolBuilder,
182182 otherMethod_b_c_d_: (int a, int b, int c, int d) {
183183 return a * b * c * d;
@@ -208,20 +208,18 @@ void main() {
208208 final consumer = ProtocolConsumer ();
209209
210210 final protocolBuilder = ObjCProtocolBuilder ();
211- MyProtocol .instanceMethod_withDouble_.implement (protocolBuilder, (
212- NSString s,
213- double x,
214- ) {
215- return 'ProtocolBuilder: ${s .toDartString ()}: $x ' .toNSString ();
216- });
217- SecondaryProtocol .otherMethod_b_c_d_.implement (protocolBuilder, (
218- int a,
219- int b,
220- int c,
221- int d,
222- ) {
223- return a * b * c * d;
224- });
211+ MyProtocol$Builder .instanceMethod_withDouble_.implement (
212+ protocolBuilder,
213+ (NSString s, double x) {
214+ return 'ProtocolBuilder: ${s .toDartString ()}: $x ' .toNSString ();
215+ },
216+ );
217+ SecondaryProtocol$Builder .otherMethod_b_c_d_.implement (
218+ protocolBuilder,
219+ (int a, int b, int c, int d) {
220+ return a * b * c * d;
221+ },
222+ );
225223 final protocolImpl = protocolBuilder.build ();
226224 final MyProtocol asMyProtocol = MyProtocol .castFrom (protocolImpl);
227225 final SecondaryProtocol asSecondaryProtocol =
@@ -239,7 +237,7 @@ void main() {
239237 test ('Unimplemented method' , () {
240238 final consumer = ProtocolConsumer ();
241239
242- final MyProtocol myProtocol = MyProtocol .implement (
240+ final MyProtocol myProtocol = MyProtocol$Builder .implement (
243241 instanceMethod_withDouble_: (NSString s, double x) {
244242 throw UnimplementedError ();
245243 },
@@ -254,7 +252,7 @@ void main() {
254252 final consumer = ProtocolConsumer ();
255253
256254 final listenerCompleter = Completer <int >();
257- final MyProtocol myProtocol = MyProtocol .implementAsListener (
255+ final MyProtocol myProtocol = MyProtocol$Builder .implementAsListener (
258256 instanceMethod_withDouble_: (NSString s, double x) {
259257 return 'MyProtocol: ${s .toDartString ()}: $x ' .toNSString ();
260258 },
@@ -284,7 +282,7 @@ void main() {
284282
285283 final listenerCompleter = Completer <int >();
286284 final protocolBuilder = ObjCProtocolBuilder ();
287- MyProtocol .addToBuilderAsListener (
285+ MyProtocol$Builder .addToBuilderAsListener (
288286 protocolBuilder,
289287 instanceMethod_withDouble_: (NSString s, double x) {
290288 return 'ProtocolBuilder: ${s .toDartString ()}: $x ' .toNSString ();
@@ -293,7 +291,7 @@ void main() {
293291 listenerCompleter.complete (x);
294292 },
295293 );
296- SecondaryProtocol .addToBuilder (
294+ SecondaryProtocol$Builder .addToBuilder (
297295 protocolBuilder,
298296 otherMethod_b_c_d_: (int a, int b, int c, int d) {
299297 return a * b * c * d;
@@ -329,7 +327,7 @@ void main() {
329327 final consumer = ProtocolConsumer ();
330328
331329 final listenerCompleter = Completer <int >();
332- final MyProtocol myProtocol = MyProtocol .implementAsBlocking (
330+ final MyProtocol myProtocol = MyProtocol$Builder .implementAsBlocking (
333331 instanceMethod_withDouble_: (NSString s, double x) {
334332 throw UnimplementedError ();
335333 },
@@ -352,7 +350,7 @@ void main() {
352350
353351 final listenerCompleter = Completer <int >();
354352 final protocolBuilder = ObjCProtocolBuilder ();
355- MyProtocol .addToBuilderAsBlocking (
353+ MyProtocol$Builder .addToBuilderAsBlocking (
356354 protocolBuilder,
357355 instanceMethod_withDouble_: (NSString s, double x) {
358356 throw UnimplementedError ();
@@ -365,7 +363,7 @@ void main() {
365363 ptr.value = 98765 ;
366364 },
367365 );
368- SecondaryProtocol .addToBuilder (
366+ SecondaryProtocol$Builder .addToBuilder (
369367 protocolBuilder,
370368 otherMethod_b_c_d_: (int a, int b, int c, int d) {
371369 return a * b * c * d;
@@ -389,7 +387,7 @@ void main() {
389387 final consumer = ProtocolConsumer ();
390388
391389 final builder = ObjCProtocolBuilder ();
392- MyProtocol .instanceMethod_withDouble_.implementWithBlock (
390+ MyProtocol$Builder .instanceMethod_withDouble_.implementWithBlock (
393391 builder,
394392 ObjCBlock_NSString_ffiVoid_NSString_ffiDouble .fromFunction (
395393 (Pointer <Void > _, NSString s, double x) =>
@@ -440,18 +438,18 @@ void main() {
440438
441439 test ('Unused protocol' , () {
442440 // Regression test for https://github.com/dart-lang/native/issues/1672.
443- final proto = UnusedProtocol .implement (someMethod: () => 123 );
441+ final proto = UnusedProtocol$Builder .implement (someMethod: () => 123 );
444442 expect (proto, isNotNull);
445443 });
446444
447445 test ('Disabled method' , () {
448446 // Regression test for https://github.com/dart-lang/native/issues/1702.
449- expect (MyProtocol .instanceMethod_withDouble_.isAvailable, isTrue);
450- expect (MyProtocol .optionalMethod_.isAvailable, isTrue);
451- expect (MyProtocol .disabledMethod.isAvailable, isFalse);
447+ expect (MyProtocol$Builder .instanceMethod_withDouble_.isAvailable, isTrue);
448+ expect (MyProtocol$Builder .optionalMethod_.isAvailable, isTrue);
449+ expect (MyProtocol$Builder .disabledMethod.isAvailable, isFalse);
452450
453451 expect (
454- () => MyProtocol .disabledMethod.implement (
452+ () => MyProtocol$Builder .disabledMethod.implement (
455453 ObjCProtocolBuilder (),
456454 () => 123 ,
457455 ),
@@ -474,7 +472,9 @@ void main() {
474472 int count = 0 ;
475473
476474 final protocolBuilder = ObjCProtocolBuilder ();
477- MyProtocol .voidMethod_.implementAsListener (protocolBuilder, (int x) {
475+ MyProtocol$Builder .voidMethod_.implementAsListener (protocolBuilder, (
476+ int x,
477+ ) {
478478 expect (x, 123 );
479479 ++ count;
480480 if (count == 1000 ) completer.complete ();
@@ -497,7 +497,7 @@ void main() {
497497 final block = InstanceMethodBlock .fromFunction (
498498 (Pointer <Void > p, NSString s, double x) => 'Hello' .toNSString (),
499499 );
500- MyProtocol .instanceMethod_withDouble_.implementWithBlock (
500+ MyProtocol$Builder .instanceMethod_withDouble_.implementWithBlock (
501501 protocolBuilder,
502502 block,
503503 );
@@ -655,7 +655,7 @@ void main() {
655655 test ('adding more methods after build' , () {
656656 final protocolBuilder = ObjCProtocolBuilder ();
657657
658- MyProtocol .addToBuilder (
658+ MyProtocol$Builder .addToBuilder (
659659 protocolBuilder,
660660 instanceMethod_withDouble_: (NSString s, double x) {
661661 return 'ProtocolBuilder: ${s .toDartString ()}: $x ' .toNSString ();
@@ -668,7 +668,7 @@ void main() {
668668 final protocolImpl = protocolBuilder.build ();
669669
670670 expect (
671- () => SecondaryProtocol .addToBuilder (
671+ () => SecondaryProtocol$Builder .addToBuilder (
672672 protocolBuilder,
673673 otherMethod_b_c_d_: (int a, int b, int c, int d) {
674674 return a * b * c * d;
@@ -677,5 +677,16 @@ void main() {
677677 throwsA (isA <StateError >()),
678678 );
679679 });
680+
681+ test ('calling methods on a protocol instance' , () {
682+ final protoImpl = ObjCProtocolImpl ();
683+
684+ final MyProtocol myProto = protoImpl.returnsMyProtocol ();
685+ final result = myProto.instanceMethod (
686+ "abc" .toNSString (),
687+ withDouble: 123 ,
688+ );
689+ expect (result.toDartString (), 'ObjCProtocolImpl: abc: 123.00' );
690+ });
680691 });
681692}
0 commit comments