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

Unified Diff: webrtc/system_wrappers/source/logging_unittest.cc

Issue 1590983005: Simplify the implementation of LoggingTest. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove unnecessary expectation Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/system_wrappers/source/logging_unittest.cc
diff --git a/webrtc/system_wrappers/source/logging_unittest.cc b/webrtc/system_wrappers/source/logging_unittest.cc
index 2da24b26f443ffeb912b0d6b987e1f278757a04a..695b03f93a09cb7cd6e7ee34c73a31618303792a 100644
--- a/webrtc/system_wrappers/source/logging_unittest.cc
+++ b/webrtc/system_wrappers/source/logging_unittest.cc
@@ -11,66 +11,48 @@
#include "webrtc/system_wrappers/include/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/base/arraysize.h"
+#include "webrtc/base/event.h"
#include "webrtc/base/scoped_ptr.h"
-#include "webrtc/system_wrappers/include/condition_variable_wrapper.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-#include "webrtc/system_wrappers/include/sleep.h"
#include "webrtc/system_wrappers/include/trace.h"
namespace webrtc {
namespace {
+const char kTestLogString[] = "Incredibly important test message!(?)";
+const int kTestLevel = kTraceWarning;
-class LoggingTest : public ::testing::Test, public TraceCallback {
+class LoggingTestCallback : public TraceCallback {
public:
- 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.
- if (level_ != kTraceNone && static_cast<int>(expected_log_.str().size()) ==
- length - Trace::kBoilerplateLength - 1) {
- EXPECT_EQ(level_, level);
- EXPECT_EQ(expected_log_.str(), &msg[Trace::kBoilerplateLength]);
- level_ = kTraceNone;
- cv_->Wake();
+ LoggingTestCallback(rtc::Event* event) : event_(event) {}
+
+ private:
+ void Print(TraceLevel level, const char* msg, int length) override {
+ if (static_cast<size_t>(length) < arraysize(kTestLogString) ||
+ level != kTestLevel) {
+ return;
}
- }
- protected:
- LoggingTest()
- : crit_(CriticalSectionWrapper::CreateCriticalSection()),
- cv_(ConditionVariableWrapper::CreateConditionVariable()),
- level_(kTraceNone),
- expected_log_() {
+ std::string msg_str(msg, length);
+ if (msg_str.find(kTestLogString) != std::string::npos)
+ event_->Set();
}
- void SetUp() {
- Trace::CreateTrace();
- Trace::SetTraceCallback(this);
- }
+ rtc::Event* const event_;
+};
- void TearDown() {
- Trace::SetTraceCallback(NULL);
- Trace::ReturnTrace();
- CriticalSectionScoped cs(crit_.get());
- ASSERT_EQ(kTraceNone, level_) << "Print() was not called";
- }
+} // namespace
- rtc::scoped_ptr<CriticalSectionWrapper> crit_;
- rtc::scoped_ptr<ConditionVariableWrapper> cv_;
- TraceLevel level_ GUARDED_BY(crit_);
- std::ostringstream expected_log_ GUARDED_BY(crit_);
-};
+TEST(LoggingTest, LogStream) {
+ Trace::CreateTrace();
-TEST_F(LoggingTest, LogStream) {
- {
- CriticalSectionScoped cs(crit_.get());
- level_ = kTraceWarning;
- std::string msg = "Important message";
- expected_log_ << "(logging_unittest.cc:" << __LINE__ + 1 << "): " << msg;
- LOG(LS_WARNING) << msg;
- cv_->SleepCS(*crit_.get(), 2000);
- }
-}
+ rtc::Event event(false, false);
+ LoggingTestCallback callback(&event);
+ Trace::SetTraceCallback(&callback);
-} // namespace
+ LOG(LS_WARNING) << kTestLogString;
+ EXPECT_TRUE(event.Wait(2000));
+
+ Trace::SetTraceCallback(nullptr);
+ Trace::ReturnTrace();
+}
} // namespace webrtc
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698