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 18 matching lines...) Expand all Loading... | |
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) == 0; | 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 class CrashReportDatabaseTest : public testing::Test { |
40 FileHandle handle = LoggingOpenFileForWrite(path, | 40 public: |
41 FileWriteMode::kCreateOrFail, | 41 CrashReportDatabaseTest() { |
42 FilePermissions::kWorldReadable); | 42 } |
43 #if defined(OS_POSIX) | |
44 ASSERT_GE(handle, 0); | |
45 #elif defined(OS_WIN) | |
46 ASSERT_NE(handle, nullptr); | |
47 #endif | |
48 ASSERT_TRUE( | |
49 LoggingWriteFile(handle, path.value().c_str(), path.value().length())); | |
50 ASSERT_TRUE(LoggingCloseFile(handle)); | |
51 } | |
52 | 43 |
53 class CrashReportDatabaseTest : public testing::Test { | |
54 protected: | 44 protected: |
55 // testing::Test: | 45 // testing::Test: |
56 void SetUp() override { | 46 void SetUp() override { |
57 db_ = CrashReportDatabase::Initialize(path()); | 47 db_ = CrashReportDatabase::Initialize(path()); |
58 ASSERT_TRUE(db_.get()); | 48 ASSERT_TRUE(db_); |
59 } | 49 } |
60 | 50 |
61 void ResetDatabase() { | 51 void ResetDatabase() { |
62 db_.reset(); | 52 db_.reset(); |
63 } | 53 } |
64 | 54 |
65 CrashReportDatabase* db() const { return db_.get(); } | 55 CrashReportDatabase* db() { return db_.get(); } |
66 const base::FilePath& path() const { return temp_dir_.path(); } | 56 const base::FilePath& path() const { return temp_dir_.path(); } |
67 | 57 |
68 void CreateCrashReport(CrashReportDatabase::Report* report) { | 58 void CreateCrashReport(CrashReportDatabase::Report* report) { |
69 CrashReportDatabase::NewReport* new_report; | 59 CrashReportDatabase::NewReport* new_report = nullptr; |
70 EXPECT_EQ(CrashReportDatabase::kNoError, | 60 ASSERT_EQ(CrashReportDatabase::kNoError, |
71 db_->PrepareNewCrashReport(&new_report)); | 61 db_->PrepareNewCrashReport(&new_report)); |
72 const char kTest[] = "test"; | 62 const char kTest[] = "test"; |
73 ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); | 63 ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); |
74 | 64 |
75 UUID uuid; | 65 UUID uuid; |
76 EXPECT_EQ(CrashReportDatabase::kNoError, | 66 EXPECT_EQ(CrashReportDatabase::kNoError, |
77 db_->FinishedWritingCrashReport(new_report, &uuid)); | 67 db_->FinishedWritingCrashReport(new_report, &uuid)); |
78 | 68 |
79 EXPECT_EQ(CrashReportDatabase::kNoError, | 69 EXPECT_EQ(CrashReportDatabase::kNoError, |
80 db_->LookUpCrashReport(uuid, report)); | 70 db_->LookUpCrashReport(uuid, report)); |
81 ExpectPreparedCrashReport(*report); | 71 ExpectPreparedCrashReport(*report); |
82 ASSERT_TRUE(FileExistsAtPath(report->file_path)); | 72 ASSERT_TRUE(FileExistsAtPath(report->file_path)); |
83 } | 73 } |
84 | 74 |
85 void UploadReport(const UUID& uuid, bool successful, const std::string& id) { | 75 void UploadReport(const UUID& uuid, bool successful, const std::string& id) { |
86 const CrashReportDatabase::Report* report = nullptr; | 76 const CrashReportDatabase::Report* report = nullptr; |
87 EXPECT_EQ(CrashReportDatabase::kNoError, | 77 ASSERT_EQ(CrashReportDatabase::kNoError, |
88 db_->GetReportForUploading(uuid, &report)); | 78 db_->GetReportForUploading(uuid, &report)); |
89 EXPECT_TRUE(report); | |
90 EXPECT_NE(UUID(), report->uuid); | 79 EXPECT_NE(UUID(), report->uuid); |
91 EXPECT_FALSE(report->file_path.empty()); | 80 EXPECT_FALSE(report->file_path.empty()); |
92 EXPECT_TRUE(FileExistsAtPath(report->file_path)) | 81 EXPECT_TRUE(FileExistsAtPath(report->file_path)) |
93 << report->file_path.value(); | 82 << report->file_path.value(); |
94 EXPECT_GT(report->creation_time, 0); | 83 EXPECT_GT(report->creation_time, 0); |
95 EXPECT_EQ(CrashReportDatabase::kNoError, | 84 EXPECT_EQ(CrashReportDatabase::kNoError, |
96 db_->RecordUploadAttempt(report, successful, id)); | 85 db_->RecordUploadAttempt(report, successful, id)); |
97 } | 86 } |
98 | 87 |
99 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) { | 88 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) { |
100 EXPECT_NE(UUID(), report.uuid); | 89 EXPECT_NE(UUID(), report.uuid); |
101 EXPECT_FALSE(report.file_path.empty()); | 90 EXPECT_FALSE(report.file_path.empty()); |
102 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); | 91 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); |
103 EXPECT_TRUE(report.id.empty()); | 92 EXPECT_TRUE(report.id.empty()); |
104 EXPECT_GT(report.creation_time, 0); | 93 EXPECT_GT(report.creation_time, 0); |
105 EXPECT_FALSE(report.uploaded); | 94 EXPECT_FALSE(report.uploaded); |
106 EXPECT_EQ(0, report.last_upload_attempt_time); | 95 EXPECT_EQ(0, report.last_upload_attempt_time); |
107 EXPECT_EQ(0, report.upload_attempts); | 96 EXPECT_EQ(0, report.upload_attempts); |
108 } | 97 } |
109 | 98 |
110 void RelocateDatabase() { | 99 void RelocateDatabase() { |
111 ResetDatabase(); | 100 ResetDatabase(); |
112 temp_dir_.Rename(); | 101 temp_dir_.Rename(); |
113 SetUp(); | 102 SetUp(); |
114 } | 103 } |
115 | 104 |
116 private: | 105 private: |
117 ScopedTempDir temp_dir_; | 106 ScopedTempDir temp_dir_; |
118 scoped_ptr<CrashReportDatabase> db_; | 107 scoped_ptr<CrashReportDatabase> db_; |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseTest); | |
119 }; | 110 }; |
120 | 111 |
121 TEST_F(CrashReportDatabaseTest, Initialize) { | 112 TEST_F(CrashReportDatabaseTest, Initialize) { |
122 // Initialize the database for the first time, creating it. | 113 // Initialize the database for the first time, creating it. |
123 EXPECT_TRUE(db()); | 114 EXPECT_TRUE(db()); |
124 | 115 |
125 // Close and reopen the database at the same path. | 116 // Close and reopen the database at the same path. |
126 ResetDatabase(); | 117 ResetDatabase(); |
127 EXPECT_FALSE(db()); | 118 EXPECT_FALSE(db()); |
128 auto db = CrashReportDatabase::Initialize(path()); | 119 auto db = CrashReportDatabase::Initialize(path()); |
129 EXPECT_TRUE(db.get()); | 120 ASSERT_TRUE(db); |
130 | 121 |
131 std::vector<const CrashReportDatabase::Report> reports; | 122 std::vector<const CrashReportDatabase::Report> reports; |
132 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports)); | 123 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports)); |
133 EXPECT_TRUE(reports.empty()); | 124 EXPECT_TRUE(reports.empty()); |
125 reports.clear(); | |
134 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports)); | 126 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports)); |
135 EXPECT_TRUE(reports.empty()); | 127 EXPECT_TRUE(reports.empty()); |
136 } | 128 } |
137 | 129 |
138 TEST_F(CrashReportDatabaseTest, NewCrashReport) { | 130 TEST_F(CrashReportDatabaseTest, NewCrashReport) { |
139 CrashReportDatabase::NewReport* new_report; | 131 CrashReportDatabase::NewReport* new_report; |
140 EXPECT_EQ(CrashReportDatabase::kNoError, | 132 EXPECT_EQ(CrashReportDatabase::kNoError, |
141 db()->PrepareNewCrashReport(&new_report)); | 133 db()->PrepareNewCrashReport(&new_report)); |
142 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); | 134 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); |
143 UUID uuid; | 135 UUID uuid; |
(...skipping 11 matching lines...) Expand all Loading... | |
155 ASSERT_EQ(1u, reports.size()); | 147 ASSERT_EQ(1u, reports.size()); |
156 EXPECT_EQ(report.uuid, reports[0].uuid); | 148 EXPECT_EQ(report.uuid, reports[0].uuid); |
157 | 149 |
158 reports.clear(); | 150 reports.clear(); |
159 EXPECT_EQ(CrashReportDatabase::kNoError, | 151 EXPECT_EQ(CrashReportDatabase::kNoError, |
160 db()->GetCompletedReports(&reports)); | 152 db()->GetCompletedReports(&reports)); |
161 EXPECT_TRUE(reports.empty()); | 153 EXPECT_TRUE(reports.empty()); |
162 } | 154 } |
163 | 155 |
164 TEST_F(CrashReportDatabaseTest, ErrorWritingCrashReport) { | 156 TEST_F(CrashReportDatabaseTest, ErrorWritingCrashReport) { |
165 CrashReportDatabase::NewReport* new_report; | 157 CrashReportDatabase::NewReport* new_report = nullptr; |
166 EXPECT_EQ(CrashReportDatabase::kNoError, | 158 ASSERT_EQ(CrashReportDatabase::kNoError, |
167 db()->PrepareNewCrashReport(&new_report)); | 159 db()->PrepareNewCrashReport(&new_report)); |
168 base::FilePath new_report_path = new_report->path; | 160 base::FilePath new_report_path = new_report->path; |
169 EXPECT_TRUE(FileExistsAtPath(new_report_path)) << new_report_path.value(); | 161 EXPECT_TRUE(FileExistsAtPath(new_report_path)) << new_report_path.value(); |
170 EXPECT_EQ(CrashReportDatabase::kNoError, | 162 EXPECT_EQ(CrashReportDatabase::kNoError, |
171 db()->ErrorWritingCrashReport(new_report)); | 163 db()->ErrorWritingCrashReport(new_report)); |
172 EXPECT_FALSE(FileExistsAtPath(new_report_path)) << new_report_path.value(); | 164 EXPECT_FALSE(FileExistsAtPath(new_report_path)) << new_report_path.value(); |
173 } | 165 } |
174 | 166 |
175 TEST_F(CrashReportDatabaseTest, LookUpCrashReport) { | 167 TEST_F(CrashReportDatabaseTest, LookUpCrashReport) { |
176 UUID uuid; | 168 UUID uuid; |
177 | 169 |
178 { | 170 { |
179 CrashReportDatabase::Report report; | 171 CrashReportDatabase::Report report; |
180 CreateCrashReport(&report); | 172 CreateCrashReport(&report); |
181 uuid = report.uuid; | 173 uuid = report.uuid; |
182 } | 174 } |
183 | 175 |
184 { | 176 { |
185 CrashReportDatabase::Report report; | 177 CrashReportDatabase::Report report; |
186 EXPECT_EQ(CrashReportDatabase::kNoError, | 178 EXPECT_EQ(CrashReportDatabase::kNoError, |
187 db()->LookUpCrashReport(uuid, &report)); | 179 db()->LookUpCrashReport(uuid, &report)); |
188 EXPECT_EQ(uuid, report.uuid); | 180 EXPECT_EQ(uuid, report.uuid); |
189 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); | 181 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); |
190 EXPECT_EQ("", report.id); | 182 EXPECT_EQ(std::string(), report.id); |
191 EXPECT_FALSE(report.uploaded); | 183 EXPECT_FALSE(report.uploaded); |
192 EXPECT_EQ(0, report.last_upload_attempt_time); | 184 EXPECT_EQ(0, report.last_upload_attempt_time); |
193 EXPECT_EQ(0, report.upload_attempts); | 185 EXPECT_EQ(0, report.upload_attempts); |
194 } | 186 } |
195 | 187 |
196 UploadReport(uuid, true, "test"); | 188 UploadReport(uuid, true, "test"); |
197 | 189 |
198 { | 190 { |
199 CrashReportDatabase::Report report; | 191 CrashReportDatabase::Report report; |
200 EXPECT_EQ(CrashReportDatabase::kNoError, | 192 EXPECT_EQ(CrashReportDatabase::kNoError, |
201 db()->LookUpCrashReport(uuid, &report)); | 193 db()->LookUpCrashReport(uuid, &report)); |
202 EXPECT_EQ(uuid, report.uuid); | 194 EXPECT_EQ(uuid, report.uuid); |
203 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); | 195 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); |
204 EXPECT_EQ("test", report.id); | 196 EXPECT_EQ("test", report.id); |
205 EXPECT_TRUE(report.uploaded); | 197 EXPECT_TRUE(report.uploaded); |
206 EXPECT_NE(0, report.last_upload_attempt_time); | 198 EXPECT_NE(0, report.last_upload_attempt_time); |
207 EXPECT_EQ(1, report.upload_attempts); | 199 EXPECT_EQ(1, report.upload_attempts); |
208 } | 200 } |
209 } | 201 } |
210 | 202 |
211 TEST_F(CrashReportDatabaseTest, RecordUploadAttempt) { | 203 TEST_F(CrashReportDatabaseTest, RecordUploadAttempt) { |
212 std::vector<CrashReportDatabase::Report> reports(3); | 204 std::vector<CrashReportDatabase::Report> reports(3); |
213 CreateCrashReport(&reports[0]); | 205 CreateCrashReport(&reports[0]); |
214 CreateCrashReport(&reports[1]); | 206 CreateCrashReport(&reports[1]); |
215 CreateCrashReport(&reports[2]); | 207 CreateCrashReport(&reports[2]); |
216 | 208 |
217 // Record two attempts: one successful, one not. | 209 // Record two attempts: one successful, one not. |
218 UploadReport(reports[1].uuid, false, ""); | 210 UploadReport(reports[1].uuid, false, std::string()); |
219 UploadReport(reports[2].uuid, true, "abc123"); | 211 UploadReport(reports[2].uuid, true, "abc123"); |
220 | 212 |
221 std::vector<CrashReportDatabase::Report> query(3); | 213 std::vector<CrashReportDatabase::Report> query(3); |
222 | |
223 EXPECT_EQ(CrashReportDatabase::kNoError, | 214 EXPECT_EQ(CrashReportDatabase::kNoError, |
224 db()->LookUpCrashReport(reports[0].uuid, &query[0])); | 215 db()->LookUpCrashReport(reports[0].uuid, &query[0])); |
225 EXPECT_EQ(CrashReportDatabase::kNoError, | 216 EXPECT_EQ(CrashReportDatabase::kNoError, |
226 db()->LookUpCrashReport(reports[1].uuid, &query[1])); | 217 db()->LookUpCrashReport(reports[1].uuid, &query[1])); |
227 EXPECT_EQ(CrashReportDatabase::kNoError, | 218 EXPECT_EQ(CrashReportDatabase::kNoError, |
228 db()->LookUpCrashReport(reports[2].uuid, &query[2])); | 219 db()->LookUpCrashReport(reports[2].uuid, &query[2])); |
229 | 220 |
230 EXPECT_EQ("", query[0].id); | 221 EXPECT_EQ(std::string(), query[0].id); |
231 EXPECT_EQ("", query[1].id); | 222 EXPECT_EQ(std::string(), query[1].id); |
232 EXPECT_EQ("abc123", query[2].id); | 223 EXPECT_EQ("abc123", query[2].id); |
233 | 224 |
234 EXPECT_FALSE(query[0].uploaded); | 225 EXPECT_FALSE(query[0].uploaded); |
235 EXPECT_FALSE(query[1].uploaded); | 226 EXPECT_FALSE(query[1].uploaded); |
236 EXPECT_TRUE(query[2].uploaded); | 227 EXPECT_TRUE(query[2].uploaded); |
237 | 228 |
238 EXPECT_EQ(0, query[0].last_upload_attempt_time); | 229 EXPECT_EQ(0, query[0].last_upload_attempt_time); |
239 EXPECT_NE(0, query[1].last_upload_attempt_time); | 230 EXPECT_NE(0, query[1].last_upload_attempt_time); |
240 EXPECT_NE(0, query[2].last_upload_attempt_time); | 231 EXPECT_NE(0, query[2].last_upload_attempt_time); |
241 | 232 |
242 EXPECT_EQ(0, query[0].upload_attempts); | 233 EXPECT_EQ(0, query[0].upload_attempts); |
243 EXPECT_EQ(1, query[1].upload_attempts); | 234 EXPECT_EQ(1, query[1].upload_attempts); |
244 EXPECT_EQ(1, query[2].upload_attempts); | 235 EXPECT_EQ(1, query[2].upload_attempts); |
245 | 236 |
246 // Attempt to upload and fail again. | 237 // Attempt to upload and fail again. |
247 UploadReport(reports[1].uuid, false, ""); | 238 UploadReport(reports[1].uuid, false, std::string()); |
248 | 239 |
249 time_t report_2_upload_time = query[2].last_upload_attempt_time; | 240 time_t report_2_upload_time = query[2].last_upload_attempt_time; |
250 | 241 |
251 EXPECT_EQ(CrashReportDatabase::kNoError, | 242 EXPECT_EQ(CrashReportDatabase::kNoError, |
252 db()->LookUpCrashReport(reports[0].uuid, &query[0])); | 243 db()->LookUpCrashReport(reports[0].uuid, &query[0])); |
253 EXPECT_EQ(CrashReportDatabase::kNoError, | 244 EXPECT_EQ(CrashReportDatabase::kNoError, |
254 db()->LookUpCrashReport(reports[1].uuid, &query[1])); | 245 db()->LookUpCrashReport(reports[1].uuid, &query[1])); |
255 EXPECT_EQ(CrashReportDatabase::kNoError, | 246 EXPECT_EQ(CrashReportDatabase::kNoError, |
256 db()->LookUpCrashReport(reports[2].uuid, &query[2])); | 247 db()->LookUpCrashReport(reports[2].uuid, &query[2])); |
257 | 248 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 ASSERT_EQ(1u, completed.size()); | 323 ASSERT_EQ(1u, completed.size()); |
333 | 324 |
334 for (const auto& report : pending) | 325 for (const auto& report : pending) |
335 EXPECT_NE(report_1_uuid, report.uuid); | 326 EXPECT_NE(report_1_uuid, report.uuid); |
336 EXPECT_EQ(report_1_uuid, completed[0].uuid); | 327 EXPECT_EQ(report_1_uuid, completed[0].uuid); |
337 EXPECT_EQ("report1", completed[0].id); | 328 EXPECT_EQ("report1", completed[0].id); |
338 EXPECT_EQ(true, completed[0].uploaded); | 329 EXPECT_EQ(true, completed[0].uploaded); |
339 EXPECT_GT(completed[0].last_upload_attempt_time, 0); | 330 EXPECT_GT(completed[0].last_upload_attempt_time, 0); |
340 EXPECT_EQ(1, completed[0].upload_attempts); | 331 EXPECT_EQ(1, completed[0].upload_attempts); |
341 | 332 |
342 const CrashReportDatabase::Report completed_report_1 = completed[0]; | |
343 | |
344 // Fail to upload one report. | 333 // Fail to upload one report. |
345 UploadReport(report_2_uuid, false, ""); | 334 UploadReport(report_2_uuid, false, std::string()); |
346 | 335 |
347 pending.clear(); | 336 pending.clear(); |
348 EXPECT_EQ(CrashReportDatabase::kNoError, | 337 EXPECT_EQ(CrashReportDatabase::kNoError, |
349 db()->GetPendingReports(&pending)); | 338 db()->GetPendingReports(&pending)); |
350 completed.clear(); | 339 completed.clear(); |
351 EXPECT_EQ(CrashReportDatabase::kNoError, | 340 EXPECT_EQ(CrashReportDatabase::kNoError, |
352 db()->GetCompletedReports(&completed)); | 341 db()->GetCompletedReports(&completed)); |
353 | 342 |
354 EXPECT_EQ(4u, pending.size()); | 343 EXPECT_EQ(4u, pending.size()); |
355 ASSERT_EQ(1u, completed.size()); | 344 ASSERT_EQ(1u, completed.size()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 const CrashReportDatabase::Report* upload_report; | 419 const CrashReportDatabase::Report* upload_report; |
431 EXPECT_EQ(CrashReportDatabase::kNoError, | 420 EXPECT_EQ(CrashReportDatabase::kNoError, |
432 db()->GetReportForUploading(report.uuid, &upload_report)); | 421 db()->GetReportForUploading(report.uuid, &upload_report)); |
433 | 422 |
434 const CrashReportDatabase::Report* upload_report_2 = nullptr; | 423 const CrashReportDatabase::Report* upload_report_2 = nullptr; |
435 EXPECT_EQ(CrashReportDatabase::kBusyError, | 424 EXPECT_EQ(CrashReportDatabase::kBusyError, |
436 db()->GetReportForUploading(report.uuid, &upload_report_2)); | 425 db()->GetReportForUploading(report.uuid, &upload_report_2)); |
437 EXPECT_FALSE(upload_report_2); | 426 EXPECT_FALSE(upload_report_2); |
438 | 427 |
439 EXPECT_EQ(CrashReportDatabase::kNoError, | 428 EXPECT_EQ(CrashReportDatabase::kNoError, |
440 db()->RecordUploadAttempt(upload_report, true, "")); | 429 db()->RecordUploadAttempt(upload_report, true, std::string())); |
441 } | 430 } |
442 | 431 |
443 TEST_F(CrashReportDatabaseTest, MoveDatabase) { | 432 TEST_F(CrashReportDatabaseTest, MoveDatabase) { |
444 CrashReportDatabase::NewReport* new_report; | 433 CrashReportDatabase::NewReport* new_report; |
445 EXPECT_EQ(CrashReportDatabase::kNoError, | 434 EXPECT_EQ(CrashReportDatabase::kNoError, |
446 db()->PrepareNewCrashReport(&new_report)); | 435 db()->PrepareNewCrashReport(&new_report)); |
447 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); | 436 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); |
448 UUID uuid; | 437 UUID uuid; |
449 EXPECT_EQ(CrashReportDatabase::kNoError, | 438 EXPECT_EQ(CrashReportDatabase::kNoError, |
450 db()->FinishedWritingCrashReport(new_report, &uuid)); | 439 db()->FinishedWritingCrashReport(new_report, &uuid)); |
451 | 440 |
452 RelocateDatabase(); | 441 RelocateDatabase(); |
453 | 442 |
454 CrashReportDatabase::Report report; | 443 CrashReportDatabase::Report report; |
455 EXPECT_EQ(CrashReportDatabase::kNoError, | 444 EXPECT_EQ(CrashReportDatabase::kNoError, |
456 db()->LookUpCrashReport(uuid, &report)); | 445 db()->LookUpCrashReport(uuid, &report)); |
457 ExpectPreparedCrashReport(report); | 446 ExpectPreparedCrashReport(report); |
458 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); | 447 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); |
459 } | 448 } |
460 | 449 |
450 TEST_F(CrashReportDatabaseTest, ReportRemoved) { | |
451 CrashReportDatabase::NewReport* new_report; | |
452 EXPECT_EQ(CrashReportDatabase::kNoError, | |
453 db()->PrepareNewCrashReport(&new_report)); | |
454 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); | |
455 base::FilePath report_path = new_report->path; | |
456 UUID uuid; | |
457 EXPECT_EQ(CrashReportDatabase::kNoError, | |
458 db()->FinishedWritingCrashReport(new_report, &uuid)); | |
459 | |
460 #if defined(OS_WIN) | |
461 _wunlink(report_path.value().c_str()); | |
Mark Mentovai
2015/02/17 19:40:40
Check the return value, both branches.
scottmg
2015/02/17 19:52:19
Done.
| |
462 #else | |
463 unlink(report_path.value().c_str()); | |
464 #endif | |
465 | |
466 CrashReportDatabase::Report report; | |
467 EXPECT_EQ(CrashReportDatabase::kReportNotFound, | |
468 db()->LookUpCrashReport(uuid, &report)); | |
469 } | |
470 | |
461 } // namespace | 471 } // namespace |
462 } // namespace test | 472 } // namespace test |
463 } // namespace crashpad | 473 } // namespace crashpad |
OLD | NEW |