Clean up TraceCallback::Print.
Review URL: https://webrtc-codereview.appspot.com/936024 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3102 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
8123ed74dd
commit
23ec30bdfc
@ -103,17 +103,14 @@ enum TraceLevel
|
||||
};
|
||||
|
||||
// External Trace API
|
||||
class TraceCallback
|
||||
{
|
||||
public:
|
||||
virtual void Print(const TraceLevel level,
|
||||
const char *traceString,
|
||||
const int length) = 0;
|
||||
protected:
|
||||
virtual ~TraceCallback() {}
|
||||
TraceCallback() {}
|
||||
};
|
||||
class TraceCallback {
|
||||
public:
|
||||
virtual void Print(TraceLevel level, const char* message, int length) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~TraceCallback() {}
|
||||
TraceCallback() {}
|
||||
};
|
||||
|
||||
enum FileFormats
|
||||
{
|
||||
|
@ -24,31 +24,12 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "modules/udp_transport/source/udp_socket_wrapper.h"
|
||||
#include "modules/udp_transport/source/udp_socket_manager_wrapper.h"
|
||||
#include "system_wrappers/interface/trace.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
const int kLogTrace = 0;
|
||||
|
||||
class TestTraceCallback: public TraceCallback {
|
||||
public:
|
||||
void Print(const TraceLevel level,
|
||||
const char *traceString,
|
||||
const int length) {
|
||||
if (traceString) {
|
||||
char* tmp = new char[length+1];
|
||||
memcpy(tmp, traceString, length);
|
||||
tmp[length] = '\0';
|
||||
printf("%s\n", tmp);
|
||||
fflush(stdout);
|
||||
delete[] tmp;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class MockSocketManager : public UdpSocketManager {
|
||||
public:
|
||||
MockSocketManager() {}
|
||||
@ -67,20 +48,10 @@ class MockSocketManager : public UdpSocketManager {
|
||||
// Creates a socket using the static constructor method and verifies that
|
||||
// it's added to the socket manager.
|
||||
TEST(UdpSocketWrapper, CreateSocket) {
|
||||
TestTraceCallback trace;
|
||||
if (kLogTrace) {
|
||||
Trace::CreateTrace();
|
||||
Trace::SetLevelFilter(webrtc::kTraceAll);
|
||||
Trace::SetTraceCallback(&trace);
|
||||
}
|
||||
|
||||
WebRtc_Word32 id = 42;
|
||||
// We can't test deletion of sockets without a socket manager.
|
||||
WebRtc_UWord8 threads = 1;
|
||||
UdpSocketManager* mgr = UdpSocketManager::Create(id, threads);
|
||||
WEBRTC_TRACE(kTraceMemory, kTraceTransport, 42,
|
||||
"Test trace call");
|
||||
|
||||
UdpSocketWrapper* socket
|
||||
= UdpSocketWrapper::CreateSocket(id,
|
||||
mgr,
|
||||
@ -90,9 +61,6 @@ TEST(UdpSocketWrapper, CreateSocket) {
|
||||
false); // disableGQOS
|
||||
socket->CloseBlocking();
|
||||
UdpSocketManager::Return();
|
||||
if (kLogTrace) {
|
||||
Trace::ReturnTrace();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
@ -24,9 +24,7 @@ const size_t kBoilerplateLength = 71;
|
||||
|
||||
class LoggingTest : public ::testing::Test, public TraceCallback {
|
||||
public:
|
||||
virtual void Print(const TraceLevel level,
|
||||
const char* msg,
|
||||
const int length) {
|
||||
virtual void Print(TraceLevel level, const char* msg, int length) {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
// We test the length here to ensure (with high likelihood) that only our
|
||||
// traces will be tested.
|
||||
|
@ -12,56 +12,10 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "system_wrappers/interface/scoped_ptr.h"
|
||||
#include "system_wrappers/interface/trace.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
const int kLogTrace = 0;
|
||||
|
||||
class TestTraceCallback : public TraceCallback {
|
||||
public:
|
||||
virtual void Print(const TraceLevel level,
|
||||
const char* traceString,
|
||||
const int length) {
|
||||
if (traceString) {
|
||||
char* cmd_print = new char[length+1];
|
||||
memcpy(cmd_print, traceString, length);
|
||||
cmd_print[length] = '\0';
|
||||
printf("%s\n", cmd_print);
|
||||
fflush(stdout);
|
||||
delete[] cmd_print;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ThreadTest : public ::testing::Test {
|
||||
public:
|
||||
ThreadTest() {
|
||||
StartTrace();
|
||||
}
|
||||
~ThreadTest() {
|
||||
StopTrace();
|
||||
}
|
||||
|
||||
private:
|
||||
void StartTrace() {
|
||||
if (kLogTrace) {
|
||||
Trace::CreateTrace();
|
||||
Trace::SetLevelFilter(webrtc::kTraceAll);
|
||||
Trace::SetTraceCallback(&trace_);
|
||||
}
|
||||
}
|
||||
|
||||
void StopTrace() {
|
||||
if (kLogTrace) {
|
||||
Trace::ReturnTrace();
|
||||
}
|
||||
}
|
||||
|
||||
TestTraceCallback trace_;
|
||||
};
|
||||
|
||||
TEST_F(ThreadTest, NullFunctionPointer) {
|
||||
TEST(ThreadTest, NullFunctionPointer) {
|
||||
webrtc::scoped_ptr<ThreadWrapper> thread(
|
||||
webrtc::ThreadWrapper::CreateThread());
|
||||
unsigned int id = 42;
|
||||
@ -73,7 +27,7 @@ bool NullRunFunction(void* /* obj */) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST_F(ThreadTest, StartStop) {
|
||||
TEST(ThreadTest, StartStop) {
|
||||
ThreadWrapper* thread = ThreadWrapper::CreateThread(&NullRunFunction);
|
||||
unsigned int id = 42;
|
||||
ASSERT_TRUE(thread->Start(id));
|
||||
@ -88,7 +42,7 @@ bool SetFlagRunFunction(void* obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST_F(ThreadTest, RunFunctionIsCalled) {
|
||||
TEST(ThreadTest, RunFunctionIsCalled) {
|
||||
bool flag = false;
|
||||
ThreadWrapper* thread = ThreadWrapper::CreateThread(&SetFlagRunFunction,
|
||||
&flag);
|
||||
|
@ -23,12 +23,10 @@ namespace webrtc {
|
||||
|
||||
class TestTraceCallback : public TraceCallback {
|
||||
public:
|
||||
virtual void Print(const TraceLevel level,
|
||||
const char* traceString,
|
||||
const int length) {
|
||||
if (traceString) {
|
||||
virtual void Print(TraceLevel level, const char* msg, int length) {
|
||||
if (msg) {
|
||||
char* cmd_print = new char[length+1];
|
||||
memcpy(cmd_print, traceString, length);
|
||||
memcpy(cmd_print, msg, length);
|
||||
cmd_print[length] = '\0';
|
||||
printf("%s\n", cmd_print);
|
||||
fflush(stdout);
|
||||
|
Loading…
Reference in New Issue
Block a user