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

Side by Side Diff: mojo/edk/system/platform_handle_dispatcher_unittest.cc

Issue 1160203002: Make Dispatcher::Type an enum class. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 21 matching lines...) Expand all
32 fwrite(kHelloWorld, 1, sizeof(kHelloWorld), fp.get())); 32 fwrite(kHelloWorld, 1, sizeof(kHelloWorld), fp.get()));
33 33
34 embedder::ScopedPlatformHandle h( 34 embedder::ScopedPlatformHandle h(
35 mojo::test::PlatformHandleFromFILE(fp.Pass())); 35 mojo::test::PlatformHandleFromFILE(fp.Pass()));
36 EXPECT_FALSE(fp); 36 EXPECT_FALSE(fp);
37 ASSERT_TRUE(h.is_valid()); 37 ASSERT_TRUE(h.is_valid());
38 38
39 scoped_refptr<PlatformHandleDispatcher> dispatcher( 39 scoped_refptr<PlatformHandleDispatcher> dispatcher(
40 new PlatformHandleDispatcher(h.Pass())); 40 new PlatformHandleDispatcher(h.Pass()));
41 EXPECT_FALSE(h.is_valid()); 41 EXPECT_FALSE(h.is_valid());
42 EXPECT_EQ(Dispatcher::kTypePlatformHandle, dispatcher->GetType()); 42 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, dispatcher->GetType());
43 43
44 h = dispatcher->PassPlatformHandle().Pass(); 44 h = dispatcher->PassPlatformHandle().Pass();
45 EXPECT_TRUE(h.is_valid()); 45 EXPECT_TRUE(h.is_valid());
46 46
47 fp = mojo::test::FILEFromPlatformHandle(h.Pass(), "rb").Pass(); 47 fp = mojo::test::FILEFromPlatformHandle(h.Pass(), "rb").Pass();
48 EXPECT_FALSE(h.is_valid()); 48 EXPECT_FALSE(h.is_valid());
49 EXPECT_TRUE(fp); 49 EXPECT_TRUE(fp);
50 50
51 rewind(fp.get()); 51 rewind(fp.get());
52 char read_buffer[1000] = {}; 52 char read_buffer[1000] = {};
(...skipping 19 matching lines...) Expand all
72 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); 72 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused));
73 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); 73 EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get()));
74 74
75 scoped_refptr<PlatformHandleDispatcher> dispatcher( 75 scoped_refptr<PlatformHandleDispatcher> dispatcher(
76 new PlatformHandleDispatcher( 76 new PlatformHandleDispatcher(
77 mojo::test::PlatformHandleFromFILE(fp.Pass()))); 77 mojo::test::PlatformHandleFromFILE(fp.Pass())));
78 78
79 DispatcherTransport transport( 79 DispatcherTransport transport(
80 test::DispatcherTryStartTransport(dispatcher.get())); 80 test::DispatcherTryStartTransport(dispatcher.get()));
81 EXPECT_TRUE(transport.is_valid()); 81 EXPECT_TRUE(transport.is_valid());
82 EXPECT_EQ(Dispatcher::kTypePlatformHandle, transport.GetType()); 82 EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, transport.GetType());
83 EXPECT_FALSE(transport.IsBusy()); 83 EXPECT_FALSE(transport.IsBusy());
84 84
85 scoped_refptr<Dispatcher> generic_dispatcher = 85 scoped_refptr<Dispatcher> generic_dispatcher =
86 transport.CreateEquivalentDispatcherAndClose(); 86 transport.CreateEquivalentDispatcherAndClose();
87 ASSERT_TRUE(generic_dispatcher); 87 ASSERT_TRUE(generic_dispatcher);
88 88
89 transport.End(); 89 transport.End();
90 EXPECT_TRUE(dispatcher->HasOneRef()); 90 EXPECT_TRUE(dispatcher->HasOneRef());
91 dispatcher = nullptr; 91 dispatcher = nullptr;
92 92
93 ASSERT_EQ(Dispatcher::kTypePlatformHandle, generic_dispatcher->GetType()); 93 ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType());
94 dispatcher = static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get()); 94 dispatcher = static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get());
95 95
96 fp = mojo::test::FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), 96 fp = mojo::test::FILEFromPlatformHandle(dispatcher->PassPlatformHandle(),
97 "rb").Pass(); 97 "rb").Pass();
98 EXPECT_TRUE(fp); 98 EXPECT_TRUE(fp);
99 99
100 rewind(fp.get()); 100 rewind(fp.get());
101 char read_buffer[1000] = {}; 101 char read_buffer[1000] = {};
102 EXPECT_EQ(sizeof(kFooBar), 102 EXPECT_EQ(sizeof(kFooBar),
103 fread(read_buffer, 1, sizeof(read_buffer), fp.get())); 103 fread(read_buffer, 1, sizeof(read_buffer), fp.get()));
104 EXPECT_STREQ(kFooBar, read_buffer); 104 EXPECT_STREQ(kFooBar, read_buffer);
105 105
106 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 106 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
107 } 107 }
108 108
109 } // namespace 109 } // namespace
110 } // namespace system 110 } // namespace system
111 } // namespace mojo 111 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698