diff options
author | Dr. David Alan Gilbert <dave@treblig.org> | 2023-05-31 01:58:18 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-06-02 16:58:57 +0200 |
commit | 7bec1689fcbe9102aa220739b6113118d9a8dd1f (patch) | |
tree | ad0146c3bf6f14530e36b79a0c620cfd1dad4084 /sal | |
parent | f8036f2f5238adf227d0ffa646e503f0446bb37b (diff) |
tdf#145538,tdf#147021: qa: range based loops
A bunch of range based loop changes in various qa
sections that also take out about 1% of SAL_N_ELEMENTS
Change-Id: I8ef000e9aa400cd8363b48f6175f6ab258cefbd9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152422
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_convert.cxx | 4 | ||||
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_endswith.cxx | 19 | ||||
-rw-r--r-- | sal/qa/rtl/textenc/rtl_textcvt.cxx | 71 | ||||
-rw-r--r-- | sal/qa/rtl/uri/rtl_testuri.cxx | 34 |
4 files changed, 61 insertions, 67 deletions
diff --git a/sal/qa/rtl/strings/test_oustring_convert.cxx b/sal/qa/rtl/strings/test_oustring_convert.cxx index da930a03f244..e74276a11b0f 100644 --- a/sal/qa/rtl/strings/test_oustring_convert.cxx +++ b/sal/qa/rtl/strings/test_oustring_convert.cxx @@ -170,8 +170,8 @@ void test::oustring::Convert::convertToString() OUSTRING_TO_OSTRING_CVTFLAGS, "A?B", "A?B" } }; - for (size_t i = 0; i < SAL_N_ELEMENTS(aTests); ++i) - testConvertToString(aTests[i]); + for (auto const& aTest : aTests) + testConvertToString(aTest); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/qa/rtl/strings/test_oustring_endswith.cxx b/sal/qa/rtl/strings/test_oustring_endswith.cxx index bf01577e28be..9ec08fa55045 100644 --- a/sal/qa/rtl/strings/test_oustring_endswith.cxx +++ b/sal/qa/rtl/strings/test_oustring_endswith.cxx @@ -93,20 +93,17 @@ void test::oustring::EndsWith::endsWith() RTL_CONSTASCII_STRINGPARAM("b\0c"), true }, { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"), RTL_CONSTASCII_STRINGPARAM("b"), false } }; - for (size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + for (auto const[pStr1, nStr1Len, pStr2, nStr2Len, bEndsWith] : data) + { OStringBuffer msg; - appendString(msg, OString(data[i].str1, data[i].str1Len)); + appendString(msg, OString(pStr1, nStr1Len)); msg.append(".endsWithIgnoreAsciiCaseAsciiL("); - appendString(msg, OString(data[i].str2, data[i].str2Len)); + appendString(msg, OString(pStr2, nStr2Len)); msg.append(") == "); - msg.append(data[i].endsWith); - CPPUNIT_ASSERT_EQUAL_MESSAGE( - msg.getStr(), - data[i].endsWith, - OUString( - data[i].str1, data[i].str1Len, - RTL_TEXTENCODING_ASCII_US).endsWithIgnoreAsciiCaseAsciiL( - data[i].str2, data[i].str2Len)); + msg.append(bEndsWith); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), bEndsWith, + OUString(pStr1, nStr1Len, RTL_TEXTENCODING_ASCII_US) + .endsWithIgnoreAsciiCaseAsciiL(pStr2, nStr2Len)); } } diff --git a/sal/qa/rtl/textenc/rtl_textcvt.cxx b/sal/qa/rtl/textenc/rtl_textcvt.cxx index 05aab30a063a..e64dbd4c5e03 100644 --- a/sal/qa/rtl/textenc/rtl_textcvt.cxx +++ b/sal/qa/rtl/textenc/rtl_textcvt.cxx @@ -1353,8 +1353,9 @@ void Test::testSingleByte() { 0x03A6,0x0398,0x03A9,0x03B4,0x221E,0x03C6,0x03B5,0x2229, 0x2261,0x00B1,0x2265,0x2264,0x2320,0x2321,0x00F7,0x2248, 0x00B0,0x2219,0x00B7,0x221A,0x207F,0x00B2,0x25A0,0x00A0 } } }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { - testSingleByteCharSet(data[i]); + for (auto const& aDatum : data) + { + testSingleByteCharSet(aDatum); } } @@ -2628,8 +2629,9 @@ void Test::testComplex() { RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR } #endif }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { - doComplexCharSetTest(data[i]); + for (auto const& aDatum : data) + { + doComplexCharSetTest(aDatum); } } @@ -2723,8 +2725,9 @@ void Test::testComplexCut() { false, false, RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR } */ }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { - doComplexCharSetCutTest(data[i]); + for (auto const& aDatum : data) + { + doComplexCharSetCutTest(aDatum); } #endif } @@ -3189,21 +3192,21 @@ void Test::testMime() { { "CP154", RTL_TEXTENCODING_PT154, false }, { "Cyrillic-Asian", RTL_TEXTENCODING_PT154, false } }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { - if (data[i].mime == nullptr) { - OSL_ASSERT(data[i].reverse); - CPPUNIT_ASSERT_EQUAL( - static_cast< char const * >(nullptr), - rtl_getMimeCharsetFromTextEncoding(data[i].encoding)); - } else { - CPPUNIT_ASSERT_EQUAL( - data[i].encoding, - rtl_getTextEncodingFromMimeCharset(data[i].mime)); - if (data[i].reverse) { - CPPUNIT_ASSERT_EQUAL( - OString(data[i].mime), - OString( - rtl_getMimeCharsetFromTextEncoding(data[i].encoding))); + for (auto const[pMime,nEncoding,bReverse] : data) + { + if (pMime == nullptr) + { + OSL_ASSERT(bReverse); + CPPUNIT_ASSERT_EQUAL(static_cast< char const * >(nullptr), + rtl_getMimeCharsetFromTextEncoding(nEncoding)); + } + else + { + CPPUNIT_ASSERT_EQUAL(nEncoding, rtl_getTextEncodingFromMimeCharset(pMime)); + if (bReverse) + { + CPPUNIT_ASSERT_EQUAL(OString(pMime), + OString( rtl_getMimeCharsetFromTextEncoding(nEncoding))); } } } @@ -3290,17 +3293,16 @@ void Test::testWindows() { { 0, RTL_TEXTENCODING_UCS2, true }, { 57002, RTL_TEXTENCODING_ISCII_DEVANAGARI, true } }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { - OSL_ASSERT(data[i].codePage != 0 || data[i].reverse); - if (data[i].codePage != 0) { - CPPUNIT_ASSERT_EQUAL( - data[i].encoding, - rtl_getTextEncodingFromWindowsCodePage(data[i].codePage)); + for (auto const[nCodePage,nEncoding,bReverse] : data) + { + OSL_ASSERT(nCodePage != 0 || bReverse); + if (nCodePage != 0) + { + CPPUNIT_ASSERT_EQUAL( nEncoding, rtl_getTextEncodingFromWindowsCodePage(nCodePage)); } - if (data[i].reverse) { - CPPUNIT_ASSERT_EQUAL( - data[i].codePage, - rtl_getWindowsCodePageFromTextEncoding(data[i].encoding)); + if (bReverse) + { + CPPUNIT_ASSERT_EQUAL( nCodePage, rtl_getWindowsCodePageFromTextEncoding(nEncoding)); } } } @@ -3364,11 +3366,12 @@ void Test::testInfo() { { RTL_TEXTENCODING_PT154, RTL_TEXTENCODING_INFO_ASCII, true }, { RTL_TEXTENCODING_PT154, RTL_TEXTENCODING_INFO_MIME, true } }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) { + for (auto const[nEncoding, nFlag, bValue] : data) + { rtl_TextEncodingInfo info; info.StructSize = sizeof info; - CPPUNIT_ASSERT(rtl_getTextEncodingInfo(data[i].encoding, &info)); - CPPUNIT_ASSERT_EQUAL(data[i].value, ((info.Flags & data[i].flag) != 0)); + CPPUNIT_ASSERT(rtl_getTextEncodingInfo(nEncoding, &info)); + CPPUNIT_ASSERT_EQUAL(bValue, ((info.Flags & nFlag) != 0)); } } diff --git a/sal/qa/rtl/uri/rtl_testuri.cxx b/sal/qa/rtl/uri/rtl_testuri.cxx index fc45ba238f2c..3b119820aea9 100644 --- a/sal/qa/rtl/uri/rtl_testuri.cxx +++ b/sal/qa/rtl/uri/rtl_testuri.cxx @@ -326,31 +326,25 @@ void Test::test_Uri() { { "http://a/b/c/", "d", "http://a/b/c/d" }, { "http://a/b/c//", "d", "http://a/b/c//d" } }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(aRelToAbsTest); ++i) + for (auto const[pBase, pRel, pAbs] : aRelToAbsTest) { - OUString aAbs; + OUString aAbsResult; bool bMalformed = false; - try { - aAbs = rtl::Uri::convertRelToAbs( - OUString::createFromAscii(aRelToAbsTest[i].pBase), - OUString::createFromAscii(aRelToAbsTest[i].pRel)); - } catch (const rtl::MalformedUriException &) { + try + { + aAbsResult = rtl::Uri::convertRelToAbs(OUString::createFromAscii(pBase), + OUString::createFromAscii(pRel)); + } + catch (const rtl::MalformedUriException &) + { bMalformed = true; } - if (bMalformed - ? aRelToAbsTest[i].pAbs != nullptr - : (aRelToAbsTest[i].pAbs == nullptr - || !aAbs.equalsAscii(aRelToAbsTest[i].pAbs))) + if (bMalformed ? pAbs != nullptr : (pAbs == nullptr || !aAbsResult.equalsAscii(pAbs))) { - printf( - "FAILED convertRelToAbs(%s, %s) -> %s != %s\n", - aRelToAbsTest[i].pBase, aRelToAbsTest[i].pRel, - (bMalformed - ? "<MALFORMED>" - : OUStringToOString( - aAbs, RTL_TEXTENCODING_UTF8).getStr()), - (aRelToAbsTest[i].pAbs == nullptr - ? "<MALFORMED>" : aRelToAbsTest[i].pAbs)); + printf("FAILED convertRelToAbs(%s, %s) -> %s != %s\n", pBase, pRel, + (bMalformed ? "<MALFORMED>" + : OUStringToOString(aAbsResult, RTL_TEXTENCODING_UTF8).getStr()), + (pAbs == nullptr ? "<MALFORMED>" : pAbs)); CPPUNIT_ASSERT(false); } } |