3 Copyright (C) 2010-2016 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "exceptions.h"
23 #include "remoteplayer.h"
24 #include "content_sao.h"
27 class TestPlayer : public TestBase {
29 TestPlayer() { TestManager::registerTestModule(this); }
30 const char *getName() { return "TestPlayer"; }
32 void runTests(IGameDef *gamedef);
34 void testSave(IGameDef *gamedef);
35 void testLoad(IGameDef *gamedef);
38 static TestPlayer g_test_instance;
40 void TestPlayer::runTests(IGameDef *gamedef)
42 TEST(testSave, gamedef);
43 TEST(testLoad, gamedef);
46 void TestPlayer::testSave(IGameDef *gamedef)
48 RemotePlayer rplayer("testplayer_save", gamedef->idef());
49 PlayerSAO sao(NULL, 1, false);
50 sao.initialize(&rplayer, std::set<std::string>());
51 rplayer.setPlayerSAO(&sao);
52 sao.setBreath(10, false);
56 sao.setBasePosition(v3f(450.2f, -15.7f, 68.1f));
57 rplayer.save(".", gamedef);
58 UASSERT(fs::PathExists("testplayer_save"));
61 void TestPlayer::testLoad(IGameDef *gamedef)
63 RemotePlayer rplayer("testplayer_load", gamedef->idef());
64 PlayerSAO sao(NULL, 1, false);
65 sao.initialize(&rplayer, std::set<std::string>());
66 rplayer.setPlayerSAO(&sao);
67 sao.setBreath(10, false);
71 sao.setBasePosition(v3f(450.2f, -15.7f, 68.1f));
72 rplayer.save(".", gamedef);
73 UASSERT(fs::PathExists("testplayer_load"));
75 RemotePlayer rplayer_load("testplayer_load", gamedef->idef());
76 PlayerSAO sao_load(NULL, 2, false);
77 std::ifstream is("testplayer_load", std::ios_base::binary);
79 rplayer_load.deSerialize(is, "testplayer_load", &sao_load);
82 UASSERT(strcmp(rplayer_load.getName(), "testplayer_load") == 0);
83 UASSERT(sao_load.getBreath() == 10);
84 UASSERT(sao_load.getHP() == 8);
85 UASSERT(sao_load.getYaw() == 0.1f);
86 UASSERT(sao_load.getPitch() == 0.6f);
87 UASSERT(sao_load.getBasePosition() == v3f(450.2f, -15.7f, 68.1f));