summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-05-25 15:09:11 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-05-25 15:09:11 +0200
commita89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd (patch)
treeb7abd9f49ae1d4d2e426a5883bfccd42b8e2ee12 /Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp
parent8d473cf9743f1d30a16a27114e93bd5af5648d23 (diff)
downloadqtwebkit-a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd.tar.gz
Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516)
Diffstat (limited to 'Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp')
-rw-r--r--Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp b/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp
index eb9962d58..8f5b8ef01 100644
--- a/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp
+++ b/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp
@@ -30,6 +30,7 @@
#if USE(LEVELDB)
#include "IDBKey.h"
+#include "IDBKeyPath.h"
#include "LevelDBSlice.h"
#include <gtest/gtest.h>
#include <wtf/Vector.h>
@@ -418,6 +419,133 @@ TEST(IDBLevelDBCodingTest, EncodeDecodeIDBKey)
EXPECT_EQ(0, decodeIDBKey(v.data(), v.data() + v.size() - 1, decodedKey));
}
+TEST(IDBLevelDBCodingTest, EncodeIDBKeyPath)
+{
+ const unsigned char kIDBKeyPathTypeCodedByte1 = 0;
+ const unsigned char kIDBKeyPathTypeCodedByte2 = 0;
+ {
+ IDBKeyPath keyPath;
+ EXPECT_EQ(keyPath.type(), IDBKeyPath::NullType);
+ Vector<char> v = encodeIDBKeyPath(keyPath);
+ EXPECT_EQ(v.size(), 3U);
+ EXPECT_EQ(v[0], kIDBKeyPathTypeCodedByte1);
+ EXPECT_EQ(v[1], kIDBKeyPathTypeCodedByte2);
+ EXPECT_EQ(v[2], IDBKeyPath::NullType);
+ }
+
+ {
+ Vector<String> testCases;
+ testCases.append("");
+ testCases.append("foo");
+ testCases.append("foo.bar");
+
+ for (size_t i = 0; i < testCases.size(); ++i) {
+ IDBKeyPath keyPath = IDBKeyPath(testCases[i]);
+ Vector<char> v = encodeIDBKeyPath(keyPath);
+ EXPECT_EQ(v.size(), encodeStringWithLength(testCases[i]).size() + 3);
+ const char* p = v.data();
+ const char* limit = v.data() + v.size();
+ EXPECT_EQ(*p++, kIDBKeyPathTypeCodedByte1);
+ EXPECT_EQ(*p++, kIDBKeyPathTypeCodedByte2);
+ EXPECT_EQ(*p++, IDBKeyPath::StringType);
+ String string;
+ p = decodeStringWithLength(p, limit, string);
+ EXPECT_EQ(string, testCases[i]);
+ EXPECT_EQ(p, limit);
+ }
+ }
+
+ {
+ Vector<String> testCase;
+ testCase.append("");
+ testCase.append("foo");
+ testCase.append("foo.bar");
+
+ IDBKeyPath keyPath(testCase);
+ EXPECT_EQ(keyPath.type(), IDBKeyPath::ArrayType);
+ Vector<char> v = encodeIDBKeyPath(keyPath);
+ const char* p = v.data();
+ const char* limit = v.data() + v.size();
+ EXPECT_EQ(*p++, kIDBKeyPathTypeCodedByte1);
+ EXPECT_EQ(*p++, kIDBKeyPathTypeCodedByte2);
+ EXPECT_EQ(*p++, IDBKeyPath::ArrayType);
+ int64_t count;
+ p = decodeVarInt(p, limit, count);
+ EXPECT_EQ(count, static_cast<int64_t>(testCase.size()));
+ for (size_t i = 0; i < static_cast<size_t>(count); ++i) {
+ String string;
+ p = decodeStringWithLength(p, limit, string);
+ EXPECT_EQ(string, testCase[i]);
+ }
+ EXPECT_EQ(p, limit);
+ }
+}
+
+TEST(IDBLevelDBCodingTest, DecodeIDBKeyPath)
+{
+ const unsigned char kIDBKeyPathTypeCodedByte1 = 0;
+ const unsigned char kIDBKeyPathTypeCodedByte2 = 0;
+ {
+ // Legacy encoding of string key paths.
+ Vector<String> testCases;
+ testCases.append("");
+ testCases.append("foo");
+ testCases.append("foo.bar");
+
+ for (size_t i = 0; i < testCases.size(); ++i) {
+ Vector<char> v = encodeString(testCases[i]);
+ IDBKeyPath keyPath = decodeIDBKeyPath(v.data(), v.data() + v.size());
+ EXPECT_EQ(keyPath.type(), IDBKeyPath::StringType);
+ EXPECT_EQ(testCases[i], keyPath.string());
+ }
+ }
+ {
+ Vector<char> v;
+ v.append(kIDBKeyPathTypeCodedByte1);
+ v.append(kIDBKeyPathTypeCodedByte2);
+ v.append(IDBKeyPath::NullType);
+ IDBKeyPath keyPath = decodeIDBKeyPath(v.data(), v.data() + v.size());
+ EXPECT_EQ(keyPath.type(), IDBKeyPath::NullType);
+ EXPECT_TRUE(keyPath.isNull());
+ }
+ {
+ Vector<String> testCases;
+ testCases.append("");
+ testCases.append("foo");
+ testCases.append("foo.bar");
+
+ for (size_t i = 0; i < testCases.size(); ++i) {
+ Vector<char> v;
+ v.append(kIDBKeyPathTypeCodedByte1);
+ v.append(kIDBKeyPathTypeCodedByte2);
+ v.append(IDBKeyPath::StringType);
+ v.append(encodeStringWithLength(testCases[i]));
+ IDBKeyPath keyPath = decodeIDBKeyPath(v.data(), v.data() + v.size());
+ EXPECT_EQ(keyPath.type(), IDBKeyPath::StringType);
+ EXPECT_EQ(testCases[i], keyPath.string());
+ }
+ }
+ {
+ Vector<String> testCase;
+ testCase.append("");
+ testCase.append("foo");
+ testCase.append("foo.bar");
+
+ Vector<char> v;
+ v.append(kIDBKeyPathTypeCodedByte1);
+ v.append(kIDBKeyPathTypeCodedByte2);
+ v.append(IDBKeyPath::ArrayType);
+ v.append(encodeVarInt(testCase.size()));
+ for (size_t i = 0; i < testCase.size(); ++i)
+ v.append(encodeStringWithLength(testCase[i]));
+ IDBKeyPath keyPath = decodeIDBKeyPath(v.data(), v.data() + v.size());
+ EXPECT_EQ(keyPath.type(), IDBKeyPath::ArrayType);
+ EXPECT_EQ(keyPath.array().size(), testCase.size());
+ for (size_t i = 0; i < testCase.size(); ++i)
+ EXPECT_EQ(keyPath.array()[i], testCase[i]);
+ }
+}
+
TEST(IDBLevelDBCodingTest, ExtractAndCompareIDBKeys)
{
Vector<RefPtr<IDBKey> > keys;