Skip to content

Commit

Permalink
Fixed issue compiling unit tests
Browse files Browse the repository at this point in the history
For some reason had to define ToString() methods as exact template specializations of unit test framework type rather than matching overloads.
  • Loading branch information
mattnewport committed Feb 10, 2019
1 parent eeed01c commit d876009
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 332 deletions.
5 changes: 0 additions & 5 deletions MathLib/include/mathio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ auto& operator<<(std::basic_ostream<CharT>& os, const Matrix<T, M, N>& x) {
return os;
}

template <typename T, typename CharT>
auto& operator<<(std::basic_ostream<CharT>& os, const Quaternion<T>& x) {
return os << x.vec4();
}

} // namespace mathlib
3 changes: 3 additions & 0 deletions UnitTests/UnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="matrixasserthelpers.h" />
<ClInclude Include="quaternionasserthelpers.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="unittestwrapper.h" />
<ClInclude Include="vectorasserthelpers.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="mathfunctests.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions UnitTests/UnitTests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
<ClInclude Include="unittestwrapper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="vectorasserthelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="quaternionasserthelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="matrixasserthelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down
16 changes: 5 additions & 11 deletions UnitTests/mathfunctests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@
#include "vector.h"
#include "vectorio.h"

#include "vectorasserthelpers.h"

using namespace mathlib;

using namespace std::literals;

namespace Microsoft {
namespace VisualStudio {
namespace CppUnitTestFramework {
template <typename T, size_t N>
auto ToString(const mathlib::Vector<T, N>& x) { RETURN_WIDE_STRING(x); }
}
}
}


namespace UnitTests {

template<typename T>
Expand All @@ -43,7 +35,9 @@ TEST_CLASS(FuncsUnitTests) {

TEST_METHOD(TestAbs) {
constexpr auto v0 = Vec3f{ -0.5f, 2.0f, 1.1f };
const auto v2 = abs(v0);
const Vec3f v2 = abs(v0);
auto s = ToString(v2);
const auto same = v2 == Vec3f{0.5f, 2.0f, 1.1f};
Assert::AreEqual(v2, Vec3f{ 0.5f, 2.0f, 1.1f });
}

Expand Down
33 changes: 33 additions & 0 deletions UnitTests/matrixasserthelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "unittestwrapper.h"

#include "matrix.h"
#include "mathio.h"

namespace Microsoft {
namespace VisualStudio {
namespace CppUnitTestFramework {
template <typename T, size_t M, size_t N>
auto ToStringHelper(const mathlib::Matrix<T, M, N>& x) {
RETURN_WIDE_STRING(x);
}

template <>
std::wstring ToString<mathlib::Mat4f>(const mathlib::Mat4f& x) {
return ToStringHelper(x);
}

template <>
std::wstring ToString<mathlib::Matrix<float, 3, 4>>(const mathlib::Matrix<float, 3, 4>& x) {
return ToStringHelper(x);
}

template <>
std::wstring ToString<mathlib::Matrix<float, 2, 3>>(const mathlib::Matrix<float, 2, 3>& x) {
return ToStringHelper(x);
}

} // namespace CppUnitTestFramework
} // namespace VisualStudio
} // namespace Microsoft
23 changes: 23 additions & 0 deletions UnitTests/quaternionasserthelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "unittestwrapper.h"

#include "quaternion.h"
#include "quaternionio.h"

namespace Microsoft {
namespace VisualStudio {
namespace CppUnitTestFramework {
template <typename T>
auto ToStringHelper(const mathlib::Quaternion<T>& x) {
RETURN_WIDE_STRING(x);
}

template <>
std::wstring ToString<mathlib::Quatf>(const mathlib::Quatf& x) {
return ToStringHelper(x);
}

} // namespace CppUnitTestFramework
} // namespace VisualStudio
} // namespace Microsoft
18 changes: 3 additions & 15 deletions UnitTests/quaterniontests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "quaternion.h"
#include "quaternionio.h"

#include "vectorasserthelpers.h"
#include "quaternionasserthelpers.h"

#if defined(__clang__)
#elif defined(_MSC_VER)
#include <DirectXMath.h>
Expand All @@ -21,21 +24,6 @@ using namespace mathlib;

using namespace std::literals;

namespace Microsoft {
namespace VisualStudio {
namespace CppUnitTestFramework {
template <typename T, size_t N>
auto ToString(const Vector<T, N>& x) {
RETURN_WIDE_STRING(x);
}
template <typename T>
auto ToString(const Quaternion<T>& x) {
RETURN_WIDE_STRING(x);
}
} // namespace CppUnitTestFramework
} // namespace VisualStudio
} // namespace Microsoft

namespace UnitTests {

template <typename T>
Expand Down
Loading

0 comments on commit d876009

Please sign in to comment.