[FIX]: Window Build Fix

This commit is contained in:
2026-01-26 22:55:39 +05:30
parent fac013d63f
commit 21a474b6f9
75 changed files with 5430 additions and 4643 deletions

View File

@ -20,18 +20,24 @@
using namespace IACore;
struct SchedulerGuard {
SchedulerGuard(u8 worker_count = 2) {
struct SchedulerGuard
{
SchedulerGuard(u8 worker_count = 2)
{
(void)AsyncOps::initialize_scheduler(worker_count);
(void) AsyncOps::initialize_scheduler(worker_count);
}
~SchedulerGuard() { AsyncOps::terminate_scheduler(); }
~SchedulerGuard()
{
AsyncOps::terminate_scheduler();
}
};
IAT_BEGIN_BLOCK(Core, AsyncOps)
auto test_initialization() -> bool {
auto test_initialization() -> bool
{
AsyncOps::terminate_scheduler();
@ -50,14 +56,14 @@ auto test_initialization() -> bool {
return true;
}
auto test_basic_execution() -> bool {
auto test_basic_execution() -> bool
{
SchedulerGuard guard(2);
AsyncOps::Schedule schedule;
std::atomic<i32> run_count{0};
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { run_count++; }, 0,
&schedule);
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { run_count++; }, 0, &schedule);
AsyncOps::wait_for_schedule_completion(&schedule);
@ -66,14 +72,16 @@ auto test_basic_execution() -> bool {
return true;
}
auto test_concurrency() -> bool {
auto test_concurrency() -> bool
{
SchedulerGuard guard(4);
AsyncOps::Schedule schedule;
std::atomic<i32> run_count{0};
const i32 total_tasks = 100;
for (i32 i = 0; i < total_tasks; ++i) {
for (i32 i = 0; i < total_tasks; ++i)
{
AsyncOps::schedule_task(
[&](AsyncOps::WorkerId) {
std::this_thread::sleep_for(std::chrono::microseconds(10));
@ -89,17 +97,16 @@ auto test_concurrency() -> bool {
return true;
}
auto test_priorities() -> bool {
auto test_priorities() -> bool
{
SchedulerGuard guard(2);
AsyncOps::Schedule schedule;
std::atomic<i32> high_priority_ran{0};
std::atomic<i32> normal_priority_ran{0};
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { high_priority_ran++; }, 0,
&schedule, AsyncOps::Priority::High);
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { high_priority_ran++; }, 0, &schedule, AsyncOps::Priority::High);
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { normal_priority_ran++; }, 0,
&schedule, AsyncOps::Priority::Normal);
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { normal_priority_ran++; }, 0, &schedule, AsyncOps::Priority::Normal);
AsyncOps::wait_for_schedule_completion(&schedule);
@ -109,14 +116,16 @@ auto test_priorities() -> bool {
return true;
}
auto test_run_task_fire_and_forget() -> bool {
auto test_run_task_fire_and_forget() -> bool
{
SchedulerGuard guard(2);
std::atomic<bool> executed{false};
AsyncOps::run_task([&]() { executed = true; });
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 100; ++i)
{
if (executed.load())
break;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
@ -127,7 +136,8 @@ auto test_run_task_fire_and_forget() -> bool {
return true;
}
auto test_cancellation_safety() -> bool {
auto test_cancellation_safety() -> bool
{
SchedulerGuard guard(2);
AsyncOps::cancel_tasks_of_tag(999);
@ -135,8 +145,7 @@ auto test_cancellation_safety() -> bool {
AsyncOps::Schedule schedule;
std::atomic<i32> counter{0};
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { counter++; }, 10,
&schedule);
AsyncOps::schedule_task([&](AsyncOps::WorkerId) { counter++; }, 10, &schedule);
AsyncOps::wait_for_schedule_completion(&schedule);
IAT_CHECK_EQ(counter.load(), 1);

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, CLI)
auto test_basic_traversal() -> bool {
auto test_basic_traversal() -> bool
{
const Vec<String> args = {"ignored", "one", "two", "three"};
CLIParser parser(args);
@ -41,7 +42,8 @@ auto test_basic_traversal() -> bool {
return true;
}
auto test_peek() -> bool {
auto test_peek() -> bool
{
const Vec<String> args = {"ignored", "peek_val", "next_val"};
CLIParser parser(args);
@ -58,7 +60,8 @@ auto test_peek() -> bool {
return true;
}
auto test_consume() -> bool {
auto test_consume() -> bool
{
const Vec<String> args = {"ignored", "-v", "--output", "file.txt"};
CLIParser parser(args);
@ -79,7 +82,8 @@ auto test_consume() -> bool {
return true;
}
auto test_empty() -> bool {
auto test_empty() -> bool
{
const Vec<String> args = {};
CLIParser parser(args);

View File

@ -24,7 +24,11 @@ set(TEST_SOURCES
add_executable(IACore_Test_Suite ${TEST_SOURCES})
target_compile_options(IACore_Test_Suite PRIVATE -fexceptions)
if(MSVC)
target_compile_options(IACore_Test_Suite PRIVATE "/EHsc")
else()
target_compile_options(IACore_Test_Suite PRIVATE "-fexceptions")
endif()
set_target_properties(IACore_Test_Suite PROPERTIES USE_EXCEPTIONS ON)
target_link_libraries(IACore_Test_Suite PRIVATE IACore)

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, DataOps)
auto test_crc32() -> bool {
auto test_crc32() -> bool
{
{
const String s = "123456789";
const Span<const u8> span(reinterpret_cast<const u8 *>(s.data()), s.size());
@ -36,20 +37,20 @@ auto test_crc32() -> bool {
{
Vec<u8> buffer(33);
for (usize i = 1; i < 33; ++i) {
for (usize i = 1; i < 33; ++i)
{
buffer[i] = static_cast<u8>(i);
}
Vec<u8> ref_data(32);
for (usize i = 0; i < 32; ++i) {
for (usize i = 0; i < 32; ++i)
{
ref_data[i] = static_cast<u8>(i + 1);
}
const u32 hash_ref =
DataOps::crc32(Span<const u8>(ref_data.data(), ref_data.size()));
const u32 hash_ref = DataOps::crc32(Span<const u8>(ref_data.data(), ref_data.size()));
const u32 hash_unaligned =
DataOps::crc32(Span<const u8>(buffer.data() + 1, 32));
const u32 hash_unaligned = DataOps::crc32(Span<const u8>(buffer.data() + 1, 32));
IAT_CHECK_EQ(hash_ref, hash_unaligned);
}
@ -57,7 +58,8 @@ auto test_crc32() -> bool {
return true;
}
auto test_hash_xxhash() -> bool {
auto test_hash_xxhash() -> bool
{
{
const String s = "123456789";
const u32 result = DataOps::hash_xxhash(s);
@ -73,19 +75,18 @@ auto test_hash_xxhash() -> bool {
{
const String s = "Test";
const u32 r1 = DataOps::hash_xxhash(s);
const u32 r2 = DataOps::hash_xxhash(
Span<const u8>(reinterpret_cast<const u8 *>(s.data()), s.size()));
const u32 r2 = DataOps::hash_xxhash(Span<const u8>(reinterpret_cast<const u8 *>(s.data()), s.size()));
IAT_CHECK_EQ(r1, r2);
}
return true;
}
auto test_hash_fnv1a() -> bool {
auto test_hash_fnv1a() -> bool
{
{
const String s = "123456789";
const u32 result = DataOps::hash_fnv1a(
Span<const u8>(reinterpret_cast<const u8 *>(s.data()), s.size()));
const u32 result = DataOps::hash_fnv1a(Span<const u8>(reinterpret_cast<const u8 *>(s.data()), s.size()));
IAT_CHECK_EQ(result, 0xbb86b11c);
}

View File

@ -23,9 +23,10 @@ static constexpr const char *TEST_VAL = "Hello World";
IAT_BEGIN_BLOCK(Core, Environment)
auto test_basic_cycle() -> bool {
auto test_basic_cycle() -> bool
{
(void)Environment::unset(TEST_KEY);
(void) Environment::unset(TEST_KEY);
IAT_CHECK_NOT(Environment::exists(TEST_KEY));
const auto set_res = Environment::set(TEST_KEY, TEST_VAL);
@ -39,23 +40,25 @@ auto test_basic_cycle() -> bool {
const String val = Environment::get(TEST_KEY);
IAT_CHECK_EQ(val, String(TEST_VAL));
(void)Environment::unset(TEST_KEY);
(void) Environment::unset(TEST_KEY);
return true;
}
auto test_overwrite() -> bool {
(void)Environment::set(TEST_KEY, "ValueA");
auto test_overwrite() -> bool
{
(void) Environment::set(TEST_KEY, "ValueA");
IAT_CHECK_EQ(Environment::get(TEST_KEY), String("ValueA"));
(void)Environment::set(TEST_KEY, "ValueB");
(void) Environment::set(TEST_KEY, "ValueB");
IAT_CHECK_EQ(Environment::get(TEST_KEY), String("ValueB"));
(void)Environment::unset(TEST_KEY);
(void) Environment::unset(TEST_KEY);
return true;
}
auto test_unset() -> bool {
(void)Environment::set(TEST_KEY, "To Be Deleted");
auto test_unset() -> bool
{
(void) Environment::set(TEST_KEY, "To Be Deleted");
IAT_CHECK(Environment::exists(TEST_KEY));
const auto unset_res = Environment::unset(TEST_KEY);
@ -69,10 +72,11 @@ auto test_unset() -> bool {
return true;
}
auto test_defaults() -> bool {
auto test_defaults() -> bool
{
const char *ghost_key = "IA_THIS_KEY_DOES_NOT_EXIST";
(void)Environment::unset(ghost_key);
(void) Environment::unset(ghost_key);
const String empty = Environment::get(ghost_key);
IAT_CHECK(empty.empty());
@ -83,8 +87,9 @@ auto test_defaults() -> bool {
return true;
}
auto test_empty_value() -> bool {
(void)Environment::set(TEST_KEY, "");
auto test_empty_value() -> bool
{
(void) Environment::set(TEST_KEY, "");
#if IA_PLATFORM_WINDOWS
@ -96,13 +101,14 @@ auto test_empty_value() -> bool {
IAT_CHECK(opt->empty());
#endif
(void)Environment::unset(TEST_KEY);
(void) Environment::unset(TEST_KEY);
IAT_CHECK_NOT(Environment::exists(TEST_KEY));
return true;
}
auto test_bad_input() -> bool {
auto test_bad_input() -> bool
{
const auto res = Environment::set("", "Value");
IAT_CHECK_NOT(res.has_value());

View File

@ -20,14 +20,17 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, FileOps)
void cleanup_file(const Path &path) {
void cleanup_file(const Path &path)
{
std::error_code ec;
if (std::filesystem::exists(path, ec)) {
if (std::filesystem::exists(path, ec))
{
std::filesystem::remove(path, ec);
}
}
auto test_text_io() -> bool {
auto test_text_io() -> bool
{
const Path path = "iatest_fileops_text.txt";
const String content = "Hello IACore FileOps!\nLine 2";
@ -43,7 +46,8 @@ auto test_text_io() -> bool {
return true;
}
auto test_binary_io() -> bool {
auto test_binary_io() -> bool
{
const Path path = "iatest_fileops_bin.bin";
const Vec<u8> content = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0xFF};
@ -55,7 +59,8 @@ auto test_binary_io() -> bool {
IAT_CHECK(read_res.has_value());
IAT_CHECK_EQ(read_res->size(), content.size());
for (usize i = 0; i < content.size(); ++i) {
for (usize i = 0; i < content.size(); ++i)
{
IAT_CHECK_EQ((*read_res)[i], content[i]);
}
@ -63,11 +68,12 @@ auto test_binary_io() -> bool {
return true;
}
auto test_file_mapping() -> bool {
auto test_file_mapping() -> bool
{
const Path path = "iatest_fileops_map.txt";
const String content = "MappedContent";
(void)FileOps::write_text_file(path, content, true);
(void) FileOps::write_text_file(path, content, true);
usize size = 0;
const auto map_res = FileOps::map_file(path, size);
@ -86,7 +92,8 @@ auto test_file_mapping() -> bool {
return true;
}
auto test_shared_memory() -> bool {
auto test_shared_memory() -> bool
{
const String shm_name = "iatest_shm_block";
const usize shm_size = 4096;
@ -112,7 +119,8 @@ auto test_shared_memory() -> bool {
return true;
}
auto test_stream_integration() -> bool {
auto test_stream_integration() -> bool
{
const Path path = "iatest_fileops_stream.bin";
cleanup_file(path);
@ -121,8 +129,8 @@ auto test_stream_integration() -> bool {
IAT_CHECK(writer_res.has_value());
auto &writer = *writer_res;
(void)writer.write<u32>(0x12345678);
(void)writer.write<u8>(0xFF);
(void) writer.write<u32>(0x12345678);
(void) writer.write<u8>(0xFF);
}
{

View File

@ -21,27 +21,26 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, IPC)
auto test_layout_constraints() -> bool {
auto test_layout_constraints() -> bool
{
IAT_CHECK_EQ(alignof(IpcSharedMemoryLayout), static_cast<usize>(64));
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, meta), static_cast<usize>(0));
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, moni_control),
static_cast<usize>(64));
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, moni_control), static_cast<usize>(64));
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, mino_control),
static_cast<usize>(192));
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, mino_control), static_cast<usize>(192));
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, moni_data_offset),
static_cast<usize>(320));
IAT_CHECK_EQ(offsetof(IpcSharedMemoryLayout, moni_data_offset), static_cast<usize>(320));
IAT_CHECK_EQ(sizeof(IpcSharedMemoryLayout) % 64, static_cast<usize>(0));
return true;
}
auto test_manual_shm_ringbuffer() -> bool {
auto test_manual_shm_ringbuffer() -> bool
{
const String shm_name = "IA_TEST_IPC_LAYOUT_CHECK";
const usize shm_size = 16 * 1024;
@ -67,28 +66,20 @@ auto test_manual_shm_ringbuffer() -> bool {
layout->mino_data_offset = header_size + half_data;
layout->mino_data_size = half_data;
Span<u8> moni_data_span(base_ptr + layout->moni_data_offset,
static_cast<usize>(layout->moni_data_size));
auto moni_res =
RingBufferView::create(&layout->moni_control, moni_data_span, true);
Span<u8> moni_data_span(base_ptr + layout->moni_data_offset, static_cast<usize>(layout->moni_data_size));
auto moni_res = RingBufferView::create(&layout->moni_control, moni_data_span, true);
IAT_CHECK(moni_res.has_value());
auto moni = std::move(*moni_res);
Span<u8> mino_data_span(base_ptr + layout->mino_data_offset,
static_cast<usize>(layout->mino_data_size));
auto mino_res =
RingBufferView::create(&layout->mino_control, mino_data_span, true);
Span<u8> mino_data_span(base_ptr + layout->mino_data_offset, static_cast<usize>(layout->mino_data_size));
auto mino_res = RingBufferView::create(&layout->mino_control, mino_data_span, true);
IAT_CHECK(mino_res.has_value());
auto _ = std::move(*mino_res);
String msg = "IPC_TEST_MESSAGE";
IAT_CHECK(
moni.push(100, Span<const u8>(reinterpret_cast<const u8 *>(msg.data()),
msg.size()))
.has_value());
IAT_CHECK(moni.push(100, Span<const u8>(reinterpret_cast<const u8 *>(msg.data()), msg.size())).has_value());
auto moni_reader_res =
RingBufferView::create(&layout->moni_control, moni_data_span, false);
auto moni_reader_res = RingBufferView::create(&layout->moni_control, moni_data_span, false);
IAT_CHECK(moni_reader_res.has_value());
auto moni_reader = std::move(*moni_reader_res);
@ -99,7 +90,7 @@ auto test_manual_shm_ringbuffer() -> bool {
IAT_CHECK(pop_res->has_value());
IAT_CHECK_EQ(header.id, static_cast<u16>(100));
String received((char *)buffer, *pop_res.value());
String received((char *) buffer, *pop_res.value());
IAT_CHECK_EQ(received, msg);
FileOps::unmap_file(base_ptr);
@ -108,13 +99,20 @@ auto test_manual_shm_ringbuffer() -> bool {
return true;
}
class TestManager : public IpcManager {
public:
void on_signal(NativeProcessID, u8) override {}
void on_packet(NativeProcessID, u16, Span<const u8>) override {}
class TestManager : public IpcManager
{
public:
void on_signal(NativeProcessID, u8) override
{
}
void on_packet(NativeProcessID, u16, Span<const u8>) override
{
}
};
auto test_manager_instantiation() -> bool {
auto test_manager_instantiation() -> bool
{
TestManager mgr;
return true;
}

View File

@ -18,21 +18,23 @@
using namespace IACore;
struct UserProfile {
struct UserProfile
{
String username;
u32 id;
bool is_active;
Vec<String> roles;
bool operator==(const UserProfile &other) const {
return username == other.username && id == other.id &&
is_active == other.is_active && roles == other.roles;
bool operator==(const UserProfile &other) const
{
return username == other.username && id == other.id && is_active == other.is_active && roles == other.roles;
}
};
IAT_BEGIN_BLOCK(Core, JSON)
auto test_dynamic_parse() -> bool {
auto test_dynamic_parse() -> bool
{
const String json_text = R"({
"string": "Hello World",
"int": 42,
@ -69,7 +71,8 @@ auto test_dynamic_parse() -> bool {
return true;
}
auto test_dynamic_encode() -> bool {
auto test_dynamic_encode() -> bool
{
nlohmann::json j;
j["name"] = "IACore";
j["version"] = 2;
@ -83,18 +86,17 @@ auto test_dynamic_encode() -> bool {
return true;
}
auto test_parse_invalid() -> bool {
auto test_parse_invalid() -> bool
{
const String bad_json = "{ key: value }";
auto res = Json::parse(bad_json);
IAT_CHECK_NOT(res.has_value());
return true;
}
auto test_struct_round_trip() -> bool {
UserProfile original{.username = "test_user",
.id = 12345,
.is_active = true,
.roles = {"admin", "editor"}};
auto test_struct_round_trip() -> bool
{
UserProfile original{.username = "test_user", .id = 12345, .is_active = true, .roles = {"admin", "editor"}};
auto encode_res = Json::encode_struct(original);
IAT_CHECK(encode_res.has_value());
@ -112,14 +114,16 @@ auto test_struct_round_trip() -> bool {
return true;
}
auto test_struct_parse_error() -> bool {
auto test_struct_parse_error() -> bool
{
const String malformed = "{ broken_json: ";
auto res = Json::parse_to_struct<UserProfile>(malformed);
IAT_CHECK_NOT(res.has_value());
return true;
}
auto test_read_only() -> bool {
auto test_read_only() -> bool
{
const String json_text = R"({
"id": 999,
"name": "Simd",

View File

@ -23,7 +23,17 @@ IAT_BEGIN_BLOCK(Core, Logger)
static constexpr const char *LOG_FILE = "iacore_test_log.txt";
auto test_file_logging() -> bool {
void cleanup_file(const Path &path)
{
std::error_code ec;
if (std::filesystem::exists(path, ec))
{
std::filesystem::remove(path, ec);
}
}
auto test_file_logging() -> bool
{
const auto res = Logger::enable_logging_to_disk(LOG_FILE);
IAT_CHECK(res.has_value());
@ -41,9 +51,10 @@ auto test_file_logging() -> bool {
Logger::flush_logs();
auto read_res = FileOps::read_text_file(LOG_FILE);
if (!read_res) {
std::cout << console::YELLOW << " Warning: Could not read log file ("
<< read_res.error() << "). Skipping verification.\n"
if (!read_res)
{
std::cout << console::YELLOW << " Warning: Could not read log file (" << read_res.error()
<< "). Skipping verification.\n"
<< console::RESET;
return true;
}
@ -58,10 +69,13 @@ auto test_file_logging() -> bool {
IAT_CHECK(content.find("ERROR") != String::npos);
IAT_CHECK(content.find("WARN") != String::npos);
cleanup_file(LOG_FILE);
return true;
}
auto test_log_levels() -> bool {
auto test_log_levels() -> bool
{
Logger::set_log_level(Logger::LogLevel::Warn);
@ -74,7 +88,8 @@ auto test_log_levels() -> bool {
Logger::flush_logs();
auto read_res = FileOps::read_text_file(LOG_FILE);
if (!read_res) {
if (!read_res)
{
return true;
}
@ -87,7 +102,8 @@ auto test_log_levels() -> bool {
return true;
}
auto test_formatting() -> bool {
auto test_formatting() -> bool
{
Logger::set_log_level(Logger::LogLevel::Info);
const String name = "IACore";
@ -97,7 +113,8 @@ auto test_formatting() -> bool {
Logger::flush_logs();
auto read_res = FileOps::read_text_file(LOG_FILE);
if (!read_res) {
if (!read_res)
{
return true;
}

View File

@ -20,18 +20,15 @@
using namespace IACore;
IACORE_MAIN() {
(void)args;
IACORE_MAIN()
{
(void) args;
AU_TRY_PURE(SocketOps::initialize());
std::cout
<< console::GREEN
<< "\n===============================================================\n";
std::cout << console::GREEN << "\n===============================================================\n";
std::cout << " IACore (Independent Architecture Core) - Unit Test Suite\n";
std::cout
<< "===============================================================\n"
<< console::RESET << "\n";
std::cout << "===============================================================\n" << console::RESET << "\n";
const i32 result = Test::TestRegistry::run_all();

View File

@ -21,7 +21,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, Platform)
auto test_os_name() -> bool {
auto test_os_name() -> bool
{
const char *os_name = Platform::get_operating_system_name();
IAT_CHECK(os_name != nullptr);
@ -41,7 +42,8 @@ auto test_os_name() -> bool {
return true;
}
auto test_arch_name() -> bool {
auto test_arch_name() -> bool
{
const char *arch_name = Platform::get_architecture_name();
IAT_CHECK(arch_name != nullptr);
@ -59,7 +61,8 @@ auto test_arch_name() -> bool {
return true;
}
auto test_capabilities() -> bool {
auto test_capabilities() -> bool
{
const bool check_result = Platform::check_cpu();
IAT_CHECK(check_result);
@ -67,13 +70,14 @@ auto test_capabilities() -> bool {
const auto &caps = Platform::get_capabilities();
volatile bool has_crc = caps.hardware_crc32;
(void)has_crc;
(void) has_crc;
return true;
}
#if IA_ARCH_X64
auto test_cpuid() -> bool {
auto test_cpuid() -> bool
{
i32 regs[4] = {0};
Platform::cpuid(0, 0, regs);
@ -91,12 +95,11 @@ auto test_cpuid() -> bool {
const String vendor_str(vendor);
IAT_CHECK(!vendor_str.empty());
bool is_known =
(vendor_str == "GenuineIntel" || vendor_str == "AuthenticAMD" ||
vendor_str == "KVMKVMKVM" || vendor_str == "Microsoft Hv" ||
vendor_str == "VBoxVBoxVBox");
bool is_known = (vendor_str == "GenuineIntel" || vendor_str == "AuthenticAMD" || vendor_str == "KVMKVMKVM" ||
vendor_str == "Microsoft Hv" || vendor_str == "VBoxVBoxVBox");
if (!is_known) {
if (!is_known)
{
std::cout << " [Info] Unknown CPU Vendor: " << vendor_str << "\n";
}

View File

@ -19,24 +19,24 @@
using namespace IACore;
#if IA_PLATFORM_WINDOWS
#define CMD_ECHO_EXE "cmd.exe"
#define CMD_ARG_PREFIX "/c echo"
#define NULL_DEVICE "NUL"
# define CMD_ECHO_EXE "cmd.exe"
# define CMD_ARG_PREFIX "/c echo"
# define NULL_DEVICE "NUL"
#else
#define CMD_ECHO_EXE "/bin/echo"
#define CMD_ARG_PREFIX ""
#define NULL_DEVICE "/dev/null"
# define CMD_ECHO_EXE "/bin/echo"
# define CMD_ARG_PREFIX ""
# define NULL_DEVICE "/dev/null"
#endif
IAT_BEGIN_BLOCK(Core, ProcessOps)
auto test_basic_run() -> bool {
auto test_basic_run() -> bool
{
String captured;
const auto result =
ProcessOps::spawn_process_sync(CMD_ECHO_EXE, CMD_ARG_PREFIX " HelloIA",
[&](StringView line) { captured = line; });
const auto result = ProcessOps::spawn_process_sync(CMD_ECHO_EXE, CMD_ARG_PREFIX " HelloIA",
[&](StringView line) { captured = line; });
IAT_CHECK(result.has_value());
IAT_CHECK_EQ(*result, 0);
@ -46,18 +46,18 @@ auto test_basic_run() -> bool {
return true;
}
auto test_arguments() -> bool {
auto test_arguments() -> bool
{
Vec<String> lines;
String args = String(CMD_ARG_PREFIX) + " one two";
if (!args.empty() && args[0] == ' ') {
if (!args.empty() && args[0] == ' ')
{
args.erase(0, 1);
}
const auto result =
ProcessOps::spawn_process_sync(CMD_ECHO_EXE, args, [&](StringView line) {
lines.push_back(String(line));
});
ProcessOps::spawn_process_sync(CMD_ECHO_EXE, args, [&](StringView line) { lines.push_back(String(line)); });
IAT_CHECK_EQ(*result, 0);
IAT_CHECK(lines.size() > 0);
@ -67,7 +67,8 @@ auto test_arguments() -> bool {
return true;
}
auto test_exit_codes() -> bool {
auto test_exit_codes() -> bool
{
String cmd;
String arg;
@ -80,8 +81,7 @@ auto test_exit_codes() -> bool {
arg = "-c \"exit 42\"";
#endif
const auto result =
ProcessOps::spawn_process_sync(cmd, arg, [](StringView) {});
const auto result = ProcessOps::spawn_process_sync(cmd, arg, [](StringView) {});
IAT_CHECK(result.has_value());
IAT_CHECK_EQ(*result, 42);
@ -89,10 +89,10 @@ auto test_exit_codes() -> bool {
return true;
}
auto test_missing_exe() -> bool {
auto test_missing_exe() -> bool
{
const auto result =
ProcessOps::spawn_process_sync("sdflkjghsdflkjg", "", [](StringView) {});
const auto result = ProcessOps::spawn_process_sync("sdflkjghsdflkjg", "", [](StringView) {});
#if IA_PLATFORM_WINDOWS
IAT_CHECK_NOT(result.has_value());
@ -105,11 +105,13 @@ auto test_missing_exe() -> bool {
return true;
}
auto test_large_output() -> bool {
auto test_large_output() -> bool
{
String massive_string;
massive_string.reserve(5000);
for (i32 i = 0; i < 500; ++i) {
for (i32 i = 0; i < 500; ++i)
{
massive_string += "1234567890";
}
@ -126,8 +128,7 @@ auto test_large_output() -> bool {
#endif
String captured;
const auto result = ProcessOps::spawn_process_sync(
cmd, arg, [&](StringView line) { captured += line; });
const auto result = ProcessOps::spawn_process_sync(cmd, arg, [&](StringView line) { captured += line; });
IAT_CHECK(result.has_value());
IAT_CHECK_EQ(*result, 0);
@ -137,7 +138,8 @@ auto test_large_output() -> bool {
return true;
}
auto test_multi_line() -> bool {
auto test_multi_line() -> bool
{
String cmd;
String arg;
@ -153,16 +155,17 @@ auto test_multi_line() -> bool {
bool found_a = false;
bool found_b = false;
const auto res =
ProcessOps::spawn_process_sync(cmd, arg, [&](StringView line) {
line_count++;
if (line.find("LineA") != String::npos) {
found_a = true;
}
if (line.find("LineB") != String::npos) {
found_b = true;
}
});
const auto res = ProcessOps::spawn_process_sync(cmd, arg, [&](StringView line) {
line_count++;
if (line.find("LineA") != String::npos)
{
found_a = true;
}
if (line.find("LineB") != String::npos)
{
found_b = true;
}
});
IAT_CHECK(res.has_value());
IAT_CHECK(found_a);
@ -173,10 +176,10 @@ auto test_multi_line() -> bool {
return true;
}
auto test_complex_arguments() -> bool {
auto test_complex_arguments() -> bool
{
const String complex_args =
"-DDEFINED_MSG=\\\"Hello World\\\" -v path/to/file";
const String complex_args = "-DDEFINED_MSG=\\\"Hello World\\\" -v path/to/file";
const String cmd = CMD_ECHO_EXE;
@ -188,8 +191,7 @@ auto test_complex_arguments() -> bool {
#endif
String captured;
const auto result = ProcessOps::spawn_process_sync(
cmd, final_args, [&](StringView line) { captured += line; });
const auto result = ProcessOps::spawn_process_sync(cmd, final_args, [&](StringView line) { captured += line; });
IAT_CHECK(result.has_value());
IAT_CHECK_EQ(*result, 0);

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, RingBuffer)
auto test_push_pop() -> bool {
auto test_push_pop() -> bool
{
Vec<u8> memory(sizeof(RingBufferView::ControlBlock) + 1024);
@ -33,8 +34,7 @@ auto test_push_pop() -> bool {
auto consumer = std::move(*consumer_res);
String msg = "Hello RingBuffer";
const auto push_res = producer.push(
1, Span<const u8>(reinterpret_cast<const u8 *>(msg.data()), msg.size()));
const auto push_res = producer.push(1, Span<const u8>(reinterpret_cast<const u8 *>(msg.data()), msg.size()));
IAT_CHECK(push_res.has_value());
RingBufferView::PacketHeader header;
@ -57,7 +57,8 @@ auto test_push_pop() -> bool {
return true;
}
auto test_wrap_around() -> bool {
auto test_wrap_around() -> bool
{
Vec<u8> memory(sizeof(RingBufferView::ControlBlock) + 100);
@ -87,8 +88,10 @@ auto test_wrap_around() -> bool {
IAT_CHECK_EQ(pop_size, static_cast<usize>(40));
bool match = true;
for (usize i = 0; i < 40; i++) {
if (out_buf[i] != 0xAA) {
for (usize i = 0; i < 40; i++)
{
if (out_buf[i] != 0xAA)
{
match = false;
}
}

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, FloatVec4)
auto test_float_arithmetic() -> bool {
auto test_float_arithmetic() -> bool
{
FloatVec4 v1(10.0f, 20.0f, 30.0f, 40.0f);
FloatVec4 v2(2.0f, 4.0f, 5.0f, 8.0f);
@ -39,7 +40,8 @@ auto test_float_arithmetic() -> bool {
return true;
}
auto test_math_helpers() -> bool {
auto test_math_helpers() -> bool
{
alignas(16) f32 res[4];
FloatVec4 v_sq(4.0f, 9.0f, 16.0f, 25.0f);
@ -61,7 +63,8 @@ auto test_math_helpers() -> bool {
return true;
}
auto test_approx_math() -> bool {
auto test_approx_math() -> bool
{
alignas(16) f32 res[4];
FloatVec4 v(16.0f, 25.0f, 100.0f, 1.0f);
@ -73,7 +76,8 @@ auto test_approx_math() -> bool {
return true;
}
auto test_linear_algebra() -> bool {
auto test_linear_algebra() -> bool
{
FloatVec4 v1(1.0f, 2.0f, 3.0f, 4.0f);
FloatVec4 v2(1.0f, 0.0f, 1.0f, 0.0f);

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, IntVec4)
auto test_constructors() -> bool {
auto test_constructors() -> bool
{
IntVec4 v_broadcast(10);
alignas(16) u32 store_buf[4];
v_broadcast.store(store_buf);
@ -41,7 +42,8 @@ auto test_constructors() -> bool {
return true;
}
auto test_arithmetic() -> bool {
auto test_arithmetic() -> bool
{
const IntVec4 v1(10, 20, 30, 40);
const IntVec4 v2(1, 2, 3, 4);
@ -64,9 +66,10 @@ auto test_arithmetic() -> bool {
return true;
}
auto test_bitwise() -> bool {
auto test_bitwise() -> bool
{
const IntVec4 v_all_ones(0xFFFFFFFF);
const IntVec4 v_zero((u32)0);
const IntVec4 v_zero((u32) 0);
const IntVec4 v_pattern(0xAAAAAAAA);
alignas(16) u32 res[4];
@ -94,7 +97,8 @@ auto test_bitwise() -> bool {
return true;
}
auto test_saturation() -> bool {
auto test_saturation() -> bool
{
const u32 max = 0xFFFFFFFF;
const IntVec4 v_high(max - 10);
const IntVec4 v_add(20);
@ -112,7 +116,8 @@ auto test_saturation() -> bool {
return true;
}
auto test_advanced_ops() -> bool {
auto test_advanced_ops() -> bool
{
const IntVec4 v(0, 50, 100, 150);
alignas(16) u32 res[4];

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, SocketOps)
auto test_initialization() -> bool {
auto test_initialization() -> bool
{
IAT_CHECK(SocketOps::is_initialized());
const auto res = SocketOps::initialize();
@ -33,17 +34,19 @@ auto test_initialization() -> bool {
return true;
}
auto test_port_availability() -> bool {
auto test_port_availability() -> bool
{
const u16 port = 54321;
(void)SocketOps::is_port_available_tcp(port);
(void)SocketOps::is_port_available_udp(port);
(void) SocketOps::is_port_available_tcp(port);
(void) SocketOps::is_port_available_udp(port);
return true;
}
auto test_unix_socket_lifecycle() -> bool {
auto test_unix_socket_lifecycle() -> bool
{
const String socket_path = "iatest_ipc.sock";
SocketOps::unlink_file(socket_path.c_str());
@ -53,7 +56,8 @@ auto test_unix_socket_lifecycle() -> bool {
SocketHandle server = *server_res;
auto bind_res = SocketOps::bind_unix_socket(server, socket_path.c_str());
if (!bind_res) {
if (!bind_res)
{
SocketOps::close(server);
return false;
@ -66,8 +70,7 @@ auto test_unix_socket_lifecycle() -> bool {
IAT_CHECK(client_res.has_value());
SocketHandle client = *client_res;
auto connect_res =
SocketOps::connect_unix_socket(client, socket_path.c_str());
auto connect_res = SocketOps::connect_unix_socket(client, socket_path.c_str());
IAT_CHECK(connect_res.has_value());
SocketOps::close(client);
@ -77,7 +80,8 @@ auto test_unix_socket_lifecycle() -> bool {
return true;
}
auto test_unix_socket_errors() -> bool {
auto test_unix_socket_errors() -> bool
{
const String socket_path = "iatest_missing.sock";
SocketOps::unlink_file(socket_path.c_str());
@ -86,8 +90,7 @@ auto test_unix_socket_errors() -> bool {
IAT_CHECK(client_res.has_value());
SocketHandle client = *client_res;
auto connect_res =
SocketOps::connect_unix_socket(client, socket_path.c_str());
auto connect_res = SocketOps::connect_unix_socket(client, socket_path.c_str());
IAT_CHECK_NOT(connect_res.has_value());
SocketOps::close(client);

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, StreamReader)
auto test_read_uint8() -> bool {
auto test_read_uint8() -> bool
{
u8 data[] = {0xAA, 0xBB, 0xCC};
StreamReader reader(data);
@ -36,7 +37,8 @@ auto test_read_uint8() -> bool {
return true;
}
auto test_read_multi_byte() -> bool {
auto test_read_multi_byte() -> bool
{
u8 data[] = {0x01, 0x02, 0x03, 0x04};
StreamReader reader(data);
@ -52,7 +54,8 @@ auto test_read_multi_byte() -> bool {
return true;
}
auto test_read_float() -> bool {
auto test_read_float() -> bool
{
const f32 pi = 3.14159f;
u8 data[4];
@ -67,7 +70,8 @@ auto test_read_float() -> bool {
return true;
}
auto test_read_buffer() -> bool {
auto test_read_buffer() -> bool
{
u8 src[] = {1, 2, 3, 4, 5};
u8 dst[3] = {0};
StreamReader reader(src);
@ -84,7 +88,8 @@ auto test_read_buffer() -> bool {
return true;
}
auto test_navigation() -> bool {
auto test_navigation() -> bool
{
u8 data[10] = {0};
StreamReader reader(data);
@ -106,11 +111,12 @@ auto test_navigation() -> bool {
return true;
}
auto test_boundary_checks() -> bool {
auto test_boundary_checks() -> bool
{
u8 data[] = {0x00, 0x00};
StreamReader reader(data);
(void)reader.read<u16>();
(void) reader.read<u16>();
IAT_CHECK(reader.is_eof());
auto val = reader.read<u8>();

View File

@ -21,7 +21,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, StreamWriter)
auto test_memory_writer() -> bool {
auto test_memory_writer() -> bool
{
StreamWriter writer;
IAT_CHECK(writer.write(static_cast<u8>(0xAA), 1).has_value());
@ -39,7 +40,8 @@ auto test_memory_writer() -> bool {
return true;
}
auto test_fixed_buffer() -> bool {
auto test_fixed_buffer() -> bool
{
u8 buffer[4] = {0};
StreamWriter writer(Span<u8>(buffer, 4));
@ -60,10 +62,12 @@ auto test_fixed_buffer() -> bool {
return true;
}
auto test_file_writer() -> bool {
auto test_file_writer() -> bool
{
const Path path = "test_stream_writer.bin";
if (std::filesystem::exists(path)) {
if (std::filesystem::exists(path))
{
std::filesystem::remove(path);
}
@ -81,8 +85,7 @@ auto test_file_writer() -> bool {
auto read_res = FileOps::read_binary_file(path);
IAT_CHECK(read_res.has_value());
const String read_str(reinterpret_cast<const char *>(read_res->data()),
read_res->size());
const String read_str(reinterpret_cast<const char *>(read_res->data()), read_res->size());
IAT_CHECK_EQ(read_str, String("Hello World"));
std::filesystem::remove(path);
@ -90,7 +93,8 @@ auto test_file_writer() -> bool {
return true;
}
auto test_primitives() -> bool {
auto test_primitives() -> bool
{
StreamWriter writer;
const f32 f = 1.5f;

View File

@ -20,7 +20,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, StringOps)
auto test_base64_encode() -> bool {
auto test_base64_encode() -> bool
{
{
const String s = "Hello World";
@ -58,13 +59,13 @@ auto test_base64_encode() -> bool {
return true;
}
auto test_base64_decode() -> bool {
auto test_base64_decode() -> bool
{
{
const String encoded = "SGVsbG8gV29ybGQ=";
const Vec<u8> decoded = StringOps::decode_base64(encoded);
const String result(reinterpret_cast<const char *>(decoded.data()),
decoded.size());
const String result(reinterpret_cast<const char *>(decoded.data()), decoded.size());
IAT_CHECK_EQ(result, String("Hello World"));
}
@ -76,10 +77,12 @@ auto test_base64_decode() -> bool {
return true;
}
auto test_base64_round_trip() -> bool {
auto test_base64_round_trip() -> bool
{
Vec<u8> original;
original.reserve(256);
for (usize i = 0; i < 256; ++i) {
for (usize i = 0; i < 256; ++i)
{
original.push_back(static_cast<u8>(i));
}
@ -89,8 +92,10 @@ auto test_base64_round_trip() -> bool {
IAT_CHECK_EQ(original.size(), decoded.size());
bool match = true;
for (usize i = 0; i < original.size(); ++i) {
if (original[i] != decoded[i]) {
for (usize i = 0; i < original.size(); ++i)
{
if (original[i] != decoded[i])
{
match = false;
break;
}

View File

@ -18,10 +18,12 @@
using namespace IACore;
struct TestVec3 {
struct TestVec3
{
f32 x, y, z;
bool operator==(const TestVec3 &other) const {
bool operator==(const TestVec3 &other) const
{
return x == other.x && y == other.y && z == other.z;
}
};
@ -30,7 +32,8 @@ IA_MAKE_HASHABLE(TestVec3, &TestVec3::x, &TestVec3::y, &TestVec3::z);
IAT_BEGIN_BLOCK(Core, Utils)
auto test_hex_conversion() -> bool {
auto test_hex_conversion() -> bool
{
u8 bin[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0xFF};
String hex = Utils::binary_to_hex_string(bin);
@ -57,7 +60,8 @@ auto test_hex_conversion() -> bool {
return true;
}
auto test_hex_errors() -> bool {
auto test_hex_errors() -> bool
{
auto odd = Utils::hex_string_to_binary("ABC");
IAT_CHECK_NOT(odd.has_value());
@ -72,7 +76,8 @@ auto test_hex_errors() -> bool {
return true;
}
auto test_sort() -> bool {
auto test_sort() -> bool
{
Vec<i32> nums = {5, 1, 4, 2, 3};
Utils::sort(nums);
@ -86,7 +91,8 @@ auto test_sort() -> bool {
return true;
}
auto test_binary_search() -> bool {
auto test_binary_search() -> bool
{
Vec<i32> nums = {10, 20, 20, 20, 30};
@ -106,7 +112,8 @@ auto test_binary_search() -> bool {
return true;
}
auto test_hash_basics() -> bool {
auto test_hash_basics() -> bool
{
u64 h1 = Utils::compute_hash(10, 20.5f, "Hello");
u64 h2 = Utils::compute_hash(10, 20.5f, "Hello");
u64 h3 = Utils::compute_hash(10, 20.5f, "World");
@ -122,7 +129,8 @@ auto test_hash_basics() -> bool {
return true;
}
auto test_hash_macro() -> bool {
auto test_hash_macro() -> bool
{
TestVec3 v1{1.0f, 2.0f, 3.0f};
TestVec3 v2{1.0f, 2.0f, 3.0f};
TestVec3 v3{1.0f, 2.0f, 4.0f};

View File

@ -21,7 +21,8 @@ using namespace IACore;
IAT_BEGIN_BLOCK(Core, XML)
auto test_parse_string() -> bool {
auto test_parse_string() -> bool
{
const String xml_content = R"(
<root>
<item id="1">Value1</item>
@ -47,14 +48,16 @@ auto test_parse_string() -> bool {
return true;
}
auto test_parse_error() -> bool {
auto test_parse_error() -> bool
{
const String invalid_xml = "<root><unclosed>";
auto res = XML::parse_from_string(invalid_xml);
IAT_CHECK_NOT(res.has_value());
return true;
}
auto test_serialize() -> bool {
auto test_serialize() -> bool
{
const String xml_content = "<root><node>Text</node></root>";
auto res = XML::parse_from_string(xml_content);
IAT_CHECK(res.has_value());
@ -67,7 +70,8 @@ auto test_serialize() -> bool {
return true;
}
auto test_escape() -> bool {
auto test_escape() -> bool
{
const String raw = "< & > \" '";
const String escaped = XML::escape_xml_string(raw);
@ -80,7 +84,8 @@ auto test_escape() -> bool {
return true;
}
auto test_file_io() -> bool {
auto test_file_io() -> bool
{
const Path path = "test_temp_xml_doc.xml";
const String content = "<config><ver>1.0</ver></config>";
@ -91,8 +96,7 @@ auto test_file_io() -> bool {
IAT_CHECK(parse_res.has_value());
auto &doc = *parse_res;
IAT_CHECK_EQ(String(doc.child("config").child("ver").child_value()),
String("1.0"));
IAT_CHECK_EQ(String(doc.child("config").child("ver").child_value()), String("1.0"));
std::filesystem::remove(path);