Fix incorrectly inserting Float32List in the wrong location in encodable_value. (flutter/engine#26537)
This commit is contained in:
@@ -283,4 +283,51 @@ TEST(EncodableValueTest, DeepCopy) {
|
||||
EXPECT_EQ(std::get<std::string>(innermost_map[EncodableValue("a")]), "b");
|
||||
}
|
||||
|
||||
// Simple class for testing custom encodable values
|
||||
class TestCustomValue {
|
||||
public:
|
||||
TestCustomValue() : x_(0), y_(0) {}
|
||||
TestCustomValue(int x, int y) : x_(x), y_(y) {}
|
||||
~TestCustomValue() = default;
|
||||
|
||||
int x() const { return x_; }
|
||||
int y() const { return y_; }
|
||||
|
||||
private:
|
||||
int x_;
|
||||
int y_;
|
||||
};
|
||||
|
||||
TEST(EncodableValueTest, TypeIndexesCorrect) {
|
||||
// Null
|
||||
EXPECT_EQ(EncodableValue().index(), 0u);
|
||||
// Bool
|
||||
EXPECT_EQ(EncodableValue(true).index(), 1u);
|
||||
// Int32
|
||||
EXPECT_EQ(EncodableValue(100).index(), 2u);
|
||||
// Int64
|
||||
EXPECT_EQ(EncodableValue(INT64_C(100)).index(), 3u);
|
||||
// Double
|
||||
EXPECT_EQ(EncodableValue(7.0).index(), 4u);
|
||||
// String
|
||||
EXPECT_EQ(EncodableValue("one").index(), 5u);
|
||||
// ByteList
|
||||
EXPECT_EQ(EncodableValue(std::vector<uint8_t>()).index(), 6u);
|
||||
// IntList
|
||||
EXPECT_EQ(EncodableValue(std::vector<int32_t>()).index(), 7u);
|
||||
// LongList
|
||||
EXPECT_EQ(EncodableValue(std::vector<int64_t>()).index(), 8u);
|
||||
// DoubleList
|
||||
EXPECT_EQ(EncodableValue(std::vector<double>()).index(), 9u);
|
||||
// List
|
||||
EXPECT_EQ(EncodableValue(EncodableList()).index(), 10u);
|
||||
// Map
|
||||
EXPECT_EQ(EncodableValue(EncodableMap()).index(), 11u);
|
||||
// Custom type
|
||||
TestCustomValue customValue;
|
||||
EXPECT_EQ(((EncodableValue)CustomEncodableValue(customValue)).index(), 12u);
|
||||
// FloatList
|
||||
EXPECT_EQ(EncodableValue(std::vector<float>()).index(), 13u);
|
||||
} // namespace flutter
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -110,8 +110,8 @@ using EncodableValueVariant = std::variant<std::monostate,
|
||||
std::vector<double>,
|
||||
EncodableList,
|
||||
EncodableMap,
|
||||
std::vector<float>,
|
||||
CustomEncodableValue>;
|
||||
CustomEncodableValue,
|
||||
std::vector<float>>;
|
||||
} // namespace internal
|
||||
|
||||
// An object that can contain any value or collection type supported by
|
||||
@@ -156,10 +156,10 @@ using EncodableValueVariant = std::variant<std::monostate,
|
||||
// std::vector<uint8_t> -> Uint8List
|
||||
// std::vector<int32_t> -> Int32List
|
||||
// std::vector<int64_t> -> Int64List
|
||||
// std::vector<float> -> Float32List
|
||||
// std::vector<double> -> Float64List
|
||||
// EncodableList -> List
|
||||
// EncodableMap -> Map
|
||||
// std::vector<float> -> Float32List
|
||||
class EncodableValue : public internal::EncodableValueVariant {
|
||||
public:
|
||||
// Rely on std::variant for most of the constructors/operators.
|
||||
|
||||
@@ -71,7 +71,7 @@ EncodedType EncodedTypeForValue(const EncodableValue& value) {
|
||||
return EncodedType::kList;
|
||||
case 11:
|
||||
return EncodedType::kMap;
|
||||
case 12:
|
||||
case 13:
|
||||
return EncodedType::kFloat32List;
|
||||
}
|
||||
assert(false);
|
||||
@@ -153,15 +153,15 @@ void StandardCodecSerializer::WriteValue(const EncodableValue& value,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 12: {
|
||||
WriteVector(std::get<std::vector<float>>(value), stream);
|
||||
break;
|
||||
}
|
||||
case 13:
|
||||
case 12:
|
||||
std::cerr
|
||||
<< "Unhandled custom type in StandardCodecSerializer::WriteValue. "
|
||||
<< "Custom types require codec extensions." << std::endl;
|
||||
break;
|
||||
case 13: {
|
||||
WriteVector(std::get<std::vector<float>>(value), stream);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ TEST(StandardMessageCodec, CanEncodeAndDecodeInt64Array) {
|
||||
CheckEncodeDecode(value, bytes);
|
||||
}
|
||||
|
||||
TEST(StandradMessageCodec, CanEncodeAndDecodeFloat32Array) {
|
||||
TEST(StandardMessageCodec, CanEncodeAndDecodeFloat32Array) {
|
||||
std::vector<uint8_t> bytes = {0x0e, 0x02, 0x00, 0x00, 0xd8, 0x0f,
|
||||
0x49, 0x40, 0x00, 0x00, 0x7a, 0x44};
|
||||
EncodableValue value(std::vector<float>{3.1415920257568359375f, 1000.0f});
|
||||
|
||||
Reference in New Issue
Block a user