3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
25 #include "inventory.h"
27 class TestInventory : public TestBase {
29 TestInventory() { TestManager::registerTestModule(this); }
30 const char *getName() { return "TestInventory"; }
32 void runTests(IGameDef *gamedef);
34 void testSerializeDeserialize(IItemDefManager *idef);
36 static const char *serialized_inventory;
37 static const char *serialized_inventory_2;
40 static TestInventory g_test_instance;
42 void TestInventory::runTests(IGameDef *gamedef)
44 TEST(testSerializeDeserialize, gamedef->getItemDefManager());
47 ////////////////////////////////////////////////////////////////////////////////
49 void TestInventory::testSerializeDeserialize(IItemDefManager *idef)
52 std::istringstream is(serialized_inventory, std::ios::binary);
55 UASSERT(inv.getList("0"));
56 UASSERT(!inv.getList("main"));
58 inv.getList("0")->setName("main");
59 UASSERT(!inv.getList("0"));
60 UASSERT(inv.getList("main"));
61 UASSERTEQ(u32, inv.getList("main")->getWidth(), 3);
63 inv.getList("main")->setWidth(5);
64 std::ostringstream inv_os(std::ios::binary);
65 inv.serialize(inv_os);
66 UASSERTEQ(std::string, inv_os.str(), serialized_inventory_2);
69 const char *TestInventory::serialized_inventory =
81 "Item default:cobble 61\n"
88 "Item default:dirt 71\n"
96 "Item default:dirt 99\n"
97 "Item default:cobble 38\n"
107 const char *TestInventory::serialized_inventory_2 =
119 "Item default:cobble 61\n"
126 "Item default:dirt 71\n"
134 "Item default:dirt 99\n"
135 "Item default:cobble 38\n"