3 Copyright (C) 2015 est31, <MTest31@outlook.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.
22 #include "util/areastore.h"
24 class TestAreaStore : public TestBase {
26 TestAreaStore() { TestManager::registerTestModule(this); }
27 const char *getName() { return "TestAreaStore"; }
29 void runTests(IGameDef *gamedef);
31 void genericStoreTest(AreaStore *store);
32 void testVectorStore();
33 void testSpatialStore();
36 static TestAreaStore g_test_instance;
38 void TestAreaStore::runTests(IGameDef *gamedef)
40 TEST(testVectorStore);
42 TEST(testSpatialStore);
46 ////////////////////////////////////////////////////////////////////////////////
48 void TestAreaStore::testVectorStore()
50 VectorAreaStore store;
51 genericStoreTest(&store);
54 void TestAreaStore::testSpatialStore()
57 SpatialAreaStore store;
58 genericStoreTest(&store);
62 void TestAreaStore::genericStoreTest(AreaStore *store)
64 Area a(v3s16(-10, -3, 5), v3s16(0, 29, 7));
65 Area b(v3s16(-5, -2, 5), v3s16(0, 28, 6));
66 Area c(v3s16(-7, -3, 6), v3s16(-1, 27, 7));
67 std::vector<Area *> res;
69 UASSERTEQ(size_t, store->size(), 0);
70 store->reserve(2); // sic
71 store->insertArea(&a);
72 store->insertArea(&b);
73 store->insertArea(&c);
74 UASSERTEQ(size_t, store->size(), 3);
76 store->getAreasForPos(&res, v3s16(-1, 0, 6));
77 UASSERTEQ(size_t, res.size(), 3);
79 store->getAreasForPos(&res, v3s16(0, 0, 7));
80 UASSERTEQ(size_t, res.size(), 1);
83 store->removeArea(a.id);
85 store->getAreasForPos(&res, v3s16(0, 0, 7));
86 UASSERTEQ(size_t, res.size(), 0);
89 store->insertArea(&a);
91 store->getAreasForPos(&res, v3s16(0, 0, 7));
92 UASSERTEQ(size_t, res.size(), 1);
95 store->getAreasInArea(&res, v3s16(-10, -3, 5), v3s16(0, 29, 7), false);
96 UASSERTEQ(size_t, res.size(), 3);
99 store->getAreasInArea(&res, v3s16(-100, 0, 6), v3s16(200, 0, 6), false);
100 UASSERTEQ(size_t, res.size(), 0);
103 store->getAreasInArea(&res, v3s16(-100, 0, 6), v3s16(200, 0, 6), true);
104 UASSERTEQ(size_t, res.size(), 3);
107 store->removeArea(a.id);
108 store->removeArea(b.id);
109 store->removeArea(c.id);
111 Area d(v3s16(-100, -300, -200), v3s16(-50, -200, -100));
113 store->insertArea(&d);
115 store->getAreasForPos(&res, v3s16(-75, -250, -150));
116 UASSERTEQ(size_t, res.size(), 1);
117 UASSERTEQ(u16, res[0]->data.size(), 3);
118 UASSERT(strncmp(res[0]->data.c_str(), "Hi!", 3) == 0);
121 store->removeArea(d.id);