Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Lua unit tests #5117

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions azure-pipelines/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ stages:
displayName: 'Generate test locales'
- bash: |
cmake --build . --target test-units
Xvfb :99 &
export DISPLAY=:99
sleep 3 # give xvfb some time to start
CI=true ctest --verbose
workingDirectory: ./build
displayName: 'Run tests'
Expand Down
2 changes: 1 addition & 1 deletion src/core/gui/GladeGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GladeGui::GladeGui(GladeSearchpath* gladeSearchPath, const std::string& glade, c

GladeGui::~GladeGui() {
if (!gtk_widget_get_parent(window)) {
gtk_widget_destroy(window);
// gtk_widget_destroy(window);
}
}

Expand Down
79 changes: 79 additions & 0 deletions test/unit_tests/lua/LuaTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Xournal++
*
* This file is part of the Xournal UnitTests
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/

#include <cstdint>

#include <config-test.h>
#include <gio/gio.h> // for GApplication, G_APPLICATION
#include <glib-object.h> // for G_CALLBACK, g_signal_con...
#include <glib.h>
#include <gtest/gtest.h>

#include "control/Control.h"
#include "control/jobs/XournalScheduler.h" // for XournalScheduler
#include "gui/GladeSearchpath.h" // for GladeSearchpath

extern "C" {
#include <lauxlib.h> // for luaL_Reg, luaL_newstate, luaL_requiref
#include <lua.h> // for lua_getglobal, lua_getfield, lua_setf...
#include <lualib.h> // for luaL_openlibs
}

#include "plugin/luapi_application.h" // for luaopen_app


struct Data {
Data() = default;
Data(Data&&) = delete;
Data(Data const&) = delete;
auto operator=(Data&&) -> Data = delete;
auto operator=(Data const&) -> Data = delete;

~Data() {}

std::unique_ptr<GladeSearchpath> gladePath;
std::unique_ptr<Control> control;
std::unique_ptr<MainWindow> win;
};

void on_activate(GtkApplication* app, Data* data) {
auto uiPath = fs::path(PROJECT_SOURCE_DIR) / "ui";
data->gladePath = std::make_unique<GladeSearchpath>();
data->gladePath->addSearchDirectory(uiPath);

data->control = std::make_unique<Control>(G_APPLICATION(app), data->gladePath.get(), true);
data->win = std::make_unique<MainWindow>(data->gladePath.get(), data->control.get(), app);
data->control->initWindow(data->win.get());
data->control->getScheduler()->start();
Util::execInUiThread([=]() { data->control->getWindow()->getXournal()->layoutPages(); });
gtk_application_add_window(app, GTK_WINDOW(data->win->getWindow()));

data->win->show(nullptr);
data->control->addDefaultPage("");

auto pluginPath = fs::path(PROJECT_SOURCE_DIR) / "test" / "unit_tests" / "lua";
auto plugin = std::make_unique<Plugin>(data->control.get(), pluginPath.filename().string(), pluginPath);
ASSERT_TRUE(plugin->isValid());
plugin->loadScript();

g_application_quit(G_APPLICATION(app));
}

void on_shutdown(GApplication*, Data* data) { data->control->getScheduler()->stop(); }

TEST(LuaTest, testPage) {
Data data;
GtkApplication* app = gtk_application_new("com.github.xournalpp.xournalpp", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(&on_activate), &data);
g_signal_connect(app, "shutdown", G_CALLBACK(&on_shutdown), &data);
g_application_run(G_APPLICATION(app), 0, NULL);
g_object_unref(app);
}