*.l2o
/build/*/l2e
/build/*/local.mk
+/build/*/test-all
shots/
bin/*
l2e.depend
SDL_IMG_FLAGS = $(shell pkg-config --cflags SDL_image)
SDL_IMG_LIBS = $(shell pkg-config --libs SDL_image)
+CPPUNIT_FLAGS = $(shell pkg-config --cflags cppunit)
+CPPUNIT_LIBS = $(shell pkg-config --libs cppunit)
+
# set to empty to show tool invocations
VERBOSE = @
-L2E_DIRS := $(shell cd $(srcdir) && find * -type d)
-L2E_SRCS := $(shell cd $(srcdir)&& find * -type f -name '*.cpp')
+L2E_DIRS := $(shell cd $(TOP) && find src -type d)
+L2E_SRCS := $(shell cd $(TOP) && find src -type f -name '*.cpp')
L2E_DEPS = $(L2E_SRCS:%.cpp=%.d)
L2E_OBJS = $(L2E_SRCS:%.cpp=%.o)
L2E_EXES = l2e
+L2E_TEST_DIRS := $(shell cd $(TOP) && find tests -type d)
+L2E_TEST_SRCS := $(shell cd $(TOP) && find tests -type f -name '*.cpp')
+L2E_TEST_DEPS := $(L2E_TEST_SRCS:%.cpp=%.d)
+L2E_TEST_OBJS := $(L2E_TEST_SRCS:%.cpp=%.o)
+L2E_TEST_EXES := test-all
+
L2E_FLAGS = $(sort $(strip \
$(SDL_FLAGS) \
$(SDL_IMG_FLAGS) \
$(SDL_IMG_LIBS) \
))
+L2E_TEST_FLAGS = $(L2E_FLAGS) $(CPPUNIT_FLAGS)
+L2E_TEST_LIBS = $(L2E_LIBS) $(CPPUNIT_LIBS)
+
-include $(L2E_DEPS)
+-include $(L2E_TEST_DEPS)
-$(L2E_OBJS): %.o: $(srcdir)/%.cpp
+$(L2E_OBJS): %.o: $(TOP)/%.cpp
-@$(MKDIR) "$(@D)"
@echo "compile: $@"
$(VERBOSE) $(CXX) -c -o "$@" -MMD -MP -MF"$*.d" -MT"$@" "$<" \
$(VERBOSE) $(CXX) -o "$@" $^ \
$(L2E_FLAGS) $(L2E_LIBS) $(LDFLAGS)
+$(L2E_TEST_OBJS): %.o: $(TOP)/%.cpp
+ -@$(MKDIR) "$(@D)"
+ @echo "compile: $@"
+ $(VERBOSE) $(CXX) -c -o "$@" -MMD -MP -MF"$*.d" -MT"$@" "$<" \
+ $(L2E_TEST_FLAGS) $(CPPFLAGS) $(CXXFLAGS)
+
+$(L2E_TEST_EXES): $(L2E_TEST_OBJS) $(filter-out src/main.o, $(L2E_OBJS))
+ -@$(MKDIR) "$(@D)"
+ @echo "link: $@"
+ $(VERBOSE) $(CXX) -o "$@" $^ \
+ $(L2E_TEST_FLAGS) $(L2E_TEST_LIBS) $(LDFLAGS)
+
l2e-all: $(L2E_EXES)
l2e-clean:
$(VERBOSE) -$(RM) $(L2E_DEPS)
$(VERBOSE) -$(RM) $(L2E_OBJS)
$(VERBOSE) -$(RM) $(L2E_EXES)
+ $(VERBOSE) -$(RM) $(L2E_TEST_DEPS)
+ $(VERBOSE) -$(RM) $(L2E_TEST_OBJS)
+ $(VERBOSE) -$(RM) $(L2E_TEST_EXES)
$(VERBOSE) -$(RMDIR) $(L2E_DIRS)
+ $(VERBOSE) -$(RMDIR) $(L2E_TEST_DIRS)
+
+l2e-tests: $(L2E_TEST_EXES)
+
+l2e-test-all: test-all
+ @echo "test: test-all"
+ $(VERBOSE) ./test-all
all: l2e-all
clean: l2e-clean
+tests: l2e-tests
+test: l2e-test-all
-.PHONY: l2e-all l2e-clean
+.PHONY: l2e-all l2e-clean l2e-tests l2e-test-all
-include $(BUILD)l2e-local.mk
clean:
@echo "clean"
-.PHONY: all clean
+tests:
+
+test:
+
+.PHONY: all clean tests test
Its long-term goal is feature-completeness with Lufia 2.
Quickstart
- cd build/release; make all; ./2e ../../test-data/*.l2s
+ cd build/release; make all; ./l2e ../../test-data/*.l2s
Building
To build the binary, simply enter the desired build configuration directory
* Build confiuration specific settings should go into
`/build/$config/local.mk', e.g. `/build/debug/local.mk'.
+ Unit tests can be built with `make tests' and run with `make test'.
+ If a unit test should fail for you, please file a bug at
+ http://luke.redirectme.net/redmine/projects/l2e/issues/new and describe
+ * your architecture and operating system,
+ * versions of the libs,
+ * and which test(s) failed.
+ Patches are also welcome :)
+
Dependencies
Runtime
* SDL
* pkg-config
* and a number of core utilities such as rm, mkdir, and an sh-compatible
shell.
+ Building and running unit tests
+ * cppunit
Launching
The current version required huge amounts of symbols to be defined and does
--- /dev/null
+#include "../src/sdl/InitImage.h"
+#include "../src/sdl/InitSDL.h"
+
+#include <iostream>
+#include <SDL.h>
+#include <SDL_image.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+using CppUnit::TestFactoryRegistry;
+using CppUnit::TextUi::TestRunner;
+
+
+int main(int argc, char **argv) {
+
+ try {
+ sdl::InitSDL sdl;
+ sdl::InitImage image(IMG_INIT_PNG);
+
+ TestRunner runner;
+ TestFactoryRegistry ®istry = TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ runner.run();
+ } catch (std::exception &e) {
+ std::cerr << "exception in main(): " << e.what() << std::endl;
+ return 1;
+ }
+
+ return 0;
+
+}
--- /dev/null
+#include "VectorTest.h"
+
+#include <limits>
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test_geometry::VectorTest);
+
+using geometry::Vector;
+
+
+namespace test_geometry {
+
+void VectorTest::setUp() {
+
+}
+
+void VectorTest::tearDown() {
+
+}
+
+
+void VectorTest::testComparison() {
+ CPPUNIT_ASSERT_EQUAL(Vector<int>(0, 0), Vector<int>(0, 0));
+
+ CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(0, 1));
+ CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 0));
+ CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 1));
+}
+
+void VectorTest::testSum() {
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(1, 1),
+ Vector<int>(1, 1) + Vector<int>(0, 0));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(1, 1),
+ Vector<int>(0, 1) + Vector<int>(1, 0));
+
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(1, 1),
+ Vector<int>(1, 1) - Vector<int>(0, 0));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(0, 1),
+ Vector<int>(1, 1) - Vector<int>(1, 0));
+}
+
+void VectorTest::testProduct() {
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(2, 3) * Vector<int>(1, 1));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(10, 12),
+ Vector<int>(2, 3) * Vector<int>(5, 4));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(2, 3) * 1);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(4, 6),
+ Vector<int>(2, 3) * 2);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ 1 * Vector<int>(2, 3));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(4, 6),
+ 2 * Vector<int>(2, 3));
+
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(10, 12),
+ Vector<int>(10, 12) / Vector<int>(1, 1));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(10, 12) / Vector<int>(5, 4));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(4, 6),
+ Vector<int>(4, 6) / 1);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(2, 3),
+ Vector<int>(4, 6) / 2);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(3, 4),
+ 12 / Vector<int>(4, 3));
+}
+
+void VectorTest::testModulo() {
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(0, 0),
+ Vector<int>(1, 2) % Vector<int>(1, 1));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(0, 0),
+ Vector<int>(1, 2) % 1);
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(3, 1),
+ Vector<int>(3, 5) % Vector<int>(4, 2));
+ CPPUNIT_ASSERT_EQUAL(
+ Vector<int>(3, 1),
+ Vector<int>(3, 5) % 4);
+
+ Vector<float> vecf = Vector<float>(4.0f, 5.0f) % Vector<float>(2.0f, 3.0f);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
+
+ vecf = Vector<float>(4.0f, 5.0f) % 4.0f;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
+
+ Vector<double> vecd = Vector<double>(4.0, 5.0) % Vector<double>(2.0, 3.0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, vecd.Y(), std::numeric_limits<double>::epsilon());
+
+ vecd = Vector<double>(4.0, 5.0) % 4.0;
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vecd.Y(), std::numeric_limits<double>::epsilon());
+}
+
+void VectorTest::testFunctional() {
+ const Vector<int> vec(2, 5);
+ CPPUNIT_ASSERT_EQUAL(2, vec.X());
+ CPPUNIT_ASSERT_EQUAL(5, vec.Y());
+ CPPUNIT_ASSERT_EQUAL(52, vec.Index(10));
+
+ const Vector<int> indexVec = Vector<int>::FromIndex(52, 10);
+ CPPUNIT_ASSERT_EQUAL(vec, indexVec);
+
+ Vector<int> lockedVec = Vector<int>(vec);
+ lockedVec.Lock(Vector<int>(2, 2));
+ CPPUNIT_ASSERT_EQUAL(Vector<int>(2, 4), lockedVec);
+}
+
+}
--- /dev/null
+#ifndef TEST_GEOMETRY_VECTORTEST_H_
+#define TEST_GEOMETRY_VECTORTEST_H_
+
+#include "../../src/geometry/Vector.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace test_geometry {
+
+class VectorTest
+: public CppUnit::TestFixture {
+
+CPPUNIT_TEST_SUITE(VectorTest);
+CPPUNIT_TEST(testComparison);
+CPPUNIT_TEST(testSum);
+CPPUNIT_TEST(testProduct);
+CPPUNIT_TEST(testModulo);
+CPPUNIT_TEST(testFunctional);
+CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+ void tearDown();
+
+ void testComparison();
+ void testSum();
+ void testProduct();
+ void testModulo();
+ void testFunctional();
+
+};
+
+}
+
+#endif