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

Side by Side Diff: test/cctest/test-log.cc

Issue 115024: Changelist for a readability review. Not for direct commit. (Closed)
Patch Set: Second round of changes Created 11 years, 7 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 | « test/cctest/test-func-name-inference.cc ('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 2006-2009 the V8 project authors. All rights reserved.
2 //
3 // Tests of logging functions from log.h
4
5 #ifdef ENABLE_LOGGING_AND_PROFILING
6
7 #include "v8.h"
8
9 #include "log.h"
10
11 #include "cctest.h"
12
13 using v8::internal::Logger;
14
15 static void SetUp() {
16 // Log to memory buffer.
17 v8::internal::FLAG_logfile = "*";
18 v8::internal::FLAG_log = true;
19 Logger::Setup();
20 }
21
22 static void TearDown() {
23 Logger::TearDown();
24 }
25
26 TEST(EmptyLog) {
27 SetUp();
28 CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
29 CHECK_EQ(0, Logger::GetLogLines(100, NULL, 0));
30 CHECK_EQ(0, Logger::GetLogLines(0, NULL, 100));
31 CHECK_EQ(0, Logger::GetLogLines(100, NULL, 100));
32 TearDown();
33 }
34
35
36 TEST(GetMessages) {
37 SetUp();
38 Logger::StringEvent("aaa", "bbb");
39 Logger::StringEvent("cccc", "dddd");
40 CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
41 char log_lines[100];
42 memset(log_lines, 0, sizeof(log_lines));
43 // Requesting data size which is smaller than first log message length.
44 CHECK_EQ(0, Logger::GetLogLines(0, log_lines, 3));
45 // See Logger::StringEvent.
46 const char* line_1 = "aaa,\"bbb\"\n";
47 const int line_1_len = strlen(line_1);
48 // Still smaller than log message length.
49 CHECK_EQ(0, Logger::GetLogLines(0, log_lines, line_1_len - 1));
50 // The exact size.
51 CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len));
52 CHECK_EQ(line_1, log_lines);
53 memset(log_lines, 0, sizeof(log_lines));
54 // A bit more than the first line length.
55 CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len + 3));
56 CHECK_EQ(line_1, log_lines);
57 memset(log_lines, 0, sizeof(log_lines));
58 const char* line_2 = "cccc,\"dddd\"\n";
59 const int line_2_len = strlen(line_2);
60 // Now start with line_2 beginning.
61 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 0));
62 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 3));
63 CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, line_2_len - 1));
64 CHECK_EQ(line_2_len, Logger::GetLogLines(line_1_len, log_lines, line_2_len));
65 CHECK_EQ(line_2, log_lines);
66 memset(log_lines, 0, sizeof(log_lines));
67 CHECK_EQ(line_2_len,
68 Logger::GetLogLines(line_1_len, log_lines, line_2_len + 3));
69 CHECK_EQ(line_2, log_lines);
70 memset(log_lines, 0, sizeof(log_lines));
71 // Now get entire buffer contents.
72 const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n";
73 const int all_lines_len = strlen(all_lines);
74 CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len));
75 CHECK_EQ(all_lines, log_lines);
76 memset(log_lines, 0, sizeof(log_lines));
77 CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len + 3));
78 CHECK_EQ(all_lines, log_lines);
79 memset(log_lines, 0, sizeof(log_lines));
80 TearDown();
81 }
82
83
84 TEST(BeyondWritePosition) {
85 SetUp();
86 Logger::StringEvent("aaa", "bbb");
87 Logger::StringEvent("cccc", "dddd");
88 // See Logger::StringEvent.
89 const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n";
90 const int all_lines_len = strlen(all_lines);
91 CHECK_EQ(0, Logger::GetLogLines(all_lines_len, NULL, 1));
92 CHECK_EQ(0, Logger::GetLogLines(all_lines_len, NULL, 100));
93 CHECK_EQ(0, Logger::GetLogLines(all_lines_len + 1, NULL, 1));
94 CHECK_EQ(0, Logger::GetLogLines(all_lines_len + 1, NULL, 100));
95 CHECK_EQ(0, Logger::GetLogLines(all_lines_len + 100, NULL, 1));
96 CHECK_EQ(0, Logger::GetLogLines(all_lines_len + 100, NULL, 100));
97 CHECK_EQ(0, Logger::GetLogLines(10 * 1024 * 1024, NULL, 1));
98 CHECK_EQ(0, Logger::GetLogLines(10 * 1024 * 1024, NULL, 100));
99 TearDown();
100 }
101
102 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « test/cctest/test-func-name-inference.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698