*.d
*~
*.ipdf
+*.test
+*.out
+*.err
#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)
all : $(BIN)
+tests/% : tests/%.cpp ../obj/tests/%.o $(LINKOBJ)
+
+runtests : tests/runtests.sh
+ cd tests; ./runtests.sh
+
+
$(BIN) : $(LINKOBJ)
@mkdir -p $(dir $@)
- $(CXX) -o $(BIN) $(LINKOBJ) $(LIB)
+ $(CXX) -o $(BIN) $(LINKOBJ) ../obj/$(MAIN) $(LIB)
../obj/%.o : %.cpp
@mkdir -p $(dir $@)
-include $(DEPS)
+clean_bin :
+ $(RM) $(BIN)
+
clean :
$(RM) $(BIN) $(DEPS) $(LINKOBJ)
+ $(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
+
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;
}
-#include "common.h"
-
-#include "document.h"
-#include "view.h"
-#include "screen.h"
-
-using namespace std;
-using namespace IPDF;
-
+#include "main.h"
+#include <unistd.h> // Because we can.
int main(int argc, char ** argv)
-{
+{
Document doc;
- doc.Add(0.5, 0.5, 0.5, 0.5);
-
- 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]);
}
-
+ MainLoop(doc);
return 0;
}
--- /dev/null
+#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();
+ }
+}
--- /dev/null
+#!/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
-#include "../common.h"
-
-#include "../document.h"
-#include "../view.h"
-#include "../screen.h"
-
-using namespace std;
-using namespace IPDF;
-
+#include "main.h"
+#include <unistd.h>
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;
}
+
+