using library file unittest

hi my program is find non printable ASCII value(1 to 32) and calculate count from a text like "hi<tab>this<space>my text.i'm using library file here.(visual studio 2012)
-----
removeascii.h(program name)

#pragma once
#include<stdint.h>
#include <string>
using std::string;
namespace ascii
{
int64_t removeNonDisplayableAsciiChars(char text[]);
}
---------
removeascii.cpp

#include "removeascii.h"
#include<iostream>
#include<stdint.h>


static const char TheSpace = ' ';
namespace ascii
{
int64_t removeNonDisplayableAsciiChars(char rawText[])
{
int64_t bytesRemoved = 0;
for (char *p = rawText; *p != '\0'; ++p) {
if (*p > 0 && *p < 32 || *p == 127) {
*p = TheSpace;
++bytesRemoved;
}
}
return bytesRemoved;
}
}
-------------
unittest1.cpp


#include "stdafx.h"
#include "CppUnitTest.h"
#include "removeascii.h"
#include<stdint.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest2
{
TEST_CLASS(UnitTest1)
{
public:

TEST_METHOD(TestMethod1)
{

int64_t actual,expect;
char text[]="hi i give";
actual=ascii::removeNonDisplayableAsciiChars(text);
expect=1;
Assert::AreEqual(expect,actual);
}

};
}



My ERROR is:

1>c:\program files (x86)\microsoft visual studio 11.0\vc\unittest\include\cppunittestassert.h(65): 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<__int64>(const __int64 &).
1> c:\program files (x86)\microsoft visual studio 11.0\vc\unittest\include\cppunittestassert.h(128) : see reference to function template instantiation 'std::wstring Microsoft::VisualStudio::CppUnitTestFramework::ToString<T>(const Q &)' being compiled
1> with
1> [
1> T=int64_t,
1> Q=int64_t
1> ]
1> c:\users\amu1\desktop\karthikn\ascii\unittest2\unittest1.cpp(20) : see reference to function template instantiation 'void Microsoft::VisualStudio::CppUnitTestFramework::Assert::AreEqual<int64_t>(const T &,const T &,const wchar_t *,const Microsoft::VisualStudio::CppUnitTestFramework::__LineInfo *)' being compiled
1> with
1> [
1> T=int64_t
1> ]
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
Last edited on
It appears CppUnitTestAssert.h doesn't have a ToString() template specialization for int64_t. This results in an error when you call AreEqual expect and actual. You have to implement support for int64_t. The second problem is caused by the first, so fixing the first should fix both. Suggest something along the lines of
1
2
3
4
5
6
7
8
9
10
11
12
13
namespace Microsoft
{ 
    namespace VisualStudio
    { 
        namespace CppUnitTestFramework
        {
            template<> static std::wstring ToString<int64_t>(const int64_t &t)
            {
	             /* Do your magic here and return the wstring of your chopice */ 
	    }
        }
    }
}
Topic archived. No new replies allowed.