static void test_utf8proc_normalization(TestBatchRunner *runner) { SKIP(runner, 1, "utf8proc can't handle control chars or Unicode non-chars"); return; for (int32_t i = 0; i < 100; i++) { String *source = TestUtils_random_string(rand() % 40); // Normalize once. uint8_t *normalized; int32_t check = utf8proc_map((const uint8_t*)Str_Get_Ptr8(source), Str_Get_Size(source), &normalized, UTF8PROC_STABLE | UTF8PROC_COMPOSE | UTF8PROC_COMPAT | UTF8PROC_CASEFOLD); if (check < 0) { lucy_Json_set_tolerant(1); String *json = lucy_Json_to_json((Obj*)source); if (!json) { json = Str_newf("[failed to encode]"); } FAIL(runner, "Failed to normalize: %s", Str_Get_Ptr8(json)); DECREF(json); DECREF(source); return; } // Normalize again. size_t normalized_len = strlen((char*)normalized); uint8_t *dupe; int32_t dupe_check = utf8proc_map(normalized, normalized_len, &dupe, UTF8PROC_STABLE | UTF8PROC_COMPOSE | UTF8PROC_COMPAT | UTF8PROC_CASEFOLD); if (dupe_check < 0) { THROW(ERR, "Unexpected normalization error: %i32", dupe_check); } int comparison = strcmp((char*)normalized, (char*)dupe); free(dupe); free(normalized); DECREF(source); if (comparison != 0) { FAIL(runner, "Not fully normalized"); return; } } PASS(runner, "Normalization successful."); }
static void test_stress(TestBatch *batch) { Hash *hash = Hash_new(0); // trigger multiple rebuilds. VArray *expected = VA_new(1000); VArray *keys; VArray *values; for (uint32_t i = 0; i < 1000; i++) { CharBuf *cb = TestUtils_random_string(rand() % 1200); while (Hash_Fetch(hash, (Obj*)cb)) { DECREF(cb); cb = TestUtils_random_string(rand() % 1200); } Hash_Store(hash, (Obj*)cb, (Obj*)cb); VA_Push(expected, INCREF(cb)); } VA_Sort(expected, NULL, NULL); // Overwrite for good measure. for (uint32_t i = 0; i < 1000; i++) { CharBuf *cb = (CharBuf*)VA_Fetch(expected, i); Hash_Store(hash, (Obj*)cb, INCREF(cb)); } keys = Hash_Keys(hash); values = Hash_Values(hash); VA_Sort(keys, NULL, NULL); VA_Sort(values, NULL, NULL); TEST_TRUE(batch, VA_Equals(keys, (Obj*)expected), "stress Keys"); TEST_TRUE(batch, VA_Equals(values, (Obj*)expected), "stress Values"); DECREF(keys); DECREF(values); DECREF(expected); DECREF(hash); }