andrew@webrtc.org | 19eefdc | 2011-09-14 17:02:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "test/test_suite.h" |
| 12 | |
andrew@webrtc.org | c1ffd33 | 2013-03-22 17:13:23 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | |
| 15 | #include "testing/gmock/include/gmock/gmock.h" |
| 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | #include "test/testsupport/fileutils.h" |
| 18 | #include "webrtc/system_wrappers/interface/trace.h" |
andrew@webrtc.org | 19eefdc | 2011-09-14 17:02:44 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
kjellander@webrtc.org | 20a370e | 2011-11-04 01:19:16 +0000 | [diff] [blame] | 21 | namespace test { |
kjellander@webrtc.org | 83b767b | 2012-10-15 18:14:12 +0000 | [diff] [blame] | 22 | |
andrew@webrtc.org | c1ffd33 | 2013-03-22 17:13:23 +0000 | [diff] [blame] | 23 | const int kLevelFilter = kTraceError | kTraceWarning | kTraceTerseInfo; |
| 24 | |
| 25 | class TraceCallbackImpl : public TraceCallback { |
| 26 | public: |
| 27 | TraceCallbackImpl() { } |
| 28 | virtual ~TraceCallbackImpl() { } |
| 29 | |
| 30 | virtual void Print(TraceLevel level, const char* msg_array, int length) { |
| 31 | if (level & kLevelFilter) { |
| 32 | ASSERT_GT(length, Trace::kBoilerplateLength); |
| 33 | std::string msg = msg_array; |
| 34 | std::string msg_time = msg.substr(Trace::kTimestampPosition, |
| 35 | Trace::kTimestampLength); |
| 36 | std::string msg_log = msg.substr(Trace::kBoilerplateLength); |
| 37 | fprintf(stderr, "%s %s\n", msg_time.c_str(), msg_log.c_str()); |
| 38 | fflush(stderr); |
| 39 | } |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | TestSuite::TestSuite(int argc, char** argv) |
| 44 | : trace_callback_(new TraceCallbackImpl) { |
kjellander@webrtc.org | 193600b | 2012-10-17 04:39:44 +0000 | [diff] [blame] | 45 | SetExecutablePath(argv[0]); |
kjellander@webrtc.org | 20a370e | 2011-11-04 01:19:16 +0000 | [diff] [blame] | 46 | testing::InitGoogleMock(&argc, argv); // Runs InitGoogleTest() internally. |
andrew@webrtc.org | 19eefdc | 2011-09-14 17:02:44 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | TestSuite::~TestSuite() { |
| 50 | } |
| 51 | |
| 52 | int TestSuite::Run() { |
| 53 | Initialize(); |
| 54 | int result = RUN_ALL_TESTS(); |
| 55 | Shutdown(); |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | void TestSuite::Initialize() { |
andrew@webrtc.org | c1ffd33 | 2013-03-22 17:13:23 +0000 | [diff] [blame] | 60 | Trace::CreateTrace(); |
| 61 | Trace::SetTraceCallback(trace_callback_.get()); |
| 62 | Trace::SetLevelFilter(kLevelFilter); |
andrew@webrtc.org | 19eefdc | 2011-09-14 17:02:44 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void TestSuite::Shutdown() { |
andrew@webrtc.org | c1ffd33 | 2013-03-22 17:13:23 +0000 | [diff] [blame] | 66 | Trace::SetTraceCallback(NULL); |
| 67 | Trace::ReturnTrace(); |
andrew@webrtc.org | 19eefdc | 2011-09-14 17:02:44 +0000 | [diff] [blame] | 68 | } |
andrew@webrtc.org | c1ffd33 | 2013-03-22 17:13:23 +0000 | [diff] [blame] | 69 | |
kjellander@webrtc.org | 20a370e | 2011-11-04 01:19:16 +0000 | [diff] [blame] | 70 | } // namespace test |
andrew@webrtc.org | 19eefdc | 2011-09-14 17:02:44 +0000 | [diff] [blame] | 71 | } // namespace webrtc |