5#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
7#include "gtest/gtest.h"
13 ASSERT_TRUE([codec
encode:nil] == nil);
14 ASSERT_TRUE([codec
decode:nil] == nil);
19 ASSERT_TRUE([[codec
encode:
@""] isEqualTo:[NSData
data]]);
20 ASSERT_TRUE([[codec
decode:[NSData
data]] isEqualTo:
@""]);
24 NSString*
value =
@"hello world";
27 NSString* decoded = [codec
decode:encoded];
28 ASSERT_TRUE([
value isEqualTo:decoded]);
32 NSString*
value =
@"hello \u263A world";
35 NSString* decoded = [codec
decode:encoded];
36 ASSERT_TRUE([
value isEqualTo:decoded]);
40 NSString*
value =
@"hello \U0001F602 world";
43 NSString* decoded = [codec
decode:encoded];
44 ASSERT_TRUE([
value isEqualTo:decoded]);
47TEST(FlutterJSONCodec, ThrowsOnInvalidEncode) {
48 NSString*
value = [[NSString alloc] initWithBytes:
"\xdf\xff"
50 encoding:NSUTF16StringEncoding];
52 EXPECT_EXIT([codec
encode:
value], testing::KilledBySignal(SIGABRT),
"failed to convert to UTF8");
55TEST(FlutterJSONCodec, CanDecodeZeroLength) {
57 ASSERT_TRUE([codec
decode:[NSData
data]] == nil);
60TEST(FlutterJSONCodec, ThrowsOnInvalidDecode) {
61 NSString*
value =
@"{{{";
64 testing::KilledBySignal(SIGABRT),
"No string key for value in object around line 1");
67TEST(FlutterJSONCodec, CanEncodeAndDecodeNil) {
69 ASSERT_TRUE([codec
encode:nil] == nil);
70 ASSERT_TRUE([codec
decode:nil] == nil);
73TEST(FlutterJSONCodec, CanEncodeAndDecodeArray) {
74 NSArray*
value = @[ [NSNull null],
@"hello", @3.14, @47, @{
@"a" :
@"nested"} ];
77 NSArray* decoded = [codec
decode:encoded];
78 ASSERT_TRUE([
value isEqualTo:decoded]);
81TEST(FlutterJSONCodec, CanEncodeAndDecodeDictionary) {
82 NSDictionary*
value = @{
@"a" : @3.14,
@"b" : @47,
@"c" : [NSNull null],
@"d" : @[
@"nested" ]};
85 NSDictionary* decoded = [codec
decode:encoded];
86 ASSERT_TRUE([
value isEqualTo:decoded]);
static void encode(uint8_t output[16], const uint32_t input[4])
FLUTTER_ASSERT_ARC TEST(FlutterStringCodec, CanEncodeAndDecodeNil)
static DecodeResult decode(std::string path)
std::shared_ptr< const fml::Mapping > data