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

Side by Side Diff: user_collector_test.cc

Issue 2868032: Remove source from crash-reporter and crash-dumper as they are no longer necessary. (Closed) Base URL: ssh://git@chromiumos-git//crash.git
Patch Set: Created 10 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
« no previous file with comments | « user_collector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <gflags/gflags.h>
6 #include <gtest/gtest.h>
7
8 #include "base/file_util.h"
9 #include "crash/system_logging_mock.h"
10 #include "crash/user_collector.h"
11
12 int s_crashes = 0;
13 bool s_metrics = false;
14
15 static const char kFilePath[] = "/my/path";
16
17 void CountCrash() {
18 ++s_crashes;
19 }
20
21 bool IsMetrics() {
22 return s_metrics;
23 }
24
25 class UserCollectorTest : public ::testing::Test {
26 void SetUp() {
27 s_crashes = 0;
28 collector_.Initialize(CountCrash,
29 kFilePath,
30 IsMetrics,
31 &logging_);
32 mkdir("test", 0777);
33 collector_.set_core_pattern_file("test/core_pattern");
34 }
35 protected:
36 SystemLoggingMock logging_;
37 UserCollector collector_;
38 };
39
40 TEST_F(UserCollectorTest, EnableOK) {
41 std::string contents;
42 ASSERT_TRUE(collector_.Enable());
43 ASSERT_TRUE(file_util::ReadFileToString(FilePath("test/core_pattern"),
44 &contents));
45 ASSERT_STREQ(contents.c_str(),
46 "|/my/path --signal=%s --pid=%p --exec=%e");
47 ASSERT_EQ(s_crashes, 0);
48 ASSERT_NE(logging_.log().find("Enabling crash handling"), std::string::npos);
49 }
50
51 TEST_F(UserCollectorTest, EnableNoFileAccess) {
52 collector_.set_core_pattern_file("/does_not_exist");
53 ASSERT_FALSE(collector_.Enable());
54 ASSERT_EQ(s_crashes, 0);
55 ASSERT_NE(logging_.log().find("Enabling crash handling"), std::string::npos);
56 ASSERT_NE(logging_.log().find("Unable to write /does_not_exist"),
57 std::string::npos);
58 }
59
60 TEST_F(UserCollectorTest, DisableOK) {
61 std::string contents;
62 ASSERT_TRUE(collector_.Disable());
63 ASSERT_TRUE(file_util::ReadFileToString(FilePath("test/core_pattern"),
64 &contents));
65 ASSERT_STREQ(contents.c_str(), "core");
66 ASSERT_EQ(s_crashes, 0);
67 ASSERT_NE(logging_.log().find("Disabling crash handling"),
68 std::string::npos);
69 }
70
71 TEST_F(UserCollectorTest, DisableNoFileAccess) {
72 collector_.set_core_pattern_file("/does_not_exist");
73 ASSERT_FALSE(collector_.Disable());
74 ASSERT_EQ(s_crashes, 0);
75 ASSERT_NE(logging_.log().find("Disabling crash handling"), std::string::npos);
76 ASSERT_NE(logging_.log().find("Unable to write /does_not_exist"),
77 std::string::npos);
78 }
79
80
81 TEST_F(UserCollectorTest, HandleCrashWithoutMetrics) {
82 s_metrics = false;
83 collector_.HandleCrash(10, 20, "foobar");
84 ASSERT_NE(logging_.log().find(
85 "Received crash notification for foobar[20] sig 10"),
86 std::string::npos);
87 ASSERT_EQ(s_crashes, 0);
88 }
89
90 TEST_F(UserCollectorTest, HandleCrashWithMetrics) {
91 s_metrics = true;
92 collector_.HandleCrash(2, 5, "chrome");
93 ASSERT_NE(logging_.log().find(
94 "Received crash notification for chrome[5] sig 2"),
95 std::string::npos);
96 ASSERT_EQ(s_crashes, 1);
97 }
98
99 int main(int argc, char **argv) {
100 ::testing::InitGoogleTest(&argc, argv);
101 return RUN_ALL_TESTS();
102 }
OLDNEW
« no previous file with comments | « user_collector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698