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 <algorithm> | 5 #include <algorithm> |
6 #include <ostream> | 6 #include <ostream> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
10 #include "mojo/public/cpp/environment/environment.h" | |
11 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" | 9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
13 | 11 |
14 namespace mojo { | 12 namespace mojo { |
15 | 13 |
16 template <> | 14 template <> |
17 class TypeConverter<sample::Bar, int32_t> { | 15 class TypeConverter<sample::BarPtr, int32_t> { |
18 public: | 16 public: |
19 static int32_t ConvertTo(const sample::Bar& bar) { | 17 static int32_t ConvertTo(const sample::BarPtr& bar) { |
20 return static_cast<int32_t>(bar.alpha()) << 16 | | 18 return static_cast<int32_t>(bar->alpha) << 16 | |
21 static_cast<int32_t>(bar.beta()) << 8 | | 19 static_cast<int32_t>(bar->beta) << 8 | |
22 static_cast<int32_t>(bar.gamma()); | 20 static_cast<int32_t>(bar->gamma); |
23 } | 21 } |
24 | |
25 MOJO_ALLOW_IMPLICIT_TYPE_CONVERSION(); | |
26 }; | 22 }; |
27 | 23 |
28 } // namespace mojo | 24 } // namespace mojo |
29 | 25 |
30 namespace sample { | 26 namespace sample { |
31 namespace { | 27 namespace { |
32 | 28 |
33 // Set this variable to true to print the message in hex. | 29 // Set this variable to true to print the message in hex. |
34 bool g_dump_message_as_hex = false; | 30 bool g_dump_message_as_hex = false; |
35 | 31 |
36 // Set this variable to true to print the message in human readable form. | 32 // Set this variable to true to print the message in human readable form. |
37 bool g_dump_message_as_text = false; | 33 bool g_dump_message_as_text = false; |
38 | 34 |
39 // Make a sample |Foo|. | 35 // Make a sample |Foo|. |
40 Foo MakeFoo() { | 36 FooPtr MakeFoo() { |
41 mojo::String name("foopy"); | 37 mojo::String name("foopy"); |
42 | 38 |
43 Bar::Builder bar; | 39 BarPtr bar(Bar::New()); |
44 bar.set_alpha(20); | 40 bar->alpha = 20; |
45 bar.set_beta(40); | 41 bar->beta = 40; |
46 bar.set_gamma(60); | 42 bar->gamma = 60; |
47 bar.set_type(Bar::TYPE_VERTICAL); | 43 bar->type = Bar::TYPE_VERTICAL; |
48 | 44 |
49 mojo::Array<Bar>::Builder extra_bars(3); | 45 mojo::Array<BarPtr> extra_bars(3); |
50 for (size_t i = 0; i < extra_bars.size(); ++i) { | 46 for (size_t i = 0; i < extra_bars.size(); ++i) { |
51 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; | 47 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; |
52 Bar::Builder bar; | 48 BarPtr bar(Bar::New()); |
53 uint8_t base = static_cast<uint8_t>(i * 100); | 49 uint8_t base = static_cast<uint8_t>(i * 100); |
54 bar.set_alpha(base); | 50 bar->alpha = base; |
55 bar.set_beta(base + 20); | 51 bar->beta = base + 20; |
56 bar.set_gamma(base + 40); | 52 bar->gamma = base + 40; |
57 bar.set_type(type); | 53 bar->type = type; |
58 extra_bars[i] = bar.Finish(); | 54 extra_bars[i] = bar.Pass(); |
59 } | 55 } |
60 | 56 |
61 mojo::Array<uint8_t>::Builder data(10); | 57 mojo::Array<uint8_t> data(10); |
62 for (size_t i = 0; i < data.size(); ++i) | 58 for (size_t i = 0; i < data.size(); ++i) |
63 data[i] = static_cast<uint8_t>(data.size() - i); | 59 data[i] = static_cast<uint8_t>(data.size() - i); |
64 | 60 |
65 mojo::Array<mojo::DataPipeConsumerHandle>::Builder input_streams(2); | 61 mojo::Array<mojo::ScopedDataPipeConsumerHandle> input_streams(2); |
66 mojo::Array<mojo::DataPipeProducerHandle>::Builder output_streams(2); | 62 mojo::Array<mojo::ScopedDataPipeProducerHandle> output_streams(2); |
67 for (size_t i = 0; i < input_streams.size(); ++i) { | 63 for (size_t i = 0; i < input_streams.size(); ++i) { |
68 MojoCreateDataPipeOptions options; | 64 MojoCreateDataPipeOptions options; |
69 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 65 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
70 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 66 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
71 options.element_num_bytes = 1; | 67 options.element_num_bytes = 1; |
72 options.capacity_num_bytes = 1024; | 68 options.capacity_num_bytes = 1024; |
73 mojo::ScopedDataPipeProducerHandle producer; | 69 mojo::ScopedDataPipeProducerHandle producer; |
74 mojo::ScopedDataPipeConsumerHandle consumer; | 70 mojo::ScopedDataPipeConsumerHandle consumer; |
75 mojo::CreateDataPipe(&options, &producer, &consumer); | 71 mojo::CreateDataPipe(&options, &producer, &consumer); |
76 input_streams[i] = consumer.Pass(); | 72 input_streams[i] = consumer.Pass(); |
77 output_streams[i] = producer.Pass(); | 73 output_streams[i] = producer.Pass(); |
78 } | 74 } |
79 | 75 |
80 mojo::Array<mojo::Array<bool> >::Builder array_of_array_of_bools(2); | 76 mojo::Array<mojo::Array<bool> > array_of_array_of_bools(2); |
81 for (size_t i = 0; i < 2; ++i) { | 77 for (size_t i = 0; i < 2; ++i) { |
82 mojo::Array<bool>::Builder array_of_bools(2); | 78 mojo::Array<bool> array_of_bools(2); |
83 for (size_t j = 0; j < 2; ++j) { | 79 for (size_t j = 0; j < 2; ++j) |
84 array_of_bools[j] = j; | 80 array_of_bools[j] = j; |
85 } | 81 array_of_array_of_bools[i] = array_of_bools.Pass(); |
86 array_of_array_of_bools[i] = array_of_bools.Finish(); | |
87 } | 82 } |
88 | 83 |
89 mojo::ScopedMessagePipeHandle pipe0, pipe1; | 84 mojo::ScopedMessagePipeHandle pipe0, pipe1; |
90 mojo::CreateMessagePipe(&pipe0, &pipe1); | 85 mojo::CreateMessagePipe(&pipe0, &pipe1); |
91 | 86 |
92 Foo::Builder foo; | 87 FooPtr foo(Foo::New()); |
93 foo.set_name(name); | 88 foo->name = name; |
94 foo.set_x(1); | 89 foo->x = 1; |
95 foo.set_y(2); | 90 foo->y = 2; |
96 foo.set_a(false); | 91 foo->a = false; |
97 foo.set_b(true); | 92 foo->b = true; |
98 foo.set_c(false); | 93 foo->c = false; |
99 foo.set_bar(bar.Finish()); | 94 foo->bar = bar.Pass(); |
100 foo.set_extra_bars(extra_bars.Finish()); | 95 foo->extra_bars = extra_bars.Pass(); |
101 foo.set_data(data.Finish()); | 96 foo->data = data.Pass(); |
102 foo.set_source(pipe1.Pass()); | 97 foo->source = pipe1.Pass(); |
103 foo.set_input_streams(input_streams.Finish()); | 98 foo->input_streams = input_streams.Pass(); |
104 foo.set_output_streams(output_streams.Finish()); | 99 foo->output_streams = output_streams.Pass(); |
105 foo.set_array_of_array_of_bools(array_of_array_of_bools.Finish()); | 100 foo->array_of_array_of_bools = array_of_array_of_bools.Pass(); |
106 | 101 |
107 return foo.Finish(); | 102 return foo.Pass(); |
108 } | 103 } |
109 | 104 |
110 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. | 105 // Check that the given |Foo| is identical to the one made by |MakeFoo()|. |
111 void CheckFoo(const Foo& foo) { | 106 void CheckFoo(const Foo& foo) { |
112 const std::string kName("foopy"); | 107 const std::string kName("foopy"); |
113 ASSERT_FALSE(foo.name().is_null()); | 108 ASSERT_FALSE(foo.name.is_null()); |
114 EXPECT_EQ(kName.size(), foo.name().size()); | 109 EXPECT_EQ(kName.size(), foo.name.size()); |
115 for (size_t i = 0; i < std::min(kName.size(), foo.name().size()); i++) { | 110 for (size_t i = 0; i < std::min(kName.size(), foo.name.size()); i++) { |
116 // Test both |operator[]| and |at|. | 111 // Test both |operator[]| and |at|. |
117 EXPECT_EQ(kName[i], foo.name().at(i)) << i; | 112 EXPECT_EQ(kName[i], foo.name.at(i)) << i; |
118 EXPECT_EQ(kName[i], foo.name()[i]) << i; | 113 EXPECT_EQ(kName[i], foo.name[i]) << i; |
119 } | 114 } |
120 EXPECT_EQ(kName, foo.name().To<std::string>()); | 115 EXPECT_EQ(kName, foo.name.get()); |
121 | 116 |
122 EXPECT_EQ(1, foo.x()); | 117 EXPECT_EQ(1, foo.x); |
123 EXPECT_EQ(2, foo.y()); | 118 EXPECT_EQ(2, foo.y); |
124 EXPECT_FALSE(foo.a()); | 119 EXPECT_FALSE(foo.a); |
125 EXPECT_TRUE(foo.b()); | 120 EXPECT_TRUE(foo.b); |
126 EXPECT_FALSE(foo.c()); | 121 EXPECT_FALSE(foo.c); |
127 | 122 |
128 EXPECT_EQ(20, foo.bar().alpha()); | 123 EXPECT_EQ(20, foo.bar->alpha); |
129 EXPECT_EQ(40, foo.bar().beta()); | 124 EXPECT_EQ(40, foo.bar->beta); |
130 EXPECT_EQ(60, foo.bar().gamma()); | 125 EXPECT_EQ(60, foo.bar->gamma); |
131 EXPECT_EQ(Bar::TYPE_VERTICAL, foo.bar().type()); | 126 EXPECT_EQ(Bar::TYPE_VERTICAL, foo.bar->type); |
132 | 127 |
133 EXPECT_EQ(3u, foo.extra_bars().size()); | 128 EXPECT_EQ(3u, foo.extra_bars.size()); |
134 for (size_t i = 0; i < foo.extra_bars().size(); i++) { | 129 for (size_t i = 0; i < foo.extra_bars.size(); i++) { |
135 uint8_t base = static_cast<uint8_t>(i * 100); | 130 uint8_t base = static_cast<uint8_t>(i * 100); |
136 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; | 131 Bar::Type type = i % 2 == 0 ? Bar::TYPE_VERTICAL : Bar::TYPE_HORIZONTAL; |
137 EXPECT_EQ(base, foo.extra_bars()[i].alpha()) << i; | 132 EXPECT_EQ(base, foo.extra_bars[i]->alpha) << i; |
138 EXPECT_EQ(base + 20, foo.extra_bars()[i].beta()) << i; | 133 EXPECT_EQ(base + 20, foo.extra_bars[i]->beta) << i; |
139 EXPECT_EQ(base + 40, foo.extra_bars()[i].gamma()) << i; | 134 EXPECT_EQ(base + 40, foo.extra_bars[i]->gamma) << i; |
140 EXPECT_EQ(type, foo.extra_bars()[i].type()) << i; | 135 EXPECT_EQ(type, foo.extra_bars[i]->type) << i; |
141 } | 136 } |
142 | 137 |
143 EXPECT_EQ(10u, foo.data().size()); | 138 EXPECT_EQ(10u, foo.data.size()); |
144 for (size_t i = 0; i < foo.data().size(); ++i) { | 139 for (size_t i = 0; i < foo.data.size(); ++i) { |
145 EXPECT_EQ(static_cast<uint8_t>(foo.data().size() - i), foo.data()[i]) << i; | 140 EXPECT_EQ(static_cast<uint8_t>(foo.data.size() - i), foo.data[i]) << i; |
146 } | 141 } |
147 | 142 |
148 EXPECT_FALSE(foo.input_streams().is_null()); | 143 EXPECT_FALSE(foo.input_streams.is_null()); |
149 EXPECT_EQ(2u, foo.input_streams().size()); | 144 EXPECT_EQ(2u, foo.input_streams.size()); |
150 | 145 |
151 EXPECT_FALSE(foo.output_streams().is_null()); | 146 EXPECT_FALSE(foo.output_streams.is_null()); |
152 EXPECT_EQ(2u, foo.output_streams().size()); | 147 EXPECT_EQ(2u, foo.output_streams.size()); |
153 | 148 |
154 EXPECT_EQ(2u, foo.array_of_array_of_bools().size()); | 149 EXPECT_EQ(2u, foo.array_of_array_of_bools.size()); |
155 for (size_t i = 0; i < foo.array_of_array_of_bools().size(); ++i) { | 150 for (size_t i = 0; i < foo.array_of_array_of_bools.size(); ++i) { |
156 EXPECT_EQ(2u, foo.array_of_array_of_bools()[i].size()); | 151 EXPECT_EQ(2u, foo.array_of_array_of_bools[i].size()); |
157 for (size_t j = 0; j < foo.array_of_array_of_bools()[i].size(); ++j) { | 152 for (size_t j = 0; j < foo.array_of_array_of_bools[i].size(); ++j) { |
158 EXPECT_EQ(bool(j), foo.array_of_array_of_bools()[i][j]); | 153 EXPECT_EQ(bool(j), foo.array_of_array_of_bools[i][j]); |
159 } | 154 } |
160 } | 155 } |
161 } | 156 } |
162 | 157 |
163 void PrintSpacer(int depth) { | 158 void PrintSpacer(int depth) { |
164 for (int i = 0; i < depth; ++i) | 159 for (int i = 0; i < depth; ++i) |
165 std::cout << " "; | 160 std::cout << " "; |
166 } | 161 } |
167 | 162 |
168 void Print(int depth, const char* name, bool value) { | 163 void Print(int depth, const char* name, bool value) { |
169 PrintSpacer(depth); | 164 PrintSpacer(depth); |
170 std::cout << name << ": " << (value ? "true" : "false") << std::endl; | 165 std::cout << name << ": " << (value ? "true" : "false") << std::endl; |
171 } | 166 } |
172 | 167 |
173 void Print(int depth, const char* name, int32_t value) { | 168 void Print(int depth, const char* name, int32_t value) { |
174 PrintSpacer(depth); | 169 PrintSpacer(depth); |
175 std::cout << name << ": " << value << std::endl; | 170 std::cout << name << ": " << value << std::endl; |
176 } | 171 } |
177 | 172 |
178 void Print(int depth, const char* name, uint8_t value) { | 173 void Print(int depth, const char* name, uint8_t value) { |
179 PrintSpacer(depth); | 174 PrintSpacer(depth); |
180 std::cout << name << ": " << uint32_t(value) << std::endl; | 175 std::cout << name << ": " << uint32_t(value) << std::endl; |
181 } | 176 } |
182 | 177 |
183 void Print(int depth, const char* name, mojo::Handle value) { | 178 template <typename H> |
| 179 void Print(int depth, const char* name, |
| 180 const mojo::ScopedHandleBase<H>& value) { |
184 PrintSpacer(depth); | 181 PrintSpacer(depth); |
185 std::cout << name << ": 0x" << std::hex << value.value() << std::endl; | 182 std::cout << name << ": 0x" << std::hex << value.get().value() << std::endl; |
186 } | 183 } |
187 | 184 |
188 void Print(int depth, const char* name, const mojo::String& str) { | 185 void Print(int depth, const char* name, const mojo::String& str) { |
189 std::string s = str.To<std::string>(); | |
190 PrintSpacer(depth); | 186 PrintSpacer(depth); |
191 std::cout << name << ": \"" << str.To<std::string>() << "\"" << std::endl; | 187 std::cout << name << ": \"" << str.get() << "\"" << std::endl; |
192 } | 188 } |
193 | 189 |
194 void Print(int depth, const char* name, const Bar& bar) { | 190 void Print(int depth, const char* name, const BarPtr& bar) { |
195 PrintSpacer(depth); | 191 PrintSpacer(depth); |
196 std::cout << name << ":" << std::endl; | 192 std::cout << name << ":" << std::endl; |
197 if (!bar.is_null()) { | 193 if (!bar.is_null()) { |
198 ++depth; | 194 ++depth; |
199 Print(depth, "alpha", bar.alpha()); | 195 Print(depth, "alpha", bar->alpha); |
200 Print(depth, "beta", bar.beta()); | 196 Print(depth, "beta", bar->beta); |
201 Print(depth, "gamma", bar.gamma()); | 197 Print(depth, "gamma", bar->gamma); |
202 Print(depth, "packed", bar.To<int32_t>()); | 198 Print(depth, "packed", bar.To<int32_t>()); |
203 --depth; | 199 --depth; |
204 } | 200 } |
205 } | 201 } |
206 | 202 |
207 template <typename T> | 203 template <typename T> |
208 void Print(int depth, const char* name, | |
209 const mojo::Passable<T>& passable) { | |
210 Print(depth, name, passable.get()); | |
211 } | |
212 | |
213 template <typename T> | |
214 void Print(int depth, const char* name, const mojo::Array<T>& array) { | 204 void Print(int depth, const char* name, const mojo::Array<T>& array) { |
215 PrintSpacer(depth); | 205 PrintSpacer(depth); |
216 std::cout << name << ":" << std::endl; | 206 std::cout << name << ":" << std::endl; |
217 if (!array.is_null()) { | 207 if (!array.is_null()) { |
218 ++depth; | 208 ++depth; |
219 for (size_t i = 0; i < array.size(); ++i) { | 209 for (size_t i = 0; i < array.size(); ++i) { |
220 std::stringstream buf; | 210 std::stringstream buf; |
221 buf << i; | 211 buf << i; |
222 Print(depth, buf.str().data(), array.at(i)); | 212 Print(depth, buf.str().data(), array.at(i)); |
223 } | 213 } |
224 --depth; | 214 --depth; |
225 } | 215 } |
226 } | 216 } |
227 | 217 |
228 void Print(int depth, const char* name, const Foo& foo) { | 218 void Print(int depth, const char* name, const FooPtr& foo) { |
229 PrintSpacer(depth); | 219 PrintSpacer(depth); |
230 std::cout << name << ":" << std::endl; | 220 std::cout << name << ":" << std::endl; |
231 if (!foo.is_null()) { | 221 if (!foo.is_null()) { |
232 ++depth; | 222 ++depth; |
233 Print(depth, "name", foo.name()); | 223 Print(depth, "name", foo->name); |
234 Print(depth, "x", foo.x()); | 224 Print(depth, "x", foo->x); |
235 Print(depth, "y", foo.y()); | 225 Print(depth, "y", foo->y); |
236 Print(depth, "a", foo.a()); | 226 Print(depth, "a", foo->a); |
237 Print(depth, "b", foo.b()); | 227 Print(depth, "b", foo->b); |
238 Print(depth, "c", foo.c()); | 228 Print(depth, "c", foo->c); |
239 Print(depth, "bar", foo.bar()); | 229 Print(depth, "bar", foo->bar); |
240 Print(depth, "extra_bars", foo.extra_bars()); | 230 Print(depth, "extra_bars", foo->extra_bars); |
241 Print(depth, "data", foo.data()); | 231 Print(depth, "data", foo->data); |
242 Print(depth, "source", foo.source().get()); | 232 Print(depth, "source", foo->source); |
243 Print(depth, "input_streams", foo.input_streams()); | 233 Print(depth, "input_streams", foo->input_streams); |
244 Print(depth, "output_streams", foo.output_streams()); | 234 Print(depth, "output_streams", foo->output_streams); |
245 Print(depth, "array_of_array_of_bools", foo.array_of_array_of_bools()); | 235 Print(depth, "array_of_array_of_bools", foo->array_of_array_of_bools); |
246 --depth; | 236 --depth; |
247 } | 237 } |
248 } | 238 } |
249 | 239 |
250 void DumpHex(const uint8_t* bytes, uint32_t num_bytes) { | 240 void DumpHex(const uint8_t* bytes, uint32_t num_bytes) { |
251 for (uint32_t i = 0; i < num_bytes; ++i) { | 241 for (uint32_t i = 0; i < num_bytes; ++i) { |
252 std::cout << std::setw(2) << std::setfill('0') << std::hex << | 242 std::cout << std::setw(2) << std::setfill('0') << std::hex << |
253 uint32_t(bytes[i]); | 243 uint32_t(bytes[i]); |
254 | 244 |
255 if (i % 16 == 15) { | 245 if (i % 16 == 15) { |
256 std::cout << std::endl; | 246 std::cout << std::endl; |
257 continue; | 247 continue; |
258 } | 248 } |
259 | 249 |
260 if (i % 2 == 1) | 250 if (i % 2 == 1) |
261 std::cout << " "; | 251 std::cout << " "; |
262 if (i % 8 == 7) | 252 if (i % 8 == 7) |
263 std::cout << " "; | 253 std::cout << " "; |
264 } | 254 } |
265 } | 255 } |
266 | 256 |
267 class ServiceImpl : public Service { | 257 class ServiceImpl : public Service { |
268 public: | 258 public: |
269 virtual void Frobinate(const Foo& foo, BazOptions baz, PortPtr port) | 259 virtual void Frobinate(FooPtr foo, BazOptions baz, PortPtr port) |
270 MOJO_OVERRIDE { | 260 MOJO_OVERRIDE { |
271 // Users code goes here to handle the incoming Frobinate message. | 261 // Users code goes here to handle the incoming Frobinate message. |
272 | 262 |
273 // We mainly check that we're given the expected arguments. | 263 // We mainly check that we're given the expected arguments. |
274 CheckFoo(foo); | 264 EXPECT_FALSE(foo.is_null()); |
| 265 if (!foo.is_null()) |
| 266 CheckFoo(*foo); |
275 EXPECT_EQ(BAZ_EXTRA, baz); | 267 EXPECT_EQ(BAZ_EXTRA, baz); |
276 | 268 |
277 if (g_dump_message_as_text) { | 269 if (g_dump_message_as_text) { |
278 // Also dump the Foo structure and all of its members. | 270 // Also dump the Foo structure and all of its members. |
279 std::cout << "Frobinate:" << std::endl; | 271 std::cout << "Frobinate:" << std::endl; |
280 int depth = 1; | 272 int depth = 1; |
281 Print(depth, "foo", foo); | 273 Print(depth, "foo", foo); |
282 Print(depth, "baz", baz); | 274 Print(depth, "baz", baz); |
283 Print(depth, "port", port.get()); | 275 Print(depth, "port", port.get()); |
284 } | 276 } |
(...skipping 27 matching lines...) Expand all Loading... |
312 } | 304 } |
313 | 305 |
314 virtual bool AcceptWithResponder(mojo::Message* message, | 306 virtual bool AcceptWithResponder(mojo::Message* message, |
315 mojo::MessageReceiver* responder) | 307 mojo::MessageReceiver* responder) |
316 MOJO_OVERRIDE { | 308 MOJO_OVERRIDE { |
317 return false; | 309 return false; |
318 } | 310 } |
319 }; | 311 }; |
320 | 312 |
321 TEST(BindingsSampleTest, Basic) { | 313 TEST(BindingsSampleTest, Basic) { |
322 mojo::Environment env; | |
323 SimpleMessageReceiver receiver; | 314 SimpleMessageReceiver receiver; |
324 | 315 |
325 // User has a proxy to a Service somehow. | 316 // User has a proxy to a Service somehow. |
326 Service* service = new ServiceProxyImpl(&receiver); | 317 Service* service = new ServiceProxyImpl(&receiver); |
327 | 318 |
328 // User constructs a message to send. | 319 // User constructs a message to send. |
329 | 320 |
330 // Notice that it doesn't matter in what order the structs / arrays are | 321 // Notice that it doesn't matter in what order the structs / arrays are |
331 // allocated. Here, the various members of Foo are allocated before Foo is | 322 // allocated. Here, the various members of Foo are allocated before Foo is |
332 // allocated. | 323 // allocated. |
333 | 324 |
334 mojo::AllocationScope scope; | 325 FooPtr foo = MakeFoo(); |
335 | 326 CheckFoo(*foo); |
336 Foo foo = MakeFoo(); | |
337 CheckFoo(foo); | |
338 | 327 |
339 PortPtr port; | 328 PortPtr port; |
340 service->Frobinate(foo, Service::BAZ_EXTRA, port.Pass()); | 329 service->Frobinate(foo.Pass(), Service::BAZ_EXTRA, port.Pass()); |
341 | 330 |
342 delete service; | 331 delete service; |
343 } | 332 } |
344 | 333 |
345 TEST(BindingsSampleTest, DefaultValues) { | 334 TEST(BindingsSampleTest, DefaultValues) { |
346 mojo::Environment env; | 335 DefaultsTestPtr full(DefaultsTest::New()); |
347 SimpleMessageReceiver receiver; | 336 EXPECT_EQ(-12, full->a0); |
348 mojo::AllocationScope scope; | 337 EXPECT_EQ(12U, full->a1); |
349 | 338 EXPECT_EQ(1234, full->a2); |
350 DefaultsTest full = DefaultsTest::Builder().Finish(); | 339 EXPECT_EQ(34567U, full->a3); |
351 EXPECT_EQ(-12, full.a0()); | 340 EXPECT_EQ(123456, full->a4); |
352 EXPECT_EQ(12U, full.a1()); | |
353 EXPECT_EQ(1234, full.a2()); | |
354 EXPECT_EQ(34567U, full.a3()); | |
355 EXPECT_EQ(123456, full.a4()); | |
356 // TODO(vtl): crbug.com/375522 | 341 // TODO(vtl): crbug.com/375522 |
357 // EXPECT_EQ(3456789012U, full.a5()); | 342 // EXPECT_EQ(3456789012U, full->a5); |
358 EXPECT_EQ(111111111111LL, full.a6()); | 343 EXPECT_EQ(111111111111LL, full->a6); |
359 // TODO(vtl): crbug.com/375522 | 344 // TODO(vtl): crbug.com/375522 |
360 // EXPECT_EQ(9999999999999999999ULL, full.a7()); | 345 // EXPECT_EQ(9999999999999999999ULL, full->a7); |
361 EXPECT_EQ(0x12345, full.a8()); | 346 EXPECT_EQ(0x12345, full->a8); |
362 EXPECT_EQ(-0x12345, full.a9()); | 347 EXPECT_EQ(-0x12345, full->a9); |
363 EXPECT_EQ(1234, full.a10()); | 348 EXPECT_EQ(1234, full->a10); |
364 EXPECT_TRUE(full.a11()); | 349 EXPECT_TRUE(full->a11); |
365 EXPECT_FALSE(full.a12()); | 350 EXPECT_FALSE(full->a12); |
366 EXPECT_FLOAT_EQ(123.25f, full.a13()); | 351 EXPECT_FLOAT_EQ(123.25f, full->a13); |
367 EXPECT_DOUBLE_EQ(1234567890.123, full.a14()); | 352 EXPECT_DOUBLE_EQ(1234567890.123, full->a14); |
368 EXPECT_DOUBLE_EQ(1E10, full.a15()); | 353 EXPECT_DOUBLE_EQ(1E10, full->a15); |
369 EXPECT_DOUBLE_EQ(-1.2E+20, full.a16()); | 354 EXPECT_DOUBLE_EQ(-1.2E+20, full->a16); |
370 EXPECT_DOUBLE_EQ(1.23E-20, full.a17()); | 355 EXPECT_DOUBLE_EQ(1.23E-20, full->a17); |
371 EXPECT_TRUE(full.a18().is_null()); | 356 EXPECT_TRUE(full->a18.is_null()); |
372 EXPECT_TRUE(full.a19().is_null()); | 357 EXPECT_TRUE(full->a19.is_null()); |
373 EXPECT_TRUE(full.a20().is_null()); | 358 EXPECT_TRUE(full->a20.is_null()); |
374 } | 359 } |
375 | 360 |
376 } // namespace | 361 } // namespace |
377 } // namespace sample | 362 } // namespace sample |
OLD | NEW |