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

Side by Side Diff: log_unit_tests.cc

Issue 3129002: Create a bootstat library for external C and C++ programs (Closed) Base URL: ssh://gitrw.chromium.org/bootstat.git
Patch Set: Fix whitespace issue found by presubmit check Created 10 years, 4 months 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 unified diff | Download patch
« no previous file with comments | « bootstat_log.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium OS 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.
4
5 #include "bootstat.h"
6
7 #include <errno.h>
8 #include <unistd.h>
9
10 #include <string>
11 #include <iostream>
12
13 #include <gtest/gtest.h>
14
15 namespace {
16
17 using std::string;
18
19 static const char kMostVoluminousEventName[] =
20 // 16 32 48 64
21 "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 64
22 "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 128
23 "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 191
24 "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 256
25 ;
26
27 static const string kUptimeFileNamePrefix("/tmp/uptime-");
28 static const string kDiskStatFileNamePrefix("/tmp/disk-");
29
30 static void TestEventFileAccess(const string& file_name) {
31 int rv = access(file_name.c_str(), R_OK | W_OK);
32 EXPECT_EQ(rv, 0) << "access to " << file_name
33 << " failed: " << strerror(errno);
34 (void) unlink(file_name.c_str());
35 }
36
37 static void TestEventByName(const string& event_name) {
38 bootstat_log(event_name.c_str());
39 string truncated_event(event_name.substr(0, BOOTSTAT_MAX_EVENT_LEN - 1));
40 TestEventFileAccess(kUptimeFileNamePrefix + truncated_event);
41 TestEventFileAccess(kDiskStatFileNamePrefix + truncated_event);
42 }
43
44 // Tests that name truncation of logged events works as advertised
45 TEST(BoostatTest, EventNameTruncation) {
46 string very_long(kMostVoluminousEventName);
47
48 TestEventByName(very_long);
49 TestEventByName(very_long.substr(0, 1));
50 TestEventByName(very_long.substr(0, 16));
51 TestEventByName(very_long.substr(0, BOOTSTAT_MAX_EVENT_LEN - 1));
52 TestEventByName(very_long.substr(0, BOOTSTAT_MAX_EVENT_LEN));
53 }
54
55 } // namespace
56
57 int main(int argc, char** argv) {
58 testing::InitGoogleTest(&argc, argv);
59 return RUN_ALL_TESTS();
60 }
OLDNEW
« no previous file with comments | « bootstat_log.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698