Skip to content

Commit 753fbcb

Browse files
Tacetcopybara-github
Tacet
authored andcommitted
Add std::basic_string test cases (#74830)
Extend `std::basic_string` tests to cover more buffer situations and length in general, particularly non-SSO cases after SSO test cases (changing buffers). This commit is a side effect of working on tests for ASan annotations. Related PR: llvm/llvm-project#72677 NOKEYCHECK=True GitOrigin-RevId: c77cdbac9b121611121adf5806a99aff4812a40c
1 parent 3d39d2a commit 753fbcb

22 files changed

+113
-0
lines changed

test/std/strings/basic.string/string.capacity/reserve.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ template <class S>
3939
void test_string() {
4040
test<S>(0, 0);
4141
test<S>(10, 5);
42+
test<S>(100, 5);
4243
test<S>(100, 50);
4344
}
4445

test/std/strings/basic.string/string.capacity/reserve_size.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
6464
test<S>(0, 0, 50);
6565
}
6666
{
67+
test<S>(100, 1, 5);
6768
test<S>(100, 50, 5);
6869
test<S>(100, 50, 10);
6970
test<S>(100, 50, 50);

test/std/strings/basic.string/string.capacity/shrink_to_fit.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ TEST_CONSTEXPR_CXX20 void test_string() {
3636
s.erase(5);
3737
test(s);
3838

39+
s.assign(50, 'a');
40+
s.erase(5);
41+
test(s);
42+
3943
s.assign(100, 'a');
4044
s.erase(50);
4145
test(s);

test/std/strings/basic.string/string.cons/copy_assignment.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
3535

3636
test(S(), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
3737
test(S("123456789"), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
38+
test(S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"), S("123456789"));
3839
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
3940
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
4041
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"

test/std/strings/basic.string/string.cons/move_assignment.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4040

4141
test(S(), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
4242
test(S("123456789"), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
43+
test(S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"), S("123456789"));
4344
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
4445
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
4546
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"

test/std/strings/basic.string/string.cons/pointer_assignment.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
3737

3838
test(S(), "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
3939
test(S("123456789"), "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
40+
test(S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"), "123456789");
4041
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
4142
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
4243
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"

test/std/strings/basic.string/string.cons/string_view_assignment.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
3737

3838
test(S(), SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
3939
test(S("123456789"), SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
40+
test(S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"), SV("123456789"));
4041
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
4142
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
4243
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"

test/std/strings/basic.string/string.modifiers/string_append/T_size_size.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ TEST_CONSTEXPR_CXX20 void test_string() {
8080
test(S("12345678901234567890"), SV(), 0, 0, S("12345678901234567890"));
8181
test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234"));
8282
test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, S("123456789012345678906789012345"));
83+
84+
// Starting from long string (no SSO)
85+
test(S("1234512345678901234567890"), SV(), 0, 0, S("1234512345678901234567890"));
86+
test(S("1234512345678901234567890"), SV("12345"), 1, 3, S("1234512345678901234567890234"));
87+
test(S("1234512345678901234567890"), SV("12345678901234567890"), 5, 10, S("12345123456789012345678906789012345"));
8388
}
8489

8590
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ TEST_CONSTEXPR_CXX20 void test_string() {
6868
test(S(), 'a', S(1, 'a'));
6969
test(S("12345"), 'a', S("12345a"));
7070
test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
71+
test(S("123abcabcdefghabcdefgh"), 'a', S("123abcabcdefghabcdefgha"));
72+
test(S("123abcabcdefghabcdefgha"), 'b', S("123abcabcdefghabcdefghab"));
73+
test(S("123abcabcdefghabcdefghab"), 'c', S("123abcabcdefghabcdefghabc"));
74+
test(S("123abcabcdefghabcdefghabc"), 'd', S("123abcabcdefghabcdefghabcd"));
7175
}
7276

7377
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_append/size_char.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ TEST_CONSTEXPR_CXX20 void test_string() {
3838
test(S("12345678901234567890"), 0, 'a', S("12345678901234567890"));
3939
test(S("12345678901234567890"), 1, 'a', S("12345678901234567890a"));
4040
test(S("12345678901234567890"), 10, 'a', S("12345678901234567890aaaaaaaaaa"));
41+
42+
// Starting from long string (no SSO)
43+
test(S("1234567890123456789012345678901234567890"), 0, 'a', S("1234567890123456789012345678901234567890"));
44+
test(S("1234567890123456789012345678901234567890"), 1, 'a', S("1234567890123456789012345678901234567890a"));
45+
test(S("1234567890123456789012345678901234567890"), 10, 'a', S("1234567890123456789012345678901234567890aaaaaaaaaa"));
4146
}
4247

4348
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_append/string.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4545
test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
4646
test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
4747
test(S("12345678901234567890"), S("12345678901234567890"), S("1234567890123456789012345678901234567890"));
48+
49+
// Starting from long string (no SSO)
50+
test(S("123456789012345678901234567890"), S(), S("123456789012345678901234567890"));
51+
test(S("123456789012345678901234567890"), S("12345"), S("12345678901234567890123456789012345"));
52+
test(S("123456789012345678901234567890"), S("1234567890"), S("1234567890123456789012345678901234567890"));
53+
test(S("123456789012345678901234567890"),
54+
S("12345678901234567890"),
55+
S("12345678901234567890123456789012345678901234567890"));
4856
}
4957

5058
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_append/string_size_size.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ TEST_CONSTEXPR_CXX20 void test_string() {
7979
test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
8080
test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
8181
test(S("12345678901234567890"), S("12345678901234567890"), 5, 10, S("123456789012345678906789012345"));
82+
83+
// Starting from long string (no SSO)
84+
test(S("123456789012345678901234567890"), S(), 0, 0, S("123456789012345678901234567890"));
85+
test(S("123456789012345678901234567890"), S("12345"), 1, 3, S("123456789012345678901234567890234"));
86+
test(S("123456789012345678901234567890"),
87+
S("12345678901234567890"),
88+
5,
89+
10,
90+
S("1234567890123456789012345678906789012345"));
8291
}
8392

8493
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_append/string_view.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4747
test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
4848
test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
4949
test(S("12345678901234567890"), SV("12345678901234567890"), S("1234567890123456789012345678901234567890"));
50+
51+
// Starting from long string (no SSO)
52+
test(S("123456789012345678901234567890"), SV(), S("123456789012345678901234567890"));
53+
test(S("123456789012345678901234567890"), SV("12345"), S("12345678901234567890123456789012345"));
54+
test(S("123456789012345678901234567890"), SV("1234567890"), S("1234567890123456789012345678901234567890"));
55+
test(S("123456789012345678901234567890"),
56+
SV("12345678901234567890"),
57+
S("12345678901234567890123456789012345678901234567890"));
5058
}
5159

5260
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_assign/pointer.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ TEST_CONSTEXPR_CXX20 void test_string() {
3737
test(S("12345678901234567890"), "", S());
3838
test(S("12345678901234567890"), "12345", S("12345"));
3939
test(S("12345678901234567890"), "12345678901234567890", S("12345678901234567890"));
40+
41+
// Starting from long string (no SSO)
42+
test(S("1234512345678901234567890"), "", S());
43+
test(S("1234512345678901234567890"), "12345", S("12345"));
44+
test(S("1234512345678901234567890"), "12345678901234567890", S("12345678901234567890"));
4045
}
4146

4247
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_assign/pointer_size.pass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4242
test(S("12345678901234567890"), "", 0, S());
4343
test(S("12345678901234567890"), "12345", 5, S("12345"));
4444
test(S("12345678901234567890"), "12345678901234567890", 20, S("12345678901234567890"));
45+
46+
// Starting from long string (no SSO)
47+
test(S("1234512345678901234567890"), "", 0, S());
48+
test(S("1234512345678901234567890"), "12345", 5, S("12345"));
49+
test(S("1234512345678901234567890"), "12345678901234567890", 20, S("12345678901234567890"));
50+
test(S("1234512345678901234567890"), "123451234512345678901234567890", 30, S("123451234512345678901234567890"));
4551
}
4652

4753
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_copy/copy.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ TEST_CONSTEXPR_CXX20 void test_string() {
102102
test(S("abcdefghijklmnopqrst"), s, 20, 0);
103103
test(S("abcdefghijklmnopqrst"), s, 20, 1);
104104
test(S("abcdefghijklmnopqrst"), s, 21, 0);
105+
test(S("abcdefghijklmnopqrstabcdefghijklmnopqrst"), s, 40, 1);
106+
test(S("abcdefghijklmnopqrstabcdefghijklmnopqrst"), s, 40, 0);
105107
}
106108

107109
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_insert/iter_char.pass.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4747
test(s, s.begin() + 4, 'A', S("a567A1432dcb"));
4848
test(s, s.begin() + 5, 'B', S("a567AB1432dcb"));
4949
test(s, s.begin() + 6, 'C', S("a567ABC1432dcb"));
50+
test(s, s.begin(), 'x', S("xa567ABC1432dcb"));
51+
test(s, s.begin(), 'x', S("xxa567ABC1432dcb"));
52+
test(s, s.begin(), 'x', S("xxxa567ABC1432dcb"));
53+
test(s, s.begin(), 'x', S("xxxxa567ABC1432dcb"));
54+
test(s, s.begin(), 'x', S("xxxxxa567ABC1432dcb"));
55+
test(s, s.begin(), 'x', S("xxxxxxa567ABC1432dcb"));
56+
test(s, s.begin(), 'x', S("xxxxxxxa567ABC1432dcb"));
57+
test(s, s.begin(), 'x', S("xxxxxxxxa567ABC1432dcb"));
58+
test(s, s.begin(), 'x', S("xxxxxxxxxa567ABC1432dcb"));
59+
test(s, s.begin(), 'x', S("xxxxxxxxxxa567ABC1432dcb"));
60+
test(s, s.begin(), 'x', S("xxxxxxxxxxxa567ABC1432dcb"));
61+
test(s, s.begin(), 'x', S("xxxxxxxxxxxxa567ABC1432dcb"));
62+
test(s, s.begin(), 'x', S("xxxxxxxxxxxxxa567ABC1432dcb"));
63+
test(s, s.begin(), 'x', S("xxxxxxxxxxxxxxa567ABC1432dcb"));
64+
test(s, s.begin(), 'x', S("xxxxxxxxxxxxxxxa567ABC1432dcb"));
65+
test(s, s.begin(), 'x', S("xxxxxxxxxxxxxxxxa567ABC1432dcb"));
66+
test(s, s.begin() + 1, 'x', S("xxxxxxxxxxxxxxxxxa567ABC1432dcb"));
5067
}
5168

5269
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_op_plus_equal/char.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
2929
test(S("12345"), 'a', S("12345a"));
3030
test(S("1234567890"), 'a', S("1234567890a"));
3131
test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
32+
test(S("1234567890123456789012345678901234567890"), 'a', S("1234567890123456789012345678901234567890a"));
3233
}
3334

3435
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_op_plus_equal/pointer.pass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4444
test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
4545
test(S("12345678901234567890"), "1234567890", S("123456789012345678901234567890"));
4646
test(S("12345678901234567890"), "12345678901234567890", S("1234567890123456789012345678901234567890"));
47+
48+
// Starting from long string (no SSO)
49+
test(S("1234567890123456789012345678901234567890"), "", S("1234567890123456789012345678901234567890"));
50+
test(S("1234567890123456789012345678901234567890"), "12345", S("123456789012345678901234567890123456789012345"));
51+
test(S("1234567890123456789012345678901234567890"),
52+
"12345678901234567890",
53+
S("123456789012345678901234567890123456789012345678901234567890"));
54+
test(S("1234567890123456789012345678901234567890"),
55+
"1234567890123456789012345678901234567890",
56+
S("12345678901234567890123456789012345678901234567890123456789012345678901234567890"));
4757
}
4858

4959
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.modifiers/string_op_plus_equal/string.pass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4545
test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
4646
test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
4747
test(S("12345678901234567890"), S("12345678901234567890"), S("1234567890123456789012345678901234567890"));
48+
49+
// Starting from long string (no SSO)
50+
test(S("1234567890123456789012345678901234567890"), S(), S("1234567890123456789012345678901234567890"));
51+
test(S("1234567890123456789012345678901234567890"), S("12345"), S("123456789012345678901234567890123456789012345"));
52+
test(S("1234567890123456789012345678901234567890"),
53+
S("12345678901234567890"),
54+
S("123456789012345678901234567890123456789012345678901234567890"));
55+
test(S("1234567890123456789012345678901234567890"),
56+
S("1234567890123456789012345678901234567890"),
57+
S("12345678901234567890123456789012345678901234567890123456789012345678901234567890"));
4858
}
4959

5060
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.nonmembers/string.special/swap.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4949
test(S("abcdefghijklmnopqrst"), S("12345"));
5050
test(S("abcdefghijklmnopqrst"), S("1234567890"));
5151
test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
52+
test(S("abcdefghijklmnopqrst123456LONG1234567890"), S(""));
53+
test(S("abcdefghijklmnopqrst123456LONG1234567890"), S("12345"));
54+
test(S("abcdefghijklmnopqrst123456LONG1234567890"), S("1234567890"));
55+
test(S("abcdefghijklmnopqrst123456LONG1234567890"), S("12345678901234567890"));
5256
}
5357

5458
TEST_CONSTEXPR_CXX20 bool test() {

test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ TEST_CONSTEXPR_CXX20 void test_string() {
102102
test(S("ktsrmnqagdecfhijpobl"), 19, 1);
103103
test(S("lsaijeqhtrbgcdmpfkno"), 20, 0);
104104
test(S("dplqartnfgejichmoskb"), 21, 0);
105+
test(S("gbmetiprqdoasckjfhlnxx"), 0, 22);
106+
test(S("gbmetiprqdoasckjfhlnxa"), 0, 8);
107+
test(S("gbmetiprqdoasckjfhlnxb"), 1, 0);
108+
test(S("LONGtiprqdoasckjfhlnxxo"), 0, 23);
109+
test(S("LONGtiprqdoasckjfhlnxap"), 0, 8);
110+
test(S("LONGtiprqdoasckjfhlnxbl"), 1, 0);
111+
test(S("LONGtiprqdoasckjfhlnxxyy"), 0, 24);
112+
test(S("LONGtiprqdoasckjfhlnxxyr"), 0, 8);
113+
test(S("LONGtiprqdoasckjfhlnxxyz"), 1, 0);
105114
}
106115

107116
TEST_CONSTEXPR_CXX20 bool test() {

0 commit comments

Comments
 (0)