Ejemplo n.º 1
0
        public void TestSizeof(string typeName, string expected)
        {
            using (DisposableTempDirectory temp = new DisposableTempDirectory(null, true)) {
                string csFile = Path.Combine(temp.DirectoryPath, temp.UniqueName("CS", "", "cs"));
                string source = $@"using System;
using SwiftRuntimeLibrary;

using SwiftRuntimeLibrary.SwiftMarshal;
namespace dlopentest
{{
	class MainClass
	{{
		public static void Main (string[] args)
		{{
			var size = StructMarshal.Marshaler.Sizeof(typeof({typeName}));
			Console.WriteLine(size);
		}}
	}}
}}";
                source += TestRunning.GetManagedConsoleRedirectCode();
                File.WriteAllText(csFile, source);

                Compiler.CSCompile(temp.DirectoryPath, new string [] { csFile }, "TestIt.exe", $"-lib:{Compiler.CompilerLocation.SwiftCompilerLib}");
                TestRunning.CopyTestReferencesTo(temp.DirectoryPath);

                string output = Compiler.RunWithMono(Path.Combine(temp.DirectoryPath, "TestIt.exe"), temp.DirectoryPath);
                Assert.AreEqual(expected, output);
            }
        }
Ejemplo n.º 2
0
        void CheckName(string typeName, string expected)
        {
            using (DisposableTempDirectory temp = new DisposableTempDirectory(null, true)) {
                string csFile = Path.Combine(temp.DirectoryPath, temp.UniqueName("CS", "", "cs"));
                string source = $@"using System;
using SwiftRuntimeLibrary;

using SwiftRuntimeLibrary.SwiftMarshal;

namespace dlopentest
{{
	class MainClass
	{{
		public static void Main (string[] args)
		{{
			SwiftNominalTypeDescriptor nt = StructMarshal.Marshaler.Metatypeof(typeof({typeName})).GetNominalTypeDescriptor();
			Console.WriteLine(nt.GetFullName());
		}}
	}}
}}";
                source += TestRunning.GetManagedConsoleRedirectCode();
                File.WriteAllText(csFile, source);
                Compiler.CSCompile(temp.DirectoryPath, new string [] { csFile }, "TestIt.exe", $"-lib:{Compiler.CompilerLocation.SwiftCompilerLib}", PlatformName.macOS);
                TestRunning.CopyTestReferencesTo(temp.DirectoryPath);

                string output = Compiler.RunWithMono(Path.Combine(temp.DirectoryPath, "TestIt.exe"), temp.DirectoryPath, platform: PlatformName.macOS);
                Assert.AreEqual(expected, output);

                string tsource = $@"using System;
using NewClassCompilerTests;
using SwiftRuntimeLibrary;
using TomTest;
using SwiftRuntimeLibrary.SwiftMarshal;

namespace MetatypeTests
{{
	public class CheckName{typeName} : ITomTest
	{{
		public void Run()
		{{
			SwiftNominalTypeDescriptor nt = StructMarshal.Marshaler.Metatypeof(typeof({typeName})).GetNominalTypeDescriptor();
			Console.WriteLine(nt.GetMangledName());
		}}

		public string TestName {{ get {{ return ""CheckName{typeName}""; }} }}
		public string ExpectedOutput {{ get {{ return {ToStringLiteral (expected)}; }} }}
	}}
}}";

                string thisTestPath = Path.Combine(Compiler.kSwiftDeviceTestRoot, "MetatypeTests");

                Directory.CreateDirectory(thisTestPath);
                string tpath = Path.Combine(thisTestPath, $"CheckName{typeName}.cs");
                File.WriteAllText(tpath, tsource);
            }
        }