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

Side by Side Diff: base/trace_event/trace_event_unittest.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix installation_validator_unittest Created 4 years, 6 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
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 "base/trace_event/trace_event.h" 5 #include "base/trace_event/trace_event.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 2974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 std::string* g_log_buffer = NULL; 2985 std::string* g_log_buffer = NULL;
2986 bool MockLogMessageHandler(int, const char*, int, size_t, 2986 bool MockLogMessageHandler(int, const char*, int, size_t,
2987 const std::string& str) { 2987 const std::string& str) {
2988 if (!g_log_buffer) 2988 if (!g_log_buffer)
2989 g_log_buffer = new std::string(); 2989 g_log_buffer = new std::string();
2990 g_log_buffer->append(str); 2990 g_log_buffer->append(str);
2991 return false; 2991 return false;
2992 } 2992 }
2993 2993
2994 TEST_F(TraceEventTestFixture, EchoToConsole) { 2994 TEST_F(TraceEventTestFixture, EchoToConsole) {
2995 logging::LogMessageHandlerFunction old_log_message_handler = 2995 logging::PushLogMessageHandler(MockLogMessageHandler);
2996 logging::GetLogMessageHandler();
2997 logging::SetLogMessageHandler(MockLogMessageHandler);
2998 2996
2999 TraceLog::GetInstance()->SetEnabled( 2997 TraceLog::GetInstance()->SetEnabled(
3000 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), 2998 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE),
3001 TraceLog::RECORDING_MODE); 2999 TraceLog::RECORDING_MODE);
3002 TRACE_EVENT_BEGIN0("a", "begin_end"); 3000 TRACE_EVENT_BEGIN0("a", "begin_end");
3003 { 3001 {
3004 TRACE_EVENT0("b", "duration"); 3002 TRACE_EVENT0("b", "duration");
3005 TRACE_EVENT0("b1", "duration1"); 3003 TRACE_EVENT0("b1", "duration1");
3006 } 3004 }
3007 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); 3005 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL);
3008 TRACE_EVENT_END0("a", "begin_end"); 3006 TRACE_EVENT_END0("a", "begin_end");
3009 3007
3010 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); 3008 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b"));
3011 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); 3009 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b"));
3012 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); 3010 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b"));
3013 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); 3011 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] ("));
3014 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); 3012 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] ("));
3015 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); 3013 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b"));
3016 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); 3014 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] ("));
3017 3015
3018 EndTraceAndFlush(); 3016 EndTraceAndFlush();
3019 delete g_log_buffer; 3017 delete g_log_buffer;
3020 logging::SetLogMessageHandler(old_log_message_handler); 3018 logging::PopLogMessageHandler();
3021 g_log_buffer = NULL; 3019 g_log_buffer = NULL;
3022 } 3020 }
3023 3021
3024 bool LogMessageHandlerWithTraceEvent(int, const char*, int, size_t, 3022 bool LogMessageHandlerWithTraceEvent(int, const char*, int, size_t,
3025 const std::string&) { 3023 const std::string&) {
3026 TRACE_EVENT0("log", "trace_event"); 3024 TRACE_EVENT0("log", "trace_event");
3027 return false; 3025 return false;
3028 } 3026 }
3029 3027
3030 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { 3028 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) {
3031 logging::LogMessageHandlerFunction old_log_message_handler = 3029 logging::PushLogMessageHandler(LogMessageHandlerWithTraceEvent);
3032 logging::GetLogMessageHandler();
3033 logging::SetLogMessageHandler(LogMessageHandlerWithTraceEvent);
3034 3030
3035 TraceLog::GetInstance()->SetEnabled( 3031 TraceLog::GetInstance()->SetEnabled(
3036 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), 3032 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE),
3037 TraceLog::RECORDING_MODE); 3033 TraceLog::RECORDING_MODE);
3038 { 3034 {
3039 // This should not cause deadlock or infinite recursion. 3035 // This should not cause deadlock or infinite recursion.
3040 TRACE_EVENT0("b", "duration"); 3036 TRACE_EVENT0("b", "duration");
3041 } 3037 }
3042 3038
3043 EndTraceAndFlush(); 3039 EndTraceAndFlush();
3044 logging::SetLogMessageHandler(old_log_message_handler); 3040 logging::PopLogMessageHandler();
3045 } 3041 }
3046 3042
3047 TEST_F(TraceEventTestFixture, TimeOffset) { 3043 TEST_F(TraceEventTestFixture, TimeOffset) {
3048 BeginTrace(); 3044 BeginTrace();
3049 // Let TraceLog timer start from 0. 3045 // Let TraceLog timer start from 0.
3050 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); 3046 TimeDelta time_offset = TimeTicks::Now() - TimeTicks();
3051 TraceLog::GetInstance()->SetTimeOffset(time_offset); 3047 TraceLog::GetInstance()->SetTimeOffset(time_offset);
3052 3048
3053 { 3049 {
3054 TRACE_EVENT0("all", "duration1"); 3050 TRACE_EVENT0("all", "duration1");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 } 3110 }
3115 3111
3116 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { 3112 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) {
3117 const char filter[] = "DELAY(test.Delay;16;oneshot)"; 3113 const char filter[] = "DELAY(test.Delay;16;oneshot)";
3118 TraceConfig config(filter, ""); 3114 TraceConfig config(filter, "");
3119 EXPECT_EQ(filter, config.ToCategoryFilterString()); 3115 EXPECT_EQ(filter, config.ToCategoryFilterString());
3120 } 3116 }
3121 3117
3122 } // namespace trace_event 3118 } // namespace trace_event
3123 } // namespace base 3119 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698