/*
***************************************************************************
- * Copyright (C) 2008-2009, International Business Machines Corporation
+ * Copyright (C) 2008-2015, International Business Machines Corporation
* and others. All Rights Reserved.
***************************************************************************
* file name: uspoof_build.cpp
U_NAMESPACE_USE
+// Defined in uspoof.cpp, initializes file-static variables.
+U_CFUNC void uspoof_internalInit(UErrorCode *status);
// The main data building function
uspoof_openFromSource(const char *confusables, int32_t confusablesLen,
const char *confusablesWholeScript, int32_t confusablesWholeScriptLen,
int32_t *errorType, UParseError *pe, UErrorCode *status) {
-
+ uspoof_internalInit(status);
if (U_FAILURE(*status)) {
return NULL;
}
/********************************************************************
* COPYRIGHT:
- * Copyright (c) 2009-2014, International Business Machines Corporation and
+ * Copyright (c) 2009-2015, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/********************************************************************************
uspoof_close(sc); \
}
-
+static void TestOpenFromSource(void);
static void TestUSpoofCAPI(void);
void addUSpoofTest(TestNode** root);
void addUSpoofTest(TestNode** root)
{
#if !UCONFIG_NO_FILE_IO
- addTest(root, &TestUSpoofCAPI, "uspoof/TestUSpoofCAPI");
+ addTest(root, &TestOpenFromSource, "uspoof/TestOpenFromSource");
#endif
+ addTest(root, &TestUSpoofCAPI, "uspoof/TestUSpoofCAPI");
}
/*
/* Provide better code coverage */
const char goodLatinUTF8[] = {0x75, 0x77, 0};
-/*
- * Spoof Detction C API Tests
- */
-static void TestUSpoofCAPI(void) {
-
- /*
- * basic uspoof_open().
- */
- {
- USpoofChecker *sc;
- UErrorCode status = U_ZERO_ERROR;
- sc = uspoof_open(&status);
- TEST_ASSERT_SUCCESS(status);
- if (U_FAILURE(status)) {
- /* If things are so broken that we can't even open a default spoof checker, */
- /* don't even try the rest of the tests. They would all fail. */
- return;
- }
- uspoof_close(sc);
- }
-
-
- /*
- * Test Open from source rules.
- */
- TEST_SETUP
+// Test open from source rules.
+// Run this in isolation to verify initialization.
+static void TestOpenFromSource() {
+ // No TEST_SETUP because that calls uspoof_open().
+ UErrorCode status = U_ZERO_ERROR;
const char *dataSrcDir;
char *fileName;
char *confusables;
FILE *f;
UParseError pe;
int32_t errType;
+ int32_t checkResults;
USpoofChecker *rsc;
-
+
dataSrcDir = ctest_dataSrcDir();
fileName = malloc(strlen(dataSrcDir) + 100);
strcpy(fileName, dataSrcDir);
}
rsc = uspoof_openFromSource(confusables, confusablesLength,
- confusablesWholeScript, confusablesWholeScriptLength,
- &errType, &pe, &status);
+ confusablesWholeScript, confusablesWholeScriptLength,
+ &errType, &pe, &status);
TEST_ASSERT_SUCCESS(status);
+ // Ticket #11860: uspoof_openFromSource() did not initialize for use.
+ // Verify that the spoof checker does not crash.
+ checkResults = uspoof_check(rsc, goodLatin, -1, NULL, &status);
+ TEST_ASSERT_SUCCESS(status);
+ TEST_ASSERT_EQ(0, checkResults);
+
free(confusablesWholeScript);
free(confusables);
free(fileName);
uspoof_close(rsc);
/* printf("ParseError Line is %d\n", pe.line); */
- TEST_TEARDOWN;
+}
+/*
+ * Spoof Detection C API Tests
+ */
+static void TestUSpoofCAPI(void) {
+
+ /*
+ * basic uspoof_open().
+ */
+ {
+ USpoofChecker *sc;
+ UErrorCode status = U_ZERO_ERROR;
+ sc = uspoof_open(&status);
+ TEST_ASSERT_SUCCESS(status);
+ if (U_FAILURE(status)) {
+ /* If things are so broken that we can't even open a default spoof checker, */
+ /* don't even try the rest of the tests. They would all fail. */
+ return;
+ }
+ uspoof_close(sc);
+ }
/*
* openFromSerialized and serialize