mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 06:32:23 +01:00
Convert nodedef tests to Catch2 (#15045)
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
parent
5d18b6fcd0
commit
c893e0b72b
@ -17,38 +17,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "test.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "gamedef.h"
|
#include "gamedef.h"
|
||||||
#include "nodedef.h"
|
#include "nodedef.h"
|
||||||
#include "network/networkprotocol.h"
|
#include "network/networkprotocol.h"
|
||||||
|
|
||||||
class TestNodeDef : public TestBase
|
#include <catch.h>
|
||||||
{
|
|
||||||
public:
|
|
||||||
TestNodeDef() { TestManager::registerTestModule(this); }
|
|
||||||
const char *getName() { return "TestNodeDef"; }
|
|
||||||
|
|
||||||
void runTests(IGameDef *gamedef);
|
#include <ios>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
void testContentFeaturesSerialization();
|
|
||||||
};
|
|
||||||
|
|
||||||
static TestNodeDef g_test_instance;
|
TEST_CASE("Given a node definition, "
|
||||||
|
"when we serialize and then deserialize it, "
|
||||||
void TestNodeDef::runTests(IGameDef *gamedef)
|
"then the deserialized one should be equal to the original.",
|
||||||
{
|
"[nodedef]")
|
||||||
TEST(testContentFeaturesSerialization);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void TestNodeDef::testContentFeaturesSerialization()
|
|
||||||
{
|
{
|
||||||
ContentFeatures f;
|
ContentFeatures f;
|
||||||
|
|
||||||
f.name = "default:stone";
|
f.name = "default:stone";
|
||||||
for (TileDef &tiledef : f.tiledef)
|
for (TileDef &tiledef : f.tiledef)
|
||||||
tiledef.name = "default_stone.png";
|
tiledef.name = "default_stone.png";
|
||||||
@ -56,12 +40,10 @@ void TestNodeDef::testContentFeaturesSerialization()
|
|||||||
|
|
||||||
std::ostringstream os(std::ios::binary);
|
std::ostringstream os(std::ios::binary);
|
||||||
f.serialize(os, LATEST_PROTOCOL_VERSION);
|
f.serialize(os, LATEST_PROTOCOL_VERSION);
|
||||||
// verbosestream<<"Test ContentFeatures size: "<<os.str().size()<<std::endl;
|
|
||||||
|
|
||||||
std::istringstream is(os.str(), std::ios::binary);
|
std::istringstream is(os.str(), std::ios::binary);
|
||||||
ContentFeatures f2;
|
ContentFeatures f2;
|
||||||
f2.deSerialize(is, LATEST_PROTOCOL_VERSION);
|
f2.deSerialize(is, LATEST_PROTOCOL_VERSION);
|
||||||
|
|
||||||
UASSERT(f.walkable == f2.walkable);
|
CHECK(f.walkable == f2.walkable);
|
||||||
UASSERT(f.node_box.type == f2.node_box.type);
|
CHECK(f.node_box.type == f2.node_box.type);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user