Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/test/spawn_test.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/test/spawn_test.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/test/spawn_test.cpp')
-rw-r--r--source/test/spawn_test.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/source/test/spawn_test.cpp b/source/test/spawn_test.cpp
new file mode 100644
index 0000000..250dc22
--- /dev/null
+++ b/source/test/spawn_test.cpp
@@ -0,0 +1,48 @@
+#include "StarAssets.hpp"
+#include "StarCelestialDatabase.hpp"
+#include "StarRoot.hpp"
+
+#include "StarTestUniverse.hpp"
+#include "gtest/gtest.h"
+
+using namespace Star;
+
+void validateWorld(TestUniverse& testUniverse) {
+ testUniverse.update(100);
+
+ // Just make sure the test world draws something for now, this will grow to
+ // include more than this.
+ EXPECT_GE(testUniverse.currentClientDrawables().size(), 1u) << strf("world: %s", testUniverse.currentPlayerWorld());
+
+ auto assets = Root::singleton().assets();
+ for (auto const& drawable : testUniverse.currentClientDrawables()) {
+ if (drawable.isImage())
+ assets->image(drawable.imagePart().image);
+ }
+}
+
+TEST(SpawnTest, RandomCelestialWorld) {
+ CelestialMasterDatabase celestialDatabase;
+ Maybe<CelestialCoordinate> celestialWorld = celestialDatabase.findRandomWorld(10, 50, [&](CelestialCoordinate const& coord) {
+ return celestialDatabase.parameters(coord)->isVisitable();
+ });
+ ASSERT_TRUE((bool)celestialWorld);
+
+ TestUniverse testUniverse(Vec2U(100, 100));
+ WorldId worldId = CelestialWorldId(*celestialWorld);
+ testUniverse.warpPlayer(worldId);
+ EXPECT_EQ(testUniverse.currentPlayerWorld(), worldId);
+ validateWorld(testUniverse);
+}
+
+TEST(SpawnTest, RandomInstanceWorld) {
+ auto& root = Root::singleton();
+ StringList instanceWorlds = root.assets()->json("/instance_worlds.config").toObject().keys();
+ ASSERT_GT(instanceWorlds.size(), 0u);
+ WorldId instanceWorld = InstanceWorldId(Random::randFrom(instanceWorlds));
+
+ TestUniverse testUniverse(Vec2U(100, 100));
+ testUniverse.warpPlayer(instanceWorld);
+ EXPECT_EQ(testUniverse.currentPlayerWorld(), instanceWorld);
+ validateWorld(testUniverse);
+}