Browse Source

Add test for function templates

refactor
josetr 3 years ago
parent
commit
17f69fdf64
  1. 8
      tests/CSharp/CSharp.Tests.cs
  2. 18
      tests/CSharp/CSharpTemplates.h

8
tests/CSharp/CSharp.Tests.cs

@ -1900,4 +1900,12 @@ public unsafe class CSharpTests @@ -1900,4 +1900,12 @@ public unsafe class CSharpTests
{
return type.GetMethods(BindingFlags.NonPublic | BindingFlags.Static).Any(x => x.Name.Contains("NativeToManaged"));
}
[Test]
public void TestFunctionTemplate()
{
Assert.That(CSharpTemplates.FunctionTemplate(5.0), Is.EqualTo(5 + 4.2));
Assert.That(CSharpTemplates.FunctionTemplate(6f), Is.EqualTo(6 + 4.1f));
Assert.That(CSharpTemplates.FunctionTemplate(7), Is.EqualTo(7 + 4));
}
}

18
tests/CSharp/CSharpTemplates.h

@ -945,6 +945,22 @@ public: @@ -945,6 +945,22 @@ public:
};
const FloatArrayF<6> I6{ 1., 1., 1., 0., 0., 0. };
template <typename T>
DLL_API inline T FunctionTemplate(T value) {
if (std::is_same<T, double>::value)
return 4.2 + value;
else if (std::is_same<T, float>::value)
return 4.1 + value;
return 4 + value;
}
inline void FunctionTemplateInstantiation()
{
FunctionTemplate<double>({});
FunctionTemplate<float>({});
FunctionTemplate<int>({});
}
// KEEP ORDER OTHERWISE TEST WONT WORK
namespace IncompleteClassTemplatesTests
{
@ -962,4 +978,4 @@ namespace IncompleteClassTemplatesTests @@ -962,4 +978,4 @@ namespace IncompleteClassTemplatesTests
{
StructT<StructSizeT<4000>> st;
};
}
}

Loading…
Cancel
Save