generic_string_alloc.pass.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // UNSUPPORTED: c++98, c++03
  10. // <experimental/filesystem>
  11. // class path
  12. // template <class ECharT, class Traits = char_traits<ECharT>,
  13. // class Allocator = allocator<ECharT>>
  14. // basic_string<ECharT, Traits, Allocator>
  15. // generic_string(const Allocator& a = Allocator()) const;
  16. #include "filesystem_include.hpp"
  17. #include <type_traits>
  18. #include <cassert>
  19. #include "test_macros.h"
  20. #include "test_iterators.h"
  21. #include "count_new.hpp"
  22. #include "min_allocator.h"
  23. #include "filesystem_test_helper.hpp"
  24. MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  25. // generic_string<C, T, A> forwards to string<C, T, A>. Tests for
  26. // string<C, T, A>() are in "path.native.op/string_alloc.pass.cpp".
  27. // generic_string is minimally tested here.
  28. int main()
  29. {
  30. using namespace fs;
  31. using CharT = wchar_t;
  32. using Traits = std::char_traits<CharT>;
  33. using Alloc = malloc_allocator<CharT>;
  34. using Str = std::basic_string<CharT, Traits, Alloc>;
  35. const wchar_t* expect = longString;
  36. const path p((const char*)longString);
  37. {
  38. DisableAllocationGuard g;
  39. Alloc a;
  40. Alloc::disable_default_constructor = true;
  41. Str s = p.generic_string<wchar_t, Traits, Alloc>(a);
  42. assert(s == expect);
  43. assert(Alloc::alloc_count > 0);
  44. assert(Alloc::outstanding_alloc() == 1);
  45. }
  46. }