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