From: Sam Moore Date: Wed, 26 Mar 2014 16:27:44 +0000 (+0800) Subject: Merge branch 'master' of git.ucc.asn.au:/ipdf/code X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=0d33eac5144178de754ad9f53e39463f79a31398;hp=efdd8b2a07dcf770e325ec1fc9b4b7d908331e23 Merge branch 'master' of git.ucc.asn.au:/ipdf/code Conflicts: src/main.cpp Fixed that and also fixed other things. --- diff --git a/.gitignore b/.gitignore index 82affd5..365a631 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.d *~ *.ipdf +*.test +*.out +*.err diff --git a/src/Makefile b/src/Makefile index 3e8d8a0..6d7f100 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,10 +1,11 @@ #Makefile CXX = g++ -std=gnu++0x -Wall -Werror -Wshadow -pedantic -g -OBJ = log.o tests/saveload.o document.o view.o screen.o +MAIN = main.o +OBJ = log.o document.o view.o screen.o LIB = `sdl2-config --libs` -lGL OBJPATHS = $(OBJ:%=../obj/%) DEPS := $(OBJPATHS:%.o=%.d) -CFLAGS += `sdl2-config --cflags` +CFLAGS += `sdl2-config --cflags` -I`pwd` LINKOBJ = $(OBJPATHS) @@ -14,9 +15,16 @@ BIN = ../bin/ipdf all : $(BIN) -$(BIN) : $(LINKOBJ) +tests/% : tests/%.cpp ../obj/tests/%.o $(LINKOBJ) + $(CXX) -o $@.test $(LINKOBJ) ../obj/$@.o $(LIB) + +runtests : tests/runtests.sh + cd tests; ./runtests.sh + + +$(BIN) : $(LINKOBJ) ../obj/$(MAIN) @mkdir -p $(dir $@) - $(CXX) -o $(BIN) $(LINKOBJ) $(LIB) + $(CXX) -o $(BIN) $(LINKOBJ) ../obj/$(MAIN) $(LIB) ../obj/%.o : %.cpp @mkdir -p $(dir $@) @@ -24,14 +32,21 @@ $(BIN) : $(LINKOBJ) -include $(DEPS) +clean_bin : + $(RM) $(BIN) + clean : - $(RM) $(BIN) $(DEPS) $(LINKOBJ) + $(RM) $(BIN) $(DEPS) $(LINKOBJ) ../obj/$(MAIN) + $(RM) tests/*~ + $(RM) tests/*.test + $(RM) tests/*.out + $(RM) tests/*.err + -clean_full: #cleans up all backup files - $(RM) $(BIN) $(DEPS) $(LINKOBJ) +clean_full: clean $(RM) *.*~ $(RM) *~ - $(RM) *.o + diff --git a/src/log.cpp b/src/log.cpp index 699036b..3af4aca 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -75,13 +75,13 @@ void LogEx(int level, const char * funct, const char * file, int line, ...) severity = "WARNING"; break; case LOG_NOTICE: - severity = "NOTICE"; + severity = "notice"; break; case LOG_INFO: - severity = "INFO"; + severity = "info"; break; default: - severity = "DEBUG"; + severity = "debug"; break; } diff --git a/src/main.cpp b/src/main.cpp index 2a85c14..339ea8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,27 +1,22 @@ -#include "common.h" - -#include "document.h" -#include "view.h" -#include "screen.h" - -using namespace std; -using namespace IPDF; - +#include "main.h" +#include // Because we can. int main(int argc, char ** argv) -{ +{ Document doc; srand(time(NULL)); - doc.Add(RECT_FILLED, Rect(Random(), Random(), Random(), Random())); - - View view(doc); - - Screen scr; - - while (scr.PumpEvents()) + if (argc > 1) { - view.Render(); - scr.Present(); + for (int i = 2; i < argc; ++i) + { + if (fork() == 0) doc.Load(argv[i]); + } + doc.Load(argv[1]); } - + else + { + Debug("Add random object"); + doc.Add(RECT_FILLED, Rect(Random()*0.5, Random()*0.5, Random()*0.5, Random()*0.5)); + } + MainLoop(doc); return 0; } diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..ee8076a --- /dev/null +++ b/src/main.h @@ -0,0 +1,20 @@ +#include "common.h" + +#include "document.h" +#include "view.h" +#include "screen.h" + + +using namespace std; +using namespace IPDF; + +inline void MainLoop(Document & doc) +{ + View view(doc); + Screen scr; + while (scr.PumpEvents()) + { + view.Render(); + scr.Present(); + } +} diff --git a/src/tests/runtests.sh b/src/tests/runtests.sh new file mode 100755 index 0000000..e99cc1e --- /dev/null +++ b/src/tests/runtests.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +for source in *.cpp; do + t=${source%.cpp} + make -C ../ tests/$t 1>>/dev/null + (echo -n "Running $t.test ... ") 1>&2 + ./$t.test 2>$t.err 1>$t.out + if [ $? -ne 0 ]; then + (echo " FAILURE! Press enter to see stderr") 1>&2 + read + less $t.err + (echo "Stopping tests after failure.") 1>&2 + exit 1 + fi + (echo "Success!") 1>&2 +done diff --git a/src/tests/saveload.cpp b/src/tests/saveload.cpp index 32dd1d7..60bfda6 100644 --- a/src/tests/saveload.cpp +++ b/src/tests/saveload.cpp @@ -1,42 +1,46 @@ -#include "../common.h" - -#include "../document.h" -#include "../view.h" -#include "../screen.h" - -using namespace std; -using namespace IPDF; - +#include "main.h" +#include unsigned test_objects = 4; +void Cleanup() +{ + unlink("saveload.ipdf"); +} + int main(int argc, char ** argv) { + Debug("TEST STARTING %s", argv[0]); + atexit(Cleanup); srand(time(NULL)); Document doc; for (unsigned id = 0; id < test_objects; ++id) { doc.Add((ObjectType)(rand() % 2), Rect(Random(), Random(), Random(), Random())); } - doc.Save("test.ipdf"); + doc.Save("saveload.ipdf"); - Document equ("test.ipdf"); + Document equ("saveload.ipdf"); //doc.Add(Random(), Random(), Random(), Random()); if (doc != equ || equ != doc) { Error("Loaded document is not equivelant to saved document!"); doc.DebugDumpObjects(); equ.DebugDumpObjects(); + Fatal("TEST FAILED"); } - - View view(doc); - Screen scr; - - while (scr.PumpEvents()) + doc.Add((ObjectType)(0), Rect()); + if (doc == equ) { - view.Render(); - scr.Present(); + Error("Modified document is still equilant to saved document!?"); + doc.DebugDumpObjects(); + equ.DebugDumpObjects(); + Fatal("TEST FAILED"); } + Debug("TEST SUCCESSFUL"); + // Cleanup return 0; } + +