Ticket #3011: 0007-CLogger-Use-cppformat-instead-of-sys_vswprintf.patch

File 0007-CLogger-Use-cppformat-instead-of-sys_vswprintf.patch, 22.0 KB (added by Philip Taylor, 9 years ago)
  • build/premake/premake4.lua

    From abad924c3be908296ae7f70214b36f4cc1dec9ac Mon Sep 17 00:00:00 2001
    From: Philip Taylor <philip@zaynar.co.uk>
    Date: Tue, 20 Jan 2015 23:16:12 +0000
    Subject: [PATCH 07/13] CLogger: Use cppformat instead of sys_vswprintf.
    
    sys_vswprintf relies on platform-specific printf implementations, which vary widely between platforms (in handling of truncation, return values, use of %s/%S/%hs/%ls for mixing char and wchar_t strings, etc) and are therefore a pain.
    
    Use cppformat's fmt::sprintf instead, which has very similar syntax to sprintf but is more C++ish and is portable.
    
    Also, wchar_t is stupid, so use char* strings (which are expected to be UTF-8) in CLogger. This creates a bit of a pain with changing all callers to convert to char* strings, but that's their fault for not using UTF-8 already.
    ---
     build/premake/premake4.lua                         |   3 +-
     source/graphics/TextRenderer.cpp                   |   8 ++
     source/graphics/TextRenderer.h                     |   7 ++
     source/graphics/tests/test_MeshManager.h           |   4 +-
     source/lib/self_test.h                             |   3 +
     source/ps/CLogger.cpp                              | 118 +++++----------------
     source/ps/CLogger.h                                |  29 +++--
     source/ps/XML/tests/test_RelaxNG.h                 |   6 +-
     source/ps/tests/test_CLogger.h                     |  71 ++-----------
     .../scriptinterface/tests/test_ScriptInterface.h   |  10 +-
     source/simulation2/tests/test_ComponentManager.h   |   6 +-
     source/test_setup.cpp                              |   5 +
     12 files changed, 83 insertions(+), 187 deletions(-)
    
    diff --git a/build/premake/premake4.lua b/build/premake/premake4.lua
    index 44dbd76..cfb6980 100644
    a b function setup_all_libs ()  
    741741        "maths",
    742742        "maths/scripting",
    743743        "i18n",
    744         "i18n/scripting"
     744        "i18n/scripting",
     745        "third_party/cppformat",
    745746    }
    746747    extern_libs = {
    747748        "spidermonkey",
  • source/graphics/TextRenderer.cpp

    diff --git a/source/graphics/TextRenderer.cpp b/source/graphics/TextRenderer.cpp
    index 3149ed6..ae5ac69 100644
    a b void CTextRenderer::Put(float x, float y, const wchar_t* buf)  
    144144    PutString(x, y, new std::wstring(buf), true);
    145145}
    146146
     147void CTextRenderer::Put(float x, float y, const char* buf)
     148{
     149    if (buf[0] == 0)
     150        return; // empty string; don't bother storing
     151
     152    PutString(x, y, new std::wstring(wstring_from_utf8(buf)), true);
     153}
     154
    147155void CTextRenderer::Put(float x, float y, const std::wstring* buf)
    148156{
    149157    if (buf->empty())
  • source/graphics/TextRenderer.h

    diff --git a/source/graphics/TextRenderer.h b/source/graphics/TextRenderer.h
    index ac4d3b1..0c096f9 100644
    a b public:  
    9191    /**
    9292     * Print text at (x,y) under the current transform.
    9393     * Does not alter the current transform.
     94     * @p buf must be a UTF-8 string.
     95     */
     96    void Put(float x, float y, const char* buf);
     97
     98    /**
     99     * Print text at (x,y) under the current transform.
     100     * Does not alter the current transform.
    94101     * @p buf must remain valid until Render() is called.
    95102     * (This should be used to minimise memory copies when possible.)
    96103     */
  • source/graphics/tests/test_MeshManager.h

    diff --git a/source/graphics/tests/test_MeshManager.h b/source/graphics/tests/test_MeshManager.h
    index 4e59ba1..a35d3b3 100644
    a b public:  
    190190
    191191        CModelDefPtr modeldef = meshManager->GetMesh(testDAE);
    192192        TS_ASSERT(! modeldef);
    193         TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"parser error");
     193        TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "parser error");
    194194    }
    195195
    196196    void test_invalid_dae()
    public:  
    205205
    206206        CModelDefPtr modeldef = meshManager->GetMesh(testDAE);
    207207        TS_ASSERT(! modeldef);
    208         TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"parser error");
     208        TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "parser error");
    209209    }
    210210
    211211    void test_load_nonexistent_pmd()
  • source/lib/self_test.h

    diff --git a/source/lib/self_test.h b/source/lib/self_test.h
    index 27e3870..4b68be0 100644
    a b namespace CxxTest  
    269269#define TS_ASSERT_PATH_EQUALS(path1, path2) TS_ASSERT_EQUALS((path1).string(), (path2).string())
    270270#define TSM_ASSERT_PATH_EQUALS(m, path1, path2) TSM_ASSERT_EQUALS(m, (path1).string(), (path2).string())
    271271
     272bool ts_str_contains(const std::string& str1, const std::string& str2); // defined in test_setup.cpp
    272273bool ts_str_contains(const std::wstring& str1, const std::wstring& str2); // defined in test_setup.cpp
     274#define TS_ASSERT_STR_CONTAINS(str1, str2) TSM_ASSERT(str1, ts_str_contains(str1, str2))
     275#define TS_ASSERT_STR_NOT_CONTAINS(str1, str2) TSM_ASSERT(str1, !ts_str_contains(str1, str2))
    273276#define TS_ASSERT_WSTR_CONTAINS(str1, str2) TSM_ASSERT(str1, ts_str_contains(str1, str2))
    274277#define TS_ASSERT_WSTR_NOT_CONTAINS(str1, str2) TSM_ASSERT(str1, !ts_str_contains(str1, str2))
    275278
  • source/ps/CLogger.cpp

    diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp
    index 1a68943..16c8ff0 100644
    a b  
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    CLogger::~CLogger()  
    140140    }
    141141}
    142142
    143 static std::string ToHTML(const wchar_t* message)
     143static std::string ToHTML(const char* message)
    144144{
    145     Status err;
    146     std::string cmessage = utf8_from_wstring(message, &err);
     145    std::string cmessage = message;
    147146    boost::algorithm::replace_all(cmessage, "&", "&amp;");
    148147    boost::algorithm::replace_all(cmessage, "<", "&lt;");
    149148    return cmessage;
    150149}
    151150
    152 void CLogger::WriteMessage(const wchar_t* message, bool doRender = false)
     151void CLogger::WriteMessage(const char* message, bool doRender = false)
    153152{
    154153    std::string cmessage = ToHTML(message);
    155154
    void CLogger::WriteMessage(const wchar_t* message, bool doRender = false)  
    157156
    158157    ++m_NumberOfMessages;
    159158//  if (m_UseDebugPrintf)
    160 //      debug_printf(L"MESSAGE: %ls\n", message);
     159//      debug_printf(L"MESSAGE: %hs\n", message);
    161160
    162161    *m_MainLog << "<p>" << cmessage << "</p>\n";
    163162    m_MainLog->flush();
    164163   
    165164    if (doRender)
    166165    {
    167         if (g_Console) g_Console->InsertMessage(L"INFO: %ls", message);
     166        if (g_Console) g_Console->InsertMessage(L"INFO: %hs", message);
    168167
    169168        PushRenderMessage(Normal, message);
    170169    }
    171170}
    172171
    173 void CLogger::WriteError(const wchar_t* message)
     172void CLogger::WriteError(const char* message)
    174173{
    175174    std::string cmessage = ToHTML(message);
    176175
    void CLogger::WriteError(const wchar_t* message)  
    178177
    179178    ++m_NumberOfErrors;
    180179    if (m_UseDebugPrintf)
    181         debug_printf(L"ERROR: %ls\n", message);
     180        debug_printf(L"ERROR: %hs\n", message);
    182181
    183     if (g_Console) g_Console->InsertMessage(L"ERROR: %ls", message);
     182    if (g_Console) g_Console->InsertMessage(L"ERROR: %hs", message);
    184183    *m_InterestingLog << "<p class=\"error\">ERROR: " << cmessage << "</p>\n";
    185184    m_InterestingLog->flush();
    186185
    void CLogger::WriteError(const wchar_t* message)  
    190189    PushRenderMessage(Error, message);
    191190}
    192191
    193 void CLogger::WriteWarning(const wchar_t* message)
     192void CLogger::WriteWarning(const char* message)
    194193{
    195194    std::string cmessage = ToHTML(message);
    196195
    void CLogger::WriteWarning(const wchar_t* message)  
    198197
    199198    ++m_NumberOfWarnings;
    200199    if (m_UseDebugPrintf)
    201         debug_printf(L"WARNING: %ls\n", message);
     200        debug_printf(L"WARNING: %hs\n", message);
    202201
    203     if (g_Console) g_Console->InsertMessage(L"WARNING: %ls", message);
     202    if (g_Console) g_Console->InsertMessage(L"WARNING: %hs", message);
    204203    *m_InterestingLog << "<p class=\"warning\">WARNING: " << cmessage << "</p>\n";
    205204    m_InterestingLog->flush();
    206205
    void CLogger::WriteWarning(const wchar_t* message)  
    210209    PushRenderMessage(Warning, message);
    211210}
    212211
    213 void CLogger::LogMessage(const wchar_t* fmt, ...)
    214 {
    215     va_list argp;
    216     wchar_t buffer[BUFFER_SIZE] = {0};
    217    
    218     va_start(argp, fmt);
    219     if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1)
    220     {
    221         // Buffer too small - ensure the string is nicely terminated
    222         wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"...");
    223     }
    224     va_end(argp);
    225 
    226     WriteMessage(buffer);
    227 }
    228 
    229 void CLogger::LogMessageRender(const wchar_t* fmt, ...)
    230 {
    231     va_list argp;
    232     wchar_t buffer[BUFFER_SIZE] = {0};
    233    
    234     va_start(argp, fmt);
    235     if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1)
    236     {
    237         // Buffer too small - ensure the string is nicely terminated
    238         wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"...");
    239     }
    240     va_end(argp);
    241 
    242     WriteMessage(buffer, true);
    243 }
    244 
    245 void CLogger::LogWarning(const wchar_t* fmt, ...)
    246 {
    247     va_list argp;
    248     wchar_t buffer[BUFFER_SIZE] = {0};
    249    
    250     va_start(argp, fmt);
    251     if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1)
    252     {
    253         // Buffer too small - ensure the string is nicely terminated
    254         wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"...");
    255     }
    256     va_end(argp);
    257 
    258     WriteWarning(buffer);
    259 }
    260 
    261 void CLogger::LogError(const wchar_t* fmt, ...)
    262 {
    263     va_list argp;
    264     wchar_t buffer[BUFFER_SIZE] = {0};
    265    
    266     va_start(argp, fmt);
    267     if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1)
    268     {
    269         // Buffer too small - ensure the string is nicely terminated
    270         wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"...");
    271     }
    272     va_end(argp);
    273 
    274     WriteError(buffer);
    275 }
    276 
    277212void CLogger::Render()
    278213{
    279214    PROFILE3_GPU("logger");
    void CLogger::Render()  
    300235
    301236    for (std::deque<RenderedMessage>::iterator it = m_RenderMessages.begin(); it != m_RenderMessages.end(); ++it)
    302237    {
    303         const wchar_t* type;
     238        const char* type;
    304239        if (it->method == Normal)
    305240        {
    306             type = L"info";
     241            type = "info";
    307242            textRenderer.Color(0.0f, 0.8f, 0.0f);
    308243        }
    309244        else if (it->method == Warning)
    310245        {
    311             type = L"warning";
     246            type = "warning";
    312247            textRenderer.Color(1.0f, 1.0f, 0.0f);
    313248        }
    314249        else
    315250        {
    316             type = L"error";
     251            type = "error";
    317252            textRenderer.Color(1.0f, 0.0f, 0.0f);
    318253        }
    319254
    320255        CMatrix3D savedTransform = textRenderer.GetTransform();
    321256
    322         textRenderer.PrintfAdvance(L"[%8.3f] %ls: ", it->time, type);
     257        textRenderer.PrintfAdvance(L"[%8.3f] %hs: ", it->time, type);
    323258        // Display the actual message in white so it's more readable
    324259        textRenderer.Color(1.0f, 1.0f, 1.0f);
    325260        textRenderer.Put(0.0f, 0.0f, it->message.c_str());
    void CLogger::Render()  
    334269    textTech->EndPass();
    335270}
    336271
    337 void CLogger::PushRenderMessage(ELogMethod method, const wchar_t* message)
     272void CLogger::PushRenderMessage(ELogMethod method, const char* message)
    338273{
    339274    double now = timer_Time();
    340275
    341276    // Add each message line separately
    342     const wchar_t* pos = message;
    343     const wchar_t* eol;
    344     while ((eol = wcschr(pos, L'\n')) != NULL)
     277    const char* pos = message;
     278    const char* eol;
     279    while ((eol = strchr(pos, '\n')) != NULL)
    345280    {
    346281        if (eol != pos)
    347282        {
    348             RenderedMessage r = { method, now, std::wstring(pos, eol) };
     283            RenderedMessage r = { method, now, std::string(pos, eol) };
    349284            m_RenderMessages.push_back(r);
    350285        }
    351286        pos = eol + 1;
    352287    }
    353288    // Add the last line, if we didn't end on a \n
    354     if (*pos != L'\0')
     289    if (*pos != '\0')
    355290    {
    356         RenderedMessage r = { method, now, std::wstring(pos) };
     291        RenderedMessage r = { method, now, std::string(pos) };
    357292        m_RenderMessages.push_back(r);
    358293    }
    359294}
    TestLogger::~TestLogger()  
    398333    g_Logger = m_OldLogger;
    399334}
    400335
    401 std::wstring TestLogger::GetOutput()
     336std::string TestLogger::GetOutput()
    402337{
    403     Status err;
    404     return wstring_from_utf8(m_Stream.str(), &err);
     338    return m_Stream.str();
    405339}
    406340
    407341TestStdoutLogger::TestStdoutLogger()
  • source/ps/CLogger.h

    diff --git a/source/ps/CLogger.h b/source/ps/CLogger.h
    index 78e9ad8..ba23976 100644
    a b  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2424#include <sstream>
    2525
    2626#include "ps/ThreadUtil.h"
     27#include "third_party/cppformat/format.h"
    2728
    2829class CLogger;
    2930extern CLogger* g_Logger;
    3031
    3132
    32 #define LOGMESSAGE g_Logger->LogMessage
    33 #define LOGMESSAGERENDER g_Logger->LogMessageRender
    34 #define LOGWARNING g_Logger->LogWarning
    35 #define LOGERROR g_Logger->LogError
     33#define LOGMESSAGE(...)       g_Logger->WriteMessage(fmt::sprintf(__VA_ARGS__).c_str(), false)
     34#define LOGMESSAGERENDER(...) g_Logger->WriteMessage(fmt::sprintf(__VA_ARGS__).c_str(), true)
     35#define LOGWARNING(...)       g_Logger->WriteWarning(fmt::sprintf(__VA_ARGS__).c_str())
     36#define LOGERROR(...)         g_Logger->WriteError  (fmt::sprintf(__VA_ARGS__).c_str())
    3637
    3738/**
    3839 * Error/warning/message logging class.
    public:  
    6465
    6566    // Functions to write different message types (Errors and warnings are placed
    6667    // both in mainLog and intrestingLog.)
    67     void WriteMessage(const wchar_t* message, bool doRender);
    68     void WriteError  (const wchar_t* message);
    69     void WriteWarning(const wchar_t* message);
     68    void WriteMessage(const char* message, bool doRender);
     69    void WriteError  (const char* message);
     70    void WriteWarning(const char* message);
    7071   
    71     // Functions to write a message, warning or error to file.
    72     void LogMessage(const wchar_t* fmt, ...) WPRINTF_ARGS(2);
    73     void LogMessageRender(const wchar_t* fmt, ...) WPRINTF_ARGS(2);
    74     void LogWarning(const wchar_t* fmt, ...) WPRINTF_ARGS(2);
    75     void LogError(const wchar_t* fmt, ...) WPRINTF_ARGS(2);
    76 
    7772    // Render recent log messages onto the screen
    7873    void Render();
    7974   
    8075private:
    8176    void Init();
    8277
    83     void PushRenderMessage(ELogMethod method, const wchar_t* message);
     78    void PushRenderMessage(ELogMethod method, const char* message);
    8479
    8580    // Delete old timed-out entries from the list of text to render
    8681    void CleanupRenderQueue();
    private:  
    10499    {
    105100        ELogMethod method;
    106101        double time;
    107         std::wstring message;
     102        std::string message;
    108103    };
    109104    std::deque<RenderedMessage> m_RenderMessages;
    110105    double m_RenderLastEraseTime;
    class TestLogger  
    123118public:
    124119    TestLogger();
    125120    ~TestLogger();
    126     std::wstring GetOutput();
     121    std::string GetOutput();
    127122private:
    128123    CLogger* m_OldLogger;
    129124    std::stringstream m_Stream;
  • source/ps/XML/tests/test_RelaxNG.h

    diff --git a/source/ps/XML/tests/test_RelaxNG.h b/source/ps/XML/tests/test_RelaxNG.h
    index 0cb11c6..3b10986 100644
    a b public:  
    4444        {
    4545            TestLogger logger;
    4646            TS_ASSERT(!v.Validate(L"doc", L"<bogus/>"));
    47             TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"Parse error: doc:1: Expecting element test, got bogus");
     47            TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "Parse error: doc:1: Expecting element test, got bogus");
    4848        }
    4949
    5050        {
    5151            TestLogger logger;
    5252            TS_ASSERT(!v.Validate(L"doc", L"bogus"));
    53             TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"RelaxNGValidator: Failed to parse document");
     53            TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "RelaxNGValidator: Failed to parse document");
    5454        }
    5555
    5656        TS_ASSERT(v.Validate(L"doc", L"<test/>"));
    public:  
    8282
    8383        TestLogger logger;
    8484        TS_ASSERT(!v.LoadGrammar("whoops"));
    85         TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"RelaxNGValidator: Failed to compile schema");
     85        TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "RelaxNGValidator: Failed to compile schema");
    8686
    8787        TS_ASSERT(!v.Validate(L"doc", L"<test/>"));
    8888    }
  • source/ps/tests/test_CLogger.h

    diff --git a/source/ps/tests/test_CLogger.h b/source/ps/tests/test_CLogger.h
    index 1ba5281..8d1dc34 100644
    a b class TestCLogger : public CxxTest::TestSuite  
    2424public:
    2525    void test_basic()
    2626    {
    27         logger->LogMessage(L"Test 1");
    28         logger->LogMessage(L"Test 2");
     27        logger->WriteMessage("Test 1", false);
     28        logger->WriteMessage("Test 2", false);
    2929
    3030        ParseOutput();
    3131
    public:  
    3434        TS_ASSERT_EQUALS(lines[1], "Test 2");
    3535    }
    3636
    37     void test_overflow()
    38     {
    39         const int buflen = 1024;
    40 
    41         std::string msg0 (buflen-2, '*');
    42         std::string msg1 (buflen-1, '*');
    43         std::string msg2 (buflen,   '*');
    44         std::string msg3 (buflen+1, '*');
    45 
    46         std::string clipped (buflen-4, '*');
    47         clipped += "...";
    48 
    49         logger->LogMessage(L"%hs", msg0.c_str());
    50         logger->LogMessage(L"%hs", msg1.c_str());
    51         logger->LogMessage(L"%hs", msg2.c_str());
    52         logger->LogMessage(L"%hs", msg3.c_str());
    53 
    54         logger->LogMessageRender(L"%hs", msg0.c_str());
    55         logger->LogMessageRender(L"%hs", msg1.c_str());
    56         logger->LogMessageRender(L"%hs", msg2.c_str());
    57         logger->LogMessageRender(L"%hs", msg3.c_str());
    58 
    59         logger->LogWarning(L"%hs", msg0.c_str());
    60         logger->LogWarning(L"%hs", msg1.c_str());
    61         logger->LogWarning(L"%hs", msg2.c_str());
    62         logger->LogWarning(L"%hs", msg3.c_str());
    63 
    64         logger->LogError(L"%hs", msg0.c_str());
    65         logger->LogError(L"%hs", msg1.c_str());
    66         logger->LogError(L"%hs", msg2.c_str());
    67         logger->LogError(L"%hs", msg3.c_str());
    68 
    69         ParseOutput();
    70 
    71         TS_ASSERT_EQUALS((int)lines.size(), 4*4);
    72         TS_ASSERT_EQUALS(lines[0], msg0);
    73         TS_ASSERT_EQUALS(lines[1], msg1);
    74         TS_ASSERT_EQUALS(lines[2], clipped);
    75         TS_ASSERT_EQUALS(lines[3], clipped);
    76 
    77         TS_ASSERT_EQUALS(lines[4], msg0);
    78         TS_ASSERT_EQUALS(lines[5], msg1);
    79         TS_ASSERT_EQUALS(lines[6], clipped);
    80         TS_ASSERT_EQUALS(lines[7], clipped);
    81 
    82         TS_ASSERT_EQUALS(lines[8], "WARNING: "+msg0);
    83         TS_ASSERT_EQUALS(lines[9], "WARNING: "+msg1);
    84         TS_ASSERT_EQUALS(lines[10], "WARNING: "+clipped);
    85         TS_ASSERT_EQUALS(lines[11], "WARNING: "+clipped);
    86 
    87         TS_ASSERT_EQUALS(lines[12], "ERROR: "+msg0);
    88         TS_ASSERT_EQUALS(lines[13], "ERROR: "+msg1);
    89         TS_ASSERT_EQUALS(lines[14], "ERROR: "+clipped);
    90         TS_ASSERT_EQUALS(lines[15], "ERROR: "+clipped);
    91     }
    92 
    9337    void test_unicode()
    9438    {
    95         logger->LogMessage(L"%lc %lc", 226, 295);
     39        wchar_t str[] = { 226, 32, 295, 0 };
     40        logger->WriteMessage(utf8_from_wstring(str).c_str(), false);
    9641
    9742        ParseOutput();
    9843
    public:  
    10247
    10348    void test_html()
    10449    {
    105         logger->LogMessage(L"Test<a&b>c<d&e>");
     50        logger->WriteMessage("Test<a&b>c<d&e>", false);
    10651
    10752        ParseOutput();
    10853
    public:  
    11257
    11358    void test_null()
    11459    {
    115         logger->LogMessage(L"a %hs b", (const char *)NULL);
    116         logger->LogMessage(L"c %ls d", (const wchar_t *)NULL);
     60        logger->WriteMessage(fmt::sprintf("a %s b", (const char *)NULL).c_str(), false);
    11761
    11862        ParseOutput();
    11963
    120         TS_ASSERT_EQUALS((int)lines.size(), 2);
     64        TS_ASSERT_EQUALS((int)lines.size(), 1);
    12165        TS_ASSERT_EQUALS(lines[0], "a (null) b");
    122         TS_ASSERT_EQUALS(lines[1], "c (null) d");
    12366    }
    12467
    12568    //////////////////////////////////////////////////////////////////////////
  • source/scriptinterface/tests/test_ScriptInterface.h

    diff --git a/source/scriptinterface/tests/test_ScriptInterface.h b/source/scriptinterface/tests/test_ScriptInterface.h
    index 3089ea6..e966ee4 100644
    a b public:  
    3131        ScriptInterface script("Test", "Test", g_ScriptRuntime);
    3232        TestLogger logger;
    3333        TS_ASSERT(script.LoadScript(L"test.js", "var x = 1+1;"));
    34         TS_ASSERT_WSTR_NOT_CONTAINS(logger.GetOutput(), L"JavaScript error");
    35         TS_ASSERT_WSTR_NOT_CONTAINS(logger.GetOutput(), L"JavaScript warning");
     34        TS_ASSERT_STR_NOT_CONTAINS(logger.GetOutput(), "JavaScript error");
     35        TS_ASSERT_STR_NOT_CONTAINS(logger.GetOutput(), "JavaScript warning");
    3636    }
    3737
    3838    void test_loadscript_error()
    public:  
    4040        ScriptInterface script("Test", "Test", g_ScriptRuntime);
    4141        TestLogger logger;
    4242        TS_ASSERT(!script.LoadScript(L"test.js", "1+"));
    43         TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript error: test.js line 1\nSyntaxError: syntax error");
     43        TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "JavaScript error: test.js line 1\nSyntaxError: syntax error");
    4444    }
    4545
    4646    void test_loadscript_strict_warning()
    public:  
    4949        TestLogger logger;
    5050        // in strict mode, this inside a function doesn't point to the global object
    5151        TS_ASSERT(script.LoadScript(L"test.js", "var isStrict = (function() { return !this; })();warn('isStrict is '+isStrict);"));
    52         TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"WARNING: isStrict is true");
     52        TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "WARNING: isStrict is true");
    5353    }
    5454
    5555    void test_loadscript_strict_error()
    public:  
    5757        ScriptInterface script("Test", "Test", g_ScriptRuntime);
    5858        TestLogger logger;
    5959        TS_ASSERT(!script.LoadScript(L"test.js", "with(1){}"));
    60         TS_ASSERT_WSTR_CONTAINS(logger.GetOutput(), L"JavaScript error: test.js line 1\nSyntaxError: strict mode code may not contain \'with\' statements");
     60        TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "JavaScript error: test.js line 1\nSyntaxError: strict mode code may not contain \'with\' statements");
    6161    }
    6262
    6363    void test_clone_basic()
  • source/simulation2/tests/test_ComponentManager.h

    diff --git a/source/simulation2/tests/test_ComponentManager.h b/source/simulation2/tests/test_ComponentManager.h
    index c84fe34..9c92b4b 100644
    a b public:  
    109109        {
    110110            TestLogger log;
    111111            TS_ASSERT(! man.AddComponent(hnd1, 12345, noParam));
    112             TS_ASSERT_WSTR_CONTAINS(log.GetOutput(), L"ERROR: Invalid component id 12345");
     112            TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Invalid component id 12345");
    113113        }
    114114
    115115        {
    116116            TestLogger log;
    117117            TS_ASSERT(! man.AddComponent(hnd1, CID_Test1B, noParam));
    118             TS_ASSERT_WSTR_CONTAINS(log.GetOutput(), L"ERROR: Multiple components for interface ");
     118            TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Multiple components for interface ");
    119119        }
    120120    }
    121121
    public:  
    347347            // In SpiderMonkey 1.6, JS_ReportError calls the error reporter even if it's inside
    348348            // a try{} in the script; in recent versions (not sure when it changed) it doesn't
    349349            // so the error here won't get reported.
    350             TS_ASSERT_WSTR_NOT_CONTAINS(log.GetOutput(), L"ERROR: JavaScript error: simulation/components/error.js line 4\nInvalid interface id");
     350            TS_ASSERT_STR_NOT_CONTAINS(log.GetOutput(), "ERROR: JavaScript error: simulation/components/error.js line 4\nInvalid interface id");
    351351        }
    352352    }
    353353
  • source/test_setup.cpp

    diff --git a/source/test_setup.cpp b/source/test_setup.cpp
    index 448a650..c75f43a 100644
    a b static MiscSetup miscSetup;  
    100100
    101101// Definition of functions from lib/self_test.h
    102102
     103bool ts_str_contains(const std::string& str1, const std::string& str2)
     104{
     105    return str1.find(str2) != str1.npos;
     106}
     107
    103108bool ts_str_contains(const std::wstring& str1, const std::wstring& str2)
    104109{
    105110    return str1.find(str2) != str1.npos;