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

Side by Side Diff: sql/meta_table_unittest.cc

Issue 23649002: Unit tests for sql::MetaTable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sql/sql.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "sql/meta_table.h"
6
7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "sql/connection.h"
10 #include "sql/statement.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 class SQLMetaTableTest : public testing::Test {
16 public:
17 SQLMetaTableTest() {}
Greg Billock 2013/08/29 18:05:40 needed?
Scott Hess - ex-Googler 2013/08/29 23:32:26 You're right. Also removing in the place I did th
18
19 virtual void SetUp() {
20 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
21 ASSERT_TRUE(db_.Open(db_path()));
22 }
23
24 virtual void TearDown() {
25 db_.Close();
26 }
27
28 sql::Connection& db() { return db_; }
29
30 base::FilePath db_path() {
Greg Billock 2013/08/29 18:05:40 private? or just build in SetUp?
Scott Hess - ex-Googler 2013/08/29 23:32:26 Sure. And connection_unittest.cc while I'm there.
Greg Billock 2013/09/06 16:02:09 I meant just build db_path_ in SetUp and don't hav
Scott Hess - ex-Googler 2013/09/06 16:28:28 Done. Didn't even notice that :-).
31 return temp_dir_.path().AppendASCII("SQLMetaTableTest.db");
32 }
33
34 private:
35 base::ScopedTempDir temp_dir_;
36 sql::Connection db_;
Scott Hess - ex-Googler 2013/08/29 23:32:26 Hmm. Also, seems iffy to have temp_dir_ destructe
Greg Billock 2013/09/06 16:02:09 This was right, no? Destruction is in reverse orde
Scott Hess - ex-Googler 2013/09/06 16:28:28 Darn it. You are correct, and I know this, but it
Greg Billock 2013/09/06 23:19:34 :-) I feel your pain. :-)
37 };
38
39 TEST_F(SQLMetaTableTest, DoesTableExist) {
40 EXPECT_FALSE(sql::MetaTable::DoesTableExist(&db()));
41
42 {
43 sql::MetaTable meta_table;
44 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
45 }
46
47 EXPECT_TRUE(sql::MetaTable::DoesTableExist(&db()));
48 }
49
50 TEST_F(SQLMetaTableTest, VersionNumber) {
51 const int kVersionFirst = 2, kCompatVersionFirst = 1;
Greg Billock 2013/08/29 18:05:40 one per line (and below)
Scott Hess - ex-Googler 2013/08/29 23:32:26 Done.
52 const int kVersionSecond = 4, kCompatVersionSecond = 3;
53 const int kVersionThird = 6, kCompatVersionThird = 5;
54
55 // First Init() sets the version info as expected.
56 {
57 sql::MetaTable meta_table;
58 EXPECT_TRUE(meta_table.Init(&db(), kVersionFirst, kCompatVersionFirst));
59 EXPECT_EQ(kVersionFirst, meta_table.GetVersionNumber());
60 EXPECT_EQ(kCompatVersionFirst, meta_table.GetCompatibleVersionNumber());
61 }
62
63 // Second Init() does not change the version info.
64 {
65 sql::MetaTable meta_table;
66 EXPECT_TRUE(meta_table.Init(&db(), kVersionSecond, kCompatVersionSecond));
Greg Billock 2013/08/29 18:05:40 This sure looks like it is changing the version in
Scott Hess - ex-Googler 2013/08/29 23:32:26 I believe that the idea is that on first run, the
67 EXPECT_EQ(kVersionFirst, meta_table.GetVersionNumber());
68 EXPECT_EQ(kCompatVersionFirst, meta_table.GetCompatibleVersionNumber());
69
70 meta_table.SetVersionNumber(kVersionSecond);
71 meta_table.SetCompatibleVersionNumber(kCompatVersionSecond);
72 }
73
74 // Version info from Set*() calls is seen.
75 {
76 sql::MetaTable meta_table;
77 EXPECT_TRUE(meta_table.Init(&db(), kVersionThird, kCompatVersionThird));
78 EXPECT_EQ(kVersionSecond, meta_table.GetVersionNumber());
79 EXPECT_EQ(kCompatVersionSecond, meta_table.GetCompatibleVersionNumber());
80 }
81 }
82
83 TEST_F(SQLMetaTableTest, StringValue) {
84 const char kKey[] = "String Key";
85 const std::string kFirstValue("First Value"), kSecondValue("Second Value");
86
87 // Initially, the value isn't there until set.
88 {
89 sql::MetaTable meta_table;
90 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
91
92 std::string value;
93 EXPECT_FALSE(meta_table.GetValue(kKey, &value));
94
95 EXPECT_TRUE(meta_table.SetValue(kKey, kFirstValue));
96 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
97 EXPECT_EQ(kFirstValue, value);
98 }
99
100 // Value is persistent across different instances.
101 {
102 sql::MetaTable meta_table;
103 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
104
105 std::string value;
106 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
107 EXPECT_EQ(kFirstValue, value);
108
109 EXPECT_TRUE(meta_table.SetValue(kKey, kSecondValue));
110 }
111
112 // Existing value was successfully changed.
113 {
114 sql::MetaTable meta_table;
115 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
116
117 std::string value;
118 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
119 EXPECT_EQ(kSecondValue, value);
120 }
121 }
122
123 TEST_F(SQLMetaTableTest, IntValue) {
124 const char kKey[] = "Int Key";
125 const int kFirstValue = 17, kSecondValue = 23;
126
127 // Initially, the value isn't there until set.
128 {
129 sql::MetaTable meta_table;
130 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
131
132 int value;
133 EXPECT_FALSE(meta_table.GetValue(kKey, &value));
134
135 EXPECT_TRUE(meta_table.SetValue(kKey, kFirstValue));
136 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
137 EXPECT_EQ(kFirstValue, value);
138 }
139
140 // Value is persistent across different instances.
141 {
142 sql::MetaTable meta_table;
143 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
144
145 int value;
146 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
147 EXPECT_EQ(kFirstValue, value);
148
149 EXPECT_TRUE(meta_table.SetValue(kKey, kSecondValue));
150 }
151
152 // Existing value was successfully changed.
153 {
154 sql::MetaTable meta_table;
155 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
156
157 int value;
158 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
159 EXPECT_EQ(kSecondValue, value);
160 }
161 }
162
163 TEST_F(SQLMetaTableTest, Int64Value) {
164 const char kKey[] = "Int Key";
165 const int64 kFirstValue = 5000000017LLU, kSecondValue = 5000000023LLU;
166
167 // Initially, the value isn't there until set.
168 {
169 sql::MetaTable meta_table;
170 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
171
172 int64 value;
173 EXPECT_FALSE(meta_table.GetValue(kKey, &value));
174
175 EXPECT_TRUE(meta_table.SetValue(kKey, kFirstValue));
176 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
177 EXPECT_EQ(kFirstValue, value);
178 }
179
180 // Value is persistent across different instances.
181 {
182 sql::MetaTable meta_table;
183 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
184
185 int64 value;
186 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
187 EXPECT_EQ(kFirstValue, value);
188
189 EXPECT_TRUE(meta_table.SetValue(kKey, kSecondValue));
190 }
191
192 // Existing value was successfully changed.
193 {
194 sql::MetaTable meta_table;
195 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
196
197 int64 value;
198 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
199 EXPECT_EQ(kSecondValue, value);
200 }
201 }
202
203 TEST_F(SQLMetaTableTest, DeleteKey) {
204 const char kKey[] = "String Key";
205 const std::string kValue("String Value");
206
207 sql::MetaTable meta_table;
208 EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
209
210 // Value isn't present.
211 std::string value;
212 EXPECT_FALSE(meta_table.GetValue(kKey, &value));
213
214 // Now value is present.
215 EXPECT_TRUE(meta_table.SetValue(kKey, kValue));
216 EXPECT_TRUE(meta_table.GetValue(kKey, &value));
217 EXPECT_EQ(kValue, value);
218
219 // After delete value isn't present.
220 EXPECT_TRUE(meta_table.DeleteKey(kKey));
221 EXPECT_FALSE(meta_table.GetValue(kKey, &value));
222 }
223
224 } // namespace
OLDNEW
« no previous file with comments | « no previous file | sql/sql.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698