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

Side by Side Diff: net/log/test_net_log_util.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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 | « net/log/test_net_log_util.h ('k') | net/log/trace_net_log_observer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/log/test_net_log_util.h" 5 #include "net/log/test_net_log_util.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 namespace net { 9 namespace net {
10 10
(...skipping 12 matching lines...) Expand all
23 if (abs_offset > entries.size()) 23 if (abs_offset > entries.size())
24 return entries.size(); 24 return entries.size();
25 return entries.size() - abs_offset; 25 return entries.size() - abs_offset;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 ::testing::AssertionResult LogContainsEvent( 30 ::testing::AssertionResult LogContainsEvent(
31 const TestNetLogEntry::List& entries, 31 const TestNetLogEntry::List& entries,
32 int offset, 32 int offset,
33 NetLog::EventType expected_event, 33 NetLogEventType expected_event,
34 NetLog::EventPhase expected_phase) { 34 NetLogEventPhase expected_phase) {
35 size_t index = GetIndex(entries, offset); 35 size_t index = GetIndex(entries, offset);
36 if (index >= entries.size()) 36 if (index >= entries.size())
37 return ::testing::AssertionFailure() << index << " is out of bounds."; 37 return ::testing::AssertionFailure() << index << " is out of bounds.";
38 const TestNetLogEntry& entry = entries[index]; 38 const TestNetLogEntry& entry = entries[index];
39 if (expected_event != entry.type) { 39 if (expected_event != entry.type) {
40 return ::testing::AssertionFailure() 40 return ::testing::AssertionFailure()
41 << "Actual event: " << NetLog::EventTypeToString(entry.type) 41 << "Actual event: " << NetLog::EventTypeToString(entry.type)
42 << ". Expected event: " << NetLog::EventTypeToString(expected_event) 42 << ". Expected event: " << NetLog::EventTypeToString(expected_event)
43 << "."; 43 << ".";
44 } 44 }
45 if (expected_phase != entry.phase) { 45 if (expected_phase != entry.phase) {
46 return ::testing::AssertionFailure() 46 return ::testing::AssertionFailure()
47 << "Actual phase: " << entry.phase 47 << "Actual phase: " << static_cast<int>(entry.phase)
48 << ". Expected phase: " << expected_phase << "."; 48 << ". Expected phase: " << static_cast<int>(expected_phase) << ".";
49 } 49 }
50 return ::testing::AssertionSuccess(); 50 return ::testing::AssertionSuccess();
51 } 51 }
52 52
53 ::testing::AssertionResult LogContainsBeginEvent( 53 ::testing::AssertionResult LogContainsBeginEvent(
54 const TestNetLogEntry::List& entries, 54 const TestNetLogEntry::List& entries,
55 int offset, 55 int offset,
56 NetLog::EventType expected_event) { 56 NetLogEventType expected_event) {
57 return LogContainsEvent(entries, offset, expected_event, NetLog::PHASE_BEGIN); 57 return LogContainsEvent(entries, offset, expected_event,
58 NetLogEventPhase::BEGIN);
58 } 59 }
59 60
60 ::testing::AssertionResult LogContainsEndEvent( 61 ::testing::AssertionResult LogContainsEndEvent(
61 const TestNetLogEntry::List& entries, 62 const TestNetLogEntry::List& entries,
62 int offset, 63 int offset,
63 NetLog::EventType expected_event) { 64 NetLogEventType expected_event) {
64 return LogContainsEvent(entries, offset, expected_event, NetLog::PHASE_END); 65 return LogContainsEvent(entries, offset, expected_event,
66 NetLogEventPhase::END);
65 } 67 }
66 68
67 ::testing::AssertionResult LogContainsEntryWithType( 69 ::testing::AssertionResult LogContainsEntryWithType(
68 const TestNetLogEntry::List& entries, 70 const TestNetLogEntry::List& entries,
69 int offset, 71 int offset,
70 NetLog::EventType type) { 72 NetLogEventType type) {
71 size_t index = GetIndex(entries, offset); 73 size_t index = GetIndex(entries, offset);
72 if (index >= entries.size()) 74 if (index >= entries.size())
73 return ::testing::AssertionFailure() << index << " is out of bounds."; 75 return ::testing::AssertionFailure() << index << " is out of bounds.";
74 const TestNetLogEntry& entry = entries[index]; 76 const TestNetLogEntry& entry = entries[index];
75 if (entry.type != type) 77 if (entry.type != type)
76 return ::testing::AssertionFailure() << "Type does not match."; 78 return ::testing::AssertionFailure() << "Type does not match.";
77 return ::testing::AssertionSuccess(); 79 return ::testing::AssertionSuccess();
78 } 80 }
79 81
80 ::testing::AssertionResult LogContainsEntryWithTypeAfter( 82 ::testing::AssertionResult LogContainsEntryWithTypeAfter(
81 const TestNetLogEntry::List& entries, 83 const TestNetLogEntry::List& entries,
82 int start_offset, 84 int start_offset,
83 NetLog::EventType type) { 85 NetLogEventType type) {
84 for (size_t i = GetIndex(entries, start_offset); i < entries.size(); ++i) { 86 for (size_t i = GetIndex(entries, start_offset); i < entries.size(); ++i) {
85 const TestNetLogEntry& entry = entries[i]; 87 const TestNetLogEntry& entry = entries[i];
86 if (entry.type == type) 88 if (entry.type == type)
87 return ::testing::AssertionSuccess(); 89 return ::testing::AssertionSuccess();
88 } 90 }
89 return ::testing::AssertionFailure(); 91 return ::testing::AssertionFailure();
90 } 92 }
91 93
92 size_t ExpectLogContainsSomewhere(const TestNetLogEntry::List& entries, 94 size_t ExpectLogContainsSomewhere(const TestNetLogEntry::List& entries,
93 size_t min_offset, 95 size_t min_offset,
94 NetLog::EventType expected_event, 96 NetLogEventType expected_event,
95 NetLog::EventPhase expected_phase) { 97 NetLogEventPhase expected_phase) {
96 size_t min_index = GetIndex(entries, min_offset); 98 size_t min_index = GetIndex(entries, min_offset);
97 size_t i = 0; 99 size_t i = 0;
98 for (; i < entries.size(); ++i) { 100 for (; i < entries.size(); ++i) {
99 const TestNetLogEntry& entry = entries[i]; 101 const TestNetLogEntry& entry = entries[i];
100 if (entry.type == expected_event && entry.phase == expected_phase) 102 if (entry.type == expected_event && entry.phase == expected_phase)
101 break; 103 break;
102 } 104 }
103 EXPECT_LT(i, entries.size()); 105 EXPECT_LT(i, entries.size());
104 EXPECT_GE(i, min_index); 106 EXPECT_GE(i, min_index);
105 return i; 107 return i;
106 } 108 }
107 109
108 size_t ExpectLogContainsSomewhereAfter(const TestNetLogEntry::List& entries, 110 size_t ExpectLogContainsSomewhereAfter(const TestNetLogEntry::List& entries,
109 size_t start_offset, 111 size_t start_offset,
110 NetLog::EventType expected_event, 112 NetLogEventType expected_event,
111 NetLog::EventPhase expected_phase) { 113 NetLogEventPhase expected_phase) {
112 size_t i = GetIndex(entries, start_offset); 114 size_t i = GetIndex(entries, start_offset);
113 for (; i < entries.size(); ++i) { 115 for (; i < entries.size(); ++i) {
114 const TestNetLogEntry& entry = entries[i]; 116 const TestNetLogEntry& entry = entries[i];
115 if (entry.type == expected_event && entry.phase == expected_phase) 117 if (entry.type == expected_event && entry.phase == expected_phase)
116 break; 118 break;
117 } 119 }
118 EXPECT_LT(i, entries.size()); 120 EXPECT_LT(i, entries.size());
119 return i; 121 return i;
120 } 122 }
121 123
122 } // namespace net 124 } // namespace net
OLDNEW
« no previous file with comments | « net/log/test_net_log_util.h ('k') | net/log/trace_net_log_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698