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 "gtest/gtest.h"
6#include "ppapi/cpp/instance.h"
7#include "ppapi/cpp/var.h"
8#include "ppapi_simple/ps_main.h"
9
10#if defined(WIN32)
11#include <Windows.h>
12#undef PostMessage
13#endif
14
15TEST(TestCase, SimpleTest) {
16  EXPECT_EQ(4, 2*2);
17}
18
19TEST(TestCase, AnotherTest) {
20  EXPECT_EQ(1, sizeof(char));
21}
22
23class GTestEventListener : public ::testing::EmptyTestEventListener {
24 public:
25  // TestEventListener overrides.
26  virtual void OnTestStart(const ::testing::TestInfo& test_info) {
27    std::stringstream msg;
28    msg << "start:" << test_info.test_case_name() << "." << test_info.name();
29    pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
30  }
31
32  virtual void OnTestPartResult(
33      const ::testing::TestPartResult& test_part_result) {
34    if (test_part_result.failed()) {
35      std::stringstream msg;
36      msg << "fail:" << test_part_result.file_name() << ","
37          << test_part_result.line_number() << ","
38          << test_part_result.summary();
39      pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
40    }
41  }
42
43  virtual void OnTestEnd(const ::testing::TestInfo& test_info) {
44    std::stringstream msg;
45    msg << "end:" << test_info.test_case_name() << "." << test_info.name()
46        << "," << (test_info.result()->Failed() ? "failed" : "ok");
47    pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
48  }
49};
50
51int example_main(int argc, char* argv[]) {
52  setenv("TERM", "xterm-256color", 0);
53  ::testing::InitGoogleTest(&argc, argv);
54  if (PSGetInstanceId() != 0) {
55    ::testing::UnitTest::GetInstance()->listeners()
56        .Append(new GTestEventListener());
57  }
58  return RUN_ALL_TESTS();
59}
60
61// Register the function to call once the Instance Object is initialized.
62// see: pappi_simple/ps_main.h
63PPAPI_SIMPLE_REGISTER_MAIN(example_main);
64