[+] Parse test
[+] Log test [+] Added runtime shutdown on unit assert failure [*] Updated runtime
This commit is contained in:
parent
1de8a60060
commit
6b0e11741c
@ -1 +1 @@
|
||||
Subproject commit 3f4cf9387797115b55d4b484bc67bb378090d4cb
|
||||
Subproject commit c6d649e3de9cd1cdc3fc39a2713a0e1cc572e5e1
|
@ -11,7 +11,10 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <AuroraRuntime.hpp>
|
||||
|
||||
void Aurora::UnitTesting::EndTest(TestResponse response)
|
||||
{
|
||||
Aurora::RuntimeShutdown();
|
||||
exit(ToExitCode(response));
|
||||
}
|
48
Tests/Public/10. Hello Logger/Main.cpp
Normal file
48
Tests/Public/10. Hello Logger/Main.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: Main.cpp
|
||||
Date: 2022-2-18
|
||||
Author: Reece
|
||||
Note: Run the registry template in the ./Aurora/Runtime/Media directory
|
||||
***/
|
||||
#include <AuroraRuntime.hpp>
|
||||
|
||||
static void WriteHelloToEventLogGlobal()
|
||||
{
|
||||
auto logger = AuLog::NewLoggerShared(AuList<AuSPtr<AuLog::IBasicSink>>{
|
||||
AuLog::NewOSNamedEventDirectorySinkShared("Aurora Demo"),
|
||||
AuLog::NewStdSinkShared()
|
||||
});
|
||||
SysAssert(logger);
|
||||
|
||||
AuLog::SetGlobalLogger(logger);
|
||||
AuLogInfo("Hello event log and stdout from from global AuLogInfo shorthand");
|
||||
try
|
||||
{
|
||||
AU_THROW_STRING("Crinkled and delivered with many of seethes, hello event log");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
}
|
||||
AuLog::SetGlobalLogger({});
|
||||
}
|
||||
|
||||
static void SayHelloEventLog()
|
||||
{
|
||||
auto logger = AuLog::NewLoggerShared(AuList<AuSPtr<AuLog::IBasicSink>>{AuLog::NewOSNamedEventDirectorySinkShared("Aurora Demo")});
|
||||
|
||||
logger->LogInfo("hello 2+2={}", 2 + 2);
|
||||
}
|
||||
|
||||
void RunTests()
|
||||
{
|
||||
Aurora::RuntimeStartInfo info;
|
||||
info.console.fio.enableLogging = false;
|
||||
info.console.forceToolKitWindow = false;
|
||||
Aurora::RuntimeStart(info);
|
||||
|
||||
SayHelloEventLog();
|
||||
WriteHelloToEventLogGlobal();
|
||||
}
|
@ -93,6 +93,7 @@ static void TestBasicCompression(AuCompression::ECompresionType type)
|
||||
{
|
||||
auto compressMeBytes = GetCompressableBlob();
|
||||
|
||||
// Legacy API
|
||||
AuIO::Buffered::BlobWriter compressed;
|
||||
{
|
||||
AuIO::Buffered::BlobReader reader(AuMove(compressMeBytes));
|
||||
@ -118,6 +119,7 @@ static void TestBasicCompression(AuCompression::ECompresionType type)
|
||||
ASSERT_TRUE(AuCompression::Compress(pipe, info));
|
||||
}
|
||||
|
||||
// Legacy API
|
||||
AuIO::Buffered::BlobWriter decompressed;
|
||||
{
|
||||
AuIO::Buffered::BlobReader reader(compressed.GetBuffer());
|
||||
@ -145,6 +147,7 @@ static void TestBasicCompression(AuCompression::ECompresionType type)
|
||||
|
||||
ASSERT_EQ(compressMeBytes, *decompressed.GetBuffer());
|
||||
|
||||
// New API
|
||||
{
|
||||
auto decompressLength = decompressed.GetBuffer()->size();
|
||||
|
||||
|
302
Tests/Public/7. Hello Parse/Main.cpp
Normal file
302
Tests/Public/7. Hello Parse/Main.cpp
Normal file
@ -0,0 +1,302 @@
|
||||
/***
|
||||
Copyright (C) 2020-2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: Main.cpp
|
||||
Date: 2020-11-14
|
||||
Author: Reece
|
||||
Note: Yes, this test is from gen 1, 2020. feelsoldman
|
||||
***/
|
||||
#include <AuroraRuntime.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Parse, EncapsulatedString)
|
||||
{
|
||||
AuLogInfo("Testing encapsulated string");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseNumber, "Bravo"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "String"),
|
||||
};
|
||||
|
||||
AuString str = "4 5.3 \"hello\"";
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
const auto &array = res.result;
|
||||
ASSERT_EQ(array.size(), 3);
|
||||
|
||||
auto ia = array[0].value.single.primitive.uint;
|
||||
auto ib = array[1].value.single.primitive.number;
|
||||
auto str2 = array[2].value.single.string;
|
||||
|
||||
AuLogDbg("Got: a: {}, b: {}, c: {}", ia, ib, str2);
|
||||
|
||||
ASSERT_EQ(ia, 4);
|
||||
ASSERT_EQ(ib, 5.3);
|
||||
ASSERT_EQ(str2, "hello");
|
||||
}
|
||||
|
||||
TEST(Parse, BrokenString)
|
||||
{
|
||||
AuLogWarn("Testing broken string (IGNORE WARNINGS)");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseNumber, "Bravo"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "String"),
|
||||
};
|
||||
|
||||
AuString str = "4 5.3 \"hello";
|
||||
AuMach offset = 0;
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_FALSE(AuParse::Parse(res, exampleStructure, str));
|
||||
}
|
||||
|
||||
TEST(Parse, BrokenIntegerLiteral)
|
||||
{
|
||||
AuLogInfo("Testing bad integer literal failure (IGNORE WARNINGS)");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha")
|
||||
};
|
||||
|
||||
AuString str = "hello";
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_FALSE(AuParse::Parse(res, exampleStructure, str));
|
||||
}
|
||||
|
||||
TEST(Parse, Vararg)
|
||||
{
|
||||
AuLogInfo("Testing variable arrays [string]");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseNumber, "Bravo"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "String", false, false, true)
|
||||
};
|
||||
|
||||
AuString str = "4 5.3 \"re eee\" hello world";
|
||||
AuMach offset = 0;
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
ASSERT_EQ(res.result.size(), 3);
|
||||
|
||||
const auto & result = res.result[2];
|
||||
const auto & array = result.value.array;
|
||||
|
||||
ASSERT_EQ(array.size(), result.count);
|
||||
ASSERT_EQ(result.count, 3);
|
||||
|
||||
ASSERT_EQ(array[0].string, "re eee");
|
||||
ASSERT_EQ(array[1].string, "hello");
|
||||
ASSERT_EQ(array[2].string, "world");
|
||||
}
|
||||
|
||||
TEST(Parse, Arrays)
|
||||
{
|
||||
AuLogInfo("Testing length prefixed arrays");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Int Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "String Fren", true, false, false)
|
||||
};
|
||||
|
||||
AuString str = "4 3 \"re eee\" hello world";
|
||||
AuMach offset = 0;
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
ASSERT_EQ(res.result.size(), 2);
|
||||
|
||||
const auto &result = res.result[1];
|
||||
const auto &array = result.value.array;
|
||||
ASSERT_EQ(array.size(), result.count);
|
||||
ASSERT_EQ(result.count, 3);
|
||||
|
||||
ASSERT_EQ(array[0].string, "re eee");
|
||||
ASSERT_EQ(array[1].string, "hello");
|
||||
ASSERT_EQ(array[2].string, "world");
|
||||
|
||||
AuString reserialized = "";
|
||||
str = "4 3 \"re eee\" \"hello\" \"world\"";
|
||||
AuParse::Serialize(res.result, reserialized);
|
||||
ASSERT_EQ(reserialized, str);
|
||||
}
|
||||
|
||||
TEST(Parse, ArraysReserialize)
|
||||
{
|
||||
AuLogInfo("Testing length prefixed arrays [reserialization]");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Int Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "String Fren", true, false, false)
|
||||
};
|
||||
|
||||
AuString reserialized;
|
||||
AuString str = "4 3 \"re eee\" hello world";
|
||||
AuMach offset = 0;
|
||||
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
str = "4 3 \"re eee\" \"hello\" \"world\"";
|
||||
|
||||
AuParse::Serialize(res.result, reserialized);
|
||||
ASSERT_EQ(reserialized, str);
|
||||
}
|
||||
|
||||
TEST(Parse, Optionals)
|
||||
{
|
||||
AuLogInfo("Testing optionals");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseNumber, "Bravo", false, true, false)
|
||||
};
|
||||
|
||||
AuString str_1 = "4 5.3";
|
||||
AuParse::ParseResult res_1;
|
||||
ASSERT_TRUE(AuParse::Parse(res_1, exampleStructure, str_1));
|
||||
ASSERT_EQ(res_1.result.size(), 2);
|
||||
|
||||
AuString str_2 = "4";
|
||||
AuParse::ParseResult res_2;
|
||||
ASSERT_TRUE(AuParse::Parse(res_2, exampleStructure, str_2));
|
||||
ASSERT_EQ(res_2.result.size(), 1);
|
||||
}
|
||||
|
||||
TEST(Parse, VarStrings)
|
||||
{
|
||||
AuLogInfo("Testing var strings");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseStringVararg, "String")
|
||||
};
|
||||
|
||||
AuString magic = "\"re eee\" hello world";
|
||||
AuString str = "4 " + magic;
|
||||
AuMach offset = 0;
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
ASSERT_EQ(res.result.size(), 2);
|
||||
|
||||
const auto &result = res.result[1];
|
||||
const auto &value = result.value.single;
|
||||
|
||||
ASSERT_EQ(result.count, 1);
|
||||
|
||||
ASSERT_EQ(value.string, magic);
|
||||
}
|
||||
|
||||
TEST(Parse, NewLine)
|
||||
{
|
||||
AuLogInfo("Testing newline");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "StringHog"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseStringVararg, "String")
|
||||
};
|
||||
|
||||
AuString magicStringEscaped = "\"world\nhello\"";
|
||||
AuString magicStringRaw = "world\nhello";
|
||||
|
||||
AuString magicEscaped = "\"re eee\" hello world\\\nhello";
|
||||
AuString magicRaw = "\"re eee\" hello world\nhello";
|
||||
|
||||
AuString str = "4 " + magicStringEscaped + " " + magicEscaped;
|
||||
AuMach offset = 0;
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
ASSERT_EQ(res.result.size(), 3);
|
||||
|
||||
const auto &resultString = res.result[1];
|
||||
const auto &valueString = resultString.value.single;
|
||||
ASSERT_EQ(resultString.count, 1);
|
||||
ASSERT_EQ(valueString.string, magicStringRaw);
|
||||
|
||||
const auto &resultVararg = res.result[2];
|
||||
const auto &valueVararg = resultVararg.value.single;
|
||||
ASSERT_EQ(resultVararg.count, 1);
|
||||
ASSERT_EQ(valueVararg.string, magicRaw);
|
||||
}
|
||||
|
||||
TEST(Parse, Escapes)
|
||||
{
|
||||
AuLogInfo("Testing escapes");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "StringHog"),
|
||||
};
|
||||
|
||||
AuString magicStringEscaped = "\"world \\\"hello\"";
|
||||
AuString magicStringRaw = "world \"hello";
|
||||
|
||||
AuString str = "4 " + magicStringEscaped;
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
ASSERT_EQ(res.result.size(), 2);
|
||||
|
||||
const auto& resultString = res.result[1];
|
||||
const auto& valueString = resultString.value.single;
|
||||
ASSERT_EQ(resultString.count, 1);
|
||||
ASSERT_EQ(valueString.string, magicStringRaw);
|
||||
|
||||
AuString reserialized;
|
||||
AuParse::Serialize(res.result, reserialized);
|
||||
ASSERT_EQ(reserialized, str);
|
||||
}
|
||||
|
||||
TEST(Parse, EscapesReserialize)
|
||||
{
|
||||
AuLogInfo("Testing escapes [reserialization]");
|
||||
|
||||
AuParse::ParseObject exampleStructure =
|
||||
{
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseUInt, "Alpha"),
|
||||
AuParse::ParseBit(AuParse::ParsableTag::kParseString, "StringHog"),
|
||||
};
|
||||
|
||||
AuString reserialized;
|
||||
AuString str = "3 \"world \\\"hello\"";
|
||||
AuParse::ParseResult res;
|
||||
|
||||
ASSERT_TRUE(AuParse::Parse(res, exampleStructure, str));
|
||||
|
||||
AuParse::Serialize(res.result, reserialized);
|
||||
ASSERT_EQ(reserialized, str);
|
||||
}
|
||||
|
||||
void RunTests()
|
||||
{
|
||||
Aurora::RuntimeStartInfo info;
|
||||
info.console.fio.enableLogging = false;
|
||||
info.console.forceToolKitWindow = false;
|
||||
Aurora::RuntimeStart(info);
|
||||
}
|
Loading…
Reference in New Issue
Block a user