//===----------------------------------------------------------------------===// // // 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 // // class path // template , // class Allocator = allocator> // basic_string // string(const Allocator& a = Allocator()) const; #include #include #include #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 void doShortStringTest(MultiStringType const& MS) { using namespace fs; using Ptr = CharT const*; using Str = std::basic_string; using Alloc = std::allocator; Ptr value = MS; const path p((const char*)MS); { DisableAllocationGuard g; if (!std::is_same::value) g.release(); Str s = p.string(); assert(s == value); Str s2 = p.string(Alloc{}); assert(s2 == value); } using MAlloc = malloc_allocator; MAlloc::reset(); { using Traits = std::char_traits; using AStr = std::basic_string; AStr s = p.string(); assert(s == value); assert(MAlloc::alloc_count == 0); assert(MAlloc::outstanding_alloc() == 0); } MAlloc::reset(); { // Other allocator - provided copy using Traits = std::char_traits; using AStr = std::basic_string; MAlloc a; // don't allow another allocator to be default constructed. MAlloc::disable_default_constructor = true; AStr s = p.string(a); assert(s == value); assert(MAlloc::alloc_count == 0); assert(MAlloc::outstanding_alloc() == 0); } MAlloc::reset(); } template void doLongStringTest(MultiStringType const& MS) { using namespace fs; using Ptr = CharT const*; using Str = std::basic_string; Ptr value = MS; const path p((const char*)MS); { // Default allocator using Alloc = std::allocator; Str s = p.string(); assert(s == value); Str s2 = p.string(Alloc{}); assert(s2 == value); } using MAlloc = malloc_allocator; MAlloc::reset(); { // Other allocator - default construct using Traits = std::char_traits; using AStr = std::basic_string; AStr s = p.string(); assert(s == value); assert(MAlloc::alloc_count > 0); assert(MAlloc::outstanding_alloc() == 1); } MAlloc::reset(); { // Other allocator - provided copy using Traits = std::char_traits; using AStr = std::basic_string; MAlloc a; // don't allow another allocator to be default constructed. MAlloc::disable_default_constructor = true; AStr s = p.string(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(S); doShortStringTest(S); doShortStringTest(S); doShortStringTest(S); } { auto const& S = longString; doLongStringTest(S); doLongStringTest(S); doLongStringTest(S); doLongStringTest(S); } }