mirror of
https://github.com/minetest/irrlicht.git
synced 2025-06-29 14:50:30 +02:00
Reformat the code, using:
find -type f | # list all regular files grep -E '\.(h|cpp|mm)$' | # filter for source files grep -v '/mt_' | # filter out generated files grep -v '/vendor/' | # and vendored GL grep -v '/test/image_loader_test.cpp' | # and this file (has giant literals arrays) xargs -n 1 -P $(nproc) clang-format -i # reformat everything Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
@ -28,14 +28,14 @@ static video::E_DRIVER_TYPE chooseDriver(core::stringc arg_)
|
||||
|
||||
static inline void check(bool ok, const char *msg)
|
||||
{
|
||||
if (!ok)
|
||||
{
|
||||
if (!ok) {
|
||||
test_fail++;
|
||||
device->getLogger()->log((core::stringc("FAILED TEST: ") + msg).c_str(), ELL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void run_unit_tests() {
|
||||
void run_unit_tests()
|
||||
{
|
||||
std::cout << "Running unit tests:" << std::endl;
|
||||
try {
|
||||
test_irr_array();
|
||||
@ -72,35 +72,33 @@ int main(int argc, char *argv[])
|
||||
device->setWindowCaption(L"Hello World!");
|
||||
device->setResizable(true);
|
||||
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
scene::ISceneManager* smgr = device->getSceneManager();
|
||||
gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
|
||||
video::IVideoDriver *driver = device->getVideoDriver();
|
||||
scene::ISceneManager *smgr = device->getSceneManager();
|
||||
gui::IGUIEnvironment *guienv = device->getGUIEnvironment();
|
||||
|
||||
guienv->addStaticText(L"sample text", core::rect<s32>(10,10,110,22), false);
|
||||
guienv->addStaticText(L"sample text", core::rect<s32>(10, 10, 110, 22), false);
|
||||
|
||||
gui::IGUIButton* button = guienv->addButton(
|
||||
core::rect<s32>(10,30,110,30 + 32), 0, -1, L"sample button",
|
||||
L"sample tooltip");
|
||||
gui::IGUIButton *button = guienv->addButton(
|
||||
core::rect<s32>(10, 30, 110, 30 + 32), 0, -1, L"sample button",
|
||||
L"sample tooltip");
|
||||
|
||||
gui::IGUIEditBox* editbox = guienv->addEditBox(L"",
|
||||
core::rect<s32>(10,70,60,70 + 16));
|
||||
gui::IGUIEditBox *editbox = guienv->addEditBox(L"",
|
||||
core::rect<s32>(10, 70, 60, 70 + 16));
|
||||
|
||||
const io::path mediaPath = getExampleMediaPath();
|
||||
|
||||
auto mesh_file = device->getFileSystem()->createAndOpenFile(mediaPath + "coolguy_opt.x");
|
||||
check(mesh_file, "mesh file loading");
|
||||
scene::IAnimatedMesh* mesh = smgr->getMesh(mesh_file);
|
||||
scene::IAnimatedMesh *mesh = smgr->getMesh(mesh_file);
|
||||
check(mesh, "mesh loading");
|
||||
if (mesh_file)
|
||||
mesh_file->drop();
|
||||
if (mesh)
|
||||
{
|
||||
video::ITexture* tex = driver->getTexture(mediaPath + "cooltexture.png");
|
||||
if (mesh) {
|
||||
video::ITexture *tex = driver->getTexture(mediaPath + "cooltexture.png");
|
||||
check(tex, "texture loading");
|
||||
scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
|
||||
if (node)
|
||||
{
|
||||
node->forEachMaterial([tex] (video::SMaterial &mat) {
|
||||
scene::IAnimatedMeshSceneNode *node = smgr->addAnimatedMeshSceneNode(mesh);
|
||||
if (node) {
|
||||
node->forEachMaterial([tex](video::SMaterial &mat) {
|
||||
mat.Lighting = false;
|
||||
mat.setTexture(0, tex);
|
||||
});
|
||||
@ -109,16 +107,14 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
smgr->addCameraSceneNode(0, core::vector3df(0,4,5), core::vector3df(0,2,0));
|
||||
smgr->addCameraSceneNode(0, core::vector3df(0, 4, 5), core::vector3df(0, 2, 0));
|
||||
|
||||
s32 n = 0;
|
||||
SEvent event;
|
||||
device->getTimer()->start();
|
||||
|
||||
while (device->run())
|
||||
{
|
||||
if (device->getTimer()->getTime() >= 1000)
|
||||
{
|
||||
while (device->run()) {
|
||||
if (device->getTimer()->getTime() >= 1000) {
|
||||
device->getTimer()->setTime(0);
|
||||
++n;
|
||||
if (n == 1) // Tooltip display
|
||||
@ -129,8 +125,7 @@ int main(int argc, char *argv[])
|
||||
event.MouseInput.X = button->getAbsolutePosition().getCenter().X;
|
||||
event.MouseInput.Y = button->getAbsolutePosition().getCenter().Y;
|
||||
device->postEventFromUser(event);
|
||||
}
|
||||
else if (n == 2) // Text input focus
|
||||
} else if (n == 2) // Text input focus
|
||||
guienv->setFocus(editbox);
|
||||
else if (n == 3) // Keypress for Text input
|
||||
{
|
||||
@ -142,13 +137,12 @@ int main(int argc, char *argv[])
|
||||
device->postEventFromUser(event);
|
||||
event.KeyInput.PressedDown = false;
|
||||
device->postEventFromUser(event);
|
||||
}
|
||||
else
|
||||
} else
|
||||
device->closeDevice();
|
||||
}
|
||||
|
||||
driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH,
|
||||
video::SColor(255,100,100,150));
|
||||
video::SColor(255, 100, 100, 150));
|
||||
smgr->drawAll();
|
||||
guienv->drawAll();
|
||||
driver->endScene();
|
||||
|
@ -4,13 +4,14 @@
|
||||
using namespace irr;
|
||||
using core::array;
|
||||
|
||||
static void test_basics() {
|
||||
static void test_basics()
|
||||
{
|
||||
array<int> v;
|
||||
v.push_back(1); // 1
|
||||
v.push_back(1); // 1
|
||||
v.push_front(2); // 2, 1
|
||||
v.insert(4, 0); // 4, 2, 1
|
||||
v.insert(3, 1); // 4, 3, 2, 1
|
||||
v.insert(0, 4); // 4, 3, 2, 1, 0
|
||||
v.insert(4, 0); // 4, 2, 1
|
||||
v.insert(3, 1); // 4, 3, 2, 1
|
||||
v.insert(0, 4); // 4, 3, 2, 1, 0
|
||||
UASSERTEQ(v.size(), 5);
|
||||
UASSERTEQ(v[0], 4);
|
||||
UASSERTEQ(v[1], 3);
|
||||
@ -57,7 +58,8 @@ static void test_basics() {
|
||||
UASSERTEQ(v.size(), 2);
|
||||
}
|
||||
|
||||
static void test_linear_searches() {
|
||||
static void test_linear_searches()
|
||||
{
|
||||
// Populate the array with 0, 1, 2, ..., 100, 100, 99, 98, 97, ..., 0
|
||||
array<int> arr;
|
||||
for (int i = 0; i <= 100; i++)
|
||||
@ -75,14 +77,15 @@ static void test_linear_searches() {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_binary_searches() {
|
||||
const auto& values = { 3, 5, 1, 2, 5, 10, 19, 9, 7, 1, 2, 5, 8, 15 };
|
||||
static void test_binary_searches()
|
||||
{
|
||||
const auto &values = {3, 5, 1, 2, 5, 10, 19, 9, 7, 1, 2, 5, 8, 15};
|
||||
array<int> arr;
|
||||
for (int value : values) {
|
||||
arr.push_back(value);
|
||||
}
|
||||
// Test the const form first, it uses a linear search without sorting
|
||||
const array<int> & carr = arr;
|
||||
const array<int> &carr = arr;
|
||||
UASSERTEQ(carr.binary_search(20), -1);
|
||||
UASSERTEQ(carr.binary_search(0), -1);
|
||||
UASSERTEQ(carr.binary_search(1), 2);
|
||||
|
@ -3,28 +3,31 @@
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
class TestFailedException : public std::exception {
|
||||
class TestFailedException : public std::exception
|
||||
{
|
||||
};
|
||||
|
||||
// Asserts the comparison specified by CMP is true, or fails the current unit test
|
||||
#define UASSERTCMP(CMP, actual, expected) do { \
|
||||
const auto &a = (actual); \
|
||||
const auto &e = (expected); \
|
||||
if (!CMP(a, e)) { \
|
||||
std::cout \
|
||||
<< "Test assertion failed: " << #actual << " " << #CMP << " " \
|
||||
<< #expected << std::endl \
|
||||
<< " at " << __FILE__ << ":" << __LINE__ << std::endl \
|
||||
<< " actual: " << a << std::endl << " expected: " \
|
||||
<< e << std::endl; \
|
||||
throw TestFailedException(); \
|
||||
} \
|
||||
} while (0)
|
||||
#define UASSERTCMP(CMP, actual, expected) \
|
||||
do { \
|
||||
const auto &a = (actual); \
|
||||
const auto &e = (expected); \
|
||||
if (!CMP(a, e)) { \
|
||||
std::cout \
|
||||
<< "Test assertion failed: " << #actual << " " << #CMP << " " \
|
||||
<< #expected << std::endl \
|
||||
<< " at " << __FILE__ << ":" << __LINE__ << std::endl \
|
||||
<< " actual: " << a << std::endl \
|
||||
<< " expected: " \
|
||||
<< e << std::endl; \
|
||||
throw TestFailedException(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CMPEQ(a, e) (a == e)
|
||||
#define CMPTRUE(a, e) (a)
|
||||
#define CMPNE(a, e) (a != e)
|
||||
#define CMPEQ(a, e) (a == e)
|
||||
#define CMPTRUE(a, e) (a)
|
||||
#define CMPNE(a, e) (a != e)
|
||||
|
||||
#define UASSERTEQ(actual, expected) UASSERTCMP(CMPEQ, actual, expected)
|
||||
#define UASSERTEQ(actual, expected) UASSERTCMP(CMPEQ, actual, expected)
|
||||
#define UASSERTNE(actual, nexpected) UASSERTCMP(CMPNE, actual, nexpected)
|
||||
#define UASSERT(actual) UASSERTCMP(CMPTRUE, actual, true)
|
||||
#define UASSERT(actual) UASSERTCMP(CMPTRUE, actual, true)
|
||||
|
@ -38,7 +38,7 @@ static void test_basics()
|
||||
UASSERTSTR(s, "abcdef");
|
||||
s = L"abcdef";
|
||||
UASSERTSTR(s, "abcdef");
|
||||
s = static_cast<const char*>(nullptr);
|
||||
s = static_cast<const char *>(nullptr);
|
||||
UASSERTSTR(s, "");
|
||||
// operator+
|
||||
s = s + stringc("foo");
|
||||
@ -163,7 +163,7 @@ static void test_methods()
|
||||
UASSERTSTR(res[0], "a");
|
||||
UASSERTSTR(res[2], "");
|
||||
for (int i = 0; i < 3; i++)
|
||||
UASSERTSTR(res[2*i+1], ",");
|
||||
UASSERTSTR(res[2 * i + 1], ",");
|
||||
}
|
||||
|
||||
static void test_conv()
|
||||
@ -180,9 +180,9 @@ static void test_conv()
|
||||
wStringToUTF8(out2, L"†††");
|
||||
UASSERTEQ(out2.size(), 9);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
UASSERTEQ(static_cast<u8>(out2[3*i]), 0xe2);
|
||||
UASSERTEQ(static_cast<u8>(out2[3*i+1]), 0x80);
|
||||
UASSERTEQ(static_cast<u8>(out2[3*i+2]), 0xa0);
|
||||
UASSERTEQ(static_cast<u8>(out2[3 * i]), 0xe2);
|
||||
UASSERTEQ(static_cast<u8>(out2[3 * i + 1]), 0x80);
|
||||
UASSERTEQ(static_cast<u8>(out2[3 * i + 2]), 0xa0);
|
||||
}
|
||||
|
||||
// locale-dependent
|
||||
|
Reference in New Issue
Block a user