Пример #1
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);
        }
Пример #2
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);
        }