#include "unicode/utypes.h"
#include "unicode/utext.h"
#include "unicode/utf8.h"
+#include "unicode/utf16.h"
#include "unicode/ustring.h"
#include "unicode/uchriter.h"
#include "cmemory.h"
void
UTextTest::runIndexedTest(int32_t index, UBool exec,
const char* &name, char* /*par*/) {
- switch (index) {
- case 0: name = "TextTest";
- if (exec) TextTest(); break;
- case 1: name = "ErrorTest";
- if (exec) ErrorTest(); break;
- case 2: name = "FreezeTest";
- if (exec) FreezeTest(); break;
- case 3: name = "Ticket5560";
- if (exec) Ticket5560(); break;
- case 4: name = "Ticket6847";
- if (exec) Ticket6847(); break;
- case 5: name = "Ticket10562";
- if (exec) Ticket10562(); break;
- case 6: name = "Ticket10983";
- if (exec) Ticket10983(); break;
- case 7: name = "Ticket12130";
- if (exec) Ticket12130(); break;
- case 8: name = "Ticket12888";
- if (exec) Ticket12888(); break;
- default: name = ""; break;
- }
+ TESTCASE_AUTO_BEGIN;
+ TESTCASE_AUTO(TextTest);
+ TESTCASE_AUTO(ErrorTest);
+ TESTCASE_AUTO(FreezeTest);
+ TESTCASE_AUTO(Ticket5560);
+ TESTCASE_AUTO(Ticket6847);
+ TESTCASE_AUTO(Ticket10562);
+ TESTCASE_AUTO(Ticket10983);
+ TESTCASE_AUTO(Ticket12130);
+ TESTCASE_AUTO(Ticket13344);
+ TESTCASE_AUTO_END;
}
//
UChar buf[10];
int n = utext_extract(ut, 0, 9, buf, 10, &status);
TEST_SUCCESS(status);
- TEST_ASSERT(n==5);
+ TEST_ASSERT(n==7);
+ TEST_ASSERT(buf[0] == 0x41);
TEST_ASSERT(buf[1] == 0xfffd);
- TEST_ASSERT(buf[3] == 0xfffd);
TEST_ASSERT(buf[2] == 0x42);
+ TEST_ASSERT(buf[3] == 0xfffd);
+ TEST_ASSERT(buf[4] == 0xfffd);
+ TEST_ASSERT(buf[5] == 0xfffd);
+ TEST_ASSERT(buf[6] == 0x43);
utext_close(ut);
}
utext_close(&ut);
}
-// Ticket 12888: bad handling of illegal utf-8 containing many instances of the archaic, now illegal,
-// six byte utf-8 forms. Original implementation had an assumption that
-// there would be at most three utf-8 bytes per UTF-16 code unit.
-// The five and six byte sequences map to a single replacement character.
-
-void UTextTest::Ticket12888() {
- const char *badString =
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80"
- "\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80\xfd\x80\x80\x80\x80\x80";
+// Ticket 13344 The macro form of UTEXT_SETNATIVEINDEX failed when target was a trail surrogate
+// of a supplementary character.
+void UTextTest::Ticket13344() {
UErrorCode status = U_ZERO_ERROR;
- LocalUTextPointer ut(utext_openUTF8(NULL, badString, -1, &status));
- TEST_SUCCESS(status);
- for (;;) {
- UChar32 c = utext_next32(ut.getAlias());
- if (c == U_SENTINEL) {
- break;
- }
- }
- int32_t endIdx = utext_getNativeIndex(ut.getAlias());
- if (endIdx != (int32_t)strlen(badString)) {
- errln("%s:%d expected=%d, actual=%d", __FILE__, __LINE__, strlen(badString), endIdx);
- return;
- }
-
- for (int32_t prevIndex = endIdx; prevIndex>0;) {
- UChar32 c = utext_previous32(ut.getAlias());
- int32_t currentIndex = utext_getNativeIndex(ut.getAlias());
- if (c != 0xfffd) {
- errln("%s:%d (expected, actual, index) = (%d, %d, %d)\n",
- __FILE__, __LINE__, 0xfffd, c, currentIndex);
- break;
- }
- if (currentIndex != prevIndex - 6) {
- errln("%s:%d: wrong index. Expected, actual = %d, %d",
- __FILE__, __LINE__, prevIndex - 6, currentIndex);
- break;
- }
- prevIndex = currentIndex;
- }
+ const char16_t *str = u"abc\U0010abcd xyz";
+ LocalUTextPointer ut(utext_openUChars(NULL, str, -1, &status));
+
+ assertSuccess("UTextTest::Ticket13344-status", status);
+ UTEXT_SETNATIVEINDEX(ut.getAlias(), 3);
+ assertEquals("UTextTest::Ticket13344-lead", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+ UTEXT_SETNATIVEINDEX(ut.getAlias(), 4);
+ assertEquals("UTextTest::Ticket13344-trail", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+ UTEXT_SETNATIVEINDEX(ut.getAlias(), 5);
+ assertEquals("UTextTest::Ticket13344-bmp", (int64_t)5, utext_getNativeIndex(ut.getAlias()));
+
+ utext_setNativeIndex(ut.getAlias(), 3);
+ assertEquals("UTextTest::Ticket13344-lead-2", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+ utext_setNativeIndex(ut.getAlias(), 4);
+ assertEquals("UTextTest::Ticket13344-trail-2", (int64_t)3, utext_getNativeIndex(ut.getAlias()));
+ utext_setNativeIndex(ut.getAlias(), 5);
+ assertEquals("UTextTest::Ticket13344-bmp-2", (int64_t)5, utext_getNativeIndex(ut.getAlias()));
}
+