Chromium Code Reviews| Index: base/debug/trace_event_unittest.cc |
| diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc |
| index 0ccf440a5569782eacd486cac6603e5459db5934..c30c77329294d0be3c1897203cf1d6b977ad6571 100644 |
| --- a/base/debug/trace_event_unittest.cc |
| +++ b/base/debug/trace_event_unittest.cc |
| @@ -40,7 +40,7 @@ class TraceEventTestFixture : public testing::Test { |
| // up multiple times when testing AtExit. Use ManualTestSetUp for this. |
| void ManualTestSetUp(); |
| void OnTraceDataCollected( |
| - scoped_refptr<TraceLog::RefCountedString> json_events_str); |
| + scoped_refptr<TraceLog::RefCountedString> events_str); |
| bool FindMatchingTraceEntry(const JsonKeyValue* key_values); |
| bool FindNamePhase(const char* name, const char* phase); |
| bool FindMatchingValue(const char* key, |
| @@ -48,12 +48,13 @@ class TraceEventTestFixture : public testing::Test { |
| bool FindNonMatchingValue(const char* key, |
| const char* value); |
| void Clear() { |
| - trace_string_.clear(); |
| trace_parsed_.Clear(); |
| + json_output_.json_output.clear(); |
| } |
| - std::string trace_string_; |
| ListValue trace_parsed_; |
| + base::debug::TraceResultBuffer trace_buffer_; |
| + base::debug::TraceResultBuffer::SimpleOutput json_output_; |
| private: |
| // We want our singleton torn down after each test. |
| @@ -70,15 +71,19 @@ void TraceEventTestFixture::ManualTestSetUp() { |
| tracelog->SetOutputCallback( |
| base::Bind(&TraceEventTestFixture::OnTraceDataCollected, |
| base::Unretained(this))); |
| + trace_buffer_.SetOutputCallback(json_output_.GetCallback()); |
| } |
| void TraceEventTestFixture::OnTraceDataCollected( |
| - scoped_refptr<TraceLog::RefCountedString> json_events_str) { |
| + scoped_refptr<TraceLog::RefCountedString> events_str) { |
| AutoLock lock(lock_); |
| - trace_string_ += json_events_str->data; |
| + json_output_.json_output.clear(); |
| + trace_buffer_.Start(); |
| + trace_buffer_.AddFragment(events_str->data); |
| + trace_buffer_.Finish(); |
| scoped_ptr<Value> root; |
| - root.reset(base::JSONReader::Read(json_events_str->data, false)); |
| + root.reset(base::JSONReader::Read(json_output_.json_output, false)); |
| ListValue* root_list = NULL; |
| ASSERT_TRUE(root.get()); |
| @@ -281,8 +286,7 @@ void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) { |
| task_complete_event->Signal(); |
| } |
| -void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed, |
| - const std::string& trace_string) { |
| +void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed) { |
| DictionaryValue* item = NULL; |
| #define EXPECT_FIND_(string) \ |
| @@ -345,7 +349,7 @@ void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed, |
| } |
| void TraceManyInstantEvents(int thread_id, int num_events, |
| - WaitableEvent* task_complete_event) { |
| + WaitableEvent* task_complete_event) { |
| for (int i = 0; i < num_events; i++) { |
| TRACE_EVENT_INSTANT2("all", "multi thread event", |
| "thread", thread_id, |
| @@ -357,8 +361,8 @@ void TraceManyInstantEvents(int thread_id, int num_events, |
| } |
| void ValidateInstantEventPresentOnEveryThread(const ListValue& trace_parsed, |
| - const std::string& trace_string, |
| - int num_threads, int num_events) { |
| + int num_threads, |
| + int num_events) { |
| std::map<int, std::map<int, bool> > results; |
| size_t trace_parsed_count = trace_parsed.GetSize(); |
| @@ -406,7 +410,7 @@ TEST_F(TraceEventTestFixture, DataCaptured) { |
| TraceLog::GetInstance()->SetEnabled(false); |
| - ValidateAllTraceMacrosCreatedData(trace_parsed_, trace_string_); |
| + ValidateAllTraceMacrosCreatedData(trace_parsed_); |
| } |
| // Test that categories work. |
| @@ -687,7 +691,7 @@ TEST_F(TraceEventTestFixture, DataCapturedOnThread) { |
| thread.Stop(); |
| TraceLog::GetInstance()->SetEnabled(false); |
| - ValidateAllTraceMacrosCreatedData(trace_parsed_, trace_string_); |
| + ValidateAllTraceMacrosCreatedData(trace_parsed_); |
| } |
| // Test that data sent from multiple threads is gathered |
| @@ -720,7 +724,7 @@ TEST_F(TraceEventTestFixture, DataCapturedManyThreads) { |
| TraceLog::GetInstance()->SetEnabled(false); |
| - ValidateInstantEventPresentOnEveryThread(trace_parsed_, trace_string_, |
| + ValidateInstantEventPresentOnEveryThread(trace_parsed_, |
| num_threads, num_events); |
| } |
| @@ -925,5 +929,27 @@ TEST_F(TraceEventTestFixture, DeepCopy) { |
| EXPECT_EQ("val2", s); |
| } |
| +// Test that TraceResultBuffer outputs the correct result whether it is added |
| +// in chunks or added all at once. |
| +TEST_F(TraceEventTestFixture, TraceResultBuffer) { |
| + ManualTestSetUp(); |
| + |
| + Clear(); |
| + |
| + trace_buffer_.Start(); |
| + trace_buffer_.AddFragment("bla1"); |
| + trace_buffer_.AddFragment("bla2"); |
| + trace_buffer_.AddFragment("bla3,bla4"); |
| + trace_buffer_.Finish(); |
| + EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
| + |
| + Clear(); |
|
nduca
2011/10/20 23:20:05
This is two tests, no?
jbates
2011/10/20 23:55:13
Easier to follow in one test IMO. Is there a rule
|
| + |
| + trace_buffer_.Start(); |
| + trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); |
| + trace_buffer_.Finish(); |
| + EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
| +} |
| + |
|
nduca
2011/10/20 23:20:05
Output callback test?
Any corner cases?
Not a big
jbates
2011/10/20 23:55:13
Output callback is tested by every other test now,
|
| } // namespace debug |
| } // namespace base |