| Index: third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
|
| diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
|
| index 524b07c64d2e750e2eadb2cca09f52ff41f6d423..09e481242cfd266eb8c8e1788b5d3a9df4a93899 100644
|
| --- a/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
|
| +++ b/third_party/mojo/src/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
|
| @@ -8,6 +8,7 @@
|
| #include "mojo/public/cpp/environment/environment.h"
|
| #include "mojo/public/cpp/utility/run_loop.h"
|
| #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h"
|
| +#include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h"
|
| #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -176,6 +177,23 @@ class ReentrantServiceImpl : public sample::Service {
|
| Binding<sample::Service> binding_;
|
| };
|
|
|
| +class IntegerAccessorImpl : public sample::IntegerAccessor {
|
| + public:
|
| + IntegerAccessorImpl() : integer_(0) {}
|
| + ~IntegerAccessorImpl() override {}
|
| +
|
| + int64_t integer() const { return integer_; }
|
| +
|
| + private:
|
| + // sample::IntegerAccessor implementation.
|
| + void GetInteger(const GetIntegerCallback& callback) override {
|
| + callback.Run(integer_, sample::ENUM_VALUE);
|
| + }
|
| + void SetInteger(int64_t data, sample::Enum type) override { integer_ = data; }
|
| +
|
| + int64_t integer_;
|
| +};
|
| +
|
| class InterfacePtrTest : public testing::Test {
|
| public:
|
| ~InterfacePtrTest() override { loop_.RunUntilIdle(); }
|
| @@ -248,7 +266,7 @@ TEST_F(InterfacePtrTest, Resettable) {
|
| // Save this so we can test it later.
|
| Handle handle = pipe.handle0.get();
|
|
|
| - a = MakeProxy<math::Calculator>(pipe.handle0.Pass());
|
| + a = MakeProxy(InterfacePtrInfo<math::Calculator>(pipe.handle0.Pass(), 0u));
|
|
|
| EXPECT_FALSE(!a);
|
|
|
| @@ -266,7 +284,7 @@ TEST_F(InterfacePtrTest, BindInvalidHandle) {
|
| EXPECT_FALSE(ptr.get());
|
| EXPECT_FALSE(ptr);
|
|
|
| - ptr.Bind(ScopedMessagePipeHandle());
|
| + ptr.Bind(InterfacePtrInfo<math::Calculator>());
|
| EXPECT_FALSE(ptr.get());
|
| EXPECT_FALSE(ptr);
|
| }
|
| @@ -374,6 +392,53 @@ TEST_F(InterfacePtrTest, ReentrantWaitForIncomingMethodCall) {
|
| EXPECT_EQ(2, impl.max_call_depth());
|
| }
|
|
|
| +TEST_F(InterfacePtrTest, QueryVersion) {
|
| + IntegerAccessorImpl impl;
|
| + sample::IntegerAccessorPtr ptr;
|
| + Binding<sample::IntegerAccessor> binding(&impl, GetProxy(&ptr));
|
| +
|
| + EXPECT_EQ(0u, ptr.version());
|
| +
|
| + auto callback = [](uint32_t version) { EXPECT_EQ(3u, version); };
|
| + ptr.QueryVersion(callback);
|
| +
|
| + PumpMessages();
|
| +
|
| + EXPECT_EQ(3u, ptr.version());
|
| +}
|
| +
|
| +TEST_F(InterfacePtrTest, RequireVersion) {
|
| + IntegerAccessorImpl impl;
|
| + sample::IntegerAccessorPtr ptr;
|
| + Binding<sample::IntegerAccessor> binding(&impl, GetProxy(&ptr));
|
| +
|
| + EXPECT_EQ(0u, ptr.version());
|
| +
|
| + ptr.RequireVersion(1u);
|
| + EXPECT_EQ(1u, ptr.version());
|
| + ptr->SetInteger(123, sample::ENUM_VALUE);
|
| + PumpMessages();
|
| + EXPECT_FALSE(ptr.encountered_error());
|
| + EXPECT_EQ(123, impl.integer());
|
| +
|
| + ptr.RequireVersion(3u);
|
| + EXPECT_EQ(3u, ptr.version());
|
| + ptr->SetInteger(456, sample::ENUM_VALUE);
|
| + PumpMessages();
|
| + EXPECT_FALSE(ptr.encountered_error());
|
| + EXPECT_EQ(456, impl.integer());
|
| +
|
| + // Require a version that is not supported by the impl side.
|
| + ptr.RequireVersion(4u);
|
| + // This value is set to the input of RequireVersion() synchronously.
|
| + EXPECT_EQ(4u, ptr.version());
|
| + ptr->SetInteger(789, sample::ENUM_VALUE);
|
| + PumpMessages();
|
| + EXPECT_TRUE(ptr.encountered_error());
|
| + // The call to SetInteger() after RequireVersion(4u) is ignored.
|
| + EXPECT_EQ(456, impl.integer());
|
| +}
|
| +
|
| class StrongMathCalculatorImpl : public math::Calculator, public ErrorHandler {
|
| public:
|
| StrongMathCalculatorImpl(ScopedMessagePipeHandle handle,
|
| @@ -421,7 +486,7 @@ TEST(StrongConnectorTest, Math) {
|
| &destroyed);
|
|
|
| math::CalculatorPtr calc;
|
| - calc.Bind(pipe.handle1.Pass());
|
| + calc.Bind(InterfacePtrInfo<math::Calculator>(pipe.handle1.Pass(), 0u));
|
|
|
| {
|
| // Suppose this is instantiated in a process that has the other end of the
|
| @@ -491,7 +556,7 @@ TEST(WeakConnectorTest, Math) {
|
| WeakMathCalculatorImpl impl(pipe.handle0.Pass(), &error_received, &destroyed);
|
|
|
| math::CalculatorPtr calc;
|
| - calc.Bind(pipe.handle1.Pass());
|
| + calc.Bind(InterfacePtrInfo<math::Calculator>(pipe.handle1.Pass(), 0u));
|
|
|
| {
|
| // Suppose this is instantiated in a process that has the other end of the
|
|
|