Implement listing tests to a JSON file for iOS gtest test launcher
[chromium-blink-merge.git] / content / common / indexed_db / indexed_db_key_unittest.cc
blobabee848511a69489c496b847a5d8893718c73a63
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <vector>
7 #include "base/basictypes.h"
8 #include "base/memory/scoped_vector.h"
9 #include "base/strings/string16.h"
10 #include "content/common/indexed_db/indexed_db_key.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace content {
15 namespace {
17 TEST(IndexedDBKeyTest, KeySizeEstimates) {
18 std::vector<IndexedDBKey> keys;
19 std::vector<size_t> estimates;
21 keys.push_back(IndexedDBKey());
22 estimates.push_back(16u); // Overhead.
24 keys.push_back(IndexedDBKey(blink::WebIDBKeyTypeNull));
25 estimates.push_back(16u);
27 double number = 3.14159;
28 keys.push_back(IndexedDBKey(number, blink::WebIDBKeyTypeNumber));
29 estimates.push_back(24u); // Overhead + sizeof(double).
31 double date = 1370884329.0;
32 keys.push_back(IndexedDBKey(date, blink::WebIDBKeyTypeDate));
33 estimates.push_back(24u); // Overhead + sizeof(double).
35 const base::string16 string(1024, static_cast<base::char16>('X'));
36 keys.push_back(IndexedDBKey(string));
37 // Overhead + string length * sizeof(base::char16).
38 estimates.push_back(2064u);
40 const size_t array_size = 1024;
41 IndexedDBKey::KeyArray array;
42 double value = 123.456;
43 for (size_t i = 0; i < array_size; ++i) {
44 array.push_back(IndexedDBKey(value, blink::WebIDBKeyTypeNumber));
46 keys.push_back(IndexedDBKey(array));
47 // Overhead + array length * (Overhead + sizeof(double)).
48 estimates.push_back(24592u);
50 ASSERT_EQ(keys.size(), estimates.size());
51 for (size_t i = 0; i < keys.size(); ++i) {
52 EXPECT_EQ(estimates[i], keys[i].size_estimate());
56 } // namespace
58 } // namespace content