Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1864)

Side by Side Diff: chromecast/crash/minidump_writer_unittest.cc

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: Corrected version hack in breakpad_util. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1
2 #include "base/files/file_path.h"
3 #include "base/files/file_util.h"
4 #include "base/memory/scoped_ptr.h"
5 #include "chromecast/crash/minidump_generator.h"
6 #include "chromecast/crash/minidump_writer.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace chromecast {
10 namespace {
11
12 const char kMinidumpPath[] = "/this/is/a/fake/path";
13
14 class FakeMinidumpGenerator : public MinidumpGenerator {
15 public:
16 FakeMinidumpGenerator() {}
17 ~FakeMinidumpGenerator() override {}
18
19 // MinidumpGenerator implementation:
20 bool Generate(const std::string& minidump_path) override { return true; }
21 };
22
23 } // namespace
24
25 class MinidumpWriterTest : public testing::Test {
gunsch 2015/06/09 18:46:19 note: prefer not using test fixtures when possible
slan 2015/06/10 01:49:13 Done.
26 public:
27 MinidumpWriterTest()
28 : writer_(
29 new MinidumpWriter(&generator_, kMinidumpPath, MinidumpParams())) {}
30 ~MinidumpWriterTest() override {}
31
32 // testing::Test implementation:
33 void SetUp() override {}
34
35 void TearDown() override {}
36
37 // Accessors and mutators for for testing.
38 void SetLockfile(const std::string& lockfile) {
39 writer_->lockfile_path_ = lockfile;
40 }
41 void SetMaxDumps(int max_dumps) { writer_->max_dumps_ = max_dumps; }
42 void SetMaxRecentDumps(int max_recent_dumps) {
43 writer_->max_recent_dumps_ = max_recent_dumps;
44 }
45
46 bool CanWriteDump() { return writer_->CanWriteDump(); }
47
48 private:
49 FakeMinidumpGenerator generator_;
50 scoped_ptr<MinidumpWriter> writer_;
51
52 DISALLOW_COPY_AND_ASSIGN(MinidumpWriterTest);
53 };
54
55 TEST_F(MinidumpWriterTest, CanWriteDump_WithEmptyLogFile) {
56 base::FilePath path;
57 ASSERT_TRUE(base::CreateTemporaryFile(&path));
58 SetLockfile(path.value());
59 SetMaxDumps(2);
60 SetMaxRecentDumps(10);
61
62 // Should be able to write dump with empty file.
63 ASSERT_TRUE(CanWriteDump());
64
65 // Add an entry to the lockfile. Should still be able to write dump.
66 DumpInfo info("p|2015-01-01 01:02:03|/dump/path||");
67 ASSERT_TRUE(info.valid());
68 base::AppendToFile(path, info.entry().c_str(), info.entry().size());
69 ASSERT_TRUE(CanWriteDump());
70
71 // Cannot write dump if next dump would exceed maximum.
72 DumpInfo info2("p|2015-01-01 01:02:04|/dump/path||");
73 ASSERT_TRUE(info2.valid());
74 base::AppendToFile(path, info2.entry().c_str(), info2.entry().size());
75 ASSERT_FALSE(CanWriteDump());
76
77 // Cannot write dump if next dump would exceed maximum.
78 DumpInfo info3("p|2015-01-01 01:02:05|/dump/path||");
79 ASSERT_TRUE(info3.valid());
80 base::AppendToFile(path, info3.entry().c_str(), info3.entry().size());
81 ASSERT_FALSE(CanWriteDump());
82 }
83
84 } // namespace chromecast
OLDNEW
« chromecast/crash/minidump_writer.h ('K') | « chromecast/crash/minidump_writer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698