aboutsummaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/CMakeLists.txt5
-rw-r--r--src/unittest/test.cpp6
-rw-r--r--src/unittest/test_areastore.cpp4
-rw-r--r--src/unittest/test_clientactiveobjectmgr.cpp1
-rw-r--r--src/unittest/test_compression.cpp42
-rw-r--r--src/unittest/test_config.h.in1
-rw-r--r--src/unittest/test_connection.cpp10
-rw-r--r--src/unittest/test_gettext.cpp43
-rw-r--r--src/unittest/test_irrptr.cpp10
-rw-r--r--src/unittest/test_map.cpp68
-rw-r--r--src/unittest/test_map_settings_manager.cpp5
-rw-r--r--src/unittest/test_mod/test_mod/init.lua1
-rw-r--r--src/unittest/test_mod/test_mod/mod.conf2
-rw-r--r--src/unittest/test_modmetadatadatabase.cpp253
-rw-r--r--src/unittest/test_noderesolver.cpp2
-rw-r--r--src/unittest/test_player.cpp39
-rw-r--r--src/unittest/test_schematic.cpp40
-rw-r--r--src/unittest/test_servermodmanager.cpp21
-rw-r--r--src/unittest/test_socket.cpp18
-rw-r--r--src/unittest/test_utilities.cpp99
-rw-r--r--src/unittest/test_voxelarea.cpp18
21 files changed, 606 insertions, 82 deletions
diff --git a/src/unittest/CMakeLists.txt b/src/unittest/CMakeLists.txt
index 5703b8906..92f31ecac 100644
--- a/src/unittest/CMakeLists.txt
+++ b/src/unittest/CMakeLists.txt
@@ -11,14 +11,15 @@ set (UNITTEST_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/test_filepath.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_inventory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_irrptr.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_map.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_map_settings_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_mapnode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_modchannels.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_modmetadatadatabase.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_nodedef.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_noderesolver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_noise.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_objdef.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/test_player.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_profiler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_random.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_schematic.cpp
@@ -33,6 +34,7 @@ set (UNITTEST_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/test_voxelarea.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_voxelalgorithms.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_voxelmanipulator.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/test_gettext.cpp
PARENT_SCOPE)
set (UNITTEST_CLIENT_SRCS
@@ -44,6 +46,7 @@ set (UNITTEST_CLIENT_SRCS
set (TEST_WORLDDIR ${CMAKE_CURRENT_SOURCE_DIR}/test_world)
set (TEST_SUBGAME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../games/devtest)
+set (TEST_MOD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/test_mod)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/test_config.h.in"
diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp
index af324e1b1..f223d567e 100644
--- a/src/unittest/test.cpp
+++ b/src/unittest/test.cpp
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gamedef.h"
#include "modchannels.h"
#include "content/mods.h"
+#include "database/database-dummy.h"
#include "util/numeric.h"
#include "porting.h"
@@ -55,6 +56,7 @@ public:
scene::ISceneManager *getSceneManager() { return m_scenemgr; }
IRollbackManager *getRollbackManager() { return m_rollbackmgr; }
EmergeManager *getEmergeManager() { return m_emergemgr; }
+ ModMetadataDatabase *getModStorageDatabase() { return m_mod_storage_database; }
scene::IAnimatedMesh *getMesh(const std::string &filename) { return NULL; }
bool checkLocalPrivilege(const std::string &priv) { return false; }
@@ -68,7 +70,6 @@ public:
return testmodspec;
}
virtual const ModSpec* getModSpec(const std::string &modname) const { return NULL; }
- virtual std::string getModStoragePath() const { return "."; }
virtual bool registerModStorage(ModMetadata *meta) { return true; }
virtual void unregisterModStorage(const std::string &name) {}
bool joinModChannel(const std::string &channel);
@@ -89,11 +90,13 @@ private:
scene::ISceneManager *m_scenemgr = nullptr;
IRollbackManager *m_rollbackmgr = nullptr;
EmergeManager *m_emergemgr = nullptr;
+ ModMetadataDatabase *m_mod_storage_database = nullptr;
std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
};
TestGameDef::TestGameDef() :
+ m_mod_storage_database(new Database_Dummy()),
m_modchannel_mgr(new ModChannelMgr())
{
m_itemdef = createItemDefManager();
@@ -107,6 +110,7 @@ TestGameDef::~TestGameDef()
{
delete m_itemdef;
delete m_nodedef;
+ delete m_mod_storage_database;
}
diff --git a/src/unittest/test_areastore.cpp b/src/unittest/test_areastore.cpp
index 691cd69d2..2af3ca90c 100644
--- a/src/unittest/test_areastore.cpp
+++ b/src/unittest/test_areastore.cpp
@@ -135,7 +135,7 @@ void TestAreaStore::testSerialization()
b.data = "Area BB";
store.insertArea(&b);
- std::ostringstream os;
+ std::ostringstream os(std::ios_base::binary);
store.serialize(os);
std::string str = os.str();
@@ -157,7 +157,7 @@ void TestAreaStore::testSerialization()
UASSERTEQ(const std::string &, str, str_wanted);
- std::istringstream is(str);
+ std::istringstream is(str, std::ios_base::binary);
store.deserialize(is);
// deserialize() doesn't clear the store
diff --git a/src/unittest/test_clientactiveobjectmgr.cpp b/src/unittest/test_clientactiveobjectmgr.cpp
index 4d2846c8d..2d508cf32 100644
--- a/src/unittest/test_clientactiveobjectmgr.cpp
+++ b/src/unittest/test_clientactiveobjectmgr.cpp
@@ -29,6 +29,7 @@ public:
TestClientActiveObject() : ClientActiveObject(0, nullptr, nullptr) {}
~TestClientActiveObject() = default;
ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_TEST; }
+ virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) {}
};
class TestClientActiveObjectMgr : public TestBase
diff --git a/src/unittest/test_compression.cpp b/src/unittest/test_compression.cpp
index dfcadd4b2..a96282f58 100644
--- a/src/unittest/test_compression.cpp
+++ b/src/unittest/test_compression.cpp
@@ -37,6 +37,7 @@ public:
void testRLECompression();
void testZlibCompression();
void testZlibLargeData();
+ void testZstdLargeData();
void testZlibLimit();
void _testZlibLimit(u32 size, u32 limit);
};
@@ -48,6 +49,7 @@ void TestCompression::runTests(IGameDef *gamedef)
TEST(testRLECompression);
TEST(testZlibCompression);
TEST(testZlibLargeData);
+ TEST(testZstdLargeData);
TEST(testZlibLimit);
}
@@ -111,7 +113,7 @@ void TestCompression::testZlibCompression()
fromdata[3]=1;
std::ostringstream os(std::ios_base::binary);
- compress(fromdata, os, SER_FMT_VER_HIGHEST_READ);
+ compressZlib(*fromdata, fromdata.getSize(), os);
std::string str_out = os.str();
@@ -124,7 +126,7 @@ void TestCompression::testZlibCompression()
std::istringstream is(str_out, std::ios_base::binary);
std::ostringstream os2(std::ios_base::binary);
- decompress(is, os2, SER_FMT_VER_HIGHEST_READ);
+ decompressZlib(is, os2);
std::string str_out2 = os2.str();
infostream << "decompress: ";
@@ -174,6 +176,42 @@ void TestCompression::testZlibLargeData()
}
}
+void TestCompression::testZstdLargeData()
+{
+ infostream << "Test: Testing zstd wrappers with a large amount "
+ "of pseudorandom data" << std::endl;
+
+ u32 size = 500000;
+ infostream << "Test: Input size of large compressZstd is "
+ << size << std::endl;
+
+ std::string data_in;
+ data_in.resize(size);
+ PseudoRandom pseudorandom(9420);
+ for (u32 i = 0; i < size; i++)
+ data_in[i] = pseudorandom.range(0, 255);
+
+ std::ostringstream os_compressed(std::ios::binary);
+ compressZstd(data_in, os_compressed, 0);
+ infostream << "Test: Output size of large compressZstd is "
+ << os_compressed.str().size()<<std::endl;
+
+ std::istringstream is_compressed(os_compressed.str(), std::ios::binary);
+ std::ostringstream os_decompressed(std::ios::binary);
+ decompressZstd(is_compressed, os_decompressed);
+ infostream << "Test: Output size of large decompressZstd is "
+ << os_decompressed.str().size() << std::endl;
+
+ std::string str_decompressed = os_decompressed.str();
+ UASSERTEQ(size_t, str_decompressed.size(), data_in.size());
+
+ for (u32 i = 0; i < size && i < str_decompressed.size(); i++) {
+ UTEST(str_decompressed[i] == data_in[i],
+ "index out[%i]=%i differs from in[%i]=%i",
+ i, str_decompressed[i], i, data_in[i]);
+ }
+}
+
void TestCompression::testZlibLimit()
{
// edge cases
diff --git a/src/unittest/test_config.h.in b/src/unittest/test_config.h.in
index 36850b00d..50d2398e4 100644
--- a/src/unittest/test_config.h.in
+++ b/src/unittest/test_config.h.in
@@ -4,3 +4,4 @@
#define TEST_WORLDDIR "@TEST_WORLDDIR@"
#define TEST_SUBGAME_PATH "@TEST_SUBGAME_PATH@"
+#define TEST_MOD_PATH "@TEST_MOD_PATH@"
diff --git a/src/unittest/test_connection.cpp b/src/unittest/test_connection.cpp
index 23b7e9105..04fea90d6 100644
--- a/src/unittest/test_connection.cpp
+++ b/src/unittest/test_connection.cpp
@@ -124,7 +124,7 @@ void TestConnection::testHelpers()
Address a(127,0,0,1, 10);
const u16 seqnum = 34352;
- con::BufferedPacket p1 = con::makePacket(a, data1,
+ con::BufferedPacketPtr p1 = con::makePacket(a, data1,
proto_id, peer_id, channel);
/*
We should now have a packet with this data:
@@ -135,10 +135,10 @@ void TestConnection::testHelpers()
Data:
[7] u8 data1[0]
*/
- UASSERT(readU32(&p1.data[0]) == proto_id);
- UASSERT(readU16(&p1.data[4]) == peer_id);
- UASSERT(readU8(&p1.data[6]) == channel);
- UASSERT(readU8(&p1.data[7]) == data1[0]);
+ UASSERT(readU32(&p1->data[0]) == proto_id);
+ UASSERT(readU16(&p1->data[4]) == peer_id);
+ UASSERT(readU8(&p1->data[6]) == channel);
+ UASSERT(readU8(&p1->data[7]) == data1[0]);
//infostream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
diff --git a/src/unittest/test_gettext.cpp b/src/unittest/test_gettext.cpp
new file mode 100644
index 000000000..338a416d7
--- /dev/null
+++ b/src/unittest/test_gettext.cpp
@@ -0,0 +1,43 @@
+#include "test.h"
+#include "porting.h"
+#include "gettext.h"
+
+class TestGettext : public TestBase
+{
+public:
+ TestGettext() {
+ TestManager::registerTestModule(this);
+ }
+
+ const char *getName() { return "TestGettext"; }
+
+ void runTests(IGameDef *gamedef);
+
+ void testFmtgettext();
+};
+
+static TestGettext g_test_instance;
+
+void TestGettext::runTests(IGameDef *gamedef)
+{
+ TEST(testFmtgettext);
+}
+
+// Make sure updatepo.sh does not pick up the strings
+#define dummyname fmtgettext
+
+void TestGettext::testFmtgettext()
+{
+ std::string buf = dummyname("sample text %d", 12);
+ UASSERTEQ(std::string, buf, "sample text 12");
+
+ std::string src, expect;
+ src = "You are about to join this server with the name \"%s\".\n";
+ expect = "You are about to join this server with the name \"foo\".\n";
+ for (int i = 0; i < 20; i++) {
+ src.append("loooong text");
+ expect.append("loooong text");
+ }
+ buf = dummyname(src.c_str(), "foo");
+ UASSERTEQ(const std::string &, buf, expect);
+}
diff --git a/src/unittest/test_irrptr.cpp b/src/unittest/test_irrptr.cpp
index aa857ff46..3484f1514 100644
--- a/src/unittest/test_irrptr.cpp
+++ b/src/unittest/test_irrptr.cpp
@@ -91,6 +91,12 @@ void TestIrrPtr::testRefCounting()
obj->getReferenceCount());
}
+#if defined(__clang__)
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wself-assign-overloaded"
+ #pragma GCC diagnostic ignored "-Wself-move"
+#endif
+
void TestIrrPtr::testSelfAssignment()
{
irr_ptr<IReferenceCounted> p1{new IReferenceCounted()};
@@ -129,3 +135,7 @@ void TestIrrPtr::testNullHandling()
UASSERT(!p2);
UASSERT(!p3);
}
+
+#if defined(__clang__)
+ #pragma GCC diagnostic pop
+#endif
diff --git a/src/unittest/test_map.cpp b/src/unittest/test_map.cpp
new file mode 100644
index 000000000..82e55e1aa
--- /dev/null
+++ b/src/unittest/test_map.cpp
@@ -0,0 +1,68 @@
+/*
+Minetest
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "test.h"
+
+#include <cstdio>
+#include "mapblock.h"
+
+class TestMap : public TestBase
+{
+public:
+ TestMap() { TestManager::registerTestModule(this); }
+ const char *getName() { return "TestMap"; }
+
+ void runTests(IGameDef *gamedef);
+
+ void testMaxMapgenLimit();
+};
+
+static TestMap g_test_instance;
+
+void TestMap::runTests(IGameDef *gamedef)
+{
+ TEST(testMaxMapgenLimit);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void TestMap::testMaxMapgenLimit()
+{
+ // limit must end on a mapblock boundary
+ UASSERTEQ(int, MAX_MAP_GENERATION_LIMIT % MAP_BLOCKSIZE, MAP_BLOCKSIZE - 1);
+
+ // objectpos_over_limit should do exactly this except the last node
+ // actually spans from LIMIT-0.5 to LIMIT+0.5
+ float limit_times_bs = MAX_MAP_GENERATION_LIMIT * BS;
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs-BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs)) == false);
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS)) == true);
+
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs+BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs)) == false);
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS)) == true);
+
+ // blockpos_over_max_limit
+ s16 limit_block = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
+ UASSERT(blockpos_over_max_limit(v3s16(limit_block)) == false);
+ UASSERT(blockpos_over_max_limit(v3s16(limit_block+1)) == true);
+ UASSERT(blockpos_over_max_limit(v3s16(-limit_block)) == false);
+ UASSERT(blockpos_over_max_limit(v3s16(-limit_block-1)) == true);
+}
diff --git a/src/unittest/test_map_settings_manager.cpp b/src/unittest/test_map_settings_manager.cpp
index 81ca68705..17c31fe79 100644
--- a/src/unittest/test_map_settings_manager.cpp
+++ b/src/unittest/test_map_settings_manager.cpp
@@ -148,6 +148,11 @@ void TestMapSettingsManager::testMapSettingsManager()
check_noise_params(&dummy, &script_np_factor);
}
+ // The settings manager MUST leave user settings alone
+ mgr.setMapSetting("testname", "1");
+ mgr.setMapSetting("testname", "1", true);
+ UASSERT(!Settings::getLayer(SL_GLOBAL)->exists("testname"));
+
// Now make our Params and see if the values are correctly sourced
MapgenParams *params = mgr.makeMapgenParams();
UASSERT(params->mgtype == MAPGEN_V5);
diff --git a/src/unittest/test_mod/test_mod/init.lua b/src/unittest/test_mod/test_mod/init.lua
new file mode 100644
index 000000000..724a863f5
--- /dev/null
+++ b/src/unittest/test_mod/test_mod/init.lua
@@ -0,0 +1 @@
+-- deliberately empty
diff --git a/src/unittest/test_mod/test_mod/mod.conf b/src/unittest/test_mod/test_mod/mod.conf
new file mode 100644
index 000000000..56c64b2d8
--- /dev/null
+++ b/src/unittest/test_mod/test_mod/mod.conf
@@ -0,0 +1,2 @@
+name = test_mod
+description = A mod doing nothing, to test if MINETEST_MOD_PATH is recognised
diff --git a/src/unittest/test_modmetadatadatabase.cpp b/src/unittest/test_modmetadatadatabase.cpp
new file mode 100644
index 000000000..be97fae5e
--- /dev/null
+++ b/src/unittest/test_modmetadatadatabase.cpp
@@ -0,0 +1,253 @@
+/*
+Minetest
+Copyright (C) 2018 bendeutsch, Ben Deutsch <ben@bendeutsch.de>
+Copyright (C) 2021 TurkeyMcMac, Jude Melton-Houghton <jwmhjwmh@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+// This file is an edited copy of test_authdatabase.cpp
+
+#include "test.h"
+
+#include <algorithm>
+#include "database/database-files.h"
+#include "database/database-sqlite3.h"
+#include "filesys.h"
+
+namespace
+{
+// Anonymous namespace to create classes that are only
+// visible to this file
+//
+// These are helpers that return a *ModMetadataDatabase and
+// allow us to run the same tests on different databases and
+// database acquisition strategies.
+
+class ModMetadataDatabaseProvider
+{
+public:
+ virtual ~ModMetadataDatabaseProvider() = default;
+ virtual ModMetadataDatabase *getModMetadataDatabase() = 0;
+};
+
+class FixedProvider : public ModMetadataDatabaseProvider
+{
+public:
+ FixedProvider(ModMetadataDatabase *mod_meta_db) : mod_meta_db(mod_meta_db){};
+ virtual ~FixedProvider(){};
+ virtual ModMetadataDatabase *getModMetadataDatabase() { return mod_meta_db; };
+
+private:
+ ModMetadataDatabase *mod_meta_db;
+};
+
+class FilesProvider : public ModMetadataDatabaseProvider
+{
+public:
+ FilesProvider(const std::string &dir) : dir(dir){};
+ virtual ~FilesProvider()
+ {
+ if (mod_meta_db)
+ mod_meta_db->endSave();
+ delete mod_meta_db;
+ }
+ virtual ModMetadataDatabase *getModMetadataDatabase()
+ {
+ if (mod_meta_db)
+ mod_meta_db->endSave();
+ delete mod_meta_db;
+ mod_meta_db = new ModMetadataDatabaseFiles(dir);
+ mod_meta_db->beginSave();
+ return mod_meta_db;
+ };
+
+private:
+ std::string dir;
+ ModMetadataDatabase *mod_meta_db = nullptr;
+};
+
+class SQLite3Provider : public ModMetadataDatabaseProvider
+{
+public:
+ SQLite3Provider(const std::string &dir) : dir(dir){};
+ virtual ~SQLite3Provider()
+ {
+ if (mod_meta_db)
+ mod_meta_db->endSave();
+ delete mod_meta_db;
+ }
+ virtual ModMetadataDatabase *getModMetadataDatabase()
+ {
+ if (mod_meta_db)
+ mod_meta_db->endSave();
+ delete mod_meta_db;
+ mod_meta_db = new ModMetadataDatabaseSQLite3(dir);
+ mod_meta_db->beginSave();
+ return mod_meta_db;
+ };
+
+private:
+ std::string dir;
+ ModMetadataDatabase *mod_meta_db = nullptr;
+};
+}
+
+class TestModMetadataDatabase : public TestBase
+{
+public:
+ TestModMetadataDatabase() { TestManager::registerTestModule(this); }
+ const char *getName() { return "TestModMetadataDatabase"; }
+
+ void runTests(IGameDef *gamedef);
+ void runTestsForCurrentDB();
+
+ void testRecallFail();
+ void testCreate();
+ void testRecall();
+ void testChange();
+ void testRecallChanged();
+ void testListMods();
+ void testRemove();
+
+private:
+ ModMetadataDatabaseProvider *mod_meta_provider;
+};
+
+static TestModMetadataDatabase g_test_instance;
+
+void TestModMetadataDatabase::runTests(IGameDef *gamedef)
+{
+ // fixed directory, for persistence
+ thread_local const std::string test_dir = getTestTempDirectory();
+
+ // Each set of tests is run twice for each database type:
+ // one where we reuse the same ModMetadataDatabase object (to test local caching),
+ // and one where we create a new ModMetadataDatabase object for each call
+ // (to test actual persistence).
+
+ rawstream << "-------- Files database (same object)" << std::endl;
+
+ ModMetadataDatabase *mod_meta_db = new ModMetadataDatabaseFiles(test_dir);
+ mod_meta_provider = new FixedProvider(mod_meta_db);
+
+ runTestsForCurrentDB();
+
+ delete mod_meta_db;
+ delete mod_meta_provider;
+
+ // reset database
+ fs::RecursiveDelete(test_dir + DIR_DELIM + "mod_storage");
+
+ rawstream << "-------- Files database (new objects)" << std::endl;
+
+ mod_meta_provider = new FilesProvider(test_dir);
+
+ runTestsForCurrentDB();
+
+ delete mod_meta_provider;
+
+ rawstream << "-------- SQLite3 database (same object)" << std::endl;
+
+ mod_meta_db = new ModMetadataDatabaseSQLite3(test_dir);
+ mod_meta_provider = new FixedProvider(mod_meta_db);
+
+ runTestsForCurrentDB();
+
+ delete mod_meta_db;
+ delete mod_meta_provider;
+
+ // reset database
+ fs::DeleteSingleFileOrEmptyDirectory(test_dir + DIR_DELIM + "mod_storage.sqlite");
+
+ rawstream << "-------- SQLite3 database (new objects)" << std::endl;
+
+ mod_meta_provider = new SQLite3Provider(test_dir);
+
+ runTestsForCurrentDB();
+
+ delete mod_meta_provider;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void TestModMetadataDatabase::runTestsForCurrentDB()
+{
+ TEST(testRecallFail);
+ TEST(testCreate);
+ TEST(testRecall);
+ TEST(testChange);
+ TEST(testRecallChanged);
+ TEST(testListMods);
+ TEST(testRemove);
+ TEST(testRecallFail);
+}
+
+void TestModMetadataDatabase::testRecallFail()
+{
+ ModMetadataDatabase *mod_meta_db = mod_meta_provider->getModMetadataDatabase();
+ StringMap recalled;
+ mod_meta_db->getModEntries("mod1", &recalled);
+ UASSERT(recalled.empty());
+}
+
+void TestModMetadataDatabase::testCreate()
+{
+ ModMetadataDatabase *mod_meta_db = mod_meta_provider->getModMetadataDatabase();
+ StringMap recalled;
+ UASSERT(mod_meta_db->setModEntry("mod1", "key1", "value1"));
+}
+
+void TestModMetadataDatabase::testRecall()
+{
+ ModMetadataDatabase *mod_meta_db = mod_meta_provider->getModMetadataDatabase();
+ StringMap recalled;
+ mod_meta_db->getModEntries("mod1", &recalled);
+ UASSERT(recalled.size() == 1);
+ UASSERT(recalled["key1"] == "value1");
+}
+
+void TestModMetadataDatabase::testChange()
+{
+ ModMetadataDatabase *mod_meta_db = mod_meta_provider->getModMetadataDatabase();
+ StringMap recalled;
+ UASSERT(mod_meta_db->setModEntry("mod1", "key1", "value2"));
+}
+
+void TestModMetadataDatabase::testRecallChanged()
+{
+ ModMetadataDatabase *mod_meta_db = mod_meta_provider->getModMetadataDatabase();
+ StringMap recalled;
+ mod_meta_db->getModEntries("mod1", &recalled);
+ UASSERT(recalled.size() == 1);
+ UASSERT(recalled["key1"] == "value2");
+}
+
+void TestModMetadataDatabase::testListMods()
+{
+ ModMetadataDatabase *mod_meta_db = mod_meta_provider->getModMetadataDatabase();
+ UASSERT(mod_meta_db->setModEntry("mod2", "key1", "value1"));
+ std::vector<std::string> mod_list;
+ mod_meta_db->listMods(&mod_list);
+ UASSERT(mod_list.size() == 2);
+ UASSERT(std::find(mod_list.cbegin(), mod_list.cend(), "mod1") != mod_list.cend());
+ UASSERT(std::find(mod_list.cbegin(), mod_list.cend(), "mod2") != mod_list.cend());
+}
+
+void TestModMetadataDatabase::testRemove()
+{
+ ModMetadataDatabase *mod_meta_db = mod_meta_provider->getModMetadataDatabase();
+ UASSERT(mod_meta_db->removeModEntry("mod1", "key1"));
+}
diff --git a/src/unittest/test_noderesolver.cpp b/src/unittest/test_noderesolver.cpp
index 28da43620..ed66093a9 100644
--- a/src/unittest/test_noderesolver.cpp
+++ b/src/unittest/test_noderesolver.cpp
@@ -56,6 +56,8 @@ void TestNodeResolver::runTests(IGameDef *gamedef)
class Foobar : public NodeResolver {
public:
+ friend class TestNodeResolver; // m_ndef
+
void resolveNodeNames();
content_t test_nr_node1;
diff --git a/src/unittest/test_player.cpp b/src/unittest/test_player.cpp
deleted file mode 100644
index 6990b4016..000000000
--- a/src/unittest/test_player.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-Minetest
-Copyright (C) 2010-2016 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "test.h"
-
-#include "exceptions.h"
-#include "remoteplayer.h"
-#include "server.h"
-
-class TestPlayer : public TestBase
-{
-public:
- TestPlayer() { TestManager::registerTestModule(this); }
- const char *getName() { return "TestPlayer"; }
-
- void runTests(IGameDef *gamedef);
-};
-
-static TestPlayer g_test_instance;
-
-void TestPlayer::runTests(IGameDef *gamedef)
-{
-}
diff --git a/src/unittest/test_schematic.cpp b/src/unittest/test_schematic.cpp
index da4ce50d2..d2f027eb4 100644
--- a/src/unittest/test_schematic.cpp
+++ b/src/unittest/test_schematic.cpp
@@ -66,13 +66,14 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef)
std::stringstream ss(std::ios_base::binary |
std::ios_base::in | std::ios_base::out);
- std::vector<std::string> names;
- names.emplace_back("foo");
- names.emplace_back("bar");
- names.emplace_back("baz");
- names.emplace_back("qux");
-
- Schematic schem, schem2;
+ Schematic schem;
+ {
+ std::vector<std::string> &names = schem.m_nodenames;
+ names.emplace_back("foo");
+ names.emplace_back("bar");
+ names.emplace_back("baz");
+ names.emplace_back("qux");
+ }
schem.flags = 0;
schem.size = size;
@@ -83,18 +84,21 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef)
for (s16 y = 0; y != size.Y; y++)
schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;
- UASSERT(schem.serializeToMts(&ss, names));
+ UASSERT(schem.serializeToMts(&ss));
ss.seekg(0);
- names.clear();
- UASSERT(schem2.deserializeFromMts(&ss, &names));
+ Schematic schem2;
+ UASSERT(schem2.deserializeFromMts(&ss));
- UASSERTEQ(size_t, names.size(), 4);
- UASSERTEQ(std::string, names[0], "foo");
- UASSERTEQ(std::string, names[1], "bar");
- UASSERTEQ(std::string, names[2], "baz");
- UASSERTEQ(std::string, names[3], "qux");
+ {
+ std::vector<std::string> &names = schem2.m_nodenames;
+ UASSERTEQ(size_t, names.size(), 4);
+ UASSERTEQ(std::string, names[0], "foo");
+ UASSERTEQ(std::string, names[1], "bar");
+ UASSERTEQ(std::string, names[2], "baz");
+ UASSERTEQ(std::string, names[3], "qux");
+ }
UASSERT(schem2.size == size);
for (size_t i = 0; i != volume; i++)
@@ -120,14 +124,14 @@ void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef)
for (s16 y = 0; y != size.Y; y++)
schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;
- std::vector<std::string> names;
+ std::vector<std::string> &names = schem.m_nodenames;
names.emplace_back("air");
names.emplace_back("default:lava_source");
names.emplace_back("default:glass");
std::ostringstream ss(std::ios_base::binary);
- UASSERT(schem.serializeToLua(&ss, names, false, 0));
+ UASSERT(schem.serializeToLua(&ss, false, 0));
UASSERTEQ(std::string, ss.str(), expected_lua_output);
}
@@ -159,6 +163,8 @@ void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef)
schem1.slice_probs[0] = 80;
schem1.slice_probs[1] = 160;
schem1.slice_probs[2] = 240;
+ // Node resolving happened manually.
+ schem1.m_resolve_done = true;
for (size_t i = 0; i != volume; i++) {
content_t c = content_map[test_schem2_data[i]];
diff --git a/src/unittest/test_servermodmanager.cpp b/src/unittest/test_servermodmanager.cpp
index e3edb0c32..4c473d8b5 100644
--- a/src/unittest/test_servermodmanager.cpp
+++ b/src/unittest/test_servermodmanager.cpp
@@ -48,14 +48,20 @@ static TestServerModManager g_test_instance;
void TestServerModManager::runTests(IGameDef *gamedef)
{
const char *saved_env_mt_subgame_path = getenv("MINETEST_SUBGAME_PATH");
+ const char *saved_env_mt_mod_path = getenv("MINETEST_MOD_PATH");
#ifdef WIN32
{
std::string subgame_path("MINETEST_SUBGAME_PATH=");
subgame_path.append(TEST_SUBGAME_PATH);
_putenv(subgame_path.c_str());
+
+ std::string mod_path("MINETEST_MOD_PATH=");
+ mod_path.append(TEST_MOD_PATH);
+ _putenv(mod_path.c_str());
}
#else
setenv("MINETEST_SUBGAME_PATH", TEST_SUBGAME_PATH, 1);
+ setenv("MINETEST_MOD_PATH", TEST_MOD_PATH, 1);
#endif
TEST(testCreation);
@@ -75,12 +81,21 @@ void TestServerModManager::runTests(IGameDef *gamedef)
if (saved_env_mt_subgame_path)
subgame_path.append(saved_env_mt_subgame_path);
_putenv(subgame_path.c_str());
+
+ std::string mod_path("MINETEST_MOD_PATH=");
+ if (saved_env_mt_mod_path)
+ mod_path.append(saved_env_mt_mod_path);
+ _putenv(mod_path.c_str());
}
#else
if (saved_env_mt_subgame_path)
setenv("MINETEST_SUBGAME_PATH", saved_env_mt_subgame_path, 1);
else
unsetenv("MINETEST_SUBGAME_PATH");
+ if (saved_env_mt_mod_path)
+ setenv("MINETEST_MOD_PATH", saved_env_mt_mod_path, 1);
+ else
+ unsetenv("MINETEST_MOD_PATH");
#endif
}
@@ -89,6 +104,7 @@ void TestServerModManager::testCreation()
std::string path = std::string(TEST_WORLDDIR) + DIR_DELIM + "world.mt";
Settings world_config;
world_config.set("gameid", "devtest");
+ world_config.set("load_mod_test_mod", "true");
UASSERTEQ(bool, world_config.updateConfigFile(path.c_str()), true);
ServerModManager sm(TEST_WORLDDIR);
}
@@ -119,16 +135,21 @@ void TestServerModManager::testGetMods()
UASSERTEQ(bool, mods.empty(), false);
// Ensure we found basenodes mod (part of devtest)
+ // and test_mod (for testing MINETEST_MOD_PATH).
bool default_found = false;
+ bool test_mod_found = false;
for (const auto &m : mods) {
if (m.name == "basenodes")
default_found = true;
+ if (m.name == "test_mod")
+ test_mod_found = true;
// Verify if paths are not empty
UASSERTEQ(bool, m.path.empty(), false);
}
UASSERTEQ(bool, default_found, true);
+ UASSERTEQ(bool, test_mod_found, true);
}
void TestServerModManager::testGetModspec()
diff --git a/src/unittest/test_socket.cpp b/src/unittest/test_socket.cpp
index 6d5cf334d..620021b59 100644
--- a/src/unittest/test_socket.cpp
+++ b/src/unittest/test_socket.cpp
@@ -97,11 +97,11 @@ void TestSocket::testIPv4Socket()
UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer)) == 0);
if (address != Address(0, 0, 0, 0, port)) {
- UASSERT(sender.getAddress().sin_addr.s_addr ==
- address.getAddress().sin_addr.s_addr);
+ UASSERT(sender.getAddress().s_addr ==
+ address.getAddress().s_addr);
} else {
- UASSERT(sender.getAddress().sin_addr.s_addr ==
- Address(127, 0, 0, 1, 0).getAddress().sin_addr.s_addr);
+ UASSERT(sender.getAddress().s_addr ==
+ Address(127, 0, 0, 1, 0).getAddress().s_addr);
}
}
@@ -128,7 +128,7 @@ void TestSocket::testIPv6Socket()
socket6.Bind(address6);
- try {
+ {
socket6.Send(Address(&bytes, port), sendbuffer, sizeof(sendbuffer));
sleep_ms(50);
@@ -142,10 +142,8 @@ void TestSocket::testIPv6Socket()
}
//FIXME: This fails on some systems
UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer)) == 0);
- UASSERT(memcmp(sender.getAddress6().sin6_addr.s6_addr,
- Address(&bytes, 0).getAddress6().sin6_addr.s6_addr, 16) == 0);
- } catch (SendFailedException &e) {
- errorstream << "IPv6 support enabled but not available!"
- << std::endl;
+
+ UASSERT(memcmp(sender.getAddress6().s6_addr,
+ Address(&bytes, 0).getAddress6().s6_addr, 16) == 0);
}
}
diff --git a/src/unittest/test_utilities.cpp b/src/unittest/test_utilities.cpp
index 93ba3f844..743fe4462 100644
--- a/src/unittest/test_utilities.cpp
+++ b/src/unittest/test_utilities.cpp
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/enriched_string.h"
#include "util/numeric.h"
#include "util/string.h"
+#include "util/base64.h"
class TestUtilities : public TestBase {
public:
@@ -56,6 +57,7 @@ public:
void testMyround();
void testStringJoin();
void testEulerConversion();
+ void testBase64();
};
static TestUtilities g_test_instance;
@@ -87,6 +89,7 @@ void TestUtilities::runTests(IGameDef *gamedef)
TEST(testMyround);
TEST(testStringJoin);
TEST(testEulerConversion);
+ TEST(testBase64);
}
////////////////////////////////////////////////////////////////////////////////
@@ -389,9 +392,9 @@ void TestUtilities::testIsPowerOfTwo()
UASSERT(is_power_of_two(2) == true);
UASSERT(is_power_of_two(3) == false);
for (int exponent = 2; exponent <= 31; ++exponent) {
- UASSERT(is_power_of_two((1 << exponent) - 1) == false);
- UASSERT(is_power_of_two((1 << exponent)) == true);
- UASSERT(is_power_of_two((1 << exponent) + 1) == false);
+ UASSERT(is_power_of_two((1U << exponent) - 1) == false);
+ UASSERT(is_power_of_two((1U << exponent)) == true);
+ UASSERT(is_power_of_two((1U << exponent) + 1) == false);
}
UASSERT(is_power_of_two(U32_MAX) == false);
}
@@ -537,3 +540,93 @@ void TestUtilities::testEulerConversion()
setPitchYawRoll(m2, v2);
UASSERT(within(m1, m2, tolL));
}
+
+void TestUtilities::testBase64()
+{
+ // Test character set
+ UASSERT(base64_is_valid("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/") == true);
+ UASSERT(base64_is_valid("/+9876543210"
+ "zyxwvutsrqponmlkjihgfedcba"
+ "ZYXWVUTSRQPONMLKJIHGFEDCBA") == true);
+ UASSERT(base64_is_valid("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+.") == false);
+ UASSERT(base64_is_valid("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789 /") == false);
+
+ // Test empty string
+ UASSERT(base64_is_valid("") == true);
+
+ // Test different lengths, with and without padding,
+ // with correct and incorrect padding
+ UASSERT(base64_is_valid("A") == false);
+ UASSERT(base64_is_valid("AA") == true);
+ UASSERT(base64_is_valid("AAA") == true);
+ UASSERT(base64_is_valid("AAAA") == true);
+ UASSERT(base64_is_valid("AAAAA") == false);
+ UASSERT(base64_is_valid("AAAAAA") == true);
+ UASSERT(base64_is_valid("AAAAAAA") == true);
+ UASSERT(base64_is_valid("AAAAAAAA") == true);
+ UASSERT(base64_is_valid("A===") == false);
+ UASSERT(base64_is_valid("AA==") == true);
+ UASSERT(base64_is_valid("AAA=") == true);
+ UASSERT(base64_is_valid("AAAA") == true);
+ UASSERT(base64_is_valid("AAAA====") == false);
+ UASSERT(base64_is_valid("AAAAA===") == false);
+ UASSERT(base64_is_valid("AAAAAA==") == true);
+ UASSERT(base64_is_valid("AAAAAAA=") == true);
+ UASSERT(base64_is_valid("AAAAAAA==") == false);
+ UASSERT(base64_is_valid("AAAAAAA===") == false);
+ UASSERT(base64_is_valid("AAAAAAA====") == false);
+ UASSERT(base64_is_valid("AAAAAAAA") == true);
+ UASSERT(base64_is_valid("AAAAAAAA=") == false);
+ UASSERT(base64_is_valid("AAAAAAAA==") == false);
+ UASSERT(base64_is_valid("AAAAAAAA===") == false);
+ UASSERT(base64_is_valid("AAAAAAAA====") == false);
+
+ // Test if canonical encoding
+ // Last character limitations, length % 4 == 3
+ UASSERT(base64_is_valid("AAB") == false);
+ UASSERT(base64_is_valid("AAE") == true);
+ UASSERT(base64_is_valid("AAQ") == true);
+ UASSERT(base64_is_valid("AAB=") == false);
+ UASSERT(base64_is_valid("AAE=") == true);
+ UASSERT(base64_is_valid("AAQ=") == true);
+ UASSERT(base64_is_valid("AAAAAAB=") == false);
+ UASSERT(base64_is_valid("AAAAAAE=") == true);
+ UASSERT(base64_is_valid("AAAAAAQ=") == true);
+ // Last character limitations, length % 4 == 2
+ UASSERT(base64_is_valid("AB") == false);
+ UASSERT(base64_is_valid("AE") == false);
+ UASSERT(base64_is_valid("AQ") == true);
+ UASSERT(base64_is_valid("AB==") == false);
+ UASSERT(base64_is_valid("AE==") == false);
+ UASSERT(base64_is_valid("AQ==") == true);
+ UASSERT(base64_is_valid("AAAAAB==") == false);
+ UASSERT(base64_is_valid("AAAAAE==") == false);
+ UASSERT(base64_is_valid("AAAAAQ==") == true);
+
+ // Extraneous character present
+ UASSERT(base64_is_valid(".") == false);
+ UASSERT(base64_is_valid("A.") == false);
+ UASSERT(base64_is_valid("AA.") == false);
+ UASSERT(base64_is_valid("AAA.") == false);
+ UASSERT(base64_is_valid("AAAA.") == false);
+ UASSERT(base64_is_valid("AAAAA.") == false);
+ UASSERT(base64_is_valid("A.A") == false);
+ UASSERT(base64_is_valid("AA.A") == false);
+ UASSERT(base64_is_valid("AAA.A") == false);
+ UASSERT(base64_is_valid("AAAA.A") == false);
+ UASSERT(base64_is_valid("AAAAA.A") == false);
+ UASSERT(base64_is_valid("\xE1""AAA") == false);
+
+ // Padding in wrong position
+ UASSERT(base64_is_valid("A=A") == false);
+ UASSERT(base64_is_valid("AA=A") == false);
+ UASSERT(base64_is_valid("AAA=A") == false);
+ UASSERT(base64_is_valid("AAAA=A") == false);
+ UASSERT(base64_is_valid("AAAAA=A") == false);
+}
diff --git a/src/unittest/test_voxelarea.cpp b/src/unittest/test_voxelarea.cpp
index 6ec0412d5..9826d2ee7 100644
--- a/src/unittest/test_voxelarea.cpp
+++ b/src/unittest/test_voxelarea.cpp
@@ -30,6 +30,7 @@ public:
void test_addarea();
void test_pad();
+ void test_extent();
void test_volume();
void test_contains_voxelarea();
void test_contains_point();
@@ -65,6 +66,7 @@ void TestVoxelArea::runTests(IGameDef *gamedef)
{
TEST(test_addarea);
TEST(test_pad);
+ TEST(test_extent);
TEST(test_volume);
TEST(test_contains_voxelarea);
TEST(test_contains_point);
@@ -113,10 +115,22 @@ void TestVoxelArea::test_pad()
UASSERT(v1.MaxEdge == v3s16(-47, -9347, 969));
}
+void TestVoxelArea::test_extent()
+{
+ VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669));
+ UASSERT(v1.getExtent() == v3s16(1191, 995, 1459));
+
+ VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768));
+ UASSERT(v2.getExtent() == v3s16(16, 16, 16));
+}
+
void TestVoxelArea::test_volume()
{
- VoxelArea v1(v3s16(-1337, 447, -789), v3s16(-147, -9547, 669));
- UASSERTEQ(s32, v1.getVolume(), -184657133);
+ VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669));
+ UASSERTEQ(s32, v1.getVolume(), 1728980655);
+
+ VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768));
+ UASSERTEQ(s32, v2.getVolume(), 4096);
}
void TestVoxelArea::test_contains_voxelarea()