main.cc revision f2477e01787aa58f445919b809d89e252beef54f
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <string>
6
7#include "gtest/gtest.h"
8
9#if defined(SEL_LDR)
10
11int main(int argc, char* argv[]) {
12  ::testing::InitGoogleTest(&argc, argv);
13  return RUN_ALL_TESTS();
14}
15
16#else
17
18#include "ppapi/cpp/instance.h"
19#include "ppapi/cpp/var.h"
20#include "ppapi_simple/ps_main.h"
21
22#if defined(WIN32)
23#include <Windows.h>
24#undef PostMessage
25#endif
26
27class GTestEventListener : public ::testing::EmptyTestEventListener {
28 public:
29  // TestEventListener overrides.
30  virtual void OnTestStart(const ::testing::TestInfo& test_info) {
31    std::stringstream msg;
32    msg << "start:" << test_info.test_case_name() << "." << test_info.name();
33    pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
34  }
35
36  virtual void OnTestPartResult(
37      const ::testing::TestPartResult& test_part_result) {
38    if (test_part_result.failed()) {
39      std::stringstream msg;
40      msg << "fail:" << test_part_result.file_name() << ","
41          << test_part_result.line_number() << ","
42          << test_part_result.summary();
43      pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
44    }
45  }
46
47  virtual void OnTestEnd(const ::testing::TestInfo& test_info) {
48    std::stringstream msg;
49    msg << "end:" << test_info.test_case_name() << "." << test_info.name()
50        << "," << (test_info.result()->Failed() ? "failed" : "ok");
51    pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
52  }
53};
54
55int example_main(int argc, char* argv[]) {
56  ::testing::InitGoogleTest(&argc, argv);
57  ::testing::UnitTest::GetInstance()->listeners()
58      .Append(new GTestEventListener());
59  return RUN_ALL_TESTS();
60}
61
62// Register the function to call once the Instance Object is initialized.
63// see: pappi_simple/ps_main.h
64PPAPI_SIMPLE_REGISTER_MAIN(example_main);
65
66#endif
67