Date: prev next · Thread: first prev next last
2014 Archives by date, by thread · List index


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

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.