diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/AssetTest.cpp | 26 | ||||
| -rw-r--r-- | src/test/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/test/OptionalRefTest.cpp | 47 | ||||
| -rw-r--r-- | src/test/ParticleTest.cpp | 2 | 
4 files changed, 77 insertions, 1 deletions
| diff --git a/src/test/AssetTest.cpp b/src/test/AssetTest.cpp new file mode 100644 index 0000000..8aa7629 --- /dev/null +++ b/src/test/AssetTest.cpp @@ -0,0 +1,26 @@ +#include <gtest/gtest.h> + +#include <crepe/api/Asset.h> +#include <crepe/api/Config.h> + +using namespace std; +using namespace crepe; +using namespace testing; + +class AssetTest : public Test { +public: +	Config & cfg = Config::get_instance(); +	void SetUp() override { this->cfg.asset.root_pattern = ".crepe-root"; } +}; + +TEST_F(AssetTest, Existant) { ASSERT_NO_THROW(Asset{"asset/texture/img.png"}); } + +TEST_F(AssetTest, Nonexistant) { ASSERT_ANY_THROW(Asset{"asset/nonexistant"}); } + +TEST_F(AssetTest, Rootless) { +	cfg.asset.root_pattern.clear(); + +	string arbitrary = "\\/this is / /../passed through as-is"; +	Asset asset{arbitrary}; +	ASSERT_EQ(arbitrary, asset.get_path()); +} diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index dc985a3..8cb4232 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -3,6 +3,9 @@ target_sources(test_main PUBLIC  	PhysicsTest.cpp  	ScriptTest.cpp  	ParticleTest.cpp +	AssetTest.cpp +	OptionalRefTest.cpp +	RenderSystemTest.cpp  	EventTest.cpp  	ECSTest.cpp  	SceneManagerTest.cpp diff --git a/src/test/OptionalRefTest.cpp b/src/test/OptionalRefTest.cpp new file mode 100644 index 0000000..1c69348 --- /dev/null +++ b/src/test/OptionalRefTest.cpp @@ -0,0 +1,47 @@ +#include <gtest/gtest.h> + +#include <crepe/util/OptionalRef.h> + +using namespace std; +using namespace crepe; +using namespace testing; + +TEST(OptionalRefTest, Normal) { +	string value = "foo"; +	OptionalRef<string> ref = value; + +	EXPECT_TRUE(ref); +	ASSERT_NO_THROW({ +		string & value_ref = ref; +		EXPECT_EQ(value_ref, value); +	}); + +	ref.clear(); +	EXPECT_FALSE(ref); +	ASSERT_THROW({ +		string & value_ref = ref; +	}, runtime_error); +} + +TEST(OptionalRefTest, Empty) { +	string value = "foo"; +	OptionalRef<string> ref; + +	EXPECT_FALSE(ref); +	ASSERT_THROW({ +		string & value_ref = ref; +	}, runtime_error); +} + +TEST(OptionalRefTest, Chain) { +	string value = "foo"; +	OptionalRef<string> ref1 = value; +	OptionalRef<string> ref2 = ref1; + +	EXPECT_TRUE(ref2); +	string & value_ref = ref2; +	EXPECT_EQ(value_ref, value); +	value_ref = "bar"; +	EXPECT_EQ(value_ref, value); +} + diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index d9bbba0..eee022f 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -29,7 +29,7 @@ public:  			Color color(0, 0, 0, 0);  			Sprite & test_sprite = game_object.add_component<Sprite>( -				make_shared<Texture>("../asset/texture/img.png"), color, +				make_shared<Texture>("asset/texture/img.png"), color,  				FlipSettings{true, true});  			game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{ |