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)
{ {
"CppSharp.AST", "CppSharp.AST",
"CppSharp.Generator", "CppSharp.Generator",
"CppSharp.Generator.Tests"
} }
SetupParser() SetupParser()
@ -110,7 +111,7 @@ function SetupTestProjectsCSharp(name, file, lib)
SetupManagedTestProject() SetupManagedTestProject()
files { name .. ".Tests.cs" } files { name .. ".Tests.cs" }
links { name .. ".CSharp" } links { name .. ".CSharp", "CppSharp.Generator.Tests" }
dependson { name .. ".Native" } dependson { name .. ".Native" }
LinkNUnit() LinkNUnit()
@ -141,7 +142,7 @@ function SetupTestProjectsCLI(name, file, lib)
SetupManagedTestProject() SetupManagedTestProject()
files { name .. ".Tests.cs" } files { name .. ".Tests.cs" }
links { name .. ".CLI" } links { name .. ".CLI", "CppSharp.Generator.Tests" }
dependson { name .. ".Native" } dependson { name .. ".Native" }
LinkNUnit() LinkNUnit()

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

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

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

@ -2,55 +2,24 @@
using System.IO; using System.IO;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Generators; using CppSharp.Generators;
using NUnit.Framework;
namespace CppSharp.Utils 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 string name;
readonly GeneratorKind kind; readonly GeneratorKind kind;
protected LibraryTest(string name, GeneratorKind kind) protected GeneratorTest(string name, GeneratorKind kind)
{ {
this.name = name; this.name = name;
this.kind = kind; 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) public virtual void Setup(Driver driver)
{ {
var options = driver.Options; var options = driver.Options;
@ -96,5 +65,55 @@ namespace CppSharp.Utils
public virtual void SetupPasses(Driver driver) 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;
namespace CppSharp.Generator.Tests.Passes namespace CppSharp.Generator.Tests.Passes
{ {
[TestFixture] [TestFixture]
public class TestPasses : HeaderTestFixture public class TestPasses : ASTTestFixture
{ {
private PassBuilder<TranslationUnitPass> passBuilder; private PassBuilder<TranslationUnitPass> passBuilder;

5
tests/Basic/Basic.Tests.cs

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

2
tests/Basic/Basic.cs

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

3
tests/CLITemp/CLITemp.Tests.cs

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

2
tests/CLITemp/CLITemp.cs

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

3
tests/CSharpTemp/CSharpTemp.Tests.cs

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

2
tests/CSharpTemp/CSharpTemp.cs

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

3
tests/STL/STL.Tests.cs

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

2
tests/STL/STL.cs

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

4
tests/UTF16/UTF16.Tests.cs

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

2
tests/UTF16/UTF16.cs

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

3
tests/VTables/VTables.Tests.cs

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

2
tests/VTables/VTables.cs

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

Loading…
Cancel
Save