| Flutter macOS Embedder |

json_message_codec_unittests.cc
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 #include "flutter/shell/platform/common/json_message_codec.h"
6
7 #include <limits>
8 #include <map>
9 #include <vector>
10
11 #include "gtest/gtest.h"
12
13 namespace flutter {
14
15 namespace {
16
17 // Validates round-trip encoding and decoding of |value|.
18 static void CheckEncodeDecode(const rapidjson::Document& value) {
19 const JsonMessageCodec& codec = JsonMessageCodec::GetInstance();
20 auto encoded = codec.EncodeMessage(value);
21 ASSERT_TRUE(encoded);
22 auto decoded = codec.DecodeMessage(*encoded);
23 EXPECT_EQ(value, *decoded);
24 }
25
26 } // namespace
27
28 // Tests that a JSON document with various data types round-trips correctly.
29 TEST(JsonMessageCodec, EncodeDecode) {
30 // NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
31 rapidjson::Document array(rapidjson::kArrayType);
32 auto& allocator = array.GetAllocator();
33
34 array.PushBack("string", allocator);
35
36 rapidjson::Value map(rapidjson::kObjectType);
37 map.AddMember("a", -7, allocator);
38 map.AddMember("b", std::numeric_limits<int>::max(), allocator);
39 map.AddMember("c", 3.14159, allocator);
40 map.AddMember("d", true, allocator);
41 map.AddMember("e", rapidjson::Value(), allocator);
42 array.PushBack(map, allocator);
43
44 CheckEncodeDecode(array);
45 }
46
47 } // namespace flutter
flutter::TEST
TEST(BasicMessageChannelTest, Registration)
Definition: basic_message_channel_unittests.cc:58
flutter::JsonMessageCodec::GetInstance
static const JsonMessageCodec & GetInstance()
Definition: json_message_codec.cc:17
json_message_codec.h
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::JsonMessageCodec
Definition: json_message_codec.h:16
flutter::CheckEncodeDecode
static void CheckEncodeDecode(const EncodableValue &value, const std::vector< uint8_t > &expected_encoding, const StandardCodecSerializer *serializer=nullptr, const std::function< bool(const EncodableValue &a, const EncodableValue &b)> &custom_comparator=nullptr)
Definition: standard_message_codec_unittests.cc:37