Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp

Issue 12310146: Merge 143347 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1364/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 expected.append(1); 109 expected.append(1);
110 EXPECT_EQ(expected, encodeBool(true)); 110 EXPECT_EQ(expected, encodeBool(true));
111 } 111 }
112 { 112 {
113 Vector<char> expected; 113 Vector<char> expected;
114 expected.append(0); 114 expected.append(0);
115 EXPECT_EQ(expected, encodeBool(false)); 115 EXPECT_EQ(expected, encodeBool(false));
116 } 116 }
117 } 117 }
118 118
119 static int compareKeys(const Vector<char>& a, const Vector<char>& b)
120 {
121 bool ok;
122 int result = compareEncodedIDBKeys(a, b, ok);
123 EXPECT_TRUE(ok);
124 return result;
125 }
126
119 TEST(IDBLevelDBCodingTest, MaxIDBKey) 127 TEST(IDBLevelDBCodingTest, MaxIDBKey)
120 { 128 {
121 Vector<char> maxKey = maxIDBKey(); 129 Vector<char> maxKey = maxIDBKey();
122 130
123 Vector<char> minKey = minIDBKey(); 131 Vector<char> minKey = minIDBKey();
124 Vector<char> arrayKey = encodeIDBKey(*IDBKey::createArray(IDBKey::KeyArray() )); 132 Vector<char> arrayKey = encodeIDBKey(*IDBKey::createArray(IDBKey::KeyArray() ));
125 Vector<char> stringKey = encodeIDBKey(*IDBKey::createString("Hello world")); 133 Vector<char> stringKey = encodeIDBKey(*IDBKey::createString("Hello world"));
126 Vector<char> numberKey = encodeIDBKey(*IDBKey::createNumber(3.14)); 134 Vector<char> numberKey = encodeIDBKey(*IDBKey::createNumber(3.14));
127 Vector<char> dateKey = encodeIDBKey(*IDBKey::createDate(1000000)); 135 Vector<char> dateKey = encodeIDBKey(*IDBKey::createDate(1000000));
128 136
129 EXPECT_GT(compareEncodedIDBKeys(maxKey, minKey), 0); 137 EXPECT_GT(compareKeys(maxKey, minKey), 0);
130 EXPECT_GT(compareEncodedIDBKeys(maxKey, arrayKey), 0); 138 EXPECT_GT(compareKeys(maxKey, arrayKey), 0);
131 EXPECT_GT(compareEncodedIDBKeys(maxKey, stringKey), 0); 139 EXPECT_GT(compareKeys(maxKey, stringKey), 0);
132 EXPECT_GT(compareEncodedIDBKeys(maxKey, numberKey), 0); 140 EXPECT_GT(compareKeys(maxKey, numberKey), 0);
133 EXPECT_GT(compareEncodedIDBKeys(maxKey, dateKey), 0); 141 EXPECT_GT(compareKeys(maxKey, dateKey), 0);
134 } 142 }
135 143
136 TEST(IDBLevelDBCodingTest, MinIDBKey) 144 TEST(IDBLevelDBCodingTest, MinIDBKey)
137 { 145 {
138 Vector<char> minKey = minIDBKey(); 146 Vector<char> minKey = minIDBKey();
139 147
140 Vector<char> maxKey = maxIDBKey(); 148 Vector<char> maxKey = maxIDBKey();
141 Vector<char> arrayKey = encodeIDBKey(*IDBKey::createArray(IDBKey::KeyArray() )); 149 Vector<char> arrayKey = encodeIDBKey(*IDBKey::createArray(IDBKey::KeyArray() ));
142 Vector<char> stringKey = encodeIDBKey(*IDBKey::createString("Hello world")); 150 Vector<char> stringKey = encodeIDBKey(*IDBKey::createString("Hello world"));
143 Vector<char> numberKey = encodeIDBKey(*IDBKey::createNumber(3.14)); 151 Vector<char> numberKey = encodeIDBKey(*IDBKey::createNumber(3.14));
144 Vector<char> dateKey = encodeIDBKey(*IDBKey::createDate(1000000)); 152 Vector<char> dateKey = encodeIDBKey(*IDBKey::createDate(1000000));
145 153
146 EXPECT_LT(compareEncodedIDBKeys(minKey, maxKey), 0); 154 EXPECT_LT(compareKeys(minKey, maxKey), 0);
147 EXPECT_LT(compareEncodedIDBKeys(minKey, arrayKey), 0); 155 EXPECT_LT(compareKeys(minKey, arrayKey), 0);
148 EXPECT_LT(compareEncodedIDBKeys(minKey, stringKey), 0); 156 EXPECT_LT(compareKeys(minKey, stringKey), 0);
149 EXPECT_LT(compareEncodedIDBKeys(minKey, numberKey), 0); 157 EXPECT_LT(compareKeys(minKey, numberKey), 0);
150 EXPECT_LT(compareEncodedIDBKeys(minKey, dateKey), 0); 158 EXPECT_LT(compareKeys(minKey, dateKey), 0);
151 } 159 }
152 160
153 TEST(IDBLevelDBCodingTest, EncodeInt) 161 TEST(IDBLevelDBCodingTest, EncodeInt)
154 { 162 {
155 EXPECT_EQ(static_cast<size_t>(1), encodeInt(0).size()); 163 EXPECT_EQ(static_cast<size_t>(1), encodeInt(0).size());
156 EXPECT_EQ(static_cast<size_t>(1), encodeInt(1).size()); 164 EXPECT_EQ(static_cast<size_t>(1), encodeInt(1).size());
157 EXPECT_EQ(static_cast<size_t>(1), encodeInt(255).size()); 165 EXPECT_EQ(static_cast<size_t>(1), encodeInt(255).size());
158 EXPECT_EQ(static_cast<size_t>(2), encodeInt(256).size()); 166 EXPECT_EQ(static_cast<size_t>(2), encodeInt(256).size());
159 EXPECT_EQ(static_cast<size_t>(4), encodeInt(0xffffffff).size()); 167 EXPECT_EQ(static_cast<size_t>(4), encodeInt(0xffffffff).size());
160 #ifdef NDEBUG 168 #ifdef NDEBUG
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 EXPECT_EQ(s, res); 323 EXPECT_EQ(s, res);
316 EXPECT_EQ(v.data() + v.size(), p); 324 EXPECT_EQ(v.data() + v.size(), p);
317 325
318 EXPECT_EQ(0, decodeStringWithLength(v.data(), v.data() + v.size() - 1, r es)); 326 EXPECT_EQ(0, decodeStringWithLength(v.data(), v.data() + v.size() - 1, r es));
319 EXPECT_EQ(0, decodeStringWithLength(v.data(), v.data(), res)); 327 EXPECT_EQ(0, decodeStringWithLength(v.data(), v.data(), res));
320 } 328 }
321 } 329 }
322 330
323 static int compareStrings(const char* p, const char* limitP, const char* q, cons t char* limitQ) 331 static int compareStrings(const char* p, const char* limitP, const char* q, cons t char* limitQ)
324 { 332 {
325 int result = compareEncodedStringsWithLength(p, limitP, q, limitQ); 333 bool ok;
334 int result = compareEncodedStringsWithLength(p, limitP, q, limitQ, ok);
335 EXPECT_TRUE(ok);
326 EXPECT_EQ(p, limitP); 336 EXPECT_EQ(p, limitP);
327 EXPECT_EQ(q, limitQ); 337 EXPECT_EQ(q, limitQ);
328 return result; 338 return result;
329 } 339 }
330 340
331 TEST(IDBLevelDBCodingTest, CompareEncodedStringsWithLength) 341 TEST(IDBLevelDBCodingTest, CompareEncodedStringsWithLength)
332 { 342 {
333 const UChar testStringA[] = {0x1000, 0x1000, '\0'}; 343 const UChar testStringA[] = {0x1000, 0x1000, '\0'};
334 const UChar testStringB[] = {0x1000, 0x1000, 0x1000, '\0'}; 344 const UChar testStringB[] = {0x1000, 0x1000, 0x1000, '\0'};
335 const UChar testStringC[] = {0x1000, 0x1000, 0x1001, '\0'}; 345 const UChar testStringC[] = {0x1000, 0x1000, 0x1001, '\0'};
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 Vector<char> extractedB; 634 Vector<char> extractedB;
625 635
626 const char* p = extractEncodedIDBKey(encodedA.data(), encodedA.data() + encodedA.size(), &extractedA); 636 const char* p = extractEncodedIDBKey(encodedA.data(), encodedA.data() + encodedA.size(), &extractedA);
627 EXPECT_EQ(encodedA.data() + encodedA.size(), p); 637 EXPECT_EQ(encodedA.data() + encodedA.size(), p);
628 EXPECT_EQ(encodedA, extractedA); 638 EXPECT_EQ(encodedA, extractedA);
629 639
630 const char* q = extractEncodedIDBKey(encodedB.data(), encodedB.data() + encodedB.size(), &extractedB); 640 const char* q = extractEncodedIDBKey(encodedB.data(), encodedB.data() + encodedB.size(), &extractedB);
631 EXPECT_EQ(encodedB.data() + encodedB.size(), q); 641 EXPECT_EQ(encodedB.data() + encodedB.size(), q);
632 EXPECT_EQ(encodedB, extractedB); 642 EXPECT_EQ(encodedB, extractedB);
633 643
634 EXPECT_LT(compareEncodedIDBKeys(extractedA, extractedB), 0); 644 EXPECT_LT(compareKeys(extractedA, extractedB), 0);
635 EXPECT_GT(compareEncodedIDBKeys(extractedB, extractedA), 0); 645 EXPECT_GT(compareKeys(extractedB, extractedA), 0);
636 EXPECT_EQ(compareEncodedIDBKeys(extractedA, extractedA), 0); 646 EXPECT_EQ(compareKeys(extractedA, extractedA), 0);
637 EXPECT_EQ(compareEncodedIDBKeys(extractedB, extractedB), 0); 647 EXPECT_EQ(compareKeys(extractedB, extractedB), 0);
638 648
639 EXPECT_EQ(0, extractEncodedIDBKey(encodedA.data(), encodedA.data() + enc odedA.size() - 1, &extractedA)); 649 EXPECT_EQ(0, extractEncodedIDBKey(encodedA.data(), encodedA.data() + enc odedA.size() - 1, &extractedA));
640 } 650 }
641 } 651 }
642 652
643 TEST(IDBLevelDBCodingTest, ComparisonTest) 653 TEST(IDBLevelDBCodingTest, ComparisonTest)
644 { 654 {
645 Vector<Vector<char> > keys; 655 Vector<Vector<char> > keys;
646 keys.append(SchemaVersionKey::encode()); 656 keys.append(SchemaVersionKey::encode());
647 keys.append(MaxDatabaseIdKey::encode()); 657 keys.append(MaxDatabaseIdKey::encode());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 740
731 EXPECT_EQ(vA.size(), vB.size()); 741 EXPECT_EQ(vA.size(), vB.size());
732 EXPECT_EQ(*(vA.data()), *(vB.data())); 742 EXPECT_EQ(*(vA.data()), *(vB.data()));
733 } 743 }
734 } 744 }
735 745
736 } // namespace 746 } // namespace
737 747
738 #endif // USE(LEVELDB) 748 #endif // USE(LEVELDB)
739 #endif // ENABLE(INDEXED_DATABASE) 749 #endif // ENABLE(INDEXED_DATABASE)
OLDNEW
« no previous file with comments | « Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698