Update UnusedResources lint suppressions.
[chromium-blink-merge.git] / chromecast / crash / linux / dump_info_unittest.cc
blobe99daa47831beac4a3d03d3fcd9093b5f3d8e866
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 "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");
29 struct tm tm = {0};
30 tm.tm_isdst = 0;
31 tm.tm_sec = 1;
32 tm.tm_min = 31;
33 tm.tm_hour = 18;
34 tm.tm_mday = 12;
35 tm.tm_mon = 10;
36 tm.tm_year = 101;
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|||");
54 struct tm tm = {0};
55 tm.tm_isdst = 0;
56 tm.tm_sec = 1;
57 tm.tm_min = 31;
58 tm.tm_hour = 18;
59 tm.tm_mday = 12;
60 tm.tm_mon = 10;
61 tm.tm_year = 101;
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) {
73 DumpInfo info(
74 "name|2001-11-12 18:31:01|dump_string|123456789|logfile.log|"
75 "suffix|previous_app|current_app|last_app|RELEASE|BUILD_NUMBER");
76 struct tm tm = {0};
77 tm.tm_isdst = 0;
78 tm.tm_sec = 1;
79 tm.tm_min = 31;
80 tm.tm_hour = 18;
81 tm.tm_mday = 12;
82 tm.tm_mon = 10;
83 tm.tm_year = 101;
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) {
100 DumpInfo info(
101 "name|2001-11-12 18:31:01|dump_string|123456789|logfile.log|"
102 "suffix|previous_app");
103 struct tm tm = {0};
104 tm.tm_isdst = 0;
105 tm.tm_sec = 1;
106 tm.tm_min = 31;
107 tm.tm_hour = 18;
108 tm.tm_mday = 12;
109 tm.tm_mon = 10;
110 tm.tm_year = 101;
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) {
125 DumpInfo info(
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());
131 } // chromecast