| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/edk/system/platform_handle_dispatcher.h" | 5 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "mojo/edk/test/scoped_test_dir.h" | 10 #include "mojo/edk/system/test/scoped_test_dir.h" |
| 11 #include "mojo/edk/test/test_utils.h" | 11 #include "mojo/edk/test/test_utils.h" |
| 12 #include "mojo/edk/util/scoped_file.h" | 12 #include "mojo/edk/util/scoped_file.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace system { | 16 namespace system { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 TEST(PlatformHandleDispatcherTest, Basic) { | 19 TEST(PlatformHandleDispatcherTest, Basic) { |
| 20 mojo::test::ScopedTestDir test_dir; | 20 test::ScopedTestDir test_dir; |
| 21 | 21 |
| 22 static const char kHelloWorld[] = "hello world"; | 22 static const char kHelloWorld[] = "hello world"; |
| 23 | 23 |
| 24 util::ScopedFILE fp(test_dir.CreateFile()); | 24 util::ScopedFILE fp(test_dir.CreateFile()); |
| 25 ASSERT_TRUE(fp); | 25 ASSERT_TRUE(fp); |
| 26 EXPECT_EQ(sizeof(kHelloWorld), | 26 EXPECT_EQ(sizeof(kHelloWorld), |
| 27 fwrite(kHelloWorld, 1, sizeof(kHelloWorld), fp.get())); | 27 fwrite(kHelloWorld, 1, sizeof(kHelloWorld), fp.get())); |
| 28 | 28 |
| 29 embedder::ScopedPlatformHandle h( | 29 embedder::ScopedPlatformHandle h( |
| 30 mojo::test::PlatformHandleFromFILE(fp.Pass())); | 30 mojo::test::PlatformHandleFromFILE(fp.Pass())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 49 EXPECT_STREQ(kHelloWorld, read_buffer); | 49 EXPECT_STREQ(kHelloWorld, read_buffer); |
| 50 | 50 |
| 51 // Try getting the handle again. (It should fail cleanly.) | 51 // Try getting the handle again. (It should fail cleanly.) |
| 52 h = dispatcher->PassPlatformHandle().Pass(); | 52 h = dispatcher->PassPlatformHandle().Pass(); |
| 53 EXPECT_FALSE(h.is_valid()); | 53 EXPECT_FALSE(h.is_valid()); |
| 54 | 54 |
| 55 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 55 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { | 58 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { |
| 59 mojo::test::ScopedTestDir test_dir; | 59 test::ScopedTestDir test_dir; |
| 60 | 60 |
| 61 static const char kFooBar[] = "foo bar"; | 61 static const char kFooBar[] = "foo bar"; |
| 62 | 62 |
| 63 util::ScopedFILE fp(test_dir.CreateFile()); | 63 util::ScopedFILE fp(test_dir.CreateFile()); |
| 64 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); | 64 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); |
| 65 | 65 |
| 66 auto dispatcher = PlatformHandleDispatcher::Create( | 66 auto dispatcher = PlatformHandleDispatcher::Create( |
| 67 mojo::test::PlatformHandleFromFILE(fp.Pass())); | 67 mojo::test::PlatformHandleFromFILE(fp.Pass())); |
| 68 | 68 |
| 69 DispatcherTransport transport( | 69 DispatcherTransport transport( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 92 EXPECT_EQ(sizeof(kFooBar), | 92 EXPECT_EQ(sizeof(kFooBar), |
| 93 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); | 93 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); |
| 94 EXPECT_STREQ(kFooBar, read_buffer); | 94 EXPECT_STREQ(kFooBar, read_buffer); |
| 95 | 95 |
| 96 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 96 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 } // namespace system | 100 } // namespace system |
| 101 } // namespace mojo | 101 } // namespace mojo |
| OLD | NEW |