Initial test bootstrap.
This commit is contained in:
parent
6c618749f1
commit
4b308f6c32
94 changed files with 2543 additions and 681 deletions
|
@ -4,6 +4,7 @@ set(UNIT_TEST_TARGETS)
|
|||
set(INTEGRATION_TEST_TARGETS)
|
||||
|
||||
add_subdirectory(core)
|
||||
#add_subdirectory(console)
|
||||
add_subdirectory(database)
|
||||
add_subdirectory(fonts)
|
||||
add_subdirectory(geometry)
|
||||
|
@ -18,6 +19,7 @@ set(TEST_MODULES
|
|||
audio
|
||||
compiler
|
||||
compression
|
||||
console
|
||||
image
|
||||
ipc
|
||||
mesh
|
||||
|
|
23
test/bootstrap_tests.sh
Executable file
23
test/bootstrap_tests.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
|
||||
CORE_SRC_DIR=$SCRIPT_DIR/../src/base/core
|
||||
|
||||
g++ $SCRIPT_DIR/test_runner.cpp \
|
||||
$SCRIPT_DIR/../src/base/core/CommandLineArgs.cpp \
|
||||
$CORE_SRC_DIR/base_types/Error.cpp \
|
||||
$CORE_SRC_DIR/base_types/Index.cpp \
|
||||
$CORE_SRC_DIR/data_structures/String.cpp \
|
||||
$CORE_SRC_DIR/file_utilities/FileSystemPath.cpp \
|
||||
$CORE_SRC_DIR/loggers/ConsoleLogger.cpp \
|
||||
$SCRIPT_DIR/test_utils/TestCaseRunner.cpp \
|
||||
$SCRIPT_DIR/core/TestString.cpp \
|
||||
$SCRIPT_DIR/core/TestVector.cpp \
|
||||
-o bootstrap_tests -g \
|
||||
-I$SCRIPT_DIR/test_utils \
|
||||
-I$CORE_SRC_DIR \
|
||||
-I$CORE_SRC_DIR/encoding \
|
||||
-I$CORE_SRC_DIR/loggers \
|
||||
-I$CORE_SRC_DIR/data_structures \
|
||||
-I$CORE_SRC_DIR/base_types \
|
||||
-I$CORE_SRC_DIR/memory \
|
||||
-I$CORE_SRC_DIR/file_utilities
|
9
test/console/CMakeLists.txt
Normal file
9
test/console/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
include(TestTargets)
|
||||
|
||||
unit_tests(
|
||||
MODULE_NAME console
|
||||
FILES
|
||||
TestConsoleApp.cpp
|
||||
DEPENDENCIES
|
||||
console
|
||||
)
|
93
test/console/TestConsoleApp.cpp
Normal file
93
test/console/TestConsoleApp.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
#include "TermInfo.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/select.h>
|
||||
#include <termios.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
TEST_CASE(TestConsoleApp, "console")
|
||||
{
|
||||
//std::cout << "Hi from test console\n";
|
||||
|
||||
int ttyfd = open("/dev/tty", O_RDWR);
|
||||
if (ttyfd > 0)
|
||||
{
|
||||
std::cout << "opened tty ok\n" << std::endl;
|
||||
}
|
||||
|
||||
if (isatty(ttyfd))
|
||||
{
|
||||
auto tty_name = ttyname(ttyfd);
|
||||
std::string tty_name_str;
|
||||
if (tty_name != nullptr)
|
||||
{
|
||||
tty_name_str = std::string(tty_name);
|
||||
}
|
||||
|
||||
std::string fd_msg = "Hello tty: '" + tty_name_str + "'\n";
|
||||
//write(ttyfd, fd_msg.data(), fd_msg.size());
|
||||
|
||||
TermInfo term_info;
|
||||
term_info.load();
|
||||
/*
|
||||
|
||||
termios orig_tios;
|
||||
tcgetattr(ttyfd, &orig_tios);
|
||||
|
||||
termios tios;
|
||||
memcpy(&tios, &orig_tios, sizeof(tios));
|
||||
|
||||
cfmakeraw(&tios);
|
||||
tios.c_cc[VMIN] = 1;
|
||||
tios.c_cc[VTIME] = 0;
|
||||
|
||||
tcsetattr(ttyfd, TCSAFLUSH, &tios);
|
||||
|
||||
//int cap_enter_ca = 23;
|
||||
//int cap_exit_ca = 24;
|
||||
//int cap_hide_cursor = 26;
|
||||
//int cap_clear_screen = 27;
|
||||
|
||||
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
|
||||
int timeout = 2000;
|
||||
timeval tv;
|
||||
tv.tv_sec = timeout/1000;
|
||||
tv.tv_usec = (timeout - (tv.tv_sec*1000))*1000;
|
||||
|
||||
while(true)
|
||||
{
|
||||
|
||||
int select_rv = select(1, &fds, nullptr, nullptr, &tv);
|
||||
|
||||
if (select_rv == 0)
|
||||
{
|
||||
std::cout << "timeout" << std::endl;
|
||||
break;
|
||||
}
|
||||
std::vector<char> buffer(100);
|
||||
auto read_size = read(ttyfd, buffer.data(), buffer.size());
|
||||
std::string out(buffer.begin(), buffer.begin()+read_size);
|
||||
std::cout << "buf: " << out << std::endl;
|
||||
}
|
||||
std::cout << "loop break" << std::endl;
|
||||
tcsetattr(ttyfd, TCSAFLUSH, &orig_tios);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
close(ttyfd);
|
||||
}
|
|
@ -1,8 +1,43 @@
|
|||
#include "StringUtils.h"
|
||||
#include "String.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
//#include "TestUtils.h"
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE(TestBasicStringOps, "core")
|
||||
{
|
||||
String str;
|
||||
str += 'a';
|
||||
str += 'b';
|
||||
str += 'c';
|
||||
str += 'd';
|
||||
REQUIRE(str == "abcd");
|
||||
}
|
||||
|
||||
TEST_CASE(TestStringReverse, "core")
|
||||
{
|
||||
String str0;
|
||||
str0.reverse();
|
||||
REQUIRE(str0.empty());
|
||||
|
||||
String str1("a");
|
||||
str1.reverse();
|
||||
REQUIRE(str1 == "a");
|
||||
|
||||
String str2("ab");
|
||||
str2.reverse();
|
||||
REQUIRE(str2 == "ba");
|
||||
|
||||
String str3("abc");
|
||||
str3.reverse();
|
||||
REQUIRE(str3 == "cba");
|
||||
|
||||
String str4("abcd");
|
||||
str4.reverse();
|
||||
REQUIRE(str4 == "dcba");
|
||||
}
|
||||
|
||||
/*
|
||||
TEST_CASE(TestStringUtils_StripSurroundingWhitepsace, "core")
|
||||
{
|
||||
std::string input = " super() ";
|
||||
|
@ -28,3 +63,5 @@ TEST_CASE(TestStringUtils_startsWith, "core")
|
|||
starts_with = StringUtils::startsWith(input, "```", ignore_whitespace);
|
||||
REQUIRE(starts_with);
|
||||
}
|
||||
|
||||
*/
|
18
test/core/TestVector.cpp
Normal file
18
test/core/TestVector.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "Vector.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
TEST_CASE(TestVectorOps, "core")
|
||||
{
|
||||
Vector<size_t> vec;
|
||||
for(size_t idx=0;idx<100;idx++)
|
||||
{
|
||||
vec.push_back(idx);
|
||||
}
|
||||
for(size_t idx=0; idx<100; idx++)
|
||||
{
|
||||
REQUIRE(vec[idx] == idx);
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
#include "TestUtils.h"
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE(TestCompressedPng, "image")
|
||||
TEST_CASE(TestUncompressedPng, "image")
|
||||
{
|
||||
unsigned width = 20;
|
||||
unsigned height = 20;
|
||||
|
@ -30,13 +30,14 @@ TEST_CASE(TestCompressedPng, "image")
|
|||
image->getGridT<unsigned char>()->setData(data);
|
||||
|
||||
PngWriter writer;
|
||||
//writer.setCompressionMethod(Deflate::CompressionMethod::NONE);
|
||||
writer.write(TestUtils::getTestOutputDir() / "test_compressed.png", image.get());
|
||||
writer.setCompressionMethod(Deflate::CompressionMethod::NONE);
|
||||
writer.write(TestUtils::getTestOutputDir(__FILE__) / "test_uncompressed.png", image.get());
|
||||
|
||||
return;
|
||||
File test_file(TestUtils::getTestOutputDir() / "test_compressed.png");
|
||||
File test_file(TestUtils::getTestOutputDir(__FILE__) / "test_uncompressed.png");
|
||||
test_file.open(File::AccessMode::Read);
|
||||
|
||||
std::cout << test_file.dumpBinary();
|
||||
return;
|
||||
while(auto byte = test_file.readNextByte())
|
||||
{
|
||||
//std::cout << static_cast<unsigned>(*byte) << std::endl;
|
||||
|
@ -63,13 +64,8 @@ TEST_CASE(TestFixedPng, "image")
|
|||
image->getGridT<unsigned char>()->setData(data);
|
||||
|
||||
PngWriter writer;
|
||||
//writer.setCompressionMethod(Deflate::CompressionMethod::FIXED_HUFFMAN);
|
||||
writer.write(TestUtils::getTestOutputDir() / "test_fixed.png", image.get());
|
||||
|
||||
//return;
|
||||
File test_file(TestUtils::getTestOutputDir() / "test_fixed.png");
|
||||
//std::cout << test_file.dumpBinary();
|
||||
|
||||
writer.setCompressionMethod(Deflate::CompressionMethod::FIXED_HUFFMAN);
|
||||
writer.write(TestUtils::getTestOutputDir(__FILE__) / "test_fixed.png", image.get());
|
||||
}
|
||||
|
||||
TEST_CASE(TestDynamicCompressedPng, "image")
|
||||
|
@ -93,9 +89,9 @@ TEST_CASE(TestDynamicCompressedPng, "image")
|
|||
|
||||
PngWriter writer;
|
||||
//writer.setPath(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
||||
writer.write(TestUtils::getTestOutputDir() / "test_dynamic.png", image.get());
|
||||
writer.write(TestUtils::getTestOutputDir(__FILE__) / "test_dynamic.png", image.get());
|
||||
|
||||
//return;
|
||||
File test_file(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
||||
File test_file(TestUtils::getTestOutputDir(__FILE__) / "test_dynamic.png");
|
||||
//std::cout << test_file.dumpBinary();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "TestFramework.h"
|
||||
|
||||
#include "CommandLineArgs.h"
|
||||
#include "ConsoleLogger.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
@ -13,10 +14,12 @@ int main(int argc, char *argv[])
|
|||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
#endif
|
||||
|
||||
auto args = CommandLineArgs::Create();
|
||||
args->process(argc, argv);
|
||||
CommandLineArgs args;
|
||||
args.process(argc, argv);
|
||||
|
||||
TestCaseRunner::getInstance().run(args->getUserArgs());
|
||||
ConsoleLogger::logLine("Starting test run.");
|
||||
TestCaseRunner::getInstance().run(args.getUserArgs());
|
||||
ConsoleLogger::logLine("Finished test run.");
|
||||
|
||||
#ifdef _WIN32
|
||||
CoUninitialize();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "String.h"
|
||||
#include "Pointer.h"
|
||||
#include <functional>
|
||||
|
||||
class TestCase
|
||||
|
@ -9,7 +9,7 @@ class TestCase
|
|||
public:
|
||||
using TestCaseFunction = std::function<void()>;
|
||||
|
||||
TestCase(const std::string& name, const std::string& tags, TestCaseFunction func)
|
||||
TestCase(const String& name, const String& tags, TestCaseFunction func)
|
||||
: mTestFunction(func),
|
||||
mName(name),
|
||||
mTags(tags)
|
||||
|
@ -19,12 +19,12 @@ public:
|
|||
|
||||
virtual ~TestCase() = default;
|
||||
|
||||
const std::string& getName() const
|
||||
const String& getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
const std::string& getTags() const
|
||||
const String& getTags() const
|
||||
{
|
||||
return mTags;
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ public:
|
|||
TestCaseFunction mTestFunction{nullptr};
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mTags;
|
||||
String mName;
|
||||
String mTags;
|
||||
|
||||
};
|
||||
using TestCasePtr = std::unique_ptr<TestCase>;
|
||||
using TestCasePtr = Ptr<TestCase>;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
#include "TestCaseRunner.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
#include "TestUiApplication.h"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "ConsoleLogger.h"
|
||||
//#include "TestUiApplication.h"
|
||||
|
||||
bool TestCaseRunner::sLastTestFailed = false;
|
||||
std::string TestCaseRunner::sFailureLine = {};
|
||||
String TestCaseRunner::sFailureLine = {};
|
||||
|
||||
TestCaseRunner::TestCaseRunner()
|
||||
{
|
||||
|
@ -19,6 +17,7 @@ TestCaseRunner::~TestCaseRunner()
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
TestUiApplication* TestCaseRunner::getTestApplication()
|
||||
{
|
||||
return mTestApplication;
|
||||
|
@ -28,6 +27,7 @@ void TestCaseRunner::setTestApplication(TestUiApplication* app)
|
|||
{
|
||||
mTestApplication = app;
|
||||
}
|
||||
*/
|
||||
|
||||
TestCaseRunner& TestCaseRunner::getInstance()
|
||||
{
|
||||
|
@ -35,26 +35,26 @@ TestCaseRunner& TestCaseRunner::getInstance()
|
|||
return instance;
|
||||
}
|
||||
|
||||
void TestCaseRunner::addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func)
|
||||
void TestCaseRunner::addTestCase(const String& label, const String& tag, TestCase::TestCaseFunction func)
|
||||
{
|
||||
auto test_case = new TestCase(label, tag, func);
|
||||
mCases.push_back(test_case);
|
||||
}
|
||||
|
||||
void TestCaseRunner::markTestFailure(const std::string& line)
|
||||
void TestCaseRunner::markTestFailure(const String& line)
|
||||
{
|
||||
sLastTestFailed = true;
|
||||
sFailureLine = line;
|
||||
}
|
||||
|
||||
bool TestCaseRunner::run(const std::vector<std::string>& args)
|
||||
bool TestCaseRunner::run(const Vector<String>& args)
|
||||
{
|
||||
std::string test_to_run;
|
||||
String test_to_run;
|
||||
if (args.size() > 0 )
|
||||
{
|
||||
test_to_run = args[0];
|
||||
}
|
||||
FileLogger::GetInstance().disable();
|
||||
//FileLogger::GetInstance().disable();
|
||||
for (auto test_case : mCases)
|
||||
{
|
||||
if (!test_to_run.empty())
|
||||
|
@ -66,41 +66,22 @@ bool TestCaseRunner::run(const std::vector<std::string>& args)
|
|||
}
|
||||
|
||||
sLastTestFailed = false;
|
||||
std::cout << "TestFramework: Running Test - " << test_case->getName() << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
test_case->run();
|
||||
}
|
||||
catch (const std::runtime_error& re)
|
||||
{
|
||||
std::cout << "Failed with runtime error: " << re.what() << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cout << "Failed with exception: " << e.what() << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cout << "Failed with unknown exception" << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
};
|
||||
|
||||
ConsoleLogger::logLine("TestFramework: Running Test - %s", test_case->getName().raw());
|
||||
test_case->run();
|
||||
|
||||
if (sLastTestFailed)
|
||||
{
|
||||
std::cout << "Failed at line: " << sFailureLine << std::endl;
|
||||
ConsoleLogger::logLine("Failed at line %s", sFailureLine.raw());
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (mFailingTests.size() > 0)
|
||||
{
|
||||
std::cout << mFailingTests.size() << " failing tests: " << std::endl;
|
||||
ConsoleLogger::logLine("%d failing tests", mFailingTests.size());
|
||||
for(const auto& name : mFailingTests)
|
||||
{
|
||||
std::cout << name << std::endl;
|
||||
ConsoleLogger::logLine(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include "TestCase.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Vector.h"
|
||||
#include "String.h"
|
||||
|
||||
class TestUiApplication;
|
||||
|
||||
|
@ -16,20 +16,20 @@ public:
|
|||
|
||||
~TestCaseRunner();
|
||||
|
||||
TestUiApplication* getTestApplication();
|
||||
//TestUiApplication* getTestApplication();
|
||||
|
||||
void addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func);
|
||||
void addTestCase(const String& label, const String& tag, TestCase::TestCaseFunction func);
|
||||
|
||||
void markTestFailure(const std::string& line);
|
||||
void markTestFailure(const String& line);
|
||||
|
||||
bool run(const std::vector<std::string>& args);
|
||||
bool run(const Vector<String>& args);
|
||||
|
||||
void setTestApplication(TestUiApplication* app);
|
||||
//void setTestApplication(TestUiApplication* app);
|
||||
private:
|
||||
|
||||
TestUiApplication* mTestApplication{ nullptr };
|
||||
std::vector<std::string> mFailingTests;
|
||||
//TestUiApplication* mTestApplication{ nullptr };
|
||||
Vector<String> mFailingTests;
|
||||
static bool sLastTestFailed;
|
||||
static std::string sFailureLine;
|
||||
std::vector<TestCase*> mCases;
|
||||
static String sFailureLine;
|
||||
Vector<TestCase*> mCases;
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
struct Holder
|
||||
{
|
||||
Holder(const std::string& name, const std::string& tags, std::function<void()> func)
|
||||
Holder(const String& name, const String& tags, std::function<void()> func)
|
||||
{
|
||||
TestCaseRunner::getInstance().addTestCase(name, tags, func);
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ struct Holder
|
|||
#define REQUIRE(predicate) \
|
||||
if(!bool(predicate)) \
|
||||
{ \
|
||||
TestCaseRunner::getInstance().markTestFailure(std::to_string(__LINE__) + " with check: '" + std::string(#predicate) + "'"); \
|
||||
return; \
|
||||
const auto msg = String::to_string(__LINE__) + String(" with check: '") + String(#predicate) + String("'"); \
|
||||
TestCaseRunner::getInstance().markTestFailure(msg); \
|
||||
} \
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "TestDataLocations.h"
|
||||
//#include "TestDataLocations.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
|
|
|
@ -16,5 +16,5 @@ TEST_CASE(TestWaylandWindow, "web")
|
|||
//app->setUiInterfaceBackend(UiInterfaceFactory::Backend::WAYLAND);
|
||||
app->setUiInterfaceBackend(UiInterfaceFactory::Backend::WAYLAND_RASTER);
|
||||
|
||||
app->run();
|
||||
//app->run();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue