Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/debug/trace_event_unittest.h" | 5 #include "base/debug/trace_event_unittest.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 } | 71 } |
| 72 | 72 |
| 73 void EndTraceAndFlush() { | 73 void EndTraceAndFlush() { |
| 74 TraceLog::GetInstance()->SetDisabled(); | 74 TraceLog::GetInstance()->SetDisabled(); |
| 75 TraceLog::GetInstance()->Flush( | 75 TraceLog::GetInstance()->Flush( |
| 76 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, | 76 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, |
| 77 base::Unretained(this))); | 77 base::Unretained(this))); |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual void SetUp() OVERRIDE { | 80 virtual void SetUp() OVERRIDE { |
| 81 old_thread_name_ = PlatformThread::GetName(); | 81 const char* name = PlatformThread::GetName(); |
| 82 old_thread_name_ = name ? strdup(name) : NULL; | |
| 82 } | 83 } |
| 83 virtual void TearDown() OVERRIDE { | 84 virtual void TearDown() OVERRIDE { |
| 84 if (TraceLog::GetInstance()) | 85 if (TraceLog::GetInstance()) |
| 85 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); | 86 EXPECT_FALSE(TraceLog::GetInstance()->IsEnabled()); |
| 86 PlatformThread::SetName(old_thread_name_ ? old_thread_name_ : ""); | 87 if (old_thread_name_) { |
| 88 PlatformThread::SetName(old_thread_name_); | |
| 89 free(old_thread_name_); | |
| 90 old_thread_name_ = NULL; | |
|
jar (doing other things)
2012/12/21 00:17:00
nit: Using the fact that you can free a NULL point
dsinclair
2012/12/21 16:28:59
Done.
That's a lot nicer, didn't realize free(NUL
| |
| 91 } else { | |
| 92 PlatformThread::SetName(""); | |
| 93 } | |
| 87 } | 94 } |
| 88 | 95 |
| 89 const char* old_thread_name_; | 96 char* old_thread_name_; |
| 90 ListValue trace_parsed_; | 97 ListValue trace_parsed_; |
| 91 base::debug::TraceResultBuffer trace_buffer_; | 98 base::debug::TraceResultBuffer trace_buffer_; |
| 92 base::debug::TraceResultBuffer::SimpleOutput json_output_; | 99 base::debug::TraceResultBuffer::SimpleOutput json_output_; |
| 93 int event_watch_notification_; | 100 int event_watch_notification_; |
| 94 | 101 |
| 95 private: | 102 private: |
| 96 // We want our singleton torn down after each test. | 103 // We want our singleton torn down after each test. |
| 97 ShadowingAtExitManager at_exit_manager_; | 104 ShadowingAtExitManager at_exit_manager_; |
| 98 Lock lock_; | 105 Lock lock_; |
| 99 }; | 106 }; |
| (...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1332 Clear(); | 1339 Clear(); |
| 1333 | 1340 |
| 1334 trace_buffer_.Start(); | 1341 trace_buffer_.Start(); |
| 1335 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); | 1342 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); |
| 1336 trace_buffer_.Finish(); | 1343 trace_buffer_.Finish(); |
| 1337 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); | 1344 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
| 1338 } | 1345 } |
| 1339 | 1346 |
| 1340 } // namespace debug | 1347 } // namespace debug |
| 1341 } // namespace base | 1348 } // namespace base |
| OLD | NEW |