-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d0bd6d
commit 31e713a
Showing
3 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,6 @@ | ||
|
||
#include "../webpp/unicode/normalization.hpp" | ||
#include "common/fuzz_common.hpp" | ||
|
||
// NOLINTBEGIN(*-pro-type-reinterpret-cast) | ||
void unicode_fuzz(std::string_view data) { | ||
using webpp::unicode::toNFC; | ||
#include "./unicode_fuzz.hpp" | ||
|
||
std::string const str{data.data(), data.size()}; | ||
std::u8string const str8{reinterpret_cast<char8_t const*>(data.data()), data.size()}; | ||
std::u16string const str16{reinterpret_cast<char16_t const*>(data.data()), data.size() / 2}; | ||
std::u32string const str32{reinterpret_cast<char32_t const*>(data.data()), data.size() / 4}; | ||
auto const res = toNFC<std::string>(str); | ||
auto const res8 = toNFC<std::u8string>(str8); | ||
auto const res16 = toNFC<std::u16string>(str16); | ||
auto const res32 = toNFC<std::u32string>(str32); | ||
if (!str8.empty()) { | ||
ASSERT_NE(str8.size(), 0); | ||
ASSERT_NE(str16.size(), 0); | ||
ASSERT_NE(str32.size(), 0); | ||
ASSERT_NE(str.size(), 0); | ||
ASSERT_NE(res.size(), 0); | ||
ASSERT_NE(res16.size(), 0); | ||
ASSERT_NE(res8.size(), 0); | ||
ASSERT_NE(res32.size(), 0); | ||
} | ||
} | ||
|
||
// NOLINTEND(*-pro-type-reinterpret-cast) | ||
#include "common/fuzz_common.hpp" | ||
|
||
register_fuzz(unicode_fuzz); | ||
register_fuzz(webpp::tests::unicode_fuzz); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Created by moisrex on 12/23/24. | ||
|
||
#ifndef UNICODE_FUZZ_HPP | ||
#define UNICODE_FUZZ_HPP | ||
|
||
#include "../webpp/unicode/normalization.hpp" | ||
#include "./common/tests_common_pch.hpp" | ||
|
||
namespace webpp::tests { | ||
// NOLINTBEGIN(*-pro-type-reinterpret-cast) | ||
static void unicode_fuzz(std::string_view data) { | ||
using webpp::unicode::toNFC; | ||
|
||
auto const length = data.size(); | ||
auto const* const ptr = data.data(); | ||
|
||
std::string const str{ptr, length}; | ||
std::u8string const str8{reinterpret_cast<char8_t const*>(ptr), length}; | ||
std::u16string str16; | ||
std::u32string str32; | ||
if (length / 2 != 0) { | ||
str16 = std::u16string{reinterpret_cast<char16_t const*>(ptr), length / 2}; | ||
} | ||
if (length / 4 != 0) { | ||
str32 = std::u32string{reinterpret_cast<char32_t const*>(ptr), length / 4}; | ||
} | ||
auto const res = toNFC<std::string>(str); | ||
auto const res8 = toNFC<std::u8string>(str8); | ||
auto const res16 = toNFC<std::u16string>(str16); | ||
auto const res32 = toNFC<std::u32string>(str32); | ||
if (!str8.empty()) { | ||
ASSERT_NE(str8.size(), 0); | ||
if (length / 2 != 0) { | ||
ASSERT_NE(str16.size(), 0); | ||
ASSERT_NE(res16.size(), 0); | ||
} | ||
if (length / 4 != 0) { | ||
ASSERT_NE(str32.size(), 0); | ||
ASSERT_NE(res32.size(), 0); | ||
} | ||
ASSERT_NE(str.size(), 0); | ||
ASSERT_NE(res.size(), 0); | ||
ASSERT_NE(res8.size(), 0); | ||
} | ||
} | ||
} // namespace webpp::tests | ||
|
||
// NOLINTEND(*-pro-type-reinterpret-cast) | ||
|
||
|
||
#endif // UNICODE_FUZZ_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters