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. 4 5#include <string> 6 7#include "gtest/gtest.h" 8#include "ppapi/cpp/instance.h" 9#include "ppapi/cpp/var.h" 10#include "ppapi_simple/ps_main.h" 11 12#if defined(WIN32) 13#include <Windows.h> 14#undef PostMessage 15#endif 16 17class 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()); 24 } 25 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()); 34 } 35 } 36 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()); 42 } 43}; 44 45int example_main(int argc, char* argv[]) { 46 ::testing::InitGoogleTest(&argc, argv); 47 if (PSGetInstanceId() != 0) { 48 ::testing::UnitTest::GetInstance()->listeners() 49 .Append(new GTestEventListener()); 50 } 51 return RUN_ALL_TESTS(); 52} 53 54// Register the function to call once the Instance Object is initialized. 55// see: pappi_simple/ps_main.h 56PPAPI_SIMPLE_REGISTER_MAIN(example_main); 57