[Lldb-commits] [PATCH] D36496: Fix VASprintfTest.cpp for Darwin, add checks

Tim Hammerquist via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 8 16:31:11 PDT 2017


penryu created this revision.

The EncodingError test ensures that trying to encode a multibyte wchar
with a given codepage fails. If setlocale() fails, the encoding is
performed using the current locale, which may or may not fail.

This patch asserts that both setlocale() operations are successful, as
well as falling back to a widely available unibyte encoding for
non-Windows systems.

rdar://problem/33782806


https://reviews.llvm.org/D36496

Files:
  lldb.xcodeproj/project.pbxproj
  unittests/Utility/VASprintfTest.cpp


Index: unittests/Utility/VASprintfTest.cpp
===================================================================
--- unittests/Utility/VASprintfTest.cpp
+++ unittests/Utility/VASprintfTest.cpp
@@ -14,6 +14,12 @@
 
 #include <locale.h>
 
+#if defined (_WIN32)
+#define TEST_ENCODING ".932"  // On Windows, test codepage 932
+#else
+#define TEST_ENCODING "C"     // ...otherwise, any widely available uni-byte LC
+#endif
+
 using namespace lldb_private;
 using namespace llvm;
 
@@ -46,14 +52,16 @@
   // Save the current locale first.
   std::string Current(::setlocale(LC_ALL, nullptr));
 
-  setlocale(LC_ALL, ".932");
+  // Ensure tested locale is successfully set
+  ASSERT_TRUE(setlocale(LC_ALL, TEST_ENCODING));
 
   wchar_t Invalid[2];
   Invalid[0] = 0x100;
   Invalid[1] = 0;
   llvm::SmallString<32> Buffer;
   EXPECT_FALSE(Sprintf(Buffer, "%ls", Invalid));
   EXPECT_EQ("<Encoding error>", Buffer);
 
-  setlocale(LC_ALL, Current.c_str());
+  // Ensure we've restored the original locale once tested
+  ASSERT_TRUE(setlocale(LC_ALL, Current.c_str()));
 }
Index: lldb.xcodeproj/project.pbxproj
===================================================================
--- lldb.xcodeproj/project.pbxproj
+++ lldb.xcodeproj/project.pbxproj
@@ -875,6 +875,7 @@
 		9A19A6B01163BBB300E0D453 /* SBValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A19A6AD1163BB9800E0D453 /* SBValue.cpp */; };
 		9A1E595C1EB2B141002206A5 /* SBTrace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A1E59521EB2B0B9002206A5 /* SBTrace.cpp */; };
 		9A1E595D1EB2B141002206A5 /* SBTraceOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A1E59531EB2B0B9002206A5 /* SBTraceOptions.cpp */; };
+		9A2057031F3A605200F6C293 /* VASprintfTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A3D43C41F3150D200EB767C /* VASprintfTest.cpp */; };
 		9A22A161135E30370024DDC3 /* EmulateInstructionARM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A22A15D135E30370024DDC3 /* EmulateInstructionARM.cpp */; };
 		9A22A163135E30370024DDC3 /* EmulationStateARM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A22A15F135E30370024DDC3 /* EmulationStateARM.cpp */; };
 		9A357583116CFDEE00E8ED2F /* SBValueList.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A357582116CFDEE00E8ED2F /* SBValueList.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -7092,6 +7093,7 @@
 				AFEC5FD81D94F9380076A480 /* Testx86AssemblyInspectionEngine.cpp in Sources */,
 				23CB15401D66DA9300EDDDE1 /* TestClangASTContext.cpp in Sources */,
 				23CB15411D66DA9300EDDDE1 /* StringExtractorTest.cpp in Sources */,
+				9A2057031F3A605200F6C293 /* VASprintfTest.cpp in Sources */,
 				23CB15421D66DA9300EDDDE1 /* TaskPoolTest.cpp in Sources */,
 				23CB15431D66DA9300EDDDE1 /* BroadcasterTest.cpp in Sources */,
 				9A3D43EE1F3237F900EB767C /* StreamCallbackTest.cpp in Sources */,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36496.110300.patch
Type: text/x-patch
Size: 2856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170808/0eedf00c/attachment.bin>


More information about the lldb-commits mailing list