I'm currently getting the following error for a Visual Studio 2013 C++/CLI Native Unit Test.
error C2338: Test writer must define specialization of ToString<const Q& q> for your class class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl Microsoft::VisualStudio::CppUnitTestFramework::ToString<class LTI::IPCommon::CPPBoxesBuffer>(const class LTI::IPCommon::CPPBoxesBuffer &). c:\program files (x86)\microsoft visual studio 12.0\vc\unittest\include\cppunittestassert.h
I've tried the solution suggested in VS2012 : Error with unit test : Assert::AreEqual( object, object ) didn't work and wrote a specialization but it didn't work.
Here is the class in BoxesBuffer.h:
class CPPBoxesBuffer{
private:
unsigned char* _data;
int _lines;
public:
CPPBoxesBuffer(unsigned char* data, int lines){ _data = data; _lines = lines; };
// Methods for std::map. Class must be Assignable
CPPBoxesBuffer(){ _data = nullptr; _lines = 0; };
CPPBoxesBuffer(const CPPBoxesBuffer& other)
{
_lines = other._lines;
_data = other._data;
}
CPPBoxesBuffer& operator=(const CPPBoxesBuffer& other)
{
_lines = other._lines;
_data = other._data;
return *this;
}
bool operator==(const CPPBoxesBuffer& other) const
{
return _lines == other._lines && _data == other._data;
}
};
Here is the test:
TEST_METHOD(ShouldSetAndGetCppBoxesBufferData)
{
std::string key = "WhenPassingData";
unsigned char t[5] = { 'a', 'b', 'c', 'd', 'e' };
CPPBoxesBuffer data(t, 5);
auto result = data;
auto db = data == result; // This compiles.
Assert::AreEqual(data, result); // This fails with the error.
}
Here is the specialization I wrote:
#include "CppUnitTest.h"
#include "BoxesBuffer.h"
namespace Microsoft
{
namespace VisualStudio
{
namespace CppUnitTestFramework
{
template<> static std::wstring ToString<CPPBoxesBuffer>(const class CPPBoxesBuffer& t) { return L"CppBoxesBuffer"; }
}
}
}
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire