Beispiel #1
0
        public void Indentation()
        {
            string apiLine = @"SWIFT_API int ApiFun(MODEL_SIMULATION_PTR simulation);";

            HeaderFilter filter   = new HeaderFilter();
            var          gen      = new MatlabApiWrapperGenerator();
            var          filtered = filter.FilterInput(apiLine);
            var          w        = new WrapperGenerator(gen, filter);
            var          result   = w.Convert(filtered);

            Assert.Equal(1, result.Length);
            var s = result[0].Trim('\n');

            string[] expectedLines =
            {
                "function f = ApiFun(simulation)",
//"% ApiFun_m",
//"%",
//"% INPUT simulation [libpointer] A SWIFT simulation object (i.e. a model runner)",
//"% OUTPUT some integer",
//"",
                "simulation_xptr = getExternalPtr(simulation);",
                "res = calllib('swift', 'ApiFun', simulation_xptr);",
                "f = mkExternalObjRef(res);",
//"",
                "end",
                "", // newline
                ""  // newline, ie empty line after body.
            };

            CSharpWrapperGenerator.CheckWrappingFunction(filter, gen, apiLine, expectedLines);
        }
Beispiel #2
0
        public static void CheckWrappingFunction(HeaderFilter filter, IApiConverter gen, string apiLine, string[] expectedLines)
        {
            var filtered = filter.FilterInput(apiLine);
            var w        = new WrapperGenerator(gen, filter);
            var result   = w.Convert(filtered);

            string[] lines = SplitToLines(result);

            CheckExpectedLines(expectedLines, lines);
        }
Beispiel #3
0
        private static void ProcessTestLine(string[] args, IApiConverter gen, HeaderFilter filter = null)
        {
            if (filter == null)
            {
                filter = createFilter();
            }
            string apiLine = args[0];

            apiLine = filter.FilterInput(apiLine)[0];
            var w      = new WrapperGenerator(gen, filter);
            var result = w.Convert(new string[] { apiLine });

            Console.WriteLine(result[0]);
        }
Beispiel #4
0
        public void ReturnsCharPtrPtrToDelegate()
        {
            string apiLine = @"SWIFT_API char** ApiFun(MODEL_SIMULATION_PTR simulation, char** elementIds, int numElements, int* size);";

            HeaderFilter filter = new HeaderFilter();
            var          gen    = new CsharpDelegatesApiWrapperGenerator();

            gen.AddCustomWrapper(gen.ReturnsCharPtrPtrWrapper());
            var filtered = filter.FilterInput(apiLine);
            var w        = new WrapperGenerator(gen, filter);
            var result   = w.Convert(filtered);

            string[] lines = SplitToLines(result);
            Assert.Equal(2, lines.Length);
            var    s        = lines[0].Trim();
            string expected = @"private delegate IntPtr ApiFun_csdelegate(IntPtr simulation, IntPtr elementIds, int numElements, IntPtr size);";

            Assert.Equal(expected, s);
        }
Beispiel #5
0
        public void Indentation()
        {
            string apiLine = @"SWIFT_API int ApiFun(MODEL_SIMULATION_PTR simulation);";

            HeaderFilter filter      = new HeaderFilter();
            var          genDelegate = new CsharpDelegatesApiWrapperGenerator();

            genDelegate.UniformIndentationCount = 2;
            genDelegate.Indentation             = "    ";
            var filtered = filter.FilterInput(apiLine);
            var w        = new WrapperGenerator(genDelegate, filter);
            var result   = w.Convert(filtered);

            Assert.Equal(1, result.Length);
            var    s        = result[0].Trim('\n');
            string expected = genDelegate.Indentation + genDelegate.Indentation + @"private delegate int ApiFun_csdelegate(IntPtr simulation);";

            Assert.Equal(expected, s);

            string[] expectedLines =
            {
                "        int ApiFun_cs(IModelSimulation simulation)",
                "        {",
                "            var result = " + ClassName + ".NativeSwiftLib.GetFunction<ApiFun_csdelegate>(\"ApiFun\")(CheckedDangerousGetHandle(simulation, \"simulation\"));",
                "            var x = result;",
                "            return x;",
                "        }",
                "", // newline
                ""  // newline, ie empty line after body.
            };

            var gen = new CsharpApiWrapperGenerator();

            gen.UniformIndentationCount = 2;
            gen.Indentation             = "    ";

            CheckWrappingFunction(filter, gen, apiLine, expectedLines);
        }