Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: fuzzers/fuzzer_utils.h

Issue 1995823002: [libfuzzer] moving icu fuzzers to //third_party/icu, additional fuzzers. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fuzzers/BUILD.gn ('k') | fuzzers/icu_break_iterator_fuzzer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2
3 #ifndef THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_
4 #define THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_
5
6 #include <assert.h>
7 #include <random>
8 #include "base/at_exit.h"
9 #include "base/i18n/icu_util.h"
10 #include "third_party/icu/source/common/unicode/locid.h"
11
12 struct IcuEnvironment {
13 IcuEnvironment() {
14 base::i18n::InitializeICU();
15 }
16 };
17
18 // Create RNG and seed it from data.
19 std::mt19937_64 CreateRng(const uint8_t* data, size_t size) {
20 std::mt19937_64 rng;
21 std::string str = std::string(reinterpret_cast<const char*>(data), size);
22 std::size_t data_hash = std::hash<std::string>()(str);
23 rng.seed(data_hash);
24 return rng;
25 }
26
27 const icu::Locale& GetRandomLocale(std::mt19937_64* rng) {
28 int32_t num_locales;
29 assert(num_locales > 0);
30 const icu::Locale* locales = icu::Locale::getAvailableLocales(num_locales);
31 return locales[(*rng)() % num_locales];
32 }
33
34 #endif // THIRD_PARTY_ICU_FUZZERS_FUZZER_UTILS_H_
OLDNEW
« no previous file with comments | « fuzzers/BUILD.gn ('k') | fuzzers/icu_break_iterator_fuzzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698