diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-06-03 00:33:12 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-06-03 22:31:02 +0300 |
commit | e4bc76f55cb3314a6e6cbd47e5dedd1923ad5328 (patch) | |
tree | 818024a9674568ecdbf29aa29f012dc75fb93110 /src | |
parent | 81c5e5200bcc20be6b1513a440b2c45985fe3c49 (diff) | |
download | minetest-e4bc76f55cb3314a6e6cbd47e5dedd1923ad5328.tar.gz minetest-e4bc76f55cb3314a6e6cbd47e5dedd1923ad5328.tar.bz2 minetest-e4bc76f55cb3314a6e6cbd47e5dedd1923ad5328.zip |
Add a bit of unit test for inventory
Diffstat (limited to 'src')
-rw-r--r-- | src/test.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/test.cpp b/src/test.cpp index cb01edffd..ecbf653f9 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "utility_string.h" #include "voxelalgorithms.h" +#include "inventory.h" /* Asserts that the exception occurs @@ -650,6 +651,98 @@ struct TestVoxelAlgorithms } }; +struct TestInventory +{ + void Run(IItemDefManager *idef) + { + std::string serialized_inventory = + "List 0 32\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Item default:cobble 61\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Item default:dirt 71\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Item default:dirt 99\n" + "Item default:cobble 38\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "EndInventoryList\n" + "EndInventory\n"; + + std::string serialized_inventory_2 = + "List main 32\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Item default:cobble 61\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Item default:dirt 71\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Item default:dirt 99\n" + "Item default:cobble 38\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "Empty\n" + "EndInventoryList\n" + "EndInventory\n"; + + Inventory inv(idef); + std::istringstream is(serialized_inventory, std::ios::binary); + inv.deSerialize(is); + assert(inv.getList("0")); + assert(!inv.getList("main")); + inv.getList("0")->setName("main"); + assert(!inv.getList("0")); + assert(inv.getList("main")); + std::ostringstream inv_os(std::ios::binary); + inv.serialize(inv_os); + assert(inv_os.str() == serialized_inventory_2); + } +}; + /* NOTE: These tests became non-working then NodeContainer was removed. These should be redone, utilizing some kind of a virtual @@ -1447,6 +1540,7 @@ void run_tests() TESTPARAMS(TestMapNode, ndef); TESTPARAMS(TestVoxelManipulator, ndef); TESTPARAMS(TestVoxelAlgorithms, ndef); + TESTPARAMS(TestInventory, idef); //TEST(TestMapBlock); //TEST(TestMapSector); if(INTERNET_SIMULATOR == false){ |