OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "test/win/win_child_process.h" |
| 16 |
| 17 #include <windows.h> |
| 18 |
| 19 #include "base/basictypes.h" |
| 20 #include "gtest/gtest.h" |
| 21 |
| 22 namespace crashpad { |
| 23 namespace test { |
| 24 namespace { |
| 25 |
| 26 int ReadInt(HANDLE handle) { |
| 27 int value = 0; |
| 28 DWORD bytes_read = 0; |
| 29 EXPECT_TRUE(::ReadFile(handle, &value, sizeof(value), &bytes_read, nullptr)); |
| 30 EXPECT_EQ(sizeof(value), bytes_read); |
| 31 return value; |
| 32 } |
| 33 |
| 34 void WriteInt(HANDLE handle, int value) { |
| 35 DWORD bytes_written = 0; |
| 36 EXPECT_TRUE( |
| 37 ::WriteFile(handle, &value, sizeof(value), &bytes_written, nullptr)); |
| 38 EXPECT_EQ(sizeof(value), bytes_written); |
| 39 } |
| 40 |
| 41 class TestWinChildProcess final : public WinChildProcess { |
| 42 public: |
| 43 TestWinChildProcess() : WinChildProcess() {} |
| 44 |
| 45 ~TestWinChildProcess() {} |
| 46 |
| 47 private: |
| 48 // WinChildProcess will have already exercised the pipes. |
| 49 void Run() override { |
| 50 int value = ReadInt(ReadPipeHandle()); |
| 51 WriteInt(WritePipeHandle(), value); |
| 52 } |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(TestWinChildProcess); |
| 55 }; |
| 56 |
| 57 TEST(WinChildProcessTest, WinChildProcess) { |
| 58 WinChildProcess::EntryPoint<TestWinChildProcess>(); |
| 59 |
| 60 WinChildProcess::Launch(); |
| 61 } |
| 62 |
| 63 TEST(WinChildProcessTest, MultipleChildren) { |
| 64 WinChildProcess::EntryPoint<TestWinChildProcess>(); |
| 65 |
| 66 scoped_ptr<WinChildProcess::Handles> handles_1 = WinChildProcess::Launch(); |
| 67 scoped_ptr<WinChildProcess::Handles> handles_2 = WinChildProcess::Launch(); |
| 68 scoped_ptr<WinChildProcess::Handles> handles_3 = WinChildProcess::Launch(); |
| 69 |
| 70 WriteInt(handles_1->write.get(), 1); |
| 71 WriteInt(handles_2->write.get(), 2); |
| 72 WriteInt(handles_3->write.get(), 3); |
| 73 ASSERT_EQ(3, ReadInt(handles_3->read.get())); |
| 74 ASSERT_EQ(2, ReadInt(handles_2->read.get())); |
| 75 ASSERT_EQ(1, ReadInt(handles_1->read.get())); |
| 76 } |
| 77 |
| 78 } // namespace |
| 79 } // namespace test |
| 80 } // namespace crashpad |
OLD | NEW |