OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/perftimer.h" | 9 #include "base/perftimer.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Test deserialization of a json string into a Value object. We run the test | 45 // Test deserialization of a json string into a Value object. We run the test |
46 // using 3 sample strings for both the current decoder and jsoncpp's decoder. | 46 // using 3 sample strings for both the current decoder and jsoncpp's decoder. |
47 TEST_F(JSONValueSerializerTests, Reading) { | 47 TEST_F(JSONValueSerializerTests, Reading) { |
48 printf("\n"); | 48 printf("\n"); |
49 const int kIterations = 100000; | 49 const int kIterations = 100000; |
50 | 50 |
51 // Test chrome json implementation | 51 // Test chrome json implementation |
52 PerfTimeLogger chrome_timer("chrome"); | 52 PerfTimeLogger chrome_timer("chrome"); |
53 for (int i = 0; i < kIterations; ++i) { | 53 for (int i = 0; i < kIterations; ++i) { |
54 for (size_t j = 0; j < test_cases_.size(); ++j) { | 54 for (size_t j = 0; j < test_cases_.size(); ++j) { |
55 Value* root = NULL; | |
56 JSONStringValueSerializer reader(test_cases_[j]); | 55 JSONStringValueSerializer reader(test_cases_[j]); |
57 ASSERT_TRUE(reader.Deserialize(&root, NULL)); | 56 scoped_ptr<Value> root(reader.Deserialize(NULL)); |
58 delete root; | 57 ASSERT_TRUE(root.get()); |
59 } | 58 } |
60 } | 59 } |
61 chrome_timer.Done(); | 60 chrome_timer.Done(); |
62 } | 61 } |
63 | 62 |
64 TEST_F(JSONValueSerializerTests, CompactWriting) { | 63 TEST_F(JSONValueSerializerTests, CompactWriting) { |
65 printf("\n"); | 64 printf("\n"); |
66 const int kIterations = 100000; | 65 const int kIterations = 100000; |
67 // Convert test cases to Value objects. | 66 // Convert test cases to Value objects. |
68 std::vector<Value*> test_cases; | 67 std::vector<Value*> test_cases; |
69 for (size_t i = 0; i < test_cases_.size(); ++i) { | 68 for (size_t i = 0; i < test_cases_.size(); ++i) { |
70 Value* root = NULL; | |
71 JSONStringValueSerializer reader(test_cases_[i]); | 69 JSONStringValueSerializer reader(test_cases_[i]); |
72 ASSERT_TRUE(reader.Deserialize(&root, NULL)); | 70 Value* root = reader.Deserialize(NULL); |
| 71 ASSERT_TRUE(root); |
73 test_cases.push_back(root); | 72 test_cases.push_back(root); |
74 } | 73 } |
75 | 74 |
76 PerfTimeLogger chrome_timer("chrome"); | 75 PerfTimeLogger chrome_timer("chrome"); |
77 for (int i = 0; i < kIterations; ++i) { | 76 for (int i = 0; i < kIterations; ++i) { |
78 for (size_t j = 0; j < test_cases.size(); ++j) { | 77 for (size_t j = 0; j < test_cases.size(); ++j) { |
79 std::string json; | 78 std::string json; |
80 JSONStringValueSerializer reader(&json); | 79 JSONStringValueSerializer reader(&json); |
81 ASSERT_TRUE(reader.Serialize(*test_cases[j])); | 80 ASSERT_TRUE(reader.Serialize(*test_cases[j])); |
82 } | 81 } |
83 } | 82 } |
84 chrome_timer.Done(); | 83 chrome_timer.Done(); |
85 | 84 |
86 // Clean up test cases. | 85 // Clean up test cases. |
87 for (size_t i = 0; i < test_cases.size(); ++i) { | 86 for (size_t i = 0; i < test_cases.size(); ++i) { |
88 delete test_cases[i]; | 87 delete test_cases[i]; |
89 test_cases[i] = NULL; | 88 test_cases[i] = NULL; |
90 } | 89 } |
91 } | 90 } |
92 | 91 |
OLD | NEW |