diff --git a/shell/platform/common/cpp/client_wrapper/BUILD.gn b/shell/platform/common/cpp/client_wrapper/BUILD.gn index 331a0c97d3509a8b89c3668f86d9c03bda179c1c..e1adbbaf3e510c3dcc8e48ebd79a8cc5474c5a97 100644 --- a/shell/platform/common/cpp/client_wrapper/BUILD.gn +++ b/shell/platform/common/cpp/client_wrapper/BUILD.gn @@ -19,6 +19,23 @@ source_set("client_wrapper") { [ "//flutter/shell/platform/common/cpp:relative_flutter_library_headers" ] } +# Temporary test for the legacy EncodableValue implementation. Remove once the +# legacy version is removed. +source_set("client_wrapper_legacy_encodable_value") { + sources = core_cpp_client_wrapper_sources + public = core_cpp_client_wrapper_includes + + deps = [ "//flutter/shell/platform/common/cpp:common_cpp_library_headers" ] + + configs += + [ "//flutter/shell/platform/common/cpp:desktop_library_implementation" ] + + defines = [ "USE_LEGACY_ENCODABLE_VALUE" ] + + public_configs = + [ "//flutter/shell/platform/common/cpp:relative_flutter_library_headers" ] +} + source_set("client_wrapper_library_stubs") { sources = [ "testing/stub_flutter_api.cc", @@ -56,6 +73,9 @@ executable("client_wrapper_unittests") { ":client_wrapper", ":client_wrapper_fixtures", ":client_wrapper_library_stubs", + + # Build the legacy version as well as a sanity check. + ":client_wrapper_unittests_legacy_encodable_value", "//flutter/testing", # TODO(chunhtai): Consider refactoring flutter_root/testing so that there's a testing @@ -66,3 +86,31 @@ executable("client_wrapper_unittests") { defines = [ "FLUTTER_DESKTOP_LIBRARY" ] } + +# Ensures that the legacy EncodableValue codepath still compiles. +executable("client_wrapper_unittests_legacy_encodable_value") { + testonly = true + + sources = [ + "encodable_value_unittests.cc", + "standard_message_codec_unittests.cc", + "testing/test_codec_extensions.h", + ] + + deps = [ + ":client_wrapper_fixtures", + ":client_wrapper_legacy_encodable_value", + ":client_wrapper_library_stubs", + "//flutter/testing", + + # TODO(chunhtai): Consider refactoring flutter_root/testing so that there's a testing + # target that doesn't require a Dart runtime to be linked in. + # https://github.com/flutter/flutter/issues/41414. + "//third_party/dart/runtime:libdart_jit", + ] + + defines = [ + "FLUTTER_DESKTOP_LIBRARY", + "USE_LEGACY_ENCODABLE_VALUE", + ] +} diff --git a/shell/platform/common/cpp/client_wrapper/encodable_value_unittests.cc b/shell/platform/common/cpp/client_wrapper/encodable_value_unittests.cc index 17be80b6aeeb4dbbc3828578327731e2595e9c07..e64beae8b3a8f8fbe5005a47b94a64967b2a37d8 100644 --- a/shell/platform/common/cpp/client_wrapper/encodable_value_unittests.cc +++ b/shell/platform/common/cpp/client_wrapper/encodable_value_unittests.cc @@ -15,6 +15,8 @@ TEST(EncodableValueTest, Null) { value.IsNull(); } +#ifndef USE_LEGACY_ENCODABLE_VALUE + TEST(EncodableValueTest, Bool) { EncodableValue value(false); @@ -280,4 +282,6 @@ TEST(EncodableValueTest, DeepCopy) { EXPECT_EQ(std::get(innermost_map[EncodableValue("a")]), "b"); } +#endif // !LEGACY_ENCODABLE_VALUE + } // namespace flutter diff --git a/shell/platform/common/cpp/client_wrapper/standard_codec.cc b/shell/platform/common/cpp/client_wrapper/standard_codec.cc index 6ba13b48a67e19a946bcb57fa133665f960b67fa..a17845750d8ca49d20e00ef6110c8f9bb4ee135b 100644 --- a/shell/platform/common/cpp/client_wrapper/standard_codec.cc +++ b/shell/platform/common/cpp/client_wrapper/standard_codec.cc @@ -132,14 +132,14 @@ void StandardCodecSerializer::WriteValue(const EncodableValue& value, // Null and bool are encoded directly in the type. break; case EncodableValue::Type::kInt: - stream->WriteInt32(std::get(value)); + stream->WriteInt32(value.IntValue()); break; - case case EncodableValue::Type::kLong: - stream->WriteInt64(std::get(value)); + case EncodableValue::Type::kLong: + stream->WriteInt64(value.LongValue()); break; case EncodableValue::Type::kDouble: stream->WriteAlignment(8); - stream->WriteDouble(std::get(value)); + stream->WriteDouble(value.DoubleValue()); break; case EncodableValue::Type::kString: { const auto& string_value = value.StringValue(); diff --git a/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc b/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc index 3d8c077133eab1b21db42add63daf724959840b2..03459dc75ddfa3d095998d99ae7ceac0c142fddf 100644 --- a/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc +++ b/shell/platform/common/cpp/client_wrapper/standard_message_codec_unittests.cc @@ -6,9 +6,12 @@ #include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h" -#include "flutter/shell/platform/common/cpp/client_wrapper/testing/test_codec_extensions.h" #include "gtest/gtest.h" +#ifndef USE_LEGACY_ENCODABLE_VALUE +#include "flutter/shell/platform/common/cpp/client_wrapper/testing/test_codec_extensions.h" +#endif + namespace flutter { // Validates round-trip encoding and decoding of |value|, and checks that the @@ -30,11 +33,21 @@ static void CheckEncodeDecode( EXPECT_EQ(*encoded, expected_encoding); auto decoded = codec.DecodeMessage(*encoded); +#ifdef USE_LEGACY_ENCODABLE_VALUE + // Full equality isn't implemented for the legacy path; just do a sanity test + // of basic types. + if (value.IsNull() || value.IsBool() || value.IsInt() || value.IsLong() || + value.IsDouble() || value.IsString()) { + EXPECT_FALSE(value < *decoded); + EXPECT_FALSE(*decoded < value); + } +#else if (custom_comparator) { EXPECT_TRUE(custom_comparator(value, *decoded)); } else { EXPECT_EQ(value, *decoded); } +#endif } // Validates round-trip encoding and decoding of |value|, and checks that the @@ -46,7 +59,11 @@ static void CheckEncodeDecodeWithEncodePrefix( const EncodableValue& value, const std::vector& expected_encoding_prefix, size_t expected_encoding_length) { +#ifdef USE_LEGACY_ENCODABLE_VALUE + EXPECT_TRUE(value.IsMap()); +#else EXPECT_TRUE(std::holds_alternative(value)); +#endif const StandardMessageCodec& codec = StandardMessageCodec::GetInstance(); auto encoded = codec.EncodeMessage(value); ASSERT_TRUE(encoded); @@ -58,7 +75,12 @@ static void CheckEncodeDecodeWithEncodePrefix( expected_encoding_prefix.begin(), expected_encoding_prefix.end())); auto decoded = codec.DecodeMessage(*encoded); + +#ifdef USE_LEGACY_ENCODABLE_VALUE + EXPECT_NE(decoded, nullptr); +#else EXPECT_EQ(value, *decoded); +#endif } TEST(StandardMessageCodec, CanEncodeAndDecodeNull) { @@ -182,6 +204,8 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeFloat64Array) { CheckEncodeDecode(value, bytes); } +#ifndef USE_LEGACY_ENCODABLE_VALUE + TEST(StandardMessageCodec, CanEncodeAndDecodeSimpleCustomType) { std::vector bytes = {0x80, 0x09, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}; @@ -217,4 +241,6 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeVariableLengthCustomType) { some_data_comparator); } +#endif // !USE_LEGACY_ENCODABLE_VALUE + } // namespace flutter