diff --git a/deps/ox/src/ox/mc/test/tests.cpp b/deps/ox/src/ox/mc/test/tests.cpp index 4b10ebb7..3043ed7a 100644 --- a/deps/ox/src/ox/mc/test/tests.cpp +++ b/deps/ox/src/ox/mc/test/tests.cpp @@ -6,14 +6,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "ox/std/hashmap.hpp" #undef NDEBUG -#include #include #include -#include -#include #include #include #include @@ -94,27 +90,28 @@ constexpr ox::Error model(T *io, TestStruct *obj) noexcept { return OxError(0); } -std::map tests = { +std::map 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 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 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 &&expected) { + static constexpr auto check = [](McInt val, ox::Vector &&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 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 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 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 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), MaxValue), "Encode MaxValue fail"); @@ -231,6 +225,7 @@ std::map tests = { return OxError(0); } }, + { "decodeInteger", [] { @@ -238,8 +233,7 @@ std::map 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(encodeInteger(val)); oxReturnError(result.error); if (result.value != val) { @@ -269,19 +263,18 @@ std::map 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 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"); diff --git a/deps/ox/src/ox/std/test/tests.cpp b/deps/ox/src/ox/std/test/tests.cpp index a2a4a96c..e2d17843 100644 --- a/deps/ox/src/ox/std/test/tests.cpp +++ b/deps/ox/src/ox/std/test/tests.cpp @@ -8,12 +8,10 @@ #undef NDEBUG -#include #include -#include #include -std::map> tests = { +std::map tests = { { "malloc", [] { @@ -79,6 +77,8 @@ std::map> 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");