예제 #1
0
        public void ShouldParseServiceFunctionWithComplexType()
        {
            string idl = @"service serverSync
                            {
                                array<string> testFunction1(i32 param);
                                map<string, boolean> testFunction2(i32 param);
                            }";

            Assert.DoesNotThrow(() => IDLParser.Instance.ParseIDL(idl));
            var testFunction1 = IDLParser.Instance.CurrentlyParsedSinTD
                                .SINFONIServices.GetService("serverSync").GetServiceFunction("testFunction1");
            var testFunction2 = IDLParser.Instance.CurrentlyParsedSinTD
                                .SINFONIServices.GetService("serverSync").GetServiceFunction("testFunction2");

            Assert.AreEqual(typeof(SinTDArray), testFunction1.ReturnType.GetType());
            SinTDArray array = (SinTDArray)testFunction1.ReturnType;

            Assert.AreEqual(IDLParser.Instance.CurrentlyParsedSinTD.GetSinTDType("string"), array.elementType);

            Assert.AreEqual(typeof(SinTDMap), testFunction2.ReturnType.GetType());
            SinTDMap map = (SinTDMap)testFunction2.ReturnType;

            Assert.AreEqual(IDLParser.Instance.CurrentlyParsedSinTD.GetSinTDType("string"), map.keyType);
            Assert.AreEqual(IDLParser.Instance.CurrentlyParsedSinTD.GetSinTDType("boolean"), map.elementType);
        }
예제 #2
0
        public void InitTests()
        {
            i16 = new SinTDType("i16");

            i32 = new SinTDType("i32");

            i64 = new SinTDType("i64");

            ui16 = new SinTDType("u16");
            ui32 = new SinTDType("u32");
            ui64 = new SinTDType("u64");

            SinTD_double = new SinTDType("double");

            SinTD_float = new SinTDType("float");

            SinTD_string      = new SinTDType();
            SinTD_string.Name = "string";

            SinTD_bool      = new SinTDType();
            SinTD_bool.Name = "boolean";

            intStruct = new SinTDStruct("intStruct");
            intStruct.members["x"] = i32;
            intStruct.members["y"] = i32;

            nestedStruct = new SinTDStruct("nestedStruct");
            nestedStruct.members["name"] = SinTD_string;
            nestedStruct.members["b"]    = SinTD_bool;
            nestedStruct.members["s"]    = intStruct;

            SinTD_array             = new SinTDArray();
            SinTD_array.Name        = "array<int32>";
            SinTD_array.elementType = i32;

            map             = new SinTDMap();
            map.keyType     = SinTD_string;
            map.elementType = intStruct;

            SinTD_arrayOfStructs             = new SinTDArray();
            SinTD_arrayOfStructs.Name        = "array<nestedStruct>";
            SinTD_arrayOfStructs.elementType = nestedStruct;

            SinTD_mapWithStructElements             = new SinTDMap();
            SinTD_mapWithStructElements.elementType = nestedStruct;
            SinTD_mapWithStructElements.keyType     = SinTD_string;

            SinTD_mapWithStructKeys             = new SinTDMap();
            SinTD_mapWithStructKeys.elementType = SinTD_string;
            SinTD_mapWithStructKeys.keyType     = nestedStruct;

            Vector = new SinTDStruct("Vector");
            Vector.members.Add("x", SinTD_float);
            Vector.members.Add("y", SinTD_float);
            Vector.members.Add("z", SinTD_float);
        }
예제 #3
0
        public void CallShouldBeValidForMapParameters()
        {
            SinTDMap parameterMap = new SinTDMap();
            parameterMap.elementType = i32;
            parameterMap.keyType = SinTD_string;

            var serviceFunction = new ServiceFunctionDescription("mapFunction", new SinTDType("void"));
            serviceFunction.Parameters.Add("mapParam", parameterMap);
            service.serviceFunctions.Add("mapFunction", serviceFunction);
            var clientFunction = connection.GenerateClientFunction("service", "mapFunction");
            Assert.DoesNotThrow(() => clientFunction(new Dictionary<string, int> {
                {"first", 1},
                {"second", 2}
            }));
        }
예제 #4
0
파일: MapParser.cs 프로젝트: tospie/SINFONI
        internal SinTDMap ParseMap(string mapDefinition)
        {
            int openingBracket = mapDefinition.IndexOf('<');
            int comma = mapDefinition.IndexOf(',');
            int closingBracket = mapDefinition.LastIndexOf('>');

            string keyType = mapDefinition.Substring(openingBracket + 1, comma - openingBracket - 1);
            string valueType = mapDefinition.Substring(comma + 1, closingBracket - comma - 1);

            SinTDMap result = new SinTDMap();
            result.keyType = getKeyOrValueType(keyType);
            result.elementType = getKeyOrValueType(valueType);

            return result;
        }
예제 #5
0
        public void ShouldThrowExceptionOnWrongValueType()
        {
            var baseTypeDictionary = new Dictionary <string, int> {
                { "test", 1 }
            };

            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType     = SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = SinTDInstance.GetSinTDType("string");

            Assert.Throws <TypeCastException>(
                () => { var mapInstance
                            = SinTDMap.AssignValuesFromObject(baseTypeDictionary) as Dictionary <object, object>; });
        }
예제 #6
0
        public void ShouldAssignMapOfBaseTypesToDictionary()
        {
            var baseTypeDictionary = new Dictionary <string, int> {
                { "test", 1 }
            };

            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType     = SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = SinTDInstance.GetSinTDType("i32");
            Dictionary <string, int> nativeDictionary =
                (Dictionary <string, int>)SinTDMap.AssignValuesToNativeType(baseTypeDictionary,
                                                                            typeof(Dictionary <string, int>));

            Assert.AreEqual(baseTypeDictionary, nativeDictionary);
        }
예제 #7
0
        public void ShouldAssignDictionaryOfBaseTypesToMap()
        {
            var baseTypeDictionary = new Dictionary <string, int> {
                { "test", 1 }
            };

            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType     = SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = SinTDInstance.GetSinTDType("i32");

            Dictionary <object, object> mapInstance
                = SinTDMap.AssignValuesFromObject(baseTypeDictionary) as Dictionary <object, object>;

            Assert.AreEqual(1, mapInstance.Values.Count);
            Assert.AreEqual("test", (mapInstance.Keys.ElementAt(0)));
            Assert.AreEqual(1, (mapInstance.Values.ElementAt(0)));
        }
예제 #8
0
        public void CallShouldBeValidForMapParameters()
        {
            SinTDMap parameterMap = new SinTDMap();

            parameterMap.elementType = i32;
            parameterMap.keyType     = SinTD_string;

            var serviceFunction = new ServiceFunctionDescription("mapFunction", new SinTDType("void"));

            serviceFunction.Parameters.Add("mapParam", parameterMap);
            service.serviceFunctions.Add("mapFunction", serviceFunction);
            var clientFunction = connection.GenerateClientFunction("service", "mapFunction");

            Assert.DoesNotThrow(() => clientFunction(new Dictionary <string, int> {
                { "first", 1 },
                { "second", 2 }
            }));
        }
예제 #9
0
        public void ShouldAssingMapWithArrayKeysToNativeArrayKeyDictionary()
        {
            var arrayKeyDictionary = new Dictionary <int[], string> {
                { new int[] { 1 }, "test" }
            };

            SinTDArray keyArray = new SinTDArray();

            keyArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType     = keyArray;
            SinTDMap.elementType = SinTDInstance.GetSinTDType("string");
            Dictionary <int[], string> nativeDictionary = (Dictionary <int[], string>)SinTDMap
                                                          .AssignValuesToNativeType(arrayKeyDictionary, arrayKeyDictionary.GetType());

            Assert.AreEqual(arrayKeyDictionary.Keys, nativeDictionary.Keys);
            Assert.AreEqual(arrayKeyDictionary.Values, nativeDictionary.Values);
        }
예제 #10
0
        public void ShouldAssignedArrayTypedKeysToMap()
        {
            var arrayKeyDictionary = new Dictionary <int[], string> {
                { new int[] { 1 }, "test" }
            };

            SinTDArray keyArray = new SinTDArray();

            keyArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType     = keyArray;
            SinTDMap.elementType = SinTDInstance.GetSinTDType("string");
            Dictionary <object, object> mapInstance
                = SinTDMap.AssignValuesFromObject(arrayKeyDictionary) as Dictionary <object, object>;

            Assert.AreEqual(typeof(object[]), mapInstance.Keys.ElementAt(0).GetType());
            Assert.AreEqual(1, ((object[])mapInstance.Keys.ElementAt(0)).Length);
            Assert.AreEqual(1, ((object[])mapInstance.Keys.ElementAt(0))[0]);
        }
예제 #11
0
        public void ShouldAssignArrayTypedValuesToMap()
        {
            var arrayKeyDictionary = new Dictionary <string, int[]> {
                { "test", new int[] { 1 } }
            };

            SinTDArray valueArray = new SinTDArray();

            valueArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType     = SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = valueArray;
            Dictionary <object, object> mapInstance
                = SinTDMap.AssignValuesFromObject(arrayKeyDictionary) as Dictionary <object, object>;

            Assert.AreEqual(typeof(object[]), mapInstance.Values.ElementAt(0).GetType());
            Assert.AreEqual(1, ((object[])mapInstance.Values.ElementAt(0)).Length);
            Assert.AreEqual(1, ((object[])mapInstance.Values.ElementAt(0))[0]);
        }
예제 #12
0
        public void ShouldThrowExceptionOnWrongValueType()
        {
            var baseTypeDictionary = new Dictionary<string, int> {
                {"test", 1}
            };

            SinTDMap SinTDMap = new SinTDMap();
            SinTDMap.keyType = SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = SinTDInstance.GetSinTDType("string");

            Assert.Throws<TypeCastException>(
                () => { var mapInstance
                    = SinTDMap.AssignValuesFromObject(baseTypeDictionary) as Dictionary<object, object>; });
        }
예제 #13
0
        public void ShouldAssingMapWithArrayKeysToNativeArrayKeyDictionary()
        {
            var arrayKeyDictionary = new Dictionary<int[], string>{
                {new int[]{1}, "test"}
            };

            SinTDArray keyArray = new SinTDArray();
            keyArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType = keyArray;
            SinTDMap.elementType = SinTDInstance.GetSinTDType("string");
            Dictionary<int[], string> nativeDictionary = (Dictionary<int[], string>)SinTDMap
                .AssignValuesToNativeType(arrayKeyDictionary, arrayKeyDictionary.GetType());
            Assert.AreEqual(arrayKeyDictionary.Keys, nativeDictionary.Keys);
            Assert.AreEqual(arrayKeyDictionary.Values, nativeDictionary.Values);
        }
예제 #14
0
        public void ShouldAssignMapOfBaseTypesToDictionary()
        {
            var baseTypeDictionary = new Dictionary<string, int> {
                {"test", 1}
            };

            SinTDMap SinTDMap = new SinTDMap();
            SinTDMap.keyType = SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = SinTDInstance.GetSinTDType("i32");
            Dictionary<string, int> nativeDictionary =
                (Dictionary<string, int>)SinTDMap.AssignValuesToNativeType(baseTypeDictionary,
                typeof(Dictionary<string, int>));
            Assert.AreEqual(baseTypeDictionary, nativeDictionary);
        }
예제 #15
0
        public void ShouldAssignedArrayTypedKeysToMap()
        {
            var arrayKeyDictionary = new Dictionary<int[], string>{
                {new int[]{1}, "test"}
            };

            SinTDArray keyArray = new SinTDArray();
            keyArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType = keyArray;
            SinTDMap.elementType = SinTDInstance.GetSinTDType("string");
            Dictionary<object, object> mapInstance
                = SinTDMap.AssignValuesFromObject(arrayKeyDictionary) as Dictionary<object, object>;

            Assert.AreEqual(typeof(object[]), mapInstance.Keys.ElementAt(0).GetType());
            Assert.AreEqual(1,  ((object[])mapInstance.Keys.ElementAt(0)).Length);
            Assert.AreEqual(1, ((object[])mapInstance.Keys.ElementAt(0))[0]);
        }
예제 #16
0
        public void ShouldAssignDictionaryOfBaseTypesToMap()
        {
            var baseTypeDictionary = new Dictionary<string, int> {
                {"test", 1}
            };

            SinTDMap SinTDMap = new SinTDMap();
            SinTDMap.keyType = SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = SinTDInstance.GetSinTDType("i32");

            Dictionary<object, object> mapInstance
                = SinTDMap.AssignValuesFromObject(baseTypeDictionary) as Dictionary<object, object>;

            Assert.AreEqual(1, mapInstance.Values.Count);
            Assert.AreEqual("test", (mapInstance.Keys.ElementAt(0)));
            Assert.AreEqual(1, (mapInstance.Values.ElementAt(0)));
        }
예제 #17
0
        public void ShouldAssignArrayTypedValuesToMap()
        {
            var arrayKeyDictionary = new Dictionary<string, int[]>{
                {"test", new int[]{1} }
            };

            SinTDArray valueArray = new SinTDArray();
            valueArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDMap SinTDMap = new SinTDMap();

            SinTDMap.keyType =  SinTDInstance.GetSinTDType("string");
            SinTDMap.elementType = valueArray;
            Dictionary<object, object> mapInstance
                = SinTDMap.AssignValuesFromObject(arrayKeyDictionary) as Dictionary<object, object>;

            Assert.AreEqual(typeof(object[]), mapInstance.Values.ElementAt(0).GetType());
            Assert.AreEqual(1, ((object[])mapInstance.Values.ElementAt(0)).Length);
            Assert.AreEqual(1, ((object[])mapInstance.Values.ElementAt(0))[0]);
        }