Browse Source

Fix CheckStaticClass pass and add test. (#795)

pull/796/head
Abhinav Tripathi 10 years ago committed by Dimitar Dobrev
parent
commit
91fcfd0b5c
  1. 4
      src/Generator/Passes/CheckStaticClass.cs
  2. 3
      tests/Common/Common.Tests.cs
  3. 5
      tests/Common/Common.cpp
  4. 5
      tests/Common/Common.h

4
src/Generator/Passes/CheckStaticClass.cs

@ -90,8 +90,8 @@ namespace CppSharp.Passes @@ -90,8 +90,8 @@ namespace CppSharp.Passes
// If one exists, we assume it's a factory function and the class is
// not meant to be static. It's a simple heuristic but it should be
// good enough for the time being.
if (@class.Functions.Any(ReturnsClassInstance) ||
@class.Methods.Any(ReturnsClassInstance))
if (@class.Functions.Any(m => !m.IsOperator && ReturnsClassInstance(m)) ||
@class.Methods.Any(m => !m.IsOperator && ReturnsClassInstance(m)))
return false;
// If the class is to be used as an opaque type, then it cannot be

3
tests/Common/Common.Tests.cs

@ -342,6 +342,9 @@ public class CommonTests : GeneratorTestFixture @@ -342,6 +342,9 @@ public class CommonTests : GeneratorTestFixture
[Test]
public void TestStaticClasses()
{
Type staticClassType = typeof(TestStaticClass);
// Only static class can be both abstract and sealed
Assert.IsTrue(staticClassType.IsAbstract && staticClassType.IsSealed);
Assert.That(TestStaticClass.Add(1, 2), Is.EqualTo(3));
Assert.That(TestStaticClass.OneTwoThree, Is.EqualTo(123));
Assert.That(TestStaticClassDerived.Foo, Is.EqualTo(0));

5
tests/Common/Common.cpp

@ -673,3 +673,8 @@ void hasPointerParam(const Foo& foo) @@ -673,3 +673,8 @@ void hasPointerParam(const Foo& foo)
void sMallFollowedByCapital()
{
}
TestStaticClass& TestStaticClass::operator=(const TestStaticClass& oth)
{
return *this;
}

5
tests/Common/Common.h

@ -388,13 +388,14 @@ struct DLL_API TestStaticClass @@ -388,13 +388,14 @@ struct DLL_API TestStaticClass
static int GetOneTwoThree();
protected:
TestStaticClass& operator=(const TestStaticClass& oth);
private:
static int _Mult(int a, int b);
static int GetFourFiveSix();
private:
TestStaticClass();
};

Loading…
Cancel
Save