[libcxx-commits] [libcxx] c12c812 - [libcxx] [test] Change the generic_string_alloc test to test conversions to all char types

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 14 01:57:08 PDT 2021


Author: Martin Storsjö
Date: 2021-05-14T11:56:48+03:00
New Revision: c12c8124e14217779eb5b8d3a2a92a6469a799e7

URL: https://github.com/llvm/llvm-project/commit/c12c8124e14217779eb5b8d3a2a92a6469a799e7
DIFF: https://github.com/llvm/llvm-project/commit/c12c8124e14217779eb5b8d3a2a92a6469a799e7.diff

LOG: [libcxx] [test] Change the generic_string_alloc test to test conversions to all char types

On windows, the native path char type is wchar_t - therefore, this test
didn't actually do the conversion that the test was supposed to exercise.

The charset conversions on windows do cause extra allocations outside of
the provided allocator though, so that bit of the test has to be waived
now that the test actually does something. (Other tests have similar
TEST_NOT_WIN32() for allocation checks for charset conversions.)

Also fix a typo, and amend the path.native.obs/string_alloc test to
test char8_t, too.

Differential Revision: https://reviews.llvm.org/D102360

Added: 
    

Modified: 
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/string_alloc.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp
index c57ca6ebbaec8..8034e22080890 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp
@@ -34,26 +34,39 @@ MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR
 
 
 // generic_string<C, T, A> forwards to string<C, T, A>. Tests for
-// string<C, T, A>() are in "path.native.op/string_alloc.pass.cpp".
+// string<C, T, A>() are in "path.native.obs/string_alloc.pass.cpp".
 // generic_string is minimally tested here.
-int main(int, char**)
+template <class CharT>
+void doAllocTest()
 {
   using namespace fs;
-  using CharT = wchar_t;
   using Traits = std::char_traits<CharT>;
   using Alloc = malloc_allocator<CharT>;
   using Str = std::basic_string<CharT, Traits, Alloc>;
-  const wchar_t* expect = longString;
+  const CharT* expect = longString;
   const path p((const char*)longString);
   {
-    DisableAllocationGuard g;
+    // On Windows, charset conversions cause allocations outside of the
+    // provided allocator.
+    TEST_NOT_WIN32(DisableAllocationGuard g);
     Alloc a;
     Alloc::disable_default_constructor = true;
-    Str s = p.generic_string<wchar_t, Traits, Alloc>(a);
+    Str s = p.generic_string<CharT, Traits, Alloc>(a);
     assert(s == expect);
     assert(Alloc::alloc_count > 0);
     assert(Alloc::outstanding_alloc() == 1);
+    Alloc::disable_default_constructor = false;
   }
+}
 
+int main(int, char**)
+{
+  doAllocTest<char>();
+  doAllocTest<wchar_t>();
+  doAllocTest<char16_t>();
+  doAllocTest<char32_t>();
+#if TEST_STD_VER > 17 && defined(__cpp_lib_char8_t)
+  doAllocTest<char8_t>();
+#endif
   return 0;
 }

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/string_alloc.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/string_alloc.pass.cpp
index 1b462b4b9053b..7bdae75bcb296 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/string_alloc.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.native.obs/string_alloc.pass.cpp
@@ -150,6 +150,9 @@ int main(int, char**)
     doShortStringTest<wchar_t>(S);
     doShortStringTest<char16_t>(S);
     doShortStringTest<char32_t>(S);
+#if TEST_STD_VER > 17 && defined(__cpp_lib_char8_t)
+    doShortStringTest<char8_t>(S);
+#endif
   }
   {
     auto const& S = longString;
@@ -157,6 +160,9 @@ int main(int, char**)
     doLongStringTest<wchar_t>(S);
     doLongStringTest<char16_t>(S);
     doLongStringTest<char32_t>(S);
+#if TEST_STD_VER > 17 && defined(__cpp_lib_char8_t)
+    doLongStringTest<char8_t>(S);
+#endif
   }
 
   return 0;


        


More information about the libcxx-commits mailing list