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 "base/values.h"
8 #include "chromecast/crash/linux/crash_testing_utils.h"
9 #include "chromecast/crash/linux/dump_info.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace chromecast
{
14 TEST(DumpInfoTest
, EmptyStringIsNotValid
) {
15 scoped_ptr
<DumpInfo
> dump_info(CreateDumpInfo(""));
16 ASSERT_FALSE(dump_info
->valid());
19 TEST(DumpInfoTest
, TooFewFieldsIsNotValid
) {
20 scoped_ptr
<DumpInfo
> dump_info(CreateDumpInfo(
23 "\"dump_time\" : \"2001-11-12 18:31:01\","
24 "\"dump\": \"dump_string\""
26 ASSERT_FALSE(dump_info
->valid());
29 TEST(DumpInfoTest
, BadTimeStringIsNotValid
) {
30 scoped_ptr
<DumpInfo
> info(CreateDumpInfo(
33 "\"dump_time\" : \"Mar 23 2014 01:23:45\","
34 "\"dump\": \"dump_string\","
35 "\"uptime\": \"123456789\","
36 "\"logfile\": \"logfile.log\""
38 ASSERT_FALSE(info
->valid());
41 TEST(DumpInfoTest
, AllRequiredFieldsIsValid
) {
42 scoped_ptr
<DumpInfo
> info(CreateDumpInfo(
45 "\"dump_time\" : \"2001-11-12 18:31:01\","
46 "\"dump\": \"dump_string\","
47 "\"uptime\": \"123456789\","
48 "\"logfile\": \"logfile.log\""
58 time_t dump_time
= mktime(&tm
);
60 ASSERT_TRUE(info
->valid());
61 ASSERT_EQ("name", info
->params().process_name
);
62 ASSERT_EQ(dump_time
, info
->dump_time());
63 ASSERT_EQ("dump_string", info
->crashed_process_dump());
64 ASSERT_EQ(123456789u, info
->params().process_uptime
);
65 ASSERT_EQ("logfile.log", info
->logfile());
68 TEST(DumpInfoTest
, EmptyProcessNameIsValid
) {
69 scoped_ptr
<DumpInfo
> dump_info(CreateDumpInfo(
72 "\"dump_time\" : \"2001-11-12 18:31:01\","
73 "\"dump\": \"dump_string\","
74 "\"uptime\": \"123456789\","
75 "\"logfile\": \"logfile.log\""
77 ASSERT_TRUE(dump_info
->valid());
80 TEST(DumpInfoTest
, SomeRequiredFieldsEmptyIsValid
) {
81 scoped_ptr
<DumpInfo
> info(CreateDumpInfo(
84 "\"dump_time\" : \"2001-11-12 18:31:01\","
97 time_t dump_time
= mktime(&tm
);
99 ASSERT_TRUE(info
->valid());
100 ASSERT_EQ("name", info
->params().process_name
);
101 ASSERT_EQ(dump_time
, info
->dump_time());
102 ASSERT_EQ("", info
->crashed_process_dump());
103 ASSERT_EQ(0u, info
->params().process_uptime
);
104 ASSERT_EQ("", info
->logfile());
107 TEST(DumpInfoTest
, AllOptionalFieldsIsValid
) {
108 scoped_ptr
<DumpInfo
> info(CreateDumpInfo(
110 "\"name\": \"name\","
111 "\"dump_time\" : \"2001-11-12 18:31:01\","
112 "\"dump\": \"dump_string\","
113 "\"uptime\": \"123456789\","
114 "\"logfile\": \"logfile.log\","
115 "\"suffix\": \"suffix\","
116 "\"prev_app_name\": \"previous_app\","
117 "\"cur_app_name\": \"current_app\","
118 "\"last_app_name\": \"last_app\","
119 "\"release_version\": \"RELEASE\","
120 "\"build_number\": \"BUILD_NUMBER\""
130 time_t dump_time
= mktime(&tm
);
132 ASSERT_TRUE(info
->valid());
133 ASSERT_EQ("name", info
->params().process_name
);
134 ASSERT_EQ(dump_time
, info
->dump_time());
135 ASSERT_EQ("dump_string", info
->crashed_process_dump());
136 ASSERT_EQ(123456789u, info
->params().process_uptime
);
137 ASSERT_EQ("logfile.log", info
->logfile());
139 ASSERT_EQ("suffix", info
->params().suffix
);
140 ASSERT_EQ("previous_app", info
->params().previous_app_name
);
141 ASSERT_EQ("current_app", info
->params().current_app_name
);
142 ASSERT_EQ("last_app", info
->params().last_app_name
);
145 TEST(DumpInfoTest
, SomeOptionalFieldsIsValid
) {
146 scoped_ptr
<DumpInfo
> info(CreateDumpInfo(
148 "\"name\": \"name\","
149 "\"dump_time\" : \"2001-11-12 18:31:01\","
150 "\"dump\": \"dump_string\","
151 "\"uptime\": \"123456789\","
152 "\"logfile\": \"logfile.log\","
153 "\"suffix\": \"suffix\","
154 "\"prev_app_name\": \"previous_app\""
164 time_t dump_time
= mktime(&tm
);
166 ASSERT_TRUE(info
->valid());
167 ASSERT_EQ("name", info
->params().process_name
);
168 ASSERT_EQ(dump_time
, info
->dump_time());
169 ASSERT_EQ("dump_string", info
->crashed_process_dump());
170 ASSERT_EQ(123456789u, info
->params().process_uptime
);
171 ASSERT_EQ("logfile.log", info
->logfile());
173 ASSERT_EQ("suffix", info
->params().suffix
);
174 ASSERT_EQ("previous_app", info
->params().previous_app_name
);
177 TEST(DumpInfoTest
, TooManyFieldsIsNotValid
) {
178 scoped_ptr
<DumpInfo
> info(CreateDumpInfo(
180 "\"name\": \"name\","
181 "\"dump_time\" : \"2001-11-12 18:31:01\","
182 "\"dump\": \"dump_string\","
183 "\"uptime\": \"123456789\","
184 "\"logfile\": \"logfile.log\","
185 "\"suffix\": \"suffix\","
186 "\"prev_app_name\": \"previous_app\","
187 "\"cur_app_name\": \"current_app\","
188 "\"last_app_name\": \"last_app\","
189 "\"release_version\": \"RELEASE\","
190 "\"build_number\": \"BUILD_NUMBER\","
191 "\"hello\": \"extra_field\""
193 ASSERT_FALSE(info
->valid());
196 } // namespace chromecast