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