Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 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) |
| 44 ASSERT_GE(handle, 0); | 44 ASSERT_GE(handle, 0); |
| 45 #elif defined(OS_WIN) | 45 #elif defined(OS_WIN) |
| 46 ASSERT_NE(handle, nullptr); | 46 ASSERT_NE(handle, nullptr); |
|
Peter Kasting
2015/02/13 00:32:38
Nit: (expected, actual) for gtest ASSERT/EXPECT_EQ
scottmg
2015/02/13 06:34:01
So yoda ugly! Done.
Mark Mentovai
2015/02/13 14:08:37
Peter Kasting wrote:
scottmg
2015/02/13 17:26:41
Thanks, removed.
| |
| 47 #endif | 47 #endif |
| 48 ASSERT_TRUE( | 48 ASSERT_TRUE( |
| 49 LoggingWriteFile(handle, path.value().c_str(), path.value().length())); | 49 LoggingWriteFile(handle, path.value().c_str(), path.value().length())); |
| 50 ASSERT_TRUE(LoggingCloseFile(handle)); | 50 ASSERT_TRUE(LoggingCloseFile(handle)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 class CrashReportDatabaseTest : public testing::Test { | 53 class CrashReportDatabaseTest : public testing::Test { |
| 54 protected: | 54 protected: |
| 55 // testing::Test: | 55 // testing::Test: |
| 56 void SetUp() override { | 56 void SetUp() override { |
| 57 db_ = CrashReportDatabase::Initialize(path()); | 57 db_ = CrashReportDatabase::Initialize(path()); |
| 58 ASSERT_TRUE(db_.get()); | 58 ASSERT_TRUE(db_.get()); |
|
Peter Kasting
2015/02/13 00:32:38
I believe .get() is unnecessary here (multiple pla
scottmg
2015/02/13 06:34:01
Done. (2 locations)
| |
| 59 } | 59 } |
| 60 | 60 |
| 61 void ResetDatabase() { | 61 void ResetDatabase() { |
| 62 db_.reset(); | 62 db_.reset(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 CrashReportDatabase* db() const { return db_.get(); } | 65 CrashReportDatabase* db() const { return db_.get(); } |
|
Peter Kasting
2015/02/13 00:32:38
Const functions should not return pointers to non-
scottmg
2015/02/13 06:34:01
Done.
| |
| 66 const base::FilePath& path() const { return temp_dir_.path(); } | 66 const base::FilePath& path() const { return temp_dir_.path(); } |
| 67 | 67 |
| 68 void CreateCrashReport(CrashReportDatabase::Report* report) { | 68 void CreateCrashReport(CrashReportDatabase::Report* report) { |
| 69 CrashReportDatabase::NewReport* new_report; | 69 CrashReportDatabase::NewReport* new_report; |
|
Peter Kasting
2015/02/13 00:32:38
Nit: Should this be initialized? You don't do it
scottmg
2015/02/13 06:34:01
Done.
| |
| 70 EXPECT_EQ(CrashReportDatabase::kNoError, | 70 EXPECT_EQ(CrashReportDatabase::kNoError, |
|
Peter Kasting
2015/02/13 00:32:38
Change to ASSERT_EQ or add an ASSERT_TRUE(new_repo
scottmg
2015/02/13 06:34:01
Done.
| |
| 71 db_->PrepareNewCrashReport(&new_report)); | 71 db_->PrepareNewCrashReport(&new_report)); |
| 72 const char kTest[] = "test"; | 72 const char kTest[] = "test"; |
| 73 ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); | 73 ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); |
| 74 | 74 |
| 75 UUID uuid; | 75 UUID uuid; |
| 76 EXPECT_EQ(CrashReportDatabase::kNoError, | 76 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 77 db_->FinishedWritingCrashReport(new_report, &uuid)); | 77 db_->FinishedWritingCrashReport(new_report, &uuid)); |
| 78 | 78 |
| 79 EXPECT_EQ(CrashReportDatabase::kNoError, | 79 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 80 db_->LookUpCrashReport(uuid, report)); | 80 db_->LookUpCrashReport(uuid, report)); |
| 81 ExpectPreparedCrashReport(*report); | 81 ExpectPreparedCrashReport(*report); |
| 82 ASSERT_TRUE(FileExistsAtPath(report->file_path)); | 82 ASSERT_TRUE(FileExistsAtPath(report->file_path)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void UploadReport(const UUID& uuid, bool successful, const std::string& id) { | 85 void UploadReport(const UUID& uuid, bool successful, const std::string& id) { |
| 86 const CrashReportDatabase::Report* report = nullptr; | 86 const CrashReportDatabase::Report* report = nullptr; |
| 87 EXPECT_EQ(CrashReportDatabase::kNoError, | 87 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 88 db_->GetReportForUploading(uuid, &report)); | 88 db_->GetReportForUploading(uuid, &report)); |
| 89 EXPECT_TRUE(report); | 89 EXPECT_TRUE(report); |
|
Peter Kasting
2015/02/13 00:32:38
Again, this should be ASSERT_TRUE, or the EXPECT_E
scottmg
2015/02/13 06:34:01
Done.
| |
| 90 EXPECT_NE(UUID(), report->uuid); | 90 EXPECT_NE(UUID(), report->uuid); |
| 91 EXPECT_FALSE(report->file_path.empty()); | 91 EXPECT_FALSE(report->file_path.empty()); |
| 92 EXPECT_TRUE(FileExistsAtPath(report->file_path)) | 92 EXPECT_TRUE(FileExistsAtPath(report->file_path)) |
| 93 << report->file_path.value(); | 93 << report->file_path.value(); |
| 94 EXPECT_GT(report->creation_time, 0); | 94 EXPECT_GT(report->creation_time, 0); |
| 95 EXPECT_EQ(CrashReportDatabase::kNoError, | 95 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 96 db_->RecordUploadAttempt(report, successful, id)); | 96 db_->RecordUploadAttempt(report, successful, id)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) { | 99 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) { |
| 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() { | 110 void RelocateDatabase() { |
| 111 ResetDatabase(); | 111 ResetDatabase(); |
| 112 temp_dir_.Rename(); | 112 temp_dir_.Rename(); |
| 113 SetUp(); | 113 SetUp(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 ScopedTempDir temp_dir_; | 117 ScopedTempDir temp_dir_; |
| 118 scoped_ptr<CrashReportDatabase> db_; | 118 scoped_ptr<CrashReportDatabase> db_; |
| 119 }; | 119 }; |
|
Peter Kasting
2015/02/13 00:32:38
DISALLOW_COPY_AND_ASSIGN()
scottmg
2015/02/13 06:34:01
Done.
| |
| 120 | 120 |
| 121 TEST_F(CrashReportDatabaseTest, Initialize) { | 121 TEST_F(CrashReportDatabaseTest, Initialize) { |
| 122 // Initialize the database for the first time, creating it. | 122 // Initialize the database for the first time, creating it. |
| 123 EXPECT_TRUE(db()); | 123 EXPECT_TRUE(db()); |
| 124 | 124 |
| 125 // Close and reopen the database at the same path. | 125 // Close and reopen the database at the same path. |
| 126 ResetDatabase(); | 126 ResetDatabase(); |
| 127 EXPECT_FALSE(db()); | 127 EXPECT_FALSE(db()); |
| 128 auto db = CrashReportDatabase::Initialize(path()); | 128 auto db = CrashReportDatabase::Initialize(path()); |
| 129 EXPECT_TRUE(db.get()); | 129 EXPECT_TRUE(db.get()); |
|
Peter Kasting
2015/02/13 00:32:38
This should be ASSERT_TRUE since you deref |db| un
scottmg
2015/02/13 06:34:01
Done.
| |
| 130 | 130 |
| 131 std::vector<const CrashReportDatabase::Report> reports; | 131 std::vector<const CrashReportDatabase::Report> reports; |
|
Peter Kasting
2015/02/13 00:32:38
This is out-of-scope for the current CL, but consi
scottmg
2015/02/13 06:34:01
That seems reasonable. I sort of dislike hiding ve
Peter Kasting
2015/02/13 22:30:32
It's a minor thing. It wouldn't normally be an is
scottmg
2015/02/13 23:37:16
Acknowledged.
| |
| 132 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports)); | 132 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports)); |
| 133 EXPECT_TRUE(reports.empty()); | 133 EXPECT_TRUE(reports.empty()); |
|
Peter Kasting
2015/02/13 00:32:38
Either change this to ASSERT_TRUE or add a "report
scottmg
2015/02/13 06:34:01
They're slightly unrelated checks, so I went with
| |
| 134 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports)); | 134 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports)); |
| 135 EXPECT_TRUE(reports.empty()); | 135 EXPECT_TRUE(reports.empty()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST_F(CrashReportDatabaseTest, NewCrashReport) { | 138 TEST_F(CrashReportDatabaseTest, NewCrashReport) { |
| 139 CrashReportDatabase::NewReport* new_report; | 139 CrashReportDatabase::NewReport* new_report; |
| 140 EXPECT_EQ(CrashReportDatabase::kNoError, | 140 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 141 db()->PrepareNewCrashReport(&new_report)); | 141 db()->PrepareNewCrashReport(&new_report)); |
| 142 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); | 142 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); |
| 143 UUID uuid; | 143 UUID uuid; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 CreateCrashReport(&report); | 180 CreateCrashReport(&report); |
| 181 uuid = report.uuid; | 181 uuid = report.uuid; |
| 182 } | 182 } |
| 183 | 183 |
| 184 { | 184 { |
| 185 CrashReportDatabase::Report report; | 185 CrashReportDatabase::Report report; |
| 186 EXPECT_EQ(CrashReportDatabase::kNoError, | 186 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 187 db()->LookUpCrashReport(uuid, &report)); | 187 db()->LookUpCrashReport(uuid, &report)); |
| 188 EXPECT_EQ(uuid, report.uuid); | 188 EXPECT_EQ(uuid, report.uuid); |
| 189 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); | 189 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); |
| 190 EXPECT_EQ("", report.id); | 190 EXPECT_EQ("", report.id); |
|
Peter Kasting
2015/02/13 00:32:38
Nit: "" -> std::string() (multiple places)
You co
scottmg
2015/02/13 06:34:01
Done.
| |
| 191 EXPECT_FALSE(report.uploaded); | 191 EXPECT_FALSE(report.uploaded); |
| 192 EXPECT_EQ(0, report.last_upload_attempt_time); | 192 EXPECT_EQ(0, report.last_upload_attempt_time); |
| 193 EXPECT_EQ(0, report.upload_attempts); | 193 EXPECT_EQ(0, report.upload_attempts); |
| 194 } | 194 } |
| 195 | 195 |
| 196 UploadReport(uuid, true, "test"); | 196 UploadReport(uuid, true, "test"); |
| 197 | 197 |
| 198 { | 198 { |
| 199 CrashReportDatabase::Report report; | 199 CrashReportDatabase::Report report; |
| 200 EXPECT_EQ(CrashReportDatabase::kNoError, | 200 EXPECT_EQ(CrashReportDatabase::kNoError, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 212 std::vector<CrashReportDatabase::Report> reports(3); | 212 std::vector<CrashReportDatabase::Report> reports(3); |
| 213 CreateCrashReport(&reports[0]); | 213 CreateCrashReport(&reports[0]); |
| 214 CreateCrashReport(&reports[1]); | 214 CreateCrashReport(&reports[1]); |
| 215 CreateCrashReport(&reports[2]); | 215 CreateCrashReport(&reports[2]); |
| 216 | 216 |
| 217 // Record two attempts: one successful, one not. | 217 // Record two attempts: one successful, one not. |
| 218 UploadReport(reports[1].uuid, false, ""); | 218 UploadReport(reports[1].uuid, false, ""); |
| 219 UploadReport(reports[2].uuid, true, "abc123"); | 219 UploadReport(reports[2].uuid, true, "abc123"); |
| 220 | 220 |
| 221 std::vector<CrashReportDatabase::Report> query(3); | 221 std::vector<CrashReportDatabase::Report> query(3); |
| 222 | 222 |
|
Peter Kasting
2015/02/13 00:32:38
Nit: I would remove this blank line
scottmg
2015/02/13 06:34:01
I hate to dissent for something so minor, but beca
Peter Kasting
2015/02/13 22:30:32
In that case, I wonder why you don't have a blank
scottmg
2015/02/13 23:37:16
Fair enough. Done.
| |
| 223 EXPECT_EQ(CrashReportDatabase::kNoError, | 223 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 224 db()->LookUpCrashReport(reports[0].uuid, &query[0])); | 224 db()->LookUpCrashReport(reports[0].uuid, &query[0])); |
| 225 EXPECT_EQ(CrashReportDatabase::kNoError, | 225 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 226 db()->LookUpCrashReport(reports[1].uuid, &query[1])); | 226 db()->LookUpCrashReport(reports[1].uuid, &query[1])); |
| 227 EXPECT_EQ(CrashReportDatabase::kNoError, | 227 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 228 db()->LookUpCrashReport(reports[2].uuid, &query[2])); | 228 db()->LookUpCrashReport(reports[2].uuid, &query[2])); |
| 229 | 229 |
| 230 EXPECT_EQ("", query[0].id); | 230 EXPECT_EQ("", query[0].id); |
| 231 EXPECT_EQ("", query[1].id); | 231 EXPECT_EQ("", query[1].id); |
| 232 EXPECT_EQ("abc123", query[2].id); | 232 EXPECT_EQ("abc123", query[2].id); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 ASSERT_EQ(1u, completed.size()); | 332 ASSERT_EQ(1u, completed.size()); |
| 333 | 333 |
| 334 for (const auto& report : pending) | 334 for (const auto& report : pending) |
| 335 EXPECT_NE(report_1_uuid, report.uuid); | 335 EXPECT_NE(report_1_uuid, report.uuid); |
| 336 EXPECT_EQ(report_1_uuid, completed[0].uuid); | 336 EXPECT_EQ(report_1_uuid, completed[0].uuid); |
| 337 EXPECT_EQ("report1", completed[0].id); | 337 EXPECT_EQ("report1", completed[0].id); |
| 338 EXPECT_EQ(true, completed[0].uploaded); | 338 EXPECT_EQ(true, completed[0].uploaded); |
| 339 EXPECT_GT(completed[0].last_upload_attempt_time, 0); | 339 EXPECT_GT(completed[0].last_upload_attempt_time, 0); |
| 340 EXPECT_EQ(1, completed[0].upload_attempts); | 340 EXPECT_EQ(1, completed[0].upload_attempts); |
| 341 | 341 |
| 342 const CrashReportDatabase::Report completed_report_1 = completed[0]; | 342 const CrashReportDatabase::Report completed_report_1 = completed[0]; |
|
Peter Kasting
2015/02/13 00:32:38
You don't seem to use this.
scottmg
2015/02/13 06:34:01
Done.
| |
| 343 | 343 |
| 344 // Fail to upload one report. | 344 // Fail to upload one report. |
| 345 UploadReport(report_2_uuid, false, ""); | 345 UploadReport(report_2_uuid, false, ""); |
| 346 | 346 |
| 347 pending.clear(); | 347 pending.clear(); |
| 348 EXPECT_EQ(CrashReportDatabase::kNoError, | 348 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 349 db()->GetPendingReports(&pending)); | 349 db()->GetPendingReports(&pending)); |
| 350 completed.clear(); | 350 completed.clear(); |
| 351 EXPECT_EQ(CrashReportDatabase::kNoError, | 351 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 352 db()->GetCompletedReports(&completed)); | 352 db()->GetCompletedReports(&completed)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 CrashReportDatabase::Report report; | 454 CrashReportDatabase::Report report; |
| 455 EXPECT_EQ(CrashReportDatabase::kNoError, | 455 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 456 db()->LookUpCrashReport(uuid, &report)); | 456 db()->LookUpCrashReport(uuid, &report)); |
| 457 ExpectPreparedCrashReport(report); | 457 ExpectPreparedCrashReport(report); |
| 458 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); | 458 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 } // namespace | 461 } // namespace |
| 462 } // namespace test | 462 } // namespace test |
| 463 } // namespace crashpad | 463 } // namespace crashpad |
| 464 // EOF comment added for readability review. | |
| OLD | NEW |