Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

[no sq] Reformat the code (adopted) #295

Merged
merged 10 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
enable_testing()
add_subdirectory(source/Irrlicht)
add_subdirectory(src)
add_subdirectory(test)

option(BUILD_EXAMPLES "Build example applications" FALSE)
Expand Down
60 changes: 26 additions & 34 deletions examples/AutomatedTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
Expand All @@ -109,31 +107,26 @@ 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
{
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
} else if (n == 2) // Text input focus
guienv->setFocus(editbox);
else if (n == 3) // Keypress for Text input
{
else if (n == 3) { // Keypress for Text input
bzero(&event, sizeof(SEvent));
event.EventType = irr::EET_KEY_INPUT_EVENT;
event.KeyInput.Char = L'a';
Expand All @@ -142,13 +135,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();
Expand Down
13 changes: 8 additions & 5 deletions examples/AutomatedTest/test_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using namespace irr;
using core::array;

static void test_basics() {
static void test_basics()
{
array<int> v;
v.push_back(1); // 1
v.push_front(2); // 2, 1
Expand Down Expand Up @@ -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++)
Expand All @@ -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);
Expand Down
41 changes: 22 additions & 19 deletions examples/AutomatedTest/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 5 additions & 5 deletions examples/AutomatedTest/test_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
Loading