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<charT,traits,Allocator>& 13 // operator=(const charT* s); 14 15 #include <string> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "min_allocator.h" 20 21 template <class S> 22 void 23 test(S s1, const typename S::value_type* s2) 24 { 25 typedef typename S::traits_type T; 26 s1 = s2; 27 LIBCPP_ASSERT(s1.__invariants()); 28 assert(s1.size() == T::length(s2)); 29 assert(T::compare(s1.data(), s2, s1.size()) == 0); 30 assert(s1.capacity() >= s1.size()); 31 } 32 33 int main() 34 { 35 { 36 typedef std::string S; 37 test(S(), ""); 38 test(S("1"), ""); 39 test(S(), "1"); 40 test(S("1"), "2"); 41 test(S("1"), "2"); 42 43 test(S(), 44 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 45 test(S("123456789"), 46 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 47 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 48 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 49 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 50 "1234567890123456789012345678901234567890123456789012345678901234567890"), 51 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 52 } 53 #if TEST_STD_VER >= 11 54 { 55 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 56 test(S(), ""); 57 test(S("1"), ""); 58 test(S(), "1"); 59 test(S("1"), "2"); 60 test(S("1"), "2"); 61 62 test(S(), 63 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 64 test(S("123456789"), 65 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 66 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 67 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 68 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 69 "1234567890123456789012345678901234567890123456789012345678901234567890"), 70 "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); 71 } 72 #endif 73 } 74