MCPcopy Create free account
hub / github.com/HelenOS/helenos / test_construction_and_assignment

Method test_construction_and_assignment

uspace/lib/cpp/src/__bits/test/string.cpp:59–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 }
58
59 void string_test::test_construction_and_assignment()
60 {
61 const char* check1 = "hello";
62
63 std::string str1{"hello"};
64 test_eq(
65 "size of string",
66 str1.size(), 5ul
67 );
68 test_eq(
69 "initialization from a cstring literal",
70 str1.begin(), str1.end(),
71 check1, check1 + 5
72 );
73
74 std::string str2{str1};
75 test_eq(
76 "copy constructor",
77 str1.begin(), str1.end(),
78 str2.begin(), str2.end()
79 );
80
81 std::string str3{std::move(str1)};
82 test_eq(
83 "move constructor equality",
84 str2.begin(), str2.end(),
85 str3.begin(), str3.end()
86 );
87 test_eq(
88 "move constructor source empty",
89 str1.size(), 0ul
90 );
91
92 std::string str4{};
93 test_eq(
94 "default constructor empty",
95 str4.size(), 0ul
96 );
97
98 str4.assign(str3, 2ul, 2ul);
99 test_eq(
100 "assign substring to an empty string",
101 str4.begin(), str4.end(),
102 str3.begin() + 2, str3.begin() + 4
103 );
104
105 std::string str5{str3.begin() + 2, str3.begin() + 4};
106 test_eq(
107 "constructor from a pair of iterators",
108 str5.begin(), str5.end(),
109 str3.begin() + 2, str3.begin() + 4
110 );
111 }
112
113 void string_test::test_append()
114 {

Callers

nothing calls this directly

Calls 5

moveFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected