HelloAurora/Tests/Common/test.hpp

50 lines
1.1 KiB
C++
Raw Normal View History

2022-02-19 22:25:03 +00:00
/***
Copyright 2020 Reece Wilson (a/k/a "Reece"). All rights reserved.
File: test.hpp
Date: 2020-6-9
Originator: Reece
Purpose:
***/
#pragma once
using namespace Aurora;
static_assert(sizeof(int) <= sizeof(Types::uint32_t), "not enough space to store exit code in exit int (sizeof(uint32_t) > sizeof(int))");
namespace Aurora::UnitTesting
{
const Types::uint16_t kExitMagic = 0x1771; // avoid UB by avoiding twos complement
enum class TestResponse
{
kPass,
kPassWithWarn,
kUnitError,
kScriptabilityError
};
static int ToExitCode(TestResponse code)
{
Types::uint32_t exit = 0;
exit |= (kExitMagic << 16);
exit |= static_cast<Types::uint16_t>(code);
return static_cast<int>(exit);
}
static bool ToTestResponse(int code, TestResponse &response)
{
Types::uint32_t exit = static_cast<Types::uint32_t>(code);
if (((exit >> 16) & 0xFFFF) != kExitMagic)
return false;
response = static_cast<TestResponse>(exit & 0xFFFF);
return true;
}
void EndTest(TestResponse response);
}