pointer_assignment.pass.cpp 2.5 KB

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