From 2461e899ba9046d406248216d92f5ac11a02e6d2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 22 Apr 2021 10:46:31 +0200 Subject: [PATCH] Add basic test application that runs under CI --- .github/workflows/build.yml | 18 +++-- examples/AutomatedTest/main.cpp | 112 ++++++++++++++++++++++++++++++++ examples/CMakeLists.txt | 3 + 3 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 examples/AutomatedTest/main.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea1ca207..27a71d1f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: - name: Build run: | cmake . - make + make -j2 - name: Package run: | @@ -36,14 +36,24 @@ jobs: - uses: actions/checkout@v2 - name: Install deps run: | - sudo apt-get install g++ cmake libxxf86vm-dev libgles2-mesa-dev libpng-dev libjpeg-dev zlib1g-dev -qyy + sudo apt-get install g++ cmake libxxf86vm-dev libgles2-mesa-dev libpng-dev libjpeg-dev zlib1g-dev xvfb -qyy - name: Build run: | sed '/#define _IRR_COMPILE_WITH_OGLES2_/ s|^//||g' -i include/IrrCompileConfig.h sed '/#define _IRR_COMPILE_WITH_OPENGL_/ s|^|//|g' -i include/IrrCompileConfig.h - cmake . - make + cmake . -DBUILD_EXAMPLES=1 + make -j2 + + - name: Test (headless) + run: | + cd bin/Linux + ./AutomatedTest null + + - name: Test (Xvfb) + run: | + cd bin/Linux + LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest win32: runs-on: ubuntu-18.04 diff --git a/examples/AutomatedTest/main.cpp b/examples/AutomatedTest/main.cpp new file mode 100644 index 00000000..b155696c --- /dev/null +++ b/examples/AutomatedTest/main.cpp @@ -0,0 +1,112 @@ +#include +#include "exampleHelper.h" + +using namespace irr; + +static video::E_DRIVER_TYPE chooseDriver(const char *arg_) +{ + if (core::stringc(arg_) == "null") + return video::EDT_NULL; + + if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES1)) + return video::EDT_OGLES1; + if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES2)) + return video::EDT_OGLES2; + return video::EDT_OPENGL; +} + +int main(int argc, char *argv[]) +{ + SIrrlichtCreationParameters p; + p.DriverType = chooseDriver(argc > 1 ? argv[1] : ""); + p.WindowSize = core::dimension2du(640, 480); + p.Vsync = true; + p.LoggingLevel = ELL_DEBUG; + + IrrlichtDevice *device = createDeviceEx(p); + if (!device) + return 1; + + device->setWindowCaption(L"Hello World!"); + device->setResizable(true); + + video::IVideoDriver* driver = device->getVideoDriver(); + scene::ISceneManager* smgr = device->getSceneManager(); + gui::IGUIEnvironment* guienv = device->getGUIEnvironment(); + + guienv->addStaticText(L"sample text", core::rect(10,10,110,22), false); + + gui::IGUIButton* button = guienv->addButton( + core::rect(10,30,110,30 + 32), 0, -1, L"sample button", + L"sample tooltip"); + + gui::IGUIEditBox* editbox = guienv->addEditBox(L"", + core::rect(10,70,60,70 + 16)); + + const io::path mediaPath = getExampleMediaPath(); + + scene::IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "sydney.md2"); + if (!mesh) + return 1; + scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh); + if (node) + { + node->setMaterialFlag(video::EMF_LIGHTING, false); + node->setMD2Animation(scene::EMAT_STAND); + node->setMaterialTexture(0, driver->getTexture(mediaPath + "sydney.bmp")); + } + + smgr->addCameraSceneNode(0, core::vector3df(0,30,-40), core::vector3df(0,5,0)); + + s32 n = 0; + SEvent event; + device->getTimer()->start(); + + while (device->run()) + { + if (device->getTimer()->getTime() >= 1300) + { + device->getTimer()->setTime(0); + ++n; + if (n == 1) // Tooltip display + { + bzero(&event, sizeof(SEvent)); + event.EventType = irr::EET_MOUSE_INPUT_EVENT; + event.MouseInput.Event = irr::EMIE_MOUSE_MOVED; + event.MouseInput.X = button->getAbsolutePosition().getCenter().X; + event.MouseInput.Y = button->getAbsolutePosition().getCenter().Y; + device->postEventFromUser(event); + } + else if (n == 2) // Text input focus + guienv->setFocus(editbox); + else if (n == 3) // Keypress for Text input + { + bzero(&event, sizeof(SEvent)); + event.EventType = irr::EET_KEY_INPUT_EVENT; + event.KeyInput.Char = L'a'; + event.KeyInput.Key = KEY_KEY_A; + event.KeyInput.PressedDown = true; + device->postEventFromUser(event); + event.KeyInput.PressedDown = false; + device->postEventFromUser(event); + } + else + device->closeDevice(); + } + + driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, + video::SColor(255,100,100,150)); + smgr->drawAll(); + guienv->drawAll(); + driver->endScene(); + } + + if (core::stringw(L"a") != editbox->getText()) { + device->getLogger()->log("EditBox text mismatch", ELL_INFORMATION); + return 1; + } + + device->getLogger()->log("Done.", ELL_INFORMATION); + device->drop(); + return 0; +} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e35f38cf..aca268b4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -32,6 +32,9 @@ set(IRREXAMPLES if(WIN32) list(APPEND IRREXAMPLES 14.Win32Window) endif() +if(UNIX) + list(APPEND IRREXAMPLES AutomatedTest) +endif() foreach(exname IN ITEMS ${IRREXAMPLES}) file(GLOB sources "${CMAKE_CURRENT_SOURCE_DIR}/${exname}/*.cpp")