generic_string_alloc.pass.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <experimental/filesystem>
  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. namespace fs = std::experimental::filesystem;
  25. MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  26. // generic_string<C, T, A> forwards to string<C, T, A>. Tests for
  27. // string<C, T, A>() are in "path.native.op/string_alloc.pass.cpp".
  28. // generic_string is minimally tested here.
  29. int main()
  30. {
  31. using namespace fs;
  32. using CharT = wchar_t;
  33. using Traits = std::char_traits<CharT>;
  34. using Alloc = malloc_allocator<CharT>;
  35. using Str = std::basic_string<CharT, Traits, Alloc>;
  36. const wchar_t* expect = longString;
  37. const path p((const char*)longString);
  38. {
  39. DisableAllocationGuard g;
  40. Alloc a;
  41. Alloc::disable_default_constructor = true;
  42. Str s = p.generic_string<wchar_t, Traits, Alloc>(a);
  43. assert(s == expect);
  44. assert(Alloc::alloc_count > 0);
  45. assert(Alloc::outstanding_alloc() == 1);
  46. }
  47. }