CppUnit wstring support
Randall Britten
r.britten at auckland.ac.nz
Thu Jul 3 21:10:34 PDT 2014
Hi
Is there a plan to include wstring support out-of-the-box for CppUnit? If not, and in the mean time, what is the “correct” way to add support for wstring, (e.g. such that the following will compile on a strict compiler such as the one included with Xcode 5.1.1)?
(This is is an excerpt showing an additional test added to examples/simple/ExampleTestCase.cpp (with corresponding change in .h).)
#include <cppunit/config/SourcePrefix.h>
#include "ExampleTestCase.h"
//HERE
#include <string>
CPPUNIT_TEST_SUITE_REGISTRATION( ExampleTestCase );
…
void ExampleTestCase::exampleForWString()
{
std::wstring ws1 = L"Hello";
std::wstring ws2 = L"Goodbye ????????";
CPPUNIT_ASSERT_EQUAL (ws1, ws2);
}
…
My solution was to #include “CppUnitWstringSupport.hpp” where after the line “//HERE”, this is the content of CppUnitWstringSupport.hpp:
#ifndef CPPUNITWSTRINGSUPPORT_H
#define CPPUNITWSTRINGSUPPORT_H
#include <iostream> // std::cout, std::hex
#include <string> // std::string, std::u32string
#include <locale> // std::wstring_convert
#include <codecvt> // std::codecvt_utf8
#include <cstdint> // std::uint_least32_t
namespace CppUnit {
template<>
struct assertion_traits<std::wstring>
{
static bool equal(const std::wstring& x, const std::wstring& y)
{
return x == y;
}
static std::string toString(const std::wstring& ws)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>,wchar_t> cv;
return cv.to_bytes(ws);
}
};
};
#endif // CPPUNITWSTRINGSUPPORT_H
Regards,
Randall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20140704/cf5510fc/attachment.html>
More information about the LibreOffice
mailing list