コード例 #1
0
		public void TestListenerRegisteredUnregistered()
		{
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.BusListener busListener = new TestBusListener(this);
			listenerRegistered = false;
			listenerUnregistered = false;
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// start the bus attachment
			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// connect to the bus
			status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			bus.UnregisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerUnregistered);

			// TODO: move these into a teardown method?
			busListener.Dispose();
			bus.Dispose();
		}
コード例 #2
0
        public void TestListenerRegisteredUnregistered()
        {
            AllJoyn.BusAttachment bus         = new AllJoyn.BusAttachment("BusListenerTest", true);
            AllJoyn.BusListener   busListener = new TestBusListener(this);
            listenerRegistered   = false;
            listenerUnregistered = false;
            AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

            // start the bus attachment
            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // connect to the bus
            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            bus.UnregisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerUnregistered);

            // TODO: move these into a teardown method?
            busListener.Dispose();
            bus.Dispose();
        }
コード例 #3
0
        public void TestNameOwnerChanged()
        {
            // create bus attachment
            AllJoyn.BusAttachment bus    = new AllJoyn.BusAttachment("BusListenerTest", true);
            AllJoyn.QStatus       status = AllJoyn.QStatus.FAIL;

            // start the bus attachment
            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // connect to the bus
            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            listenerRegistered = false;
            nameOwnerChanged   = false;

            // register the bus listener
            AllJoyn.BusListener busListener = new TestBusListener(this);
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            // test name owner changed
            status = bus.RequestName(ObjectName, 0);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Wait(MaxWaitTime);
            Assert.Equal(true, nameOwnerChanged);

            busListener.Dispose();
            bus.Dispose();
        }
コード例 #4
0
        public void TestFoundNameByTransport()
        {
            // create bus attachment
            AllJoyn.BusAttachment bus    = new AllJoyn.BusAttachment("BusListenerTest", true);
            AllJoyn.QStatus       status = AllJoyn.QStatus.FAIL;

            // start the bus attachment
            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // connect to the bus
            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            listenerRegistered  = false;
            foundAdvertisedName = false;
            nameOwnerChanged    = false;
            transportFound      = AllJoyn.TransportMask.None;

            // register the bus listener
            AllJoyn.BusListener busListener = new TestBusListener(this);
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
                AllJoyn.SessionOpts.TrafficType.Messages, false,
                AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            // advertise the name, & see if we find it
            status = bus.FindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, foundAdvertisedName);
            Assert.Equal(AllJoyn.TransportMask.Local, transportFound);

            status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = bus.CancelFindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            foundAdvertisedName = false;
            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(TimeSpan.FromSeconds(1));
            Assert.Equal(false, foundAdvertisedName);

            busListener.Dispose();
            bus.Dispose();
        }
コード例 #5
0
        public void TestFoundLostAdvertisedName()
        {
            // create bus attachment
            AllJoyn.BusAttachment bus    = new AllJoyn.BusAttachment("BusListenerTest", true);
            AllJoyn.QStatus       status = AllJoyn.QStatus.FAIL;

            // start the bus attachment
            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // connect to the bus
            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            listenerRegistered  = false;
            foundAdvertisedName = false;
            lostAdvertisedName  = false;

            // register the bus listener
            AllJoyn.BusListener busListener = new TestBusListener(this);
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            // advertise the name, & see if we find it
            status = bus.FindAdvertisedName(ObjectName);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
                AllJoyn.SessionOpts.TrafficType.Messages, false,
                AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, foundAdvertisedName);

            // stop advertising the name, & see if we lose it
            status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, lostAdvertisedName);

            // TODO: move these into a teardown method?
            busListener.Dispose();
            bus.Dispose();
        }
コード例 #6
0
        public void TestStopDisconnected()
        {
            // create bus attachment
            AllJoyn.BusAttachment bus    = new AllJoyn.BusAttachment("BusListenerTest", true);
            AllJoyn.QStatus       status = AllJoyn.QStatus.FAIL;

            // start the bus attachment
            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // connect to the bus
            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            listenerRegistered = false;
            busDisconnected    = false;
            busStopping        = false;

            // register the bus listener
            AllJoyn.BusListener busListener = new TestBusListener(this);
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            // test disconnecting from the bus
            status = bus.Disconnect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Wait(MaxWaitTime);
            Assert.Equal(true, busDisconnected);

            // test stopping the bus
            status = bus.Stop();
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Wait(MaxWaitTime);
            Assert.Equal(true, busStopping);

            busListener.Dispose();
            bus.Dispose();
        }
コード例 #7
0
		public void Properties()
		{
			//SetUp Service
			//start service BusAttachment
			AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			TestBusListener testBusListener = new TestBusListener(this);
			serviceBus.RegisterBusListener(testBusListener);

			//Create and activate the service Interface
			AllJoyn.InterfaceDescription testIntf = null;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
			Assert.NotNull(testIntf);
			Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
			testIntf.Activate();

			//create and register BusObject
			MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);
			busObj.AddInterface(testIntf);
			AllJoyn.InterfaceDescription.Member ping;
			ping = testIntf.GetMember("ping");
			Assert.NotNull(ping);

			Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

			_nameOwnerChangedFlag = false;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
																					AllJoyn.DBus.NameFlags.DoNotQueue |
																					AllJoyn.DBus.NameFlags.AllowReplacement));
			Wait(TimeSpan.FromSeconds(2));

			Assert.True(_nameOwnerChangedFlag);


			// SetUp Client
			// start client BusAttachment
			AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, INTERFACE_NAME, OBJECT_PATH, 0);

			Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

			AllJoyn.Message reply = new AllJoyn.Message(clientBus);
			AllJoyn.MsgArg input = new AllJoyn.MsgArg("s", "AllJoyn");

			proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

			// Actual tests for GetArg/GetArgs
			// check the message properties
			Assert.False(reply.IsBroadcastSignal);
			Assert.False(reply.IsGlobalBroadcast);
			Assert.False(reply.IsSessionless);
			Assert.False(reply.IsExpired());
			uint timeLeft;
			reply.IsExpired(out timeLeft);
			Assert.True(timeLeft > 0);
			Assert.False(reply.IsUnreliable);
			Assert.False(reply.IsEncrypted);
			// we don't expect any flags
			Assert.Equal((byte)0, reply.Flags);
			// no security is being used so there should be no security mechanism
			Assert.Equal("", reply.AuthMechanism);
			Assert.Equal(AllJoyn.Message.Type.MethodReturn, reply.MessageType);
			// The serial is unknown before hand but it should not be zero
			Assert.NotEqual<uint>(0u, reply.CallSerial);
			Assert.NotEqual<uint>(0u, reply.ReplySerial);
			// A method return does not have an Object Path
			Assert.Equal("", reply.ObjectPath);
			// A method return does not have an interface specified
			Assert.Equal("", reply.Interface);
			// The member name is not specified on a message return
			Assert.Equal("", reply.MemberName);
			// TODO possible error the documentation for Sender states it should
			// be returning the well-known name however in this case it is
			// returning the unique name of the sender.
			Assert.Equal(serviceBus.UniqueName, reply.Sender);
			Assert.Equal(clientBus.UniqueName, reply.ReceiveEndPointName);
			Assert.Equal(clientBus.UniqueName, reply.Destination);
			Assert.Equal(0u, reply.CompressionToken);
			// no session set up for this test Session Id should be 0
			Assert.Equal(0u, reply.SessionId);
			String errorMsg;
			// TODO produce test that generates actual error Message
			Assert.Null(reply.GetErrorName(out errorMsg));
			Assert.Equal("", errorMsg);
			// The  ToString method only returns a string when running debug code
#if DEBUG
			Assert.True(reply.ToString().StartsWith("<message endianness="));
			Assert.True(reply.ToString().Contains("<header field=\"REPLY_SERIAL\">"));
			Assert.True(reply.ToString().Contains("<header field=\"DESTINATION\">"));
			Assert.True(reply.ToString().Contains("<header field=\"SENDER\">"));
			Assert.True(reply.ToString().Contains("<header field=\"SIGNATURE\">"));
			Assert.True(reply.ToString().Contains("<signature>s</signature>"));
			Assert.True(reply.ToString().Contains("<string>AllJoyn</string>"));
			Assert.True(reply.ToString().EndsWith("</message>"));

			// this call to description should return 'METHID_RET[<reply serial>](s)'
			Assert.True(reply.Description.StartsWith("METHOD_RET["));
#else
			Assert.Equal("", reply.ToString());
			Assert.Equal("", reply.Description);
#endif
			// TODO figure out a good way to test the TimeStamp property
			//reply.TimeStamp

			// CleanUp
			serviceBus.UnregisterBusListener(testBusListener);
			reply.Dispose();
			input.Dispose();
			proxyObj.Dispose();
			clientBus.Dispose();

			testBusListener.Dispose();
			busObj.Dispose();
			serviceBus.Dispose();
		}
コード例 #8
0
		public void GetArgs()
		{
			//SetUp Service
			//start service BusAttachment
			AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			TestBusListener testBusListener = new TestBusListener(this);
			serviceBus.RegisterBusListener(testBusListener);

			//Create and activate the service Interface
			AllJoyn.InterfaceDescription testIntf = null;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
			Assert.NotNull(testIntf);
			Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
			testIntf.Activate();

			//create and register BusObject
			MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);
			busObj.AddInterface(testIntf);
			AllJoyn.InterfaceDescription.Member ping;
			ping = testIntf.GetMember("ping");
			Assert.NotNull(ping);

			Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

			_nameOwnerChangedFlag = false;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
																					AllJoyn.DBus.NameFlags.DoNotQueue |
																					AllJoyn.DBus.NameFlags.AllowReplacement));
			Wait(TimeSpan.FromSeconds(2));
			Assert.True(_nameOwnerChangedFlag);


			//SetUp Client
			//start client BusAttachment
			AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, WELLKNOWN_NAME, OBJECT_PATH, 0);

			Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

			AllJoyn.Message reply = new AllJoyn.Message(clientBus);
			AllJoyn.MsgArg input = new AllJoyn.MsgArg("s", "AllJoyn");

			proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

			//Actual tests for GetArg/GetArgs
			// call using GetArg specifying the array index
			Assert.Equal("AllJoyn", (string)reply.GetArg(0));
			// use the this[] operator call to get the MsgArg
			Assert.Equal("AllJoyn", (string)(reply[0]));
			// Return the MsgArgs note could be multiple values
			AllJoyn.MsgArg replyArg = reply.GetArgs();
			Assert.Equal(1, replyArg.Length);
			Assert.Equal("AllJoyn", (string)replyArg);
			// Parse the Message Drectly
			object replyString;
			Assert.Equal(AllJoyn.QStatus.OK, reply.GetArgs("s", out replyString));
			Assert.Equal("AllJoyn", (string)replyString);

			serviceBus.UnregisterBusListener(testBusListener);
			reply.Dispose();
			input.Dispose();
			proxyObj.Dispose();
			clientBus.Dispose();

			testBusListener.Dispose();
			busObj.Dispose();
			serviceBus.Dispose();
		}
コード例 #9
0
        public void Properties()
        {
            //SetUp Service
            //start service BusAttachment
            AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            TestBusListener testBusListener = new TestBusListener(this);

            serviceBus.RegisterBusListener(testBusListener);

            //Create and activate the service Interface
            AllJoyn.InterfaceDescription testIntf = null;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
            Assert.NotNull(testIntf);
            Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
            testIntf.Activate();

            //create and register BusObject
            MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);

            busObj.AddInterface(testIntf);
            AllJoyn.InterfaceDescription.Member ping;
            ping = testIntf.GetMember("ping");
            Assert.NotNull(ping);

            Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

            _nameOwnerChangedFlag = false;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
                                                                    AllJoyn.DBus.NameFlags.DoNotQueue |
                                                                    AllJoyn.DBus.NameFlags.AllowReplacement));
            Wait(TimeSpan.FromSeconds(2));

            Assert.True(_nameOwnerChangedFlag);


            // SetUp Client
            // start client BusAttachment
            AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, INTERFACE_NAME, OBJECT_PATH, 0);

            Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

            AllJoyn.Message reply = new AllJoyn.Message(clientBus);
            AllJoyn.MsgArg  input = new AllJoyn.MsgArg("s", "AllJoyn");

            proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

            // Actual tests for GetArg/GetArgs
            // check the message properties
            Assert.False(reply.IsBroadcastSignal);
            Assert.False(reply.IsGlobalBroadcast);
            Assert.False(reply.IsSessionless);
            Assert.False(reply.IsExpired());
            uint timeLeft;

            reply.IsExpired(out timeLeft);
            Assert.True(timeLeft > 0);
            Assert.False(reply.IsUnreliable);
            Assert.False(reply.IsEncrypted);
            // we don't expect any flags
            Assert.Equal((byte)0, reply.Flags);
            // no security is being used so there should be no security mechanism
            Assert.Equal("", reply.AuthMechanism);
            Assert.Equal(AllJoyn.Message.Type.MethodReturn, reply.MessageType);
            // The serial is unknown before hand but it should not be zero
            Assert.NotEqual <uint>(0u, reply.CallSerial);
            Assert.NotEqual <uint>(0u, reply.ReplySerial);
            // A method return does not have an Object Path
            Assert.Equal("", reply.ObjectPath);
            // A method return does not have an interface specified
            Assert.Equal("", reply.Interface);
            // The member name is not specified on a message return
            Assert.Equal("", reply.MemberName);
            // TODO possible error the documentation for Sender states it should
            // be returning the well-known name however in this case it is
            // returning the unique name of the sender.
            Assert.Equal(serviceBus.UniqueName, reply.Sender);
            Assert.Equal(clientBus.UniqueName, reply.ReceiveEndPointName);
            Assert.Equal(clientBus.UniqueName, reply.Destination);
            Assert.Equal(0u, reply.CompressionToken);
            // no session set up for this test Session Id should be 0
            Assert.Equal(0u, reply.SessionId);
            String errorMsg;

            // TODO produce test that generates actual error Message
            Assert.Null(reply.GetErrorName(out errorMsg));
            Assert.Equal("", errorMsg);
            // The  ToString method only returns a string when running debug code
#if DEBUG
            Assert.True(reply.ToString().StartsWith("<message endianness="));
            Assert.True(reply.ToString().Contains("<header field=\"REPLY_SERIAL\">"));
            Assert.True(reply.ToString().Contains("<header field=\"DESTINATION\">"));
            Assert.True(reply.ToString().Contains("<header field=\"SENDER\">"));
            Assert.True(reply.ToString().Contains("<header field=\"SIGNATURE\">"));
            Assert.True(reply.ToString().Contains("<signature>s</signature>"));
            Assert.True(reply.ToString().Contains("<string>AllJoyn</string>"));
            Assert.True(reply.ToString().EndsWith("</message>"));

            // this call to description should return 'METHID_RET[<reply serial>](s)'
            Assert.True(reply.Description.StartsWith("METHOD_RET["));
#else
            Assert.Equal("", reply.ToString());
            Assert.Equal("", reply.Description);
#endif
            // TODO figure out a good way to test the TimeStamp property
            //reply.TimeStamp

            // CleanUp
            serviceBus.UnregisterBusListener(testBusListener);
            reply.Dispose();
            input.Dispose();
            proxyObj.Dispose();
            clientBus.Dispose();

            testBusListener.Dispose();
            busObj.Dispose();
            serviceBus.Dispose();
        }
コード例 #10
0
        public void GetArgs()
        {
            //SetUp Service
            //start service BusAttachment
            AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            TestBusListener testBusListener = new TestBusListener(this);

            serviceBus.RegisterBusListener(testBusListener);

            //Create and activate the service Interface
            AllJoyn.InterfaceDescription testIntf = null;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
            Assert.NotNull(testIntf);
            Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
            testIntf.Activate();

            //create and register BusObject
            MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);

            busObj.AddInterface(testIntf);
            AllJoyn.InterfaceDescription.Member ping;
            ping = testIntf.GetMember("ping");
            Assert.NotNull(ping);

            Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

            _nameOwnerChangedFlag = false;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
                                                                    AllJoyn.DBus.NameFlags.DoNotQueue |
                                                                    AllJoyn.DBus.NameFlags.AllowReplacement));
            Wait(TimeSpan.FromSeconds(2));
            Assert.True(_nameOwnerChangedFlag);


            //SetUp Client
            //start client BusAttachment
            AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, WELLKNOWN_NAME, OBJECT_PATH, 0);

            Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

            AllJoyn.Message reply = new AllJoyn.Message(clientBus);
            AllJoyn.MsgArg  input = new AllJoyn.MsgArg("s", "AllJoyn");

            proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

            //Actual tests for GetArg/GetArgs
            // call using GetArg specifying the array index
            Assert.Equal("AllJoyn", (string)reply.GetArg(0));
            // use the this[] operator call to get the MsgArg
            Assert.Equal("AllJoyn", (string)(reply[0]));
            // Return the MsgArgs note could be multiple values
            AllJoyn.MsgArg replyArg = reply.GetArgs();
            Assert.Equal(1, replyArg.Length);
            Assert.Equal("AllJoyn", (string)replyArg);
            // Parse the Message Drectly
            object replyString;

            Assert.Equal(AllJoyn.QStatus.OK, reply.GetArgs("s", out replyString));
            Assert.Equal("AllJoyn", (string)replyString);

            serviceBus.UnregisterBusListener(testBusListener);
            reply.Dispose();
            input.Dispose();
            proxyObj.Dispose();
            clientBus.Dispose();

            testBusListener.Dispose();
            busObj.Dispose();
            serviceBus.Dispose();
        }
コード例 #11
0
		public void TestFoundLostAdvertisedName()
		{
			// create bus attachment
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// start the bus attachment
			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// connect to the bus
			status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			listenerRegistered = false;
			foundAdvertisedName = false;
			lostAdvertisedName = false;

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			// advertise the name, & see if we find it
			status = bus.FindAdvertisedName(ObjectName);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, false,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

			status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedName);

			// stop advertising the name, & see if we lose it
			status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(MaxWaitTime);
			Assert.Equal(true, lostAdvertisedName);

			// TODO: move these into a teardown method?
			busListener.Dispose();
			bus.Dispose();
		}
コード例 #12
0
		public void TestFoundNameByTransport()
		{
			// create bus attachment
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// start the bus attachment
			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// connect to the bus
			status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			listenerRegistered = false;
			foundAdvertisedName = false;
			nameOwnerChanged = false;
			transportFound = AllJoyn.TransportMask.None;

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, false,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

			// advertise the name, & see if we find it
			status = bus.FindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedName);
			Assert.Equal(AllJoyn.TransportMask.Local, transportFound);

			status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = bus.CancelFindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			foundAdvertisedName = false;
			status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(TimeSpan.FromSeconds(1));
			Assert.Equal(false, foundAdvertisedName);

			busListener.Dispose();
			bus.Dispose();
		}
コード例 #13
0
		public void TestNameOwnerChanged()
		{
			// create bus attachment
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// start the bus attachment
			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// connect to the bus
			status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			listenerRegistered = false;
			nameOwnerChanged = false;

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			// test name owner changed
			status = bus.RequestName(ObjectName, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Wait(MaxWaitTime);
			Assert.Equal(true, nameOwnerChanged);

			busListener.Dispose();
			bus.Dispose();
		}
コード例 #14
0
		public void TestStopDisconnected()
		{
			// create bus attachment
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// start the bus attachment
			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// connect to the bus
			status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			listenerRegistered = false;
			busDisconnected = false;
			busStopping = false;

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			// test disconnecting from the bus
			status = bus.Disconnect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Wait(MaxWaitTime);
			Assert.Equal(true, busDisconnected);

			// test stopping the bus
			status = bus.Stop();
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Wait(MaxWaitTime);
			Assert.Equal(true, busStopping);

			busListener.Dispose();
			bus.Dispose();
		}