| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 class DummyMessageReceiver : public MessageReceiver { | 190 class DummyMessageReceiver : public MessageReceiver { |
| 191 public: | 191 public: |
| 192 bool Accept(Message* message) override { | 192 bool Accept(Message* message) override { |
| 193 return true; // Any message is OK. | 193 return true; // Any message is OK. |
| 194 } | 194 } |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 using ValidationTest = testing::Test; | 197 class ValidationTest : public testing::Test { |
| 198 public: |
| 199 ValidationTest() : loop_(common::MessagePumpMojo::Create()) {} |
| 200 |
| 201 protected: |
| 202 base::MessageLoop loop_; |
| 203 }; |
| 198 | 204 |
| 199 class ValidationIntegrationTest : public ValidationTest { | 205 class ValidationIntegrationTest : public ValidationTest { |
| 200 public: | 206 public: |
| 201 ValidationIntegrationTest() | 207 ValidationIntegrationTest() : test_message_receiver_(nullptr) {} |
| 202 : loop_(common::MessagePumpMojo::Create()), | |
| 203 test_message_receiver_(nullptr) {} | |
| 204 | 208 |
| 205 ~ValidationIntegrationTest() override {} | 209 ~ValidationIntegrationTest() override {} |
| 206 | 210 |
| 207 void SetUp() override { | 211 void SetUp() override { |
| 208 ScopedMessagePipeHandle tester_endpoint; | 212 ScopedMessagePipeHandle tester_endpoint; |
| 209 ASSERT_EQ(MOJO_RESULT_OK, | 213 ASSERT_EQ(MOJO_RESULT_OK, |
| 210 CreateMessagePipe(nullptr, &tester_endpoint, &testee_endpoint_)); | 214 CreateMessagePipe(nullptr, &tester_endpoint, &testee_endpoint_)); |
| 211 test_message_receiver_ = | 215 test_message_receiver_ = |
| 212 new TestMessageReceiver(this, std::move(tester_endpoint)); | 216 new TestMessageReceiver(this, std::move(tester_endpoint)); |
| 213 } | 217 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 243 return connector_.Accept(message); | 247 return connector_.Accept(message); |
| 244 } | 248 } |
| 245 | 249 |
| 246 public: | 250 public: |
| 247 ValidationIntegrationTest* owner_; | 251 ValidationIntegrationTest* owner_; |
| 248 mojo::internal::Connector connector_; | 252 mojo::internal::Connector connector_; |
| 249 }; | 253 }; |
| 250 | 254 |
| 251 void PumpMessages() { loop_.RunUntilIdle(); } | 255 void PumpMessages() { loop_.RunUntilIdle(); } |
| 252 | 256 |
| 253 base::MessageLoop loop_; | |
| 254 TestMessageReceiver* test_message_receiver_; | 257 TestMessageReceiver* test_message_receiver_; |
| 255 ScopedMessagePipeHandle testee_endpoint_; | 258 ScopedMessagePipeHandle testee_endpoint_; |
| 256 }; | 259 }; |
| 257 | 260 |
| 258 class IntegrationTestInterfaceImpl : public IntegrationTestInterface { | 261 class IntegrationTestInterfaceImpl : public IntegrationTestInterface { |
| 259 public: | 262 public: |
| 260 ~IntegrationTestInterfaceImpl() override {} | 263 ~IntegrationTestInterfaceImpl() override {} |
| 261 | 264 |
| 262 void Method0(BasicStructPtr param0, | 265 void Method0(BasicStructPtr param0, |
| 263 const Method0Callback& callback) override { | 266 const Method0Callback& callback) override { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 EXPECT_TRUE(mojo::internal::ValidateEncodedPointer(&offset)); | 458 EXPECT_TRUE(mojo::internal::ValidateEncodedPointer(&offset)); |
| 456 | 459 |
| 457 offset = 1ULL; | 460 offset = 1ULL; |
| 458 EXPECT_TRUE(mojo::internal::ValidateEncodedPointer(&offset)); | 461 EXPECT_TRUE(mojo::internal::ValidateEncodedPointer(&offset)); |
| 459 | 462 |
| 460 // offset must be <= 32-bit. | 463 // offset must be <= 32-bit. |
| 461 offset = std::numeric_limits<uint32_t>::max() + 1ULL; | 464 offset = std::numeric_limits<uint32_t>::max() + 1ULL; |
| 462 EXPECT_FALSE(mojo::internal::ValidateEncodedPointer(&offset)); | 465 EXPECT_FALSE(mojo::internal::ValidateEncodedPointer(&offset)); |
| 463 } | 466 } |
| 464 | 467 |
| 465 // Tests the IsValidValue() function generated for BasicEnum. | 468 // Tests the IsKnownEnumValue() function generated for BasicEnum. |
| 466 TEST(EnumValueValidationTest, BasicEnum) { | 469 TEST(EnumValueValidationTest, BasicEnum) { |
| 467 // BasicEnum can have -3,0,1,10 as possible integral values. | 470 // BasicEnum can have -3,0,1,10 as possible integral values. |
| 468 EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-4))); | 471 EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(-4))); |
| 469 EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-3))); | 472 EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(-3))); |
| 470 EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-2))); | 473 EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(-2))); |
| 471 EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(-1))); | 474 EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(-1))); |
| 472 EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(0))); | 475 EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(0))); |
| 473 EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(1))); | 476 EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(1))); |
| 474 EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(2))); | 477 EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(2))); |
| 475 EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(9))); | 478 EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(9))); |
| 476 // In the mojom, we represent this value as hex (0xa). | 479 // In the mojom, we represent this value as hex (0xa). |
| 477 EXPECT_TRUE(BasicEnum_IsValidValue(static_cast<BasicEnum>(10))); | 480 EXPECT_TRUE(IsKnownEnumValue(static_cast<BasicEnum>(10))); |
| 478 EXPECT_FALSE(BasicEnum_IsValidValue(static_cast<BasicEnum>(11))); | 481 EXPECT_FALSE(IsKnownEnumValue(static_cast<BasicEnum>(11))); |
| 479 } | 482 } |
| 480 | 483 |
| 481 // Tests the IsValidValue() method generated for StructWithEnum. | 484 // Tests the IsKnownEnumValue() method generated for StructWithEnum. |
| 482 TEST(EnumValueValidationTest, EnumWithin) { | 485 TEST(EnumValueValidationTest, EnumWithin) { |
| 483 // StructWithEnum::EnumWithin can have [0,4] as possible integral values. | 486 // StructWithEnum::EnumWithin can have [0,4] as possible integral values. |
| 484 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue( | 487 EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(-1))); |
| 485 static_cast<StructWithEnum::EnumWithin>(-1))); | 488 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(0))); |
| 486 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( | 489 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(1))); |
| 487 static_cast<StructWithEnum::EnumWithin>(0))); | 490 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(2))); |
| 488 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( | 491 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(3))); |
| 489 static_cast<StructWithEnum::EnumWithin>(1))); | 492 EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(4))); |
| 490 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( | |
| 491 static_cast<StructWithEnum::EnumWithin>(2))); | |
| 492 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( | |
| 493 static_cast<StructWithEnum::EnumWithin>(3))); | |
| 494 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue( | |
| 495 static_cast<StructWithEnum::EnumWithin>(4))); | |
| 496 } | 493 } |
| 497 | 494 |
| 498 } // namespace | 495 } // namespace |
| 499 } // namespace test | 496 } // namespace test |
| 500 } // namespace mojo | 497 } // namespace mojo |
| OLD | NEW |