1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Code modernization: subfolders (#6283)

* Code modernization: subfolders

Modernize various code on subfolders client, network, script, threading, unittests, util

* empty function
* default constructor/destructor
* for range-based loops
* use emplace_back instead of push_back
* C++ STL header style
* Make connection.cpp readable in a pointed place + typo
This commit is contained in:
Loïc Blot 2017-08-19 22:23:47 +02:00 committed by GitHub
parent 7528986e44
commit 88b436e6a9
49 changed files with 398 additions and 518 deletions

View file

@ -31,7 +31,7 @@ class TestFailedException : public std::exception {
};
// Runs a unit test and reports results
#define TEST(fxn, ...) do { \
#define TEST(fxn, ...) { \
u64 t1 = porting::getTimeMs(); \
try { \
fxn(__VA_ARGS__); \
@ -47,21 +47,20 @@ class TestFailedException : public std::exception {
num_tests_run++; \
u64 tdiff = porting::getTimeMs() - t1; \
rawstream << #fxn << " - " << tdiff << "ms" << std::endl; \
} while (0)
}
// Asserts the specified condition is true, or fails the current unit test
#define UASSERT(x) do { \
#define UASSERT(x) \
if (!(x)) { \
rawstream << "Test assertion failed: " #x << std::endl \
<< " at " << fs::GetFilenameFromPath(__FILE__) \
<< ":" << __LINE__ << std::endl; \
throw TestFailedException(); \
} \
} while (0)
}
// Asserts the specified condition is true, or fails the current unit test
// and prints the format specifier fmt
#define UTEST(x, fmt, ...) do { \
#define UTEST(x, fmt, ...) \
if (!(x)) { \
char utest_buf[1024]; \
snprintf(utest_buf, sizeof(utest_buf), fmt, __VA_ARGS__); \
@ -69,8 +68,7 @@ class TestFailedException : public std::exception {
<< " at " << fs::GetFilenameFromPath(__FILE__) \
<< ":" << __LINE__ << std::endl; \
throw TestFailedException(); \
} \
} while (0)
}
// Asserts the comparison specified by CMP is true, or fails the current unit test
#define UASSERTCMP(T, CMP, actual, expected) do { \

View file

@ -109,28 +109,28 @@ void TestNodeResolver::testNodeResolving(IWritableNodeDefManager *ndef)
Foobar foobar;
size_t i;
foobar.m_nodenames.push_back("default:torch");
foobar.m_nodenames.emplace_back("default:torch");
foobar.m_nodenames.push_back("default:dirt_with_grass");
foobar.m_nodenames.push_back("default:water");
foobar.m_nodenames.push_back("default:abloobloobloo");
foobar.m_nodenames.push_back("default:stone");
foobar.m_nodenames.push_back("default:shmegoldorf");
foobar.m_nodenames.emplace_back("default:dirt_with_grass");
foobar.m_nodenames.emplace_back("default:water");
foobar.m_nodenames.emplace_back("default:abloobloobloo");
foobar.m_nodenames.emplace_back("default:stone");
foobar.m_nodenames.emplace_back("default:shmegoldorf");
foobar.m_nnlistsizes.push_back(5);
foobar.m_nodenames.push_back("group:liquids");
foobar.m_nodenames.emplace_back("group:liquids");
foobar.m_nnlistsizes.push_back(1);
foobar.m_nodenames.push_back("default:warf");
foobar.m_nodenames.push_back("default:stone");
foobar.m_nodenames.push_back("default:bloop");
foobar.m_nodenames.emplace_back("default:warf");
foobar.m_nodenames.emplace_back("default:stone");
foobar.m_nodenames.emplace_back("default:bloop");
foobar.m_nnlistsizes.push_back(3);
foobar.m_nnlistsizes.push_back(0);
foobar.m_nodenames.push_back("default:brick");
foobar.m_nodenames.push_back("default:desert_stone");
foobar.m_nodenames.push_back("default:shnitzle");
foobar.m_nodenames.emplace_back("default:brick");
foobar.m_nodenames.emplace_back("default:desert_stone");
foobar.m_nodenames.emplace_back("default:shnitzle");
ndef->pendNodeResolve(&foobar);
UASSERT(foobar.m_ndef == ndef);
@ -187,15 +187,15 @@ void TestNodeResolver::testPendingResolveCancellation(IWritableNodeDefManager *n
Foobaz foobaz1;
foobaz1.test_content1 = 1234;
foobaz1.test_content2 = 5678;
foobaz1.m_nodenames.push_back("default:dirt_with_grass");
foobaz1.m_nodenames.push_back("default:abloobloobloo");
foobaz1.m_nodenames.emplace_back("default:dirt_with_grass");
foobaz1.m_nodenames.emplace_back("default:abloobloobloo");
ndef->pendNodeResolve(&foobaz1);
Foobaz foobaz2;
foobaz2.test_content1 = 1234;
foobaz2.test_content2 = 5678;
foobaz2.m_nodenames.push_back("default:dirt_with_grass");
foobaz2.m_nodenames.push_back("default:abloobloobloo");
foobaz2.m_nodenames.emplace_back("default:dirt_with_grass");
foobaz2.m_nodenames.emplace_back("default:abloobloobloo");
ndef->pendNodeResolve(&foobaz2);
ndef->cancelNodeResolveCallback(&foobaz1);

View file

@ -67,10 +67,10 @@ void TestSchematic::testMtsSerializeDeserialize(INodeDefManager *ndef)
std::ios_base::in | std::ios_base::out);
std::vector<std::string> names;
names.push_back("foo");
names.push_back("bar");
names.push_back("baz");
names.push_back("qux");
names.emplace_back("foo");
names.emplace_back("bar");
names.emplace_back("baz");
names.emplace_back("qux");
Schematic schem, schem2;
@ -121,9 +121,9 @@ void TestSchematic::testLuaTableSerialize(INodeDefManager *ndef)
schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;
std::vector<std::string> names;
names.push_back("air");
names.push_back("default:lava_source");
names.push_back("default:glass");
names.emplace_back("air");
names.emplace_back("default:lava_source");
names.emplace_back("default:glass");
std::ostringstream ss(std::ios_base::binary);

View file

@ -166,16 +166,16 @@ void TestThreading::testAtomicSemaphoreThread()
static const u8 num_threads = 4;
AtomicTestThread *threads[num_threads];
for (u8 i = 0; i < num_threads; ++i) {
threads[i] = new AtomicTestThread(val, trigger);
UASSERT(threads[i]->start());
for (auto &thread : threads) {
thread = new AtomicTestThread(val, trigger);
UASSERT(thread->start());
}
trigger.post(num_threads);
for (u8 i = 0; i < num_threads; ++i) {
threads[i]->wait();
delete threads[i];
for (AtomicTestThread *thread : threads) {
thread->wait();
delete thread;
}
UASSERT(val == num_threads * 0x10000);

View file

@ -61,8 +61,8 @@ void TestVoxelManipulator::testVoxelArea()
// Correct results
std::vector<VoxelArea> results;
results.push_back(VoxelArea(v3s16(-2,-2,-3), v3s16(3,2,-3)));
results.push_back(VoxelArea(v3s16(3,-2,-2), v3s16(3,2,2)));
results.emplace_back(v3s16(-2,-2,-3), v3s16(3,2,-3));
results.emplace_back(v3s16(3,-2,-2), v3s16(3,2,2));
UASSERT(aa.size() == results.size());