| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace crashpad { | 23 namespace crashpad { |
| 24 namespace test { | 24 namespace test { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 bool FileExistsAtPath(const base::FilePath& path) { | 27 bool FileExistsAtPath(const base::FilePath& path) { |
| 28 #if defined(OS_POSIX) | 28 #if defined(OS_POSIX) |
| 29 struct stat st; | 29 struct stat st; |
| 30 return lstat(path.value().c_str(), &st) == 0; | 30 return lstat(path.value().c_str(), &st) == 0; |
| 31 #elif defined(OS_WIN) | 31 #elif defined(OS_WIN) |
| 32 struct _stat st; | 32 struct _stat st; |
| 33 return _wstat(path.value().c_str(), &st); | 33 return _wstat(path.value().c_str(), &st) == 0; |
| 34 #else | 34 #else |
| 35 #error "Not implemented" | 35 #error "Not implemented" |
| 36 #endif | 36 #endif |
| 37 } | 37 } |
| 38 | 38 |
| 39 void CreateFile(const base::FilePath& path) { | 39 void CreateFile(const base::FilePath& path) { |
| 40 FileHandle handle = LoggingOpenFileForWrite(path, | 40 FileHandle handle = LoggingOpenFileForWrite(path, |
| 41 FileWriteMode::kCreateOrFail, | 41 FileWriteMode::kCreateOrFail, |
| 42 FilePermissions::kWorldReadable); | 42 FilePermissions::kWorldReadable); |
| 43 #if defined(OS_POSIX) | 43 #if defined(OS_POSIX) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 EXPECT_NE(UUID(), report.uuid); | 100 EXPECT_NE(UUID(), report.uuid); |
| 101 EXPECT_FALSE(report.file_path.empty()); | 101 EXPECT_FALSE(report.file_path.empty()); |
| 102 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); | 102 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); |
| 103 EXPECT_TRUE(report.id.empty()); | 103 EXPECT_TRUE(report.id.empty()); |
| 104 EXPECT_GT(report.creation_time, 0); | 104 EXPECT_GT(report.creation_time, 0); |
| 105 EXPECT_FALSE(report.uploaded); | 105 EXPECT_FALSE(report.uploaded); |
| 106 EXPECT_EQ(0, report.last_upload_attempt_time); | 106 EXPECT_EQ(0, report.last_upload_attempt_time); |
| 107 EXPECT_EQ(0, report.upload_attempts); | 107 EXPECT_EQ(0, report.upload_attempts); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void RelocateDatabase() { |
| 111 ResetDatabase(); |
| 112 temp_dir_.Rename(); |
| 113 SetUp(); |
| 114 } |
| 115 |
| 110 private: | 116 private: |
| 111 ScopedTempDir temp_dir_; | 117 ScopedTempDir temp_dir_; |
| 112 scoped_ptr<CrashReportDatabase> db_; | 118 scoped_ptr<CrashReportDatabase> db_; |
| 113 }; | 119 }; |
| 114 | 120 |
| 115 TEST_F(CrashReportDatabaseTest, Initialize) { | 121 TEST_F(CrashReportDatabaseTest, Initialize) { |
| 116 // Initialize the database for the first time, creating it. | 122 // Initialize the database for the first time, creating it. |
| 117 EXPECT_TRUE(db()); | 123 EXPECT_TRUE(db()); |
| 118 | 124 |
| 119 // Close and reopen the database at the same path. | 125 // Close and reopen the database at the same path. |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 433 |
| 428 const CrashReportDatabase::Report* upload_report_2 = nullptr; | 434 const CrashReportDatabase::Report* upload_report_2 = nullptr; |
| 429 EXPECT_EQ(CrashReportDatabase::kBusyError, | 435 EXPECT_EQ(CrashReportDatabase::kBusyError, |
| 430 db()->GetReportForUploading(report.uuid, &upload_report_2)); | 436 db()->GetReportForUploading(report.uuid, &upload_report_2)); |
| 431 EXPECT_FALSE(upload_report_2); | 437 EXPECT_FALSE(upload_report_2); |
| 432 | 438 |
| 433 EXPECT_EQ(CrashReportDatabase::kNoError, | 439 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 434 db()->RecordUploadAttempt(upload_report, true, "")); | 440 db()->RecordUploadAttempt(upload_report, true, "")); |
| 435 } | 441 } |
| 436 | 442 |
| 443 TEST_F(CrashReportDatabaseTest, MoveDatabase) { |
| 444 CrashReportDatabase::NewReport* new_report; |
| 445 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 446 db()->PrepareNewCrashReport(&new_report)); |
| 447 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); |
| 448 UUID uuid; |
| 449 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 450 db()->FinishedWritingCrashReport(new_report, &uuid)); |
| 451 |
| 452 RelocateDatabase(); |
| 453 |
| 454 CrashReportDatabase::Report report; |
| 455 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 456 db()->LookUpCrashReport(uuid, &report)); |
| 457 ExpectPreparedCrashReport(report); |
| 458 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); |
| 459 } |
| 460 |
| 437 } // namespace | 461 } // namespace |
| 438 } // namespace test | 462 } // namespace test |
| 439 } // namespace crashpad | 463 } // namespace crashpad |
| OLD | NEW |