Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void ShouldThrowExceptionWhenAssigningNonEnumerableToArray()
        {
            SinTDArray array = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");

            Assert.Throws <TypeCastException>(
                () => { object[] arrayInstance = array.AssignValuesFromObject(1) as object[]; });
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void ShouldThrowExceptionWhenAssigningArrayWithWrongElementType()
        {
            var        floatArray = new float[] { 1f };
            SinTDArray array      = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");

            Assert.Throws <TypeCastException>(
                () => { var arrayInstance = array.AssignValuesFromObject(floatArray) as object[]; });
        }
Ejemplo n.º 5
0
        public void ShouldAssignEmptyArray()
        {
            var        intArray = new int[] {};
            SinTDArray array    = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");

            object[] arrayInstance = array.AssignValuesFromObject(intArray) as object[];
            Assert.AreEqual(0, arrayInstance.Length);
        }
Ejemplo n.º 6
0
        public void CallShouldBeValidForArrayParameters()
        {
            SinTDArray parameterArray = new SinTDArray();
            parameterArray.elementType = i32;

            var serviceFunction = new ServiceFunctionDescription("arrayFunction", new SinTDType("void"));
            serviceFunction.Parameters.Add("arrayParam", parameterArray);
            service.serviceFunctions.Add("arrayFunction", serviceFunction);
            var clientFunction = connection.GenerateClientFunction("service", "arrayFunction");
            Assert.DoesNotThrow(() => clientFunction(new int[] {1, 2, 3, 4}));
        }
Ejemplo n.º 7
0
        public void ShouldAssignArrayToArray()
        {
            var        intArray = new int[] { 1 };
            SinTDArray array    = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");

            var arrayInstance = array.AssignValuesFromObject(intArray) as object[];

            Assert.AreEqual(1, arrayInstance.Length);
            Assert.AreEqual(1, (int)arrayInstance[0]);
        }
Ejemplo n.º 8
0
        public void ShouldAssignArrayToNativeArray()
        {
            var        intArray = new int[0];
            SinTDArray array    = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");
            var test = array.AssignValuesToNativeType(new int[1] {
                1
            }, intArray.GetType());

            Assert.AreEqual(1, ((int[])test).Length);
            Assert.AreEqual(1, ((int[])test)[0]);
        }
Ejemplo n.º 9
0
 public void ShouldAssignArrayOfArraysToNative()
 {
     var intArray = new int[1][];
     intArray[0] = new int[1] { 2 };
     SinTDArray innerArray = new SinTDArray();
     innerArray.elementType = SinTDInstance.GetSinTDType("i32");
     SinTDArray outerArray = new SinTDArray();
     outerArray.elementType = innerArray;
     int[][] test = (int[][])outerArray.AssignValuesToNativeType(intArray, intArray.GetType());
     Assert.AreEqual(1, test.Length);
     Assert.AreEqual(1, test[0].Length);
     Assert.AreEqual(new int[1] { 2 }, test[0]);
 }
Ejemplo n.º 10
0
 public void ShouldAssignArrayOfListsToNative()
 {
     var intArray = new int[1][];
     intArray[0] = new int[1] { 2 };
     List<int>[] listArray = new List<int> [1] { new List<int> { 1 } };
     SinTDArray innerArray = new SinTDArray();
     innerArray.elementType = SinTDInstance.GetSinTDType("i32");
     SinTDArray outerArray = new SinTDArray();
     outerArray.elementType = innerArray;
     List<int>[] test = (List<int>[])outerArray.AssignValuesToNativeType(intArray, listArray.GetType());
     Assert.IsAssignableFrom<List<int>>(test[0]);
     Assert.AreEqual(2, test[0][0]);
 }
Ejemplo n.º 11
0
        public void ShouldAssignArrayToNativeSet()
        {
            var        intSet = new HashSet <int>();
            SinTDArray array  = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");
            ISet <int> test = (HashSet <int>)array.AssignValuesToNativeType(new int[1] {
                1
            }, intSet.GetType());

            Assert.AreEqual(1, test.Count);
            Assert.AreEqual(1, test.ElementAt(0));
        }
Ejemplo n.º 12
0
        public void ShouldAssignSetToArray()
        {
            var intSet = new HashSet <int> {
                1
            };
            SinTDArray array = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");

            object[] arrayInstance = array.AssignValuesFromObject(intSet) as object[];
            Assert.AreEqual(1, arrayInstance.Length);
            Assert.AreEqual(1, (int)arrayInstance[0]);
        }
Ejemplo n.º 13
0
        public void ShouldAssignArrayToNativeList()
        {
            var        intList = new List <int>();
            SinTDArray array   = new SinTDArray();

            array.elementType = SinTDInstance.GetSinTDType("i32");
            List <int> test = (List <int>)array.AssignValuesToNativeType(new int[1] {
                1
            }, intList.GetType());

            Assert.AreEqual(1, test.Count);
            Assert.AreEqual(1, test[0]);
        }
Ejemplo n.º 14
0
        public void CallShouldBeValidForArrayParameters()
        {
            SinTDArray parameterArray = new SinTDArray();

            parameterArray.elementType = i32;

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

            serviceFunction.Parameters.Add("arrayParam", parameterArray);
            service.serviceFunctions.Add("arrayFunction", serviceFunction);
            var clientFunction = connection.GenerateClientFunction("service", "arrayFunction");

            Assert.DoesNotThrow(() => clientFunction(new int[] { 1, 2, 3, 4 }));
        }
Ejemplo n.º 15
0
        internal SinTDArray ParseArray(string arrayDefinition)
        {
            SinTDArray result = new SinTDArray();

            int indexStart = arrayDefinition.IndexOf('<') + 1;
            int indexEnd = arrayDefinition.LastIndexOf ('>');
            string elementType = arrayDefinition.Substring(indexStart, indexEnd - indexStart);

            if (elementType.StartsWith("map"))
                result.elementType = MapParser.Instance.ParseMap(elementType);
            else if (elementType.StartsWith("array"))
                result.elementType = ArrayParser.Instance.ParseArray(elementType);
            else
                result.elementType = IDLParser.Instance.CurrentlyParsedSinTD.GetSinTDType(elementType.Trim());

            return result;
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        public void ShouldAssignArrayOfArraysToNative()
        {
            var intArray = new int[1][];

            intArray[0] = new int[1] {
                2
            };
            SinTDArray innerArray = new SinTDArray();

            innerArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDArray outerArray = new SinTDArray();

            outerArray.elementType = innerArray;
            int[][] test = (int[][])outerArray.AssignValuesToNativeType(intArray, intArray.GetType());
            Assert.AreEqual(1, test.Length);
            Assert.AreEqual(1, test[0].Length);
            Assert.AreEqual(new int[1] {
                2
            }, test[0]);
        }
Ejemplo n.º 18
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]);
        }
Ejemplo n.º 19
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]);
        }
Ejemplo n.º 20
0
        public void ShouldAssignArrayOfListsToNative()
        {
            var intArray = new int[1][];

            intArray[0] = new int[1] {
                2
            };
            List <int>[] listArray = new List <int> [1] {
                new List <int> {
                    1
                }
            };
            SinTDArray innerArray = new SinTDArray();

            innerArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDArray outerArray = new SinTDArray();

            outerArray.elementType = innerArray;
            List <int>[] test = (List <int>[])outerArray.AssignValuesToNativeType(intArray, listArray.GetType());
            Assert.IsAssignableFrom <List <int> >(test[0]);
            Assert.AreEqual(2, test[0][0]);
        }
Ejemplo n.º 21
0
        public void ShouldAssignArrayOfSetsToNative()
        {
            var intArray = new int[1][];

            intArray[0] = new int[1] {
                2
            };
            ISet <int>[] setArray = new HashSet <int>[1] {
                new HashSet <int> {
                    1
                }
            };
            SinTDArray innerArray = new SinTDArray();

            innerArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDArray outerArray = new SinTDArray();

            outerArray.elementType = innerArray;
            HashSet <int>[] test = (HashSet <int>[])outerArray.AssignValuesToNativeType(intArray, setArray.GetType());
            Assert.IsAssignableFrom <HashSet <int> >(test[0]);
            Assert.AreEqual(2, test[0].ElementAt(0));
        }
Ejemplo n.º 22
0
        public void ShouldAssignLSetOfArraysToNative()
        {
            var intArray = new int[1][];

            intArray[0] = new int[1] {
                2
            };
            ISet <int[]> arraySet = new HashSet <int[]> {
                new int[1] {
                    1
                }
            };
            SinTDArray innerArray = new SinTDArray();

            innerArray.elementType = SinTDInstance.GetSinTDType("i32");
            SinTDArray outerArray = new SinTDArray();

            outerArray.elementType = innerArray;
            ISet <int[]> test = (HashSet <int[]>)outerArray.AssignValuesToNativeType(intArray, arraySet.GetType());

            Assert.IsAssignableFrom <int[]>(test.ElementAt(0));
            Assert.AreEqual(2, test.ElementAt(0)[0]);
        }
Ejemplo n.º 23
0
 public void ShouldAssignLSetOfArraysToNative()
 {
     var intArray = new int[1][];
     intArray[0] = new int[1] { 2 };
     ISet<int[]> arraySet = new HashSet<int[]> { new int[1] { 1 } };
     SinTDArray innerArray = new SinTDArray();
     innerArray.elementType = SinTDInstance.GetSinTDType("i32");
     SinTDArray outerArray = new SinTDArray();
     outerArray.elementType = innerArray;
     ISet<int[]> test = (HashSet<int[]>)outerArray.AssignValuesToNativeType(intArray, arraySet.GetType());
     Assert.IsAssignableFrom<int[]>(test.ElementAt(0));
     Assert.AreEqual(2, test.ElementAt(0)[0]);
 }
Ejemplo n.º 24
0
 public void ShouldAssignArrayOfSetsToNative()
 {
     var intArray = new int[1][];
     intArray[0] = new int[1] { 2 };
     ISet<int>[] setArray = new HashSet<int>[1] { new HashSet<int> { 1 } };
     SinTDArray innerArray = new SinTDArray();
     innerArray.elementType = SinTDInstance.GetSinTDType("i32");
     SinTDArray outerArray = new SinTDArray();
     outerArray.elementType = innerArray;
     HashSet<int>[] test = (HashSet<int>[])outerArray.AssignValuesToNativeType(intArray, setArray.GetType());
     Assert.IsAssignableFrom<HashSet<int>>(test[0]);
     Assert.AreEqual(2, test[0].ElementAt(0));
 }
Ejemplo n.º 25
0
        public void ShouldThrowExceptionWhenAssigningNonEnumerableToArray()
        {
            SinTDArray array = new SinTDArray();
            array.elementType = SinTDInstance.GetSinTDType("i32");

            Assert.Throws<TypeCastException>(
                () => { object[] arrayInstance = array.AssignValuesFromObject(1) as object[]; });
        }
Ejemplo n.º 26
0
        public void ShouldThrowExceptionWhenAssigningArrayWithWrongElementType()
        {
            var floatArray = new float[] { 1f };
            SinTDArray array = new SinTDArray();
            array.elementType = SinTDInstance.GetSinTDType("i32");

            Assert.Throws<TypeCastException>(
                () => { var arrayInstance = array.AssignValuesFromObject(floatArray) as object[]; });
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
 public void ShouldAssignArrayToNativeArray()
 {
     var intArray = new int[0];
     SinTDArray array = new SinTDArray();
     array.elementType = SinTDInstance.GetSinTDType("i32");
     var test = array.AssignValuesToNativeType(new int[1]{1}, intArray.GetType());
     Assert.AreEqual(1, ((int[])test).Length);
     Assert.AreEqual(1, ((int[])test)[0]);
 }
Ejemplo n.º 29
0
 public void ShouldAssignArrayToNativeList()
 {
     var intList = new List<int>();
     SinTDArray array = new SinTDArray();
     array.elementType = SinTDInstance.GetSinTDType("i32");
     List<int> test = (List<int>)array.AssignValuesToNativeType(new int[1] { 1 }, intList.GetType());
     Assert.AreEqual(1, test.Count);
     Assert.AreEqual(1, test[0]);
 }
Ejemplo n.º 30
0
        public void ShouldAssignEmptyArray()
        {
            var intArray = new int[] {};
            SinTDArray array = new SinTDArray();
            array.elementType = SinTDInstance.GetSinTDType("i32");

            object[] arrayInstance = array.AssignValuesFromObject(intArray) as object[];
            Assert.AreEqual(0, arrayInstance.Length);
        }
Ejemplo n.º 31
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]);
        }
Ejemplo n.º 32
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]);
        }
Ejemplo n.º 33
0
 public void ShouldAssignArrayToNativeSet()
 {
     var intSet = new HashSet<int>();
     SinTDArray array = new SinTDArray();
     array.elementType = SinTDInstance.GetSinTDType("i32");
     ISet<int> test = (HashSet<int>)array.AssignValuesToNativeType(new int[1] { 1 }, intSet.GetType());
     Assert.AreEqual(1, test.Count);
     Assert.AreEqual(1, test.ElementAt(0));
 }
Ejemplo n.º 34
0
        public void ShouldAssignArrayToArray()
        {
            var intArray = new int[] { 1 };
            SinTDArray array = new SinTDArray();
            array.elementType = SinTDInstance.GetSinTDType("i32");

            var arrayInstance =  array.AssignValuesFromObject(intArray) as object[];
            Assert.AreEqual(1, arrayInstance.Length);
            Assert.AreEqual(1, (int)arrayInstance[0]);
        }
Ejemplo n.º 35
0
        public void ShouldAssignSetToArray()
        {
            var intSet = new HashSet<int> { 1 };
            SinTDArray array = new SinTDArray();
            array.elementType = SinTDInstance.GetSinTDType("i32");

            object[] arrayInstance = array.AssignValuesFromObject(intSet) as object[];
            Assert.AreEqual(1, arrayInstance.Length);
            Assert.AreEqual(1, (int)arrayInstance[0]);
        }