+#include <iostream>\r
#include <irrlicht.h>\r
#include "exampleHelper.h"\r
\r
using namespace irr;\r
\r
-static video::E_DRIVER_TYPE chooseDriver(const char *arg_)\r
+static IrrlichtDevice *device = nullptr;\r
+static int test_fail = 0;\r
+\r
+void test_irr_array();\r
+void test_irr_string();\r
+\r
+static video::E_DRIVER_TYPE chooseDriver(core::stringc arg_)\r
{\r
- if (core::stringc(arg_) == "null")\r
+ if (arg_ == "null")\r
return video::EDT_NULL;\r
-\r
- if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES1))\r
+ if (arg_ == "ogles1")\r
return video::EDT_OGLES1;\r
- if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES2))\r
+ if (arg_ == "ogles2")\r
return video::EDT_OGLES2;\r
+ if (arg_ == "opengl")\r
+ return video::EDT_OPENGL;\r
+ if (arg_ == "opengl3")\r
+ return video::EDT_OPENGL3;\r
+ std::cerr << "Unknown driver type: " << arg_.c_str() << ". Trying OpenGL." << std::endl;\r
return video::EDT_OPENGL;\r
}\r
\r
+static inline void check(bool ok, const char *msg)\r
+{\r
+ if (!ok)\r
+ {\r
+ test_fail++;\r
+ device->getLogger()->log((core::stringc("FAILED TEST: ") + msg).c_str(), ELL_ERROR);\r
+ }\r
+}\r
+\r
+void run_unit_tests() {\r
+ std::cout << "Running unit tests:" << std::endl;\r
+ try {\r
+ test_irr_array();\r
+ test_irr_string();\r
+ } catch (const std::exception &e) {\r
+ std::cerr << e.what() << std::endl;\r
+ test_fail++;\r
+ }\r
+ std::cout << std::endl;\r
+}\r
+\r
int main(int argc, char *argv[])\r
{\r
+ run_unit_tests();\r
+\r
SIrrlichtCreationParameters p;\r
p.DriverType = chooseDriver(argc > 1 ? argv[1] : "");\r
p.WindowSize = core::dimension2du(640, 480);\r
p.Vsync = true;\r
p.LoggingLevel = ELL_DEBUG;\r
\r
- IrrlichtDevice *device = createDeviceEx(p);\r
+ device = createDeviceEx(p);\r
if (!device)\r
return 1;\r
\r
+ {\r
+ u32 total = 0;\r
+ device->getOSOperator()->getSystemMemory(&total, nullptr);\r
+ core::stringc message = core::stringc("Total RAM in MiB: ") + core::stringc(total >> 10);\r
+ device->getLogger()->log(message.c_str(), ELL_INFORMATION);\r
+ check(total > 130 * 1024, "RAM amount");\r
+ }\r
+\r
device->setWindowCaption(L"Hello World!");\r
device->setResizable(true);\r
\r
\r
const io::path mediaPath = getExampleMediaPath();\r
\r
- scene::IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "sydney.md2");\r
- if (!mesh)\r
- return 1;\r
- scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);\r
- if (node)\r
+ auto mesh_file = device->getFileSystem()->createAndOpenFile(mediaPath + "coolguy_opt.x");\r
+ check(mesh_file, "mesh file loading");\r
+ scene::IAnimatedMesh* mesh = smgr->getMesh(mesh_file);\r
+ check(mesh, "mesh loading");\r
+ if (mesh_file)\r
+ mesh_file->drop();\r
+ if (mesh)\r
{\r
- node->setMaterialFlag(video::EMF_LIGHTING, false);\r
- node->setMD2Animation(scene::EMAT_STAND);\r
- node->setMaterialTexture(0, driver->getTexture(mediaPath + "sydney.bmp"));\r
+ video::ITexture* tex = driver->getTexture(mediaPath + "cooltexture.png");\r
+ check(tex, "texture loading");\r
+ scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);\r
+ if (node)\r
+ {\r
+ node->setMaterialFlag(video::EMF_LIGHTING, false);\r
+ node->setFrameLoop(0, 29);\r
+ node->setAnimationSpeed(30);\r
+ node->setMaterialTexture(0, tex);\r
+ }\r
}\r
\r
- smgr->addCameraSceneNode(0, core::vector3df(0,30,-40), core::vector3df(0,5,0));\r
+ smgr->addCameraSceneNode(0, core::vector3df(0,4,5), core::vector3df(0,2,0));\r
\r
s32 n = 0;\r
SEvent event;\r
\r
while (device->run())\r
{\r
- if (device->getTimer()->getTime() >= 1300)\r
+ if (device->getTimer()->getTime() >= 1000)\r
{\r
device->getTimer()->setTime(0);\r
++n;\r
driver->endScene();\r
}\r
\r
- if (core::stringw(L"a") != editbox->getText()) {\r
- device->getLogger()->log("EditBox text mismatch", ELL_INFORMATION);\r
- return 1;\r
- }\r
+ check(core::stringw(L"a") == editbox->getText(), "EditBox text");\r
\r
device->getLogger()->log("Done.", ELL_INFORMATION);\r
device->drop();\r
- return 0;\r
+ return test_fail > 0 ? 1 : 0;\r
}\r