michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Original author: bcampen@mozilla.com michael@0: michael@0: #ifndef gtest_ringbuffer_dumper_h__ michael@0: #define gtest_ringbuffer_dumper_h__ michael@0: michael@0: #include "mozilla/SyncRunnable.h" michael@0: michael@0: #define GTEST_HAS_RTTI 0 michael@0: #include "gtest/gtest.h" michael@0: #include "gtest_utils.h" michael@0: michael@0: #include "runnable_utils.h" michael@0: #include "rlogringbuffer.h" michael@0: michael@0: using mozilla::RLogRingBuffer; michael@0: using mozilla::WrapRunnable; michael@0: michael@0: namespace test { michael@0: class RingbufferDumper : public ::testing::EmptyTestEventListener { michael@0: public: michael@0: explicit RingbufferDumper(MtransportTestUtils* test_utils) : michael@0: test_utils_(test_utils) michael@0: {} michael@0: michael@0: void ClearRingBuffer_s() { michael@0: RLogRingBuffer::CreateInstance(); michael@0: // Set limit to zero to clear the ringbuffer michael@0: RLogRingBuffer::GetInstance()->SetLogLimit(0); michael@0: RLogRingBuffer::GetInstance()->SetLogLimit(UINT32_MAX); michael@0: } michael@0: michael@0: void DestroyRingBuffer_s() { michael@0: RLogRingBuffer::DestroyInstance(); michael@0: } michael@0: michael@0: void DumpRingBuffer_s() { michael@0: std::deque logs; michael@0: // Get an unlimited number of log lines, with no filter michael@0: RLogRingBuffer::GetInstance()->GetAny(0, &logs); michael@0: for (auto l = logs.begin(); l != logs.end(); ++l) { michael@0: std::cout << *l << std::endl; michael@0: } michael@0: ClearRingBuffer_s(); michael@0: } michael@0: michael@0: virtual void OnTestStart(const ::testing::TestInfo& testInfo) { michael@0: mozilla::SyncRunnable::DispatchToThread( michael@0: test_utils_->sts_target(), michael@0: WrapRunnable(this, &RingbufferDumper::ClearRingBuffer_s)); michael@0: } michael@0: michael@0: virtual void OnTestEnd(const ::testing::TestInfo& testInfo) { michael@0: mozilla::SyncRunnable::DispatchToThread( michael@0: test_utils_->sts_target(), michael@0: WrapRunnable(this, &RingbufferDumper::DestroyRingBuffer_s)); michael@0: } michael@0: michael@0: // Called after a failed assertion or a SUCCEED() invocation. michael@0: virtual void OnTestPartResult(const ::testing::TestPartResult& testResult) { michael@0: if (testResult.failed()) { michael@0: // Dump (and empty) the RLogRingBuffer michael@0: mozilla::SyncRunnable::DispatchToThread( michael@0: test_utils_->sts_target(), michael@0: WrapRunnable(this, &RingbufferDumper::DumpRingBuffer_s)); michael@0: } michael@0: } michael@0: michael@0: private: michael@0: MtransportTestUtils *test_utils_; michael@0: }; michael@0: michael@0: } // namespace test michael@0: michael@0: #endif // gtest_ringbuffer_dumper_h__ michael@0: michael@0: michael@0: