Flutter macOS Embedder
flutter_codecs_unittest.mm File Reference

Go to the source code of this file.

Functions

FLUTTER_ASSERT_ARC TEST (FlutterStringCodec, CanEncodeAndDecodeNil)
 
 TEST (FlutterStringCodec, CanEncodeAndDecodeEmptyString)
 
 TEST (FlutterStringCodec, CanEncodeAndDecodeAsciiString)
 
 TEST (FlutterStringCodec, CanEncodeAndDecodeNonAsciiString)
 
 TEST (FlutterStringCodec, CanEncodeAndDecodeNonBMPString)
 
 TEST (FlutterJSONCodec, ThrowsOnInvalidEncode)
 
 TEST (FlutterJSONCodec, CanDecodeZeroLength)
 
 TEST (FlutterJSONCodec, ThrowsOnInvalidDecode)
 
 TEST (FlutterJSONCodec, CanEncodeAndDecodeNil)
 
 TEST (FlutterJSONCodec, CanEncodeAndDecodeArray)
 
 TEST (FlutterJSONCodec, CanEncodeAndDecodeDictionary)
 

Function Documentation

◆ TEST() [1/11]

TEST ( FlutterJSONCodec  ,
CanDecodeZeroLength   
)

Definition at line 55 of file flutter_codecs_unittest.mm.

55  {
56  FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
57  ASSERT_TRUE([codec decode:[NSData data]] == nil);
58 }

◆ TEST() [2/11]

TEST ( FlutterJSONCodec  ,
CanEncodeAndDecodeArray   
)

Definition at line 73 of file flutter_codecs_unittest.mm.

73  {
74  NSArray* value = @[ [NSNull null], @"hello", @3.14, @47, @{@"a" : @"nested"} ];
75  FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
76  NSData* encoded = [codec encode:value];
77  NSArray* decoded = [codec decode:encoded];
78  ASSERT_TRUE([value isEqualTo:decoded]);
79 }

◆ TEST() [3/11]

TEST ( FlutterJSONCodec  ,
CanEncodeAndDecodeDictionary   
)

Definition at line 81 of file flutter_codecs_unittest.mm.

81  {
82  NSDictionary* value = @{@"a" : @3.14, @"b" : @47, @"c" : [NSNull null], @"d" : @[ @"nested" ]};
83  FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
84  NSData* encoded = [codec encode:value];
85  NSDictionary* decoded = [codec decode:encoded];
86  ASSERT_TRUE([value isEqualTo:decoded]);
87 }

◆ TEST() [4/11]

TEST ( FlutterJSONCodec  ,
CanEncodeAndDecodeNil   
)

Definition at line 67 of file flutter_codecs_unittest.mm.

67  {
68  FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
69  ASSERT_TRUE([codec encode:nil] == nil);
70  ASSERT_TRUE([codec decode:nil] == nil);
71 }

◆ TEST() [5/11]

TEST ( FlutterJSONCodec  ,
ThrowsOnInvalidDecode   
)

Definition at line 60 of file flutter_codecs_unittest.mm.

60  {
61  NSString* value = @"{{{";
62  FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
63  EXPECT_EXIT([codec decode:[value dataUsingEncoding:value.fastestEncoding]],
64  testing::KilledBySignal(SIGABRT), "No string key for value in object around line 1");
65 }

◆ TEST() [6/11]

TEST ( FlutterJSONCodec  ,
ThrowsOnInvalidEncode   
)

Definition at line 47 of file flutter_codecs_unittest.mm.

47  {
48  NSString* value = [[NSString alloc] initWithBytes:"\xdf\xff"
49  length:2
50  encoding:NSUTF16StringEncoding];
51  FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
52  EXPECT_EXIT([codec encode:value], testing::KilledBySignal(SIGABRT), "failed to convert to UTF8");
53 }

◆ TEST() [7/11]

TEST ( FlutterStringCodec  ,
CanEncodeAndDecodeAsciiString   
)

Definition at line 23 of file flutter_codecs_unittest.mm.

23  {
24  NSString* value = @"hello world";
25  FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
26  NSData* encoded = [codec encode:value];
27  NSString* decoded = [codec decode:encoded];
28  ASSERT_TRUE([value isEqualTo:decoded]);
29 }

◆ TEST() [8/11]

TEST ( FlutterStringCodec  ,
CanEncodeAndDecodeEmptyString   
)

Definition at line 17 of file flutter_codecs_unittest.mm.

17  {
18  FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
19  ASSERT_TRUE([[codec encode:@""] isEqualTo:[NSData data]]);
20  ASSERT_TRUE([[codec decode:[NSData data]] isEqualTo:@""]);
21 }

◆ TEST() [9/11]

FLUTTER_ASSERT_ARC TEST ( FlutterStringCodec  ,
CanEncodeAndDecodeNil   
)

Definition at line 11 of file flutter_codecs_unittest.mm.

11  {
12  FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
13  ASSERT_TRUE([codec encode:nil] == nil);
14  ASSERT_TRUE([codec decode:nil] == nil);
15 }

◆ TEST() [10/11]

TEST ( FlutterStringCodec  ,
CanEncodeAndDecodeNonAsciiString   
)

Definition at line 31 of file flutter_codecs_unittest.mm.

31  {
32  NSString* value = @"hello \u263A world";
33  FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
34  NSData* encoded = [codec encode:value];
35  NSString* decoded = [codec decode:encoded];
36  ASSERT_TRUE([value isEqualTo:decoded]);
37 }

◆ TEST() [11/11]

TEST ( FlutterStringCodec  ,
CanEncodeAndDecodeNonBMPString   
)

Definition at line 39 of file flutter_codecs_unittest.mm.

39  {
40  NSString* value = @"hello \U0001F602 world";
41  FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
42  NSData* encoded = [codec encode:value];
43  NSString* decoded = [codec decode:encoded];
44  ASSERT_TRUE([value isEqualTo:decoded]);
45 }
FlutterStringCodec
Definition: FlutterCodecs.h:63
FlutterJSONMessageCodec
Definition: FlutterCodecs.h:81