Kaydet (Commit) 81076cb3 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Get rid of the "failure #23" style messages in CppunitTest_sal_rtl_textenc

While at it, print the character values in assertion messages in hex, not
decimal.

Change-Id: I61a5efca0a800ea295afc81e2b2f234844428b1c
üst f36769fd
...@@ -80,13 +80,14 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) { ...@@ -80,13 +80,14 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
for (int i = 0; i < 256; ++i) { for (int i = 0; i < 256; ++i) {
if (rSet.m_aMap[i] != 0xFFFF && aUnicode[j] != rSet.m_aMap[i]) { if (rSet.m_aMap[i] != 0xFFFF && aUnicode[j] != rSet.m_aMap[i]) {
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " +
OUString::number(rSet.m_aMap[i])), OUString::number(rSet.m_aMap[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(), RTL_TEXTENCODING_UTF8).getStr(),
rSet.m_aMap[i] == 0xFFFF); rSet.m_aMap[i] == 0xFFFF);
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(j) + "] == " + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(j) + "] == " +
OUString::number(aUnicode[j]) + OUString::number(aUnicode[j], 16) +
", rSet.m_aMap[" + OUString::number(i) + "] == " + ", " +
OUString::number(rSet.m_aMap[i])), "rSet.m_aMap[" + OUString::number(i) + "] == " +
OUString::number(rSet.m_aMap[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(), RTL_TEXTENCODING_UTF8).getStr(),
aUnicode[j] == rSet.m_aMap[i]); aUnicode[j] == rSet.m_aMap[i]);
} }
...@@ -127,11 +128,11 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) { ...@@ -127,11 +128,11 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
&& aText[j] != static_cast< sal_Char >(i)) && aText[j] != static_cast< sal_Char >(i))
{ {
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " +
OUString::number(rSet.m_aMap[i])), OUString::number(rSet.m_aMap[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(), RTL_TEXTENCODING_UTF8).getStr(),
rSet.m_aMap[i] == 0xFFFF); rSet.m_aMap[i] == 0xFFFF);
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aText[" + OUString::number(j) + "] == " + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aText[" + OUString::number(j) + "] == " +
OUString::number(i)), OUString::number(i, 16)),
RTL_TEXTENCODING_UTF8).getStr(), RTL_TEXTENCODING_UTF8).getStr(),
aText[j] == static_cast< sal_Char >(i)); aText[j] == static_cast< sal_Char >(i));
} }
...@@ -149,7 +150,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) { ...@@ -149,7 +150,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
aConverter != NULL); aConverter != NULL);
rtl_TextToUnicodeContext aContext rtl_TextToUnicodeContext aContext
= rtl_createTextToUnicodeContext(aConverter); = rtl_createTextToUnicodeContext(aConverter);
CPPUNIT_ASSERT_MESSAGE("failure #7", aConverter && aContext); CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != NULL);
sal_Size nSize; sal_Size nSize;
sal_uInt32 nInfo; sal_uInt32 nInfo;
sal_Size nConverted; sal_Size nConverted;
...@@ -221,9 +222,10 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) { ...@@ -221,9 +222,10 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) {
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
OUString::number(aUnicode[i]) + OUString::number(aUnicode[i], 16) +
", rTest.m_aUnicode[" + OUString::number(i) + "] == " + ", " +
OUString::number(rTest.m_aUnicode[i])), "rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(), RTL_TEXTENCODING_UTF8).getStr(),
aUnicode[i] == rTest.m_aUnicode[i]); aUnicode[i] == rTest.m_aUnicode[i]);
} }
...@@ -263,19 +265,17 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) { ...@@ -263,19 +265,17 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
nFlags, &nInfo, &nConverted); nFlags, &nInfo, &nConverted);
nOutput += nSize; nOutput += nSize;
nInput += nConverted; nInput += nConverted;
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_EQUAL((sal_uInt32) 0,
"failure #14", (nInfo & ~RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL));
(nInfo & ~RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL) == 0);
} }
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_EQUAL(rTest.m_nUnicodeSize, nOutput);
"failure #15", CPPUNIT_ASSERT_EQUAL(rTest.m_nTextSize, nInput);
nOutput == rTest.m_nUnicodeSize && nInput == rTest.m_nTextSize);
for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) {
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " + CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
OUString::number(aUnicode[i]) + OUString::number(aUnicode[i], 16) +
", rTest.m_aUnicode[" + OUString::number(i) + "] == " + ", rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i])), OUString::number(rTest.m_aUnicode[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(), RTL_TEXTENCODING_UTF8).getStr(),
aUnicode[i] == rTest.m_aUnicode[i]); aUnicode[i] == rTest.m_aUnicode[i]);
} }
...@@ -356,22 +356,26 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) { ...@@ -356,22 +356,26 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
} }
done: done:
rtl_destroyTextToUnicodeConverter(aConverter); rtl_destroyTextToUnicodeConverter(aConverter);
bool bSuccess = true;
for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) { for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) {
if (aUnicode[i] != rTest.m_aUnicode[i]) { CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
bSuccess = false; OUString::number(aUnicode[i], 16) +
break; ", " +
} "rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(),
aUnicode[i] == rTest.m_aUnicode[i]);
} }
CPPUNIT_ASSERT_MESSAGE("failure #18", bSuccess);
} }
if (rTest.m_bReverse) { if (rTest.m_bReverse) {
sal_Char aText[TEST_STRING_SIZE]; sal_Char aText[TEST_STRING_SIZE];
rtl_UnicodeToTextConverter aConverter rtl_UnicodeToTextConverter aConverter
= rtl_createUnicodeToTextConverter(rTest.m_nEncoding); = rtl_createUnicodeToTextConverter(rTest.m_nEncoding);
CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != NULL);
rtl_UnicodeToTextContext aContext rtl_UnicodeToTextContext aContext
= rtl_createUnicodeToTextContext(aConverter); = rtl_createUnicodeToTextContext(aConverter);
CPPUNIT_ASSERT_MESSAGE("failure #19", aConverter && aContext); CPPUNIT_ASSERT_MESSAGE("rtl_createTextToUnicodeContext failed", aContext != NULL);
sal_Size nSize; sal_Size nSize;
sal_uInt32 nInfo; sal_uInt32 nInfo;
sal_Size nConverted; sal_Size nConverted;
...@@ -383,24 +387,25 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) { ...@@ -383,24 +387,25 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
| (rTest.m_bGlobalSignature ? | (rTest.m_bGlobalSignature ?
RTL_UNICODETOTEXT_FLAGS_GLOBAL_SIGNATURE : 0)), RTL_UNICODETOTEXT_FLAGS_GLOBAL_SIGNATURE : 0)),
&nInfo, &nConverted); &nInfo, &nConverted);
CPPUNIT_ASSERT_MESSAGE( CPPUNIT_ASSERT_EQUAL(rTest.m_nTextSize, nSize);
"failure #20", if (nInfo != 0)
(nSize == rTest.m_nTextSize {
&& (nInfo == 0 CPPUNIT_ASSERT_EQUAL(RTL_UNICODETOTEXT_INFO_UNDEFINED, nInfo);
|| (nInfo == RTL_UNICODETOTEXT_INFO_UNDEFINED CPPUNIT_ASSERT_MESSAGE("rTest.m_nReverseUndefined should not be RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR",
&& (rTest.m_nReverseUndefined rTest.m_nReverseUndefined != RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR);
!= RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR))) }
&& nConverted == rTest.m_nUnicodeSize)); CPPUNIT_ASSERT_EQUAL(rTest.m_nUnicodeSize, nConverted);
rtl_destroyUnicodeToTextContext(aConverter, aContext); rtl_destroyUnicodeToTextContext(aConverter, aContext);
rtl_destroyUnicodeToTextConverter(aConverter); rtl_destroyUnicodeToTextConverter(aConverter);
bool bSuccess = true;
for (sal_Size i = 0; i < rTest.m_nTextSize; ++i) { for (sal_Size i = 0; i < rTest.m_nTextSize; ++i) {
if (aText[i] != rTest.m_pText[i]) { CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aText[" + OUString::number(i) + "] == " +
bSuccess = false; OUString::number(aText[i], 16) +
break; ", " +
} "rTest.m_pText[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_pText[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(),
aText[i] == rTest.m_pText[i]);
} }
CPPUNIT_ASSERT_MESSAGE("failure #21", bSuccess);
} }
} }
...@@ -422,23 +427,25 @@ void doComplexCharSetCutTest(ComplexCharSetTest const & rTest) { ...@@ -422,23 +427,25 @@ void doComplexCharSetCutTest(ComplexCharSetTest const & rTest) {
| RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
| RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR), | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR),
&nInfo, &nConverted); &nInfo, &nConverted);
CPPUNIT_ASSERT_MESSAGE(
"failure #23", CPPUNIT_ASSERT_EQUAL(rTest.m_nUnicodeSize, nSize);
(nSize <= rTest.m_nUnicodeSize if (nInfo != RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL)
&& (nInfo == RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL {
|| (nInfo CPPUNIT_ASSERT_EQUAL(RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL,
== (RTL_TEXTTOUNICODE_INFO_ERROR nInfo);
| RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL))) }
&& nConverted < rTest.m_nTextSize)); CPPUNIT_ASSERT_MESSAGE("nConverted should be less than rTest.m_nTextSize", nConverted < rTest.m_nTextSize);
rtl_destroyTextToUnicodeConverter(aConverter); rtl_destroyTextToUnicodeConverter(aConverter);
bool bSuccess = true;
for (sal_Size i = 0; i < nSize; ++i) { for (sal_Size i = 0; i < nSize; ++i) {
if (aUnicode[i] != rTest.m_aUnicode[i]) { CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
bSuccess = false; OUString::number(aUnicode[i], 16) +
break; ", " +
} "rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(),
aUnicode[i] == rTest.m_aUnicode[i]);
} }
CPPUNIT_ASSERT_MESSAGE("failure #24", bSuccess);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment