1 // Copyright 2015 The Chromium 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.
7 #include "chromecast/crash/linux/dump_info.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace chromecast
{
12 TEST(DumpInfoTest
, EmptyStringIsNotValid
) {
13 DumpInfo
dump_info("");
14 ASSERT_FALSE(dump_info
.valid());
17 TEST(DumpInfoTest
, TooFewFieldsIsNotValid
) {
18 DumpInfo
dump_info("name|2001-11-12 18:31:01|dump_string");
19 ASSERT_FALSE(dump_info
.valid());
22 TEST(DumpInfoTest
, BadTimeStringIsNotValid
) {
23 DumpInfo
info("name|Mar 23 2014 01:23:45|dump_string|123456789|logfile.log");
24 ASSERT_FALSE(info
.valid());
27 TEST(DumpInfoTest
, AllRequiredFieldsIsValid
) {
28 DumpInfo
info("name|2001-11-12 18:31:01|dump_string|123456789|logfile.log");
37 time_t dump_time
= mktime(&tm
);
39 ASSERT_TRUE(info
.valid());
40 ASSERT_EQ("name", info
.params().process_name
);
41 ASSERT_EQ(dump_time
, info
.dump_time());
42 ASSERT_EQ("dump_string", info
.crashed_process_dump());
43 ASSERT_EQ(123456789u, info
.params().process_uptime
);
44 ASSERT_EQ("logfile.log", info
.logfile());
47 TEST(DumpInfoTest
, EmptyProcessNameIsValid
) {
48 DumpInfo
dump_info("|2001-11-12 18:31:01|dump_string|123456789|logfile.log");
49 ASSERT_TRUE(dump_info
.valid());
52 TEST(DumpInfoTest
, SomeRequiredFieldsEmptyIsValid
) {
53 DumpInfo
info("name|2001-11-12 18:31:01|||");
62 time_t dump_time
= mktime(&tm
);
64 ASSERT_TRUE(info
.valid());
65 ASSERT_EQ("name", info
.params().process_name
);
66 ASSERT_EQ(dump_time
, info
.dump_time());
67 ASSERT_EQ("", info
.crashed_process_dump());
68 ASSERT_EQ(0u, info
.params().process_uptime
);
69 ASSERT_EQ("", info
.logfile());
72 TEST(DumpInfoTest
, AllOptionalFieldsIsValid
) {
74 "name|2001-11-12 18:31:01|dump_string|123456789|logfile.log|"
75 "suffix|previous_app|current_app|last_app|RELEASE|BUILD_NUMBER");
84 time_t dump_time
= mktime(&tm
);
86 ASSERT_TRUE(info
.valid());
87 ASSERT_EQ("name", info
.params().process_name
);
88 ASSERT_EQ(dump_time
, info
.dump_time());
89 ASSERT_EQ("dump_string", info
.crashed_process_dump());
90 ASSERT_EQ(123456789u, info
.params().process_uptime
);
91 ASSERT_EQ("logfile.log", info
.logfile());
93 ASSERT_EQ("suffix", info
.params().suffix
);
94 ASSERT_EQ("previous_app", info
.params().previous_app_name
);
95 ASSERT_EQ("current_app", info
.params().current_app_name
);
96 ASSERT_EQ("last_app", info
.params().last_app_name
);
99 TEST(DumpInfoTest
, SomeOptionalFieldsIsValid
) {
101 "name|2001-11-12 18:31:01|dump_string|123456789|logfile.log|"
102 "suffix|previous_app");
111 time_t dump_time
= mktime(&tm
);
113 ASSERT_TRUE(info
.valid());
114 ASSERT_EQ("name", info
.params().process_name
);
115 ASSERT_EQ(dump_time
, info
.dump_time());
116 ASSERT_EQ("dump_string", info
.crashed_process_dump());
117 ASSERT_EQ(123456789u, info
.params().process_uptime
);
118 ASSERT_EQ("logfile.log", info
.logfile());
120 ASSERT_EQ("suffix", info
.params().suffix
);
121 ASSERT_EQ("previous_app", info
.params().previous_app_name
);
124 TEST(DumpInfoTest
, TooManyFieldsIsNotValid
) {
126 "name|2001-11-12 18:31:01|dump_string|123456789|logfile.log|"
127 "suffix|previous_app|current_app|last_app|VERSION|BUILD_NUM|extra_field");
128 ASSERT_FALSE(info
.valid());