aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_server.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-06-01 23:18:24 +0200
committerGitHub <noreply@github.com>2017-06-01 23:18:24 +0200
commit1c69476d9f10540088ead63c8bcae91f46bc84d8 (patch)
tree5eb9653c3fb7ea03cf08810fb19415bfab065254 /src/script/cpp_api/s_server.cpp
parenta7787bb9d27851b3e8ff9ff388e50793ee5120ed (diff)
downloadminetest-1c69476d9f10540088ead63c8bcae91f46bc84d8.tar.gz
minetest-1c69476d9f10540088ead63c8bcae91f46bc84d8.tar.bz2
minetest-1c69476d9f10540088ead63c8bcae91f46bc84d8.zip
Show singlenode mapgen to menu (#5868)
Fix #5867
Diffstat (limited to 'src/script/cpp_api/s_server.cpp')
0 files changed, 0 insertions, 0 deletions
href='#n126'>126 127 128 129 130 131
/*
Minetest
Copyright (C) 2018 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>

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

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

	void runTests(IGameDef *gamedef);

	void testRefCounting();
	void testSelfAssignment();
	void testNullHandling();
};

static TestIrrPtr g_test_instance;

void TestIrrPtr::runTests(IGameDef *gamedef)
{
	TEST(testRefCounting);
	TEST(testSelfAssignment);
	TEST(testNullHandling);
}

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

#define UASSERT_REFERENCE_COUNT(object, value, info)                                     \
	UTEST((object)->getReferenceCount() == value,                                    \
			info "Reference count is %d instead of " #value,                 \
			(object)->getReferenceCount())

void TestIrrPtr::testRefCounting()
{
	IReferenceCounted *obj = new IReferenceCounted(); // RC=1
	obj->grab();
	UASSERT_REFERENCE_COUNT(obj, 2, "Pre-condition failed: ");
	{
		irr_ptr<IReferenceCounted> p1{obj}; // move semantics
		UASSERT(p1.get() == obj);
		UASSERT_REFERENCE_COUNT(obj, 2, );

		irr_ptr<IReferenceCounted> p2{p1}; // copy ctor
		UASSERT(p1.get() == obj);
		UASSERT(p2.get() == obj);
		UASSERT_REFERENCE_COUNT(obj, 3, );

		irr_ptr<IReferenceCounted> p3{std::move(p1)}; // move ctor
		UASSERT(p1.get() == nullptr);
		UASSERT(p3.get() == obj);
		UASSERT_REFERENCE_COUNT(obj, 3, );

		p1 = std::move(p2); // move assignment
		UASSERT(p1.get() == obj);
		UASSERT(p2.get() == nullptr);