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 , 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 () 741 741 "maths", 742 742 "maths/scripting", 743 743 "i18n", 744 "i18n/scripting" 744 "i18n/scripting", 745 "third_party/cppformat", 745 746 } 746 747 extern_libs = { 747 748 "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) 144 144 PutString(x, y, new std::wstring(buf), true); 145 145 } 146 146 147 void 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 147 155 void CTextRenderer::Put(float x, float y, const std::wstring* buf) 148 156 { 149 157 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: 91 91 /** 92 92 * Print text at (x,y) under the current transform. 93 93 * 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. 94 101 * @p buf must remain valid until Render() is called. 95 102 * (This should be used to minimise memory copies when possible.) 96 103 */ -
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: 190 190 191 191 CModelDefPtr modeldef = meshManager->GetMesh(testDAE); 192 192 TS_ASSERT(! modeldef); 193 TS_ASSERT_ WSTR_CONTAINS(logger.GetOutput(), L"parser error");193 TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "parser error"); 194 194 } 195 195 196 196 void test_invalid_dae() … … public: 205 205 206 206 CModelDefPtr modeldef = meshManager->GetMesh(testDAE); 207 207 TS_ASSERT(! modeldef); 208 TS_ASSERT_ WSTR_CONTAINS(logger.GetOutput(), L"parser error");208 TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "parser error"); 209 209 } 210 210 211 211 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 269 269 #define TS_ASSERT_PATH_EQUALS(path1, path2) TS_ASSERT_EQUALS((path1).string(), (path2).string()) 270 270 #define TSM_ASSERT_PATH_EQUALS(m, path1, path2) TSM_ASSERT_EQUALS(m, (path1).string(), (path2).string()) 271 271 272 bool ts_str_contains(const std::string& str1, const std::string& str2); // defined in test_setup.cpp 272 273 bool 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)) 273 276 #define TS_ASSERT_WSTR_CONTAINS(str1, str2) TSM_ASSERT(str1, ts_str_contains(str1, str2)) 274 277 #define TS_ASSERT_WSTR_NOT_CONTAINS(str1, str2) TSM_ASSERT(str1, !ts_str_contains(str1, str2)) 275 278 -
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) 201 2Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … CLogger::~CLogger() 140 140 } 141 141 } 142 142 143 static std::string ToHTML(const wchar_t* message)143 static std::string ToHTML(const char* message) 144 144 { 145 Status err; 146 std::string cmessage = utf8_from_wstring(message, &err); 145 std::string cmessage = message; 147 146 boost::algorithm::replace_all(cmessage, "&", "&"); 148 147 boost::algorithm::replace_all(cmessage, "<", "<"); 149 148 return cmessage; 150 149 } 151 150 152 void CLogger::WriteMessage(const wchar_t* message, bool doRender = false)151 void CLogger::WriteMessage(const char* message, bool doRender = false) 153 152 { 154 153 std::string cmessage = ToHTML(message); 155 154 … … void CLogger::WriteMessage(const wchar_t* message, bool doRender = false) 157 156 158 157 ++m_NumberOfMessages; 159 158 // if (m_UseDebugPrintf) 160 // debug_printf(L"MESSAGE: % ls\n", message);159 // debug_printf(L"MESSAGE: %hs\n", message); 161 160 162 161 *m_MainLog << "<p>" << cmessage << "</p>\n"; 163 162 m_MainLog->flush(); 164 163 165 164 if (doRender) 166 165 { 167 if (g_Console) g_Console->InsertMessage(L"INFO: % ls", message);166 if (g_Console) g_Console->InsertMessage(L"INFO: %hs", message); 168 167 169 168 PushRenderMessage(Normal, message); 170 169 } 171 170 } 172 171 173 void CLogger::WriteError(const wchar_t* message)172 void CLogger::WriteError(const char* message) 174 173 { 175 174 std::string cmessage = ToHTML(message); 176 175 … … void CLogger::WriteError(const wchar_t* message) 178 177 179 178 ++m_NumberOfErrors; 180 179 if (m_UseDebugPrintf) 181 debug_printf(L"ERROR: % ls\n", message);180 debug_printf(L"ERROR: %hs\n", message); 182 181 183 if (g_Console) g_Console->InsertMessage(L"ERROR: % ls", message);182 if (g_Console) g_Console->InsertMessage(L"ERROR: %hs", message); 184 183 *m_InterestingLog << "<p class=\"error\">ERROR: " << cmessage << "</p>\n"; 185 184 m_InterestingLog->flush(); 186 185 … … void CLogger::WriteError(const wchar_t* message) 190 189 PushRenderMessage(Error, message); 191 190 } 192 191 193 void CLogger::WriteWarning(const wchar_t* message)192 void CLogger::WriteWarning(const char* message) 194 193 { 195 194 std::string cmessage = ToHTML(message); 196 195 … … void CLogger::WriteWarning(const wchar_t* message) 198 197 199 198 ++m_NumberOfWarnings; 200 199 if (m_UseDebugPrintf) 201 debug_printf(L"WARNING: % ls\n", message);200 debug_printf(L"WARNING: %hs\n", message); 202 201 203 if (g_Console) g_Console->InsertMessage(L"WARNING: % ls", message);202 if (g_Console) g_Console->InsertMessage(L"WARNING: %hs", message); 204 203 *m_InterestingLog << "<p class=\"warning\">WARNING: " << cmessage << "</p>\n"; 205 204 m_InterestingLog->flush(); 206 205 … … void CLogger::WriteWarning(const wchar_t* message) 210 209 PushRenderMessage(Warning, message); 211 210 } 212 211 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 terminated222 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 terminated238 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 terminated254 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 terminated270 wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"...");271 }272 va_end(argp);273 274 WriteError(buffer);275 }276 277 212 void CLogger::Render() 278 213 { 279 214 PROFILE3_GPU("logger"); … … void CLogger::Render() 300 235 301 236 for (std::deque<RenderedMessage>::iterator it = m_RenderMessages.begin(); it != m_RenderMessages.end(); ++it) 302 237 { 303 const wchar_t* type;238 const char* type; 304 239 if (it->method == Normal) 305 240 { 306 type = L"info";241 type = "info"; 307 242 textRenderer.Color(0.0f, 0.8f, 0.0f); 308 243 } 309 244 else if (it->method == Warning) 310 245 { 311 type = L"warning";246 type = "warning"; 312 247 textRenderer.Color(1.0f, 1.0f, 0.0f); 313 248 } 314 249 else 315 250 { 316 type = L"error";251 type = "error"; 317 252 textRenderer.Color(1.0f, 0.0f, 0.0f); 318 253 } 319 254 320 255 CMatrix3D savedTransform = textRenderer.GetTransform(); 321 256 322 textRenderer.PrintfAdvance(L"[%8.3f] % ls: ", it->time, type);257 textRenderer.PrintfAdvance(L"[%8.3f] %hs: ", it->time, type); 323 258 // Display the actual message in white so it's more readable 324 259 textRenderer.Color(1.0f, 1.0f, 1.0f); 325 260 textRenderer.Put(0.0f, 0.0f, it->message.c_str()); … … void CLogger::Render() 334 269 textTech->EndPass(); 335 270 } 336 271 337 void CLogger::PushRenderMessage(ELogMethod method, const wchar_t* message)272 void CLogger::PushRenderMessage(ELogMethod method, const char* message) 338 273 { 339 274 double now = timer_Time(); 340 275 341 276 // 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) 345 280 { 346 281 if (eol != pos) 347 282 { 348 RenderedMessage r = { method, now, std:: wstring(pos, eol) };283 RenderedMessage r = { method, now, std::string(pos, eol) }; 349 284 m_RenderMessages.push_back(r); 350 285 } 351 286 pos = eol + 1; 352 287 } 353 288 // Add the last line, if we didn't end on a \n 354 if (*pos != L'\0')289 if (*pos != '\0') 355 290 { 356 RenderedMessage r = { method, now, std:: wstring(pos) };291 RenderedMessage r = { method, now, std::string(pos) }; 357 292 m_RenderMessages.push_back(r); 358 293 } 359 294 } … … TestLogger::~TestLogger() 398 333 g_Logger = m_OldLogger; 399 334 } 400 335 401 std:: wstring TestLogger::GetOutput()336 std::string TestLogger::GetOutput() 402 337 { 403 Status err; 404 return wstring_from_utf8(m_Stream.str(), &err); 338 return m_Stream.str(); 405 339 } 406 340 407 341 TestStdoutLogger::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) 201 0Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 24 24 #include <sstream> 25 25 26 26 #include "ps/ThreadUtil.h" 27 #include "third_party/cppformat/format.h" 27 28 28 29 class CLogger; 29 30 extern CLogger* g_Logger; 30 31 31 32 32 #define LOGMESSAGE g_Logger->LogMessage33 #define LOGMESSAGERENDER g_Logger->LogMessageRender34 #define LOGWARNING g_Logger->LogWarning35 #define LOGERROR g_Logger->LogError33 #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()) 36 37 37 38 /** 38 39 * Error/warning/message logging class. … … public: 64 65 65 66 // Functions to write different message types (Errors and warnings are placed 66 67 // 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); 70 71 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 77 72 // Render recent log messages onto the screen 78 73 void Render(); 79 74 80 75 private: 81 76 void Init(); 82 77 83 void PushRenderMessage(ELogMethod method, const wchar_t* message);78 void PushRenderMessage(ELogMethod method, const char* message); 84 79 85 80 // Delete old timed-out entries from the list of text to render 86 81 void CleanupRenderQueue(); … … private: 104 99 { 105 100 ELogMethod method; 106 101 double time; 107 std:: wstring message;102 std::string message; 108 103 }; 109 104 std::deque<RenderedMessage> m_RenderMessages; 110 105 double m_RenderLastEraseTime; … … class TestLogger 123 118 public: 124 119 TestLogger(); 125 120 ~TestLogger(); 126 std:: wstring GetOutput();121 std::string GetOutput(); 127 122 private: 128 123 CLogger* m_OldLogger; 129 124 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: 44 44 { 45 45 TestLogger logger; 46 46 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"); 48 48 } 49 49 50 50 { 51 51 TestLogger logger; 52 52 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"); 54 54 } 55 55 56 56 TS_ASSERT(v.Validate(L"doc", L"<test/>")); … … public: 82 82 83 83 TestLogger logger; 84 84 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"); 86 86 87 87 TS_ASSERT(!v.Validate(L"doc", L"<test/>")); 88 88 } -
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 24 24 public: 25 25 void test_basic() 26 26 { 27 logger-> LogMessage(L"Test 1");28 logger-> LogMessage(L"Test 2");27 logger->WriteMessage("Test 1", false); 28 logger->WriteMessage("Test 2", false); 29 29 30 30 ParseOutput(); 31 31 … … public: 34 34 TS_ASSERT_EQUALS(lines[1], "Test 2"); 35 35 } 36 36 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 93 37 void test_unicode() 94 38 { 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); 96 41 97 42 ParseOutput(); 98 43 … … public: 102 47 103 48 void test_html() 104 49 { 105 logger-> LogMessage(L"Test<a&b>c<d&e>");50 logger->WriteMessage("Test<a&b>c<d&e>", false); 106 51 107 52 ParseOutput(); 108 53 … … public: 112 57 113 58 void test_null() 114 59 { 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); 117 61 118 62 ParseOutput(); 119 63 120 TS_ASSERT_EQUALS((int)lines.size(), 2);64 TS_ASSERT_EQUALS((int)lines.size(), 1); 121 65 TS_ASSERT_EQUALS(lines[0], "a (null) b"); 122 TS_ASSERT_EQUALS(lines[1], "c (null) d");123 66 } 124 67 125 68 ////////////////////////////////////////////////////////////////////////// -
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: 31 31 ScriptInterface script("Test", "Test", g_ScriptRuntime); 32 32 TestLogger logger; 33 33 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"); 36 36 } 37 37 38 38 void test_loadscript_error() … … public: 40 40 ScriptInterface script("Test", "Test", g_ScriptRuntime); 41 41 TestLogger logger; 42 42 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"); 44 44 } 45 45 46 46 void test_loadscript_strict_warning() … … public: 49 49 TestLogger logger; 50 50 // in strict mode, this inside a function doesn't point to the global object 51 51 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"); 53 53 } 54 54 55 55 void test_loadscript_strict_error() … … public: 57 57 ScriptInterface script("Test", "Test", g_ScriptRuntime); 58 58 TestLogger logger; 59 59 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"); 61 61 } 62 62 63 63 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: 109 109 { 110 110 TestLogger log; 111 111 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"); 113 113 } 114 114 115 115 { 116 116 TestLogger log; 117 117 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 "); 119 119 } 120 120 } 121 121 … … public: 347 347 // In SpiderMonkey 1.6, JS_ReportError calls the error reporter even if it's inside 348 348 // a try{} in the script; in recent versions (not sure when it changed) it doesn't 349 349 // 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"); 351 351 } 352 352 } 353 353 -
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; 100 100 101 101 // Definition of functions from lib/self_test.h 102 102 103 bool ts_str_contains(const std::string& str1, const std::string& str2) 104 { 105 return str1.find(str2) != str1.npos; 106 } 107 103 108 bool ts_str_contains(const std::wstring& str1, const std::wstring& str2) 104 109 { 105 110 return str1.find(str2) != str1.npos;