mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
Implements a pattern scanning feature that allows searching for byte patterns within a byte range. Adds `scan_for_pattern` method to `PatternScanner` to locate a pattern within a byte span. Adds corner case tests to verify functionality and handle invalid inputs.
54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
//
|
|
// Created by Vlad on 10/4/2025.
|
|
//
|
|
#include "gtest/gtest.h"
|
|
#include <omath/utility/pattern_scan.hpp>
|
|
#include <source_location>
|
|
|
|
|
|
TEST(unit_test_pattern_scan, read_test)
|
|
{
|
|
const auto result = omath::PatternScanner::parse_pattern("FF ? ?? E9");
|
|
|
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
|
EXPECT_EQ(result->at(1), std::nullopt);
|
|
EXPECT_EQ(result->at(2), std::nullopt);
|
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
|
}
|
|
|
|
TEST(unit_test_pattern_scan, corner_case_1)
|
|
{
|
|
const auto result = omath::PatternScanner::parse_pattern(" FF ? ?? E9");
|
|
|
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
|
EXPECT_EQ(result->at(1), std::nullopt);
|
|
EXPECT_EQ(result->at(2), std::nullopt);
|
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
|
}
|
|
|
|
TEST(unit_test_pattern_scan, corner_case_2)
|
|
{
|
|
const auto result = omath::PatternScanner::parse_pattern(" FF ? ?? E9 ");
|
|
|
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
|
EXPECT_EQ(result->at(1), std::nullopt);
|
|
EXPECT_EQ(result->at(2), std::nullopt);
|
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
|
}
|
|
|
|
TEST(unit_test_pattern_scan, corner_case_3)
|
|
{
|
|
const auto result = omath::PatternScanner::parse_pattern(" FF ? ?? E9 ");
|
|
|
|
EXPECT_EQ(result->at(0), static_cast<std::byte>(0xFF));
|
|
EXPECT_EQ(result->at(1), std::nullopt);
|
|
EXPECT_EQ(result->at(2), std::nullopt);
|
|
EXPECT_EQ(result->at(3), static_cast<std::byte>(0xE9));
|
|
}
|
|
|
|
TEST(unit_test_pattern_scan, corner_case_4)
|
|
{
|
|
const auto result = omath::PatternScanner::parse_pattern("X ? ?? E9 ");
|
|
|
|
EXPECT_FALSE(result.has_value());
|
|
} |