OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/utility/importer/edge_database_reader_win.h" | 5 #include "chrome/utility/importer/edge_database_reader_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/win/windows_version.h" | |
20 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "third_party/zlib/google/compression_utils.h" | 21 #include "third_party/zlib/google/compression_utils.h" |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 class EdgeDatabaseReaderTest : public ::testing::Test { | 25 class EdgeDatabaseReaderTest : public ::testing::Test { |
27 protected: | 26 protected: |
28 bool CopyTestDatabase(const base::string16& database_name, | 27 bool CopyTestDatabase(const base::string16& database_name, |
29 base::FilePath* copied_path) { | 28 base::FilePath* copied_path) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 0; | 64 0; |
66 } | 65 } |
67 | 66 |
68 base::ScopedTempDir temp_dir_; | 67 base::ScopedTempDir temp_dir_; |
69 base::FilePath test_data_path_; | 68 base::FilePath test_data_path_; |
70 }; | 69 }; |
71 | 70 |
72 } // namespace | 71 } // namespace |
73 | 72 |
74 TEST_F(EdgeDatabaseReaderTest, OpenFileTest) { | 73 TEST_F(EdgeDatabaseReaderTest, OpenFileTest) { |
75 // Only verified to work with ESE library on Windows 7 and above. | |
76 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
77 return; | |
78 | |
79 base::FilePath database_path; | 74 base::FilePath database_path; |
80 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 75 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
81 EdgeDatabaseReader reader; | 76 EdgeDatabaseReader reader; |
82 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 77 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
83 } | 78 } |
84 | 79 |
85 TEST_F(EdgeDatabaseReaderTest, NoFileTest) { | 80 TEST_F(EdgeDatabaseReaderTest, NoFileTest) { |
86 // Only verified to work with ESE library on Windows 7 and above. | |
87 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
88 return; | |
89 | |
90 EdgeDatabaseReader reader; | 81 EdgeDatabaseReader reader; |
91 EXPECT_FALSE(reader.OpenDatabase(L"ThisIsntARealFileName.edb")); | 82 EXPECT_FALSE(reader.OpenDatabase(L"ThisIsntARealFileName.edb")); |
92 } | 83 } |
93 | 84 |
94 TEST_F(EdgeDatabaseReaderTest, RandomGarbageDatabaseTest) { | 85 TEST_F(EdgeDatabaseReaderTest, RandomGarbageDatabaseTest) { |
95 // Only verified to work with ESE library on Windows 7 and above. | |
96 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
97 return; | |
98 | |
99 base::FilePath database_path; | 86 base::FilePath database_path; |
100 ASSERT_TRUE(CopyTestDatabase(L"random.edb", &database_path)); | 87 ASSERT_TRUE(CopyTestDatabase(L"random.edb", &database_path)); |
101 EdgeDatabaseReader reader; | 88 EdgeDatabaseReader reader; |
102 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); | 89 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); |
103 } | 90 } |
104 | 91 |
105 TEST_F(EdgeDatabaseReaderTest, ZerosDatabaseTest) { | 92 TEST_F(EdgeDatabaseReaderTest, ZerosDatabaseTest) { |
106 // Only verified to work with ESE library on Windows 7 and above. | |
107 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
108 return; | |
109 | |
110 base::FilePath database_path; | 93 base::FilePath database_path; |
111 std::string zeros(0x10000, '\0'); | 94 std::string zeros(0x10000, '\0'); |
112 ASSERT_TRUE(WriteFile(L"zeros.edb", zeros, &database_path)); | 95 ASSERT_TRUE(WriteFile(L"zeros.edb", zeros, &database_path)); |
113 EdgeDatabaseReader reader; | 96 EdgeDatabaseReader reader; |
114 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); | 97 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); |
115 } | 98 } |
116 | 99 |
117 TEST_F(EdgeDatabaseReaderTest, EmptyDatabaseTest) { | 100 TEST_F(EdgeDatabaseReaderTest, EmptyDatabaseTest) { |
118 // Only verified to work with ESE library on Windows 7 and above. | |
119 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
120 return; | |
121 | |
122 base::FilePath database_path; | 101 base::FilePath database_path; |
123 ASSERT_TRUE(WriteFile(L"empty.edb", "", &database_path)); | 102 ASSERT_TRUE(WriteFile(L"empty.edb", "", &database_path)); |
124 EdgeDatabaseReader reader; | 103 EdgeDatabaseReader reader; |
125 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); | 104 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); |
126 } | 105 } |
127 | 106 |
128 TEST_F(EdgeDatabaseReaderTest, OpenTableDatabaseTest) { | 107 TEST_F(EdgeDatabaseReaderTest, OpenTableDatabaseTest) { |
129 // Only verified to work with ESE library on Windows 7 and above. | |
130 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
131 return; | |
132 | |
133 base::FilePath database_path; | 108 base::FilePath database_path; |
134 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 109 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
135 EdgeDatabaseReader reader; | 110 EdgeDatabaseReader reader; |
136 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 111 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
137 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 112 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
138 reader.OpenTableEnumerator(L"TestTable"); | 113 reader.OpenTableEnumerator(L"TestTable"); |
139 EXPECT_NE(nullptr, table_enum); | 114 EXPECT_NE(nullptr, table_enum); |
140 } | 115 } |
141 | 116 |
142 TEST_F(EdgeDatabaseReaderTest, InvalidTableDatabaseTest) { | 117 TEST_F(EdgeDatabaseReaderTest, InvalidTableDatabaseTest) { |
143 // Only verified to work with ESE library on Windows 7 and above. | |
144 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
145 return; | |
146 | |
147 base::FilePath database_path; | 118 base::FilePath database_path; |
148 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 119 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
149 EdgeDatabaseReader reader; | 120 EdgeDatabaseReader reader; |
150 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 121 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
151 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 122 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
152 reader.OpenTableEnumerator(L"NotARealTableName"); | 123 reader.OpenTableEnumerator(L"NotARealTableName"); |
153 EXPECT_EQ(nullptr, table_enum); | 124 EXPECT_EQ(nullptr, table_enum); |
154 } | 125 } |
155 | 126 |
156 TEST_F(EdgeDatabaseReaderTest, NotOpenDatabaseTest) { | 127 TEST_F(EdgeDatabaseReaderTest, NotOpenDatabaseTest) { |
157 // Only verified to work with ESE library on Windows 7 and above. | |
158 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
159 return; | |
160 | |
161 EdgeDatabaseReader reader; | 128 EdgeDatabaseReader reader; |
162 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 129 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
163 reader.OpenTableEnumerator(L"TestTable"); | 130 reader.OpenTableEnumerator(L"TestTable"); |
164 EXPECT_EQ(nullptr, table_enum); | 131 EXPECT_EQ(nullptr, table_enum); |
165 EXPECT_EQ(JET_errDatabaseNotFound, reader.last_error()); | 132 EXPECT_EQ(JET_errDatabaseNotFound, reader.last_error()); |
166 } | 133 } |
167 | 134 |
168 TEST_F(EdgeDatabaseReaderTest, AlreadyOpenDatabaseTest) { | 135 TEST_F(EdgeDatabaseReaderTest, AlreadyOpenDatabaseTest) { |
169 // Only verified to work with ESE library on Windows 7 and above. | |
170 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
171 return; | |
172 | |
173 base::FilePath database_path; | 136 base::FilePath database_path; |
174 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 137 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
175 EdgeDatabaseReader reader; | 138 EdgeDatabaseReader reader; |
176 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 139 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
177 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); | 140 EXPECT_FALSE(reader.OpenDatabase(database_path.value())); |
178 EXPECT_EQ(JET_errOneDatabasePerSession, reader.last_error()); | 141 EXPECT_EQ(JET_errOneDatabasePerSession, reader.last_error()); |
179 } | 142 } |
180 | 143 |
181 TEST_F(EdgeDatabaseReaderTest, OpenTableAndReadDataDatabaseTest) { | 144 TEST_F(EdgeDatabaseReaderTest, OpenTableAndReadDataDatabaseTest) { |
182 // Only verified to work with ESE library on Windows 7 and above. | |
183 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
184 return; | |
185 | |
186 base::FilePath database_path; | 145 base::FilePath database_path; |
187 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 146 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
188 EdgeDatabaseReader reader; | 147 EdgeDatabaseReader reader; |
189 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 148 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
190 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 149 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
191 reader.OpenTableEnumerator(L"TestTable"); | 150 reader.OpenTableEnumerator(L"TestTable"); |
192 EXPECT_NE(nullptr, table_enum); | 151 EXPECT_NE(nullptr, table_enum); |
193 int row_count = 0; | 152 int row_count = 0; |
194 do { | 153 do { |
195 int32_t int_col_value = 0; | 154 int32_t int_col_value = 0; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 bool bool_col_value; | 194 bool bool_col_value; |
236 EXPECT_TRUE(table_enum->RetrieveColumn(L"BoolCol", &bool_col_value)); | 195 EXPECT_TRUE(table_enum->RetrieveColumn(L"BoolCol", &bool_col_value)); |
237 EXPECT_EQ((row_count % 2) == 0, bool_col_value); | 196 EXPECT_EQ((row_count % 2) == 0, bool_col_value); |
238 | 197 |
239 row_count++; | 198 row_count++; |
240 } while (table_enum->Next()); | 199 } while (table_enum->Next()); |
241 EXPECT_EQ(16, row_count); | 200 EXPECT_EQ(16, row_count); |
242 } | 201 } |
243 | 202 |
244 TEST_F(EdgeDatabaseReaderTest, CheckEnumResetDatabaseTest) { | 203 TEST_F(EdgeDatabaseReaderTest, CheckEnumResetDatabaseTest) { |
245 // Only verified to work with ESE library on Windows 7 and above. | |
246 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
247 return; | |
248 | |
249 base::FilePath database_path; | 204 base::FilePath database_path; |
250 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 205 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
251 EdgeDatabaseReader reader; | 206 EdgeDatabaseReader reader; |
252 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 207 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
253 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 208 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
254 reader.OpenTableEnumerator(L"TestTable"); | 209 reader.OpenTableEnumerator(L"TestTable"); |
255 EXPECT_NE(nullptr, table_enum); | 210 EXPECT_NE(nullptr, table_enum); |
256 int row_count = 0; | 211 int row_count = 0; |
257 do { | 212 do { |
258 row_count++; | 213 row_count++; |
259 } while (table_enum->Next()); | 214 } while (table_enum->Next()); |
260 EXPECT_NE(0, row_count); | 215 EXPECT_NE(0, row_count); |
261 EXPECT_TRUE(table_enum->Reset()); | 216 EXPECT_TRUE(table_enum->Reset()); |
262 do { | 217 do { |
263 row_count--; | 218 row_count--; |
264 } while (table_enum->Next()); | 219 } while (table_enum->Next()); |
265 EXPECT_EQ(0, row_count); | 220 EXPECT_EQ(0, row_count); |
266 } | 221 } |
267 | 222 |
268 TEST_F(EdgeDatabaseReaderTest, InvalidColumnDatabaseTest) { | 223 TEST_F(EdgeDatabaseReaderTest, InvalidColumnDatabaseTest) { |
269 // Only verified to work with ESE library on Windows 7 and above. | |
270 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
271 return; | |
272 | |
273 base::FilePath database_path; | 224 base::FilePath database_path; |
274 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 225 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
275 EdgeDatabaseReader reader; | 226 EdgeDatabaseReader reader; |
276 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 227 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
277 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 228 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
278 reader.OpenTableEnumerator(L"TestTable"); | 229 reader.OpenTableEnumerator(L"TestTable"); |
279 EXPECT_NE(nullptr, table_enum); | 230 EXPECT_NE(nullptr, table_enum); |
280 int32_t int_col_value = 0; | 231 int32_t int_col_value = 0; |
281 EXPECT_FALSE(table_enum->RetrieveColumn(L"NotARealNameCol", &int_col_value)); | 232 EXPECT_FALSE(table_enum->RetrieveColumn(L"NotARealNameCol", &int_col_value)); |
282 EXPECT_EQ(JET_errColumnNotFound, table_enum->last_error()); | 233 EXPECT_EQ(JET_errColumnNotFound, table_enum->last_error()); |
283 } | 234 } |
284 | 235 |
285 TEST_F(EdgeDatabaseReaderTest, NoColumnDatabaseTest) { | 236 TEST_F(EdgeDatabaseReaderTest, NoColumnDatabaseTest) { |
286 // Only verified to work with ESE library on Windows 7 and above. | |
287 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
288 return; | |
289 | |
290 base::FilePath database_path; | 237 base::FilePath database_path; |
291 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 238 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
292 EdgeDatabaseReader reader; | 239 EdgeDatabaseReader reader; |
293 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 240 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
294 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 241 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
295 reader.OpenTableEnumerator(L"NoColsTable"); | 242 reader.OpenTableEnumerator(L"NoColsTable"); |
296 EXPECT_NE(nullptr, table_enum); | 243 EXPECT_NE(nullptr, table_enum); |
297 int32_t int_col_value = 0; | 244 int32_t int_col_value = 0; |
298 EXPECT_FALSE(table_enum->RetrieveColumn(L"IntCol", &int_col_value)); | 245 EXPECT_FALSE(table_enum->RetrieveColumn(L"IntCol", &int_col_value)); |
299 EXPECT_EQ(JET_errColumnNotFound, table_enum->last_error()); | 246 EXPECT_EQ(JET_errColumnNotFound, table_enum->last_error()); |
300 } | 247 } |
301 | 248 |
302 TEST_F(EdgeDatabaseReaderTest, EmptyTableDatabaseTest) { | 249 TEST_F(EdgeDatabaseReaderTest, EmptyTableDatabaseTest) { |
303 // Only verified to work with ESE library on Windows 7 and above. | |
304 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
305 return; | |
306 | |
307 base::FilePath database_path; | 250 base::FilePath database_path; |
308 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 251 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
309 EdgeDatabaseReader reader; | 252 EdgeDatabaseReader reader; |
310 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 253 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
311 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 254 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
312 reader.OpenTableEnumerator(L"EmptyTable"); | 255 reader.OpenTableEnumerator(L"EmptyTable"); |
313 EXPECT_NE(nullptr, table_enum); | 256 EXPECT_NE(nullptr, table_enum); |
314 int32_t int_col_value = 0; | 257 int32_t int_col_value = 0; |
315 EXPECT_FALSE(table_enum->RetrieveColumn(L"IntCol", &int_col_value)); | 258 EXPECT_FALSE(table_enum->RetrieveColumn(L"IntCol", &int_col_value)); |
316 EXPECT_NE(JET_errColumnNotFound, table_enum->last_error()); | 259 EXPECT_NE(JET_errColumnNotFound, table_enum->last_error()); |
317 EXPECT_FALSE(table_enum->Reset()); | 260 EXPECT_FALSE(table_enum->Reset()); |
318 EXPECT_FALSE(table_enum->Next()); | 261 EXPECT_FALSE(table_enum->Next()); |
319 } | 262 } |
320 | 263 |
321 TEST_F(EdgeDatabaseReaderTest, UnicodeStringsDatabaseTest) { | 264 TEST_F(EdgeDatabaseReaderTest, UnicodeStringsDatabaseTest) { |
322 const char* utf8_strings[] = { | 265 const char* utf8_strings[] = { |
323 "\xE3\x81\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF", | 266 "\xE3\x81\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF", |
324 "\xE4\xBD\xA0\xE5\xA5\xBD", | 267 "\xE4\xBD\xA0\xE5\xA5\xBD", |
325 "\xD0\x97\xD0\xB4\xD1\x80\xD0\xB0\xD0\xB2\xD1\x81\xD1\x82\xD0\xB2\xD1\x83" | 268 "\xD0\x97\xD0\xB4\xD1\x80\xD0\xB0\xD0\xB2\xD1\x81\xD1\x82\xD0\xB2\xD1\x83" |
326 "\xD0\xB9\xD1\x82\xD0\xB5", | 269 "\xD0\xB9\xD1\x82\xD0\xB5", |
327 "\x48\x65\x6C\x6C\x6F", | 270 "\x48\x65\x6C\x6C\x6F", |
328 "\xEC\x95\x88\xEB\x85\x95\xED\x95\x98\xEC\x84\xB8\xEC\x9A\x94", | 271 "\xEC\x95\x88\xEB\x85\x95\xED\x95\x98\xEC\x84\xB8\xEC\x9A\x94", |
329 }; | 272 }; |
330 // Only verified to work with ESE library on Windows 7 and above. | |
331 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
332 return; | |
333 | 273 |
334 base::FilePath database_path; | 274 base::FilePath database_path; |
335 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 275 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
336 EdgeDatabaseReader reader; | 276 EdgeDatabaseReader reader; |
337 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 277 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
338 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 278 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
339 reader.OpenTableEnumerator(L"UnicodeTable"); | 279 reader.OpenTableEnumerator(L"UnicodeTable"); |
340 EXPECT_NE(nullptr, table_enum); | 280 EXPECT_NE(nullptr, table_enum); |
341 size_t utf8_strings_count = arraysize(utf8_strings); | 281 size_t utf8_strings_count = arraysize(utf8_strings); |
342 for (size_t row_count = 0; row_count < utf8_strings_count; ++row_count) { | 282 for (size_t row_count = 0; row_count < utf8_strings_count; ++row_count) { |
343 std::wstring row_string = base::UTF8ToWide(utf8_strings[row_count]); | 283 std::wstring row_string = base::UTF8ToWide(utf8_strings[row_count]); |
344 base::string16 str_col_value; | 284 base::string16 str_col_value; |
345 EXPECT_TRUE(table_enum->RetrieveColumn(L"StrCol", &str_col_value)); | 285 EXPECT_TRUE(table_enum->RetrieveColumn(L"StrCol", &str_col_value)); |
346 EXPECT_EQ(row_string, str_col_value); | 286 EXPECT_EQ(row_string, str_col_value); |
347 if (row_count < utf8_strings_count - 1) | 287 if (row_count < utf8_strings_count - 1) |
348 EXPECT_TRUE(table_enum->Next()); | 288 EXPECT_TRUE(table_enum->Next()); |
349 else | 289 else |
350 EXPECT_FALSE(table_enum->Next()); | 290 EXPECT_FALSE(table_enum->Next()); |
351 } | 291 } |
352 } | 292 } |
353 | 293 |
354 TEST_F(EdgeDatabaseReaderTest, NonUnicodeStringsDatabaseTest) { | 294 TEST_F(EdgeDatabaseReaderTest, NonUnicodeStringsDatabaseTest) { |
355 // Only verified to work with ESE library on Windows 7 and above. | |
356 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
357 return; | |
358 | |
359 base::FilePath database_path; | 295 base::FilePath database_path; |
360 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 296 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
361 EdgeDatabaseReader reader; | 297 EdgeDatabaseReader reader; |
362 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 298 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
363 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 299 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
364 reader.OpenTableEnumerator(L"NonUnicodeTable"); | 300 reader.OpenTableEnumerator(L"NonUnicodeTable"); |
365 EXPECT_NE(nullptr, table_enum); | 301 EXPECT_NE(nullptr, table_enum); |
366 base::string16 str_col_value; | 302 base::string16 str_col_value; |
367 EXPECT_FALSE(table_enum->RetrieveColumn(L"StrCol", &str_col_value)); | 303 EXPECT_FALSE(table_enum->RetrieveColumn(L"StrCol", &str_col_value)); |
368 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 304 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
369 } | 305 } |
370 | 306 |
371 TEST_F(EdgeDatabaseReaderTest, CheckNullColumnDatabaseTest) { | 307 TEST_F(EdgeDatabaseReaderTest, CheckNullColumnDatabaseTest) { |
372 // Only verified to work with ESE library on Windows 7 and above. | |
373 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
374 return; | |
375 | |
376 base::FilePath database_path; | 308 base::FilePath database_path; |
377 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 309 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
378 EdgeDatabaseReader reader; | 310 EdgeDatabaseReader reader; |
379 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 311 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
380 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 312 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
381 reader.OpenTableEnumerator(L"NullTable"); | 313 reader.OpenTableEnumerator(L"NullTable"); |
382 EXPECT_NE(nullptr, table_enum); | 314 EXPECT_NE(nullptr, table_enum); |
383 | 315 |
384 // We expect to successfully open a column value but get the default value | 316 // We expect to successfully open a column value but get the default value |
385 // back. | 317 // back. |
(...skipping 27 matching lines...) Expand all Loading... |
413 base::string16 str_col_value; | 345 base::string16 str_col_value; |
414 EXPECT_TRUE(table_enum->RetrieveColumn(L"StrCol", &str_col_value)); | 346 EXPECT_TRUE(table_enum->RetrieveColumn(L"StrCol", &str_col_value)); |
415 EXPECT_TRUE(str_col_value.empty()); | 347 EXPECT_TRUE(str_col_value.empty()); |
416 | 348 |
417 bool bool_col_value; | 349 bool bool_col_value; |
418 EXPECT_TRUE(table_enum->RetrieveColumn(L"BoolCol", &bool_col_value)); | 350 EXPECT_TRUE(table_enum->RetrieveColumn(L"BoolCol", &bool_col_value)); |
419 EXPECT_EQ(false, bool_col_value); | 351 EXPECT_EQ(false, bool_col_value); |
420 } | 352 } |
421 | 353 |
422 TEST_F(EdgeDatabaseReaderTest, CheckInvalidColumnTypeDatabaseTest) { | 354 TEST_F(EdgeDatabaseReaderTest, CheckInvalidColumnTypeDatabaseTest) { |
423 // Only verified to work with ESE library on Windows 7 and above. | |
424 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
425 return; | |
426 | |
427 base::FilePath database_path; | 355 base::FilePath database_path; |
428 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); | 356 ASSERT_TRUE(CopyTestDatabase(L"testdata.edb", &database_path)); |
429 EdgeDatabaseReader reader; | 357 EdgeDatabaseReader reader; |
430 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); | 358 EXPECT_TRUE(reader.OpenDatabase(database_path.value())); |
431 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = | 359 std::unique_ptr<EdgeDatabaseTableEnumerator> table_enum = |
432 reader.OpenTableEnumerator(L"TestTable"); | 360 reader.OpenTableEnumerator(L"TestTable"); |
433 EXPECT_NE(nullptr, table_enum); | 361 EXPECT_NE(nullptr, table_enum); |
434 | 362 |
435 uint32_t uint_col_value = 0; | 363 uint32_t uint_col_value = 0; |
436 EXPECT_FALSE(table_enum->RetrieveColumn(L"IntCol", &uint_col_value)); | 364 EXPECT_FALSE(table_enum->RetrieveColumn(L"IntCol", &uint_col_value)); |
437 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 365 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
438 // Check unsigned int with a signed int. | 366 // Check unsigned int with a signed int. |
439 int32_t int_col_value = 0; | 367 int32_t int_col_value = 0; |
440 EXPECT_FALSE(table_enum->RetrieveColumn(L"UIntCol", &int_col_value)); | 368 EXPECT_FALSE(table_enum->RetrieveColumn(L"UIntCol", &int_col_value)); |
441 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 369 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
442 EXPECT_FALSE(table_enum->RetrieveColumn(L"LongLongCol", &uint_col_value)); | 370 EXPECT_FALSE(table_enum->RetrieveColumn(L"LongLongCol", &uint_col_value)); |
443 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 371 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
444 EXPECT_FALSE(table_enum->RetrieveColumn(L"GuidCol", &uint_col_value)); | 372 EXPECT_FALSE(table_enum->RetrieveColumn(L"GuidCol", &uint_col_value)); |
445 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 373 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
446 EXPECT_FALSE(table_enum->RetrieveColumn(L"DateCol", &uint_col_value)); | 374 EXPECT_FALSE(table_enum->RetrieveColumn(L"DateCol", &uint_col_value)); |
447 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 375 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
448 EXPECT_FALSE(table_enum->RetrieveColumn(L"StrCol", &uint_col_value)); | 376 EXPECT_FALSE(table_enum->RetrieveColumn(L"StrCol", &uint_col_value)); |
449 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 377 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
450 EXPECT_FALSE(table_enum->RetrieveColumn(L"BoolCol", &uint_col_value)); | 378 EXPECT_FALSE(table_enum->RetrieveColumn(L"BoolCol", &uint_col_value)); |
451 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); | 379 EXPECT_EQ(JET_errInvalidColumnType, table_enum->last_error()); |
452 } | 380 } |
OLD | NEW |