Index: webrtc/pc/rtcstats_integrationtest.cc |
diff --git a/webrtc/pc/rtcstats_integrationtest.cc b/webrtc/pc/rtcstats_integrationtest.cc |
index 56a4ef11edae0c74339569cd760b1cc530986a6c..1847c4077df69aa62316af79d6caade69c830b61 100644 |
--- a/webrtc/pc/rtcstats_integrationtest.cc |
+++ b/webrtc/pc/rtcstats_integrationtest.cc |
@@ -24,6 +24,7 @@ |
#include "webrtc/rtc_base/gunit.h" |
#include "webrtc/rtc_base/refcountedobject.h" |
#include "webrtc/rtc_base/scoped_ref_ptr.h" |
+#include "webrtc/rtc_base/trace_event.h" |
#include "webrtc/rtc_base/virtualsocketserver.h" |
namespace webrtc { |
@@ -33,27 +34,64 @@ namespace { |
const int64_t kGetStatsTimeoutMs = 10000; |
const unsigned char* GetCategoryEnabledHandler(const char* name) { |
- return reinterpret_cast<const unsigned char*>("webrtc_stats"); |
+ if (strcmp("webrtc_stats", name) != 0) { |
+ return reinterpret_cast<const unsigned char*>("\0"); |
hbos
2017/08/14 13:15:39
All string literals are null-terminated, should th
ehmaldonado_webrtc
2017/08/14 13:43:24
Right, thanks.
|
+ } |
+ return reinterpret_cast<const unsigned char*>(name); |
} |
-void AddTraceEventHandler(char phase, |
- const unsigned char* category_enabled, |
- const char* name, |
- unsigned long long id, |
- int num_args, |
- const char** arg_names, |
- const unsigned char* arg_types, |
- const unsigned long long* arg_values, |
- unsigned char flags) { |
- // Do nothing |
-} |
+class RTCStatsTracedReport { |
+ public: |
+ static RTCStatsTracedReport* Get() { |
+ static RTCStatsTracedReport* traced_report = nullptr; |
+ if (!traced_report) |
+ traced_report = new RTCStatsTracedReport(); |
+ return traced_report; |
+ } |
+ |
+ static void AddTraceEventHandler(char phase, |
+ const unsigned char* category_enabled, |
+ const char* name, |
+ unsigned long long id, |
+ int num_args, |
+ const char** arg_names, |
+ const unsigned char* arg_types, |
+ const unsigned long long* arg_values, |
+ unsigned char flags) { |
+ RTCStatsTracedReport* traced_report = RTCStatsTracedReport::Get(); |
+ EXPECT_FALSE(traced_report->report_received_); |
+ EXPECT_STREQ("webrtc_stats", |
+ reinterpret_cast<const char*>(category_enabled)); |
+ EXPECT_STREQ("webrtc_stats", name); |
+ EXPECT_EQ(1, num_args); |
+ EXPECT_STREQ("report", arg_names[0]); |
+ EXPECT_EQ(TRACE_VALUE_TYPE_COPY_STRING, arg_types[0]); |
+ |
+ traced_report->report_received_ = true; |
+ traced_report->traced_report_ = |
+ reinterpret_cast<const char*>(arg_values[0]); |
+ } |
+ |
+ void Reset() { report_received_ = false; } |
+ |
+ const std::string& GetTracedReport() const { |
+ EXPECT_TRUE(report_received_); |
+ return traced_report_; |
+ } |
+ |
+ private: |
+ std::string traced_report_; |
+ bool report_received_; |
hbos
2017/08/14 13:15:39
Add a constructor that default-initializes this to
ehmaldonado_webrtc
2017/08/14 13:43:24
Done.
|
+}; |
class RTCStatsIntegrationTest : public testing::Test { |
public: |
RTCStatsIntegrationTest() |
: network_thread_(new rtc::Thread(&virtual_socket_server_)), |
worker_thread_(rtc::Thread::Create()) { |
- SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler); |
+ RTCStatsTracedReport::Get()->Reset(); |
+ SetupEventTracer(&GetCategoryEnabledHandler, |
+ &RTCStatsTracedReport::AddTraceEventHandler); |
hbos
2017/08/14 13:15:39
Because of the usage of a global variable, it is w
ehmaldonado_webrtc
2017/08/14 13:43:24
Done.
|
RTC_CHECK(network_thread_->Start()); |
RTC_CHECK(worker_thread_->Start()); |
@@ -650,6 +688,7 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCaller) { |
rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCaller(); |
RTCStatsReportVerifier(report.get()).VerifyReport(); |
+ EXPECT_EQ(report->ToJson(), RTCStatsTracedReport::Get()->GetTracedReport()); |
} |
TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { |
@@ -657,6 +696,7 @@ TEST_F(RTCStatsIntegrationTest, GetStatsFromCallee) { |
rtc::scoped_refptr<const RTCStatsReport> report = GetStatsFromCallee(); |
RTCStatsReportVerifier(report.get()).VerifyReport(); |
+ EXPECT_EQ(report->ToJson(), RTCStatsTracedReport::Get()->GetTracedReport()); |
} |
TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { |
@@ -670,6 +710,8 @@ TEST_F(RTCStatsIntegrationTest, GetsStatsWhileDestroyingPeerConnections) { |
// Any pending stats requests should have completed in the act of destroying |
// the peer connection. |
EXPECT_TRUE(stats_obtainer->report()); |
+ EXPECT_EQ(stats_obtainer->report()->ToJson(), |
+ RTCStatsTracedReport::Get()->GetTracedReport()); |
} |
#endif // HAVE_SCTP |