mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-22549 Add Normalizer2 Fuzzer
ICU-22549 Remove unnecessary include files
This commit is contained in:
parent
e76094c55a
commit
77759422dd
2 changed files with 80 additions and 0 deletions
|
@ -41,6 +41,7 @@ FUZZER_TARGETS = \
|
|||
date_time_pattern_generator_fuzzer \
|
||||
list_format_fuzzer locale_fuzzer \
|
||||
locale_morph_fuzzer \
|
||||
normalizer2_fuzzer \
|
||||
number_format_fuzzer \
|
||||
number_formatter_fuzzer \
|
||||
relative_date_time_formatter_fuzzer \
|
||||
|
|
79
icu4c/source/test/fuzzer/normalizer2_fuzzer.cpp
Normal file
79
icu4c/source/test/fuzzer/normalizer2_fuzzer.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
// © 2023 and later: Unicode, Inc. and others.
|
||||
// License & terms of use: http://www.unicode.org/copyright.html
|
||||
|
||||
// Fuzzer for ICU Calendar.
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "unicode/normalizer2.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
uint16_t rnd;
|
||||
UChar32 char1, char2;
|
||||
if (size < sizeof(rnd) + sizeof(char1) + sizeof(char2)) return 0;
|
||||
icu::StringPiece fuzzData(reinterpret_cast<const char *>(data), size);
|
||||
|
||||
std::memcpy(&rnd, fuzzData.data(), sizeof(rnd));
|
||||
fuzzData.remove_prefix(sizeof(rnd));
|
||||
std::memcpy(&char1, fuzzData.data(), sizeof(char1));
|
||||
fuzzData.remove_prefix(sizeof(char1));
|
||||
std::memcpy(&char2, fuzzData.data(), sizeof(char2));
|
||||
fuzzData.remove_prefix(sizeof(char2));
|
||||
|
||||
size_t len = fuzzData.size() / sizeof(char16_t);
|
||||
icu::UnicodeString text(false, reinterpret_cast<const char16_t*>(fuzzData.data()), len);
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const icu::Normalizer2* norm = nullptr;
|
||||
switch (rnd % 6) {
|
||||
case 0:
|
||||
norm = icu::Normalizer2::getNFCInstance(status);
|
||||
break;
|
||||
case 1:
|
||||
norm = icu::Normalizer2::getNFDInstance(status);
|
||||
break;
|
||||
case 2:
|
||||
norm = icu::Normalizer2::getNFKCInstance(status);
|
||||
break;
|
||||
case 3:
|
||||
norm = icu::Normalizer2::getNFKDInstance(status);
|
||||
break;
|
||||
case 4:
|
||||
norm = icu::Normalizer2::getNFKCCasefoldInstance(status);
|
||||
break;
|
||||
case 5:
|
||||
norm = icu::Normalizer2::getNFKCSimpleCasefoldInstance(status);
|
||||
break;
|
||||
}
|
||||
if (U_SUCCESS(status)) {
|
||||
norm->normalize(text, status);
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
icu::UnicodeString out;
|
||||
|
||||
norm->normalize(text, out, status);
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
norm->normalizeSecondAndAppend(out, text, status);
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
norm->append(out, text, status);
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
norm->getDecomposition(char1, out);
|
||||
norm->getRawDecomposition(char1, out);
|
||||
norm->composePair(char1, char2);
|
||||
norm->getCombiningClass(char1);
|
||||
norm->isNormalized(text, status);
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
norm->quickCheck(text, status);
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
norm->hasBoundaryBefore(char1);
|
||||
norm->hasBoundaryAfter(char1);
|
||||
norm->isInert(char1);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Reference in a new issue