libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

generic_string_alloc.pass.cpp (1783B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03
     11 
     12 // <filesystem>
     13 
     14 // class path
     15 
     16 // template <class ECharT, class Traits = char_traits<ECharT>,
     17 //           class Allocator = allocator<ECharT>>
     18 // basic_string<ECharT, Traits, Allocator>
     19 // generic_string(const Allocator& a = Allocator()) const;
     20 
     21 #include "filesystem_include.hpp"
     22 #include <type_traits>
     23 #include <cassert>
     24 
     25 #include "test_macros.h"
     26 #include "test_iterators.h"
     27 #include "count_new.hpp"
     28 #include "min_allocator.h"
     29 #include "filesystem_test_helper.hpp"
     30 
     31 MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
     32 
     33 
     34 // generic_string<C, T, A> forwards to string<C, T, A>. Tests for
     35 // string<C, T, A>() are in "path.native.op/string_alloc.pass.cpp".
     36 // generic_string is minimally tested here.
     37 int main()
     38 {
     39   using namespace fs;
     40   using CharT = wchar_t;
     41   using Traits = std::char_traits<CharT>;
     42   using Alloc = malloc_allocator<CharT>;
     43   using Str = std::basic_string<CharT, Traits, Alloc>;
     44   const wchar_t* expect = longString;
     45   const path p((const char*)longString);
     46   {
     47     DisableAllocationGuard g;
     48     Alloc a;
     49     Alloc::disable_default_constructor = true;
     50     Str s = p.generic_string<wchar_t, Traits, Alloc>(a);
     51     assert(s == expect);
     52     assert(Alloc::alloc_count > 0);
     53     assert(Alloc::outstanding_alloc() == 1);
     54   }
     55 }