10 #include "flutter/shell/platform/common/client_wrapper/testing/test_codec_extensions.h"
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
18 class MockStandardCodecSerializer :
public StandardCodecSerializer {
22 (
const EncodableValue& value, ByteStreamWriter* stream),
24 MOCK_METHOD(EncodableValue,
26 (uint8_t type, ByteStreamReader* stream),
39 const std::vector<uint8_t>& expected_encoding,
42 custom_comparator =
nullptr) {
47 EXPECT_EQ(*encoded, expected_encoding);
50 if (custom_comparator) {
51 EXPECT_TRUE(custom_comparator(value, *decoded));
53 EXPECT_EQ(value, *decoded);
64 const std::vector<uint8_t>& expected_encoding_prefix,
65 size_t expected_encoding_length) {
66 EXPECT_TRUE(std::holds_alternative<EncodableMap>(value));
71 EXPECT_EQ(encoded->size(), expected_encoding_length);
72 ASSERT_GT(encoded->size(), expected_encoding_prefix.size());
73 EXPECT_TRUE(std::equal(
74 encoded->begin(), encoded->begin() + expected_encoding_prefix.size(),
75 expected_encoding_prefix.begin(), expected_encoding_prefix.end()));
79 EXPECT_EQ(value, *decoded);
87 EXPECT_EQ(&codec_a, &codec_b);
91 std::vector<uint8_t> bytes = {0x00};
96 std::vector<uint8_t> bytes = {};
97 const MockStandardCodecSerializer serializer;
104 EXPECT_CALL(serializer, ReadValueOfType(::testing::_, ::testing::_)).Times(0);
108 std::vector<uint8_t> bytes = {0x01};
113 std::vector<uint8_t> bytes = {0x02};
118 std::vector<uint8_t> bytes = {0x03, 0x78, 0x56, 0x34, 0x12};
123 std::vector<uint8_t> bytes = {0x04, 0xef, 0xcd, 0xab, 0x90,
124 0x78, 0x56, 0x34, 0x12};
129 std::vector<uint8_t> bytes = {0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40};
135 std::vector<uint8_t> bytes = {0x07, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
136 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64};
141 std::vector<uint8_t> bytes = {0x07, 0x05, 0x68, 0xe2, 0x98, 0xba, 0x77};
146 std::vector<uint8_t> bytes = {0x07, 0x06, 0x68, 0xf0, 0x9f, 0x98, 0x82, 0x77};
151 std::vector<uint8_t> bytes = {0x07, 0x00};
156 std::vector<uint8_t> bytes = {
157 0x0c, 0x05, 0x00, 0x07, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x06,
158 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x85, 0xeb, 0x51, 0xb8, 0x1e,
159 0x09, 0x40, 0x03, 0x2f, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x03, 0x2a,
160 0x00, 0x00, 0x00, 0x07, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64,
176 std::vector<uint8_t> bytes = {0x0c, 0x00};
181 std::vector<uint8_t> bytes_prefix = {0x0d, 0x04};
194 std::vector<uint8_t> bytes = {0x08, 0x04, 0xba, 0x5e, 0xba, 0x11};
195 EncodableValue value(std::vector<uint8_t>{0xba, 0x5e, 0xba, 0x11});
200 std::vector<uint8_t> bytes = {0x09, 0x03, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12,
201 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
207 std::vector<uint8_t> bytes = {0x0a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
208 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12,
209 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
210 EncodableValue value(std::vector<int64_t>{0x1234567890abcdef, -1});
215 std::vector<uint8_t> bytes = {0x0e, 0x02, 0x00, 0x00, 0xd8, 0x0f,
216 0x49, 0x40, 0x00, 0x00, 0x7a, 0x44};
217 EncodableValue value(std::vector<float>{3.1415920257568359375f, 1000.0f});
222 std::vector<uint8_t> bytes = {0x0b, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40,
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x8f, 0x40};
226 std::vector<double>{3.14159265358979311599796346854, 1000.0});
231 std::vector<uint8_t> bytes = {0x80, 0x09, 0x00, 0x00, 0x00,
232 0x10, 0x00, 0x00, 0x00};
234 const Point& a_point =
235 std::any_cast<Point>(std::get<CustomEncodableValue>(a));
236 const Point& b_point =
237 std::any_cast<Point>(std::get<CustomEncodableValue>(b));
238 return a_point == b_point;
241 &PointExtensionSerializer::GetInstance(), point_comparator);
245 std::vector<uint8_t> bytes = {
247 0x06, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
249 0x74, 0x65, 0x73, 0x74
253 const SomeData& data_a =
254 std::any_cast<SomeData>(std::get<CustomEncodableValue>(a));
255 const SomeData& data_b =
256 std::any_cast<SomeData>(std::get<CustomEncodableValue>(b));
257 return data_a.data() == data_b.data() && data_a.label() == data_b.label();
260 SomeData(
"test", {0x00, 0x01, 0x02, 0x03, 0x04, 0x05})),
261 bytes, &SomeDataExtensionSerializer::GetInstance(),
262 some_data_comparator);