[ox] Make tests more consistent
This commit is contained in:
53
deps/ox/src/ox/std/test/tests.cpp
vendored
53
deps/ox/src/ox/std/test/tests.cpp
vendored
@@ -12,9 +12,9 @@
|
||||
#include <ox/std/uuid.hpp>
|
||||
#include <ox/std/std.hpp>
|
||||
|
||||
static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
ox::String("malloc"),
|
||||
"malloc",
|
||||
[] {
|
||||
ox::Buffer buff(ox::units::MB);
|
||||
ox::heapmgr::initHeap(&buff[0], &buff[buff.size()-1]);
|
||||
@@ -26,7 +26,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("itoa"),
|
||||
"itoa",
|
||||
[]() {
|
||||
ox::Array<char, 10> buff;
|
||||
ox::CharBuffWriter bw(buff);
|
||||
@@ -42,31 +42,31 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("ABCDEFG != HIJKLMN"),
|
||||
"ABCDEFG != HIJKLMN",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("HIJKLMN != ABCDEFG"),
|
||||
"HIJKLMN != ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("ABCDEFG == ABCDEFG"),
|
||||
"ABCDEFG == ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("ABCDEFGHI == ABCDEFG"),
|
||||
"ABCDEFGHI == ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("BString"),
|
||||
"BString",
|
||||
[]() {
|
||||
ox::BString<5> s;
|
||||
s += "A";
|
||||
@@ -82,7 +82,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("String"),
|
||||
"String",
|
||||
[]() {
|
||||
ox::String s;
|
||||
s += "A";
|
||||
@@ -113,10 +113,11 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("Vector"),
|
||||
"Vector",
|
||||
[] {
|
||||
ox::Vector<int> v;
|
||||
oxAssert(v.size() == 0, "Initial Vector size not 0");
|
||||
oxAssert(v.empty(), "Vector::empty() is broken");
|
||||
auto insertTest = [&v](int val, [[maybe_unused]] std::size_t size) {
|
||||
v.push_back(val);
|
||||
oxReturnError(OxError(v.size() != size, "Vector size incorrect"));
|
||||
@@ -130,7 +131,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("HashMap"),
|
||||
"HashMap",
|
||||
[] {
|
||||
ox::HashMap<const char*, int> si;
|
||||
si["asdf"] = 42;
|
||||
@@ -146,7 +147,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("Serialize-Int"),
|
||||
"Serialize-Int",
|
||||
[] {
|
||||
using BA = ox::Array<char, 4>;
|
||||
const auto actual = ox::serialize<uint32_t>(256).unwrap();
|
||||
@@ -163,7 +164,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("BufferWriter"),
|
||||
"BufferWriter",
|
||||
[] {
|
||||
ox::Buffer b;
|
||||
ox::BufferWriter w(&b);
|
||||
@@ -172,7 +173,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
oxAssert(w.write("aoeu", 4), "write failed");
|
||||
oxExpect(b.size(), 8u);
|
||||
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeu");
|
||||
ox::StringView qwerty = "qwerty";
|
||||
ox::StringView constexpr qwerty = "qwerty";
|
||||
oxAssert(w.write(qwerty.data(), qwerty.bytes()), "write failed");
|
||||
oxExpect(b.size(), 14u);
|
||||
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeuqwerty");
|
||||
@@ -180,7 +181,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("FromHex"),
|
||||
"FromHex",
|
||||
[] {
|
||||
oxExpect(ox::detail::fromHex("01").unwrap(), 0x01);
|
||||
oxExpect(ox::detail::fromHex("02").unwrap(), 0x02);
|
||||
@@ -203,7 +204,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("ToHex"),
|
||||
"ToHex",
|
||||
[] {
|
||||
oxExpect(ox::detail::toHex(0x01), "01");
|
||||
oxExpect(ox::detail::toHex(0x02), "02");
|
||||
@@ -223,7 +224,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("UUID"),
|
||||
"UUID",
|
||||
[] {
|
||||
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
||||
oxRequire(uuid, ox::UUID::fromString(uuidStr));
|
||||
@@ -234,7 +235,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("UUID::generate"),
|
||||
"UUID::generate",
|
||||
[] {
|
||||
ox::UUID::seedGenerator({1234, 4321});
|
||||
oxExpect(ox::UUID::generate().unwrap().toString(), "5c3f4b5e-ccbf-4727-7f03-3053dedc8827");
|
||||
@@ -244,7 +245,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
}
|
||||
},
|
||||
{
|
||||
ox::String("StringSplit"),
|
||||
"StringSplit",
|
||||
[] {
|
||||
ox::StringView sv = "ab.cd";
|
||||
auto list = ox::split(sv, ".");
|
||||
@@ -313,12 +314,14 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **args) {
|
||||
if (argc > 1) {
|
||||
auto testName = ox::String(args[1]);
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
oxAssert(tests[testName](), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
if (argc < 2) {
|
||||
oxError("Must specify test to run");
|
||||
}
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user