aboutsummaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-08-20 13:30:50 +0200
committerGitHub <noreply@github.com>2017-08-20 13:30:50 +0200
commit1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3 (patch)
tree03dd0c39e323c7f0b1f06014ff30e74f429bfa01 /src/unittest
parent50669cd2822a11570ae462972194eeb2d585a8c1 (diff)
downloadminetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.tar.gz
minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.tar.bz2
minetest-1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3.zip
Modernize source code: last part (#6285)
* Modernize source code: last par * Use empty when needed * Use emplace_back instead of push_back when needed * For range-based loops * Initializers fixes * constructors, destructors default * c++ C stl includes
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/test.cpp16
-rw-r--r--src/unittest/test.h8
-rw-r--r--src/unittest/test_compression.cpp16
-rw-r--r--src/unittest/test_nodedef.cpp4
-rw-r--r--src/unittest/test_noise.cpp2
-rw-r--r--src/unittest/test_voxelalgorithms.cpp4
6 files changed, 25 insertions, 25 deletions
diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp
index b52189cb4..615ec2162 100644
--- a/src/unittest/test.cpp
+++ b/src/unittest/test.cpp
@@ -120,8 +120,8 @@ void TestGameDef::defineSomeNodes()
"{default_stone.png";
f = ContentFeatures();
f.name = itemdef.name;
- for(int i = 0; i < 6; i++)
- f.tiledef[i].name = "default_stone.png";
+ for (TileDef &tiledef : f.tiledef)
+ tiledef.name = "default_stone.png";
f.is_ground_content = true;
idef->registerItem(itemdef);
t_CONTENT_STONE = ndef->set(f.name, f);
@@ -175,8 +175,8 @@ void TestGameDef::defineSomeNodes()
f.liquid_viscosity = 4;
f.is_ground_content = true;
f.groups["liquids"] = 3;
- for(int i = 0; i < 6; i++)
- f.tiledef[i].name = "default_water.png";
+ for (TileDef &tiledef : f.tiledef)
+ tiledef.name = "default_water.png";
idef->registerItem(itemdef);
t_CONTENT_WATER = ndef->set(f.name, f);
@@ -197,8 +197,8 @@ void TestGameDef::defineSomeNodes()
f.light_source = LIGHT_MAX-1;
f.is_ground_content = true;
f.groups["liquids"] = 3;
- for(int i = 0; i < 6; i++)
- f.tiledef[i].name = "default_lava.png";
+ for (TileDef &tiledef : f.tiledef)
+ tiledef.name = "default_lava.png";
idef->registerItem(itemdef);
t_CONTENT_LAVA = ndef->set(f.name, f);
@@ -215,8 +215,8 @@ void TestGameDef::defineSomeNodes()
"{default_brick.png";
f = ContentFeatures();
f.name = itemdef.name;
- for(int i = 0; i < 6; i++)
- f.tiledef[i].name = "default_brick.png";
+ for (TileDef &tiledef : f.tiledef)
+ tiledef.name = "default_brick.png";
f.is_ground_content = true;
idef->registerItem(itemdef);
t_CONTENT_BRICK = ndef->set(f.name, f);
diff --git a/src/unittest/test.h b/src/unittest/test.h
index 44b0cd02b..1102f6d33 100644
--- a/src/unittest/test.h
+++ b/src/unittest/test.h
@@ -71,7 +71,7 @@ class TestFailedException : public std::exception {
}
// Asserts the comparison specified by CMP is true, or fails the current unit test
-#define UASSERTCMP(T, CMP, actual, expected) do { \
+#define UASSERTCMP(T, CMP, actual, expected) { \
T a = (actual); \
T e = (expected); \
if (!(a CMP e)) { \
@@ -84,12 +84,12 @@ class TestFailedException : public std::exception {
<< e << std::endl; \
throw TestFailedException(); \
} \
-} while (0)
+}
#define UASSERTEQ(T, actual, expected) UASSERTCMP(T, ==, actual, expected)
// UASSERTs that the specified exception occurs
-#define EXCEPTION_CHECK(EType, code) do { \
+#define EXCEPTION_CHECK(EType, code) { \
bool exception_thrown = false; \
try { \
code; \
@@ -97,7 +97,7 @@ class TestFailedException : public std::exception {
exception_thrown = true; \
} \
UASSERT(exception_thrown); \
-} while (0)
+}
class IGameDef;
diff --git a/src/unittest/test_compression.cpp b/src/unittest/test_compression.cpp
index a3132aa17..7d0378131 100644
--- a/src/unittest/test_compression.cpp
+++ b/src/unittest/test_compression.cpp
@@ -65,8 +65,8 @@ void TestCompression::testRLECompression()
infostream << "str_out.size()="<<str_out.size()<<std::endl;
infostream << "TestCompress: 1,5,5,1 -> ";
- for (u32 i = 0; i < str_out.size(); i++)
- infostream << (u32)str_out[i] << ",";
+ for (char i : str_out)
+ infostream << (u32) i << ",";
infostream << std::endl;
UASSERT(str_out.size() == 10);
@@ -89,8 +89,8 @@ void TestCompression::testRLECompression()
std::string str_out2 = os2.str();
infostream << "decompress: ";
- for (u32 i = 0; i < str_out2.size(); i++)
- infostream << (u32)str_out2[i] << ",";
+ for (char i : str_out2)
+ infostream << (u32) i << ",";
infostream << std::endl;
UASSERTEQ(size_t, str_out2.size(), fromdata.getSize());
@@ -114,8 +114,8 @@ void TestCompression::testZlibCompression()
infostream << "str_out.size()=" << str_out.size() <<std::endl;
infostream << "TestCompress: 1,5,5,1 -> ";
- for (u32 i = 0; i < str_out.size(); i++)
- infostream << (u32)str_out[i] << ",";
+ for (char i : str_out)
+ infostream << (u32) i << ",";
infostream << std::endl;
std::istringstream is(str_out, std::ios_base::binary);
@@ -125,8 +125,8 @@ void TestCompression::testZlibCompression()
std::string str_out2 = os2.str();
infostream << "decompress: ";
- for (u32 i = 0; i < str_out2.size(); i++)
- infostream << (u32)str_out2[i] << ",";
+ for (char i : str_out2)
+ infostream << (u32) i << ",";
infostream << std::endl;
UASSERTEQ(size_t, str_out2.size(), fromdata.getSize());
diff --git a/src/unittest/test_nodedef.cpp b/src/unittest/test_nodedef.cpp
index cb99ae854..66ca0ccbc 100644
--- a/src/unittest/test_nodedef.cpp
+++ b/src/unittest/test_nodedef.cpp
@@ -50,8 +50,8 @@ void TestNodeDef::testContentFeaturesSerialization()
ContentFeatures f;
f.name = "default:stone";
- for (int i = 0; i < 6; i++)
- f.tiledef[i].name = "default_stone.png";
+ for (TileDef &tiledef : f.tiledef)
+ tiledef.name = "default_stone.png";
f.is_ground_content = true;
std::ostringstream os(std::ios::binary);
diff --git a/src/unittest/test_noise.cpp b/src/unittest/test_noise.cpp
index d1821c950..988ea4495 100644
--- a/src/unittest/test_noise.cpp
+++ b/src/unittest/test_noise.cpp
@@ -113,7 +113,7 @@ void TestNoise::testNoiseInvalidParams()
NoiseParams np_highmem(4, 70, v3f(1, 1, 1), 5, 60, 0.7, 10.0);
Noise noise_highmem_3d(&np_highmem, 1337, 200, 200, 200);
noise_highmem_3d.perlinMap3D(0, 0, 0, NULL);
- } catch (InvalidNoiseParamsException) {
+ } catch (InvalidNoiseParamsException &) {
exception_thrown = true;
}
diff --git a/src/unittest/test_voxelalgorithms.cpp b/src/unittest/test_voxelalgorithms.cpp
index fd83844af..8c236b73e 100644
--- a/src/unittest/test_voxelalgorithms.cpp
+++ b/src/unittest/test_voxelalgorithms.cpp
@@ -215,11 +215,11 @@ void TestVoxelAlgorithms::testVoxelLineIterator(INodeDefManager *ndef)
for (f32 x = -9.1; x < 9; x += 3.124) {
for (f32 y = -9.2; y < 9; y += 3.123) {
for (f32 z = -9.3; z < 9; z += 3.122) {
- lines.push_back(core::line3d<f32>(-x, -y, -z, x, y, z));
+ lines.emplace_back(-x, -y, -z, x, y, z);
}
}
}
- lines.push_back(core::line3d<f32>(0, 0, 0, 0, 0, 0));
+ lines.emplace_back(0, 0, 0, 0, 0, 0);
// Test every line
std::vector<core::line3d<f32> >::iterator it = lines.begin();
for (; it < lines.end(); it++) {