Re: [PATCH] libstdc++: testsuite: Enhance codecvt_unicode with tests for length()
On Wed, 2023-10-18 at 10:52 +0100, Jonathan Wakely wrote: > On Tue, 17 Oct 2023 at 23:51, Dimitrij Mijoski wrote: > > > > We can test codecvt::length() with the same data that we test > > codecvt::in(). For each call of in() we add another call to length(). > > Some additional small cosmentic changes are applied. > > Thanks! I'll get this applied. I think I have an improvement to this patch, see bellow. > > @@ -79,6 +78,10 @@ utf8_to_utf32_in_ok (const std::codecvt > ExternT, mbstate_t> ) > > VERIFY (char_traits::compare (out, exp, t.out_size) == 0); > > if (t.out_size < array_size (out)) > > VERIFY (out[t.out_size] == 0); > > + > > + state = {}; > > + auto len = cvt.length (state, in, in + t.in_size, t.out_size); > > + VERIFY (len == t.in_size); > > } > > > > for (auto t : offsets) Notice that codecvt::length() return type is (signed) int that should never be negative. Still because t.in_size is size_t the assertion may generate some warnings. In theory that assrtion can be done like this: VERIFY(len >= 0); VERIFY(static_cast(len) == t.in_size);
Re: [PATCH] libstdc++: testsuite: Enhance codecvt_unicode with tests for length()
On Tue, 17 Oct 2023 at 23:51, Dimitrij Mijoski wrote: > > We can test codecvt::length() with the same data that we test > codecvt::in(). For each call of in() we add another call to length(). > Some additional small cosmentic changes are applied. Thanks! I'll get this applied. > > libstdc++-v3/ChangeLog: > > * testsuite/22_locale/codecvt/codecvt_unicode.h: Test length() > --- > .../22_locale/codecvt/codecvt_unicode.h | 103 +++--- > 1 file changed, 90 insertions(+), 13 deletions(-) > > diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h > b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h > index d3ae42fac..b3c257ec2 100644 > --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h > +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h > @@ -17,7 +17,6 @@ > > #include > #include > -#include > #include > > struct test_offsets_ok > @@ -79,6 +78,10 @@ utf8_to_utf32_in_ok (const std::codecvt mbstate_t> ) >VERIFY (char_traits::compare (out, exp, t.out_size) == 0); >if (t.out_size < array_size (out)) > VERIFY (out[t.out_size] == 0); > + > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, t.out_size); > + VERIFY (len == t.in_size); > } > >for (auto t : offsets) > @@ -99,6 +102,10 @@ utf8_to_utf32_in_ok (const std::codecvt mbstate_t> ) >VERIFY (char_traits::compare (out, exp, t.out_size) == 0); >if (t.out_size < array_size (out)) > VERIFY (out[t.out_size] == 0); > + > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, array_size (out)); > + VERIFY (len == t.in_size); > } > } > > @@ -163,6 +170,10 @@ utf8_to_utf32_in_partial (const std::codecvt ExternT, mbstate_t> ) > == 0); >if (t.expected_out_next < array_size (out)) > VERIFY (out[t.expected_out_next] == 0); > + > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, t.out_size); > + VERIFY (len == t.expected_in_next); > } > } > > @@ -303,6 +314,10 @@ utf8_to_utf32_in_error (const std::codecvt ExternT, mbstate_t> ) >if (t.expected_out_next < array_size (out)) > VERIFY (out[t.expected_out_next] == 0); > > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, t.out_size); > + VERIFY (len == t.expected_in_next); > + >in[t.replace_pos] = old_char; > } > } > @@ -334,7 +349,7 @@ utf32_to_utf8_out_ok (const std::codecvt ExternT, mbstate_t> ) >VERIFY (char_traits::length (in) == 4); >VERIFY (char_traits::length (exp) == 10); > > - const test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {4, > 10}}; > + test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {4, 10}}; >for (auto t : offsets) > { >ExternT out[array_size (exp) - 1] = {}; > @@ -374,7 +389,7 @@ utf32_to_utf8_out_partial (const std::codecvt ExternT, mbstate_t> ) >VERIFY (char_traits::length (in) == 4); >VERIFY (char_traits::length (exp) == 10); > > - const test_offsets_partial offsets[] = { > + test_offsets_partial offsets[] = { > {1, 0, 0, 0}, // no space for first CP > > {2, 1, 1, 1}, // no space for second CP > @@ -528,6 +543,10 @@ utf8_to_utf16_in_ok (const std::codecvt ExternT, mbstate_t> ) >VERIFY (char_traits::compare (out, exp, t.out_size) == 0); >if (t.out_size < array_size (out)) > VERIFY (out[t.out_size] == 0); > + > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, t.out_size); > + VERIFY (len == t.in_size); > } > >for (auto t : offsets) > @@ -548,6 +567,10 @@ utf8_to_utf16_in_ok (const std::codecvt ExternT, mbstate_t> ) >VERIFY (char_traits::compare (out, exp, t.out_size) == 0); >if (t.out_size < array_size (out)) > VERIFY (out[t.out_size] == 0); > + > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, array_size (out)); > + VERIFY (len == t.in_size); > } > } > > @@ -617,6 +640,10 @@ utf8_to_utf16_in_partial (const std::codecvt ExternT, mbstate_t> ) > == 0); >if (t.expected_out_next < array_size (out)) > VERIFY (out[t.expected_out_next] == 0); > + > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, t.out_size); > + VERIFY (len == t.expected_in_next); > } > } > > @@ -757,6 +784,10 @@ utf8_to_utf16_in_error (const std::codecvt ExternT, mbstate_t> ) >if (t.expected_out_next < array_size (out)) > VERIFY (out[t.expected_out_next] == 0); > > + state = {}; > + auto len = cvt.length (state, in, in + t.in_size, t.out_size); > + VERIFY (len == t.expected_in_next); > + >in[t.replace_pos] = old_char; > } > } > @@ -788,7 +819,7 @@ utf16_to_utf8_out_ok (const std::codecvt ExternT, mbstate_t> ) >VERIFY (char_traits::length (in) == 5); >VERIFY (char_traits::length (exp)
[PATCH] libstdc++: testsuite: Enhance codecvt_unicode with tests for length()
We can test codecvt::length() with the same data that we test codecvt::in(). For each call of in() we add another call to length(). Some additional small cosmentic changes are applied. libstdc++-v3/ChangeLog: * testsuite/22_locale/codecvt/codecvt_unicode.h: Test length() --- .../22_locale/codecvt/codecvt_unicode.h | 103 +++--- 1 file changed, 90 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h index d3ae42fac..b3c257ec2 100644 --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h @@ -17,7 +17,6 @@ #include #include -#include #include struct test_offsets_ok @@ -79,6 +78,10 @@ utf8_to_utf32_in_ok (const std::codecvt ) VERIFY (char_traits::compare (out, exp, t.out_size) == 0); if (t.out_size < array_size (out)) VERIFY (out[t.out_size] == 0); + + state = {}; + auto len = cvt.length (state, in, in + t.in_size, t.out_size); + VERIFY (len == t.in_size); } for (auto t : offsets) @@ -99,6 +102,10 @@ utf8_to_utf32_in_ok (const std::codecvt ) VERIFY (char_traits::compare (out, exp, t.out_size) == 0); if (t.out_size < array_size (out)) VERIFY (out[t.out_size] == 0); + + state = {}; + auto len = cvt.length (state, in, in + t.in_size, array_size (out)); + VERIFY (len == t.in_size); } } @@ -163,6 +170,10 @@ utf8_to_utf32_in_partial (const std::codecvt ) == 0); if (t.expected_out_next < array_size (out)) VERIFY (out[t.expected_out_next] == 0); + + state = {}; + auto len = cvt.length (state, in, in + t.in_size, t.out_size); + VERIFY (len == t.expected_in_next); } } @@ -303,6 +314,10 @@ utf8_to_utf32_in_error (const std::codecvt ) if (t.expected_out_next < array_size (out)) VERIFY (out[t.expected_out_next] == 0); + state = {}; + auto len = cvt.length (state, in, in + t.in_size, t.out_size); + VERIFY (len == t.expected_in_next); + in[t.replace_pos] = old_char; } } @@ -334,7 +349,7 @@ utf32_to_utf8_out_ok (const std::codecvt ) VERIFY (char_traits::length (in) == 4); VERIFY (char_traits::length (exp) == 10); - const test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {4, 10}}; + test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {4, 10}}; for (auto t : offsets) { ExternT out[array_size (exp) - 1] = {}; @@ -374,7 +389,7 @@ utf32_to_utf8_out_partial (const std::codecvt ) VERIFY (char_traits::length (in) == 4); VERIFY (char_traits::length (exp) == 10); - const test_offsets_partial offsets[] = { + test_offsets_partial offsets[] = { {1, 0, 0, 0}, // no space for first CP {2, 1, 1, 1}, // no space for second CP @@ -528,6 +543,10 @@ utf8_to_utf16_in_ok (const std::codecvt ) VERIFY (char_traits::compare (out, exp, t.out_size) == 0); if (t.out_size < array_size (out)) VERIFY (out[t.out_size] == 0); + + state = {}; + auto len = cvt.length (state, in, in + t.in_size, t.out_size); + VERIFY (len == t.in_size); } for (auto t : offsets) @@ -548,6 +567,10 @@ utf8_to_utf16_in_ok (const std::codecvt ) VERIFY (char_traits::compare (out, exp, t.out_size) == 0); if (t.out_size < array_size (out)) VERIFY (out[t.out_size] == 0); + + state = {}; + auto len = cvt.length (state, in, in + t.in_size, array_size (out)); + VERIFY (len == t.in_size); } } @@ -617,6 +640,10 @@ utf8_to_utf16_in_partial (const std::codecvt ) == 0); if (t.expected_out_next < array_size (out)) VERIFY (out[t.expected_out_next] == 0); + + state = {}; + auto len = cvt.length (state, in, in + t.in_size, t.out_size); + VERIFY (len == t.expected_in_next); } } @@ -757,6 +784,10 @@ utf8_to_utf16_in_error (const std::codecvt ) if (t.expected_out_next < array_size (out)) VERIFY (out[t.expected_out_next] == 0); + state = {}; + auto len = cvt.length (state, in, in + t.in_size, t.out_size); + VERIFY (len == t.expected_in_next); + in[t.replace_pos] = old_char; } } @@ -788,7 +819,7 @@ utf16_to_utf8_out_ok (const std::codecvt ) VERIFY (char_traits::length (in) == 5); VERIFY (char_traits::length (exp) == 10); - const test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {5, 10}}; + test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}, {5, 10}}; for (auto t : offsets) { ExternT out[array_size (exp) - 1] = {}; @@ -828,7 +859,7 @@ utf16_to_utf8_out_partial (const std::codecvt ) VERIFY (char_traits::length (in) == 5); VERIFY (char_traits::length (exp) == 10); - const test_offsets_partial offsets[] = { + test_offsets_partial offsets[] = { {1, 0, 0, 0}, // no space for first CP