OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gtest/gtest.h" | 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" | 6 #include "ppapi/cpp/instance.h" |
25 #include "ppapi/cpp/var.h" | 7 #include "ppapi/cpp/var.h" |
26 #include "ppapi_simple/ps_main.h" | 8 #include "ppapi_simple/ps_main.h" |
27 | 9 |
28 #if defined(WIN32) | 10 #if defined(WIN32) |
29 #include <Windows.h> | 11 #include <Windows.h> |
30 #undef PostMessage | 12 #undef PostMessage |
31 #endif | 13 #endif |
32 | 14 |
| 15 TEST(TestCase, SimpleTest) { |
| 16 EXPECT_EQ(4, 2*2); |
| 17 } |
| 18 |
| 19 TEST(TestCase, AnotherTest) { |
| 20 EXPECT_EQ(1, sizeof(char)); |
| 21 } |
| 22 |
33 class GTestEventListener : public ::testing::EmptyTestEventListener { | 23 class GTestEventListener : public ::testing::EmptyTestEventListener { |
34 public: | 24 public: |
35 // TestEventListener overrides. | 25 // TestEventListener overrides. |
36 virtual void OnTestStart(const ::testing::TestInfo& test_info) { | 26 virtual void OnTestStart(const ::testing::TestInfo& test_info) { |
37 std::stringstream msg; | 27 std::stringstream msg; |
38 msg << "start:" << test_info.test_case_name() << "." << test_info.name(); | 28 msg << "start:" << test_info.test_case_name() << "." << test_info.name(); |
39 pp::Instance(PSGetInstanceId()).PostMessage(msg.str()); | 29 pp::Instance(PSGetInstanceId()).PostMessage(msg.str()); |
40 } | 30 } |
41 | 31 |
42 virtual void OnTestPartResult( | 32 virtual void OnTestPartResult( |
43 const ::testing::TestPartResult& test_part_result) { | 33 const ::testing::TestPartResult& test_part_result) { |
44 if (test_part_result.failed()) { | 34 if (test_part_result.failed()) { |
45 std::stringstream msg; | 35 std::stringstream msg; |
46 msg << "fail:" << test_part_result.file_name() << "," | 36 msg << "fail:" << test_part_result.file_name() << "," |
47 << test_part_result.line_number() << "," | 37 << test_part_result.line_number() << "," |
48 << test_part_result.summary(); | 38 << test_part_result.summary(); |
49 pp::Instance(PSGetInstanceId()).PostMessage(msg.str()); | 39 pp::Instance(PSGetInstanceId()).PostMessage(msg.str()); |
50 } | 40 } |
51 } | 41 } |
52 | 42 |
53 virtual void OnTestEnd(const ::testing::TestInfo& test_info) { | 43 virtual void OnTestEnd(const ::testing::TestInfo& test_info) { |
54 std::stringstream msg; | 44 std::stringstream msg; |
55 msg << "end:" << test_info.test_case_name() << "." << test_info.name() | 45 msg << "end:" << test_info.test_case_name() << "." << test_info.name() |
56 << "," << (test_info.result()->Failed() ? "failed" : "ok"); | 46 << "," << (test_info.result()->Failed() ? "failed" : "ok"); |
57 pp::Instance(PSGetInstanceId()).PostMessage(msg.str()); | 47 pp::Instance(PSGetInstanceId()).PostMessage(msg.str()); |
58 } | 48 } |
59 }; | 49 }; |
60 | 50 |
61 int example_main(int argc, char* argv[]) { | 51 int example_main(int argc, char* argv[]) { |
| 52 setenv("TERM", "xterm-256color", 0); |
62 ::testing::InitGoogleTest(&argc, argv); | 53 ::testing::InitGoogleTest(&argc, argv); |
63 ::testing::UnitTest::GetInstance()->listeners() | 54 if (PSGetInstanceId() != 0) { |
64 .Append(new GTestEventListener()); | 55 ::testing::UnitTest::GetInstance()->listeners() |
| 56 .Append(new GTestEventListener()); |
| 57 } |
65 return RUN_ALL_TESTS(); | 58 return RUN_ALL_TESTS(); |
66 } | 59 } |
67 | 60 |
68 // Register the function to call once the Instance Object is initialized. | 61 // Register the function to call once the Instance Object is initialized. |
69 // see: pappi_simple/ps_main.h | 62 // see: pappi_simple/ps_main.h |
70 PPAPI_SIMPLE_REGISTER_MAIN(example_main); | 63 PPAPI_SIMPLE_REGISTER_MAIN(example_main); |
71 | |
72 #endif | |
OLD | NEW |