blob: e0208e2186183f633619a6344f0a805c59f2b2b9 [file] [log] [blame]
andrew@webrtc.org19eefdc2011-09-14 17:02:44 +00001/*
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.orgc1ffd332013-03-22 17:13:23 +000013#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.org19eefdc2011-09-14 17:02:44 +000019
20namespace webrtc {
kjellander@webrtc.org20a370e2011-11-04 01:19:16 +000021namespace test {
kjellander@webrtc.org83b767b2012-10-15 18:14:12 +000022
andrew@webrtc.orgc1ffd332013-03-22 17:13:23 +000023const int kLevelFilter = kTraceError | kTraceWarning | kTraceTerseInfo;
24
25class 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
43TestSuite::TestSuite(int argc, char** argv)
44 : trace_callback_(new TraceCallbackImpl) {
kjellander@webrtc.org193600b2012-10-17 04:39:44 +000045 SetExecutablePath(argv[0]);
kjellander@webrtc.org20a370e2011-11-04 01:19:16 +000046 testing::InitGoogleMock(&argc, argv); // Runs InitGoogleTest() internally.
andrew@webrtc.org19eefdc2011-09-14 17:02:44 +000047}
48
49TestSuite::~TestSuite() {
50}
51
52int TestSuite::Run() {
53 Initialize();
54 int result = RUN_ALL_TESTS();
55 Shutdown();
56 return result;
57}
58
59void TestSuite::Initialize() {
andrew@webrtc.orgc1ffd332013-03-22 17:13:23 +000060 Trace::CreateTrace();
61 Trace::SetTraceCallback(trace_callback_.get());
62 Trace::SetLevelFilter(kLevelFilter);
andrew@webrtc.org19eefdc2011-09-14 17:02:44 +000063}
64
65void TestSuite::Shutdown() {
andrew@webrtc.orgc1ffd332013-03-22 17:13:23 +000066 Trace::SetTraceCallback(NULL);
67 Trace::ReturnTrace();
andrew@webrtc.org19eefdc2011-09-14 17:02:44 +000068}
andrew@webrtc.orgc1ffd332013-03-22 17:13:23 +000069
kjellander@webrtc.org20a370e2011-11-04 01:19:16 +000070} // namespace test
andrew@webrtc.org19eefdc2011-09-14 17:02:44 +000071} // namespace webrtc