123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //===----------------------------------------------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is dual licensed under the MIT and the University of Illinois Open
- // Source Licenses. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- // UNSUPPORTED: c++98, c++03
- // <experimental/filesystem>
- // class path
- // template <class ECharT, class Traits = char_traits<ECharT>,
- // class Allocator = allocator<ECharT>>
- // basic_string<ECharT, Traits, Allocator>
- // string(const Allocator& a = Allocator()) const;
- #include <experimental/filesystem>
- #include <type_traits>
- #include <cassert>
- #include "test_macros.h"
- #include "test_iterators.h"
- #include "count_new.hpp"
- #include "min_allocator.h"
- #include "filesystem_test_helper.hpp"
- namespace fs = std::experimental::filesystem;
- MultiStringType shortString = MKSTR("abc");
- MultiStringType longString = MKSTR("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
- template <class CharT>
- void doShortStringTest(MultiStringType const& MS) {
- using namespace fs;
- using Ptr = CharT const*;
- using Str = std::basic_string<CharT>;
- using Alloc = std::allocator<CharT>;
- Ptr value = MS;
- const path p((const char*)MS);
- {
- DisableAllocationGuard g;
- if (!std::is_same<CharT, char>::value)
- g.release();
- Str s = p.string<CharT>();
- assert(s == value);
- Str s2 = p.string<CharT>(Alloc{});
- assert(s2 == value);
- }
- using MAlloc = malloc_allocator<CharT>;
- MAlloc::reset();
- {
- using Traits = std::char_traits<CharT>;
- using AStr = std::basic_string<CharT, Traits, MAlloc>;
- AStr s = p.string<CharT, Traits, MAlloc>();
- assert(s == value);
- assert(MAlloc::alloc_count == 0);
- assert(MAlloc::outstanding_alloc() == 0);
- }
- MAlloc::reset();
- { // Other allocator - provided copy
- using Traits = std::char_traits<CharT>;
- using AStr = std::basic_string<CharT, Traits, MAlloc>;
- MAlloc a;
- // don't allow another allocator to be default constructed.
- MAlloc::disable_default_constructor = true;
- AStr s = p.string<CharT, Traits, MAlloc>(a);
- assert(s == value);
- assert(MAlloc::alloc_count == 0);
- assert(MAlloc::outstanding_alloc() == 0);
- }
- MAlloc::reset();
- }
- template <class CharT>
- void doLongStringTest(MultiStringType const& MS) {
- using namespace fs;
- using Ptr = CharT const*;
- using Str = std::basic_string<CharT>;
- Ptr value = MS;
- const path p((const char*)MS);
- { // Default allocator
- using Alloc = std::allocator<CharT>;
- Str s = p.string<CharT>();
- assert(s == value);
- Str s2 = p.string<CharT>(Alloc{});
- assert(s2 == value);
- }
- using MAlloc = malloc_allocator<CharT>;
- MAlloc::reset();
- { // Other allocator - default construct
- using Traits = std::char_traits<CharT>;
- using AStr = std::basic_string<CharT, Traits, MAlloc>;
- AStr s = p.string<CharT, Traits, MAlloc>();
- assert(s == value);
- assert(MAlloc::alloc_count > 0);
- assert(MAlloc::outstanding_alloc() == 1);
- }
- MAlloc::reset();
- { // Other allocator - provided copy
- using Traits = std::char_traits<CharT>;
- using AStr = std::basic_string<CharT, Traits, MAlloc>;
- MAlloc a;
- // don't allow another allocator to be default constructed.
- MAlloc::disable_default_constructor = true;
- AStr s = p.string<CharT, Traits, MAlloc>(a);
- assert(s == value);
- assert(MAlloc::alloc_count > 0);
- assert(MAlloc::outstanding_alloc() == 1);
- }
- MAlloc::reset();
- /////////////////////////////////////////////////////////////////////////////
- }
- int main()
- {
- using namespace fs;
- {
- auto const& S = shortString;
- doShortStringTest<char>(S);
- doShortStringTest<wchar_t>(S);
- doShortStringTest<char16_t>(S);
- doShortStringTest<char32_t>(S);
- }
- {
- auto const& S = longString;
- doLongStringTest<char>(S);
- doLongStringTest<wchar_t>(S);
- doLongStringTest<char16_t>(S);
- doLongStringTest<char32_t>(S);
- }
- }
|