Browse Source

Move all the testing infrastructure to CppSharp.Generator.Tests.

pull/146/merge
triton 12 years ago
parent
commit
1b7947538a
  1. 5
      build/Tests.lua
  2. 5
      src/Generator.Tests/ASTTestFixture.cs
  3. 93
      src/Generator.Tests/GeneratorTest.cs
  4. 2
      src/Generator.Tests/Passes/TestPasses.cs
  5. 5
      tests/Basic/Basic.Tests.cs
  6. 2
      tests/Basic/Basic.cs
  7. 3
      tests/CLITemp/CLITemp.Tests.cs
  8. 2
      tests/CLITemp/CLITemp.cs
  9. 3
      tests/CSharpTemp/CSharpTemp.Tests.cs
  10. 2
      tests/CSharpTemp/CSharpTemp.cs
  11. 3
      tests/STL/STL.Tests.cs
  12. 2
      tests/STL/STL.cs
  13. 4
      tests/UTF16/UTF16.Tests.cs
  14. 2
      tests/UTF16/UTF16.cs
  15. 3
      tests/VTables/VTables.Tests.cs
  16. 2
      tests/VTables/VTables.cs

5
build/Tests.lua

@ -51,6 +51,7 @@ function SetupTestGeneratorProject(name) @@ -51,6 +51,7 @@ function SetupTestGeneratorProject(name)
{
"CppSharp.AST",
"CppSharp.Generator",
"CppSharp.Generator.Tests"
}
SetupParser()
@ -110,7 +111,7 @@ function SetupTestProjectsCSharp(name, file, lib) @@ -110,7 +111,7 @@ function SetupTestProjectsCSharp(name, file, lib)
SetupManagedTestProject()
files { name .. ".Tests.cs" }
links { name .. ".CSharp" }
links { name .. ".CSharp", "CppSharp.Generator.Tests" }
dependson { name .. ".Native" }
LinkNUnit()
@ -141,7 +142,7 @@ function SetupTestProjectsCLI(name, file, lib) @@ -141,7 +142,7 @@ function SetupTestProjectsCLI(name, file, lib)
SetupManagedTestProject()
files { name .. ".Tests.cs" }
links { name .. ".CLI" }
links { name .. ".CLI", "CppSharp.Generator.Tests" }
dependson { name .. ".Native" }
LinkNUnit()

5
src/Generator.Tests/HeaderTestFixture.cs → src/Generator.Tests/ASTTestFixture.cs

@ -1,11 +1,10 @@ @@ -1,11 +1,10 @@
using System;
using System.IO;
using CppSharp.AST;
using CppSharp.Utils;
namespace CppSharp.Generator.Tests
{
public class HeaderTestFixture
public class ASTTestFixture
{
protected Driver Driver;
protected DriverOptions Options;
@ -15,7 +14,7 @@ namespace CppSharp.Generator.Tests @@ -15,7 +14,7 @@ namespace CppSharp.Generator.Tests
{
Options = new DriverOptions();
var testsPath = LibraryTest.GetTestsDirectory("Native");
var testsPath = GeneratorTest.GetTestsDirectory("Native");
#if OLD_PARSER
Options.IncludeDirs.Add(testsPath);

93
src/Generator/Utils/TestsUtils.cs → src/Generator.Tests/GeneratorTest.cs

@ -2,55 +2,24 @@ @@ -2,55 +2,24 @@
using System.IO;
using CppSharp.AST;
using CppSharp.Generators;
using NUnit.Framework;
namespace CppSharp.Utils
{
public abstract class LibraryTest : ILibrary
/// <summary>
/// The main base class for a generator-based tests project.
/// </summary>
public abstract class GeneratorTest : ILibrary
{
readonly string name;
readonly GeneratorKind kind;
protected LibraryTest(string name, GeneratorKind kind)
protected GeneratorTest(string name, GeneratorKind kind)
{
this.name = name;
this.kind = kind;
}
public static string GetTestsDirectory(string name)
{
var directory = Directory.GetParent(Directory.GetCurrentDirectory());
while (directory != null)
{
var path = Path.Combine(directory.FullName, "tests", name);
if (Directory.Exists(path))
return path;
directory = directory.Parent;
}
throw new Exception(string.Format(
"Tests directory for project '{0}' was not found", name));
}
static string GetOutputDirectory()
{
var directory = Directory.GetParent(Directory.GetCurrentDirectory());
while (directory != null)
{
var path = Path.Combine(directory.FullName, "obj");
if (Directory.Exists(path))
return directory.FullName;
directory = directory.Parent;
}
throw new Exception("Could not find tests output directory");
}
public virtual void Setup(Driver driver)
{
var options = driver.Options;
@ -96,5 +65,55 @@ namespace CppSharp.Utils @@ -96,5 +65,55 @@ namespace CppSharp.Utils
public virtual void SetupPasses(Driver driver)
{
}
#region Helpers
public static string GetTestsDirectory(string name)
{
var directory = Directory.GetParent(Directory.GetCurrentDirectory());
while (directory != null)
{
var path = Path.Combine(directory.FullName, "tests", name);
if (Directory.Exists(path))
return path;
directory = directory.Parent;
}
throw new Exception(string.Format(
"Tests directory for project '{0}' was not found", name));
}
static string GetOutputDirectory()
{
var directory = Directory.GetParent(Directory.GetCurrentDirectory());
while (directory != null)
{
var path = Path.Combine(directory.FullName, "obj");
if (Directory.Exists(path))
return directory.FullName;
directory = directory.Parent;
}
throw new Exception("Could not find tests output directory");
}
#endregion
}
/// <summary>
/// The main NUnit fixture base class for a generator-based tests project.
/// Provides support for a text-based test system that looks for lines
/// in the native test declarations that match a certain pattern, which
/// are used for certain kinds of tests that cannot be done with just
/// C# code and using the generated wrappers.
/// </summary>
[TestFixture]
public class GeneratorTestFixture
{
}
}

2
src/Generator.Tests/Passes/TestPasses.cs

@ -4,7 +4,7 @@ using NUnit.Framework; @@ -4,7 +4,7 @@ using NUnit.Framework;
namespace CppSharp.Generator.Tests.Passes
{
[TestFixture]
public class TestPasses : HeaderTestFixture
public class TestPasses : ASTTestFixture
{
private PassBuilder<TranslationUnitPass> passBuilder;

5
tests/Basic/Basic.Tests.cs

@ -1,8 +1,9 @@ @@ -1,8 +1,9 @@
using NUnit.Framework;
using CppSharp.Utils;
using NUnit.Framework;
using Basic;
[TestFixture]
public class BasicTests
public class BasicTests : GeneratorTestFixture
{
[Test]
public void TestHello()

2
tests/Basic/Basic.cs

@ -4,7 +4,7 @@ using CppSharp.Utils; @@ -4,7 +4,7 @@ using CppSharp.Utils;
namespace CppSharp.Tests
{
public class Basic : LibraryTest
public class Basic : GeneratorTest
{
public Basic(GeneratorKind kind)
: base("Basic", kind)

3
tests/CLITemp/CLITemp.Tests.cs

@ -1,8 +1,9 @@ @@ -1,8 +1,9 @@
using CppSharp.Utils;
using NUnit.Framework;
using CLITemp;
[TestFixture]
public class CLITests
public class CLITests : GeneratorTestFixture
{
[Test]
public void TestTypes()

2
tests/CLITemp/CLITemp.cs

@ -4,7 +4,7 @@ using CppSharp.Utils; @@ -4,7 +4,7 @@ using CppSharp.Utils;
namespace CppSharp.Tests
{
public class CLITemp : LibraryTest
public class CLITemp : GeneratorTest
{
public CLITemp(GeneratorKind kind)
: base("CLITemp", kind)

3
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
using System;
using System.Reflection;
using CSharpTemp;
using CppSharp.Utils;
using NUnit.Framework;
using Foo = CSharpTemp.Foo;
[TestFixture]
public class CSharpTempTests
public class CSharpTempTests : GeneratorTestFixture
{
[Test]
public void TestIndexer()

2
tests/CSharpTemp/CSharpTemp.cs

@ -49,7 +49,7 @@ namespace CppSharp.Tests @@ -49,7 +49,7 @@ namespace CppSharp.Tests
}
}
public class CSharpTempTests : LibraryTest
public class CSharpTempTests : GeneratorTest
{
public CSharpTempTests(GeneratorKind kind)
: base("CSharpTemp", kind)

3
tests/STL/STL.Tests.cs

@ -1,9 +1,10 @@ @@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using CppSharp.Utils;
using NUnit.Framework;
[TestFixture]
public class STLTests
public class STLTests : GeneratorTestFixture
{
[Test]
public void TestVectors()

2
tests/STL/STL.cs

@ -4,7 +4,7 @@ using CppSharp.Utils; @@ -4,7 +4,7 @@ using CppSharp.Utils;
namespace CppSharp.Tests
{
public class STL : LibraryTest
public class STL : GeneratorTest
{
public STL(GeneratorKind kind)
: base("STL", kind)

4
tests/UTF16/UTF16.Tests.cs

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
using System;
using CppSharp.Utils;
using NUnit.Framework;
using Foo = UTF16.Foo;
[TestFixture]
public class UTF16Tests
public class UTF16Tests : GeneratorTestFixture
{
[Test]
public void TestFoo()

2
tests/UTF16/UTF16.cs

@ -5,7 +5,7 @@ using CppSharp.Utils; @@ -5,7 +5,7 @@ using CppSharp.Utils;
namespace CppSharp.Tests
{
public class UTF16Tests : LibraryTest
public class UTF16Tests : GeneratorTest
{
public UTF16Tests(GeneratorKind kind)
: base("UTF16", kind)

3
tests/VTables/VTables.Tests.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using CppSharp.Utils;
using NUnit.Framework;
using VTables;
@ -12,7 +13,7 @@ public class FooDerived : Foo @@ -12,7 +13,7 @@ public class FooDerived : Foo
}
[TestFixture]
public class VTablesTests
public class VTablesTests : GeneratorTestFixture
{
[Test]
public void TestFoo()

2
tests/VTables/VTables.cs

@ -5,7 +5,7 @@ using CppSharp.Utils; @@ -5,7 +5,7 @@ using CppSharp.Utils;
namespace CppSharp.Tests
{
public class VTableTests : LibraryTest
public class VTableTests : GeneratorTest
{
public VTableTests(GeneratorKind kind)
: base("VTables", kind)

Loading…
Cancel
Save