diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-21 19:00:45 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-21 19:44:57 +0530 |
| commit | 7ec8336431787156826185628ad3ee05dc327d2a (patch) | |
| tree | 0b984450aa1ee09f6592eadb898b17ffddd45219 /spec | |
| parent | fdeb33d34a97d062a120f72da919f81d7b1d45bf (diff) | |
| download | null-browser-7ec8336431787156826185628ad3ee05dc327d2a.tar.gz null-browser-7ec8336431787156826185628ad3ee05dc327d2a.zip | |
Add event loop with uv
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/LuaRuntimeSpec.cpp | 76 | ||||
| -rw-r--r-- | spec/main.cpp | 2 |
2 files changed, 76 insertions, 2 deletions
diff --git a/spec/LuaRuntimeSpec.cpp b/spec/LuaRuntimeSpec.cpp new file mode 100644 index 0000000..149e1e1 --- /dev/null +++ b/spec/LuaRuntimeSpec.cpp @@ -0,0 +1,76 @@ +#include "testUtils.h" +#include <QtCore> +#include <atomic> +#include <uv.h> + +#include "LuaRuntime.hpp" + +class LuaRuntimeSpec : public QObject { + Q_OBJECT + +private slots: + void cleanupTestCase() { uv_library_shutdown(); } + + void testSanityCheckBuiltins() { + auto lua = LuaRuntime::instance(); + + it("evaluates simple expression") { + lua->startEventLoop(); + std::atomic<int> foobar = 2; + + lua->queueTask([&foobar]() { foobar = 10; }); + + lua->evaluate(R"( + print('Hello -- '); + local timer = uv.new_timer(); + timer:start(1000, 0, function() + print('inside timer 1') + print('inside timer 2') + print('inside timer 3') + print('inside timer 4') + print('inside timer 5') + timer:close() + end); + print('-- end'); + )"); + lua->queueTask([]() { qDebug() << "---- 1"; }); + lua->queueTask([]() { qDebug() << "---- 2"; }); + lua->queueTask([]() { qDebug() << "---- 3"; }); + std::this_thread::sleep_for(std::chrono::seconds(2)); + // std::this_thread::sleep_for(std::chrono::milliseconds(20)); + lua->stopEventLoop(); + + qDebug() << "foobar" << foobar; + + QCOMPARE(1, 1); + } + } + + void testSanityCheckBuiltins2() { + auto lua = LuaRuntime::instance(); + + it("evaluates again") { + lua->startEventLoop(); + + lua->queueTask([]() { qDebug() << "---- 5"; }); + lua->evaluate(R"( + print('Hello -- '); + local timer = uv.new_timer(); + timer:start(1000, 0, function() + print('%%%%% blagb') + timer:close() + end); + print('-- end'); + )"); + lua->queueTask([]() { qDebug() << "---- 5"; }); + // TODO: Impl + std::this_thread::sleep_for(std::chrono::seconds(2)); + lua->stopEventLoop(); + + QCOMPARE(1, 1); + } + } +}; + +QTEST_REGISTER(LuaRuntimeSpec) +#include "LuaRuntimeSpec.moc" diff --git a/spec/main.cpp b/spec/main.cpp index f238e70..352ecba 100644 --- a/spec/main.cpp +++ b/spec/main.cpp @@ -4,7 +4,5 @@ int main(int argc, char **argv) { QApplication app(argc, argv); - printf("foobar"); - return runAllTests(); } |
