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

Unified Diff: crash_collector_test.cc

Issue 5814001: crash-reporter: Capture and send recent update_engine logs when it crashes (Closed) Base URL: http://git.chromium.org/git/crash-reporter.git@master
Patch Set: Respond to petkov review Created 10 years 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 side-by-side diff with in-line comments
Download patch
Index: crash_collector_test.cc
diff --git a/crash_collector_test.cc b/crash_collector_test.cc
index bf3a9ddfecd6ea61f4c2cc6dee2053398576a015..7f1d4c23044dadff383607b8588a32157ec21e47 100644
--- a/crash_collector_test.cc
+++ b/crash_collector_test.cc
@@ -271,6 +271,15 @@ TEST_F(CrashCollectorTest, CheckHasCapacityStrangeNames) {
EXPECT_FALSE(CheckHasCapacity());
}
+TEST_F(CrashCollectorTest, IsCommentLine) {
+ EXPECT_FALSE(CrashCollector::IsCommentLine(""));
+ EXPECT_TRUE(CrashCollector::IsCommentLine("#"));
+ EXPECT_TRUE(CrashCollector::IsCommentLine("#real comment"));
+ EXPECT_TRUE(CrashCollector::IsCommentLine(" # real comment"));
+ EXPECT_FALSE(CrashCollector::IsCommentLine("not comment"));
+ EXPECT_FALSE(CrashCollector::IsCommentLine(" not comment"));
+}
+
TEST_F(CrashCollectorTest, ReadKeyValueFile) {
const char *contents = ("a=b\n"
"\n"
@@ -294,10 +303,13 @@ TEST_F(CrashCollectorTest, ReadKeyValueFile) {
" f g = h\n"
"i=j\n"
"=k\n"
+ "#comment=0\n"
"l=\n");
file_util::WriteFile(path, contents, strlen(contents));
EXPECT_FALSE(collector_.ReadKeyValueFile(path, '=', &dictionary));
+ EXPECT_EQ(5, dictionary.size());
+
i = dictionary.find("a");
EXPECT_TRUE(i != dictionary.end() && i->second == "b c d");
i = dictionary.find("e");
@@ -369,6 +381,27 @@ TEST_F(CrashCollectorTest, MetaData) {
EXPECT_NE(std::string::npos, logging_.log().find("Unable to write"));
}
+TEST_F(CrashCollectorTest, GetLogContents) {
+ FilePath config_file = test_dir_.Append("crash_config");
+ FilePath output_file = test_dir_.Append("crash_log");
+ const char kConfigContents[] =
+ "foobar:echo hello there | sed -e \"s/there/world/\"";
+ ASSERT_TRUE(
+ file_util::WriteFile(config_file,
+ kConfigContents, strlen(kConfigContents)));
+ EXPECT_FALSE(collector_.GetLogContents(config_file,
+ "barfoo",
+ output_file));
+ EXPECT_FALSE(file_util::PathExists(output_file));
+ EXPECT_TRUE(collector_.GetLogContents(config_file,
+ "foobar",
+ output_file));
+ ASSERT_TRUE(file_util::PathExists(output_file));
+ std::string contents;
+ EXPECT_TRUE(file_util::ReadFileToString(output_file, &contents));
+ EXPECT_EQ("hello world\n", contents);
+}
+
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
« no previous file with comments | « crash_collector.cc ('k') | crash_reporter_logs.conf » ('j') | user_collector.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698