Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromecast / crash / linux / dump_info_unittest.cc
blobc567e8e146d94f22350846382487f213816dc62c
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.
5 #include <time.h>
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(
21 "{"
22 "\"name\": \"name\","
23 "\"dump_time\" : \"2001-11-12 18:31:01\","
24 "\"dump\": \"dump_string\""
25 "}"));
26 ASSERT_FALSE(dump_info->valid());
29 TEST(DumpInfoTest, BadTimeStringIsNotValid) {
30 scoped_ptr<DumpInfo> info(CreateDumpInfo(
31 "{"
32 "\"name\": \"name\","
33 "\"dump_time\" : \"Mar 23 2014 01:23:45\","
34 "\"dump\": \"dump_string\","
35 "\"uptime\": \"123456789\","
36 "\"logfile\": \"logfile.log\""
37 "}"));
38 ASSERT_FALSE(info->valid());
41 TEST(DumpInfoTest, AllRequiredFieldsIsValid) {
42 scoped_ptr<DumpInfo> info(CreateDumpInfo(
43 "{"
44 "\"name\": \"name\","
45 "\"dump_time\" : \"2001-11-12 18:31:01\","
46 "\"dump\": \"dump_string\","
47 "\"uptime\": \"123456789\","
48 "\"logfile\": \"logfile.log\""
49 "}"));
50 struct tm tm = {0};
51 tm.tm_isdst = 0;
52 tm.tm_sec = 1;
53 tm.tm_min = 31;
54 tm.tm_hour = 18;
55 tm.tm_mday = 12;
56 tm.tm_mon = 10;
57 tm.tm_year = 101;
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(
70 "{"
71 "\"name\": \"\","
72 "\"dump_time\" : \"2001-11-12 18:31:01\","
73 "\"dump\": \"dump_string\","
74 "\"uptime\": \"123456789\","
75 "\"logfile\": \"logfile.log\""
76 "}"));
77 ASSERT_TRUE(dump_info->valid());
80 TEST(DumpInfoTest, SomeRequiredFieldsEmptyIsValid) {
81 scoped_ptr<DumpInfo> info(CreateDumpInfo(
82 "{"
83 "\"name\": \"name\","
84 "\"dump_time\" : \"2001-11-12 18:31:01\","
85 "\"dump\": \"\","
86 "\"uptime\": \"\","
87 "\"logfile\": \"\""
88 "}"));
89 struct tm tm = {0};
90 tm.tm_isdst = 0;
91 tm.tm_sec = 1;
92 tm.tm_min = 31;
93 tm.tm_hour = 18;
94 tm.tm_mday = 12;
95 tm.tm_mon = 10;
96 tm.tm_year = 101;
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\""
121 "}"));
122 struct tm tm = {0};
123 tm.tm_isdst = 0;
124 tm.tm_sec = 1;
125 tm.tm_min = 31;
126 tm.tm_hour = 18;
127 tm.tm_mday = 12;
128 tm.tm_mon = 10;
129 tm.tm_year = 101;
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\""
155 "}"));
156 struct tm tm = {0};
157 tm.tm_isdst = 0;
158 tm.tm_sec = 1;
159 tm.tm_min = 31;
160 tm.tm_hour = 18;
161 tm.tm_mday = 12;
162 tm.tm_mon = 10;
163 tm.tm_year = 101;
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\""
192 "}"));
193 ASSERT_FALSE(info->valid());
196 } // namespace chromecast