diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-08-19 22:23:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-19 22:23:47 +0200 |
commit | 88b436e6a9c98af7215bd115e1b7a3f1a1db99d3 (patch) | |
tree | f07cdd7f93ca26b84192d7b89f7b952e603ba5cf /src/unittest | |
parent | 7528986e4449febead9b18b6118f0b096f7cf800 (diff) | |
download | minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.tar.gz minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.tar.bz2 minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.zip |
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
Diffstat (limited to 'src/unittest')
-rw-r--r-- | src/unittest/test.h | 14 | ||||
-rw-r--r-- | src/unittest/test_noderesolver.cpp | 34 | ||||
-rw-r--r-- | src/unittest/test_schematic.cpp | 14 | ||||
-rw-r--r-- | src/unittest/test_threading.cpp | 12 | ||||
-rw-r--r-- | src/unittest/test_voxelmanipulator.cpp | 4 |
5 files changed, 38 insertions, 40 deletions
diff --git a/src/unittest/test.h b/src/unittest/test.h index c4351a67b..44b0cd02b 100644 --- a/src/unittest/test.h +++ b/src/unittest/test.h @@ -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 { \ diff --git a/src/unittest/test_noderesolver.cpp b/src/unittest/test_noderesolver.cpp index b009f5d2e..dc2106a54 100644 --- a/src/unittest/test_noderesolver.cpp +++ b/src/unittest/test_noderesolver.cpp @@ -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); diff --git a/src/unittest/test_schematic.cpp b/src/unittest/test_schematic.cpp index 480124428..3fea44829 100644 --- a/src/unittest/test_schematic.cpp +++ b/src/unittest/test_schematic.cpp @@ -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); diff --git a/src/unittest/test_threading.cpp b/src/unittest/test_threading.cpp index 03d776539..8d4d814fd 100644 --- a/src/unittest/test_threading.cpp +++ b/src/unittest/test_threading.cpp @@ -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); diff --git a/src/unittest/test_voxelmanipulator.cpp b/src/unittest/test_voxelmanipulator.cpp index 7f8ba3849..6c8ac6757 100644 --- a/src/unittest/test_voxelmanipulator.cpp +++ b/src/unittest/test_voxelmanipulator.cpp @@ -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()); |