aboutsummaryrefslogtreecommitdiff
path: root/data/glass.png
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-05-18 21:59:31 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-05-18 21:59:31 +0300
commitcdfb5345e980741f19c2ba02b06c24a763cd3e18 (patch)
tree31861f3d0f54676e1f9183026228f0414e8b70e3 /data/glass.png
parent9de8e59c2033e155a5ed9be49bbf57b11e6b91fd (diff)
downloadminetest-cdfb5345e980741f19c2ba02b06c24a763cd3e18.tar.gz
minetest-cdfb5345e980741f19c2ba02b06c24a763cd3e18.tar.bz2
minetest-cdfb5345e980741f19c2ba02b06c24a763cd3e18.zip
small comment update
Diffstat (limited to 'data/glass.png')
0 files changed, 0 insertions, 0 deletions
>105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/*
Minetest
Copyright (C) 2018 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 <server.h>
#include "test.h"

#include "util/string.h"
#include "util/serialize.h"

class FakeServer : public Server
{
public:
	FakeServer() : Server("fakeworld", SubgameSpec("fakespec", "fakespec"), true,
					Address(), true, nullptr)
	{
	}

private:
	void SendChatMessage(session_t peer_id, const ChatMessage &message)
	{
		// NOOP
	}
};

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

	void runTests(IGameDef *gamedef);

	void testInit();
	void testReset();
	void testTrigger();
	void testTick();
};

static TestServerShutdownState g_test_instance;

void TestServerShutdownState::runTests(IGameDef *gamedef)
{
	TEST(testInit);
	TEST(testReset);
	TEST(testTrigger);
	TEST(testTick);
}

void TestServerShutdownState::testInit()
{
	Server::ShutdownState ss;
	UASSERT(!ss.is_requested);
	UASSERT(!ss.should_reconnect);
	UASSERT(ss.message.empty());
	UASSERT(ss.m_timer == 0.0f);
}

void TestServerShutdownState::testReset()
{
	Server::ShutdownState ss;
	ss.reset();
	UASSERT(!ss.is_requested);
	UASSERT(!ss.should_reconnect);
	UASSERT(ss.message.empty());
	UASSERT(ss.m_timer == 0.0f);
}

void TestServerShutdownState::testTrigger()
{
	Server::ShutdownState ss;
	ss.trigger(3.0f, "testtrigger", true);
	UASSERT(!ss.is_requested);
	UASSERT(ss.should_reconnect);
	UASSERT(ss.message == "testtrigger");
	UASSERT(ss.m_timer == 3.0f);
}

void TestServerShutdownState::testTick()
{
	auto fakeServer = std::make_unique<FakeServer>();
	Server::ShutdownState ss;
	ss.trigger(28.0f, "testtrigger", true);
	ss.tick(0.0f, fakeServer.get());

	// Tick with no time should not change anything
	UASSERT(!ss.is_requested);
	UASSERT(ss.should_reconnect);
	UASSERT(ss.message == "testtrigger");
	UASSERT(ss.m_timer == 28.0f);

	// Tick 2 seconds
	ss.tick(2.0f, fakeServer.get());
	UASSERT(!ss.is_requested);
	UASSERT(ss.should_reconnect);
	UASSERT(ss.message == "testtrigger");
	UASSERT(ss.m_timer == 26.0f);

	// Tick remaining seconds + additional expire
	ss.tick(26.1f, fakeServer.get());
	UASSERT(ss.is_requested);
	UASSERT(ss.should_reconnect);
	UASSERT(ss.message == "testtrigger");
	UASSERT(ss.m_timer == 0.0f);
}