diff options
author | Jb Evain <jbevain@gmail.com> | 2007-07-16 23:37:49 +0400 |
---|---|---|
committer | Jb Evain <jbevain@gmail.com> | 2007-07-16 23:37:49 +0400 |
commit | 13b6a5f58146c0a715a263ba4df5376c5dc36b97 (patch) | |
tree | c22f80596bbec2af787082c974542e93b005ce33 /linker/Tests |
move
svn path=/trunk/mcs/; revision=82057
Diffstat (limited to 'linker/Tests')
69 files changed, 1387 insertions, 0 deletions
diff --git a/linker/Tests/Libs/nunit-console-runner.dll b/linker/Tests/Libs/nunit-console-runner.dll Binary files differnew file mode 100755 index 000000000..f112e2322 --- /dev/null +++ b/linker/Tests/Libs/nunit-console-runner.dll diff --git a/linker/Tests/Libs/nunit-console.exe b/linker/Tests/Libs/nunit-console.exe Binary files differnew file mode 100755 index 000000000..32ca802e9 --- /dev/null +++ b/linker/Tests/Libs/nunit-console.exe diff --git a/linker/Tests/Libs/nunit-console.exe.config b/linker/Tests/Libs/nunit-console.exe.config new file mode 100755 index 000000000..4926127eb --- /dev/null +++ b/linker/Tests/Libs/nunit-console.exe.config @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<configuration> + <!-- + Application settings for NUnit-console.exe. Do NOT put settings + for use by your tests here. + --> + <appSettings> + + <!-- + Specify the location to be used by .NET for the cache + --> + <add key="shadowfiles.path" value="%temp%\nunit20\ShadowCopyCache" /> + + </appSettings> + + <!-- + The startup section may be used to specify the runtime versions + supported in the order that they will be used if more than one + is present. As supplied, this section is commented out, which + causes nunit-console to use the version of the framework with + which it was built. + + Since .NET 1.0 does not recognize the <supportedRuntime> elements, + a <requiredRuntime> element is used in case it is the only version + of the framework that is installed. + --> + <!-- + <startup> + <supportedRuntime version="v2.0.50727" /> + <supportedRuntime version="v2.0.50215" /> + <supportedRuntime version="v2.0.40607" /> + <supportedRuntime version="v1.1.4322" /> + <supportedRuntime version="v1.0.3705" /> + + <requiredRuntime version="v1.0.3705" /> + </startup> + --> + + <!-- + The following <runtime> section allows running nunit under + .NET 1.0 by redirecting assemblies. The appliesTo attribute + causes the section to be ignored except under .NET 1.0version 1 + on a machine with only the .NET version 1.0 runtime installed. + If application and its tests were built for .NET 1.1 you will + also need to redirect system assemblies in the test config file. + --> + + <runtime> + + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" + appliesTo="v1.0.3705"> + + <dependentAssembly> + <assemblyIdentity name="System" + publicKeyToken="b77a5c561934e089" + culture="neutral"/> + <bindingRedirect oldVersion="1.0.5000.0" + newVersion="1.0.3300.0"/> + </dependentAssembly> + + <dependentAssembly> + <assemblyIdentity name="System.Data" + publicKeyToken="b77a5c561934e089" + culture="neutral"/> + <bindingRedirect oldVersion="1.0.5000.0" + newVersion="1.0.3300.0"/> + </dependentAssembly> + + <dependentAssembly> + <assemblyIdentity name="System.Drawing" + publicKeyToken="b03f5f7f11d50a3a" + culture="neutral"/> + <bindingRedirect oldVersion="1.0.5000.0" + newVersion="1.0.3300.0"/> + </dependentAssembly> + + <dependentAssembly> + <assemblyIdentity name="System.Windows.Forms" + publicKeyToken="b77a5c561934e089" + culture="neutral"/> + <bindingRedirect oldVersion="1.0.5000.0" + newVersion="1.0.3300.0"/> + </dependentAssembly> + + <dependentAssembly> + <assemblyIdentity name="System.Xml" + publicKeyToken="b77a5c561934e089" + culture="neutral"/> + <bindingRedirect oldVersion="1.0.5000.0" + newVersion="1.0.3300.0"/> + </dependentAssembly> + + </assemblyBinding> + + </runtime> + +</configuration>
\ No newline at end of file diff --git a/linker/Tests/Libs/nunit.core.dll b/linker/Tests/Libs/nunit.core.dll Binary files differnew file mode 100755 index 000000000..df7f9051c --- /dev/null +++ b/linker/Tests/Libs/nunit.core.dll diff --git a/linker/Tests/Libs/nunit.framework.dll b/linker/Tests/Libs/nunit.framework.dll Binary files differnew file mode 100755 index 000000000..5316687ad --- /dev/null +++ b/linker/Tests/Libs/nunit.framework.dll diff --git a/linker/Tests/Libs/nunit.util.dll b/linker/Tests/Libs/nunit.util.dll Binary files differnew file mode 100755 index 000000000..e9e479ebc --- /dev/null +++ b/linker/Tests/Libs/nunit.util.dll diff --git a/linker/Tests/Makefile b/linker/Tests/Makefile new file mode 100644 index 000000000..8b87256f6 --- /dev/null +++ b/linker/Tests/Makefile @@ -0,0 +1,21 @@ +MCS = mcs + +all: Mono.Linker.Tests.dll + +Mono.Cecil.dll: + cp ../Mono.Cecil.dll . + +monolinker.exe: + cp ../monolinker.exe . + +Mono.Linker.Tests.dll.sources: + find Mono.Linker.Tests -name "*.cs" > Mono.Linker.Tests.dll.sources + +Mono.Linker.Tests.dll: Mono.Cecil.dll monolinker.exe Mono.Linker.Tests.dll.sources + $(MCS) /target:library /out:Mono.Linker.Tests.dll /r:nunit.framework.dll /r:Mono.Cecil.dll /r:monolinker.exe @Mono.Linker.Tests.dll.sources + +clean: + rm -rf Mono.Cecil.dll monolinker.exe Mono.Linker.Tests.dll.sources Mono.Linker.Tests.dll + +run-test: all + nunit-console Mono.Linker.Tests.dll diff --git a/linker/Tests/Mono.Linker.Tests.csproj b/linker/Tests/Mono.Linker.Tests.csproj new file mode 100644 index 000000000..e591da951 --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests.csproj @@ -0,0 +1,69 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{400A1561-B6B6-482D-9E4C-3DDAEDE5BD07}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Mono.Linker.Tests</RootNamespace> + <AssemblyName>Mono.Linker.Tests</AssemblyName> + <StartupObject> + </StartupObject> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <ItemGroup> + <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>Libs\nunit.framework.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\lib\Mono.Cecil.csproj"> + <Project>{D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}</Project> + <Name>Mono.Cecil</Name> + </ProjectReference> + <ProjectReference Include="..\Mono.Linker.csproj"> + <Project>{DD28E2B1-057B-4B4D-A04D-B2EBD9E76E46}</Project> + <Name>Mono.Linker</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Compile Include="Mono.Linker.Tests\AbstractLinkingTestFixture.cs" /> + <Compile Include="Mono.Linker.Tests\AbstractTestFixture.cs" /> + <Compile Include="Mono.Linker.Tests\AssemblyLinkingTestFixture.cs" /> + <Compile Include="Mono.Linker.Tests\AssemblyInfo.cs" /> + <Compile Include="Mono.Linker.Tests\IntegrationTestFixture.cs" /> + <Compile Include="Mono.Linker.Tests\XmlLinkingTestFixture.cs" /> + </ItemGroup> + <ItemGroup> + <Folder Include="Properties\" /> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/linker/Tests/Mono.Linker.Tests/AbstractLinkingTestFixture.cs b/linker/Tests/Mono.Linker.Tests/AbstractLinkingTestFixture.cs new file mode 100644 index 000000000..5746ca03a --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests/AbstractLinkingTestFixture.cs @@ -0,0 +1,163 @@ +// +// AbstractLinkingTestFixture.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.IO; +using Mono.Cecil; +using Mono.Linker.Steps; +using NUnit.Framework; + +namespace Mono.Linker.Tests { + + [TestFixture] + public abstract class AbstractLinkingTestFixture : AbstractTestFixture { + + [SetUp] + public override void SetUp () + { + base.SetUp (); + + TestCasesRoot = "Linker"; + } + + [TearDown] + public override void TearDown () + { + base.TearDown (); + + string output = GetOutputPath (); + if (Directory.Exists (output)) + Directory.Delete (output, true); + } + + protected override Pipeline GetPipeline () + { + Pipeline p = new Pipeline (); + p.AppendStep (new LoadReferencesStep ()); + p.AppendStep (new BlacklistStep ()); + p.AppendStep (new MarkStep ()); + p.AppendStep (new SweepStep ()); + p.AppendStep (new CleanStep ()); + p.AppendStep (new OutputStep ()); + return p; + } + + protected override void RunTest (string testCase) + { + base.RunTest (testCase); + + Prepare (); + } + + void Prepare () + { + Context = GetContext (); + string output = GetOutputPath (); + if (Directory.Exists (output)) + Directory.Delete (output, true); + Directory.CreateDirectory (output); + } + + protected override void Run () + { + base.Run (); + Compare (); + } + + void Compare () + { + foreach (AssemblyDefinition assembly in Context.GetAssemblies ()) { + if (Annotations.GetAction (assembly) != AssemblyAction.Link) + continue; + + string fileName = GetAssemblyFileName (assembly); + + CompareAssemblies ( + AssemblyFactory.GetAssembly ( + Path.Combine (GetTestCasePath (), fileName)), + AssemblyFactory.GetAssembly ( + Path.Combine (GetOutputPath (), fileName))); + } + } + + static void CompareAssemblies (AssemblyDefinition original, AssemblyDefinition linked) + { + foreach (TypeDefinition originalType in original.MainModule.Types) { + TypeDefinition linkedType = linked.MainModule.Types [originalType.FullName]; + if (NotLinked (originalType)) { + Assert.IsNull (linkedType, string.Format ("Type `{0}' should not have been linked", originalType)); + continue; + } + + Assert.IsNotNull (linkedType, string.Format ("Type `{0}' should have been linked", originalType)); + CompareTypes (originalType, linkedType); + } + } + + static void CompareTypes (TypeDefinition type, TypeDefinition linkedType) + { + foreach (FieldDefinition originalField in type.Fields) { + FieldDefinition linkedField = linkedType.Fields.GetField (originalField.Name);// TODO: also get with the type! + if (NotLinked (originalField)) { + Assert.IsNull (linkedField, string.Format ("Field `{0}' should not have been linked", originalField)); + continue; + } + + Assert.IsNotNull (linkedField, string.Format ("Field `{0}' should have been linked", originalField)); + } + + foreach (MethodDefinition originalCtor in type.Constructors) { + MethodDefinition linkedCtor = linkedType.Constructors.GetConstructor (originalCtor.IsStatic, originalCtor.Parameters); + if (NotLinked (originalCtor)) { + Assert.IsNull (linkedCtor, string.Format ("Constructor `{0}' should not have been linked", originalCtor)); + continue; + } + + Assert.IsNotNull (linkedCtor, string.Format ("Constructor `{0}' should have been linked", originalCtor)); + } + + foreach (MethodDefinition originalMethod in type.Methods) { + MethodDefinition linkedMethod = linkedType.Methods.GetMethod (originalMethod.Name, originalMethod.Parameters); + if (NotLinked (originalMethod)) { + Assert.IsNull (linkedMethod, string.Format ("Method `{0}' should not have been linked", originalMethod)); + continue; + } + + Assert.IsNotNull (linkedMethod, string.Format ("Method `{0}' should have been linked", originalMethod)); + } + } + + static bool NotLinked(ICustomAttributeProvider provider) + { + foreach (CustomAttribute ca in provider.CustomAttributes) + if (ca.Constructor.DeclaringType.Name == "NotLinkedAttribute") + return true; + + return false; + } + } +} diff --git a/linker/Tests/Mono.Linker.Tests/AbstractTestFixture.cs b/linker/Tests/Mono.Linker.Tests/AbstractTestFixture.cs new file mode 100644 index 000000000..e1ea1edcf --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests/AbstractTestFixture.cs @@ -0,0 +1,135 @@ +// +// AbstractTestFixture.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Linker.Tests { + + using System; + using System.IO; + + using Mono.Cecil; + + using NUnit.Framework; + + [TestFixture] + public abstract class AbstractTestFixture { + + string _testCasesRoot; + string _testCase; + LinkContext _context; + Pipeline _pipeline; + + protected LinkContext Context { + get { return _context; } + set { _context = value; } + } + + protected Pipeline Pipeline { + get { return _pipeline; } + set { _pipeline = value; } + } + + public string TestCasesRoot { + get { return _testCasesRoot; } + set { _testCasesRoot = value; } + } + + public string TestCase { + get { return _testCase; } + set { _testCase = value; } + } + + [SetUp] + public virtual void SetUp () + { + _pipeline = GetPipeline (); + } + + [TearDown] + public virtual void TearDown () + { + } + + protected virtual Pipeline GetPipeline () + { + return new Pipeline (); + } + + protected virtual LinkContext GetContext () + { + LinkContext context = new LinkContext (_pipeline); + context.OutputDirectory = GetOutputPath (); + context.CoreAction = AssemblyAction.Copy; + return context; + } + + protected string GetOutputPath () + { + return Path.Combine ( + Path.GetTempPath (), + _testCase); + } + + protected string GetTestCasePath () + { + return Path.Combine ( + Path.Combine ( +#if DEBUG + Path.Combine (Environment.CurrentDirectory, + Path.Combine ("..", "..")), +#else + Environment.CurrentDirectory, +#endif + "TestCases"), + Path.Combine ( + _testCasesRoot, + _testCase)); + } + + protected virtual void RunTest (string testCase) + { + _testCase = testCase; + _context = GetContext (); + } + + protected virtual void Run () + { + string cd = Environment.CurrentDirectory; + Environment.CurrentDirectory = GetTestCasePath (); + try { + _pipeline.Process (_context); + } finally { + Environment.CurrentDirectory = cd; + } + } + + protected static string GetAssemblyFileName (AssemblyDefinition asm) + { + return asm.Name.Name + (asm.Kind == AssemblyKind.Dll ? ".dll" : ".exe"); + } + } +} diff --git a/linker/Tests/Mono.Linker.Tests/AssemblyInfo.cs b/linker/Tests/Mono.Linker.Tests/AssemblyInfo.cs new file mode 100644 index 000000000..0c169fdd6 --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests/AssemblyInfo.cs @@ -0,0 +1,42 @@ +// +// AssemblyInfo.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle ("Mono.Linker.Tests")] +[assembly: AssemblyDescription ("NUnit tests for Mono's CIL Linker")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("(C) 2006, Jb Evain")] +[assembly: AssemblyCulture ("")] + +[assembly: CLSCompliant (false)] +[assembly: ComVisible (false)] + diff --git a/linker/Tests/Mono.Linker.Tests/AssemblyLinkingTestFixture.cs b/linker/Tests/Mono.Linker.Tests/AssemblyLinkingTestFixture.cs new file mode 100644 index 000000000..4810cd1b7 --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests/AssemblyLinkingTestFixture.cs @@ -0,0 +1,67 @@ +// +// AssemblyLinkingTestFixture.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.IO; + +using Mono.Linker.Steps; +using NUnit.Framework; + +namespace Mono.Linker.Tests { + + [TestFixture] + public class AssemblyLinkingTestFixture : AbstractLinkingTestFixture { + + [Test] + public void TestSimple () + { + RunTest ("Simple"); + } + + [Test] + public void TestVirtualCall () + { + RunTest ("VirtualCall"); + } + + [Test] + public void TestMultipleReferences () + { + RunTest ("MultipleReferences"); + } + + protected override void RunTest (string testCase) + { + base.RunTest (testCase); + Pipeline.PrependStep ( + new ResolveFromAssemblyStep ( + Path.Combine (GetTestCasePath (), "Program.exe"))); + + Run (); + } + } +} diff --git a/linker/Tests/Mono.Linker.Tests/IntegrationTestFixture.cs b/linker/Tests/Mono.Linker.Tests/IntegrationTestFixture.cs new file mode 100644 index 000000000..1f9474208 --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests/IntegrationTestFixture.cs @@ -0,0 +1,122 @@ +// +// IntegrationTestFixture.cs +// +// Author: +// Jb Evain (jbevain@novell.com) +// +// (C) 2007 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Diagnostics; +using System.IO; +using Mono.Linker.Steps; +using NUnit.Framework; + +namespace Mono.Linker.Tests { + + [TestFixture] + public class IntegrationTestFixture : AbstractTestFixture { + + [SetUp] + public override void SetUp () + { + base.SetUp (); + + TestCasesRoot = "Integration"; + } + + [Test] + public void TestHelloWorld () + { + RunTest ("HelloWorld"); + } + + [Test] + public void TestCrypto () + { + RunTest ("Crypto"); + } + + protected override LinkContext GetContext() + { + LinkContext context = base.GetContext (); + context.CoreAction = AssemblyAction.Link; + return context; + } + + protected override Pipeline GetPipeline () + { + Pipeline p = new Pipeline (); + p.AppendStep (new LoadReferencesStep ()); + p.AppendStep (new BlacklistStep ()); + p.AppendStep (new MarkStep ()); + p.AppendStep (new SweepStep ()); + p.AppendStep (new CleanStep ()); + p.AppendStep (new OutputStep ()); + return p; + } + + protected override void RunTest (string testCase) + { + if (!OnMono ()) + Assert.Ignore ("Integration tests are only runnable on Mono"); + + base.RunTest (testCase); + string test = Path.Combine (GetTestCasePath (), "Test.exe"); + + string original = Execute (GetTestCasePath (), "Test.exe"); + + Pipeline.PrependStep ( + new ResolveFromAssemblyStep ( + test)); + + Run (); + + string linked = Execute (Context.OutputDirectory, "Test.exe"); + + Assert.AreEqual (original, linked); + } + + static bool OnMono () + { + return Type.GetType ("System.MonoType") != null; + } + + static string Execute (string directory, string file) + { + Process p = new Process (); + p.StartInfo.EnvironmentVariables ["MONO_PATH"] = directory; + p.StartInfo.CreateNoWindow = true; + p.StartInfo.WorkingDirectory = directory; + p.StartInfo.FileName = "mono"; + p.StartInfo.Arguments = file; + p.StartInfo.RedirectStandardOutput = true; + p.StartInfo.UseShellExecute = false; + + p.Start (); + p.WaitForExit (); + + return p.StandardOutput.ReadToEnd (); + } + } +} diff --git a/linker/Tests/Mono.Linker.Tests/XmlLinkingTestFixture.cs b/linker/Tests/Mono.Linker.Tests/XmlLinkingTestFixture.cs new file mode 100644 index 000000000..f6ec6e99d --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests/XmlLinkingTestFixture.cs @@ -0,0 +1,93 @@ +// +// XmlLinkingTestFixture.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.IO; +using System.Xml.XPath; + +using Mono.Linker.Steps; +using NUnit.Framework; + + +namespace Mono.Linker.Tests { + + [TestFixture] + public class XmlLinkingTestFixture : AbstractLinkingTestFixture { + + [Test] + public void TestSimpleXml () + { + RunTest ("SimpleXml"); + } + + [Test] + public void TestInterface () + { + RunTest ("Interface"); + } + + [Test] + public void TestReferenceInVirtualMethod () + { + RunTest ("ReferenceInVirtualMethod"); + } + + [Test] + public void TestGenerics () + { + RunTest ("Generics"); + } + + [Test] + public void TestNestedNested () + { + RunTest ("NestedNested"); + } + + [Test] + public void TestPreserveFieldsRequired () + { + RunTest ("PreserveFieldsRequired"); + } + + [Test] + public void TestReferenceInAttributes () + { + RunTest ("ReferenceInAttributes"); + } + + protected override void RunTest (string testCase) + { + base.RunTest (testCase); + Pipeline.PrependStep ( + new ResolveFromXmlStep ( + new XPathDocument (Path.Combine (GetTestCasePath (), "desc.xml")))); + + Run (); + } + } +} diff --git a/linker/Tests/TestCases/Integration/Crypto/Test.cs b/linker/Tests/TestCases/Integration/Crypto/Test.cs new file mode 100644 index 000000000..8c38f9297 --- /dev/null +++ b/linker/Tests/TestCases/Integration/Crypto/Test.cs @@ -0,0 +1,16 @@ +using System; +using System.Security.Cryptography; +using System.Text; + +class Test { + + static void Main () + { + byte [] foo = Encoding.UTF8.GetBytes ("foobared"); + + HashAlgorithm ha = MD5.Create (); + byte [] hash = ha.ComputeHash (foo); + + Console.WriteLine (Encoding.UTF8.GetString (hash)); + } +} diff --git a/linker/Tests/TestCases/Integration/Crypto/Test.exe b/linker/Tests/TestCases/Integration/Crypto/Test.exe Binary files differnew file mode 100755 index 000000000..2decc4983 --- /dev/null +++ b/linker/Tests/TestCases/Integration/Crypto/Test.exe diff --git a/linker/Tests/TestCases/Integration/HelloWorld/Test.cs b/linker/Tests/TestCases/Integration/HelloWorld/Test.cs new file mode 100644 index 000000000..4a65b4401 --- /dev/null +++ b/linker/Tests/TestCases/Integration/HelloWorld/Test.cs @@ -0,0 +1,9 @@ +using System; + +class Test { + + static void Main () + { + Console.WriteLine ("Hello world!"); + } +} diff --git a/linker/Tests/TestCases/Integration/HelloWorld/Test.exe b/linker/Tests/TestCases/Integration/HelloWorld/Test.exe Binary files differnew file mode 100755 index 000000000..2f4f4c9dc --- /dev/null +++ b/linker/Tests/TestCases/Integration/HelloWorld/Test.exe diff --git a/linker/Tests/TestCases/Linker/Generics/Library.cs b/linker/Tests/TestCases/Linker/Generics/Library.cs new file mode 100644 index 000000000..75fe1ed36 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Generics/Library.cs @@ -0,0 +1,61 @@ +using System; + +public class Foo { + + void Bar () + { + int i = 42; + string s = "hey"; + + Baz<int> bi = new Baz<int> (i); + bi.Gazonk (); + bi.Bat<string>(i, s); + + Baz<string> bs = new Baz<string> (s); + bs.Gazonk (); + bs.Bat<int>(s, i); + bs.BiroBiro (); + + bs.Blam<Bang> (); + } +} + +public class Baz<T> { + + T _t; + + public Baz (T t) + { + _t = t; + } + + public void Gazonk () + { + Console.WriteLine (_t); + } + + public void Bat<M> (T t, M m) + { + Console.WriteLine ("{0}{1}", t, m); + } + + public void Blam<M> () + { + } + + public T [] BiroBiro () + { + return new T [0]; + } +} + +class Bang { + + [NotLinked] public Bang () + { + } +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/Generics/Library.dll b/linker/Tests/TestCases/Linker/Generics/Library.dll Binary files differnew file mode 100644 index 000000000..fe5cab177 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Generics/Library.dll diff --git a/linker/Tests/TestCases/Linker/Generics/Makefile b/linker/Tests/TestCases/Linker/Generics/Makefile new file mode 100644 index 000000000..2e5bf5bcf --- /dev/null +++ b/linker/Tests/TestCases/Linker/Generics/Makefile @@ -0,0 +1,4 @@ +include ../../config.make + +all: + MCS /t:library Library.cs diff --git a/linker/Tests/TestCases/Linker/Generics/desc.xml b/linker/Tests/TestCases/Linker/Generics/desc.xml new file mode 100644 index 000000000..0dd61b9b3 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Generics/desc.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="Library"> + <type fullname="Foo" /> + </assembly> +</linker> diff --git a/linker/Tests/TestCases/Linker/Interface/Library.cs b/linker/Tests/TestCases/Linker/Interface/Library.cs new file mode 100644 index 000000000..7aa939469 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Interface/Library.cs @@ -0,0 +1,26 @@ +using System; + +public class Foo : IFoo { + + public void Gazonk () + { + } +} + +public interface IFoo : IBar { +} + +public interface IBar { + + void Gazonk (); +} + +[NotLinked] public class Baz : IBaz { +} + +[NotLinked] public interface IBaz { +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/Interface/Library.dll b/linker/Tests/TestCases/Linker/Interface/Library.dll Binary files differnew file mode 100644 index 000000000..2ae8b9239 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Interface/Library.dll diff --git a/linker/Tests/TestCases/Linker/Interface/Makefile b/linker/Tests/TestCases/Linker/Interface/Makefile new file mode 100644 index 000000000..2e5bf5bcf --- /dev/null +++ b/linker/Tests/TestCases/Linker/Interface/Makefile @@ -0,0 +1,4 @@ +include ../../config.make + +all: + MCS /t:library Library.cs diff --git a/linker/Tests/TestCases/Linker/Interface/desc.xml b/linker/Tests/TestCases/Linker/Interface/desc.xml new file mode 100644 index 000000000..0dd61b9b3 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Interface/desc.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="Library"> + <type fullname="Foo" /> + </assembly> +</linker> diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Bar.cs b/linker/Tests/TestCases/Linker/MultipleReferences/Bar.cs new file mode 100644 index 000000000..c2f0df4fd --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Bar.cs @@ -0,0 +1,15 @@ +using System; + +public class Bar { + + string bang = "bang !"; + + public Bar () + { + } + + public void Bang () + { + Console.WriteLine (bang); + } +} diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Bar.dll b/linker/Tests/TestCases/Linker/MultipleReferences/Bar.dll Binary files differnew file mode 100644 index 000000000..3edf8a7c8 --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Bar.dll diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Baz.cs b/linker/Tests/TestCases/Linker/MultipleReferences/Baz.cs new file mode 100644 index 000000000..ab5241ccf --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Baz.cs @@ -0,0 +1,13 @@ +using System; + +public class Baz { + + public void Chain (Foo f) + { + f.b.Bang (); + } + + [NotLinked] public void Lurman () + { + } +} diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Baz.dll b/linker/Tests/TestCases/Linker/MultipleReferences/Baz.dll Binary files differnew file mode 100644 index 000000000..7e56d0359 --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Baz.dll diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Foo.cs b/linker/Tests/TestCases/Linker/MultipleReferences/Foo.cs new file mode 100644 index 000000000..746a2b26f --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Foo.cs @@ -0,0 +1,20 @@ +using System; + +public class Foo { + + public Bar b; + + public Foo (Bar b) + { + this.b = b; + } + + public void UseBar () + { + b.Bang (); + } + + [NotLinked] public void Blam () + { + } +} diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Foo.dll b/linker/Tests/TestCases/Linker/MultipleReferences/Foo.dll Binary files differnew file mode 100644 index 000000000..5b2518edf --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Foo.dll diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Makefile b/linker/Tests/TestCases/Linker/MultipleReferences/Makefile new file mode 100644 index 000000000..28e392697 --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Makefile @@ -0,0 +1,7 @@ +include ../../config.make + +all: + MCS /t:library NotLinkedAttribute.cs + MCS /t:library Bar.cs + MCS /t:library /r:Bar.dll /r:NotLinkedAttribute.dll Foo.cs + MCS /t:library /r:Foo.dll /r:Bar.dll /r:NotLinkedAttribute.dll Baz.cs diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/NotLinkedAttribute.cs b/linker/Tests/TestCases/Linker/MultipleReferences/NotLinkedAttribute.cs new file mode 100644 index 000000000..52903442d --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/NotLinkedAttribute.cs @@ -0,0 +1,5 @@ +using System; + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/NotLinkedAttribute.dll b/linker/Tests/TestCases/Linker/MultipleReferences/NotLinkedAttribute.dll Binary files differnew file mode 100644 index 000000000..a61728004 --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/NotLinkedAttribute.dll diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Program.cs b/linker/Tests/TestCases/Linker/MultipleReferences/Program.cs new file mode 100644 index 000000000..1a2d2d851 --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Program.cs @@ -0,0 +1,15 @@ +using System; + +public class Program { + + public static int Main () + { + Foo f = new Foo (new Bar ()); + f.UseBar (); + + Baz b = new Baz (); + b.Chain (f); + + return 0; + } +} diff --git a/linker/Tests/TestCases/Linker/MultipleReferences/Program.exe b/linker/Tests/TestCases/Linker/MultipleReferences/Program.exe Binary files differnew file mode 100644 index 000000000..abdc5fef2 --- /dev/null +++ b/linker/Tests/TestCases/Linker/MultipleReferences/Program.exe diff --git a/linker/Tests/TestCases/Linker/NestedNested/Library.cs b/linker/Tests/TestCases/Linker/NestedNested/Library.cs new file mode 100644 index 000000000..139116244 --- /dev/null +++ b/linker/Tests/TestCases/Linker/NestedNested/Library.cs @@ -0,0 +1,17 @@ +using System; + +public class Foo { +} + +[NotLinked] public class Bar { + + [NotLinked] public class Baz { + + [NotLinked] public class Gazonk { + } + } +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/NestedNested/Library.dll b/linker/Tests/TestCases/Linker/NestedNested/Library.dll Binary files differnew file mode 100644 index 000000000..49151f106 --- /dev/null +++ b/linker/Tests/TestCases/Linker/NestedNested/Library.dll diff --git a/linker/Tests/TestCases/Linker/NestedNested/Makefile b/linker/Tests/TestCases/Linker/NestedNested/Makefile new file mode 100644 index 000000000..2e5bf5bcf --- /dev/null +++ b/linker/Tests/TestCases/Linker/NestedNested/Makefile @@ -0,0 +1,4 @@ +include ../../config.make + +all: + MCS /t:library Library.cs diff --git a/linker/Tests/TestCases/Linker/NestedNested/desc.xml b/linker/Tests/TestCases/Linker/NestedNested/desc.xml new file mode 100644 index 000000000..0dd61b9b3 --- /dev/null +++ b/linker/Tests/TestCases/Linker/NestedNested/desc.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="Library"> + <type fullname="Foo" /> + </assembly> +</linker> diff --git a/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Library.cs b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Library.cs new file mode 100644 index 000000000..63a5ee7e2 --- /dev/null +++ b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Library.cs @@ -0,0 +1,34 @@ +using System; + +public class Foo { + + public Foo () + { + new NotRequiredButUsedNotPreserved (); + new NotRequiredButUsedAndFieldsPreserved (); + } +} + +public class NotRequiredButUsedNotPreserved { + + [NotLinked] public int foo; + [NotLinked] public int bar; +} + +public class NotRequiredButUsedAndFieldsPreserved { + + public int foo; + public int bar; + + [NotLinked] public int FooBar () + { + return foo + bar; + } +} + +[NotLinked] public class NotRequiredAndNotUsed { +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Library.dll b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Library.dll Binary files differnew file mode 100755 index 000000000..941d6c39d --- /dev/null +++ b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Library.dll diff --git a/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Makefile b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Makefile new file mode 100644 index 000000000..2e5bf5bcf --- /dev/null +++ b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/Makefile @@ -0,0 +1,4 @@ +include ../../config.make + +all: + MCS /t:library Library.cs diff --git a/linker/Tests/TestCases/Linker/PreserveFieldsRequired/desc.xml b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/desc.xml new file mode 100644 index 000000000..979d4e05c --- /dev/null +++ b/linker/Tests/TestCases/Linker/PreserveFieldsRequired/desc.xml @@ -0,0 +1,7 @@ +<linker> + <assembly fullname="Library"> + <type fullname="Foo" /> + <type fullname="NotRequiredButUsedNotPreserved" preserve="nothing" required="false" /> + <type fullname="NotRequiredButUsedAndFieldsPreserved" preserve="fields" required="false" /> + </assembly> +</linker> diff --git a/linker/Tests/TestCases/Linker/ReferenceInAttributes/LibLib.cs b/linker/Tests/TestCases/Linker/ReferenceInAttributes/LibLib.cs new file mode 100644 index 000000000..6ca5a7f13 --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInAttributes/LibLib.cs @@ -0,0 +1,23 @@ +using System; + +namespace LibLib { + + public class LibLibAttribute : Attribute { + + public Type LibLibType { + [NotLinked] get { return null; } + set {} + } + } + + public class BilBil { + + [NotLinked] public BilBil () + { + } + } +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/ReferenceInAttributes/LibLib.dll b/linker/Tests/TestCases/Linker/ReferenceInAttributes/LibLib.dll Binary files differnew file mode 100755 index 000000000..2f1e45788 --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInAttributes/LibLib.dll diff --git a/linker/Tests/TestCases/Linker/ReferenceInAttributes/Library.cs b/linker/Tests/TestCases/Linker/ReferenceInAttributes/Library.cs new file mode 100644 index 000000000..cb3903f3c --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInAttributes/Library.cs @@ -0,0 +1,71 @@ +using System; +using LibLib; + +public class BarAttribute : Attribute { + + public BarAttribute () + { + } + + public BarAttribute (Type type) + { + } + + public Type FieldType; + + public Type PropertyType { + [NotLinked] get { return null; } + set {} + } +} + +[Bar (typeof (Guy_A))] +public class Foo { + + [Bar (FieldType = typeof (Guy_B))] + public Foo a; + + [Bar (PropertyType = typeof (Guy_C))] + public Foo b; + + [LibLib (LibLibType = typeof (BilBil))] + public Foo c; + + [LibLib (LibLibType = typeof (Guy_D))] + public Foo d; +} + +public class Guy_A { + + [NotLinked] public Guy_A () + { + } +} + +public class Guy_B { + + [NotLinked] public Guy_B () + { + } +} + +public class Guy_C { + + [NotLinked] public Guy_C () + { + } +} + +public class Guy_D { + + [NotLinked] public Guy_D () + { + } +} + +[NotLinked] public class Baz { +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/ReferenceInAttributes/Library.dll b/linker/Tests/TestCases/Linker/ReferenceInAttributes/Library.dll Binary files differnew file mode 100755 index 000000000..7c5b99700 --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInAttributes/Library.dll diff --git a/linker/Tests/TestCases/Linker/ReferenceInAttributes/desc.xml b/linker/Tests/TestCases/Linker/ReferenceInAttributes/desc.xml new file mode 100644 index 000000000..0dd61b9b3 --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInAttributes/desc.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="Library"> + <type fullname="Foo" /> + </assembly> +</linker> diff --git a/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Library.cs b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Library.cs new file mode 100644 index 000000000..8b840b4cc --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Library.cs @@ -0,0 +1,35 @@ + +using System; + +public class Foo { + + public void Do () + { + Bar b = new Baz (); + b.Bang (); + } +} + +public class Bar { + + public virtual void Bang () + { + } +} + +public class Baz : Bar { + + private string _hey; + + public string Hey { + [NotLinked] get { return _hey; } + [NotLinked] set { _hey = value; } + } + + public override void Bang () + { + Console.WriteLine (_hey); + } +} + +[NotLinked] public class NotLinkedAttribute : Attribute {}
\ No newline at end of file diff --git a/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Library.dll b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Library.dll Binary files differnew file mode 100644 index 000000000..b56fa604f --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Library.dll diff --git a/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Makefile b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Makefile new file mode 100644 index 000000000..2e5bf5bcf --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/Makefile @@ -0,0 +1,4 @@ +include ../../config.make + +all: + MCS /t:library Library.cs diff --git a/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/desc.xml b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/desc.xml new file mode 100644 index 000000000..0dd61b9b3 --- /dev/null +++ b/linker/Tests/TestCases/Linker/ReferenceInVirtualMethod/desc.xml @@ -0,0 +1,5 @@ +<linker> + <assembly fullname="Library"> + <type fullname="Foo" /> + </assembly> +</linker> diff --git a/linker/Tests/TestCases/Linker/Simple/Library.cs b/linker/Tests/TestCases/Linker/Simple/Library.cs new file mode 100644 index 000000000..538205a7c --- /dev/null +++ b/linker/Tests/TestCases/Linker/Simple/Library.cs @@ -0,0 +1,37 @@ +using System; + +public class Library { + + private int _pouet; + [NotLinked] private int _hey; + + public Library () + { + _pouet = 1; + } + + [NotLinked] public Library (int pouet) + { + _pouet = pouet; + } + + public int Hello () + { + Console.WriteLine ("Hello"); + return _pouet; + } + + [NotLinked] public void Hey (int hey) + { + _hey = hey; + Console.WriteLine (_hey); + } +} + + +[NotLinked] public class Toy { +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/Simple/Library.dll b/linker/Tests/TestCases/Linker/Simple/Library.dll Binary files differnew file mode 100644 index 000000000..06f1b3889 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Simple/Library.dll diff --git a/linker/Tests/TestCases/Linker/Simple/Makefile b/linker/Tests/TestCases/Linker/Simple/Makefile new file mode 100644 index 000000000..356b52945 --- /dev/null +++ b/linker/Tests/TestCases/Linker/Simple/Makefile @@ -0,0 +1,5 @@ +include ../../config.make + +all: + MCS /t:library Library.cs + MCS /r:Library.dll Program.cs diff --git a/linker/Tests/TestCases/Linker/Simple/Program.cs b/linker/Tests/TestCases/Linker/Simple/Program.cs new file mode 100644 index 000000000..e597acb6c --- /dev/null +++ b/linker/Tests/TestCases/Linker/Simple/Program.cs @@ -0,0 +1,10 @@ +using System; + +public class Program { + + public static int Main () + { + Library lib = new Library (); + return lib.Hello (); + } +} diff --git a/linker/Tests/TestCases/Linker/Simple/Program.exe b/linker/Tests/TestCases/Linker/Simple/Program.exe Binary files differnew file mode 100644 index 000000000..c32ca45af --- /dev/null +++ b/linker/Tests/TestCases/Linker/Simple/Program.exe diff --git a/linker/Tests/TestCases/Linker/SimpleXml/Library.cs b/linker/Tests/TestCases/Linker/SimpleXml/Library.cs new file mode 100644 index 000000000..4e81b428a --- /dev/null +++ b/linker/Tests/TestCases/Linker/SimpleXml/Library.cs @@ -0,0 +1,44 @@ +using System; + +public class Foo { + + int _baz; + [NotLinked] int _shebang; + + public Foo () + { + _baz = 42; + } + + public int Baz () + { + return _baz; + } + + [NotLinked] public int Shebang (int bang) + { + return _shebang = bang * 2; + } +} + +public class Bar { + + int _truc; + + public Bar () + { + _truc = 12; + } + + public int Truc () + { + return _truc; + } +} + +[NotLinked] public class Gazonk { +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/SimpleXml/Library.dll b/linker/Tests/TestCases/Linker/SimpleXml/Library.dll Binary files differnew file mode 100644 index 000000000..c37c05985 --- /dev/null +++ b/linker/Tests/TestCases/Linker/SimpleXml/Library.dll diff --git a/linker/Tests/TestCases/Linker/SimpleXml/Makefile b/linker/Tests/TestCases/Linker/SimpleXml/Makefile new file mode 100644 index 000000000..2e5bf5bcf --- /dev/null +++ b/linker/Tests/TestCases/Linker/SimpleXml/Makefile @@ -0,0 +1,4 @@ +include ../../config.make + +all: + MCS /t:library Library.cs diff --git a/linker/Tests/TestCases/Linker/SimpleXml/desc.xml b/linker/Tests/TestCases/Linker/SimpleXml/desc.xml new file mode 100644 index 000000000..2a20ed324 --- /dev/null +++ b/linker/Tests/TestCases/Linker/SimpleXml/desc.xml @@ -0,0 +1,10 @@ +<linker> + <assembly fullname="Library"> + <type fullname="Foo"> + <field signature="System.Int32 _baz" /> + <method signature="System.Void .ctor()" /> + <method signature="System.Int32 Baz()" /> + </type> + <type fullname="Bar" /> + </assembly> +</linker> diff --git a/linker/Tests/TestCases/Linker/VirtualCall/Library.cs b/linker/Tests/TestCases/Linker/VirtualCall/Library.cs new file mode 100644 index 000000000..b9c3f02f1 --- /dev/null +++ b/linker/Tests/TestCases/Linker/VirtualCall/Library.cs @@ -0,0 +1,31 @@ +using System; + +public class Library { + + public Library () + { + } + + public int Shebang () + { + return Bang (); + } + + protected virtual int Bang () + { + return 1; + } +} + + +public class PowerFulLibrary : Library { + + protected override int Bang () + { + return 0; + } +} + +[NotLinked, AttributeUsage (AttributeTargets.All)] +public class NotLinkedAttribute : Attribute { +} diff --git a/linker/Tests/TestCases/Linker/VirtualCall/Library.dll b/linker/Tests/TestCases/Linker/VirtualCall/Library.dll Binary files differnew file mode 100644 index 000000000..4bfd5b38b --- /dev/null +++ b/linker/Tests/TestCases/Linker/VirtualCall/Library.dll diff --git a/linker/Tests/TestCases/Linker/VirtualCall/Makefile b/linker/Tests/TestCases/Linker/VirtualCall/Makefile new file mode 100644 index 000000000..356b52945 --- /dev/null +++ b/linker/Tests/TestCases/Linker/VirtualCall/Makefile @@ -0,0 +1,5 @@ +include ../../config.make + +all: + MCS /t:library Library.cs + MCS /r:Library.dll Program.cs diff --git a/linker/Tests/TestCases/Linker/VirtualCall/Program.cs b/linker/Tests/TestCases/Linker/VirtualCall/Program.cs new file mode 100644 index 000000000..aa0467a59 --- /dev/null +++ b/linker/Tests/TestCases/Linker/VirtualCall/Program.cs @@ -0,0 +1,10 @@ +using System; + +public class Program { + + public static int Main () + { + Library lib = new PowerFulLibrary (); + return lib.Shebang (); + } +} diff --git a/linker/Tests/TestCases/Linker/VirtualCall/Program.exe b/linker/Tests/TestCases/Linker/VirtualCall/Program.exe Binary files differnew file mode 100644 index 000000000..eee22f3c2 --- /dev/null +++ b/linker/Tests/TestCases/Linker/VirtualCall/Program.exe diff --git a/linker/Tests/TestCases/config.make b/linker/Tests/TestCases/config.make new file mode 100644 index 000000000..8323eb2a8 --- /dev/null +++ b/linker/Tests/TestCases/config.make @@ -0,0 +1,3 @@ + +MCS = mcs + |