[ox] Cleanup mc and std tests
This commit is contained in:
parent
803cd28087
commit
82021b8ee5
38
deps/ox/src/ox/mc/test/tests.cpp
vendored
38
deps/ox/src/ox/mc/test/tests.cpp
vendored
@ -6,14 +6,10 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "ox/std/hashmap.hpp"
|
||||
#undef NDEBUG
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <ox/mc/mc.hpp>
|
||||
#include <ox/model/model.hpp>
|
||||
#include <ox/std/std.hpp>
|
||||
@ -94,27 +90,28 @@ constexpr ox::Error model(T *io, TestStruct *obj) noexcept {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
std::map<std::string, ox::Error(*)()> tests = {
|
||||
std::map<ox::String, ox::Error(*)()> tests = {
|
||||
{
|
||||
{
|
||||
"MetalClawWriter",
|
||||
[] {
|
||||
// This test doesn't confirm much, but it does show that the writer
|
||||
// doesn't segfault
|
||||
constexpr size_t buffLen = 1024;
|
||||
static constexpr size_t buffLen = 1024;
|
||||
char buff[buffLen];
|
||||
TestStruct ts;
|
||||
oxReturnError(ox::writeMC(buff, buffLen, &ts));
|
||||
return OxError(0);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"MetalClawReader",
|
||||
[] {
|
||||
constexpr size_t buffLen = 1024;
|
||||
// setup for tests
|
||||
static constexpr size_t buffLen = 1024;
|
||||
char buff[buffLen];
|
||||
TestStruct testIn, testOut;
|
||||
|
||||
testIn.Bool = true;
|
||||
testIn.Int = 42;
|
||||
testIn.Union.Int = 42;
|
||||
@ -129,11 +126,10 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
testIn.Struct.Bool = false;
|
||||
testIn.Struct.Int = 300;
|
||||
testIn.Struct.BString = "Test String 2";
|
||||
|
||||
// run tests
|
||||
oxAssert(ox::writeMC(buff, buffLen, &testIn), "writeMC failed");
|
||||
oxAssert(ox::readMC(buff, buffLen, &testOut), "readMC failed");
|
||||
//std::cout << testIn.Union.Int << "|" << testOut.Union.Int << "|\n";
|
||||
|
||||
oxAssert(testIn.Bool == testOut.Bool, "Bool value mismatch");
|
||||
oxAssert(testIn.Int == testOut.Int, "Int value mismatch");
|
||||
oxAssert(testIn.Int1 == testOut.Int1, "Int1 value mismatch");
|
||||
@ -159,18 +155,17 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
oxAssert(testIn.Struct.Int == testOut.Struct.Int, "Struct.Int value mismatch");
|
||||
oxAssert(testIn.Struct.BString == testOut.Struct.BString, "Struct.BString value mismatch");
|
||||
oxAssert(testIn.Struct.Bool == testOut.Struct.Bool, "Struct.Bool value mismatch");
|
||||
|
||||
return OxError(0);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"encodeInteger",
|
||||
[] {
|
||||
using ox::MaxValue;
|
||||
using ox::mc::McInt;
|
||||
using ox::mc::encodeInteger;
|
||||
|
||||
constexpr auto check = [](McInt val, std::vector<uint8_t> &&expected) {
|
||||
static constexpr auto check = [](McInt val, ox::Vector<uint8_t, 9> &&expected) {
|
||||
if (val.length != expected.size()) {
|
||||
std::cout << "val.length: " << val.length << ", expected: " << expected.size() << '\n';
|
||||
return OxError(1);
|
||||
@ -195,7 +190,7 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
}
|
||||
return OxError(0);
|
||||
};
|
||||
|
||||
// signed positive
|
||||
oxAssert(check(encodeInteger(int64_t(1)), {0b000'0001'0}), "Encode 1 fail");
|
||||
oxAssert(check(encodeInteger(int64_t(2)), {0b000'0010'0}), "Encode 2 fail");
|
||||
oxAssert(check(encodeInteger(int64_t(3)), {0b000'0011'0}), "Encode 3 fail");
|
||||
@ -204,7 +199,7 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
oxAssert(check(encodeInteger(int64_t(129)), {0b00'0001'01, 0b10}), "Encode 129 fail");
|
||||
oxAssert(check(encodeInteger(int64_t(130)), {0b00'0010'01, 0b10}), "Encode 130 fail");
|
||||
oxAssert(check(encodeInteger(int64_t(131)), {0b00'0011'01, 0b10}), "Encode 131 fail");
|
||||
|
||||
// signed negative
|
||||
oxAssert(check(encodeInteger( int64_t(-1)), {0b111'1111'0}), "Encode -1 fail");
|
||||
oxAssert(check(encodeInteger( int64_t(-2)), {0b111'1110'0}), "Encode -2 fail");
|
||||
oxAssert(check(encodeInteger( int64_t(-3)), {0b111'1101'0}), "Encode -3 fail");
|
||||
@ -213,7 +208,7 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
oxAssert(check(encodeInteger(int64_t(-129)), {0b11'1111'01, 0b11'1111'01}), "Encode -129 fail");
|
||||
oxAssert(check(encodeInteger(int64_t(-130)), {0b11'1110'01, 0b11'1111'01}), "Encode -130 fail");
|
||||
oxAssert(check(encodeInteger(int64_t(-131)), {0b11'1101'01, 0b11'1111'01}), "Encode -131 fail");
|
||||
|
||||
// unsigned
|
||||
oxAssert(check(encodeInteger(uint32_t(0xffffffff)), {0b11101111, 255, 255, 255, 0b00011111}), "Encode 0xffffffff fail");
|
||||
oxAssert(check(encodeInteger(uint64_t(1)), {0b0010}), "Encode 1 fail");
|
||||
oxAssert(check(encodeInteger(uint64_t(2)), {0b0100}), "Encode 2 fail");
|
||||
@ -223,7 +218,6 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
oxAssert(check(encodeInteger(uint64_t(129)), {0b0101, 0b10}), "Encode 129 fail");
|
||||
oxAssert(check(encodeInteger(uint64_t(130)), {0b1001, 0b10}), "Encode 130 fail");
|
||||
oxAssert(check(encodeInteger(uint64_t(131)), {0b1101, 0b10}), "Encode 131 fail");
|
||||
|
||||
// Signed check needs lambda templates to run correctly without
|
||||
// code deduplication
|
||||
oxAssert(check64(encodeInteger(MaxValue<int64_t>), MaxValue<int64_t>), "Encode MaxValue<int64_t> fail");
|
||||
@ -231,6 +225,7 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
return OxError(0);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"decodeInteger",
|
||||
[] {
|
||||
@ -238,8 +233,7 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
using ox::mc::McInt;
|
||||
using ox::mc::encodeInteger;
|
||||
using ox::mc::decodeInteger;
|
||||
|
||||
constexpr auto check = [](auto val) {
|
||||
static constexpr auto check = [](auto val) {
|
||||
auto result = decodeInteger<decltype(val)>(encodeInteger(val));
|
||||
oxReturnError(result.error);
|
||||
if (result.value != val) {
|
||||
@ -269,19 +263,18 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
oxAssert(check(0xffffffff), "Decode of 0xffffffff failed.");
|
||||
oxAssert(check(0xffffffffffff), "Decode of 0xffffffffffff failed.");
|
||||
oxAssert(check(0xffffffffffffffff), "Decode of U64 max failed.");
|
||||
|
||||
return OxError(0);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"MetalClawDef",
|
||||
[] {
|
||||
//constexpr size_t descBuffLen = 1024;
|
||||
//uint8_t descBuff[descBuffLen];
|
||||
constexpr size_t dataBuffLen = 1024;
|
||||
static constexpr size_t dataBuffLen = 1024;
|
||||
char dataBuff[dataBuffLen];
|
||||
TestStruct testIn, testOut;
|
||||
|
||||
testIn.Bool = true;
|
||||
testIn.Int = 42;
|
||||
testIn.BString = "Test String 1";
|
||||
@ -292,7 +285,6 @@ std::map<std::string, ox::Error(*)()> tests = {
|
||||
testIn.Struct.Bool = false;
|
||||
testIn.Struct.Int = 300;
|
||||
testIn.Struct.BString = "Test String 2";
|
||||
|
||||
oxAssert(ox::writeMC(dataBuff, dataBuffLen, &testIn), "Data generation failed");
|
||||
auto type = ox::buildTypeDef(&testIn);
|
||||
oxAssert(type.error, "Descriptor write failed");
|
||||
|
6
deps/ox/src/ox/std/test/tests.cpp
vendored
6
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -8,12 +8,10 @@
|
||||
|
||||
#undef NDEBUG
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <ox/std/std.hpp>
|
||||
|
||||
std::map<std::string, std::function<ox::Error()>> tests = {
|
||||
std::map<ox::String, ox::Error(*)()> tests = {
|
||||
{
|
||||
"malloc",
|
||||
[] {
|
||||
@ -79,6 +77,8 @@ std::map<std::string, std::function<ox::Error()>> tests = {
|
||||
oxAssert(s == "asdfaoeu", "String append broken");
|
||||
ox::String ending = "asdf";
|
||||
oxAssert(ending.beginsWith("as"), "String::beginsWith is broken");
|
||||
oxAssert(ending.beginsWith("asd"), "String::beginsWith is broken");
|
||||
oxAssert(ending.beginsWith("asdf"), "String::beginsWith is broken");
|
||||
oxAssert(!ending.beginsWith("aa"), "String::beginsWith is broken");
|
||||
oxAssert(!ending.beginsWith("aaaaaaa"), "String::beginsWith is broken");
|
||||
oxAssert(!ending.beginsWith("li"), "String::beginsWith is broken");
|
||||
|
Loading…
x
Reference in New Issue
Block a user