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
10 // <string>
11
12 // basic_string(const charT* s, const Allocator& a = Allocator());
13
14 #include <string>
15 #include <stdexcept>
16 #include <algorithm>
17 #include <cassert>
18
19 #include "../test_allocator.h"
20
21 template <class charT>
22 void
test(const charT * s)23 test(const charT* s)
24 {
25 typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
26 typedef typename S::traits_type T;
27 typedef typename S::allocator_type A;
28 unsigned n = T::length(s);
29 S s2(s);
30 assert(s2.__invariants());
31 assert(s2.size() == n);
32 assert(T::compare(s2.data(), s, n) == 0);
33 assert(s2.get_allocator() == A());
34 assert(s2.capacity() >= s2.size());
35 }
36
37 template <class charT>
38 void
test(const charT * s,const test_allocator<charT> & a)39 test(const charT* s, const test_allocator<charT>& a)
40 {
41 typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
42 typedef typename S::traits_type T;
43 typedef typename S::allocator_type A;
44 unsigned n = T::length(s);
45 S s2(s, a);
46 assert(s2.__invariants());
47 assert(s2.size() == n);
48 assert(T::compare(s2.data(), s, n) == 0);
49 assert(s2.get_allocator() == a);
50 assert(s2.capacity() >= s2.size());
51 }
52
main()53 int main()
54 {
55 typedef test_allocator<char> A;
56 typedef std::basic_string<char, std::char_traits<char>, A> S;
57
58 test("");
59 test("", A(2));
60
61 test("1");
62 test("1", A(2));
63
64 test("1234567980");
65 test("1234567980", A(2));
66
67 test("123456798012345679801234567980123456798012345679801234567980");
68 test("123456798012345679801234567980123456798012345679801234567980", A(2));
69 }
70