Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: test/win/win_child_process_test.cc

Issue 1164453003: Refactor multiprocess test code to allow multiple child processes to be launched. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@multiprocess_test
Patch Set: Review comment. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/win/win_child_process.cc ('k') | test/win/win_multiprocess.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/win/win_child_process_test.cc
diff --git a/test/win/win_child_process_test.cc b/test/win/win_child_process_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bdf627a8a08d7a6a16a17862ecaa8fe1c5e3bce5
--- /dev/null
+++ b/test/win/win_child_process_test.cc
@@ -0,0 +1,81 @@
+// Copyright 2015 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "test/win/win_child_process.h"
+
+#include <windows.h>
+
+#include "base/basictypes.h"
+#include "gtest/gtest.h"
+
+namespace crashpad {
+namespace test {
+namespace {
+
+int ReadInt(HANDLE handle) {
+ int value = 0;
+ DWORD bytes_read = 0;
+ EXPECT_TRUE(::ReadFile(handle, &value, sizeof(value), &bytes_read, nullptr));
+ EXPECT_EQ(sizeof(value), bytes_read);
+ return value;
+}
+
+void WriteInt(HANDLE handle, int value) {
+ DWORD bytes_written = 0;
+ EXPECT_TRUE(
+ ::WriteFile(handle, &value, sizeof(value), &bytes_written, nullptr));
+ EXPECT_EQ(sizeof(value), bytes_written);
+}
+
+class TestWinChildProcess final : public WinChildProcess {
+ public:
+ TestWinChildProcess() : WinChildProcess() {}
+
+ ~TestWinChildProcess() {}
+
+ private:
+ // WinChildProcess will have already exercised the pipes.
+ int Run() override {
+ int value = ReadInt(ReadPipeHandle());
+ WriteInt(WritePipeHandle(), value);
+ return EXIT_SUCCESS;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(TestWinChildProcess);
+};
+
+TEST(WinChildProcessTest, WinChildProcess) {
+ WinChildProcess::EntryPoint<TestWinChildProcess>();
+
+ WinChildProcess::Launch();
+}
+
+TEST(WinChildProcessTest, MultipleChildren) {
+ WinChildProcess::EntryPoint<TestWinChildProcess>();
+
+ scoped_ptr<WinChildProcess::Handles> handles_1 = WinChildProcess::Launch();
+ scoped_ptr<WinChildProcess::Handles> handles_2 = WinChildProcess::Launch();
+ scoped_ptr<WinChildProcess::Handles> handles_3 = WinChildProcess::Launch();
+
+ WriteInt(handles_1->write.get(), 1);
+ WriteInt(handles_2->write.get(), 2);
+ WriteInt(handles_3->write.get(), 3);
+ ASSERT_EQ(3, ReadInt(handles_3->read.get()));
+ ASSERT_EQ(2, ReadInt(handles_2->read.get()));
+ ASSERT_EQ(1, ReadInt(handles_1->read.get()));
+}
+
+} // namespace
+} // namespace test
+} // namespace crashpad
« no previous file with comments | « test/win/win_child_process.cc ('k') | test/win/win_multiprocess.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698