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 <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 class DummyMessageReceiver : public MessageReceiver { | 181 class DummyMessageReceiver : public MessageReceiver { |
182 public: | 182 public: |
183 virtual bool Accept(Message* message) MOJO_OVERRIDE { | 183 virtual bool Accept(Message* message) MOJO_OVERRIDE { |
184 return true; // Any message is OK. | 184 return true; // Any message is OK. |
185 } | 185 } |
186 }; | 186 }; |
187 | 187 |
188 class ValidationIntegrationTest : public testing::Test { | 188 class ValidationTest : public testing::Test { |
| 189 public: |
| 190 virtual ~ValidationTest() { |
| 191 } |
| 192 |
| 193 private: |
| 194 Environment env_; |
| 195 }; |
| 196 |
| 197 class ValidationIntegrationTest : public ValidationTest { |
189 public: | 198 public: |
190 ValidationIntegrationTest() : test_message_receiver_(NULL) { | 199 ValidationIntegrationTest() : test_message_receiver_(NULL) { |
191 } | 200 } |
192 | 201 |
193 virtual ~ValidationIntegrationTest() { | 202 virtual ~ValidationIntegrationTest() { |
194 } | 203 } |
195 | 204 |
196 virtual void SetUp() MOJO_OVERRIDE { | 205 virtual void SetUp() MOJO_OVERRIDE { |
197 ScopedMessagePipeHandle tester_endpoint; | 206 ScopedMessagePipeHandle tester_endpoint; |
198 ASSERT_EQ(MOJO_RESULT_OK, | 207 ASSERT_EQ(MOJO_RESULT_OK, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 246 |
238 public: | 247 public: |
239 ValidationIntegrationTest* owner_; | 248 ValidationIntegrationTest* owner_; |
240 mojo::internal::Connector connector_; | 249 mojo::internal::Connector connector_; |
241 }; | 250 }; |
242 | 251 |
243 void PumpMessages() { | 252 void PumpMessages() { |
244 loop_.RunUntilIdle(); | 253 loop_.RunUntilIdle(); |
245 } | 254 } |
246 | 255 |
247 Environment env_; | |
248 RunLoop loop_; | 256 RunLoop loop_; |
249 TestMessageReceiver* test_message_receiver_; | 257 TestMessageReceiver* test_message_receiver_; |
250 ScopedMessagePipeHandle testee_endpoint_; | 258 ScopedMessagePipeHandle testee_endpoint_; |
251 }; | 259 }; |
252 | 260 |
253 class IntegrationTestInterface1Client : public IntegrationTestInterface1 { | 261 class IntegrationTestInterface1Client : public IntegrationTestInterface1 { |
254 public: | 262 public: |
255 virtual ~IntegrationTestInterface1Client() { | 263 virtual ~IntegrationTestInterface1Client() { |
256 } | 264 } |
257 | 265 |
258 virtual void Method0(BasicStructPtr param0) MOJO_OVERRIDE { | 266 virtual void Method0(BasicStructPtr param0) MOJO_OVERRIDE { |
259 } | 267 } |
260 }; | 268 }; |
261 | 269 |
262 class IntegrationTestInterface1Impl | 270 class IntegrationTestInterface1Impl |
263 : public InterfaceImpl<IntegrationTestInterface1> { | 271 : public InterfaceImpl<IntegrationTestInterface1> { |
264 public: | 272 public: |
265 virtual ~IntegrationTestInterface1Impl() { | 273 virtual ~IntegrationTestInterface1Impl() { |
266 } | 274 } |
267 | 275 |
268 virtual void Method0(BasicStructPtr param0) MOJO_OVERRIDE { | 276 virtual void Method0(BasicStructPtr param0) MOJO_OVERRIDE { |
269 } | 277 } |
270 | 278 |
271 virtual void OnConnectionError() MOJO_OVERRIDE { | 279 virtual void OnConnectionError() MOJO_OVERRIDE { |
272 delete this; | 280 delete this; |
273 } | 281 } |
274 }; | 282 }; |
275 | 283 |
276 TEST(ValidationTest, InputParser) { | 284 TEST_F(ValidationTest, InputParser) { |
277 { | 285 { |
278 // The parser, as well as Append() defined above, assumes that this code is | 286 // The parser, as well as Append() defined above, assumes that this code is |
279 // running on a little-endian platform. Test whether that is true. | 287 // running on a little-endian platform. Test whether that is true. |
280 uint16_t x = 1; | 288 uint16_t x = 1; |
281 ASSERT_EQ(1, *(reinterpret_cast<char*>(&x))); | 289 ASSERT_EQ(1, *(reinterpret_cast<char*>(&x))); |
282 } | 290 } |
283 { | 291 { |
284 // Test empty input. | 292 // Test empty input. |
285 std::string input; | 293 std::string input; |
286 std::vector<uint8_t> expected; | 294 std::vector<uint8_t> expected; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 }; | 379 }; |
372 | 380 |
373 for (size_t i = 0; error_inputs[i]; ++i) { | 381 for (size_t i = 0; error_inputs[i]; ++i) { |
374 std::vector<uint8_t> expected; | 382 std::vector<uint8_t> expected; |
375 if (!TestInputParser(error_inputs[i], false, expected, 0)) | 383 if (!TestInputParser(error_inputs[i], false, expected, 0)) |
376 ADD_FAILURE() << "Unexpected test result for: " << error_inputs[i]; | 384 ADD_FAILURE() << "Unexpected test result for: " << error_inputs[i]; |
377 } | 385 } |
378 } | 386 } |
379 } | 387 } |
380 | 388 |
381 TEST(ValidationTest, Conformance) { | 389 TEST_F(ValidationTest, Conformance) { |
382 DummyMessageReceiver dummy_receiver; | 390 DummyMessageReceiver dummy_receiver; |
383 mojo::internal::FilterChain validators(&dummy_receiver); | 391 mojo::internal::FilterChain validators(&dummy_receiver); |
384 validators.Append<mojo::internal::MessageHeaderValidator>(); | 392 validators.Append<mojo::internal::MessageHeaderValidator>(); |
385 validators.Append<ConformanceTestInterface::RequestValidator_>(); | 393 validators.Append<ConformanceTestInterface::RequestValidator_>(); |
386 | 394 |
387 RunValidationTests("conformance_", validators.GetHead()); | 395 RunValidationTests("conformance_", validators.GetHead()); |
388 } | 396 } |
389 | 397 |
390 TEST_F(ValidationIntegrationTest, InterfacePtr) { | 398 TEST_F(ValidationIntegrationTest, InterfacePtr) { |
391 // Test that InterfacePtr<X> applies the correct validators and they don't | 399 // Test that InterfacePtr<X> applies the correct validators and they don't |
(...skipping 22 matching lines...) Expand all Loading... |
414 IntegrationTestInterface1Impl* interface1_impl = | 422 IntegrationTestInterface1Impl* interface1_impl = |
415 BindToPipe(new IntegrationTestInterface1Impl(), testee_endpoint().Pass()); | 423 BindToPipe(new IntegrationTestInterface1Impl(), testee_endpoint().Pass()); |
416 interface1_impl->internal_state()->router()->EnableTestingMode(); | 424 interface1_impl->internal_state()->router()->EnableTestingMode(); |
417 | 425 |
418 RunValidationTests("integration_", test_message_receiver()); | 426 RunValidationTests("integration_", test_message_receiver()); |
419 } | 427 } |
420 | 428 |
421 } // namespace | 429 } // namespace |
422 } // namespace test | 430 } // namespace test |
423 } // namespace mojo | 431 } // namespace mojo |
OLD | NEW |