OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "sql/connection.h" | 14 #include "sql/connection.h" |
15 #include "sql/statement.h" | 15 #include "sql/statement.h" |
16 #include "sql/test/sql_test_base.h" | 16 #include "sql/test/sql_test_base.h" |
17 #include "sql/test/test_helpers.h" | 17 #include "sql/test/test_helpers.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/sqlite/sqlite3.h" | 19 #include "third_party/sqlite/sqlite3.h" |
20 | 20 |
21 #if defined(OS_IOS) | 21 #if defined(OS_IOS) |
22 #include "base/ios/ios_util.h" | 22 #include "base/ios/ios_util.h" |
23 #endif | 23 #endif |
24 | 24 |
| 25 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 26 #include <CoreFoundation/CoreFoundation.h> |
| 27 #include <CoreServices/CoreServices.h> |
| 28 |
| 29 #include "base/mac/mac_util.h" |
| 30 #include "base/mac/scoped_cftyperef.h" |
| 31 #endif |
| 32 |
25 // Test that certain features are/are-not enabled in our SQLite. | 33 // Test that certain features are/are-not enabled in our SQLite. |
26 | 34 |
27 namespace { | 35 namespace { |
28 | 36 |
29 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, | 37 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, |
30 int error, sql::Statement* stmt) { | 38 int error, sql::Statement* stmt) { |
31 *error_pointer = error; | 39 *error_pointer = error; |
32 const char* text = stmt ? stmt->GetSQLStatement() : NULL; | 40 const char* text = stmt ? stmt->GetSQLStatement() : NULL; |
33 *sql_text = text ? text : "no statement available"; | 41 *sql_text = text ? text : "no statement available"; |
34 } | 42 } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 s.BindString(0, ".*test"); | 304 s.BindString(0, ".*test"); |
297 ASSERT_TRUE(s.Step()); | 305 ASSERT_TRUE(s.Step()); |
298 EXPECT_EQ(3, s.ColumnInt(0)); | 306 EXPECT_EQ(3, s.ColumnInt(0)); |
299 | 307 |
300 s.Reset(true); | 308 s.Reset(true); |
301 s.BindString(0, ".* s[a-z]+"); | 309 s.BindString(0, ".* s[a-z]+"); |
302 ASSERT_TRUE(s.Step()); | 310 ASSERT_TRUE(s.Step()); |
303 EXPECT_EQ(7, s.ColumnInt(0)); | 311 EXPECT_EQ(7, s.ColumnInt(0)); |
304 } | 312 } |
305 | 313 |
| 314 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 315 CFURLRef CFURLRefForPath(const base::FilePath& path){ |
| 316 base::ScopedCFTypeRef<CFStringRef> urlString( |
| 317 CFStringCreateWithFileSystemRepresentation( |
| 318 kCFAllocatorDefault, path.value().c_str())); |
| 319 return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlString, |
| 320 kCFURLPOSIXPathStyle, FALSE); |
| 321 } |
| 322 |
| 323 void gross() { |
| 324 CFPreferencesSetAppValue(CFSTR("CSBackupDebugLogging"), |
| 325 kCFBooleanTrue, |
| 326 kCFPreferencesCurrentApplication); |
| 327 } |
| 328 |
| 329 // If a database file is marked to be excluded from Time Machine, verify that |
| 330 // journal files are also excluded. |
| 331 TEST_F(SQLiteFeaturesTest, TimeMachine) { |
| 332 gross(); |
| 333 LOG(ERROR) << __FUNCTION__ << " geteuid() " << geteuid(); |
| 334 ASSERT_TRUE(db().Execute("CREATE TABLE t (id INTEGER PRIMARY KEY)")); |
| 335 db().Close(); |
| 336 |
| 337 { |
| 338 LOG(ERROR) << "Mount output:"; |
| 339 FILE* m = popen("mount", "r"); |
| 340 if (!m) { |
| 341 PLOG(ERROR) << "Failed to open mount"; |
| 342 } else { |
| 343 char buf[1024]; |
| 344 while (fgets(buf, sizeof(buf), m)) { |
| 345 size_t l = strlen(buf); |
| 346 if (buf[l - 1] == '\n') |
| 347 buf[l - 1] = '\0'; |
| 348 LOG(ERROR) << buf; |
| 349 } |
| 350 pclose(m); |
| 351 } |
| 352 } |
| 353 { |
| 354 LOG(ERROR) << "Ps output:"; |
| 355 FILE* m = popen("ps ax", "r"); |
| 356 if (!m) { |
| 357 PLOG(ERROR) << "Failed to open ps"; |
| 358 } else { |
| 359 char buf[1024]; |
| 360 while (fgets(buf, sizeof(buf), m)) { |
| 361 size_t l = strlen(buf); |
| 362 if (buf[l - 1] == '\n') |
| 363 buf[l - 1] = '\0'; |
| 364 LOG(ERROR) << buf; |
| 365 } |
| 366 pclose(m); |
| 367 } |
| 368 } |
| 369 base::FilePath journal(db_path().value() + FILE_PATH_LITERAL("-journal")); |
| 370 ASSERT_TRUE(GetPathExists(db_path())); |
| 371 ASSERT_TRUE(GetPathExists(journal)); |
| 372 |
| 373 base::ScopedCFTypeRef<CFURLRef> dbURL(CFURLRefForPath(db_path())); |
| 374 base::ScopedCFTypeRef<CFURLRef> journalURL(CFURLRefForPath(journal)); |
| 375 |
| 376 // Not excluded to start. |
| 377 EXPECT_FALSE(CSBackupIsItemExcluded(dbURL, NULL)); |
| 378 EXPECT_FALSE(CSBackupIsItemExcluded(journalURL, NULL)); |
| 379 |
| 380 // Exclude the main database file. |
| 381 EXPECT_TRUE(base::mac::SetFileBackupExclusion(db_path())); |
| 382 |
| 383 Boolean excluded_by_path = FALSE; |
| 384 EXPECT_TRUE(CSBackupIsItemExcluded(dbURL, &excluded_by_path)); |
| 385 EXPECT_FALSE(excluded_by_path); |
| 386 EXPECT_FALSE(CSBackupIsItemExcluded(journalURL, NULL)); |
| 387 |
| 388 EXPECT_TRUE(db().Open(db_path())); |
| 389 ASSERT_TRUE(db().Execute("INSERT INTO t VALUES (1)")); |
| 390 EXPECT_TRUE(CSBackupIsItemExcluded(dbURL, &excluded_by_path)); |
| 391 EXPECT_FALSE(excluded_by_path); |
| 392 EXPECT_TRUE(CSBackupIsItemExcluded(journalURL, &excluded_by_path)); |
| 393 EXPECT_FALSE(excluded_by_path); |
| 394 |
| 395 // TODO(shess): In WAL mode this will touch -wal and -shm files. -shm files |
| 396 // could be always excluded. |
| 397 } |
| 398 #endif |
| 399 |
306 } // namespace | 400 } // namespace |
OLD | NEW |