示例#1
0
        public void InterfaceDescriptionEquals()
        {
            AllJoyn.BusAttachment servicebus = null;
            servicebus = new AllJoyn.BusAttachment("InterfaceDescriptionTest", true);
            Assert.NotNull(servicebus);

            // create the interface one
            AllJoyn.InterfaceDescription testIntf = null;
            Assert.Equal(AllJoyn.QStatus.OK, servicebus.CreateInterface(INTERFACE_NAME, out testIntf));
            Assert.NotNull(testIntf);
            Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("ping", "s", "s", "in,out"));
            Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddSignal("chirp", "s", "chirp"));
            testIntf.Activate();

            Assert.Equal(AllJoyn.QStatus.OK, servicebus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, servicebus.Connect(AllJoynTestCommon.GetConnectSpec()));

            AllJoyn.BusObject busObject = new AllJoyn.BusObject(OBJECT_PATH, false);
            Assert.Equal(AllJoyn.QStatus.OK, busObject.AddInterface(testIntf));

            Assert.Equal(AllJoyn.QStatus.OK, servicebus.RegisterBusObject(busObject));

            Assert.Equal(AllJoyn.QStatus.OK, servicebus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.AllowReplacement |
                                                                    AllJoyn.DBus.NameFlags.DoNotQueue | AllJoyn.DBus.NameFlags.ReplaceExisting));

            AllJoyn.BusAttachment clientbus = null;
            clientbus = new AllJoyn.BusAttachment("InterfaceDescriptionTestclient", true);
            Assert.NotNull(clientbus);

            Assert.Equal(AllJoyn.QStatus.OK, clientbus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, clientbus.Connect(AllJoynTestCommon.GetConnectSpec()));

            AllJoyn.ProxyBusObject proxy = new AllJoyn.ProxyBusObject(clientbus, WELLKNOWN_NAME, OBJECT_PATH, 0);
            Assert.Equal(AllJoyn.QStatus.OK, proxy.IntrospectRemoteObject());

            AllJoyn.InterfaceDescription testIntf2 = proxy.GetInterface(INTERFACE_NAME);
            Assert.NotNull(testIntf);

            // create the interface three
            AllJoyn.InterfaceDescription testIntf3 = null;
            Assert.Equal(AllJoyn.QStatus.OK, servicebus.CreateInterface(INTERFACE_NAME + ".three", out testIntf3));
            Assert.NotNull(testIntf3);
            Assert.Equal(AllJoyn.QStatus.OK, testIntf3.AddMethod("ping", "s", "s", "in,out"));
            Assert.Equal(AllJoyn.QStatus.OK, testIntf3.AddMethod("pong", "s", "s", "in,out"));
            Assert.Equal(AllJoyn.QStatus.OK, testIntf3.AddSignal("chirp", "s", "chirp"));

            Assert.True(testIntf == testIntf2);
            Assert.True(testIntf.Equals(testIntf2));
            Assert.True(testIntf.GetHashCode() == testIntf2.GetHashCode());

            Assert.False(testIntf == testIntf3);
            Assert.False(testIntf.Equals(testIntf3));
            Assert.False(testIntf.GetHashCode() == testIntf3.GetHashCode());

            proxy.Dispose();
            busObject.Dispose();

            servicebus.Stop();
            servicebus.Join();

            clientbus.Stop();
            clientbus.Join();

            servicebus.Dispose();
            clientbus.Dispose();
        }