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