Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "test/win/win_multiprocess.h" | 15 #include "test/win/win_multiprocess.h" |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "gtest/gtest.h" | 18 #include "gtest/gtest.h" |
| 19 | 19 |
| 20 namespace crashpad { | 20 namespace crashpad { |
| 21 namespace test { | 21 namespace test { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 template <int exit_code> | |
|
scottmg
2015/06/25 04:13:25
exit_code -> ExitCode
erikwright (departed)
2015/06/25 14:36:02
Done.
| |
| 24 class TestWinMultiprocess final : public WinMultiprocess { | 25 class TestWinMultiprocess final : public WinMultiprocess { |
| 25 public: | 26 public: |
| 26 explicit TestWinMultiprocess(unsigned int exit_code) | 27 TestWinMultiprocess() {} |
| 27 : WinMultiprocess(), exit_code_(exit_code) {} | |
| 28 | |
| 29 ~TestWinMultiprocess() {} | 28 ~TestWinMultiprocess() {} |
| 30 | 29 |
| 31 private: | 30 private: |
| 32 // WinMultiprocess will have already exercised the pipes. | 31 // WinMultiprocess will have already exercised the pipes. |
| 33 void WinMultiprocessParent() override {} | 32 void WinMultiprocessParent() override { SetExpectedChildExitCode(exit_code); } |
| 34 | 33 |
| 35 void WinMultiprocessChild() override { | 34 void WinMultiprocessChild() override { |
| 36 exit(exit_code_); | 35 exit(exit_code); |
| 37 } | 36 } |
| 38 | 37 |
| 39 unsigned int exit_code_; | |
| 40 | |
| 41 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocess); | 38 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocess); |
| 42 }; | 39 }; |
| 43 | 40 |
| 44 enum class FailureType { | 41 enum class FailureType { |
| 45 kExpect, | 42 kExpect, |
| 46 kAssert, | 43 kAssert, |
| 47 }; | 44 }; |
| 48 | 45 |
| 46 template <FailureType failure_type> | |
|
scottmg
2015/06/25 04:13:25
similar
erikwright (departed)
2015/06/25 14:36:02
In the end I thought a non-template approach might
| |
| 49 class TestWinMultiprocessChildFails final : public WinMultiprocess { | 47 class TestWinMultiprocessChildFails final : public WinMultiprocess { |
| 50 public: | 48 public: |
| 51 explicit TestWinMultiprocessChildFails(FailureType failure_type) | 49 TestWinMultiprocessChildFails() {} |
| 52 : WinMultiprocess(), failure_type_(failure_type) {} | |
| 53 ~TestWinMultiprocessChildFails() {} | 50 ~TestWinMultiprocessChildFails() {} |
| 54 | 51 |
| 55 private: | 52 private: |
| 56 void WinMultiprocessParent() override {} | 53 void WinMultiprocessParent() override { SetExpectedChildExitCode(255); } |
| 57 void WinMultiprocessChild() override { | 54 void WinMultiprocessChild() override { |
| 58 switch (failure_type_) { | 55 switch (failure_type) { |
| 59 case FailureType::kExpect: | 56 case FailureType::kExpect: |
| 60 EXPECT_FALSE(true); | 57 EXPECT_FALSE(true); |
| 61 break; | 58 break; |
| 62 case FailureType::kAssert: | 59 case FailureType::kAssert: |
| 63 ASSERT_FALSE(true); | 60 ASSERT_FALSE(true); |
| 64 break; | 61 break; |
| 65 } | 62 } |
| 66 } | 63 } |
| 67 | 64 |
| 68 FailureType failure_type_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocessChildFails); | 65 DISALLOW_COPY_AND_ASSIGN(TestWinMultiprocessChildFails); |
| 71 }; | 66 }; |
| 72 | 67 |
| 73 | 68 |
| 74 TEST(WinMultiprocess, WinMultiprocess) { | 69 TEST(WinMultiprocess, WinMultiprocess) { |
| 75 TestWinMultiprocess win_multiprocess(0); | 70 WinMultiprocess::Run<TestWinMultiprocess<0>>(); |
| 76 win_multiprocess.Run(); | |
| 77 } | 71 } |
| 78 | 72 |
| 79 TEST(WinMultiprocess, WinMultiprocessNonSuccessExitCode) { | 73 TEST(WinMultiprocess, WinMultiprocessNonSuccessExitCode) { |
| 80 TestWinMultiprocess win_multiprocess(100); | 74 WinMultiprocess::Run<TestWinMultiprocess<100>>(); |
| 81 win_multiprocess.SetExpectedChildExitCode(100); | |
| 82 win_multiprocess.Run(); | |
| 83 } | 75 } |
| 84 | 76 |
| 85 TEST(WinMultiprocessChildFails, ChildExpectFailure) { | 77 TEST(WinMultiprocessChildFails, ChildExpectFailure) { |
| 86 TestWinMultiprocessChildFails multiprocess_failing_child( | 78 WinMultiprocess::Run<TestWinMultiprocessChildFails<FailureType::kExpect>>(); |
| 87 FailureType::kExpect); | |
| 88 multiprocess_failing_child.SetExpectedChildExitCode(255); | |
| 89 multiprocess_failing_child.Run(); | |
| 90 } | 79 } |
| 91 | 80 |
| 92 TEST(WinMultiprocessChildFails, ChildAssertFailure) { | 81 TEST(WinMultiprocessChildFails, ChildAssertFailure) { |
| 93 TestWinMultiprocessChildFails multiprocess_failing_child( | 82 WinMultiprocess::Run<TestWinMultiprocessChildFails<FailureType::kAssert>>(); |
| 94 FailureType::kAssert); | |
| 95 multiprocess_failing_child.SetExpectedChildExitCode(255); | |
| 96 multiprocess_failing_child.Run(); | |
| 97 } | 83 } |
| 98 | 84 |
| 99 } // namespace | 85 } // namespace |
| 100 } // namespace test | 86 } // namespace test |
| 101 } // namespace crashpad | 87 } // namespace crashpad |
| OLD | NEW |