WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-205902-20200114112945.patch (text/plain), 28.88 KB, created by
Takashi Komori
on 2020-01-13 18:33:01 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Takashi Komori
Created:
2020-01-13 18:33:01 PST
Size:
28.88 KB
patch
obsolete
>Subversion Revision: 254396 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 4351d74c8dda6c687c26637f034e0238ab42d301..05c8ea588d36e1adb7162a9e936bcef24cf16d53 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,31 @@ >+2020-01-13 Takashi Komori <Takashi.Komori@sony.com> >+ >+ KeyedDecoderGeneric crashes when it accesses data with non-existing key >+ https://bugs.webkit.org/show_bug.cgi?id=205902 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add null check function for KeyedDecoderGeneric. >+ >+ Test: TestWebKitAPI/Tests/WebCore/KeyedCodingGeneric.cpp >+ >+ * platform/generic/KeyedDecoderGeneric.cpp: >+ (WebCore::KeyedDecoderGeneric::Dictionary::get): >+ (WebCore::KeyedDecoderGeneric::getPointerFromDictionaryStack): >+ (WebCore::KeyedDecoderGeneric::decodeSimpleValue): >+ (WebCore::KeyedDecoderGeneric::decodeBytes): >+ (WebCore::KeyedDecoderGeneric::decodeBool): >+ (WebCore::KeyedDecoderGeneric::decodeUInt32): >+ (WebCore::KeyedDecoderGeneric::decodeUInt64): >+ (WebCore::KeyedDecoderGeneric::decodeInt32): >+ (WebCore::KeyedDecoderGeneric::decodeInt64): >+ (WebCore::KeyedDecoderGeneric::decodeFloat): >+ (WebCore::KeyedDecoderGeneric::decodeDouble): >+ (WebCore::KeyedDecoderGeneric::decodeString): >+ (WebCore::KeyedDecoderGeneric::beginObject): >+ (WebCore::KeyedDecoderGeneric::beginArray): >+ * platform/generic/KeyedDecoderGeneric.h: >+ > 2020-01-10 Zalan Bujtas <zalan@apple.com> > > [LFC] TableFormattingContext::layoutTableCellBox should take HorizontalConstraints >diff --git a/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp b/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp >index 0e5972321b5f73f572bd79658811f003a95ed492..bc57cb7e7b906d6c84efca09775d07adcdcf3c22 100644 >--- a/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp >+++ b/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp >@@ -42,7 +42,7 @@ public: > > template <typename T> > void add(const String& key, T&& value) { m_map.add(key, makeUnique<Node>(std::forward<T>(value))); } >- Node& get(const String& key) { return *m_map.get(key); } >+ Node* get(const String& key) { return m_map.get(key); } > > private: > HashMap<String, std::unique_ptr<Node>> m_map; >@@ -181,11 +181,35 @@ KeyedDecoderGeneric::KeyedDecoderGeneric(const uint8_t* data, size_t size) > m_arrayStack.removeLast(); > } > >+template<typename T> >+const T* KeyedDecoderGeneric::getPointerFromDictionaryStack(const String& key) >+{ >+ auto& dictionary = m_dictionaryStack.last(); >+ >+ auto node = dictionary->get(key); >+ if (!node) >+ return nullptr; >+ >+ return WTF::get_if<T>(*node); >+} >+ >+template<typename T> >+bool KeyedDecoderGeneric::decodeSimpleValue(const String& key, T& result) >+{ >+ auto value = getPointerFromDictionaryStack<T>(key); >+ if (!value) >+ return false; >+ >+ result = *value; >+ return true; >+} >+ > bool KeyedDecoderGeneric::decodeBytes(const String& key, const uint8_t*& data, size_t& size) > { >- auto* value = WTF::get_if<Vector<uint8_t>>(m_dictionaryStack.last()->get(key)); >+ auto value = getPointerFromDictionaryStack<Vector<uint8_t>>(key); > if (!value) > return false; >+ > data = value->data(); > size = value->size(); > return true; >@@ -193,81 +217,50 @@ bool KeyedDecoderGeneric::decodeBytes(const String& key, const uint8_t*& data, s > > bool KeyedDecoderGeneric::decodeBool(const String& key, bool& result) > { >- auto* value = WTF::get_if<bool>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::decodeUInt32(const String& key, uint32_t& result) > { >- auto* value = WTF::get_if<uint32_t>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::decodeUInt64(const String& key, uint64_t& result) > { >- auto* value = WTF::get_if<uint64_t>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::decodeInt32(const String& key, int32_t& result) > { >- auto* value = WTF::get_if<int32_t>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::decodeInt64(const String& key, int64_t& result) > { >- auto* value = WTF::get_if<int64_t>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::decodeFloat(const String& key, float& result) > { >- auto* value = WTF::get_if<float>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::decodeDouble(const String& key, double& result) > { >- auto* value = WTF::get_if<double>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::decodeString(const String& key, String& result) > { >- auto* value = WTF::get_if<String>(m_dictionaryStack.last()->get(key)); >- if (!value) >- return false; >- result = *value; >- return true; >+ return decodeSimpleValue(key, result); > } > > bool KeyedDecoderGeneric::beginObject(const String& key) > { >- auto* value = WTF::get_if<std::unique_ptr<Dictionary>>(m_dictionaryStack.last()->get(key)); >+ auto value = getPointerFromDictionaryStack<std::unique_ptr<Dictionary>>(key); > if (!value) > return false; >+ > m_dictionaryStack.append(value->get()); > return true; > } >@@ -279,9 +272,10 @@ void KeyedDecoderGeneric::endObject() > > bool KeyedDecoderGeneric::beginArray(const String& key) > { >- auto* value = WTF::get_if<std::unique_ptr<Array>>(m_dictionaryStack.last()->get(key)); >+ auto value = getPointerFromDictionaryStack<std::unique_ptr<Array>>(key); > if (!value) > return false; >+ > m_arrayStack.append(value->get()); > m_arrayIndexStack.append(0); > return true; >diff --git a/Source/WebCore/platform/generic/KeyedDecoderGeneric.h b/Source/WebCore/platform/generic/KeyedDecoderGeneric.h >index 56a2f938a054b477caddde037971e5312f4e2dcb..19a299bdd92299d224098ab448cf2e35c9603d32 100644 >--- a/Source/WebCore/platform/generic/KeyedDecoderGeneric.h >+++ b/Source/WebCore/platform/generic/KeyedDecoderGeneric.h >@@ -55,6 +55,12 @@ private: > void endArrayElement() override; > void endArray() override; > >+ template<typename T> >+ const T* getPointerFromDictionaryStack(const String& key); >+ >+ template<typename T> >+ bool decodeSimpleValue(const String& key, T& result); >+ > std::unique_ptr<Dictionary> m_rootDictionary; > Vector<Dictionary*, 16> m_dictionaryStack; > Vector<Array*, 16> m_arrayStack; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index a526426dd62280369773a805ac74bcf402df0177..578886caaa9e7e467ee46c63d95de073fcabcd19 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,23 @@ >+2020-01-13 Takashi Komori <Takashi.Komori@sony.com> >+ >+ KeyedDecoderGeneric crashes when it accesses data with non-existing key >+ https://bugs.webkit.org/show_bug.cgi?id=205902 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/CMakeLists.txt: >+ * TestWebKitAPI/PlatformWin.cmake: >+ * TestWebKitAPI/Tests/WebCore/KeyedCoding.cpp: Added. >+ (TestWebKitAPI::checkDecodedBytes): >+ (TestWebKitAPI::TEST): >+ (TestWebKitAPI::testSimpleValueDecode): >+ (TestWebKitAPI::testSimpleValue): >+ (TestWebKitAPI::KeyedCodingTestObject::encode): >+ (TestWebKitAPI::KeyedCodingTestObject::decode): >+ (TestWebKitAPI::KeyedCodingTestObject::KeyedCodingTestObject): >+ (TestWebKitAPI::KeyedCodingTestObject::equals const): >+ (TestWebKitAPI::operator==): >+ > 2020-01-10 Myles C. Maxfield <mmaxfield@apple.com> > > REGRESSION(r185816): In the Hong Kong locale, navigator.language reports it's in the Taiwan locale >diff --git a/Tools/TestWebKitAPI/CMakeLists.txt b/Tools/TestWebKitAPI/CMakeLists.txt >index a57c73d87e3709b480590cd5256f12fd089f303a..97da060baded58facaacc8c777750a5c02aeca36 100644 >--- a/Tools/TestWebKitAPI/CMakeLists.txt >+++ b/Tools/TestWebKitAPI/CMakeLists.txt >@@ -138,6 +138,7 @@ if (ENABLE_WEBCORE) > Tests/WebCore/IntPoint.cpp > Tests/WebCore/IntRect.cpp > Tests/WebCore/IntSize.cpp >+ Tests/WebCore/KeyedCoding.cpp > Tests/WebCore/LayoutUnit.cpp > Tests/WebCore/MIMETypeRegistry.cpp > Tests/WebCore/ParsedContentRange.cpp >diff --git a/Tools/TestWebKitAPI/PlatformWin.cmake b/Tools/TestWebKitAPI/PlatformWin.cmake >index 349334826fa34db28ae2d8260fc5ae4d524dc0ef..5c407545848146f4d4570e55a1e85863698c8e5e 100644 >--- a/Tools/TestWebKitAPI/PlatformWin.cmake >+++ b/Tools/TestWebKitAPI/PlatformWin.cmake >@@ -62,9 +62,7 @@ if (${WTF_PLATFORM_WIN_CAIRO}) > ) > list(APPEND TestWebCore_SOURCES > Tests/WebCore/CryptoDigest.cpp >- > Tests/WebCore/curl/Cookies.cpp >- > Tests/WebCore/win/BitmapImage.cpp > ) > else () >diff --git a/Tools/TestWebKitAPI/Tests/WebCore/KeyedCoding.cpp b/Tools/TestWebKitAPI/Tests/WebCore/KeyedCoding.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..cda9b59f1d82db7355bf354f1c0cf174309f51ca >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebCore/KeyedCoding.cpp >@@ -0,0 +1,356 @@ >+/* >+ * Copyright (C) 2020 Sony Interactive Entertainment Inc. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+ >+#include <WebCore/KeyedCoding.h> >+#include <WebCore/SharedBuffer.h> >+#include <cstdint> >+#include <wtf/text/WTFString.h> >+ >+namespace TestWebKitAPI { >+ >+static bool checkDecodedBytes(const uint8_t* original, size_t originalSize, const uint8_t* decoded, size_t decodedSize) >+{ >+ if (originalSize != decodedSize) >+ return false; >+ >+ if (std::memcmp(original, decoded, originalSize)) >+ return false; >+ >+ return true; >+} >+ >+TEST(KeyedCoding, SetAndGetBytes) >+{ >+ const uint8_t data[] = { 0x00, 0x01, 0x02, 0x03, 0xde, 0xad, 0xbe, 0xef }; >+ const size_t dataLength = WTF_ARRAY_LENGTH(data); >+ const size_t dataLengthOne = 1; >+ const size_t dataLengthZero = 0; >+ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeBytes("data", data, dataLength); >+ encoder->encodeBytes("data-size0", data, dataLengthZero); >+ encoder->encodeBytes("data-size1", data, dataLengthOne); >+ auto encodedBuffer = encoder->finishEncoding(); >+ >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool success; >+ const uint8_t* buffer; >+ size_t size; >+ >+ success = decoder->decodeBytes("data", buffer, size); >+ EXPECT_TRUE(success); >+ EXPECT_EQ(dataLength, size); >+ EXPECT_TRUE(checkDecodedBytes(data, dataLength, buffer, size)); >+ >+ success = decoder->decodeBytes("data-size0", buffer, size); >+ EXPECT_TRUE(success); >+ EXPECT_EQ(dataLengthZero, size); >+ >+ success = decoder->decodeBytes("data-size1", buffer, size); >+ EXPECT_TRUE(success); >+ EXPECT_EQ(dataLengthOne, size); >+ EXPECT_TRUE(checkDecodedBytes(data, dataLengthOne, buffer, size)); >+} >+ >+template <typename EncodeValueType, typename DecodeValueType> typename std::enable_if<std::is_same<EncodeValueType, DecodeValueType>::value, bool>::type testSimpleValueDecode(bool decodeSuccess, EncodeValueType expected, DecodeValueType decoded) >+{ >+ return decodeSuccess && (expected == decoded); >+} >+ >+template <typename EncodeValueType, typename DecodeValueType> typename std::enable_if<!std::is_same<EncodeValueType, DecodeValueType>::value, bool>::type testSimpleValueDecode(bool decodeSuccess, EncodeValueType expected, DecodeValueType decoded) >+{ >+ return decodeSuccess; >+} >+ >+template <typename EncodeFunctionType, typename DecodeValueType, typename EncodeValueType> >+bool testSimpleValue(EncodeFunctionType encode, bool (WebCore::KeyedDecoder::* decode)(const String&, DecodeValueType&), EncodeValueType value) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ (encoder.get()->*encode)("key", value); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ DecodeValueType decodedValue; >+ bool decodeSuccess = (decoder.get()->*decode)("key", decodedValue); >+ >+ return testSimpleValueDecode(decodeSuccess, value, decodedValue); >+} >+ >+TEST(KeyedCoding, SetAndGetBool) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeBool, true)); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeBool, false)); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeInt32, true)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeUInt32, true)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeInt64, true)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeUInt64, true)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeFloat, true)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeDouble, true)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeBool, &WebCore::KeyedDecoder::decodeString, true)); >+} >+ >+TEST(KeyedCoding, SetAndGetInt32) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeInt32, 0)); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeInt32, 1)); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeInt32, -1)); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeInt32, INT_MIN)); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeInt32, INT_MAX)); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeBool, 0)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeUInt32, 0)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeInt64, 0)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeUInt64, 0)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeFloat, 0)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeDouble, 0)); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt32, &WebCore::KeyedDecoder::decodeString, 0)); >+} >+ >+TEST(KeyedCoding, SetAndGetUInt32) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeUInt32, uint32_t(0))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeUInt32, uint32_t(1))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeUInt32, UINT32_MAX)); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeBool, uint32_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeInt32, uint32_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeInt64, uint32_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeUInt64, uint32_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeFloat, uint32_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeDouble, uint32_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt32, &WebCore::KeyedDecoder::decodeString, uint32_t(0))); >+} >+ >+TEST(KeyedCoding, SetAndGetInt64) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeInt64, int64_t(0))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeInt64, int64_t(-2))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeInt64, int64_t(2))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeInt64, INT64_MIN)); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeInt64, INT64_MAX)); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeBool, int64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeInt32, int64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeUInt32, int64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeUInt64, int64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeFloat, int64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeDouble, int64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeInt64, &WebCore::KeyedDecoder::decodeString, int64_t(0))); >+} >+ >+TEST(KeyedCoding, SetAndGetUInt64) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeUInt64, uint64_t(0))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeUInt64, uint64_t(1))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeUInt64, UINT64_MAX)); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeBool, uint64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeInt32, uint64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeUInt32, uint64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeInt64, uint64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeFloat, uint64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeDouble, uint64_t(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeUInt64, &WebCore::KeyedDecoder::decodeString, uint64_t(0))); >+} >+ >+TEST(KeyedCoding, SetAndGetFloat) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeFloat, float(0))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeFloat, float(1.5))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeFloat, float(-1.5))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeFloat, std::numeric_limits<float>::lowest())); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeFloat, std::numeric_limits<float>::min())); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeFloat, std::numeric_limits<float>::max())); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeBool, float(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeInt32, float(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeUInt32, float(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeInt64, float(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeUInt64, float(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeDouble, float(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeFloat, &WebCore::KeyedDecoder::decodeString, float(0))); >+} >+ >+TEST(KeyedCoding, SetAndGetDouble) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeDouble, double(0))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeDouble, double(1.25))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeDouble, double(-1.25))); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeDouble, std::numeric_limits<double>::lowest())); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeDouble, std::numeric_limits<double>::min())); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeDouble, std::numeric_limits<double>::max())); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeBool, double(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeInt32, double(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeUInt32, double(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeInt64, double(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeUInt64, double(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeFloat, double(0))); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeDouble, &WebCore::KeyedDecoder::decodeString, double(0))); >+} >+ >+TEST(KeyedCoding, SetAndGetString) >+{ >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeString, String())); >+ EXPECT_TRUE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeString, String("WebKit"))); >+ >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeBool, String())); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeInt32, String())); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeUInt32, String())); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeInt64, String())); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeUInt64, String())); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeFloat, String())); >+ EXPECT_FALSE(testSimpleValue(&WebCore::KeyedEncoder::encodeString, &WebCore::KeyedDecoder::decodeDouble, String())); >+} >+ >+TEST(KeyedCoding, GetNonExistingRecord) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeBool("bool-true", true); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool success, boolValue; >+ success = decoder->decodeBool("bool-true", boolValue); >+ EXPECT_TRUE(success); >+ EXPECT_EQ(true, boolValue); >+ >+ success = decoder->decodeBool("no-exist-key", boolValue); >+ EXPECT_FALSE(success); >+ >+ int32_t int32Value; >+ success = decoder->decodeInt32("no-exist-key", int32Value); >+ EXPECT_FALSE(success); >+ >+ uint32_t uint32Value; >+ success = decoder->decodeUInt32("no-exist-key", uint32Value); >+ EXPECT_FALSE(success); >+ >+ int64_t int64Value; >+ success = decoder->decodeInt64("no-exist-key", int64Value); >+ EXPECT_FALSE(success); >+ >+ uint64_t uint64Value; >+ success = decoder->decodeUInt64("no-exist-key", uint64Value); >+ EXPECT_FALSE(success); >+ >+ float floatValue; >+ success = decoder->decodeFloat("no-exist-key", floatValue); >+ EXPECT_FALSE(success); >+ >+ double doubleValue; >+ success = decoder->decodeDouble("no-exist-key", doubleValue); >+ EXPECT_FALSE(success); >+ >+ const uint8_t* buffer; >+ size_t size; >+ success = decoder->decodeBytes("no-exist-key", buffer, size); >+ EXPECT_FALSE(success); >+} >+ >+struct KeyedCodingTestObject { >+ static void encode(WebCore::KeyedEncoder& encoder, const KeyedCodingTestObject& object) >+ { >+ encoder.encodeString("name", object.m_name); >+ encoder.encodeInt32("age", object.m_age); >+ } >+ >+ static bool decode(WebCore::KeyedDecoder& decoder, KeyedCodingTestObject& object) >+ { >+ if (!decoder.decodeString("name", object.m_name)) >+ return false; >+ if (!decoder.decodeInt32("age", object.m_age)) >+ return false; >+ return true; >+ } >+ >+ KeyedCodingTestObject() { }; >+ KeyedCodingTestObject(String name, int age) >+ : m_name(name) >+ , m_age(age) >+ { >+ } >+ >+ bool equals(const KeyedCodingTestObject& other) const >+ { >+ return (m_name == other.m_name) && (m_age == other.m_age); >+ } >+ >+ String m_name; >+ int32_t m_age; >+}; >+ >+static bool operator==(const KeyedCodingTestObject& lObject, const KeyedCodingTestObject& rObject) >+{ >+ return lObject.equals(rObject); >+} >+ >+TEST(KeyedCoding, SetAndGetObject) >+{ >+ const KeyedCodingTestObject user0("Noah", 28); >+ const KeyedCodingTestObject user1("Emma", 31); >+ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeObject("user0", user0, KeyedCodingTestObject::encode); >+ encoder->encodeObject("user1", user1, KeyedCodingTestObject::encode); >+ auto encodedBuffer = encoder->finishEncoding(); >+ >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ bool success; >+ KeyedCodingTestObject decodedUser0, decodedUser1; >+ >+ success = decoder->decodeObject("user0", decodedUser0, KeyedCodingTestObject::decode); >+ EXPECT_TRUE(success); >+ EXPECT_EQ(decodedUser0, user0); >+ >+ success = decoder->decodeObject("user1", decodedUser1, KeyedCodingTestObject::decode); >+ EXPECT_TRUE(success); >+ EXPECT_EQ(decodedUser1, user1); >+} >+ >+TEST(KeyedCoding, SetAndGetObjects) >+{ >+ Vector<KeyedCodingTestObject> users; >+ for (int i = 0; i < 10; i++) >+ users.append(KeyedCodingTestObject("username", i)); >+ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeObjects("users", users.begin(), users.end(), KeyedCodingTestObject::encode); >+ auto encodedBuffer = encoder->finishEncoding(); >+ >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ Vector<KeyedCodingTestObject> decodedUsers; >+ >+ bool success = decoder->decodeObjects("users", decodedUsers, KeyedCodingTestObject::decode); >+ EXPECT_TRUE(success); >+ EXPECT_EQ(users, decodedUsers); >+} >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 205902
:
387076
|
387078
|
387603
|
387617
|
387780
|
387885
|
388199
|
388206