コード例 #1
0
void IntlTestSpoof::testSpoofAPI() {

    TEST_SETUP
    UnicodeString s("uvw");
    int32_t position = 666;
    int32_t checkResults = uspoof_checkUnicodeString(sc, s, &position, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);
    TEST_ASSERT_EQ(666, position);
    TEST_TEARDOWN;

    TEST_SETUP
    UnicodeString s1("cxs");
    UnicodeString s2 = UnicodeString("\\u0441\\u0445\\u0455").unescape();  // Cyrillic "cxs"
    int32_t checkResults = uspoof_areConfusableUnicodeString(sc, s1, s2, &status);
    TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_WHOLE_SCRIPT_CONFUSABLE, checkResults);

    TEST_TEARDOWN;

    TEST_SETUP
    UnicodeString s("I1l0O");
    UnicodeString dest;
    UnicodeString &retStr = uspoof_getSkeletonUnicodeString(sc, USPOOF_ANY_CASE, s, dest, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT(UnicodeString("11100") == dest);
    TEST_ASSERT(&dest == &retStr);
    TEST_TEARDOWN;
}
コード例 #2
0
void IntlTestSpoof::testSpoofAPI() {

    TEST_SETUP
        UnicodeString s("xyz");  // Many latin ranges are whole-script confusable with other scripts.
                                 // If this test starts failing, consult confusablesWholeScript.txt
        int32_t position = 666;
        int32_t checkResults = uspoof_checkUnicodeString(sc, s, &position, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);
        TEST_ASSERT_EQ(666, position);
    TEST_TEARDOWN;
    
    TEST_SETUP
        UnicodeString s1("cxs");
        UnicodeString s2 = UnicodeString("\\u0441\\u0445\\u0455").unescape();  // Cyrillic "cxs"
        int32_t checkResults = uspoof_areConfusableUnicodeString(sc, s1, s2, &status);
        TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_WHOLE_SCRIPT_CONFUSABLE, checkResults);

    TEST_TEARDOWN;

    TEST_SETUP
        UnicodeString s("I1l0O");
        UnicodeString dest;
        UnicodeString &retStr = uspoof_getSkeletonUnicodeString(sc, USPOOF_ANY_CASE, s, dest, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(UnicodeString("lllOO") == dest);
        TEST_ASSERT(&dest == &retStr);
    TEST_TEARDOWN;
}
コード例 #3
0
ファイル: ssearch.cpp プロジェクト: Distrotech/icu
void SSearchTest::goodSuffixTest()
{
    UErrorCode status = U_ZERO_ERROR;
    UCollator *coll = NULL;
    UnicodeString pat = /*"gcagagag"*/ "fxeld";
    UnicodeString target = /*"gcatcgcagagagtatacagtacg"*/ "cloveldfxeld";
    int32_t start = -1, end = -1;
    UBool bFound;

    coll = ucol_open(NULL, &status);
    TEST_ASSERT_SUCCESS(status);

    LocalUStringSearchPointer ss(usearch_openFromCollator(pat.getBuffer(), pat.length(),
                                                          target.getBuffer(), target.length(),
                                                          coll,
                                                          NULL,     // the break iterator
                                                          &status));
    TEST_ASSERT_SUCCESS(status);

    bFound = usearch_search(ss.getAlias(), 0, &start, &end, &status);
    TEST_ASSERT_SUCCESS(status);
    if (bFound) {
        logln("Found pattern at [%d, %d].", start, end);
    } else {
        dataerrln("Did not find pattern.");
    }

    ucol_close(coll);
}
コード例 #4
0
ファイル: ssearch.cpp プロジェクト: Distrotech/icu
void SSearchTest::sharpSTest()
{
    UErrorCode status = U_ZERO_ERROR;
    UCollator *coll = NULL;
    UnicodeString lp  = "fuss";
    UnicodeString sp = "fu\\u00DF";
    UnicodeString targets[]  = {"fu\\u00DF", "fu\\u00DFball", "1fu\\u00DFball", "12fu\\u00DFball", "123fu\\u00DFball", "1234fu\\u00DFball",
                                "ffu\\u00DF", "fufu\\u00DF", "fusfu\\u00DF",
                                "fuss", "ffuss", "fufuss", "fusfuss", "1fuss", "12fuss", "123fuss", "1234fuss", "fu\\u00DF", "1fu\\u00DF", "12fu\\u00DF", "123fu\\u00DF", "1234fu\\u00DF"};
    int32_t start = -1, end = -1;

    coll = ucol_openFromShortString("LEN_S1", FALSE, NULL, &status);
    TEST_ASSERT_SUCCESS(status);

    UnicodeString lpUnescaped = lp.unescape();
    UnicodeString spUnescaped = sp.unescape();

    LocalUStringSearchPointer ussLong(usearch_openFromCollator(lpUnescaped.getBuffer(), lpUnescaped.length(),
                                                           lpUnescaped.getBuffer(), lpUnescaped.length(),   // actual test data will be set later
                                                           coll,
                                                           NULL,     // the break iterator
                                                           &status));

    LocalUStringSearchPointer ussShort(usearch_openFromCollator(spUnescaped.getBuffer(), spUnescaped.length(),
                                                           spUnescaped.getBuffer(), spUnescaped.length(),   // actual test data will be set later
                                                           coll,
                                                           NULL,     // the break iterator
                                                           &status));
    TEST_ASSERT_SUCCESS(status);

    for (uint32_t t = 0; t < (sizeof(targets)/sizeof(targets[0])); t += 1) {
        UBool bFound;
        UnicodeString target = targets[t].unescape();

        start = end = -1;
        usearch_setText(ussLong.getAlias(), target.getBuffer(), target.length(), &status);
        bFound = usearch_search(ussLong.getAlias(), 0, &start, &end, &status);
        TEST_ASSERT_SUCCESS(status);
        if (bFound) {
            logln("Test %d: found long pattern at [%d, %d].", t, start, end);
        } else {
            dataerrln("Test %d: did not find long pattern.", t);
        }

        usearch_setText(ussShort.getAlias(), target.getBuffer(), target.length(), &status);
        bFound = usearch_search(ussShort.getAlias(), 0, &start, &end, &status);
        TEST_ASSERT_SUCCESS(status);
        if (bFound) {
            logln("Test %d: found long pattern at [%d, %d].", t, start, end);
        } else {
            dataerrln("Test %d: did not find long pattern.", t);
        }
    }

    ucol_close(coll);
}
コード例 #5
0
ファイル: spooftest.c プロジェクト: icu-project/icu4c
// 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;
    int         confusablesLength = 0;
    char       *confusablesWholeScript;
    int         confusablesWholeScriptLength = 0;
    FILE       *f;
    UParseError pe;
    int32_t     errType;
    int32_t     checkResults;
    USpoofChecker *rsc;

    dataSrcDir = ctest_dataSrcDir();
    fileName = malloc(strlen(dataSrcDir) + 100);
    strcpy(fileName, dataSrcDir);
    strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusables.txt");
    f = fopen(fileName, "rb");
    TEST_ASSERT_NE(f, NULL);
    confusables = malloc(3000000);
    if (f != NULL) {
        confusablesLength = fread(confusables, 1, 3000000, f);
        fclose(f);
    }

    strcpy(fileName, dataSrcDir);
    strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusablesWholeScript.txt");
    f = fopen(fileName, "rb");
    TEST_ASSERT_NE(f, NULL);
    confusablesWholeScript = malloc(1000000);
    if (f != NULL) {
        confusablesWholeScriptLength = fread(confusablesWholeScript, 1, 1000000, f);
        fclose(f);
    }

    rsc = uspoof_openFromSource(confusables, confusablesLength,
                                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);  */
}
コード例 #6
0
static void TestBug4315(void) {
    UErrorCode      theICUError = U_ZERO_ERROR;
    URegularExpression *theRegEx;
    UChar           *textBuff;
    const char      *thePattern;
    UChar            theString[100];
    UChar           *destFields[24];
    int32_t         neededLength1;
    int32_t         neededLength2;

    int32_t         wordCount = 0;
    int32_t         destFieldsSize = 24;

    thePattern  = "ck ";
    u_uastrcpy(theString, "The quick brown fox jumped over the slow black turtle.");

    /* open a regex */
    theRegEx = uregex_openC(thePattern, 0, NULL, &theICUError);
    TEST_ASSERT_SUCCESS(theICUError);

    /* set the input string */
    uregex_setText(theRegEx, theString, u_strlen(theString), &theICUError);
    TEST_ASSERT_SUCCESS(theICUError);

    /* split */
    /*explicitly pass NULL and 0 to force the overflow error -> this is where the
     *  error occurs! */
    wordCount = uregex_split(theRegEx, NULL, 0, &neededLength1, destFields,
        destFieldsSize, &theICUError);

    TEST_ASSERT(theICUError == U_BUFFER_OVERFLOW_ERROR);
    TEST_ASSERT(wordCount==3);

    if(theICUError == U_BUFFER_OVERFLOW_ERROR)
    {
        theICUError = U_ZERO_ERROR;
        textBuff = (UChar *) malloc(sizeof(UChar) * (neededLength1 + 1));
        wordCount = uregex_split(theRegEx, textBuff, neededLength1+1, &neededLength2,
            destFields, destFieldsSize, &theICUError);
        TEST_ASSERT(wordCount==3);
        TEST_ASSERT_SUCCESS(theICUError);
        TEST_ASSERT(neededLength1 == neededLength2);
        TEST_ASSERT_STRING("The qui", destFields[0], TRUE);
        TEST_ASSERT_STRING("brown fox jumped over the slow bla", destFields[1], TRUE);
        TEST_ASSERT_STRING("turtle.", destFields[2], TRUE);
        TEST_ASSERT(destFields[3] == NULL);
        free(textBuff);
    }
    uregex_close(theRegEx);
}
コード例 #7
0
ファイル: rbbiapts.cpp プロジェクト: Distrotech/icu
void RBBIAPITest::TestRefreshInputText() {
    /*
     *  RefreshInput changes out the input of a Break Iterator without
     *    changing anything else in the iterator's state.  Used with Java JNI,
     *    when Java moves the underlying string storage.   This test
     *    runs BreakIterator::next() repeatedly, moving the text in the middle of the sequence.
     *    The right set of boundaries should still be found.
     */
    UChar testStr[]  = {0x20, 0x41, 0x20, 0x42, 0x20, 0x43, 0x20, 0x44, 0x0};  /* = " A B C D"  */
    UChar movedStr[] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,  0};
    UErrorCode status = U_ZERO_ERROR;
    UText ut1 = UTEXT_INITIALIZER;
    UText ut2 = UTEXT_INITIALIZER;
    RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)BreakIterator::createLineInstance(Locale::getEnglish(), status);
    TEST_ASSERT_SUCCESS(status);

    utext_openUChars(&ut1, testStr, -1, &status);
    TEST_ASSERT_SUCCESS(status);

    if (U_SUCCESS(status)) {
        bi->setText(&ut1, status);
        TEST_ASSERT_SUCCESS(status);

        /* Line boundaries will occur before each letter in the original string */
        TEST_ASSERT(1 == bi->next());
        TEST_ASSERT(3 == bi->next());

        /* Move the string, kill the original string.  */
        u_strcpy(movedStr, testStr);
        u_memset(testStr, 0x20, u_strlen(testStr));
        utext_openUChars(&ut2, movedStr, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        RuleBasedBreakIterator *returnedBI = &bi->refreshInputText(&ut2, status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(bi == returnedBI);

        /* Find the following matches, now working in the moved string. */
        TEST_ASSERT(5 == bi->next());
        TEST_ASSERT(7 == bi->next());
        TEST_ASSERT(8 == bi->next());
        TEST_ASSERT(UBRK_DONE == bi->next());
    
        utext_close(&ut1);
        utext_close(&ut2);
    }
    delete bi;

}
コード例 #8
0
ファイル: cbiapts.c プロジェクト: Epictetus/build-couchdb
/*
*   TestsBreakIteratorStatusVals()   Test the ubrk_getRuleStatusVec() funciton
*/
static void TestBreakIteratorStatusVec() {
    #define RULE_STRING_LENGTH 200
    UChar          rules[RULE_STRING_LENGTH];

    #define TEST_STRING_LENGTH 25
    UChar           testString[TEST_STRING_LENGTH];
    UBreakIterator *bi        = NULL;
    int32_t         pos       = 0;
    int32_t         vals[10];
    int32_t         numVals;
    UErrorCode      status    = U_ZERO_ERROR;

    u_uastrncpy(rules,  "[A-N]{100}; \n"
                             "[a-w]{200}; \n"
                             "[\\p{L}]{300}; \n"
                             "[\\p{N}]{400}; \n"
                             "[0-5]{500}; \n"
                              "!.*;\n", RULE_STRING_LENGTH);
    u_uastrncpy(testString, "ABC", TEST_STRING_LENGTH);


    bi = ubrk_openRules(rules, -1, testString, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT(bi != NULL);

    /* The TEST_ASSERT above should change too... */
    if (bi != NULL) {
        pos = ubrk_next(bi);
        TEST_ASSERT(pos == 1);

        memset(vals, -1, sizeof(vals));
        numVals = ubrk_getRuleStatusVec(bi, vals, 10, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(numVals == 2);
        TEST_ASSERT(vals[0] == 100);
        TEST_ASSERT(vals[1] == 300);
        TEST_ASSERT(vals[2] == -1);

        numVals = ubrk_getRuleStatusVec(bi, vals, 0, &status);
        TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR);
        TEST_ASSERT(numVals == 2);
    }

    ubrk_close(bi);
}
コード例 #9
0
void IntlTestSpoof::testBug8654() {
    TEST_SETUP
        UnicodeString s = UnicodeString("B\\u00c1\\u0301").unescape();
        int32_t position = -42;
        TEST_ASSERT_EQ(USPOOF_INVISIBLE, uspoof_checkUnicodeString(sc, s, &position, &status) & USPOOF_INVISIBLE );
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(3, position);
    TEST_TEARDOWN;
}
コード例 #10
0
void IntlTestSpoof::testAreConfusable() {
    TEST_SETUP
        UnicodeString s1("A long string that will overflow stack buffers.  A long string that will overflow stack buffers. "
                         "A long string that will overflow stack buffers.  A long string that will overflow stack buffers. ");
        UnicodeString s2("A long string that wi11 overflow stack buffers.  A long string that will overflow stack buffers. "
                         "A long string that wi11 overflow stack buffers.  A long string that will overflow stack buffers. ");
        TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT_CONFUSABLE, uspoof_areConfusableUnicodeString(sc, s1, s2, &status));
        TEST_ASSERT_SUCCESS(status);

    TEST_TEARDOWN;
}
コード例 #11
0
void IntlTestSpoof::testInvisible() {
    TEST_SETUP
        UnicodeString  s = UnicodeString("abcd\\u0301ef").unescape();
        int32_t position = -42;
        TEST_ASSERT_EQ(0, uspoof_checkUnicodeString(sc, s, &position, &status));
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(position == -42);

        UnicodeString  s2 = UnicodeString("abcd\\u0301\\u0302\\u0301ef").unescape();
        TEST_ASSERT_EQ(USPOOF_INVISIBLE, uspoof_checkUnicodeString(sc, s2, &position, &status));
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(7, position);

        // Two acute accents, one from the composed a with acute accent, \u00e1,
        // and one separate.
        position = -42;
        UnicodeString  s3 = UnicodeString("abcd\\u00e1\\u0301xyz").unescape();
        TEST_ASSERT_EQ(USPOOF_INVISIBLE, uspoof_checkUnicodeString(sc, s3, &position, &status));
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(7, position);
    TEST_TEARDOWN;
}
コード例 #12
0
ファイル: cbiapts.c プロジェクト: Cyril2004/proto-quic
static void TestBug11665(void) {
    // The problem was with the incorrect breaking of Japanese text beginning
    // with Katakana characters when no prior Japanese or Chinese text had been
    // encountered.
    //
    // Tested here in cintltst, rather than in intltest, because only cintltst
    // tests have the ability to reset ICU, which is needed to get the bug
    // to manifest itself.

    static UChar japaneseText[] = {0x30A2, 0x30EC, 0x30EB, 0x30AE, 0x30FC, 0x6027, 0x7D50, 0x819C, 0x708E};
    int32_t boundaries[10] = {0};
    UBreakIterator *bi = NULL;
    int32_t brk;
    int32_t brkIdx = 0;
    int32_t totalBreaks = 0;
    UErrorCode status = U_ZERO_ERROR;

    ctest_resetICU();
    bi = ubrk_open(UBRK_WORD, "en_US", japaneseText, UPRV_LENGTHOF(japaneseText), &status);
    TEST_ASSERT_SUCCESS(status);
    if (!bi) {
        return;
    }
    for (brk=ubrk_first(bi); brk != UBRK_DONE; brk=ubrk_next(bi)) {
        boundaries[brkIdx] = brk;
        if (++brkIdx >= UPRV_LENGTHOF(boundaries) - 1) {
            break;
        }
    }
    if (brkIdx <= 2 || brkIdx >= UPRV_LENGTHOF(boundaries)) {
        log_err("%s:%d too few or many breaks found.\n", __FILE__, __LINE__);
    } else {
        totalBreaks = brkIdx;
        brkIdx = 0;
        for (brk=ubrk_first(bi); brk != UBRK_DONE; brk=ubrk_next(bi)) {
            if (brk != boundaries[brkIdx]) {
                log_err("%s:%d Break #%d differs between first and second iteration.\n", __FILE__, __LINE__, brkIdx);
                break;
            }
            if (++brkIdx >= UPRV_LENGTHOF(boundaries) - 1) {
                log_err("%s:%d Too many breaks.\n", __FILE__, __LINE__);
                break;
            }
        }
        if (totalBreaks != brkIdx) {
            log_err("%s:%d Number of breaks differ between first and second iteration.\n", __FILE__, __LINE__);
        }
    }
    ubrk_close(bi);
}
コード例 #13
0
ファイル: test_resource.c プロジェクト: DrenfongWong/dpdk
static int test_resource_tar(void)
{
	const struct resource *r;
	FILE *f;

	r = resource_find("test_resource_tar");
	TEST_ASSERT_NOT_NULL(r, "No test_resource_tar found");
	TEST_ASSERT(!strcmp(r->name, "test_resource_tar"),
			"Found resource %s, expected test_resource_tar",
			r->name);

	TEST_ASSERT_SUCCESS(resource_untar(r),
			"Failed to to untar %s", r->name);

	f = fopen("test_resource.c", "r");
	TEST_ASSERT_NOT_NULL(f,
			"Missing extracted file test_resource.c");
	fclose(f);

	TEST_ASSERT_SUCCESS(resource_rm_by_tar(r),
			"Failed to remove extracted contents of %s", r->name);
	return 0;
}
コード例 #14
0
ファイル: cbiapts.c プロジェクト: Cyril2004/proto-quic
static void TestBreakIteratorRefresh(void) {
    /*
     *  RefreshInput changes out the input of a Break Iterator without
     *    changing anything else in the iterator's state.  Used with Java JNI,
     *    when Java moves the underlying string storage.   This test
     *    runs a ubrk_next() repeatedly, moving the text in the middle of the sequence.
     *    The right set of boundaries should still be found.
     */
    UChar testStr[]  = {0x20, 0x41, 0x20, 0x42, 0x20, 0x43, 0x20, 0x44, 0x0};  /* = " A B C D"  */
    UChar movedStr[] = {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,  0};
    UErrorCode status = U_ZERO_ERROR;
    UBreakIterator *bi;
    UText ut1 = UTEXT_INITIALIZER;
    UText ut2 = UTEXT_INITIALIZER;
    
    bi = ubrk_open(UBRK_LINE, "en_US", NULL, 0, &status);
    TEST_ASSERT_SUCCESS(status);
    if (U_FAILURE(status)) {
        return;
    }

    utext_openUChars(&ut1, testStr, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    ubrk_setUText(bi, &ut1, &status);
    TEST_ASSERT_SUCCESS(status);

    if (U_SUCCESS(status)) {
        /* Line boundaries will occur before each letter in the original string */
        TEST_ASSERT(1 == ubrk_next(bi));
        TEST_ASSERT(3 == ubrk_next(bi));

        /* Move the string, kill the original string.  */
        u_strcpy(movedStr, testStr);
        u_memset(testStr, 0x20, u_strlen(testStr));
        utext_openUChars(&ut2, movedStr, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        ubrk_refreshUText(bi, &ut2, &status);
        TEST_ASSERT_SUCCESS(status);
    
        /* Find the following matches, now working in the moved string. */
        TEST_ASSERT(5 == ubrk_next(bi));
        TEST_ASSERT(7 == ubrk_next(bi));
        TEST_ASSERT(8 == ubrk_next(bi));
        TEST_ASSERT(UBRK_DONE == ubrk_next(bi));
        TEST_ASSERT_SUCCESS(status);

        utext_close(&ut1);
        utext_close(&ut2);
    }
    ubrk_close(bi);
}
コード例 #15
0
ファイル: cbiapts.c プロジェクト: Epictetus/build-couchdb
/*
 *  static void TestBreakIteratorUText(void);
 *
 *         Test that ubrk_setUText() is present and works for a simple case.
 */
static void TestBreakIteratorUText(void) {
    const char *UTF8Str = "\x41\xc3\x85\x5A\x20\x41\x52\x69\x6E\x67";  /* c3 85 is utf-8 for A with a ring on top */
                      /*   0  1   2 34567890  */

    UErrorCode      status = U_ZERO_ERROR;
    UBreakIterator *bi     = NULL;
    int32_t         pos    = 0;


    UText *ut = utext_openUTF8(NULL, UTF8Str, -1, &status);
    TEST_ASSERT_SUCCESS(status);

    bi = ubrk_open(UBRK_WORD, "en_US", NULL, 0, &status);
    if (U_FAILURE(status)) {
        log_err_status(status, "Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status));
        return;
    }

    ubrk_setUText(bi, ut, &status);
    if (U_FAILURE(status)) {
        log_err("Failure at file %s, line %d, error = %s\n", __FILE__, __LINE__, u_errorName(status));
        return;
    }

    pos = ubrk_first(bi);
    TEST_ASSERT(pos == 0);

    pos = ubrk_next(bi);
    TEST_ASSERT(pos == 4);

    pos = ubrk_next(bi);
    TEST_ASSERT(pos == 5);

    pos = ubrk_next(bi);
    TEST_ASSERT(pos == 10);

    pos = ubrk_next(bi);
    TEST_ASSERT(pos == UBRK_DONE);
    ubrk_close(bi);
    utext_close(ut);
}
コード例 #16
0
ファイル: test_resource.c プロジェクト: DrenfongWong/dpdk
static int test_resource_c(void)
{
	const struct resource *r;
	FILE *f;

	r = resource_find("test_resource_c");
	TEST_ASSERT_NOT_NULL(r, "No test_resource_c found");
	TEST_ASSERT(!strcmp(r->name, "test_resource_c"),
			"Found resource %s, expected test_resource_c",
			r->name);

	TEST_ASSERT_SUCCESS(resource_fwrite_file(r, "test_resource.c"),
			"Failed to to write file %s", r->name);

	f = fopen("test_resource.c", "r");
	TEST_ASSERT_NOT_NULL(f,
			"Missing extracted file resource.c");
	fclose(f);
	remove("test_resource.c");

	return 0;
}
コード例 #17
0
ファイル: control_test.c プロジェクト: aukeman/sdl_game
void map_jump_and_fire_to_buttons(){
  
  int setup_result = 0;
  struct linked_list__node_t* iter = NULL;
  const struct control_mapping_t* mapping = NULL;
  const char* mapping_file = setup(&setup_result, 
				   "2\n"
				   "jump joystick 5 button 3\n"
				   "fire joystick 5 button 10\n");
  TEST_ASSERT_SUCCESS(setup_result);

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[5][3], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, BINARY );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_NOT_NULL( control__get_state(2) );
  TEST_ASSERT_PTR( mapping->control_type.binary, &control__get_state(2)->jump );

  TEST_ASSERT_NULL( linked_list__next(&iter) );


  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[5][10], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, BINARY );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.binary, &control__get_state(2)->fire );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  teardown(mapping_file);
}
コード例 #18
0
ファイル: control_test.c プロジェクト: aukeman/sdl_game
void no_mapping_file(){

  int idx1, idx2;

  TEST_ASSERT_INT(control__setup(""), CONTROL__MAPPING_FILE_NOT_FOUND);

  for ( idx1 = 0; idx1 < 512; ++idx1 ){
    linked_list__empty( &keyboard_mappings[idx1] );
  }

  for ( idx1 = 0; idx1 < JS__MAX_JOYSTICKS; ++idx1 ){

    for ( idx2 = 0; idx2 < JS__MAX_AXES; ++idx2 ){
      TEST_ASSERT_TRUE( linked_list__empty( &js_axis_mappings[idx1][idx2] ) );
    }

    for ( idx2 = 0; idx2 < JS__MAX_BUTTONS; ++idx2 ){
      TEST_ASSERT_TRUE( linked_list__empty( &js_button_mappings[idx1][idx2] ) );
    }
  }

  TEST_ASSERT_SUCCESS(control__teardown());
}
コード例 #19
0
ファイル: ssearch.cpp プロジェクト: Distrotech/icu
void SSearchTest::searchTest()
{
#if !UCONFIG_NO_REGULAR_EXPRESSIONS && !UCONFIG_NO_FILE_IO
    UErrorCode status = U_ZERO_ERROR;
    char path[PATH_BUFFER_SIZE];
    const char *testFilePath = getPath(path, "ssearch.xml");

    if (testFilePath == NULL) {
        return; /* Couldn't get path: error message already output. */
    }

    LocalPointer<UXMLParser> parser(UXMLParser::createParser(status));
    TEST_ASSERT_SUCCESS(status);
    LocalPointer<UXMLElement> root(parser->parseFile(testFilePath, status));
    TEST_ASSERT_SUCCESS(status);
    if (U_FAILURE(status)) {
        return;
    }

    const UnicodeString *debugTestCase = root->getAttribute("debug");
    if (debugTestCase != NULL) {
//       setenv("USEARCH_DEBUG", "1", 1);
    }


    const UXMLElement *testCase;
    int32_t tc = 0;

    while((testCase = root->nextChildElement(tc)) != NULL) {

        if (testCase->getTagName().compare("test-case") != 0) {
            errln("ssearch, unrecognized XML Element in test file");
            continue;
        }
        const UnicodeString *id       = testCase->getAttribute("id");
        *testId = 0;
        if (id != NULL) {
            id->extract(0, id->length(), testId,  sizeof(testId), US_INV);
        }

        // If debugging test case has been specified and this is not it, skip to next.
        if (id!=NULL && debugTestCase!=NULL && *id != *debugTestCase) {
            continue;
        }
        //
        //  Get the requested collation strength.
        //    Default is tertiary if the XML attribute is missing from the test case.
        //
        const UnicodeString *strength = testCase->getAttribute("strength");
        UColAttributeValue collatorStrength = UCOL_PRIMARY;
        if      (strength==NULL)          { collatorStrength = UCOL_TERTIARY;}
        else if (*strength=="PRIMARY")    { collatorStrength = UCOL_PRIMARY;}
        else if (*strength=="SECONDARY")  { collatorStrength = UCOL_SECONDARY;}
        else if (*strength=="TERTIARY")   { collatorStrength = UCOL_TERTIARY;}
        else if (*strength=="QUATERNARY") { collatorStrength = UCOL_QUATERNARY;}
        else if (*strength=="IDENTICAL")  { collatorStrength = UCOL_IDENTICAL;}
        else {
            // Bogus value supplied for strength.  Shouldn't happen, even from
            //  typos, if the  XML source has been validated.
            //  This assert is a little deceiving in that strength can be
            //   any of the allowed values, not just TERTIARY, but it will
            //   do the job of getting the error output.
            TEST_ASSERT(*strength=="TERTIARY")
        }

        //
        // Get the collator normalization flag.  Default is UCOL_OFF.
        //
        UColAttributeValue normalize = UCOL_OFF;
        const UnicodeString *norm = testCase->getAttribute("norm");
        TEST_ASSERT (norm==NULL || *norm=="ON" || *norm=="OFF");
        if (norm!=NULL && *norm=="ON") {
            normalize = UCOL_ON;
        }

        //
        // Get the alternate_handling flag. Default is UCOL_NON_IGNORABLE.
        //
        UColAttributeValue alternateHandling = UCOL_NON_IGNORABLE;
        const UnicodeString *alt = testCase->getAttribute("alternate_handling");
        TEST_ASSERT (alt == NULL || *alt == "SHIFTED" || *alt == "NON_IGNORABLE");
        if (alt != NULL && *alt == "SHIFTED") {
            alternateHandling = UCOL_SHIFTED;
        }

        const UnicodeString defLocale("en");
        char  clocale[100];
        const UnicodeString *locale   = testCase->getAttribute("locale");
        if (locale == NULL || locale->length()==0) {
            locale = &defLocale;
        };
        locale->extract(0, locale->length(), clocale, sizeof(clocale), NULL);


        UnicodeString  text;
        UnicodeString  target;
        UnicodeString  pattern;
        int32_t        expectedMatchStart = -1;
        int32_t        expectedMatchLimit = -1;
        const UXMLElement  *n;
        int32_t                nodeCount = 0;

        n = testCase->getChildElement("pattern");
        TEST_ASSERT(n != NULL);
        if (n==NULL) {
            continue;
        }
        text = n->getText(FALSE);
        text = text.unescape();
        pattern.append(text);
        nodeCount++;

        n = testCase->getChildElement("pre");
        if (n!=NULL) {
            text = n->getText(FALSE);
            text = text.unescape();
            target.append(text);
            nodeCount++;
        }

        n = testCase->getChildElement("m");
        if (n!=NULL) {
            expectedMatchStart = target.length();
            text = n->getText(FALSE);
            text = text.unescape();
            target.append(text);
            expectedMatchLimit = target.length();
            nodeCount++;
        }

        n = testCase->getChildElement("post");
        if (n!=NULL) {
            text = n->getText(FALSE);
            text = text.unescape();
            target.append(text);
            nodeCount++;
        }

        //  Check that there weren't extra things in the XML
        TEST_ASSERT(nodeCount == testCase->countChildren());

        // Open a collator and StringSearch based on the parameters
        //   obtained from the XML.
        //
        status = U_ZERO_ERROR;
        LocalUCollatorPointer collator(ucol_open(clocale, &status));
        ucol_setStrength(collator.getAlias(), collatorStrength);
        ucol_setAttribute(collator.getAlias(), UCOL_NORMALIZATION_MODE, normalize, &status);
        ucol_setAttribute(collator.getAlias(), UCOL_ALTERNATE_HANDLING, alternateHandling, &status);
        LocalUStringSearchPointer uss(usearch_openFromCollator(pattern.getBuffer(), pattern.length(),
                                                               target.getBuffer(), target.length(),
                                                               collator.getAlias(),
                                                               NULL,     // the break iterator
                                                               &status));

        TEST_ASSERT_SUCCESS(status);
        if (U_FAILURE(status)) {
            continue;
        }

        int32_t foundStart = 0;
        int32_t foundLimit = 0;
        UBool   foundMatch;

        //
        // Do the search, check the match result against the expected results.
        //
        foundMatch= usearch_search(uss.getAlias(), 0, &foundStart, &foundLimit, &status);
        TEST_ASSERT_SUCCESS(status);
        if ((foundMatch && expectedMatchStart<0) ||
            (foundStart != expectedMatchStart)   ||
            (foundLimit != expectedMatchLimit)) {
                TEST_ASSERT(FALSE);   //  ouput generic error position
                infoln("Found, expected match start = %d, %d \n"
                       "Found, expected match limit = %d, %d",
                foundStart, expectedMatchStart, foundLimit, expectedMatchLimit);
        }

        // In case there are other matches...
        // (should we only do this if the test case passed?)
        while (foundMatch) {
            expectedMatchStart = foundStart;
            expectedMatchLimit = foundLimit;

            foundMatch = usearch_search(uss.getAlias(), foundLimit, &foundStart, &foundLimit, &status);
        }

        uss.adoptInstead(usearch_openFromCollator(pattern.getBuffer(), pattern.length(),
            target.getBuffer(), target.length(),
            collator.getAlias(),
            NULL,
            &status));

        //
        // Do the backwards search, check the match result against the expected results.
        //
        foundMatch= usearch_searchBackwards(uss.getAlias(), target.length(), &foundStart, &foundLimit, &status);
        TEST_ASSERT_SUCCESS(status);
        if ((foundMatch && expectedMatchStart<0) ||
            (foundStart != expectedMatchStart)   ||
            (foundLimit != expectedMatchLimit)) {
                TEST_ASSERT(FALSE);   //  ouput generic error position
                infoln("Found, expected backwards match start = %d, %d \n"
                       "Found, expected backwards match limit = %d, %d",
                foundStart, expectedMatchStart, foundLimit, expectedMatchLimit);
        }
    }
#endif
}
コード例 #20
0
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
    const char *dataSrcDir;
    char       *fileName;
    char       *confusables;
    int         confusablesLength;
    char       *confusablesWholeScript;
    int         confusablesWholeScriptLength;
    FILE       *f;
    UParseError pe;
    int32_t     errType;
    USpoofChecker *rsc;
    
    dataSrcDir = ctest_dataSrcDir();
    fileName = malloc(strlen(dataSrcDir) + 100);
    strcpy(fileName, dataSrcDir);
    strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusables.txt");
    f = fopen(fileName, "r");
    TEST_ASSERT_NE(f, NULL);
    confusables = malloc(3000000);
    confusablesLength = fread(confusables, 1, 3000000, f);
    fclose(f);

    
    strcpy(fileName, dataSrcDir);
    strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusablesWholeScript.txt");
    f = fopen(fileName, "r");
    TEST_ASSERT_NE(f, NULL);
    confusablesWholeScript = malloc(1000000);
    confusablesWholeScriptLength = fread(confusablesWholeScript, 1, 1000000, f);
    fclose(f);

    rsc = uspoof_openFromSource(confusables, confusablesLength,
                                              confusablesWholeScript, confusablesWholeScriptLength,
                                              &errType, &pe, &status);
    TEST_ASSERT_SUCCESS(status);

    free(confusablesWholeScript);
    free(confusables);
    free(fileName);
    uspoof_close(rsc);
    /*  printf("ParseError Line is %d\n", pe.line);  */
    TEST_TEARDOWN;


    /*
     * openFromSerialized and serialize
    */
    TEST_SETUP
        int32_t        serializedSize = 0;
        int32_t        actualLength = 0;
        char           *buf;
        USpoofChecker  *sc2;
        int32_t         checkResults;

        
        serializedSize = uspoof_serialize(sc, NULL, 0, &status);
        TEST_ASSERT_EQ(status, U_BUFFER_OVERFLOW_ERROR);
        TEST_ASSERT(serializedSize > 0);

        /* Serialize the default spoof checker */
        status = U_ZERO_ERROR;
        buf = (char *)malloc(serializedSize + 10);
        TEST_ASSERT(buf != NULL);
        buf[serializedSize] = 42;
        uspoof_serialize(sc, buf, serializedSize, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(42, buf[serializedSize]);

        /* Create a new spoof checker from the freshly serialized data */
        sc2 = uspoof_openFromSerialized(buf, serializedSize+10, &actualLength, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_NE(NULL, sc2);
        TEST_ASSERT_EQ(serializedSize, actualLength);

        /* Verify that the new spoof checker at least wiggles */
        checkResults = uspoof_check(sc2, goodLatin, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);

        checkResults = uspoof_check(sc2, scMixed, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);

        uspoof_close(sc2);
        free(buf);
    TEST_TEARDOWN;
        
        
        
    /*
     * Set & Get Check Flags
    */
    TEST_SETUP
        int32_t t;
        uspoof_setChecks(sc, USPOOF_ALL_CHECKS, &status);
        TEST_ASSERT_SUCCESS(status);
        t = uspoof_getChecks(sc, &status);
        TEST_ASSERT_EQ(t, USPOOF_ALL_CHECKS);
    
        uspoof_setChecks(sc, 0, &status);
        TEST_ASSERT_SUCCESS(status);
        t = uspoof_getChecks(sc, &status);
        TEST_ASSERT_EQ(0, t);
        
        uspoof_setChecks(sc,
                        USPOOF_WHOLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE,
                        &status);
        TEST_ASSERT_SUCCESS(status);
        t = uspoof_getChecks(sc, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_WHOLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE, t);
    TEST_TEARDOWN;

    /*
    * get & setAllowedChars
    */
    TEST_SETUP
        USet *us;
        const USet *uset;

        uset = uspoof_getAllowedChars(sc, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(uset_isFrozen(uset));
        us = uset_open((UChar32)0x41, (UChar32)0x5A);   /*  [A-Z]  */
        uspoof_setAllowedChars(sc, us, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_NE(us, uspoof_getAllowedChars(sc, &status));
        TEST_ASSERT(uset_equals(us, uspoof_getAllowedChars(sc, &status)));
        TEST_ASSERT_SUCCESS(status);
        uset_close(us);
    TEST_TEARDOWN;

    /*
    *  clone()
    */

    TEST_SETUP
        USpoofChecker *clone1 = NULL;
        USpoofChecker *clone2 = NULL;
        int32_t        checkResults = 0;
        
        clone1 = uspoof_clone(sc, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_NE(clone1, sc);

        clone2 = uspoof_clone(clone1, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_NE(clone2, clone1);

        uspoof_close(clone1);
        
        /* Verify that the cloned spoof checker is alive */
        checkResults = uspoof_check(clone2, goodLatin, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);

        checkResults = uspoof_check(clone2, scMixed, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);
        uspoof_close(clone2);
    TEST_TEARDOWN;

    /*
     *  get & set Checks
    */
    TEST_SETUP
        int32_t   checks;
        int32_t   checks2;
        int32_t   checkResults;

        checks = uspoof_getChecks(sc, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_ALL_CHECKS, checks);

        checks &= ~(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE);
        uspoof_setChecks(sc, checks, &status);
        TEST_ASSERT_SUCCESS(status);
        checks2 = uspoof_getChecks(sc, &status);
        TEST_ASSERT_EQ(checks, checks2);

        /* The checks that were disabled just above are the same ones that the "scMixed" test fails.
            So with those tests gone checking that Identifier should now succeed */
        checkResults = uspoof_check(sc, scMixed, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);
    TEST_TEARDOWN;
        
    /*
     *  AllowedLoacles
     */

    TEST_SETUP
        const char  *allowedLocales;
        int32_t  checkResults;

        /* Default allowed locales list should be empty */
        allowedLocales = uspoof_getAllowedLocales(sc, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(strcmp("", allowedLocales) == 0)

        /* Allow en and ru, which should enable Latin and Cyrillic only to pass */
        uspoof_setAllowedLocales(sc, "en, ru_RU", &status);
        TEST_ASSERT_SUCCESS(status);
        allowedLocales = uspoof_getAllowedLocales(sc, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(strstr(allowedLocales, "en") != NULL);
        TEST_ASSERT(strstr(allowedLocales, "ru") != NULL);

        /* Limit checks to USPOOF_CHAR_LIMIT.  Some of the test data has whole script confusables also,
         * which we don't want to see in this test. */
        uspoof_setChecks(sc, USPOOF_CHAR_LIMIT, &status);
        TEST_ASSERT_SUCCESS(status);

        checkResults = uspoof_check(sc, goodLatin, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);
        
        checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_CHAR_LIMIT, checkResults);

        checkResults = uspoof_check(sc, goodCyrl, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);

        /* Reset with an empty locale list, which should allow all characters to pass */
        uspoof_setAllowedLocales(sc, " ", &status);
        TEST_ASSERT_SUCCESS(status);

        checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);
    TEST_TEARDOWN;

    /*
     * AllowedChars   set/get the USet of allowed characters.
     */
    TEST_SETUP
        const USet  *set;
        USet        *tmpSet;
        int32_t      checkResults;
        
        /* By default, we should see no restriction; the USet should allow all characters. */
        set = uspoof_getAllowedChars(sc, &status);
        TEST_ASSERT_SUCCESS(status);
        tmpSet = uset_open(0, 0x10ffff);
        TEST_ASSERT(uset_equals(tmpSet, set));

        /* Setting the allowed chars should enable the check. */
        uspoof_setChecks(sc, USPOOF_ALL_CHECKS & ~USPOOF_CHAR_LIMIT, &status);
        TEST_ASSERT_SUCCESS(status);

        /* Remove a character that is in our good Latin test identifier from the allowed chars set. */
        uset_remove(tmpSet, goodLatin[1]);
        uspoof_setAllowedChars(sc, tmpSet, &status);
        TEST_ASSERT_SUCCESS(status);
        uset_close(tmpSet);

        /* Latin Identifier should now fail; other non-latin test cases should still be OK */
        checkResults = uspoof_check(sc, goodLatin, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_CHAR_LIMIT, checkResults);

        checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_WHOLE_SCRIPT_CONFUSABLE, checkResults);
    TEST_TEARDOWN;

    /*
     * check UTF-8
     */
    TEST_SETUP
        char    utf8buf[200];
        int32_t checkResults;
        int32_t position;

        u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, goodLatin, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        position = 666;
        checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);
        TEST_ASSERT_EQ(666, position);

        u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, goodCyrl, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);

        u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, scMixed, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        position = 666;
        checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_SINGLE_SCRIPT , checkResults);
        TEST_ASSERT_EQ(2, position);

    TEST_TEARDOWN;

    /*
     * uspoof_areConfusable()
     */
    TEST_SETUP
        int32_t  checkResults;
        
        checkResults = uspoof_areConfusable(sc, scLatin, -1, scMixed, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);

        checkResults = uspoof_areConfusable(sc, goodGreek, -1, scLatin, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);

        checkResults = uspoof_areConfusable(sc, lll_Latin_a, -1, lll_Latin_b, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT_CONFUSABLE, checkResults);

    TEST_TEARDOWN;

    /*
     * areConfusableUTF8
     */
    TEST_SETUP
        int32_t checkResults;
        char s1[200];
        char s2[200];


        u_strToUTF8(s1, sizeof(s1), NULL, scLatin, -1, &status);
        u_strToUTF8(s2, sizeof(s2), NULL, scMixed, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);

        u_strToUTF8(s1, sizeof(s1), NULL, goodGreek, -1, &status);
        u_strToUTF8(s2, sizeof(s2), NULL, scLatin, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, checkResults);
        
        u_strToUTF8(s1, sizeof(s1), NULL, lll_Latin_a, -1, &status);
        u_strToUTF8(s2, sizeof(s2), NULL, lll_Latin_b, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT_CONFUSABLE, checkResults);

    TEST_TEARDOWN;


  /*
   * getSkeleton
   */

    TEST_SETUP
        UChar dest[100];
        int32_t   skelLength;

        skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, dest, sizeof(dest)/sizeof(UChar), &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT_EQ(0, u_strcmp(lll_Skel, dest));
        TEST_ASSERT_EQ(u_strlen(lll_Skel), skelLength);

        skelLength = uspoof_getSkeletonUTF8(sc, USPOOF_ANY_CASE, goodLatinUTF8, -1, dest, sizeof(dest)/sizeof(UChar), &status);
        TEST_ASSERT_SUCCESS(status);

        skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, NULL, 0, &status);
        TEST_ASSERT_EQ(U_BUFFER_OVERFLOW_ERROR, status);
        TEST_ASSERT_EQ(3, skelLength);
        status = U_ZERO_ERROR;

    TEST_TEARDOWN;
}
コード例 #21
0
//  testConfData - Check each data item from the Unicode confusables.txt file,
//                 verify that it transforms correctly in a skeleton.
//
void IntlTestSpoof::testConfData() {
    UErrorCode status = U_ZERO_ERROR;

    const char *testDataDir = IntlTest::getSourceTestData(status);
    TEST_ASSERT_SUCCESS(status);
    char buffer[2000];
    uprv_strcpy(buffer, testDataDir);
    uprv_strcat(buffer, "confusables.txt");

    LocalStdioFilePointer f(fopen(buffer, "rb"));
    if (f.isNull()) {
        errln("Skipping test spoof/testConfData.  File confusables.txt not accessible.");
        return;
    }
    fseek(f.getAlias(), 0, SEEK_END);
    int32_t  fileSize = ftell(f.getAlias());
    LocalArray<char> fileBuf(new char[fileSize]);
    fseek(f.getAlias(), 0, SEEK_SET);
    int32_t amt_read = fread(fileBuf.getAlias(), 1, fileSize, f.getAlias());
    TEST_ASSERT_EQ(amt_read, fileSize);
    TEST_ASSERT(fileSize>0);
    if (amt_read != fileSize || fileSize <=0) {
        return;
    }
    UnicodeString confusablesTxt = UnicodeString::fromUTF8(StringPiece(fileBuf.getAlias(), fileSize));

    LocalUSpoofCheckerPointer sc(uspoof_open(&status));
    TEST_ASSERT_SUCCESS(status);

    // Parse lines from the confusables.txt file.  Example Line:
    // FF44 ;	0064 ;	SL	# ( d -> d ) FULLWIDTH ....
    // Three fields.  The hex fields can contain more than one character,
    //                and each character may be more than 4 digits (for supplemntals)
    // This regular expression matches lines and splits the fields into capture groups.
    RegexMatcher parseLine("(?m)^([0-9A-F]{4}[^#;]*?);([^#;]*?);([^#]*)", confusablesTxt, 0, status);
    TEST_ASSERT_SUCCESS(status);
    while (parseLine.find()) {
        UnicodeString from = parseHex(parseLine.group(1, status));
        if (!Normalizer::isNormalized(from, UNORM_NFD, status)) {
            // The source character was not NFD.
            // Skip this case; the first step in obtaining a skeleton is to NFD the input,
            //  so the mapping in this line of confusables.txt will never be applied.
            continue;
        }

        UnicodeString rawExpected = parseHex(parseLine.group(2, status));
        UnicodeString expected;
        Normalizer::decompose(rawExpected, FALSE /*NFD*/, 0, expected, status);
        TEST_ASSERT_SUCCESS(status);

        int32_t skeletonType = 0;
        UnicodeString tableType = parseLine.group(3, status);
        TEST_ASSERT_SUCCESS(status);
        if (tableType.indexOf("SL") >= 0) {
            skeletonType = USPOOF_SINGLE_SCRIPT_CONFUSABLE;
        } else if (tableType.indexOf("SA") >= 0) {
            skeletonType = USPOOF_SINGLE_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE;
        } else if (tableType.indexOf("ML") >= 0) {
            skeletonType = 0;
        } else if (tableType.indexOf("MA") >= 0) {
            skeletonType = USPOOF_ANY_CASE;
        }

        UnicodeString actual;
        uspoof_getSkeletonUnicodeString(sc.getAlias(), skeletonType, from, actual, &status);
        TEST_ASSERT_SUCCESS(status);
        TEST_ASSERT(actual == expected);
        if (actual != expected) {
            errln(parseLine.group(0, status));
            UnicodeString line = "Actual: ";
            int i = 0;
            while (i < actual.length()) {
                appendHexUChar(line, actual.char32At(i));
                i = actual.moveIndex32(i, 1);
            }
            errln(line);
        }
        if (U_FAILURE(status)) {
            break;
        }
    }
}
コード例 #22
0
ファイル: rbbiapts.cpp プロジェクト: Distrotech/icu
//
//  TestRuleStatus
//      Test word break rule status constants.
//
void RBBIAPITest::TestRuleStatus() {
     UChar str[30];
     //no longer test Han or hiragana breaking here: ruleStatusVec would return nothing
     // changed UBRK_WORD_KANA to UBRK_WORD_IDEO
     u_unescape("plain word 123.45 \\u30a1\\u30a2 ",
              // 012345678901234567  8      9    0      
              //                     Katakana      
                str, 30);
     UnicodeString testString1(str);
     int32_t bounds1[] = {0, 5, 6, 10, 11, 17, 18, 20, 21};
     int32_t tag_lo[]  = {UBRK_WORD_NONE,     UBRK_WORD_LETTER, UBRK_WORD_NONE,    UBRK_WORD_LETTER,
                          UBRK_WORD_NONE,     UBRK_WORD_NUMBER, UBRK_WORD_NONE,
                          UBRK_WORD_IDEO,     UBRK_WORD_NONE};

     int32_t tag_hi[]  = {UBRK_WORD_NONE_LIMIT, UBRK_WORD_LETTER_LIMIT, UBRK_WORD_NONE_LIMIT, UBRK_WORD_LETTER_LIMIT,
                          UBRK_WORD_NONE_LIMIT, UBRK_WORD_NUMBER_LIMIT, UBRK_WORD_NONE_LIMIT,
                          UBRK_WORD_IDEO_LIMIT, UBRK_WORD_NONE_LIMIT};

     UErrorCode status=U_ZERO_ERROR;

     BreakIterator *bi = BreakIterator::createWordInstance(Locale::getEnglish(), status);
     if(U_FAILURE(status)) {
         errcheckln(status, "Fail : in construction - %s", u_errorName(status));
     } else {
         bi->setText(testString1);
         // First test that the breaks are in the right spots.
         doBoundaryTest(*bi, testString1, bounds1);

         // Then go back and check tag values
         int32_t i = 0;
         int32_t pos, tag;
         for (pos = bi->first(); pos != BreakIterator::DONE; pos = bi->next(), i++) {
             if (pos != bounds1[i]) {
                 errln("FAIL: unexpected word break at postion %d", pos);
                 break;
             }
             tag = bi->getRuleStatus();
             if (tag < tag_lo[i] || tag >= tag_hi[i]) {
                 errln("FAIL: incorrect tag value %d at position %d", tag, pos);
                 break;
             }

             // Check that we get the same tag values from getRuleStatusVec()
             int32_t vec[10];
             int t = bi->getRuleStatusVec(vec, 10, status);
             TEST_ASSERT_SUCCESS(status);
             TEST_ASSERT(t==1);
             TEST_ASSERT(vec[0] == tag);
         }
     }
     delete bi;

     // Now test line break status.  This test mostly is to confirm that the status constants
     //                              are correctly declared in the header.
     testString1 =   "test line. \n";
     // break type    s    s     h

     bi = BreakIterator::createLineInstance(Locale::getEnglish(), status);
     if(U_FAILURE(status)) {
         errcheckln(status, "failed to create word break iterator. - %s", u_errorName(status));
     } else {
         int32_t i = 0;
         int32_t pos, tag;
         UBool   success;

         bi->setText(testString1);
         pos = bi->current();
         tag = bi->getRuleStatus();
         for (i=0; i<3; i++) {
             switch (i) {
             case 0:
                 success = pos==0  && tag==UBRK_LINE_SOFT; break;
             case 1:
                 success = pos==5  && tag==UBRK_LINE_SOFT; break;
             case 2:
                 success = pos==12 && tag==UBRK_LINE_HARD; break;
             default:
                 success = FALSE; break;
             }
             if (success == FALSE) {
                 errln("Fail: incorrect word break status or position.  i=%d, pos=%d, tag=%d",
                     i, pos, tag);
                 break;
             }
             pos = bi->next();
             tag = bi->getRuleStatus();
         }
         if (UBRK_LINE_SOFT >= UBRK_LINE_SOFT_LIMIT ||
             UBRK_LINE_HARD >= UBRK_LINE_HARD_LIMIT ||
             (UBRK_LINE_HARD > UBRK_LINE_SOFT && UBRK_LINE_HARD < UBRK_LINE_SOFT_LIMIT)) {
             errln("UBRK_LINE_* constants from header are inconsistent.");
         }
     }
     delete bi;

}
コード例 #23
0
ファイル: rbbiapts.cpp プロジェクト: Distrotech/icu
//
//  TestRuleStatusVec
//      Test the vector form of  break rule status.
//
void RBBIAPITest::TestRuleStatusVec() {
    UnicodeString rulesString(   "[A-N]{100}; \n"
                                 "[a-w]{200}; \n"
                                 "[\\p{L}]{300}; \n"
                                 "[\\p{N}]{400}; \n"
                                 "[0-5]{500}; \n"
                                  "!.*;\n", -1, US_INV);
     UnicodeString testString1  = "Aapz5?";
     int32_t  statusVals[10];
     int32_t  numStatuses;
     int32_t  pos;

     UErrorCode status=U_ZERO_ERROR;
     UParseError    parseError;

     RuleBasedBreakIterator *bi = new RuleBasedBreakIterator(rulesString, parseError, status);
     if (U_FAILURE(status)) {
         dataerrln("Failure at file %s, line %d, error = %s", __FILE__, __LINE__, u_errorName(status));
     } else {
         bi->setText(testString1);

         // A
         pos = bi->next();
         TEST_ASSERT(pos==1);
         numStatuses = bi->getRuleStatusVec(statusVals, 10, status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT(numStatuses == 2);
         TEST_ASSERT(statusVals[0] == 100);
         TEST_ASSERT(statusVals[1] == 300);

         // a
         pos = bi->next();
         TEST_ASSERT(pos==2);
         numStatuses = bi->getRuleStatusVec(statusVals, 10, status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT(numStatuses == 2);
         TEST_ASSERT(statusVals[0] == 200);
         TEST_ASSERT(statusVals[1] == 300);

         // p
         pos = bi->next();
         TEST_ASSERT(pos==3);
         numStatuses = bi->getRuleStatusVec(statusVals, 10, status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT(numStatuses == 2);
         TEST_ASSERT(statusVals[0] == 200);
         TEST_ASSERT(statusVals[1] == 300);

         // z
         pos = bi->next();
         TEST_ASSERT(pos==4);
         numStatuses = bi->getRuleStatusVec(statusVals, 10, status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT(numStatuses == 1);
         TEST_ASSERT(statusVals[0] == 300);

         // 5
         pos = bi->next();
         TEST_ASSERT(pos==5);
         numStatuses = bi->getRuleStatusVec(statusVals, 10, status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT(numStatuses == 2);
         TEST_ASSERT(statusVals[0] == 400);
         TEST_ASSERT(statusVals[1] == 500);

         // ?
         pos = bi->next();
         TEST_ASSERT(pos==6);
         numStatuses = bi->getRuleStatusVec(statusVals, 10, status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT(numStatuses == 1);
         TEST_ASSERT(statusVals[0] == 0);

         //
         //  Check buffer overflow error handling.   Char == A
         //
         bi->first();
         pos = bi->next();
         TEST_ASSERT(pos==1);
         memset(statusVals, -1, sizeof(statusVals));
         numStatuses = bi->getRuleStatusVec(statusVals, 0, status);
         TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR);
         TEST_ASSERT(numStatuses == 2);
         TEST_ASSERT(statusVals[0] == -1);

         status = U_ZERO_ERROR;
         memset(statusVals, -1, sizeof(statusVals));
         numStatuses = bi->getRuleStatusVec(statusVals, 1, status);
         TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR);
         TEST_ASSERT(numStatuses == 2);
         TEST_ASSERT(statusVals[0] == 100);
         TEST_ASSERT(statusVals[1] == -1);

         status = U_ZERO_ERROR;
         memset(statusVals, -1, sizeof(statusVals));
         numStatuses = bi->getRuleStatusVec(statusVals, 2, status);
         TEST_ASSERT_SUCCESS(status);
         TEST_ASSERT(numStatuses == 2);
         TEST_ASSERT(statusVals[0] == 100);
         TEST_ASSERT(statusVals[1] == 300);
         TEST_ASSERT(statusVals[2] == -1);
     }
     delete bi;

}
コード例 #24
0
ファイル: control_test.c プロジェクト: aukeman/sdl_game
void teardown(const char* mapping_file){
  TEST_ASSERT_SUCCESS(control__teardown());
  unlink(mapping_file);
}
コード例 #25
0
ファイル: control_test.c プロジェクト: aukeman/sdl_game
void map_directions_to_axes(){
  
  int setup_result, idx1, idx2;
  const char* mapping_file = setup(&setup_result, 
				   "0\n"
				   "up joystick 3 axis 4 0.0 1.0\n"
				   "down joystick 3 axis 4 0.0 -1.0\n"
				   "left joystick 3 axis 5 0.0 1.0\n"
				   "right joystick 3 axis 5 0.0 -1.0\n");
  TEST_ASSERT_SUCCESS(setup_result);

  for ( idx1 = 0; idx1 < 512; ++idx1 ){
    linked_list__empty( &keyboard_mappings[idx1] );
  }

  for ( idx1 = 0; idx1 < JS__MAX_JOYSTICKS; ++idx1 ){

    for ( idx2 = 0; idx2 < JS__MAX_AXES; ++idx2 ){
      
      if ( idx1 == 3 && idx2 == 4 ){

	struct linked_list__node_t* iter;
	const struct control_mapping_t* mapping = 
	  (const struct control_mapping_t*)
	  linked_list__begin(&js_axis_mappings[idx1][idx2], &iter);

	TEST_ASSERT_NOT_NULL( mapping );

	TEST_ASSERT_INT( mapping->type, ANALOG );
	TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
	TEST_ASSERT_FLOAT( mapping->max_input, 1.0f );
	
	TEST_ASSERT_NOT_NULL( control__get_state(0) );
	TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->up );

	mapping = 
	  (const struct control_mapping_t*)linked_list__next(&iter);

	TEST_ASSERT_NOT_NULL( mapping );

	TEST_ASSERT_INT( mapping->type, ANALOG );
	TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
	TEST_ASSERT_FLOAT( mapping->max_input, -1.0f );
	
	TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->down );

	mapping = 
	  (const struct control_mapping_t*)linked_list__next(&iter);

	TEST_ASSERT_NULL( mapping );
      }
      else if ( idx1 == 3 && idx2 == 5 ){

	struct linked_list__node_t* iter;
	const struct control_mapping_t* mapping = 
	  (const struct control_mapping_t*)
	  linked_list__begin(&js_axis_mappings[idx1][idx2], &iter);

	TEST_ASSERT_NOT_NULL( mapping );

	TEST_ASSERT_INT( mapping->type, ANALOG );
	TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
	TEST_ASSERT_FLOAT( mapping->max_input, 1.0f );
	
	TEST_ASSERT_NOT_NULL( control__get_state(0) );
	TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->left );

	mapping = 
	  (const struct control_mapping_t*)linked_list__next(&iter);

	TEST_ASSERT_NOT_NULL( mapping );

	TEST_ASSERT_INT( mapping->type, ANALOG );
	TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
	TEST_ASSERT_FLOAT( mapping->max_input, -1.0f );
	
	TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->right );

	mapping = 
	  (const struct control_mapping_t*)linked_list__next(&iter);

	TEST_ASSERT_NULL( mapping );
      }
      else{
	TEST_ASSERT_TRUE( linked_list__empty( &js_axis_mappings[idx1][idx2] ) );
      }
    }

    for ( idx2 = 0; idx2 < JS__MAX_BUTTONS; ++idx2 ){
      TEST_ASSERT_TRUE( linked_list__empty( &js_button_mappings[idx1][idx2] ) );
    }
  }

  teardown(mapping_file);
}
コード例 #26
0
ファイル: control_test.c プロジェクト: aukeman/sdl_game
void map_player_1_to_joystick_and_player_2_to_keyboard(){

  int setup_result = 0;
  struct linked_list__node_t* iter = NULL;
  const struct control_mapping_t* mapping = NULL;
  const char* mapping_file = setup(&setup_result, 
				   "0\n"
				   "up    joystick 0 axis    1  0.0  1.0\n"
				   "down  joystick 0 axis    1  0.0 -1.0\n"
				   "left  joystick 0 axis    0  0.0  1.0\n"
				   "right joystick 0 axis    0  0.0 -1.0\n"
				   "jump  joystick 0 button  0\n"
				   "fire  joystick 0 button  1\n"
				   "1\n"
				   "up    keyboard           273\n"
				   "down  keyboard           274\n"
				   "left  keyboard           276\n"
				   "right keyboard           275\n"
				   "jump  keyboard           306\n"
				   "fire  keyboard           32\n");
  TEST_ASSERT_SUCCESS(setup_result);

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_axis_mappings[0][1], &iter);

  TEST_ASSERT_NOT_NULL( mapping );

  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 1.0f );
	
  TEST_ASSERT_NOT_NULL( control__get_state(0) );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->up );

  mapping = (const struct control_mapping_t*)linked_list__next(&iter);

  TEST_ASSERT_NOT_NULL( mapping );

  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, -1.0f );
	
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->down );

  mapping = (const struct control_mapping_t*)linked_list__next(&iter);

  TEST_ASSERT_NULL( mapping );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_axis_mappings[0][0], &iter);

  TEST_ASSERT_NOT_NULL( mapping );

  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 1.0f );
	
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->left );

  mapping = 
    (const struct control_mapping_t*)linked_list__next(&iter);

  TEST_ASSERT_NOT_NULL( mapping );

  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, -1.0f );
	
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(0)->right );

  mapping = 
    (const struct control_mapping_t*)linked_list__next(&iter);

  TEST_ASSERT_NULL( mapping );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[0][0], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, BINARY );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.binary, &control__get_state(0)->jump );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[0][1], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, BINARY );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.binary, &control__get_state(0)->fire );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_UP], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_NOT_NULL( control__get_state(1) );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->up );

  TEST_ASSERT_NULL( linked_list__next(&iter) );


  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_DOWN], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->down );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_LEFT], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->left );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_RIGHT], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->right );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[306], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, BINARY );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.binary, &control__get_state(1)->jump );

  TEST_ASSERT_NULL( linked_list__next(&iter) );


  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[32], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, BINARY );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.binary, &control__get_state(1)->fire );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  teardown(mapping_file);
}
コード例 #27
0
ファイル: spooftest.c プロジェクト: icu-project/icu4c
/*
 *   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
    */
    TEST_SETUP
    int32_t        serializedSize = 0;
    int32_t        actualLength = 0;
    char           *buf;
    USpoofChecker  *sc2;
    int32_t         checkResults;


    serializedSize = uspoof_serialize(sc, NULL, 0, &status);
    TEST_ASSERT_EQ(status, U_BUFFER_OVERFLOW_ERROR);
    TEST_ASSERT(serializedSize > 0);

    /* Serialize the default spoof checker */
    status = U_ZERO_ERROR;
    buf = (char *)malloc(serializedSize + 10);
    TEST_ASSERT(buf != NULL);
    buf[serializedSize] = 42;
    uspoof_serialize(sc, buf, serializedSize, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(42, buf[serializedSize]);

    /* Create a new spoof checker from the freshly serialized data */
    sc2 = uspoof_openFromSerialized(buf, serializedSize+10, &actualLength, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_NE(NULL, sc2);
    TEST_ASSERT_EQ(serializedSize, actualLength);

    /* Verify that the new spoof checker at least wiggles */
    checkResults = uspoof_check(sc2, goodLatin, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);

    checkResults = uspoof_check(sc2, scMixed, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);

    uspoof_close(sc2);
    free(buf);
    TEST_TEARDOWN;



    /*
     * Set & Get Check Flags
    */
    TEST_SETUP
    int32_t t;
    uspoof_setChecks(sc, USPOOF_ALL_CHECKS, &status);
    TEST_ASSERT_SUCCESS(status);
    t = uspoof_getChecks(sc, &status);
    TEST_ASSERT_EQ(t, USPOOF_ALL_CHECKS);

    uspoof_setChecks(sc, 0, &status);
    TEST_ASSERT_SUCCESS(status);
    t = uspoof_getChecks(sc, &status);
    TEST_ASSERT_EQ(0, t);

    uspoof_setChecks(sc,
                     USPOOF_WHOLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE,
                     &status);
    TEST_ASSERT_SUCCESS(status);
    t = uspoof_getChecks(sc, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_WHOLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_ANY_CASE, t);
    TEST_TEARDOWN;

    /*
    * get & setAllowedChars
    */
    TEST_SETUP
    USet *us;
    const USet *uset;

    uset = uspoof_getAllowedChars(sc, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT(uset_isFrozen(uset));
    us = uset_open((UChar32)0x41, (UChar32)0x5A);   /*  [A-Z]  */
    uspoof_setAllowedChars(sc, us, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_NE(us, uspoof_getAllowedChars(sc, &status));
    TEST_ASSERT(uset_equals(us, uspoof_getAllowedChars(sc, &status)));
    TEST_ASSERT_SUCCESS(status);
    uset_close(us);
    TEST_TEARDOWN;

    /*
    *  clone()
    */

    TEST_SETUP
    USpoofChecker *clone1 = NULL;
    USpoofChecker *clone2 = NULL;
    int32_t        checkResults = 0;

    clone1 = uspoof_clone(sc, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_NE(clone1, sc);

    clone2 = uspoof_clone(clone1, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_NE(clone2, clone1);

    uspoof_close(clone1);

    /* Verify that the cloned spoof checker is alive */
    checkResults = uspoof_check(clone2, goodLatin, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);

    checkResults = uspoof_check(clone2, scMixed, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);
    uspoof_close(clone2);
    TEST_TEARDOWN;

    /*
    *  basic uspoof_check()
    */
    TEST_SETUP
    int32_t result;
    result = uspoof_check(sc, goodLatin, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, result);

    result = uspoof_check(sc, han_Hiragana, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, result);

    result = uspoof_check(sc, scMixed, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE, result);
    TEST_TEARDOWN


    /*
     *  get & set Checks
    */
    TEST_SETUP
    int32_t   checks;
    int32_t   checks2;
    int32_t   checkResults;

    checks = uspoof_getChecks(sc, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_ALL_CHECKS, checks);

    checks &= ~(USPOOF_SINGLE_SCRIPT | USPOOF_MIXED_SCRIPT_CONFUSABLE);
    uspoof_setChecks(sc, checks, &status);
    TEST_ASSERT_SUCCESS(status);
    checks2 = uspoof_getChecks(sc, &status);
    TEST_ASSERT_EQ(checks, checks2);

    /* The checks that were disabled just above are the same ones that the "scMixed" test fails.
        So with those tests gone checking that Identifier should now succeed */
    checkResults = uspoof_check(sc, scMixed, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);
    TEST_TEARDOWN;

    /*
     *  AllowedLoacles
     */

    TEST_SETUP
    const char  *allowedLocales;
    int32_t  checkResults;

    /* Default allowed locales list should be empty */
    allowedLocales = uspoof_getAllowedLocales(sc, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT(strcmp("", allowedLocales) == 0)

    /* Allow en and ru, which should enable Latin and Cyrillic only to pass */
    uspoof_setAllowedLocales(sc, "en, ru_RU", &status);
    TEST_ASSERT_SUCCESS(status);
    allowedLocales = uspoof_getAllowedLocales(sc, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT(strstr(allowedLocales, "en") != NULL);
    TEST_ASSERT(strstr(allowedLocales, "ru") != NULL);

    /* Limit checks to USPOOF_CHAR_LIMIT.  Some of the test data has whole script confusables also,
     * which we don't want to see in this test. */
    uspoof_setChecks(sc, USPOOF_CHAR_LIMIT, &status);
    TEST_ASSERT_SUCCESS(status);

    checkResults = uspoof_check(sc, goodLatin, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);

    checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_CHAR_LIMIT, checkResults);

    checkResults = uspoof_check(sc, goodCyrl, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);

    /* Reset with an empty locale list, which should allow all characters to pass */
    uspoof_setAllowedLocales(sc, " ", &status);
    TEST_ASSERT_SUCCESS(status);

    checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);
    TEST_TEARDOWN;

    /*
     * AllowedChars   set/get the USet of allowed characters.
     */
    TEST_SETUP
    const USet  *set;
    USet        *tmpSet;
    int32_t      checkResults;

    /* By default, we should see no restriction; the USet should allow all characters. */
    set = uspoof_getAllowedChars(sc, &status);
    TEST_ASSERT_SUCCESS(status);
    tmpSet = uset_open(0, 0x10ffff);
    TEST_ASSERT(uset_equals(tmpSet, set));

    /* Setting the allowed chars should enable the check. */
    uspoof_setChecks(sc, USPOOF_ALL_CHECKS & ~USPOOF_CHAR_LIMIT, &status);
    TEST_ASSERT_SUCCESS(status);

    /* Remove a character that is in our good Latin test identifier from the allowed chars set. */
    uset_remove(tmpSet, goodLatin[1]);
    uspoof_setAllowedChars(sc, tmpSet, &status);
    TEST_ASSERT_SUCCESS(status);
    uset_close(tmpSet);

    /* Latin Identifier should now fail; other non-latin test cases should still be OK
     *  Note: fail of CHAR_LIMIT also causes the restriction level to be USPOOF_UNRESTRICTIVE
     *        which will give us a USPOOF_RESTRICTION_LEVEL failure.
     */
    checkResults = uspoof_check(sc, goodLatin, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_CHAR_LIMIT | USPOOF_RESTRICTION_LEVEL, checkResults);

    checkResults = uspoof_check(sc, goodGreek, -1, NULL, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_WHOLE_SCRIPT_CONFUSABLE, checkResults);
    TEST_TEARDOWN;

    /*
     * check UTF-8
     */
    TEST_SETUP
    char    utf8buf[200];
    int32_t checkResults;
    int32_t position;

    u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, goodLatin, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    position = 666;
    checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);
    TEST_ASSERT_EQ(0, position);

    u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, goodCyrl, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);

    u_strToUTF8(utf8buf, sizeof(utf8buf), NULL, scMixed, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    position = 666;
    checkResults = uspoof_checkUTF8(sc, utf8buf, -1, &position, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_SINGLE_SCRIPT , checkResults);
    TEST_ASSERT_EQ(0, position);

    TEST_TEARDOWN;

    /*
     * uspoof_areConfusable()
     */
    TEST_SETUP
    int32_t  checkResults;

    checkResults = uspoof_areConfusable(sc, scLatin, -1, scMixed, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);

    checkResults = uspoof_areConfusable(sc, goodGreek, -1, scLatin, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);

    checkResults = uspoof_areConfusable(sc, lll_Latin_a, -1, lll_Latin_b, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT_CONFUSABLE, checkResults);

    TEST_TEARDOWN;

    /*
     * areConfusableUTF8
     */
    TEST_SETUP
    int32_t checkResults;
    char s1[200];
    char s2[200];


    u_strToUTF8(s1, sizeof(s1), NULL, scLatin, -1, &status);
    u_strToUTF8(s2, sizeof(s2), NULL, scMixed, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_MIXED_SCRIPT_CONFUSABLE, checkResults);

    u_strToUTF8(s1, sizeof(s1), NULL, goodGreek, -1, &status);
    u_strToUTF8(s2, sizeof(s2), NULL, scLatin, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, checkResults);

    u_strToUTF8(s1, sizeof(s1), NULL, lll_Latin_a, -1, &status);
    u_strToUTF8(s2, sizeof(s2), NULL, lll_Latin_b, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    checkResults = uspoof_areConfusableUTF8(sc, s1, -1, s2, -1, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(USPOOF_SINGLE_SCRIPT_CONFUSABLE, checkResults);

    TEST_TEARDOWN;


    /*
     * getSkeleton
     */

    TEST_SETUP
    UChar dest[100];
    int32_t   skelLength;

    skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, dest, UPRV_LENGTHOF(dest), &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(0, u_strcmp(lll_Skel, dest));
    TEST_ASSERT_EQ(u_strlen(lll_Skel), skelLength);

    skelLength = uspoof_getSkeletonUTF8(sc, USPOOF_ANY_CASE, goodLatinUTF8, -1, (char*)dest,
                                        UPRV_LENGTHOF(dest), &status);
    TEST_ASSERT_SUCCESS(status);

    skelLength = uspoof_getSkeleton(sc, USPOOF_ANY_CASE, lll_Latin_a, -1, NULL, 0, &status);
    TEST_ASSERT_EQ(U_BUFFER_OVERFLOW_ERROR, status);
    TEST_ASSERT_EQ(3, skelLength);
    status = U_ZERO_ERROR;

    TEST_TEARDOWN;

    /*
     * get Inclusion and Recommended sets
     */
    TEST_SETUP
    const USet *inclusions = NULL;
    const USet *recommended = NULL;

    inclusions = uspoof_getInclusionSet(&status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(TRUE, uset_isFrozen(inclusions));

    status = U_ZERO_ERROR;
    recommended = uspoof_getRecommendedSet(&status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_EQ(TRUE, uset_isFrozen(recommended));
    TEST_TEARDOWN;

}
コード例 #28
0
ファイル: control_test.c プロジェクト: aukeman/sdl_game
void map_directions_to_buttons(){
  
  int setup_result = 0;
  struct linked_list__node_t* iter = NULL;
  const struct control_mapping_t* mapping = NULL;
  const char* mapping_file = setup(&setup_result, 
				   "1\n"
				   "up joystick 4 button 10\n"
				   "down joystick 4 button 11\n"
				   "left joystick 4 button 12\n"
				   "right joystick 4 button 13\n");

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[4][10], &iter);


  TEST_ASSERT_SUCCESS(setup_result);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_NOT_NULL( control__get_state(1) );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->up );

  TEST_ASSERT_NULL( linked_list__next(&iter) );


  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[4][11], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->down );

  TEST_ASSERT_NULL( linked_list__next(&iter) );


  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[4][12], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->left );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&js_button_mappings[4][13], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->right );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  teardown(mapping_file);
}
コード例 #29
0
ファイル: ssearch.cpp プロジェクト: Distrotech/icu
//
//  searchTime()    A quick and dirty performance test for string search.
//                  Probably  doesn't really belong as part of intltest, but it
//                  does check that the search succeeds, and gets the right result,
//                  so it serves as a functionality test also.
//
//                  To run as a perf test, up the loop count, select by commenting
//                  and uncommenting in the code the operation to be measured,
//                  rebuild, and measure the running time of this test alone.
//
//                     time LD_LIBRARY_PATH=whatever  ./intltest  collate/SSearchTest/searchTime
//
void SSearchTest::searchTime() {
    static const char *longishText =
"Whylom, as olde stories tellen us,\n"
"Ther was a duk that highte Theseus:\n"
"Of Athenes he was lord and governour,\n"
"And in his tyme swich a conquerour,\n"
"That gretter was ther noon under the sonne.\n"
"Ful many a riche contree hadde he wonne;\n"
"What with his wisdom and his chivalrye,\n"
"He conquered al the regne of Femenye,\n"
"That whylom was y-cleped Scithia;\n"
"And weddede the quene Ipolita,\n"
"And broghte hir hoom with him in his contree\n"
"With muchel glorie and greet solempnitee,\n"
"And eek hir yonge suster Emelye.\n"
"And thus with victorie and with melodye\n"
"Lete I this noble duk to Athenes ryde,\n"
"And al his hoost, in armes, him bisyde.\n"
"And certes, if it nere to long to here,\n"
"I wolde han told yow fully the manere,\n"
"How wonnen was the regne of Femenye\n"
"By Theseus, and by his chivalrye;\n"
"And of the grete bataille for the nones\n"
"Bitwixen Athen's and Amazones;\n"
"And how asseged was Ipolita,\n"
"The faire hardy quene of Scithia;\n"
"And of the feste that was at hir weddinge,\n"
"And of the tempest at hir hoom-cominge;\n"
"But al that thing I moot as now forbere.\n"
"I have, God woot, a large feeld to ere,\n"
"And wayke been the oxen in my plough.\n"
"The remenant of the tale is long y-nough.\n"
"I wol nat letten eek noon of this route;\n"
"Lat every felawe telle his tale aboute,\n"
"And lat see now who shal the soper winne;\n"
"And ther I lefte, I wol ageyn biginne.\n"
"This duk, of whom I make mencioun,\n"
"When he was come almost unto the toun,\n"
"In al his wele and in his moste pryde,\n"
"He was war, as he caste his eye asyde,\n"
"Wher that ther kneled in the hye weye\n"
"A companye of ladies, tweye and tweye,\n"
"Ech after other, clad in clothes blake; \n"
"But swich a cry and swich a wo they make,\n"
"That in this world nis creature livinge,\n"
"That herde swich another weymentinge;\n"
"And of this cry they nolde never stenten,\n"
"Til they the reynes of his brydel henten.\n"
"'What folk ben ye, that at myn hoomcominge\n"
"Perturben so my feste with cryinge'?\n"
"Quod Theseus, 'have ye so greet envye\n"
"Of myn honour, that thus compleyne and crye? \n"
"Or who hath yow misboden, or offended?\n"
"And telleth me if it may been amended;\n"
"And why that ye ben clothed thus in blak'?\n"
"The eldest lady of hem alle spak,\n"
"When she hadde swowned with a deedly chere,\n"
"That it was routhe for to seen and here,\n"
"And seyde: 'Lord, to whom Fortune hath yiven\n"
"Victorie, and as a conquerour to liven,\n"
"Noght greveth us your glorie and your honour;\n"
"But we biseken mercy and socour.\n"
"Have mercy on our wo and our distresse.\n"
"Som drope of pitee, thurgh thy gentilesse,\n"
"Up-on us wrecched wommen lat thou falle.\n"
"For certes, lord, ther nis noon of us alle,\n"
"That she nath been a duchesse or a quene;\n"
"Now be we caitifs, as it is wel sene:\n"
"Thanked be Fortune, and hir false wheel,\n"
"That noon estat assureth to be weel.\n"
"And certes, lord, t'abyden your presence,\n"
"Here in the temple of the goddesse Clemence\n"
"We han ben waytinge al this fourtenight;\n"
"Now help us, lord, sith it is in thy might.\n"
"I wrecche, which that wepe and waille thus,\n"
"Was whylom wyf to king Capaneus,\n"
"That starf at Thebes, cursed be that day!\n"
"And alle we, that been in this array,\n"
"And maken al this lamentacioun,\n"
"We losten alle our housbondes at that toun,\n"
"Whyl that the sege ther-aboute lay.\n"
"And yet now th'olde Creon, weylaway!\n"
"The lord is now of Thebes the citee, \n"
"Fulfild of ire and of iniquitee,\n"
"He, for despyt, and for his tirannye,\n"
"To do the dede bodyes vileinye,\n"
"Of alle our lordes, whiche that ben slawe,\n"
"Hath alle the bodyes on an heep y-drawe,\n"
"And wol nat suffren hem, by noon assent,\n"
"Neither to been y-buried nor y-brent,\n"
"But maketh houndes ete hem in despyt. zet'\n";

const char *cPattern = "maketh houndes ete hem";
//const char *cPattern = "Whylom";
//const char *cPattern = "zet";
    const char *testId = "searchTime()";   // for error macros.
    UnicodeString target = longishText;
    UErrorCode status = U_ZERO_ERROR;


    LocalUCollatorPointer collator(ucol_open("en", &status));
    //ucol_setStrength(collator.getAlias(), collatorStrength);
    //ucol_setAttribute(collator.getAlias(), UCOL_NORMALIZATION_MODE, normalize, &status);
    UnicodeString uPattern = cPattern;
    LocalUStringSearchPointer uss(usearch_openFromCollator(uPattern.getBuffer(), uPattern.length(),
                                                           target.getBuffer(), target.length(),
                                                           collator.getAlias(),
                                                           NULL,     // the break iterator
                                                           &status));
    TEST_ASSERT_SUCCESS(status);

//  int32_t foundStart;
//  int32_t foundEnd;
    UBool   found;

    // Find the match position usgin strstr
    const char *pm = strstr(longishText, cPattern);
    TEST_ASSERT_M(pm!=NULL, "No pattern match with strstr");
    int32_t  refMatchPos = (int32_t)(pm - longishText);
    int32_t  icuMatchPos;
    int32_t  icuMatchEnd;
    usearch_search(uss.getAlias(), 0, &icuMatchPos, &icuMatchEnd, &status);
    TEST_ASSERT_SUCCESS(status);
    TEST_ASSERT_M(refMatchPos == icuMatchPos, "strstr and icu give different match positions.");

    int32_t i;
    // int32_t j=0;

    // Try loopcounts around 100000 to some millions, depending on the operation,
    //   to get runtimes of at least several seconds.
    for (i=0; i<10000; i++) {
        found = usearch_search(uss.getAlias(), 0, &icuMatchPos, &icuMatchEnd, &status);
        (void)found;   // Suppress set but not used warning.
        //TEST_ASSERT_SUCCESS(status);
        //TEST_ASSERT(found);

        // usearch_setOffset(uss.getAlias(), 0, &status);
        // icuMatchPos = usearch_next(uss.getAlias(), &status);

         // The i+j stuff is to confuse the optimizer and get it to actually leave the
         //   call to strstr in place.
         //pm = strstr(longishText+j, cPattern);
         //j = (j + i)%5;
    }

    //printf("%ld, %d\n", pm-longishText, j);
}
コード例 #30
0
ファイル: control_test.c プロジェクト: aukeman/sdl_game
void map_directions_to_keys(){
  
  int setup_result = 0;
  struct linked_list__node_t* iter = NULL;
  const struct control_mapping_t* mapping = NULL;
  const char* mapping_file = setup(&setup_result, 
				   "1\n"
				   "up keyboard 273\n"
				   "down keyboard 274\n"
				   "left keyboard 276\n"
				   "right keyboard 275\n");
  TEST_ASSERT_SUCCESS(setup_result);

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_UP], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_NOT_NULL( control__get_state(1) );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->up );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_DOWN], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->down );

  TEST_ASSERT_NULL( linked_list__next(&iter) );


  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_LEFT], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->left );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  mapping = 
    (const struct control_mapping_t*)
    linked_list__begin(&keyboard_mappings[EVENTS__KEY_RIGHT], &iter);

  TEST_ASSERT_NOT_NULL( mapping );
  TEST_ASSERT_INT( mapping->type, ANALOG );
  TEST_ASSERT_FLOAT( mapping->min_input, 0.0f );
  TEST_ASSERT_FLOAT( mapping->max_input, 0.0f );
  TEST_ASSERT_PTR( mapping->control_type.analog, &control__get_state(1)->right );

  TEST_ASSERT_NULL( linked_list__next(&iter) );

  teardown(mapping_file);
}