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 1E5883857B9B for ; Wed, 18 Oct 2023 09:52:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E5883857B9B 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 1E5883857B9B 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=1697622755; cv=none; b=FAfklFprRo3vaXxJB58ys3mbyo0Jb0/TPZzC7aDE9cxtQSR/7qy0HsvQhfh4zLN00xqKISS7IfECIUAWwFEozz0ZOD2RP2KO0nZnYN38zmK5J3cjFsIIgcSKDyAKoRXCtXC2nqrWflpHngvN/UNFLkq6qJFL2Hfx0lk9MncYRXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697622755; c=relaxed/simple; bh=Ci04Vp1r9GASFIdfewYnmO9GMN5E11jy3aK+6W0KFuQ=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=R9viZMsrNofm8DTWzc9QsgJgyW1qNTZ8HZ8nwOgFMx4NXKQky6GvIqy4bul6I6SebZ1i4FcJQxsSl1F0dDO/A4yHiG8uFN3LqlqgpMssp6O5+1ayybebRl5/6Ve+Lmg34XJGr8UBrCUJDKNPYuvjskJd7ADFp3cz8rOOK0z8ATk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697622751; 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=+s7qmiTScl9ypbP7pHwHR5k3LKuup1mURotUZaTEXdw=; b=TLYadcEukhsmi8H3C8AYUtgOc1cArhvrMVx2NJfKTQg4pGJvTZ1lWemZ/qgEraFUCd9R+J Ipod7mf3q+d1MFn+GTRjciNj0V0TRXHyqlZY4mZZ+L7upUKWZenjcuclasirGS5pFl+zyY TlGxrHk19adImfhozeLliBE8ofF2/Jc= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-jvRTMlUJNXSyAa4XwLhQPA-1; Wed, 18 Oct 2023 05:52:15 -0400 X-MC-Unique: jvRTMlUJNXSyAa4XwLhQPA-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2c51a7df557so35813491fa.0 for ; Wed, 18 Oct 2023 02:52:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697622734; x=1698227534; 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=+s7qmiTScl9ypbP7pHwHR5k3LKuup1mURotUZaTEXdw=; b=l4CLkhZ3MlSkLNSpaSOn7Zy5oqMwBh9mE7wbP9EEwO9eZizO1vkKzT27qKLENviXP1 wvTT1tYf8sbM9I7MTsEw91kG4LChJXATGRAo4kIqdAjpY3zmjd8VhZifqUP/4ML+7Y36 +c1BlOk11i7OZwwHwZ1vQSuP+xBJ/u3PrpdiOEprItT07EP29J/vacJ0U6ZgRtH0QsYM POvC0WL7tjc+uwbqHGvnckD/3XnsrDQK5sQEpmXcjhY8H31WNqHfcU3Ym9BNZyDXvae7 ixTdx5VYvt/nY27RSVBbDM9lCXB5wm389Ic7P8GAYebKhYTJI0yTYvBz70iWGMR3bqXU 4psw== X-Gm-Message-State: AOJu0YwWJwVF3E7UYPyXc62b6DeY8GslhJn64wmO7otIdCTTE6aEp4Hh 2+N1mOAzNyZ2UvsH5xGO1t8HO3lvybFG5//tBPlWMUJzt3Xk2S7HjmNK+90yWnx0FdJsecLRmtn L6OlA1xPqsklahkUZz86nYc5mdRsYZIs= X-Received: by 2002:a2e:874b:0:b0:2bb:78ad:56cb with SMTP id q11-20020a2e874b000000b002bb78ad56cbmr3218085ljj.37.1697622733996; Wed, 18 Oct 2023 02:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEim7QZ0AN8RE+aKLyenHvL49wWMOPh1KMofybdQvAQlKvPOb7OPOCWpmYOusV7v9zalE9JOFKnESEkm83f4Qg= X-Received: by 2002:a2e:874b:0:b0:2bb:78ad:56cb with SMTP id q11-20020a2e874b000000b002bb78ad56cbmr3218070ljj.37.1697622733556; Wed, 18 Oct 2023 02:52:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Wed, 18 Oct 2023 10:52:00 +0100 Message-ID: Subject: Re: [PATCH] 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 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 &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 == t.in_size); > } > > for (auto t : offsets) > @@ -99,6 +102,10 @@ 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 == t.in_size); > } > } > > @@ -163,6 +170,10 @@ 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 == t.expected_in_next); > } > } > > @@ -303,6 +314,10 @@ 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 == t.expected_in_next); > + > in[t.replace_pos] = old_char; > } > } > @@ -334,7 +349,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 +389,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 +543,10 @@ 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 == t.in_size); > } > > for (auto t : offsets) > @@ -548,6 +567,10 @@ 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 == t.in_size); > } > } > > @@ -617,6 +640,10 @@ 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 == t.expected_in_next); > } > } > > @@ -757,6 +784,10 @@ 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 == t.expected_in_next); > + > in[t.replace_pos] = old_char; > } > } > @@ -788,7 +819,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 +859,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 +1036,10 @@ 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 == t.in_size); > } > > for (auto t : offsets) > @@ -1025,6 +1060,10 @@ 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 == t.in_size); > } > } > > @@ -1081,6 +1120,10 @@ 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 == t.expected_in_next); > } > } > > @@ -1231,6 +1274,10 @@ 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 == t.expected_in_next); > + > in[t.replace_pos] = old_char; > } > } > @@ -1262,7 +1309,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 +1349,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 +1546,10 @@ 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 == t.in_size); > } > > for (auto t : offsets) > @@ -1519,6 +1570,10 @@ 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 == t.in_size); > } > } > > @@ -1535,7 +1590,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 +1636,10 @@ 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 == t.expected_in_next); > } > } > > @@ -1656,6 +1714,10 @@ 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 == t.expected_in_next); > + > input[t.replace_pos] = old_char; > } > } > @@ -1676,7 +1738,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 +1776,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 +1920,10 @@ 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 == t.in_size); > } > > for (auto t : offsets) > @@ -1878,6 +1944,10 @@ 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 == t.in_size); > } > } > > @@ -1894,7 +1964,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 +2002,10 @@ 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 == t.expected_in_next); > } > } > > @@ -2018,6 +2091,10 @@ 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 == t.expected_in_next); > + > input[t.replace_pos] = old_char; > } > } > @@ -2038,7 +2115,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 +2153,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 > >