| 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/test/scoped_test_dir.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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())); |
| 31 EXPECT_FALSE(fp); | 31 EXPECT_FALSE(fp); |
| 32 ASSERT_TRUE(h.is_valid()); | 32 ASSERT_TRUE(h.is_valid()); |
| 33 | 33 |
| 34 scoped_refptr<PlatformHandleDispatcher> dispatcher = | 34 auto dispatcher = PlatformHandleDispatcher::Create(h.Pass()); |
| 35 PlatformHandleDispatcher::Create(h.Pass()); | |
| 36 EXPECT_FALSE(h.is_valid()); | 35 EXPECT_FALSE(h.is_valid()); |
| 37 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, dispatcher->GetType()); | 36 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, dispatcher->GetType()); |
| 38 | 37 |
| 39 h = dispatcher->PassPlatformHandle().Pass(); | 38 h = dispatcher->PassPlatformHandle().Pass(); |
| 40 EXPECT_TRUE(h.is_valid()); | 39 EXPECT_TRUE(h.is_valid()); |
| 41 | 40 |
| 42 fp = mojo::test::FILEFromPlatformHandle(h.Pass(), "rb").Pass(); | 41 fp = mojo::test::FILEFromPlatformHandle(h.Pass(), "rb").Pass(); |
| 43 EXPECT_FALSE(h.is_valid()); | 42 EXPECT_FALSE(h.is_valid()); |
| 44 EXPECT_TRUE(fp); | 43 EXPECT_TRUE(fp); |
| 45 | 44 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 57 } | 56 } |
| 58 | 57 |
| 59 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { | 58 TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { |
| 60 mojo::test::ScopedTestDir test_dir; | 59 mojo::test::ScopedTestDir test_dir; |
| 61 | 60 |
| 62 static const char kFooBar[] = "foo bar"; | 61 static const char kFooBar[] = "foo bar"; |
| 63 | 62 |
| 64 util::ScopedFILE fp(test_dir.CreateFile()); | 63 util::ScopedFILE fp(test_dir.CreateFile()); |
| 65 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); | 64 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); |
| 66 | 65 |
| 67 scoped_refptr<PlatformHandleDispatcher> dispatcher = | 66 auto dispatcher = PlatformHandleDispatcher::Create( |
| 68 PlatformHandleDispatcher::Create( | 67 mojo::test::PlatformHandleFromFILE(fp.Pass())); |
| 69 mojo::test::PlatformHandleFromFILE(fp.Pass())); | |
| 70 | 68 |
| 71 DispatcherTransport transport( | 69 DispatcherTransport transport( |
| 72 test::DispatcherTryStartTransport(dispatcher.get())); | 70 test::DispatcherTryStartTransport(dispatcher.get())); |
| 73 EXPECT_TRUE(transport.is_valid()); | 71 EXPECT_TRUE(transport.is_valid()); |
| 74 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); | 72 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType()); |
| 75 EXPECT_FALSE(transport.IsBusy()); | 73 EXPECT_FALSE(transport.IsBusy()); |
| 76 | 74 |
| 77 scoped_refptr<Dispatcher> generic_dispatcher = | 75 auto generic_dispatcher = transport.CreateEquivalentDispatcherAndClose(); |
| 78 transport.CreateEquivalentDispatcherAndClose(); | |
| 79 ASSERT_TRUE(generic_dispatcher); | 76 ASSERT_TRUE(generic_dispatcher); |
| 80 | 77 |
| 81 transport.End(); | 78 transport.End(); |
| 82 EXPECT_TRUE(dispatcher->HasOneRef()); | 79 dispatcher->AssertHasOneRef(); |
| 83 dispatcher = nullptr; | 80 dispatcher = nullptr; |
| 84 | 81 |
| 85 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType()); | 82 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType()); |
| 86 dispatcher = static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get()); | 83 dispatcher = RefPtr<PlatformHandleDispatcher>( |
| 84 static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get())); |
| 87 | 85 |
| 88 fp = mojo::test::FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), | 86 fp = mojo::test::FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), |
| 89 "rb").Pass(); | 87 "rb").Pass(); |
| 90 EXPECT_TRUE(fp); | 88 EXPECT_TRUE(fp); |
| 91 | 89 |
| 92 rewind(fp.get()); | 90 rewind(fp.get()); |
| 93 char read_buffer[1000] = {}; | 91 char read_buffer[1000] = {}; |
| 94 EXPECT_EQ(sizeof(kFooBar), | 92 EXPECT_EQ(sizeof(kFooBar), |
| 95 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); | 93 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); |
| 96 EXPECT_STREQ(kFooBar, read_buffer); | 94 EXPECT_STREQ(kFooBar, read_buffer); |
| 97 | 95 |
| 98 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 96 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 99 } | 97 } |
| 100 | 98 |
| 101 } // namespace | 99 } // namespace |
| 102 } // namespace system | 100 } // namespace system |
| 103 } // namespace mojo | 101 } // namespace mojo |
| OLD | NEW |