From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E8DC5385696A for ; Sat, 21 Oct 2023 11:15:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8DC5385696A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E8DC5385696A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697886910; cv=none; b=j2PKJx7aoJbAzNHi2lT82oknNo2WNKAhPUpBC5XSlaU7R+PkoDOLHcS5+yXzY3d7ePHuk6Um2hQ1jm2k0MfY26/X6S1Y6SdO6b/m/9H0g3LzQ9DB/s2EhEZIUk/sx/nOc1M3PgD4i1oTZVkLHkRzlRFWOfffQbAwGtAzCEZGBKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697886910; c=relaxed/simple; bh=V67Our4q3tfhKEWfe2dn33XCWCpVLnljD88S//5eRFA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=NGYywTl361vZRoJMitYzrrwzrvbs3t0pDxi72Q40cAuOwBk/Cka5Twv4ENRu6e0Z/Mmshu0IIagU/KaQbbW3lcsA+pgLm5MoFSGASaPvWJAh4imljSZOKSHx+mziCKiLkbjhUvDmgFb3cp8XoxU8ngWMXPtPCvfQIJMQEtGLEFY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697886907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VIM71ZI5nkQSttxCdbMfPrfz/uRvrgpiQb88Aen8bMY=; b=i5hylygaZLnsd2PVFY427AtcAsbkklCfJ0xeeu6NLLkrTXuh8t+yqX/hlVHBRqeUaixp18 cQUC5vgxDGwyPMfJam6b5/aBVzS8f6Eg7D85GYR6SfShnwOHXUZQpQc9fq0k+nazfclxI5 uHSOgdLBAkXADBTQF7Q3R4frEyEGIfU= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-s5d5RBnNPqmm2JcP5q6kYg-1; Sat, 21 Oct 2023 07:15:00 -0400 X-MC-Unique: s5d5RBnNPqmm2JcP5q6kYg-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2c503af866dso16443861fa.2 for ; Sat, 21 Oct 2023 04:15:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697886899; x=1698491699; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VIM71ZI5nkQSttxCdbMfPrfz/uRvrgpiQb88Aen8bMY=; b=tL/cvi3xZBQqy1a0pSDE3W74FOvavu6jroemvB3lBxhs87o6bbC3bv5DyQoPVo0E57 WdF2eC7uc7cTPmxS+qGEaKPBx+h41ueHM1/LM2nSkjBwbeCWP0fWQZCvoufBK9XM6UPU DTgClvKuSVeAlF4e2UcspyIUWS6i7OVCERPwMdGBLmhF+urgzqghqTxQRJSKq3FyW6lQ knGXREezlQnSbhaurMk0L4RFQg4P1zuwMyJAHeTo4cuQZ5J1SFfwpfcQXxZ5RA94QlM4 iKiiIlTCCfKqRZUsIwKeVSXJTtAdjvC/RWWKOzWyDubiUivY4Q9A/oRfe4uTiYHRktsb TY3g== X-Gm-Message-State: AOJu0YwrqnUurCzBPIkVzdmc37y+j5+6b+jXexKrF8/Q2TQhpo2hnsVJ BBxDN8ywGMwv6jS0Z95AqbXfawbrN7dS+h1VbmVKBg0XmT3/gnVKgsZLpOQJuNYiBRjHmVD3z7i Xr39JICixIKmNqu1+y/k2xearKstq1SM= X-Received: by 2002:a2e:a9a7:0:b0:2c0:34ed:b5ea with SMTP id x39-20020a2ea9a7000000b002c034edb5eamr3114158ljq.45.1697886898752; Sat, 21 Oct 2023 04:14:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgHCZfB4HH6kltvVHI8cl1Z3vA+XCvGIkZZarurmHoO3hsWxxy9eXGfJmPVcrI4Yt+8qwtSsCj/kTMaTjq1qc= X-Received: by 2002:a2e:a9a7:0:b0:2c0:34ed:b5ea with SMTP id x39-20020a2ea9a7000000b002c034edb5eamr3114130ljq.45.1697886897324; Sat, 21 Oct 2023 04:14:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Sat, 21 Oct 2023 12:14:46 +0100 Message-ID: Subject: Re: [PATCH v2] libstdc++: testsuite: Enhance codecvt_unicode with tests for length() To: Dimitrij Mijoski Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 18 Oct 2023 at 11:52, 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. Pushed to master, thanks! > > libstdc++-v3/ChangeLog: > > * testsuite/22_locale/codecvt/codecvt_unicode.h: Test length() > --- > .../22_locale/codecvt/codecvt_unicode.h | 123 ++++++++++++++++-- > 1 file changed, 110 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..42270c50f 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,11 @@ utf8_to_utf32_in_ok (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > > for (auto t : offsets) > @@ -99,6 +103,11 @@ utf8_to_utf32_in_ok (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > } > > @@ -163,6 +172,11 @@ utf8_to_utf32_in_partial (const std::codecvt &cvt) > == 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > } > } > > @@ -303,6 +317,11 @@ utf8_to_utf32_in_error (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > + > in[t.replace_pos] = old_char; > } > } > @@ -334,7 +353,7 @@ utf32_to_utf8_out_ok (const std::codecvt &cvt) > 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 +393,7 @@ utf32_to_utf8_out_partial (const std::codecvt &cvt) > 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 +547,11 @@ utf8_to_utf16_in_ok (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > > for (auto t : offsets) > @@ -548,6 +572,11 @@ utf8_to_utf16_in_ok (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > } > > @@ -617,6 +646,11 @@ utf8_to_utf16_in_partial (const std::codecvt &cvt) > == 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > } > } > > @@ -757,6 +791,11 @@ utf8_to_utf16_in_error (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > + > in[t.replace_pos] = old_char; > } > } > @@ -788,7 +827,7 @@ utf16_to_utf8_out_ok (const std::codecvt &cvt) > 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 +867,7 @@ utf16_to_utf8_out_partial (const std::codecvt &cvt) > 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 > > {2, 1, 1, 1}, // no space for second CP > @@ -1005,6 +1044,11 @@ utf8_to_ucs2_in_ok (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > > for (auto t : offsets) > @@ -1025,6 +1069,11 @@ utf8_to_ucs2_in_ok (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > } > > @@ -1081,6 +1130,11 @@ utf8_to_ucs2_in_partial (const std::codecvt &cvt) > == 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > } > } > > @@ -1231,6 +1285,11 @@ utf8_to_ucs2_in_error (const std::codecvt &cvt) > 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > + > in[t.replace_pos] = old_char; > } > } > @@ -1262,7 +1321,7 @@ ucs2_to_utf8_out_ok (const std::codecvt &cvt) > VERIFY (char_traits::length (in) == 3); > VERIFY (char_traits::length (exp) == 6); > > - const test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}}; > + test_offsets_ok offsets[] = {{0, 0}, {1, 1}, {2, 3}, {3, 6}}; > for (auto t : offsets) > { > ExternT out[array_size (exp) - 1] = {}; > @@ -1302,7 +1361,7 @@ ucs2_to_utf8_out_partial (const std::codecvt &cvt) > VERIFY (char_traits::length (in) == 3); > VERIFY (char_traits::length (exp) == 6); > > - 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 > @@ -1499,6 +1558,11 @@ utf16_to_utf32_in_ok (const std::codecvt &cvt, > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > > for (auto t : offsets) > @@ -1519,6 +1583,11 @@ utf16_to_utf32_in_ok (const std::codecvt &cvt, > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > } > > @@ -1535,7 +1604,6 @@ utf16_to_utf32_in_partial (const std::codecvt &cvt, > > char in[array_size (input) * 2]; > InternT exp[array_size (expected)]; > - auto in_iter = begin (in); > utf16_to_bytes (begin (input), end (input), begin (in), endianess); > copy (begin (expected), end (expected), begin (exp)); > > @@ -1582,6 +1650,11 @@ utf16_to_utf32_in_partial (const std::codecvt &cvt, > == 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > } > } > > @@ -1656,6 +1729,11 @@ utf16_to_utf32_in_error (const std::codecvt &cvt, > 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > + > input[t.replace_pos] = old_char; > } > } > @@ -1676,7 +1754,7 @@ utf32_to_utf16_out_ok (const std::codecvt &cvt, > copy (begin (input), end (input), begin (in)); > utf16_to_bytes (begin (expected), end (expected), begin (exp), endianess); > > - const test_offsets_ok offsets[] = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 10}}; > + test_offsets_ok offsets[] = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 10}}; > for (auto t : offsets) > { > char out[array_size (exp) - 2] = {}; > @@ -1714,7 +1792,7 @@ utf32_to_utf16_out_partial (const std::codecvt &cvt, > copy (begin (input), end (input), begin (in)); > utf16_to_bytes (begin (expected), end (expected), begin (exp), endianess); > > - const test_offsets_partial offsets[] = { > + test_offsets_partial offsets[] = { > {1, 0, 0, 0}, // no space for first CP > {1, 1, 0, 0}, // no space for first CP > > @@ -1858,6 +1936,11 @@ utf16_to_ucs2_in_ok (const std::codecvt &cvt, > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > > for (auto t : offsets) > @@ -1878,6 +1961,11 @@ utf16_to_ucs2_in_ok (const std::codecvt &cvt, > 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 >= 0); > + VERIFY (static_cast (len) == t.in_size); > } > } > > @@ -1894,7 +1982,6 @@ utf16_to_ucs2_in_partial (const std::codecvt &cvt, > > char in[array_size (input) * 2]; > InternT exp[array_size (expected)]; > - auto in_iter = begin (in); > utf16_to_bytes (begin (input), end (input), begin (in), endianess); > copy (begin (expected), end (expected), begin (exp)); > > @@ -1933,6 +2020,11 @@ utf16_to_ucs2_in_partial (const std::codecvt &cvt, > == 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > } > } > > @@ -2018,6 +2110,11 @@ utf16_to_ucs2_in_error (const std::codecvt &cvt, > 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 >= 0); > + VERIFY (static_cast (len) == t.expected_in_next); > + > input[t.replace_pos] = old_char; > } > } > @@ -2038,7 +2135,7 @@ ucs2_to_utf16_out_ok (const std::codecvt &cvt, > copy (begin (input), end (input), begin (in)); > utf16_to_bytes (begin (expected), end (expected), begin (exp), endianess); > > - const test_offsets_ok offsets[] = {{0, 0}, {1, 2}, {2, 4}, {3, 6}}; > + test_offsets_ok offsets[] = {{0, 0}, {1, 2}, {2, 4}, {3, 6}}; > for (auto t : offsets) > { > char out[array_size (exp) - 2] = {}; > @@ -2076,7 +2173,7 @@ ucs2_to_utf16_out_partial (const std::codecvt &cvt, > copy (begin (input), end (input), begin (in)); > utf16_to_bytes (begin (expected), end (expected), begin (exp), endianess); > > - const test_offsets_partial offsets[] = { > + test_offsets_partial offsets[] = { > {1, 0, 0, 0}, // no space for first CP > {1, 1, 0, 0}, // no space for first CP > > -- > 2.34.1 > >