OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 // Some tests for the framework itself. | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "sandbox/src/sandbox.h" | |
9 #include "sandbox/src/target_services.h" | |
10 #include "sandbox/src/sandbox_factory.h" | |
11 #include "sandbox/tests/common/controller.h" | |
12 | |
13 namespace sandbox { | |
14 | |
15 // Returns the current process state. | |
16 SBOX_TESTS_COMMAND int IntegrationTestsTest_state(int argc, wchar_t **argv) { | |
17 if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) | |
18 return BEFORE_INIT; | |
19 | |
20 if (!SandboxFactory::GetTargetServices()->GetState()->RevertedToSelf()) | |
21 return BEFORE_REVERT; | |
22 | |
23 return AFTER_REVERT; | |
24 } | |
25 | |
26 // Returns the current process state, keeping track of it. | |
27 SBOX_TESTS_COMMAND int IntegrationTestsTest_state2(int argc, wchar_t **argv) { | |
28 static SboxTestsState state = MIN_STATE; | |
29 if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) { | |
30 if (MIN_STATE == state) | |
31 state = BEFORE_INIT; | |
32 return state; | |
33 } | |
34 | |
35 if (!SandboxFactory::GetTargetServices()->GetState()->RevertedToSelf()) { | |
36 if (BEFORE_INIT == state) | |
37 state = BEFORE_REVERT; | |
38 return state; | |
39 } | |
40 | |
41 if (BEFORE_REVERT == state) | |
42 state = AFTER_REVERT; | |
43 return state; | |
44 } | |
45 | |
46 // Returns the number of arguments | |
47 SBOX_TESTS_COMMAND int IntegrationTestsTest_args(int argc, wchar_t **argv) { | |
48 for (int i = 0; i < argc; i++) { | |
49 wchar_t argument[20]; | |
50 size_t argument_bytes = wcslen(argv[i]) * sizeof(wchar_t); | |
51 memcpy(argument, argv[i], __min(sizeof(argument), argument_bytes)); | |
52 } | |
53 | |
54 return argc; | |
55 } | |
56 | |
57 TEST(IntegrationTestsTest, CallsBeforeInit) { | |
58 TestRunner runner; | |
59 runner.SetTimeout(2000); | |
60 runner.SetTestState(BEFORE_INIT); | |
61 ASSERT_EQ(BEFORE_INIT, runner.RunTest(L"IntegrationTestsTest_state")); | |
62 } | |
63 | |
64 TEST(IntegrationTestsTest, CallsBeforeRevert) { | |
65 TestRunner runner; | |
66 runner.SetTimeout(2000); | |
67 runner.SetTestState(BEFORE_REVERT); | |
68 ASSERT_EQ(BEFORE_REVERT, runner.RunTest(L"IntegrationTestsTest_state")); | |
69 } | |
70 | |
71 TEST(IntegrationTestsTest, CallsAfterRevert) { | |
72 TestRunner runner; | |
73 runner.SetTimeout(2000); | |
74 runner.SetTestState(AFTER_REVERT); | |
75 ASSERT_EQ(AFTER_REVERT, runner.RunTest(L"IntegrationTestsTest_state")); | |
76 } | |
77 | |
78 TEST(IntegrationTestsTest, CallsEveryState) { | |
79 TestRunner runner; | |
80 runner.SetTimeout(2000); | |
81 runner.SetTestState(EVERY_STATE); | |
82 ASSERT_EQ(AFTER_REVERT, runner.RunTest(L"IntegrationTestsTest_state2")); | |
83 } | |
84 | |
85 TEST(IntegrationTestsTest, ForwardsArguments) { | |
86 TestRunner runner; | |
87 runner.SetTimeout(2000); | |
88 runner.SetTestState(BEFORE_INIT); | |
89 ASSERT_EQ(1, runner.RunTest(L"IntegrationTestsTest_args first")); | |
90 ASSERT_EQ(4, runner.RunTest(L"IntegrationTestsTest_args first second third " | |
91 L"fourth")); | |
92 } | |
93 | |
94 } // namespace sandbox | |
OLD | NEW |