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-20200108151300.patch (text/plain), 23.79 KB, created by
Takashi Komori
on 2020-01-07 22:16:18 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Takashi Komori
Created:
2020-01-07 22:16:18 PST
Size:
23.79 KB
patch
obsolete
>Subversion Revision: 254164 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 8dec2c315360d4f166c722fb26ccfd5f939258fb..20ece21223990baad47483d8d1e0fd4afb8ac145 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,33 @@ >+2020-01-07 Takashi Komori <Takashi.Komori@sony.com> >+ >+ KeyedDecoderGeneric craches when it acesses 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 >+ >+ No new tests (OOPS!). >+ >+ * platform/generic/KeyedDecoderGeneric.cpp: >+ (WebCore::KeyedDecoderGeneric::Dictionary::exists): >+ (WebCore::KeyedDecoderGeneric::getPointerFromDictionaryStack): >+ (WebCore::KeyedDecoderGeneric::getValueFromDictionaryStack): >+ (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-07 Megan Gardner <megan_gardner@apple.com> > > Rename start/endPosition to start/endOffset in SelectionRangeData for clarity >diff --git a/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp b/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp >index 0e5972321b5f73f572bd79658811f003a95ed492..9e9e37483b28f1f66cc5afd242bf2d3723dde8cc 100644 >--- a/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp >+++ b/Source/WebCore/platform/generic/KeyedDecoderGeneric.cpp >@@ -43,6 +43,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); } >+ bool exists(const String& key) { return !!m_map.get(key); } > > private: > HashMap<String, std::unique_ptr<Node>> m_map; >@@ -181,11 +182,34 @@ 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(); >+ >+ if (!dictionary->exists(key)) >+ return nullptr; >+ >+ return WTF::get_if<T>(dictionary->get(key)); >+} >+ >+template<typename T> >+bool KeyedDecoderGeneric::getValueFromDictionaryStack(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 getValueFromDictionaryStack(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 getValueFromDictionaryStack(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 getValueFromDictionaryStack(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 getValueFromDictionaryStack(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 getValueFromDictionaryStack(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 getValueFromDictionaryStack(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 getValueFromDictionaryStack(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 getValueFromDictionaryStack(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..91f5e36e3793b69c6ebb808da82395d430b8c839 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 getValueFromDictionaryStack(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 3a252f6eee4fdf64e0417ba143569d6a4da6d51c..8e02923ca93153e9e57186a7a109dad634adc930 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,20 @@ >+2020-01-07 Takashi Komori <Takashi.Komori@sony.com> >+ >+ KeyedDecoderGeneric craches when it acesses data with non-existing key. >+ https://bugs.webkit.org/show_bug.cgi?id=205902 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/PlatformWin.cmake: >+ * TestWebKitAPI/Tests/WebCore/KeyedCodingGeneric.cpp: Added. >+ (TestWebKitAPI::checkDecodedBytes): >+ (TestWebKitAPI::TEST): >+ (TestWebKitAPI::KeyedCodingGenericTestObject::encode): >+ (TestWebKitAPI::KeyedCodingGenericTestObject::decode): >+ (TestWebKitAPI::KeyedCodingGenericTestObject::KeyedCodingGenericTestObject): >+ (TestWebKitAPI::KeyedCodingGenericTestObject::equals const): >+ (TestWebKitAPI::operator==): >+ > 2020-01-07 Aakash Jain <aakash_jain@apple.com> > > [EWS] Limit pre-existing JSC tests failures to display in buildbot summary >diff --git a/Tools/TestWebKitAPI/PlatformWin.cmake b/Tools/TestWebKitAPI/PlatformWin.cmake >index 349334826fa34db28ae2d8260fc5ae4d524dc0ef..8815c50464c69c117e8d30b5690f21e7993c65b8 100644 >--- a/Tools/TestWebKitAPI/PlatformWin.cmake >+++ b/Tools/TestWebKitAPI/PlatformWin.cmake >@@ -62,9 +62,8 @@ if (${WTF_PLATFORM_WIN_CAIRO}) > ) > list(APPEND TestWebCore_SOURCES > Tests/WebCore/CryptoDigest.cpp >- >+ Tests/WebCore/KeyedCodingGeneric.cpp > Tests/WebCore/curl/Cookies.cpp >- > Tests/WebCore/win/BitmapImage.cpp > ) > else () >diff --git a/Tools/TestWebKitAPI/Tests/WebCore/KeyedCodingGeneric.cpp b/Tools/TestWebKitAPI/Tests/WebCore/KeyedCodingGeneric.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..86d9c51f0be35363ae42b4c14b797758e2364ede >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebCore/KeyedCodingGeneric.cpp >@@ -0,0 +1,434 @@ >+/* >+ * 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; >+ >+ for (int i = 0; i < originalSize; i++) { >+ if (original[i] != decoded[i]) >+ return false; >+ } >+ >+ return true; >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetBytes) >+{ >+ const uint8_t data[] = { 0x00, 0x01, 0x02, 0x03, 0xde, 0xad, 0xbe, 0xef }; >+ const size_t dataLength = sizeof(data) / sizeof(uint8_t); >+ 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 result; >+ const uint8_t* buffer; >+ size_t size; >+ >+ result = decoder->decodeBytes("data", buffer, size); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(dataLength, size); >+ EXPECT_TRUE(checkDecodedBytes(data, dataLength, buffer, size)); >+ >+ result = decoder->decodeBytes("data-size0", buffer, size); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(dataLengthZero, size); >+ >+ result = decoder->decodeBytes("data-size1", buffer, size); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(dataLengthOne, size); >+ EXPECT_TRUE(checkDecodedBytes(data, dataLengthOne, buffer, size)); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetBool) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeBool("bool-true", true); >+ encoder->encodeBool("bool-false", false); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result, value; >+ result = decoder->decodeBool("bool-true", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(true, value); >+ >+ result = decoder->decodeBool("bool-false", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(false, value); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetInt32) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeInt32("zero", 0); >+ encoder->encodeInt32("minus-one", -1); >+ encoder->encodeInt32("plus-one", 1); >+ encoder->encodeInt32("int32-min", INT32_MIN); >+ encoder->encodeInt32("int32-max", INT32_MAX); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result; >+ int32_t value; >+ result = decoder->decodeInt32("zero", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(0, value); >+ >+ result = decoder->decodeInt32("minus-one", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(-1, value); >+ >+ result = decoder->decodeInt32("plus-one", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(1, value); >+ >+ result = decoder->decodeInt32("int32-min", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(INT32_MIN, value); >+ >+ result = decoder->decodeInt32("int32-max", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(INT32_MAX, value); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetUInt32) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeUInt32("zero", 0); >+ encoder->encodeUInt32("plus-one", 1); >+ encoder->encodeUInt32("uint32-max", UINT32_MAX); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result; >+ uint32_t value; >+ result = decoder->decodeUInt32("zero", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(0, value); >+ >+ result = decoder->decodeUInt32("plus-one", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(1, value); >+ >+ result = decoder->decodeUInt32("uint32-max", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(UINT32_MAX, value); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetInt64) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeInt64("zero", 0); >+ encoder->encodeInt64("minus-two", -2); >+ encoder->encodeInt64("plus-two", 2); >+ encoder->encodeInt64("int64-min", INT64_MIN); >+ encoder->encodeInt64("int64-max", INT64_MAX); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result; >+ int64_t value; >+ result = decoder->decodeInt64("zero", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(0, value); >+ >+ result = decoder->decodeInt64("minus-two", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(-2, value); >+ >+ result = decoder->decodeInt64("plus-two", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(2, value); >+ >+ result = decoder->decodeInt64("int64-min", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(INT64_MIN, value); >+ >+ result = decoder->decodeInt64("int64-max", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(INT64_MAX, value); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetUInt64) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeUInt64("zero", 0); >+ encoder->encodeUInt64("plus-one", 1); >+ encoder->encodeUInt64("uint64-max", UINT64_MAX); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result; >+ uint64_t value; >+ result = decoder->decodeUInt64("zero", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(0, value); >+ >+ result = decoder->decodeUInt64("plus-one", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(1, value); >+ >+ result = decoder->decodeUInt64("uint64-max", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(UINT64_MAX, value); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetFloat) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeFloat("zero", 0); >+ encoder->encodeFloat("minus-one-point-five", -1.5); >+ encoder->encodeFloat("one-point-five", 1.5); >+ encoder->encodeFloat("float-min", FLT_MIN); >+ encoder->encodeFloat("float-max", FLT_MAX); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result; >+ float value; >+ result = decoder->decodeFloat("zero", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(0, value); >+ >+ result = decoder->decodeFloat("minus-one-point-five", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(-1.5, value); >+ >+ result = decoder->decodeFloat("one-point-five", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(1.5, value); >+ >+ result = decoder->decodeFloat("float-min", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(FLT_MIN, value); >+ >+ result = decoder->decodeFloat("float-max", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(FLT_MAX, value); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetDouble) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeDouble("zero", 0); >+ encoder->encodeDouble("minus-one-point-two-five", -1.25); >+ encoder->encodeDouble("one-point-two-five", 1.25); >+ encoder->encodeDouble("double-min", DBL_MIN); >+ encoder->encodeDouble("double-max", DBL_MAX); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result; >+ double value; >+ result = decoder->decodeDouble("zero", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(0, value); >+ >+ result = decoder->decodeDouble("minus-one-point-two-five", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(-1.25, value); >+ >+ result = decoder->decodeDouble("one-point-two-five", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(1.25, value); >+ >+ result = decoder->decodeDouble("double-max", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(DBL_MAX, value); >+ >+ result = decoder->decodeDouble("double-min", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(DBL_MIN, value); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetString) >+{ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeString("string-length-zero", ""); >+ encoder->encodeString("string-webkit", "WebKit"); >+ >+ auto encodedBuffer = encoder->finishEncoding(); >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ >+ bool result; >+ String value; >+ result = decoder->decodeString("string-length-zero", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(0, value.length()); >+ >+ result = decoder->decodeString("string-webkit", value); >+ EXPECT_TRUE(result); >+ EXPECT_EQ("WebKit", value); >+} >+ >+TEST(KeyedCodingGeneric, 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 result, boolValue; >+ result = decoder->decodeBool("bool-true", boolValue); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(true, boolValue); >+ >+ result = decoder->decodeBool("no-exist-key", boolValue); >+ EXPECT_FALSE(result); >+ >+ int32_t int32Value; >+ result = decoder->decodeInt32("no-exist-key", int32Value); >+ EXPECT_FALSE(result); >+ >+ uint32_t uint32Value; >+ result = decoder->decodeUInt32("no-exist-key", uint32Value); >+ EXPECT_FALSE(result); >+ >+ int64_t int64Value; >+ result = decoder->decodeInt64("no-exist-key", int64Value); >+ EXPECT_FALSE(result); >+ >+ uint64_t uint64Value; >+ result = decoder->decodeUInt64("no-exist-key", uint64Value); >+ EXPECT_FALSE(result); >+ >+ float floatValue; >+ result = decoder->decodeFloat("no-exist-key", floatValue); >+ EXPECT_FALSE(result); >+ >+ double doubleValue; >+ result = decoder->decodeDouble("no-exist-key", doubleValue); >+ EXPECT_FALSE(result); >+ >+ const uint8_t* buffer; >+ size_t size; >+ result = decoder->decodeBytes("no-exist-key", buffer, size); >+ EXPECT_FALSE(result); >+} >+ >+struct KeyedCodingGenericTestObject { >+ static void encode(WebCore::KeyedEncoder& encoder, const KeyedCodingGenericTestObject& object) >+ { >+ encoder.encodeString("name", object.m_name); >+ encoder.encodeInt32("age", object.m_age); >+ } >+ >+ static bool decode(WebCore::KeyedDecoder& decoder, KeyedCodingGenericTestObject& object) >+ { >+ if (!decoder.decodeString("name", object.m_name)) >+ return false; >+ if (!decoder.decodeInt32("age", object.m_age)) >+ return false; >+ return true; >+ } >+ >+ KeyedCodingGenericTestObject() { }; >+ KeyedCodingGenericTestObject(String name, int age) >+ : m_name(name) >+ , m_age(age) >+ { >+ } >+ >+ bool equals(const KeyedCodingGenericTestObject& other) const >+ { >+ return (m_name == other.m_name) && (m_name == other.m_name); >+ } >+ >+ String m_name; >+ int32_t m_age; >+}; >+ >+static bool operator==(const KeyedCodingGenericTestObject& lObject, const KeyedCodingGenericTestObject& rObject) >+{ >+ return lObject.equals(rObject); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetObject) >+{ >+ const KeyedCodingGenericTestObject user0("Noah", 28); >+ const KeyedCodingGenericTestObject user1("Emma", 31); >+ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeObject("user0", user0, KeyedCodingGenericTestObject::encode); >+ encoder->encodeObject("user1", user1, KeyedCodingGenericTestObject::encode); >+ auto encodedBuffer = encoder->finishEncoding(); >+ >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ bool result; >+ KeyedCodingGenericTestObject decodedUser0, decodedUser1; >+ >+ result = decoder->decodeObject("user0", decodedUser0, KeyedCodingGenericTestObject::decode); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(decodedUser0, user0); >+ >+ result = decoder->decodeObject("user1", decodedUser1, KeyedCodingGenericTestObject::decode); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(decodedUser1, user1); >+} >+ >+TEST(KeyedCodingGeneric, SetAndGetObjects) >+{ >+ Vector<KeyedCodingGenericTestObject> users; >+ for (int i = 0; i < 10; i++) >+ users.append(KeyedCodingGenericTestObject("username", i)); >+ >+ auto encoder = WebCore::KeyedEncoder::encoder(); >+ encoder->encodeObjects("users", users.begin(), users.end(), KeyedCodingGenericTestObject::encode); >+ auto encodedBuffer = encoder->finishEncoding(); >+ >+ auto decoder = WebCore::KeyedDecoder::decoder(reinterpret_cast<const uint8_t*>(encodedBuffer->data()), encodedBuffer->size()); >+ Vector<KeyedCodingGenericTestObject> decodedUsers; >+ >+ bool result = decoder->decodeObjects("users", decodedUsers, KeyedCodingGenericTestObject::decode); >+ EXPECT_TRUE(result); >+ EXPECT_EQ(users.size(), decodedUsers.size()); >+} >+}
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