+
+// Ticket 6954 - trouble with the haveC1Bytes flag that is used to distinguish between
+// similar Windows and non-Windows SBCS encodings. State was kept in the shared
+// Charset Recognizer objects, and could be overwritten.
+void CharsetDetectionTest::Ticket6954Test() {
+#if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_FORMATTING
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeString sISO = "This is a small sample of some English text. Just enough to be sure that it detects correctly.";
+ UnicodeString ssWindows("This is another small sample of some English text. Just enough to be sure that it detects correctly."
+ "It also includes some \\u201CC1\\u201D bytes.", -1, US_INV);
+ UnicodeString sWindows = ssWindows.unescape();
+ int32_t lISO = 0, lWindows = 0;
+ char *bISO = extractBytes(sISO, "ISO-8859-1", lISO);
+ char *bWindows = extractBytes(sWindows, "windows-1252", lWindows);
+
+ // First do a plain vanilla detect of 1252 text
+
+ UCharsetDetector *csd1 = ucsdet_open(&status);
+ ucsdet_setText(csd1, bWindows, lWindows, &status);
+ const UCharsetMatch *match1 = ucsdet_detect(csd1, &status);
+ const char *name1 = ucsdet_getName(match1, &status);
+ TEST_ASSERT_SUCCESS(status);
+ TEST_ASSERT(strcmp(name1, "windows-1252")==0);
+
+ // Next, using a completely separate detector, detect some 8859-1 text
+
+ UCharsetDetector *csd2 = ucsdet_open(&status);
+ ucsdet_setText(csd2, bISO, lISO, &status);
+ const UCharsetMatch *match2 = ucsdet_detect(csd2, &status);
+ const char *name2 = ucsdet_getName(match2, &status);
+ TEST_ASSERT_SUCCESS(status);
+ TEST_ASSERT(strcmp(name2, "ISO-8859-1")==0);
+
+ // Recheck the 1252 results from the first detector, which should not have been
+ // altered by the use of a different detector.
+
+ name1 = ucsdet_getName(match1, &status);
+ TEST_ASSERT_SUCCESS(status);
+ TEST_ASSERT(strcmp(name1, "windows-1252")==0);
+
+ ucsdet_close(csd1);
+ ucsdet_close(csd2);
+ freeBytes(bISO);
+ freeBytes(bWindows);
+#endif
+}