Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / tests / sdk_util_test / main.cc
bloba715b1bface1281f1c838a1fecc9003254f3327d
1 // Copyright 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.
5 #include <string>
7 #include "gtest/gtest.h"
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/var.h"
10 #include "ppapi_simple/ps_main.h"
12 #if defined(WIN32)
13 #include <Windows.h>
14 #undef PostMessage
15 #endif
17 class GTestEventListener : public ::testing::EmptyTestEventListener {
18 public:
19 // TestEventListener overrides.
20 virtual void OnTestStart(const ::testing::TestInfo& test_info) {
21 std::stringstream msg;
22 msg << "start:" << test_info.test_case_name() << "." << test_info.name();
23 pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
26 virtual void OnTestPartResult(
27 const ::testing::TestPartResult& test_part_result) {
28 if (test_part_result.failed()) {
29 std::stringstream msg;
30 msg << "fail:" << test_part_result.file_name() << ","
31 << test_part_result.line_number() << ","
32 << test_part_result.summary();
33 pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
37 virtual void OnTestEnd(const ::testing::TestInfo& test_info) {
38 std::stringstream msg;
39 msg << "end:" << test_info.test_case_name() << "." << test_info.name()
40 << "," << (test_info.result()->Failed() ? "failed" : "ok");
41 pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
45 int example_main(int argc, char* argv[]) {
46 ::testing::InitGoogleTest(&argc, argv);
47 if (PSGetInstanceId() != 0) {
48 ::testing::UnitTest::GetInstance()->listeners()
49 .Append(new GTestEventListener());
51 return RUN_ALL_TESTS();
54 // Register the function to call once the Instance Object is initialized.
55 // see: pappi_simple/ps_main.h
56 PPAPI_SIMPLE_REGISTER_MAIN(example_main);