aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/bucket
diff options
context:
space:
mode:
authorDS-Minetest <vorunbekannt75@web.de>2019-09-19 19:50:15 +0200
committersfan5 <sfan5@live.de>2019-09-22 22:12:49 +0200
commitcf78e37da37d7565a6602034f1ba6c244936bc0c (patch)
treed8f60709e93b69467cd19435c11946650c49d175 /games/minimal/mods/bucket
parent70f9e1aafa6cd7a2b2d204609cab6cc26539cdb9 (diff)
downloadminetest-cf78e37da37d7565a6602034f1ba6c244936bc0c.tar.gz
minetest-cf78e37da37d7565a6602034f1ba6c244936bc0c.tar.bz2
minetest-cf78e37da37d7565a6602034f1ba6c244936bc0c.zip
Move the code for meta formspec into bool Game::nodePlacement(const ItemDefinition &selected_def,
Diffstat (limited to 'games/minimal/mods/bucket')
0 files changed, 0 insertions, 0 deletions
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/*
Minetest
Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net>

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 "objdef.h"

class TestObjDef : public TestBase
{
public:
	TestObjDef() { TestManager::registerTestModule(this); }
	const char *getName() { return "TestObjDef"; }

	void runTests(IGameDef *gamedef);

	void testHandles();
	void testAddGetSetClear();
	void testClone();
};

static TestObjDef g_test_instance;

void TestObjDef::runTests(IGameDef *gamedef)
{
	TEST(testHandles);
	TEST(testAddGetSetClear);
	TEST(testClone);
}

////////////////////////////////////////////////////////////////////////////////

/* Minimal implementation of ObjDef and ObjDefManager subclass */

class MyObjDef : public ObjDef
{
public:
	ObjDef *clone() const
	{
		auto def = new MyObjDef();
		ObjDef::cloneTo(def);
		def->testvalue = testvalue;
		return def;
	};

	u32 testvalue;
};

class MyObjDefManager : public ObjDefManager
{
public:
	MyObjDefManager(ObjDefType type) : ObjDefManager(NULL, type){};
	MyObjDefManager *clone() const
	{
		auto mgr = new MyObjDefManager();
		ObjDefManager::cloneTo(mgr);
		return mgr;
	};

protected:
	MyObjDefManager(){};
};

void TestObjDef::testHandles()
{
	u32 uid = 0;
	u32 index = 0;
	ObjDefType type = OBJDEF_GENERIC;

	ObjDefHandle handle = ObjDefManager::createHandle(9530, OBJDEF_ORE, 47);

	UASSERTEQ(ObjDefHandle, 0xAF507B55, handle);

	UASSERT(ObjDefManager::decodeHandle(handle, &index, &type, &uid));

	UASSERTEQ(u32, 9530, index);
	UASSERTEQ(u32, 47, uid);
	UASSERTEQ(ObjDefHandle, OBJDEF_ORE, type);
}

void TestObjDef::testAddGetSetClear()
{
	ObjDefManager testmgr(NULL, OBJDEF_GENERIC);
	ObjDefHandle hObj0, hObj1, hObj2, hObj3;
	ObjDef *obj0, *obj1, *obj2, *obj3;

	UASSERTEQ(ObjDefType, testmgr.getType(), OBJDEF_GENERIC);

	obj0 = new MyObjDef;
	obj0->name = "foobar";
	hObj0 = testmgr.add(obj0);
	UASSERT(hObj0 != OBJDEF_INVALID_HANDLE);
	UASSERTEQ(u32, obj0->index, 0);

	obj1 = new MyObjDef;
	obj1->name = "FooBaz";
	hObj1 = testmgr.add(obj1);
	UASSERT(hObj1 != OBJDEF_INVALID_HANDLE);
	UASSERTEQ(u32, obj1->index, 1);

	obj2 = new MyObjDef;
	obj2->name = "asdf";
	hObj2 = testmgr.add(obj2);
	UASSERT(hObj2 != OBJDEF_INVALID_HANDLE);
	UASSERTEQ(u32, obj2->index, 2);

	obj3 = new MyObjDef;
	obj3->name = "foobaz";
	hObj3 = testmgr.add(obj3);
	UASSERT(hObj3 == OBJDEF_INVALID_HANDLE);

	UASSERTEQ(size_t, testmgr.getNumObjects(), 3);

	UASSERT(testmgr.get(hObj0) == obj0);
	UASSERT(testmgr.getByName("FOOBAZ") == obj1);

	UASSERT(testmgr.set(hObj0, obj3) == obj0);
	UASSERT(testmgr.get(hObj0) == obj3);
	delete obj0;

	testmgr.clear();
	UASSERTEQ(size_t, testmgr.getNumObjects(), 0);
}

void TestObjDef::testClone()
{
	MyObjDefManager testmgr(OBJDEF_GENERIC);
	ObjDefManager *mgrcopy;
	MyObjDef *obj, *temp2;
	ObjDef *temp1;
	ObjDefHandle hObj;

	obj = new MyObjDef;