OLD | NEW |
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 c = 1; | 77 c = 1; |
78 expected[0] = c; | 78 expected[0] = c; |
79 EXPECT_EQ(expected, encodeByte(c)); | 79 EXPECT_EQ(expected, encodeByte(c)); |
80 | 80 |
81 c = 255; | 81 c = 255; |
82 expected[0] = c; | 82 expected[0] = c; |
83 EXPECT_EQ(expected, encodeByte(c)); | 83 EXPECT_EQ(expected, encodeByte(c)); |
84 } | 84 } |
85 | 85 |
| 86 TEST(IDBLevelDBCodingTest, EncodeBool) |
| 87 { |
| 88 { |
| 89 Vector<char> expected; |
| 90 expected.append(1); |
| 91 EXPECT_EQ(expected, encodeBool(true)); |
| 92 } |
| 93 { |
| 94 Vector<char> expected; |
| 95 expected.append(0); |
| 96 EXPECT_EQ(expected, encodeBool(false)); |
| 97 } |
| 98 } |
| 99 |
86 TEST(IDBLevelDBCodingTest, MaxIDBKey) | 100 TEST(IDBLevelDBCodingTest, MaxIDBKey) |
87 { | 101 { |
88 Vector<char> maxKey = maxIDBKey(); | 102 Vector<char> maxKey = maxIDBKey(); |
89 | 103 |
90 Vector<char> minKey = minIDBKey(); | 104 Vector<char> minKey = minIDBKey(); |
91 Vector<char> arrayKey = encodeIDBKey(*IDBKey::createArray(IDBKey::KeyArray()
)); | 105 Vector<char> arrayKey = encodeIDBKey(*IDBKey::createArray(IDBKey::KeyArray()
)); |
92 Vector<char> stringKey = encodeIDBKey(*IDBKey::createString("Hello world")); | 106 Vector<char> stringKey = encodeIDBKey(*IDBKey::createString("Hello world")); |
93 Vector<char> numberKey = encodeIDBKey(*IDBKey::createNumber(3.14)); | 107 Vector<char> numberKey = encodeIDBKey(*IDBKey::createNumber(3.14)); |
94 Vector<char> dateKey = encodeIDBKey(*IDBKey::createDate(1000000)); | 108 Vector<char> dateKey = encodeIDBKey(*IDBKey::createDate(1000000)); |
95 | 109 |
(...skipping 23 matching lines...) Expand all Loading... |
119 | 133 |
120 TEST(IDBLevelDBCodingTest, EncodeInt) | 134 TEST(IDBLevelDBCodingTest, EncodeInt) |
121 { | 135 { |
122 EXPECT_EQ(static_cast<size_t>(1), encodeInt(0).size()); | 136 EXPECT_EQ(static_cast<size_t>(1), encodeInt(0).size()); |
123 EXPECT_EQ(static_cast<size_t>(1), encodeInt(1).size()); | 137 EXPECT_EQ(static_cast<size_t>(1), encodeInt(1).size()); |
124 EXPECT_EQ(static_cast<size_t>(1), encodeInt(255).size()); | 138 EXPECT_EQ(static_cast<size_t>(1), encodeInt(255).size()); |
125 EXPECT_EQ(static_cast<size_t>(2), encodeInt(256).size()); | 139 EXPECT_EQ(static_cast<size_t>(2), encodeInt(256).size()); |
126 EXPECT_EQ(static_cast<size_t>(4), encodeInt(0xffffffff).size()); | 140 EXPECT_EQ(static_cast<size_t>(4), encodeInt(0xffffffff).size()); |
127 } | 141 } |
128 | 142 |
| 143 TEST(IDBLevelDBCodingTest, DecodeBool) |
| 144 { |
| 145 { |
| 146 Vector<char> encoded; |
| 147 encoded.append(1); |
| 148 EXPECT_TRUE(decodeBool(encoded.data(), encoded.data() + encoded.size()))
; |
| 149 } |
| 150 { |
| 151 Vector<char> encoded; |
| 152 encoded.append(0); |
| 153 EXPECT_FALSE(decodeBool(encoded.data(), encoded.data() + encoded.size())
); |
| 154 } |
| 155 } |
| 156 |
129 TEST(IDBLevelDBCodingTest, DecodeInt) | 157 TEST(IDBLevelDBCodingTest, DecodeInt) |
130 { | 158 { |
131 Vector<int64_t> testCases; | 159 Vector<int64_t> testCases; |
132 testCases.append(0); | 160 testCases.append(0); |
133 testCases.append(1); | 161 testCases.append(1); |
134 testCases.append(255); | 162 testCases.append(255); |
135 testCases.append(256); | 163 testCases.append(256); |
136 testCases.append(65535); | 164 testCases.append(65535); |
137 testCases.append(655536); | 165 testCases.append(655536); |
138 testCases.append(7711192431755665792ll); | 166 testCases.append(7711192431755665792ll); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 EXPECT_LT(compare(keyA, keyB), 0); | 532 EXPECT_LT(compare(keyA, keyB), 0); |
505 EXPECT_GT(compare(keyB, keyA), 0); | 533 EXPECT_GT(compare(keyB, keyA), 0); |
506 } | 534 } |
507 } | 535 } |
508 } | 536 } |
509 | 537 |
510 } // namespace | 538 } // namespace |
511 | 539 |
512 #endif // USE(LEVELDB) | 540 #endif // USE(LEVELDB) |
513 #endif // ENABLE(INDEXED_DATABASE) | 541 #endif // ENABLE(INDEXED_DATABASE) |
OLD | NEW |