| Flutter iOS Embedder |

flutter_codecs_unittest.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
6
7 #include "gtest/gtest.h"
8
9 FLUTTER_ASSERT_ARC
10
11 TEST(FlutterStringCodec, CanEncodeAndDecodeNil) {
12 FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
13 ASSERT_TRUE([codec encode:nil] == nil);
14 ASSERT_TRUE([codec decode:nil] == nil);
15 }
16
17 TEST(FlutterStringCodec, CanEncodeAndDecodeEmptyString) {
18 FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
19 ASSERT_TRUE([[codec encode:@""] isEqualTo:[NSData data]]);
20 ASSERT_TRUE([[codec decode:[NSData data]] isEqualTo:@""]);
21 }
22
23 TEST(FlutterStringCodec, CanEncodeAndDecodeAsciiString) {
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 }
30
31 TEST(FlutterStringCodec, CanEncodeAndDecodeNonAsciiString) {
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 }
38
39 TEST(FlutterStringCodec, CanEncodeAndDecodeNonBMPString) {
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 }
46
47 TEST(FlutterJSONCodec, CanDecodeZeroLength) {
48 FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
49 ASSERT_TRUE([codec decode:[NSData data]] == nil);
50 }
51
52 TEST(FlutterJSONCodec, CanEncodeAndDecodeNil) {
53 FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
54 ASSERT_TRUE([codec encode:nil] == nil);
55 ASSERT_TRUE([codec decode:nil] == nil);
56 }
57
58 TEST(FlutterJSONCodec, CanEncodeAndDecodeArray) {
59 NSArray* value = @[ [NSNull null], @"hello", @3.14, @47, @{@"a" : @"nested"} ];
60 FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
61 NSData* encoded = [codec encode:value];
62 NSArray* decoded = [codec decode:encoded];
63 ASSERT_TRUE([value isEqualTo:decoded]);
64 }
65
66 TEST(FlutterJSONCodec, CanEncodeAndDecodeDictionary) {
67 NSDictionary* value = @{@"a" : @3.14, @"b" : @47, @"c" : [NSNull null], @"d" : @[ @"nested" ]};
68 FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance];
69 NSData* encoded = [codec encode:value];
70 NSDictionary* decoded = [codec decode:encoded];
71 ASSERT_TRUE([value isEqualTo:decoded]);
72 }
FlutterStringCodec
Definition: FlutterCodecs.h:63
FlutterCodecs.h
TEST
FLUTTER_ASSERT_ARC TEST(FlutterStringCodec, CanEncodeAndDecodeNil)
Definition: flutter_codecs_unittest.mm:11
FLUTTER_ASSERT_ARC
Definition: VsyncWaiterIosTest.mm:15
FlutterJSONMessageCodec
Definition: FlutterCodecs.h:81