generic_string_alloc.pass.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03
  9. // <filesystem>
  10. // class path
  11. // template <class ECharT, class Traits = char_traits<ECharT>,
  12. // class Allocator = allocator<ECharT>>
  13. // basic_string<ECharT, Traits, Allocator>
  14. // generic_string(const Allocator& a = Allocator()) const;
  15. #include "filesystem_include.hpp"
  16. #include <type_traits>
  17. #include <cassert>
  18. #include "test_macros.h"
  19. #include "test_iterators.h"
  20. #include "count_new.hpp"
  21. #include "min_allocator.h"
  22. #include "filesystem_test_helper.hpp"
  23. MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  24. // generic_string<C, T, A> forwards to string<C, T, A>. Tests for
  25. // string<C, T, A>() are in "path.native.op/string_alloc.pass.cpp".
  26. // generic_string is minimally tested here.
  27. int main(int, char**)
  28. {
  29. using namespace fs;
  30. using CharT = wchar_t;
  31. using Traits = std::char_traits<CharT>;
  32. using Alloc = malloc_allocator<CharT>;
  33. using Str = std::basic_string<CharT, Traits, Alloc>;
  34. const wchar_t* expect = longString;
  35. const path p((const char*)longString);
  36. {
  37. DisableAllocationGuard g;
  38. Alloc a;
  39. Alloc::disable_default_constructor = true;
  40. Str s = p.generic_string<wchar_t, Traits, Alloc>(a);
  41. assert(s == expect);
  42. assert(Alloc::alloc_count > 0);
  43. assert(Alloc::outstanding_alloc() == 1);
  44. }
  45. return 0;
  46. }