Flutter Engine
The Flutter Engine
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
13namespace flutter {
14
15namespace {
16
17// Validates round-trip encoding and decoding of |value|.
18static 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.
29TEST(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
static const JsonMessageCodec & GetInstance()
uint8_t value
static float max(float r, float g, float b)
Definition: hsl.cpp:49
TEST(FrameTimingsRecorderTest, RecordVsync)
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)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680