Beispiel #1
0
        public void AllJoynStructs()
        {
            TestStruct testStruct = new TestStruct();
            testStruct.a = 42;
            testStruct.b = "Hello";
            testStruct.c = "World";
            testStruct.d = 88;

            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            object[] mystruct = new object[4];
            mystruct[0] = testStruct.a;
            mystruct[1] = testStruct.b;
            mystruct[2] = testStruct.c;
            mystruct[3] = testStruct.d;
            AllJoyn.QStatus status = arg.Set("(issi)", mystruct);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            object outstruct;
            status = arg.Get("(issi)", out outstruct);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            object[] outstructa = (object[])outstruct;
            Assert.Equal(4, outstructa.Length);
            Assert.Equal(testStruct.a, (int)outstructa[0]);
            Assert.Equal(testStruct.b, (string)outstructa[1]);
            Assert.Equal(testStruct.c, (string)outstructa[2]);
            Assert.Equal(testStruct.d, (int)outstructa[3]);
            arg.Dispose();
            arg = new AllJoyn.MsgArg();

            //struct within a struct
            object[] mystruct2 = new object[2];
            mystruct2[0] = "bob";
            mystruct2[1] = mystruct;
            status = arg.Set("(s(issi))", mystruct2);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = arg.Get("(s(issi))", out outstruct);
            object[] outstruct1 = (object[])outstruct;
            Assert.Equal(2, outstruct1.Length);
            object[] outstruct2 = (object[])outstruct1[1];
            Assert.Equal(4, outstruct2.Length);

            Assert.Equal("bob", (string)outstruct1[0]);
            Assert.Equal(testStruct.a, (int)outstruct2[0]);
            Assert.Equal(testStruct.b, (string)outstruct2[1]);
            Assert.Equal(testStruct.c, (string)outstruct2[2]);
            Assert.Equal(testStruct.d, (int)outstruct2[3]);
        }
Beispiel #2
0
        public void BasicArraySetGet()
        {
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();

            //byte
            byte[] in_byte_array = { 9, 19, 29, 39, 49 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("ay", in_byte_array));
            object ay;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("ay", out ay));
            byte[] out_byte_array = (byte[])ay;
            Assert.Equal(in_byte_array.Length, out_byte_array.Length);
            for (int i = 0; i < out_byte_array.Length; i++)
            {
                Assert.Equal(in_byte_array[i], out_byte_array[i]);
            }

            //bool
            bool[] in_bool_array = { false, false, true, true, false, true };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("ab", in_bool_array));
            object ab;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("ab", out ab));
            bool[] out_bool_array = (bool[])ab;
            Assert.Equal(in_bool_array.Length, out_bool_array.Length);
            for (int i = 0; i < out_bool_array.Length; i++)
            {
                Assert.Equal(in_bool_array[i], out_bool_array[i]);
            }

            //short
            short[] in_short_array = { -9, -99, 999, 9999 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("an", in_short_array));
            object an;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("an", out an));
            short[] out_short_array = (short[])an;
            Assert.Equal(in_short_array.Length, out_short_array.Length);
            for (int i = 0; i < out_short_array.Length; i++)
            {
                Assert.Equal(in_short_array[i], out_short_array[i]);
            }

            //ushort
            ushort[] in_ushort_array = { 9, 99, 999, 9999 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("aq", in_ushort_array));
            object aq;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("aq", out aq));
            ushort[] out_ushort_array = (ushort[])aq;
            Assert.Equal(in_ushort_array.Length, out_ushort_array.Length);
            for (int i = 0; i < out_short_array.Length; i++)
            {
                Assert.Equal(in_ushort_array[i], out_ushort_array[i]);
            }

            //int
            int[] in_int_array = { -8, -88, 888, 8888 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("ai", in_int_array));
            object ai;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("ai", out ai));
            int[] out_int_array = (int[])ai;
            Assert.Equal(in_int_array.Length, out_int_array.Length);
            for (int i = 0; i < out_int_array.Length; i++)
            {
                Assert.Equal(in_int_array[i], out_int_array[i]);
            }

            //uint
            uint[] in_uint_array = { 8, 88, 888, 8888 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("au", in_uint_array));
            object au;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("au", out au));
            uint[] out_uint_array = (uint[])au;
            Assert.Equal(in_uint_array.Length, out_uint_array.Length);
            for (int i = 0; i < out_int_array.Length; i++)
            {
                Assert.Equal(in_uint_array[i], out_uint_array[i]);
            }

            //long
            long[] in_long_array = { -7, -77, 777, 7777 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("ax", in_long_array));
            object ax;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("ax", out ax));
            long[] out_long_array = (long[])ax;
            Assert.Equal(in_long_array.Length, out_long_array.Length);
            for (int i = 0; i < out_long_array.Length; i++)
            {
                Assert.Equal(in_long_array[i], out_long_array[i]);
            }

            //ulong
            ulong[] in_ulong_array = { 7, 77, 777, 7777 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("at", in_ulong_array));
            object at;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("at", out at));
            ulong[] out_ulong_array = (ulong[])at;
            Assert.Equal(in_ulong_array.Length, out_ulong_array.Length);
            for (int i = 0; i < out_long_array.Length; i++)
            {
                Assert.Equal(in_ulong_array[i], out_ulong_array[i]);
            }

            //double
            double[] in_double_array = { 0.001, 0.01, 0.1, 1.0, 10.0, 100.0 };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("ad", in_double_array));
            object ad;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("ad", out ad));
            double[] out_double_array = (double[])ad;
            Assert.Equal(in_double_array.Length, out_double_array.Length);
            for (int i = 0; i < out_long_array.Length; i++)
            {
                Assert.Equal(in_double_array[i], out_double_array[i]);
            }

            //string
            string[] in_string_array = { "one", "two", "three", "four" };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("as", in_string_array));
            object sa;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("as", out sa));
            string[] out_string_array = (string[])sa;
            Assert.Equal(in_string_array.Length, out_string_array.Length);
            for (int i = 0; i < out_string_array.Length; i++)
            {
                Assert.Equal(in_string_array[i], out_string_array[i]);
            }

            //object path
            string[] in_path_array = { "/org/one", "/org/two", "/org/three", "/org/four" };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("ao", in_path_array));
            object ao;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("ao", out ao));
            string[] out_path_array = (string[])ao;
            Assert.Equal(in_path_array.Length, out_path_array.Length);
            for (int i = 0; i < out_path_array.Length; i++)
            {
                Assert.Equal(in_path_array[i], out_path_array[i]);
            }

            //signature
            string[] in_signature_array = { "s", "sss", "as", "a(iiiiuu)" };
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("ag", in_signature_array));
            object sg;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("ag", out sg));
            string[] out_signature_array = (string[])sg;
            Assert.Equal(in_signature_array.Length, out_signature_array.Length);
            for (int i = 0; i < out_signature_array.Length; i++)
            {
                Assert.Equal(in_signature_array[i], out_signature_array[i]);
            }
        }
Beispiel #3
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();
		}
		public void srp_keyx2()
		{
			ResetAuthFlags();
			clientBus.ClearKeyStore();

			SrpKeyx2_service_authlistener serviceAuthlistener = new SrpKeyx2_service_authlistener(this);
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.EnablePeerSecurity("ALLJOYN_SRP_KEYX", serviceAuthlistener, null, false));

			serviceBus.ClearKeyStore();

			Assert.Equal(AllJoyn.QStatus.OK, SetUpAuthService());

			SrpKeyx2_client_authlistener clientAuthlistener = new SrpKeyx2_client_authlistener(this);
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.EnablePeerSecurity("ALLJOYN_SRP_KEYX", clientAuthlistener, null, false));
			clientBus.ClearKeyStore();

			// create+activate the interface
			AllJoyn.QStatus status;
			AllJoyn.InterfaceDescription iFace = null;
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.CreateInterface(INTERFACE_NAME, AllJoyn.InterfaceDescription.SecurityPolicy.Required, out iFace));
			Assert.NotNull(iFace);

			Assert.Equal(AllJoyn.QStatus.OK, iFace.AddMethod("ping", "s", "s", "in,out"));
			iFace.Activate();

			AllJoyn.ProxyBusObject proxyBusObject = new AllJoyn.ProxyBusObject(clientBus, WELLKNOWN_NAME, OBJECT_PATH, 0);
			Assert.NotNull(proxyBusObject);
			Assert.Equal(AllJoyn.QStatus.OK, proxyBusObject.AddInterface(iFace));

			AllJoyn.MsgArg input = new AllJoyn.MsgArg("s", "AllJoyn");
			AllJoyn.Message replyMsg = new AllJoyn.Message(clientBus);
			status = proxyBusObject.MethodCall(INTERFACE_NAME, "ping", input, replyMsg, 5000, 0);
			Assert.Equal(AllJoyn.QStatus.BUS_REPLY_IS_ERROR_MESSAGE, status);

			Assert.True(authflags.requestCreds_service);
			Assert.True(authflags.authComplete_serivce);

			Assert.True(authflags.authComplete_client);
			// Authentication complete can occure before the SecurityViolation callback
			// with authentication complete the MethodCall will return the BUS_REPLY_IS_ERROR_MESSAGE
			// and the code could check for the sercurityViolation_client before it is actually set
			// for this reason we need to wait for the flag to be set.
			Wait(TimeSpan.FromSeconds(5));
			Assert.True(authflags.securityViolation_client);
			clientAuthlistener.Dispose();
			serviceAuthlistener.Dispose();

			busObject.Dispose();

			proxyBusObject.Dispose();


			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Stop());
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Join());

			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Stop());
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Join());

			serviceBus.Dispose();
			clientBus.Dispose();
		}
		public AllJoyn.QStatus SetUpAuthClient()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;
			AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, WELLKNOWN_NAME, OBJECT_PATH, 0);

			status = proxyObj.IntrospectRemoteObject();
			if (!status)
			{
				return status;
			}

			AllJoyn.Message reply = new AllJoyn.Message(clientBus);
			AllJoyn.MsgArg input = new AllJoyn.MsgArg("s", "AllJoyn");
			Console.WriteLine(proxyObj.GetInterface(INTERFACE_NAME).Introspect());

			status = proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 5000, 0);
			if (!status)
			{
				return status;
			}

			if ((string)reply[0] != "AllJoyn")
			{
				Console.WriteLine((string)reply[0] + " != \"AllJoyn\" as expected");
				return AllJoyn.QStatus.FAIL;
			}
			return status;
		}
Beispiel #6
0
            protected void Cat(AllJoyn.InterfaceDescription.Member member, AllJoyn.Message message)
            {
                string outStr = (string)message[0] + (string)message[1];
                AllJoyn.MsgArg outArgs = new AllJoyn.MsgArg();
                outArgs = outStr;

                AllJoyn.QStatus status = MethodReply(message, outArgs);
                if(!status)
                {
                    Console.WriteLine("Server Ping: Error sending reply");
                }
            }
Beispiel #7
0
        public string CallRemoteMethod()
        {
            using(AllJoyn.ProxyBusObject remoteObj = new AllJoyn.ProxyBusObject(sMsgBus, SERVICE_NAME, SERVICE_PATH, sSessionId))
            {
                AllJoyn.InterfaceDescription alljoynTestIntf = sMsgBus.GetInterface(INTERFACE_NAME);
                if(alljoynTestIntf == null)
                {
                    throw new Exception("Client Failed to get test interface.");
                }
                remoteObj.AddInterface(alljoynTestIntf);

                AllJoyn.Message reply = new AllJoyn.Message(sMsgBus);
                AllJoyn.MsgArg inputs = new AllJoyn.MsgArg(2);
                inputs[0] = "Hello ";
                inputs[1] = "World!";

                AllJoyn.QStatus status = remoteObj.MethodCall(SERVICE_NAME, "cat", inputs, reply, 5000, 0);

                if(status)
                {
                    Console.WriteLine("{0}.{1} (path={2}) returned \"{3}\"", SERVICE_NAME, "cat", SERVICE_PATH,
                        (string)reply[0]);
                    return (string)reply[0];
                }
                else
                {
                    Console.WriteLine("MethodCall on {0}.{1} failed", SERVICE_NAME, "cat");
                    return "";
                }
            }
        }
		public void DBusProxyObj()
		{
			Assert.Equal(AllJoyn.QStatus.OK, busAttachment.Start());
			Assert.Equal(AllJoyn.QStatus.OK, busAttachment.Connect());

			AllJoyn.ProxyBusObject dbusBusObj = busAttachment.DBusProxyObj;

			String wellKnownName = "org.alljoyn.test.BusAttachment";
			AllJoyn.MsgArg msgArg = new AllJoyn.MsgArg(2);
			msgArg[0] = wellKnownName;
			msgArg[1] = (uint)(AllJoyn.DBus.NameFlags.AllowReplacement | AllJoyn.DBus.NameFlags.DoNotQueue | AllJoyn.DBus.NameFlags.ReplaceExisting);

			AllJoyn.Message replyMsg = new AllJoyn.Message(busAttachment);

			Assert.Equal(AllJoyn.QStatus.OK, dbusBusObj.MethodCall("org.freedesktop.DBus", "RequestName", msgArg, replyMsg, 5000, 0));
			// TODO this keeps returning 4 which is DBUS_REQUEST_NAME_REPLY_EXISTS when it should return 1 DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
			// unknown if this is an error only in Unity or in core code.  I suspect this issue is also in alljoyn_core code.

			AllJoyn.MsgArg nho_msgArg = new AllJoyn.MsgArg();
			nho_msgArg = wellKnownName;
			Assert.Equal(AllJoyn.QStatus.OK, dbusBusObj.MethodCall("org.freedesktop.DBus", "NameHasOwner", nho_msgArg, replyMsg, 5000, 0));
			Assert.True((bool)replyMsg[0]);

			Assert.Equal(AllJoyn.QStatus.OK, dbusBusObj.MethodCall("org.freedesktop.DBus", "ListNames", AllJoyn.MsgArg.Zero, replyMsg, 5000, 0));
			string[] sa = (string[])replyMsg[0];
			//the wellknown Name should be found in the list of strings returned.
			Assert.True(Array.IndexOf(sa, wellKnownName) > -1);
		}
Beispiel #9
0
        public void ArrayOfStruct()
        {
            AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;
            object[][] sii = new object[][]
                            {
                                new object[] {1, 2},
                                new object[] {11, 22},
                                new object[] {111, 222}
                            };

            //signature a(ii);
            AllJoyn.MsgArg structs = new AllJoyn.MsgArg(3);
            status = structs[0].Set("(ii)", sii[0]);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = structs[1].Set("(ii)", sii[1]);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = structs[2].Set("(ii)", sii[2]);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Assert.Equal("(ii)", structs[0].Signature);

            AllJoyn.MsgArg struct_array = new AllJoyn.MsgArg();
            status = struct_array.Set("a(ii)", structs);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal("a(ii)", struct_array.Signature);

            object out_struct_array;
            status = struct_array.Get("a(ii)", out out_struct_array);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            AllJoyn.MsgArg ret_value = (AllJoyn.MsgArg)out_struct_array;
            Assert.Equal(3, ret_value.Length);
            object rii;
            status = ret_value[0].Get("(ii)", out rii);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal(2, ((object[])rii).Length);
            Assert.Equal(1, (int)((object[])rii)[0]);
            Assert.Equal(2, (int)((object[])rii)[1]);
            status = ret_value[1].Get("(ii)", out rii);
            Assert.Equal(2, ((object[])rii).Length);
            Assert.Equal(11, (int)((object[])rii)[0]);
            Assert.Equal(22, (int)((object[])rii)[1]);
            status = ret_value[2].Get("(ii)", out rii);
            Assert.Equal(2, ((object[])rii).Length);
            Assert.Equal(111, (int)((object[])rii)[0]);
            Assert.Equal(222, (int)((object[])rii)[1]);
        }
Beispiel #10
0
        public void Dictionaries()
        {
            System.Collections.Generic.Dictionary<object, object> dict = new System.Collections.Generic.Dictionary<object, object>();
            dict.Add("apple", 2);
            dict.Add("pear", 1);
            dict.Add("bannana", 0);
            dict.Add("kiwi", -1);

            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            AllJoyn.QStatus status = arg.Set("a{si}", dict);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            object out_dict;
            status = arg.Get("a{si}", out out_dict);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal(dict, (System.Collections.Generic.Dictionary<object, object>)out_dict);
        }
Beispiel #11
0
 public void Clear()
 {
     AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
     arg = "Bat Man";
     Assert.Equal(AllJoyn.MsgArg.AllJoynTypeId.ALLJOYN_STRING, arg.TypeId);
     arg.Clear();
     Assert.Equal(AllJoyn.MsgArg.AllJoynTypeId.ALLJOYN_INVALID, arg.TypeId);
 }
Beispiel #12
0
        public void BasicSet()
        {
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((byte)13));
            Assert.Equal((byte)13, (byte)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set(true));
            Assert.True((bool)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((short)42));
            Assert.Equal((short)42, (short)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((ushort)0xBEBE));
            Assert.Equal((ushort)0xBEBE, (ushort)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((int)-9999));
            Assert.Equal((int)-9999, (int)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((uint)0x32323232));
            Assert.Equal((uint)0x32323232, (uint)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((long)-1));
            Assert.Equal((long)-1, (long)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((ulong)0x6464646464646464));
            Assert.Equal((ulong)0x6464646464646464, (ulong)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((float)1.61803f));
            Assert.Equal((float)1.61803f, (float)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((double)3.14159265D));
            Assert.Equal((double)3.14159265D, (double)arg);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((string)"this is a string"));
            Assert.Equal("this is a string", (string)arg);

            AllJoyn.MsgArg arg10 = new AllJoyn.MsgArg(10);
            arg10[0].Set((byte)5);
            arg10[1].Set(true);
            arg10[2].Set((short)42);
            arg10[3].Set((ushort)45);
            arg10[4].Set((int)99);
            arg10[5].Set((uint)499);
            arg10[6].Set((long)566);
            arg10[7].Set((ulong)789301);
            arg10[8].Set((double)2.7275);
            arg10[9].Set((string)"I say Hello");

            Assert.Equal((byte)5, (byte)arg10[0]);
            Assert.Equal(true, (bool)arg10[1]);
            Assert.Equal((short)42, (short)arg10[2]);
            Assert.Equal((ushort)45, (ushort)arg10[3]);
            Assert.Equal((int)99, (int)arg10[4]);
            Assert.Equal((uint)499, (uint)arg10[5]);
            Assert.Equal((long)566, (long)arg10[6]);
            Assert.Equal((ulong)789301, (ulong)arg10[7]);
            Assert.Equal((double)2.7275, (double)arg10[8]);
            Assert.Equal((string)"I say Hello", (string)arg10[9]);

            //older test code to be thrown removed
            AllJoyn.MsgArg argfoo = new AllJoyn.MsgArg();
            argfoo.Set(-9999);
            Assert.Equal((int)-9999, (int)argfoo);

            AllJoyn.MsgArg args = new AllJoyn.MsgArg(10);
            for (int i = 0; i < 10; ++i)
            {
                args[i].Set(i * 3);
            }

            for (int i = 0; i < 10; ++i)
            {
                Assert.Equal((int)i * 3, (int)args[i]);
            }
        }
Beispiel #13
0
        public void BasicGetBasicTypes()
        {
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((byte)13));
            byte y;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out y));
            Assert.Equal((byte)13, y);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set(true));
            bool b;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out b));
            Assert.True(b);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((short)42));
            short n;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out n));
            Assert.Equal((short)42, n);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((ushort)0xBEBE));
            ushort q;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out q));
            Assert.Equal((ushort)0xBEBE, q);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((int)-9999));
            int i;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out i));
            Assert.Equal((int)-9999, i);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((uint)0x32323232));
            uint u;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out u));
            Assert.Equal((uint)0x32323232, u);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((long)-1));
            long x;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out x));
            Assert.Equal((long)-1, x);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((ulong)0x6464646464646464));
            ulong t;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out t));
            Assert.Equal((ulong)0x6464646464646464, t);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((double)3.14159265D));
            double d;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out d));
            Assert.Equal((double)3.14159265D, d);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((string)"this is a string"));
            string s;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get(out s));
            Assert.Equal("this is a string", s);
        }
Beispiel #14
0
        public void BasicGet()
        {
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((byte)13));
            object y;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("y", out y));
            Assert.Equal((byte)13, (byte)y);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set(true));
            object b;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("b", out b));
            Assert.True((bool)b);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((short)42));
            object n;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("n", out n));
            Assert.Equal((short)42, (short)n);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((ushort)0xBEBE));
            object q;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("q", out q));
            Assert.Equal((ushort)0xBEBE, (ushort)q);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((int)-9999));
            object i;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("i", out i));
            Assert.Equal((int)-9999, (object)i);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((uint)0x32323232));
            object u;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("u", out u));
            Assert.Equal((uint)0x32323232, (uint)u);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((long)-1));
            object x;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("x", out x));
            Assert.Equal((long)-1, (long)x);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((ulong)0x6464646464646464));
            object t;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("t", out t));
            Assert.Equal((ulong)0x6464646464646464, (ulong)t);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((double)3.14159265D));
            object d;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("d", out d));
            Assert.Equal((double)3.14159265D, (double)d);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set((string)"this is a string"));
            object s;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("s", out s));
            Assert.Equal("this is a string", (string)s);

            // The only way to set and get object paths and signatures is to use
            // two param Get and Set methods
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("o", "/org/foo/bar"));
            object o;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("o", out o));
            Assert.Equal("/org/foo/bar", (string)o);

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("g", "a{is}d(siiux)"));
            object g;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("g", out g));
            Assert.Equal("a{is}d(siiux)", (string)g);
        }
Beispiel #15
0
        public void BasicAssignment()
        {
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            arg = (byte)42;
            Assert.Equal((byte)42, (byte)arg);
            arg = true;
            Assert.True((bool)arg);

            arg = false;
            Assert.False((bool)arg);

            arg = (short)42;
            Assert.Equal((short)42, (short)arg);

            arg = (ushort)0xBEBE;
            Assert.Equal((ushort)0xBEBE, (ushort)arg);

            arg = (int)-9999;
            Assert.Equal((int)-9999, (int)arg);

            arg = (uint)0x32323232;
            Assert.Equal((uint)0x32323232, (uint)arg);

            arg = (long)-1;
            Assert.Equal((long)-1, (long)arg);

            arg = (ulong)0x6464646464646464;
            Assert.Equal((ulong)0x6464646464646464, (ulong)arg);

            arg = (float)1.61803f;
            Assert.Equal((float)1.61803f, (float)arg);

            arg = (double)3.14159265D;
            Assert.Equal((double)3.14159265D, (double)arg);

            arg = (string)"this is a string";
            Assert.Equal("this is a string", (string)arg);

            AllJoyn.MsgArg arg10 = new AllJoyn.MsgArg(10);
            arg10[0] = (byte)5;
            arg10[1] = true;
            arg10[2] = (short)42;
            arg10[3] = (ushort)45;
            arg10[4] = (int)99;
            arg10[5] = (uint)499;
            arg10[6] = (long)566;
            arg10[7] = (ulong)789301;
            arg10[8] = (double)2.7275;
            arg10[9] = (string)"I say Hello";

            Assert.Equal((byte)5, (byte)arg10[0]);
            Assert.Equal(true, (bool)arg10[1]);
            Assert.Equal((short)42, (short)arg10[2]);
            Assert.Equal((ushort)45, (ushort)arg10[3]);
            Assert.Equal((int)99, (int)arg10[4]);
            Assert.Equal((uint)499, (uint)arg10[5]);
            Assert.Equal((long)566, (long)arg10[6]);
            Assert.Equal((ulong)789301, (ulong)arg10[7]);
            Assert.Equal((double)2.7275, (double)arg10[8]);
            Assert.Equal((string)"I say Hello", (string)arg10[9]);

            //assignment of an array
            AllJoyn.MsgArg arg3 = new AllJoyn.MsgArg(3);
            arg3[0] = (byte)5;
            arg3[1] = (byte)13;
            arg3[2] = (byte)42;

            Assert.Equal((byte)5, (byte)arg3[0]);
            Assert.Equal((byte)13, (byte)arg3[1]);
            Assert.Equal((byte)42, (byte)arg3[2]);

            //older test code to be thrown removed
            AllJoyn.MsgArg argfoo = new AllJoyn.MsgArg();
            argfoo = -9999;
            Assert.Equal((int)-9999, (int)argfoo);

            AllJoyn.MsgArg args = new AllJoyn.MsgArg(10);
            for (int i = 0; i < 10; ++i)
            {
                args[i] = i;
            }

            for (int i = 0; i < 10; ++i)
            {
                Assert.Equal((int)i, (int)args[i]);
            }
        }
			protected void Ping(AllJoyn.InterfaceDescription.Member member, AllJoyn.Message message)
			{
				string outStr = (string)message[0];
				AllJoyn.MsgArg outArgs = new AllJoyn.MsgArg();
				outArgs = outStr;

				AllJoyn.QStatus status = MethodReply(message, outArgs);
				Assert.Equal(AllJoyn.QStatus.OK, status);

//Continue testing obsolete method calls till they are removed.
#pragma warning disable 618
				AllJoyn.MsgArgs outArgs2 = new AllJoyn.MsgArgs(1);
				outArgs2[0] = outStr;

				status = MethodReply(message, outArgs2);
				Assert.Equal(AllJoyn.QStatus.OK, status);
#pragma warning restore 618
			}
		public void TestAddMethodHandler()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// create+start+connect bus attachment
			AllJoyn.BusAttachment servicebus = null;
			servicebus = new AllJoyn.BusAttachment("BusObjectTestService", true);
			Assert.NotNull(servicebus);

			status = servicebus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

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

			// create+activate the interface
			AllJoyn.InterfaceDescription testIntf = null;
			status = servicebus.CreateInterface(INTERFACE_NAME, out testIntf);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.NotNull(testIntf);

			status = testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out");
			Assert.Equal(AllJoyn.QStatus.OK, status);

			testIntf.Activate();

			// register bus listener
			AllJoyn.BusListener testBusListener = new TestBusListener(this);
			servicebus.RegisterBusListener(testBusListener);

			// create the bus object
			// the MethodTestBusObject constructor adds the interface & a handler for the ping method
			MethodTestBusObject methodTestBusObject = new MethodTestBusObject(servicebus, OBJECT_PATH);

			// register the bus object
			status = servicebus.RegisterBusObject(methodTestBusObject);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// request name
			nameOwnerChangedFlag = false;
			status = servicebus.RequestName(OBJECT_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Wait(MaxWaitTime);
			Assert.Equal(true, nameOwnerChangedFlag);

			///////////////////////////////////////////////////////////

			// create the proxy bus object & call methods
			AllJoyn.BusAttachment bus = null;
			bus = new AllJoyn.BusAttachment("BusObjectTest", true);
			Assert.NotNull(bus);

			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

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

			// create+activate the interface
			AllJoyn.InterfaceDescription iFace = null;
			status = bus.CreateInterface(INTERFACE_NAME, out iFace);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.NotNull(iFace);

			status = iFace.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out");
			Assert.Equal(AllJoyn.QStatus.OK, status);

			iFace.Activate();

			AllJoyn.ProxyBusObject proxyBusObject = new AllJoyn.ProxyBusObject(bus, OBJECT_NAME, OBJECT_PATH, 0);
			status = proxyBusObject.AddInterface(iFace);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			AllJoyn.MsgArg input = new AllJoyn.MsgArg();
			input.Set("AllJoyn");
			AllJoyn.Message replyMsg = new AllJoyn.Message(bus);
			status = proxyBusObject.MethodCall(INTERFACE_NAME, "ping", input, replyMsg, 5000, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.Equal("AllJoyn", (string)replyMsg[0]);

//continue testing obsolete method calls till they are removed.
#pragma warning disable 618
			AllJoyn.MsgArg input1 = new AllJoyn.MsgArg();
			input1.Set("AllJoyn");
			AllJoyn.Message replyMsg1 = new AllJoyn.Message(bus);
			status = proxyBusObject.MethodCallSynch(INTERFACE_NAME, "ping", input1, replyMsg1, 5000, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.Equal("AllJoyn", (string)replyMsg1[0]);

			AllJoyn.MsgArgs input2 = new AllJoyn.MsgArgs(1);
			input2[0].Set("AllJoyn");
			AllJoyn.Message replyMsg2 = new AllJoyn.Message(bus);
			status = proxyBusObject.MethodCallSynch(INTERFACE_NAME, "ping", input2, replyMsg2, 5000, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.Equal("AllJoyn", (string)replyMsg2[0]);
#pragma warning restore 618

			methodTestBusObject.Dispose();
			servicebus.Dispose();

			// TODO: need to call dispose on proxyBusObject first otherwise you get an AccessViolation???
			proxyBusObject.Dispose();
			bus.Dispose();
		}
Beispiel #18
0
        public void DictionaryOfArrays()
        {
            int[] in_int_array1 = { -2, -22, 222, 2222 };
            int[] in_int_array2 = { -8, -88, 888, 8888 };
            int[] in_int_array3 = { -4, -42, 424, 4242 };
            int[] in_int_array4 = { -5, -55, 555, 5555 };

            System.Collections.Generic.Dictionary<object, object> dict = new System.Collections.Generic.Dictionary<object, object>();
            dict.Add("one", in_int_array1);
            dict.Add("two", in_int_array2);
            dict.Add("three", in_int_array3);
            dict.Add("four", in_int_array4);

            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            Assert.Equal(AllJoyn.QStatus.OK,arg.Set("a{sai}", dict));

            object out_dict;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("a{sai}", out out_dict));

            System.Collections.Generic.Dictionary<object, object> d = (System.Collections.Generic.Dictionary<object, object>)out_dict;
            Assert.Equal(in_int_array1, (int[])d["one"]);
            Assert.Equal(in_int_array2, (int[])d["two"]);
            Assert.Equal(in_int_array3, (int[])d["three"]);
            Assert.Equal(in_int_array4, (int[])d["four"]);
        }
			public void SendTestSignal(String msg)
			{
				AllJoyn.MsgArg payload = new AllJoyn.MsgArg();
				payload.Set(msg);
				AllJoyn.QStatus status = Signal(null, 0, testSignalMember, payload, 0, 64);
				Assert.Equal(AllJoyn.QStatus.OK, status);
			}
Beispiel #20
0
        public void DictionaryOfDictionaries()
        {
            System.Collections.Generic.Dictionary<object, object> inner_dict1 = new System.Collections.Generic.Dictionary<object, object>();
            inner_dict1.Add("apple", 2);
            inner_dict1.Add("pear", 1);
            System.Collections.Generic.Dictionary<object, object> inner_dict2 = new System.Collections.Generic.Dictionary<object, object>();
            inner_dict2.Add("bannana", 0);
            inner_dict2.Add("kiwi", -1);

            System.Collections.Generic.Dictionary<object, object> dict = new System.Collections.Generic.Dictionary<object, object>();
            dict.Add("one", inner_dict1);
            dict.Add("two", inner_dict2);
            dict.Add("three", inner_dict2);
            dict.Add("four", inner_dict1);

            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("a{sa{si}}", dict));

            object out_dict;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("a{sa{si}}", out out_dict));

            System.Collections.Generic.Dictionary<object, object> d = (System.Collections.Generic.Dictionary<object, object>)out_dict;
            Assert.Equal(2, (int)((System.Collections.Generic.Dictionary<object, object>)d["one"])["apple"]);
            Assert.Equal(1, (int)((System.Collections.Generic.Dictionary<object, object>)d["one"])["pear"]);

            Assert.Equal(0, (int)((System.Collections.Generic.Dictionary<object, object>)d["two"])["bannana"]);
            Assert.Equal(-1, (int)((System.Collections.Generic.Dictionary<object, object>)d["two"])["kiwi"]);

            Assert.Equal(0, (int)((System.Collections.Generic.Dictionary<object, object>)d["three"])["bannana"]);
            Assert.Equal(-1, (int)((System.Collections.Generic.Dictionary<object, object>)d["three"])["kiwi"]);

            Assert.Equal(2, (int)((System.Collections.Generic.Dictionary<object, object>)d["four"])["apple"]);
            Assert.Equal(1, (int)((System.Collections.Generic.Dictionary<object, object>)d["four"])["pear"]);
        }
Beispiel #21
0
        public void RegisterUnregisterSessionlessSignals()
        {
            AllJoyn.InterfaceDescription testIntf;
            Assert.Equal(AllJoyn.QStatus.OK, bus.CreateInterface("org.alljoyn.test.signalstest", out testIntf));
            Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddSignal("testSignal", "s", "newName"));
            testIntf.Activate();

            TestBusObject testObj = new TestBusObject("/org/alljoyn/test/signal");
            Assert.Equal(AllJoyn.QStatus.OK, testObj.AddInterface(testIntf));
            Assert.Equal(AllJoyn.QStatus.OK, bus.RegisterBusObject(testObj));

            AllJoyn.InterfaceDescription.Member mySignalMember = testIntf.GetMember("testSignal");

            Assert.Equal(AllJoyn.QStatus.OK, bus.AddMatch("type='signal',sessionless='t',interface='org.alljoyn.test.signalstest,member='testSignal'"));

            AllJoyn.Message msg = new AllJoyn.Message(bus);
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();

            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("s", "AllJoyn"));
            Assert.Equal(AllJoyn.QStatus.OK, testObj.SendTestSignal("", 0, mySignalMember, arg, 0, AllJoyn.ALLJOYN_FLAG_SESSIONLESS, msg));

            Assert.Equal(AllJoyn.QStatus.OK, testObj.CancelSessionlessMessage(msg.CallSerial));

            Assert.Equal(AllJoyn.QStatus.OK, testObj.SendTestSignal("", 0, mySignalMember, arg, 0, AllJoyn.ALLJOYN_FLAG_SESSIONLESS, msg));
            Assert.Equal(AllJoyn.QStatus.OK, testObj.CancelSessionlessMessage(msg));
        }
Beispiel #22
0
        public void DictionaryOfStructs()
        {
            object[] in_struct1 = { -2, "say", 1.618, 888u }; //(isdu)
            object[] in_struct2 = { -42, "what", 2.718, 42u }; //(isdu)
            object[] in_struct3 = { 88, "you", 3.14, 10u }; //(isdu)
            object[] in_struct4 = { 1999, "want", 1.202, 33u }; //(isdu)

            System.Collections.Generic.Dictionary<object, object> dict = new System.Collections.Generic.Dictionary<object, object>();
            dict.Add("one", in_struct1);
            dict.Add("two", in_struct2);
            dict.Add("three", in_struct3);
            dict.Add("four", in_struct4);

            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("a{s(isdu)}", dict));

            object out_dict;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("a{s(isdu)}", out out_dict));

            System.Collections.Generic.Dictionary<object, object> d = (System.Collections.Generic.Dictionary<object, object>)out_dict;
            Assert.Equal(in_struct1, (object[])d["one"]);
            Assert.Equal(in_struct2, (object[])d["two"]);
            Assert.Equal(in_struct3, (object[])d["three"]);
            Assert.Equal(in_struct4, (object[])d["four"]);
        }
			public void Ping(AllJoyn.InterfaceDescription.Member member, AllJoyn.Message message)
			{
				string outStr = (string)message[0];
				AllJoyn.MsgArg outArgs = new AllJoyn.MsgArg();
				outArgs = outStr;

				AllJoyn.QStatus status = MethodReply(message, outArgs);
				Assert.Equal(AllJoyn.QStatus.OK, status);
			}
Beispiel #24
0
        public void DitionaryOfVariants()
        {
            AllJoyn.MsgArg a_arg = new AllJoyn.MsgArg(4);
            int[] in_int_array = { -2, -22, 222, 2222 };
            Assert.Equal(AllJoyn.QStatus.OK, a_arg[0].Set("ai", in_int_array));
            Assert.Equal(AllJoyn.QStatus.OK, a_arg[1].Set("i", 42));
            Assert.Equal(AllJoyn.QStatus.OK, a_arg[2].Set("d", 3.14));
            Assert.Equal(AllJoyn.QStatus.OK, a_arg[3].Set("s", "How are you?"));

            System.Collections.Generic.Dictionary<object, object> dict = new System.Collections.Generic.Dictionary<object, object>();
            dict.Add(10u, a_arg[0]);
            dict.Add(20u, a_arg[1]);
            dict.Add(30u, a_arg[2]);
            dict.Add(42u, a_arg[3]);

            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            Assert.Equal(AllJoyn.QStatus.OK, arg.Set("a{uv}", dict));

            object out_dict;
            Assert.Equal(AllJoyn.QStatus.OK, arg.Get("a{uv}", out out_dict));

            System.Collections.Generic.Dictionary<object, object> d = (System.Collections.Generic.Dictionary<object, object>)out_dict;
            object int_array;
            object i;
            object dub;
            object s;
            Assert.Equal(AllJoyn.QStatus.OK, ((AllJoyn.MsgArg)(d[10u])).Get("ai", out int_array));
            Assert.Equal(AllJoyn.QStatus.OK, ((AllJoyn.MsgArg)(d[20u])).Get("i", out i));
            Assert.Equal(AllJoyn.QStatus.OK, ((AllJoyn.MsgArg)(d[30u])).Get("d", out dub));
            Assert.Equal(AllJoyn.QStatus.OK, ((AllJoyn.MsgArg)(d[42u])).Get("s", out s));

            Assert.Equal(in_int_array, (int[])int_array);
            Assert.Equal(42, (int)i);
            Assert.Equal(3.14, (double)dub);
            Assert.Equal("How are you?", (string)s);
        }
		public void rsa_keyx()
		{
			ResetAuthFlags();
			clientBus.ClearKeyStore();

			PinKeyX_service_authlistener serviceAuthlistener = new PinKeyX_service_authlistener(this);
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.EnablePeerSecurity("ALLJOYN_RSA_KEYX", serviceAuthlistener, null, false));

			serviceBus.ClearKeyStore();

			Assert.Equal(AllJoyn.QStatus.OK, SetUpAuthService());

			PinKeyX_client_authlistener clientAuthlistener = new PinKeyX_client_authlistener(this);
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.EnablePeerSecurity("ALLJOYN_RSA_KEYX", clientAuthlistener, null, false));
			clientBus.ClearKeyStore();

			// create+activate the interface
			AllJoyn.QStatus status;
			AllJoyn.InterfaceDescription iFace = null;
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.CreateInterface(INTERFACE_NAME, AllJoyn.InterfaceDescription.SecurityPolicy.Required, out iFace));
			Assert.NotNull(iFace);

			Assert.Equal(AllJoyn.QStatus.OK, iFace.AddMethod("ping", "s", "s", "in,out"));
			iFace.Activate();

			AllJoyn.ProxyBusObject proxyBusObject = new AllJoyn.ProxyBusObject(clientBus, WELLKNOWN_NAME, OBJECT_PATH, 0);
			Assert.NotNull(proxyBusObject);
			Assert.Equal(AllJoyn.QStatus.OK, proxyBusObject.AddInterface(iFace));

			AllJoyn.MsgArg input = new AllJoyn.MsgArg("s", "AllJoyn");
			AllJoyn.Message replyMsg = new AllJoyn.Message(clientBus);
			status = proxyBusObject.MethodCall(INTERFACE_NAME, "ping", input, replyMsg, 5000, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.Equal("AllJoyn", (string)replyMsg[0]);

			Assert.True(authflags.requestCreds_service);
			Assert.True(authflags.authComplete_serivce);
			Assert.True(authflags.verifyCreds_service);

			Assert.True(authflags.requestCreds_client);
			Assert.True(authflags.authComplete_client);
			Assert.True(authflags.verifyCreds_client);

			clientAuthlistener.Dispose();
			serviceAuthlistener.Dispose();

			busObject.Dispose();

			proxyBusObject.Dispose();


			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Stop());
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Join());

			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Stop());
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Join());

			serviceBus.Dispose();
			clientBus.Dispose();
		}
Beispiel #26
0
        public void HasString()
        {
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg();
            arg = "Yo";
            Assert.True(arg.HasSignature("s"));
            Assert.False(arg.HasSignature("i"));

            arg = (byte)42;
            Assert.True(arg.HasSignature("y"));
            Assert.False(arg.HasSignature("o"));
        }
Beispiel #27
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();
		}
Beispiel #28
0
        public void InitilizedConstructor()
        {
            AllJoyn.MsgArg arg = new AllJoyn.MsgArg("y", (byte)13);
            Assert.Equal((byte)13, (byte)arg);

            arg = new AllJoyn.MsgArg("b", true);
            Assert.True((bool)arg);

            arg = new AllJoyn.MsgArg("n", (short)42);
            Assert.Equal((short)42, (short)arg);

            arg = new AllJoyn.MsgArg("q", (ushort)0xBEBE);
            Assert.Equal((ushort)0xBEBE, (ushort)arg);

            arg = new AllJoyn.MsgArg("i", (int)-9999);
            Assert.Equal((int)-9999, (int)arg);

            arg = new AllJoyn.MsgArg("u", (uint)0x32323232);
            Assert.Equal((uint)0x32323232, (uint)arg);

            arg = new AllJoyn.MsgArg("x", (long)-1);
            Assert.Equal((long)-1, (long)arg);

            arg = new AllJoyn.MsgArg("t", (ulong)0x6464646464646464);
            Assert.Equal((ulong)0x6464646464646464, (ulong)arg);

            arg = new AllJoyn.MsgArg("d", (double)3.14159265D);
            Assert.Equal((double)3.14159265D, (double)arg);

            arg = new AllJoyn.MsgArg("s", (string)"this is a string");
            Assert.Equal("this is a string", (string)arg);

            //error case
            arg = new AllJoyn.MsgArg("s", 42);
            Assert.Equal(AllJoyn.MsgArg.AllJoynTypeId.ALLJOYN_INVALID, arg.TypeId);
        }
Beispiel #29
0
			public void Ping(AllJoyn.InterfaceDescription.Member member, AllJoyn.Message message)
			{
				Assert.Equal(OBJECT_PATH, message.ObjectPath);
				Assert.Equal(INTERFACE_NAME, message.Interface);
				Assert.Equal("ping", message.MemberName);
				string outStr = (string)message[0];
				AllJoyn.MsgArg outArgs = new AllJoyn.MsgArg();
				outArgs = outStr;

				AllJoyn.QStatus status = MethodReply(message, outArgs);
				Assert.Equal(AllJoyn.QStatus.OK, status);
			}
			protected void Ding(AllJoyn.InterfaceDescription.Member member, AllJoyn.Message message)
			{
				AllJoyn.MsgArg outArgs = new AllJoyn.MsgArg();
				outArgs = "Hello from Ding.";

				AllJoyn.QStatus status = MethodReply(message, outArgs);
				Assert.Equal(AllJoyn.QStatus.OK, status);
			}