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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bootstat_log.c ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: log_unit_tests.cc
diff --git a/log_unit_tests.cc b/log_unit_tests.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2d279eef679bd45cde569aea19b20bd30aa6dc7b
--- /dev/null
+++ b/log_unit_tests.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "bootstat.h"
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <string>
+#include <iostream>
+
+#include <gtest/gtest.h>
+
+namespace {
+
+using std::string;
+
+static const char kMostVoluminousEventName[] =
+ // 16 32 48 64
+ "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 64
+ "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 128
+ "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 191
+ "event-6789abcdef_123456789ABCDEF.123456789abcdef0123456789abcdef" // 256
+ ;
+
+static const string kUptimeFileNamePrefix("/tmp/uptime-");
+static const string kDiskStatFileNamePrefix("/tmp/disk-");
+
+static void TestEventFileAccess(const string& file_name) {
+ int rv = access(file_name.c_str(), R_OK | W_OK);
+ EXPECT_EQ(rv, 0) << "access to " << file_name
+ << " failed: " << strerror(errno);
+ (void) unlink(file_name.c_str());
+}
+
+static void TestEventByName(const string& event_name) {
+ bootstat_log(event_name.c_str());
+ string truncated_event(event_name.substr(0, BOOTSTAT_MAX_EVENT_LEN - 1));
+ TestEventFileAccess(kUptimeFileNamePrefix + truncated_event);
+ TestEventFileAccess(kDiskStatFileNamePrefix + truncated_event);
+}
+
+// Tests that name truncation of logged events works as advertised
+TEST(BoostatTest, EventNameTruncation) {
+ string very_long(kMostVoluminousEventName);
+
+ TestEventByName(very_long);
+ TestEventByName(very_long.substr(0, 1));
+ TestEventByName(very_long.substr(0, 16));
+ TestEventByName(very_long.substr(0, BOOTSTAT_MAX_EVENT_LEN - 1));
+ TestEventByName(very_long.substr(0, BOOTSTAT_MAX_EVENT_LEN));
+}
+
+} // namespace
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
« 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