Flutter Engine
The Flutter Engine
Classes | Functions | Variables
flutter_standard_codec_unittest.mm File Reference
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
#include <CoreFoundation/CoreFoundation.h>
#include "gtest/gtest.h"

Go to the source code of this file.

Classes

struct  Pair
 
class  ExtendedWriter
 
class  ExtendedReader
 
class  ExtendedReaderWriter
 

Functions

static void CheckEncodeDecode (id value, NSData *expectedEncoding)
 
static void CheckEncodeDecode (id value)
 
 TEST (FlutterStandardCodec, CanDecodeZeroLength)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeNil)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeNSNull)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeYes)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeNo)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeUInt8)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeUInt16)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeUInt32)
 
 TEST (FlutterStandardCodec, CanEncodeUInt64)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeSInt8)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeSInt16)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeSInt32)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeSInt64)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeFloat32)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeFloat64)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeString)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeStringWithNonAsciiCodePoint)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeStringWithNonBMPCodePoint)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeIndirectString)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeArray)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeDictionary)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeByteArray)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeNSData)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeInt32Array)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeInt64Array)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeFloat32Array)
 
 TEST (FlutterStandardCodec, CanEncodeAndDecodeFloat64Array)
 
 TEST (FlutterStandardCodec, HandlesMethodCallsWithNilArguments)
 
 TEST (FlutterStandardCodec, HandlesMethodCallsWithSingleArgument)
 
 TEST (FlutterStandardCodec, HandlesMethodCallsWithArgumentList)
 
 TEST (FlutterStandardCodec, HandlesSuccessEnvelopesWithNilResult)
 
 TEST (FlutterStandardCodec, HandlesSuccessEnvelopesWithSingleResult)
 
 TEST (FlutterStandardCodec, HandlesSuccessEnvelopesWithResultMap)
 
 TEST (FlutterStandardCodec, HandlesErrorEnvelopes)
 
 TEST (FlutterStandardCodec, HandlesSubclasses)
 

Variables

static const UInt8 kDATE = 128
 
static const UInt8 kPAIR = 129
 

Function Documentation

◆ CheckEncodeDecode() [1/2]

static void CheckEncodeDecode ( id  value)
static

Definition at line 108 of file flutter_standard_codec_unittest.mm.

108 {
110 NSData* encoded = [codec encode:value];
111 id decoded = [codec decode:encoded];
112 if (value == nil || value == [NSNull null]) {
113 ASSERT_TRUE(decoded == nil);
114 } else {
115 ASSERT_TRUE([value isEqual:decoded]);
116 }
117}
static void encode(uint8_t output[16], const uint32_t input[4])
Definition: SkMD5.cpp:240
uint8_t value
static DecodeResult decode(std::string path)
Definition: png_codec.cpp:124

◆ CheckEncodeDecode() [2/2]

static void CheckEncodeDecode ( id  value,
NSData *  expectedEncoding 
)
static

Definition at line 92 of file flutter_standard_codec_unittest.mm.

92 {
94 NSData* encoded = [codec encode:value];
95 if (expectedEncoding == nil) {
96 ASSERT_TRUE(encoded == nil);
97 } else {
98 ASSERT_TRUE([encoded isEqual:expectedEncoding]);
99 }
100 id decoded = [codec decode:encoded];
101 if (value == nil || value == [NSNull null]) {
102 ASSERT_TRUE(decoded == nil);
103 } else {
104 ASSERT_TRUE([value isEqual:decoded]);
105 }
106}

◆ TEST() [1/35]

TEST ( FlutterStandardCodec  ,
CanDecodeZeroLength   
)

Definition at line 119 of file flutter_standard_codec_unittest.mm.

119 {
121 id decoded = [codec decode:[NSData data]];
122 ASSERT_TRUE(decoded == nil);
123}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ TEST() [2/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeArray   
)

Definition at line 233 of file flutter_standard_codec_unittest.mm.

233 {
234 NSArray* value = @[ [NSNull null], @"hello", @3.14, @47, @{@42 : @"nested"} ];
236}
static void CheckEncodeDecode(id value, NSData *expectedEncoding)

◆ TEST() [3/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeByteArray   
)

Definition at line 247 of file flutter_standard_codec_unittest.mm.

247 {
248 uint8_t bytes[4] = {0xBA, 0x5E, 0xBA, 0x11};
249 NSData* data = [NSData dataWithBytes:bytes length:4];
252}
size_t length

◆ TEST() [4/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeDictionary   
)

Definition at line 238 of file flutter_standard_codec_unittest.mm.

238 {
239 NSDictionary* value =
240 @{@"a" : @3.14,
241 @"b" : @47,
242 [NSNull null] : [NSNull null],
243 @3.14 : @[ @"nested" ]};
245}

◆ TEST() [5/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeFloat32   
)

Definition at line 192 of file flutter_standard_codec_unittest.mm.

192 {
193 uint8_t bytes[16] = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194 0x00, 0x00, 0x00, 0x60, 0xfb, 0x21, 0x09, 0x40};
195 CheckEncodeDecode(@3.1415927f, [NSData dataWithBytes:bytes length:16]);
196}

◆ TEST() [6/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeFloat32Array   
)

Definition at line 278 of file flutter_standard_codec_unittest.mm.

278 {
279 uint8_t bytes[8] = {0xd8, 0x0f, 0x49, 0x40, 0x00, 0x00, 0x7a, 0x44};
280 NSData* data = [NSData dataWithBytes:bytes length:8];
283}

◆ TEST() [7/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeFloat64   
)

Definition at line 198 of file flutter_standard_codec_unittest.mm.

198 {
199 uint8_t bytes[16] = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40};
201 CheckEncodeDecode(@3.14159265358979311599796346854, [NSData dataWithBytes:bytes length:16]);
202}

◆ TEST() [8/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeFloat64Array   
)

Definition at line 285 of file flutter_standard_codec_unittest.mm.

285 {
286 uint8_t bytes[16] = {0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff,
287 0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff};
288 NSData* data = [NSData dataWithBytes:bytes length:16];
291}

◆ TEST() [9/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeIndirectString   
)

Definition at line 220 of file flutter_standard_codec_unittest.mm.

220 {
221 // This test ensures that an indirect NSString, whose internal string buffer
222 // can't be simply returned by `CFStringGetCStringPtr`, can be encoded without
223 // violating the memory sanitizer. This test only works with `--asan` flag.
224 // See https://github.com/flutter/flutter/issues/142101
225 uint8_t bytes[7] = {0x07, 0x05, 0x68, 0xe2, 0x98, 0xba, 0x77};
226 NSString* target = @"h\u263Aw";
227 // Ensures that this is an indirect string so that this test makes sense.
228 ASSERT_TRUE(CFStringGetCStringPtr((__bridge CFStringRef)target, kCFStringEncodingUTF8) ==
229 nullptr);
230 CheckEncodeDecode(target, [NSData dataWithBytes:bytes length:7]);
231}
uint32_t * target

◆ TEST() [10/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeInt32Array   
)

Definition at line 264 of file flutter_standard_codec_unittest.mm.

264 {
265 uint8_t bytes[8] = {0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff};
266 NSData* data = [NSData dataWithBytes:bytes length:8];
269}

◆ TEST() [11/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeInt64Array   
)

Definition at line 271 of file flutter_standard_codec_unittest.mm.

271 {
272 uint8_t bytes[8] = {0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff};
273 NSData* data = [NSData dataWithBytes:bytes length:8];
276}

◆ TEST() [12/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeNil   
)

Definition at line 125 of file flutter_standard_codec_unittest.mm.

125 {
126 CheckEncodeDecode(nil, nil);
127}

◆ TEST() [13/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeNo   
)

Definition at line 139 of file flutter_standard_codec_unittest.mm.

139 {
140 uint8_t bytes[1] = {0x02};
141 CheckEncodeDecode(@NO, [NSData dataWithBytes:bytes length:1]);
142}

◆ TEST() [14/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeNSData   
)

Definition at line 254 of file flutter_standard_codec_unittest.mm.

254 {
256 uint8_t bytes[4] = {0xBA, 0x5E, 0xBA, 0x11};
257 NSData* data = [NSData dataWithBytes:bytes length:4];
258 FlutterStandardTypedData* standardData = [FlutterStandardTypedData typedDataWithBytes:data];
259
260 NSData* encoded = [codec encode:data];
261 ASSERT_TRUE([encoded isEqual:[codec encode:standardData]]);
262}

◆ TEST() [15/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeNSNull   
)

Definition at line 129 of file flutter_standard_codec_unittest.mm.

129 {
130 uint8_t bytes[1] = {0x00};
131 CheckEncodeDecode([NSNull null], [NSData dataWithBytes:bytes length:1]);
132}

◆ TEST() [16/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeSInt16   
)

Definition at line 176 of file flutter_standard_codec_unittest.mm.

176 {
177 uint8_t bytes[5] = {0x03, 0xdc, 0xfe, 0xff, 0xff};
178 SInt16 value = 0xfedc;
179 CheckEncodeDecode(@(value), [NSData dataWithBytes:bytes length:5]);
180}

◆ TEST() [17/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeSInt32   
)

Definition at line 182 of file flutter_standard_codec_unittest.mm.

182 {
183 uint8_t bytes[5] = {0x03, 0x78, 0x56, 0x34, 0x12};
184 CheckEncodeDecode(@(0x12345678), [NSData dataWithBytes:bytes length:5]);
185}

◆ TEST() [18/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeSInt64   
)

Definition at line 187 of file flutter_standard_codec_unittest.mm.

187 {
188 uint8_t bytes[9] = {0x04, 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12};
189 CheckEncodeDecode(@(0x1234567890abcdef), [NSData dataWithBytes:bytes length:9]);
190}

◆ TEST() [19/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeSInt8   
)

Definition at line 170 of file flutter_standard_codec_unittest.mm.

170 {
171 uint8_t bytes[5] = {0x03, 0xfe, 0xff, 0xff, 0xff};
172 SInt8 value = 0xfe;
173 CheckEncodeDecode(@(value), [NSData dataWithBytes:bytes length:5]);
174}

◆ TEST() [20/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeString   
)

Definition at line 204 of file flutter_standard_codec_unittest.mm.

204 {
205 uint8_t bytes[13] = {0x07, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
206 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64};
207 CheckEncodeDecode(@"hello world", [NSData dataWithBytes:bytes length:13]);
208}

◆ TEST() [21/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeStringWithNonAsciiCodePoint   
)

Definition at line 210 of file flutter_standard_codec_unittest.mm.

210 {
211 uint8_t bytes[7] = {0x07, 0x05, 0x68, 0xe2, 0x98, 0xba, 0x77};
212 CheckEncodeDecode(@"h\u263Aw", [NSData dataWithBytes:bytes length:7]);
213}

◆ TEST() [22/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeStringWithNonBMPCodePoint   
)

Definition at line 215 of file flutter_standard_codec_unittest.mm.

215 {
216 uint8_t bytes[8] = {0x07, 0x06, 0x68, 0xf0, 0x9f, 0x98, 0x82, 0x77};
217 CheckEncodeDecode(@"h\U0001F602w", [NSData dataWithBytes:bytes length:8]);
218}

◆ TEST() [23/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeUInt16   
)

Definition at line 150 of file flutter_standard_codec_unittest.mm.

150 {
151 uint8_t bytes[5] = {0x03, 0xdc, 0xfe, 0x00, 0x00};
152 UInt16 value = 0xfedc;
153 CheckEncodeDecode(@(value), [NSData dataWithBytes:bytes length:5]);
154}

◆ TEST() [24/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeUInt32   
)

Definition at line 156 of file flutter_standard_codec_unittest.mm.

156 {
157 uint8_t bytes[9] = {0x04, 0x09, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00};
158 UInt32 value = 0xfedcba09;
159 CheckEncodeDecode(@(value), [NSData dataWithBytes:bytes length:9]);
160}

◆ TEST() [25/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeUInt8   
)

Definition at line 144 of file flutter_standard_codec_unittest.mm.

144 {
145 uint8_t bytes[5] = {0x03, 0xfe, 0x00, 0x00, 0x00};
146 UInt8 value = 0xfe;
147 CheckEncodeDecode(@(value), [NSData dataWithBytes:bytes length:5]);
148}

◆ TEST() [26/35]

TEST ( FlutterStandardCodec  ,
CanEncodeAndDecodeYes   
)

Definition at line 134 of file flutter_standard_codec_unittest.mm.

134 {
135 uint8_t bytes[1] = {0x01};
136 CheckEncodeDecode(@YES, [NSData dataWithBytes:bytes length:1]);
137}

◆ TEST() [27/35]

TEST ( FlutterStandardCodec  ,
CanEncodeUInt64   
)

Definition at line 162 of file flutter_standard_codec_unittest.mm.

162 {
164 UInt64 u64 = 0xfffffffffffffffa;
165 uint8_t bytes[9] = {0x04, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
166 NSData* encoded = [codec encode:@(u64)];
167 ASSERT_TRUE([encoded isEqual:[NSData dataWithBytes:bytes length:9]]);
168}

◆ TEST() [28/35]

TEST ( FlutterStandardCodec  ,
HandlesErrorEnvelopes   
)

Definition at line 341 of file flutter_standard_codec_unittest.mm.

341 {
343 NSDictionary* details = @{@"a" : @42, @42 : @"a"};
344 FlutterError* error = [FlutterError errorWithCode:@"errorCode"
345 message:@"something failed"
346 details:details];
347 NSData* encoded = [codec encodeErrorEnvelope:error];
348 id decoded = [codec decodeEnvelope:encoded];
349 ASSERT_TRUE([decoded isEqual:error]);
350}
const uint8_t uint32_t uint32_t GError ** error
Win32Message message

◆ TEST() [29/35]

TEST ( FlutterStandardCodec  ,
HandlesMethodCallsWithArgumentList   
)

Definition at line 309 of file flutter_standard_codec_unittest.mm.

309 {
311 NSArray* arguments = @[ @42, @"world" ];
312 FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"hello"
313 arguments:arguments];
314 NSData* encoded = [codec encodeMethodCall:call];
315 FlutterMethodCall* decoded = [codec decodeMethodCall:encoded];
316 ASSERT_TRUE([decoded isEqual:call]);
317}
def call(args)
Definition: dom.py:159

◆ TEST() [30/35]

TEST ( FlutterStandardCodec  ,
HandlesMethodCallsWithNilArguments   
)

Definition at line 293 of file flutter_standard_codec_unittest.mm.

293 {
295 FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"hello" arguments:nil];
296 NSData* encoded = [codec encodeMethodCall:call];
297 FlutterMethodCall* decoded = [codec decodeMethodCall:encoded];
298 ASSERT_TRUE([decoded isEqual:call]);
299}

◆ TEST() [31/35]

TEST ( FlutterStandardCodec  ,
HandlesMethodCallsWithSingleArgument   
)

Definition at line 301 of file flutter_standard_codec_unittest.mm.

301 {
303 FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"hello" arguments:@42];
304 NSData* encoded = [codec encodeMethodCall:call];
305 FlutterMethodCall* decoded = [codec decodeMethodCall:encoded];
306 ASSERT_TRUE([decoded isEqual:call]);
307}

◆ TEST() [32/35]

TEST ( FlutterStandardCodec  ,
HandlesSubclasses   
)

Definition at line 352 of file flutter_standard_codec_unittest.mm.

352 {
353 ExtendedReaderWriter* extendedReaderWriter = [[ExtendedReaderWriter alloc] init];
355 [FlutterStandardMessageCodec codecWithReaderWriter:extendedReaderWriter];
356 Pair* pair = [[Pair alloc] initWithLeft:@1 right:@2];
357 NSData* encoded = [codec encode:pair];
358 Pair* decoded = [codec decode:encoded];
359 ASSERT_TRUE([pair.left isEqual:decoded.left]);
360 ASSERT_TRUE([pair.right isEqual:decoded.right]);
361}
static bool right(const SkPoint &p0, const SkPoint &p1)
static bool init()

◆ TEST() [33/35]

TEST ( FlutterStandardCodec  ,
HandlesSuccessEnvelopesWithNilResult   
)

Definition at line 319 of file flutter_standard_codec_unittest.mm.

319 {
321 NSData* encoded = [codec encodeSuccessEnvelope:nil];
322 id decoded = [codec decodeEnvelope:encoded];
323 ASSERT_TRUE(decoded == nil);
324}

◆ TEST() [34/35]

TEST ( FlutterStandardCodec  ,
HandlesSuccessEnvelopesWithResultMap   
)

Definition at line 333 of file flutter_standard_codec_unittest.mm.

333 {
335 NSDictionary* result = @{@"a" : @42, @42 : @"a"};
336 NSData* encoded = [codec encodeSuccessEnvelope:result];
337 id decoded = [codec decodeEnvelope:encoded];
338 ASSERT_TRUE([decoded isEqual:result]);
339}
GAsyncResult * result

◆ TEST() [35/35]

TEST ( FlutterStandardCodec  ,
HandlesSuccessEnvelopesWithSingleResult   
)

Definition at line 326 of file flutter_standard_codec_unittest.mm.

326 {
328 NSData* encoded = [codec encodeSuccessEnvelope:@42];
329 id decoded = [codec decodeEnvelope:encoded];
330 ASSERT_TRUE([decoded isEqual:@42]);
331}

Variable Documentation

◆ kDATE

const UInt8 kDATE = 128
static

Definition at line 30 of file flutter_standard_codec_unittest.mm.

◆ kPAIR

const UInt8 kPAIR = 129
static

Definition at line 31 of file flutter_standard_codec_unittest.mm.