main.cc revision 58537e28ecd584eab876aee8be7156509866d23a
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 virtual void OnTestProgramEnd(const ::testing::UnitTest&) { 55 pp::Instance(PSGetInstanceId()).PostMessage("testend"); 56 } 57}; 58 59int example_main(int argc, char* argv[]) { 60 ::testing::InitGoogleTest(&argc, argv); 61 ::testing::UnitTest::GetInstance()->listeners() 62 .Append(new GTestEventListener()); 63 int result = RUN_ALL_TESTS(); 64 65 // When running as an automated test, we don't want the final message 66 // ("testend") to be dropped, so don't exit. The web page will kill the 67 // plugin if it needs to. 68 while(1); 69 70 // Silence the warning. 71 return result; 72} 73 74// Register the function to call once the Instance Object is initialized. 75// see: pappi_simple/ps_main.h 76PPAPI_SIMPLE_REGISTER_MAIN(example_main); 77 78#endif 79