Check the returned length too in the utf-8 tests
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33311 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -167,7 +167,7 @@ void MBConvTestCase::WC2CP1250()
|
|||||||
#ifdef HAVE_WCHAR_H
|
#ifdef HAVE_WCHAR_H
|
||||||
|
|
||||||
// Check that 'charSequence' translates to 'wideSequence' and back.
|
// Check that 'charSequence' translates to 'wideSequence' and back.
|
||||||
// Invalid sequences can be tested by giving NULL or 'wideSequence'. Even
|
// Invalid sequences can be tested by giving NULL for 'wideSequence'. Even
|
||||||
// invalid sequences should roundtrip when an option is given and this is
|
// invalid sequences should roundtrip when an option is given and this is
|
||||||
// checked.
|
// checked.
|
||||||
//
|
//
|
||||||
@@ -230,7 +230,9 @@ void MBConvTestCase::UTF8(const char *charSequence,
|
|||||||
// translate it into wide characters
|
// translate it into wide characters
|
||||||
wxMBConvUTF8 utf8(option);
|
wxMBConvUTF8 utf8(option);
|
||||||
wchar_t widechars[BUFSIZE];
|
wchar_t widechars[BUFSIZE];
|
||||||
|
size_t lenResult = utf8.MB2WC(NULL, bytes, 0);
|
||||||
size_t result = utf8.MB2WC(widechars, bytes, BUFSIZE);
|
size_t result = utf8.MB2WC(widechars, bytes, BUFSIZE);
|
||||||
|
UTF8ASSERT(result == lenResult);
|
||||||
|
|
||||||
// check we got the expected result
|
// check we got the expected result
|
||||||
if (wideSequence) {
|
if (wideSequence) {
|
||||||
@@ -245,6 +247,7 @@ void MBConvTestCase::UTF8(const char *charSequence,
|
|||||||
wcscat(expected, wideSequence);
|
wcscat(expected, wideSequence);
|
||||||
|
|
||||||
UTF8ASSERT(wcscmp(widechars, expected) == 0);
|
UTF8ASSERT(wcscmp(widechars, expected) == 0);
|
||||||
|
UTF8ASSERT(wcslen(widechars) == result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If 'wideSequence' is NULL, then the result is expected to be
|
// If 'wideSequence' is NULL, then the result is expected to be
|
||||||
@@ -262,11 +265,14 @@ void MBConvTestCase::UTF8(const char *charSequence,
|
|||||||
|
|
||||||
// translate it back and check we get the original
|
// translate it back and check we get the original
|
||||||
char bytesAgain[BUFSIZE];
|
char bytesAgain[BUFSIZE];
|
||||||
|
size_t lenResultAgain = utf8.WC2MB(NULL, widechars, 0);
|
||||||
size_t resultAgain = utf8.WC2MB(bytesAgain, widechars, BUFSIZE);
|
size_t resultAgain = utf8.WC2MB(bytesAgain, widechars, BUFSIZE);
|
||||||
|
UTF8ASSERT(resultAgain == lenResultAgain);
|
||||||
UTF8ASSERT(resultAgain != (size_t)-1);
|
UTF8ASSERT(resultAgain != (size_t)-1);
|
||||||
wxASSERT(resultAgain < BUFSIZE);
|
wxASSERT(resultAgain < BUFSIZE);
|
||||||
|
|
||||||
UTF8ASSERT(strcmp(bytes, bytesAgain) == 0);
|
UTF8ASSERT(strcmp(bytes, bytesAgain) == 0);
|
||||||
|
UTF8ASSERT(strlen(bytesAgain) == resultAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_WCHAR_H
|
#endif // HAVE_WCHAR_H
|
||||||
|
Reference in New Issue
Block a user