summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/Makefile.am6
-rwxr-xr-xserver/autogen.sh2
-rw-r--r--server/configure.in5
-rw-r--r--server/getdata/Makefile.am28
-rw-r--r--server/getdata/getdata.cc192
-rw-r--r--server/src/Makefile.am5
-rw-r--r--server/src/acl.h33
-rw-r--r--server/src/client_connection.cc60
-rw-r--r--server/src/praxisd.cc2
-rw-r--r--server/tools/Makefile.am6
-rw-r--r--server/tools/Makefile.am.test21
-rw-r--r--server/tools/hexify.cc (renamed from server/src/acl.cc)45
-rwxr-xr-xserver/tools/test55
-rw-r--r--server/tools/test.h262
-rwxr-xr-xserver/tools/testlist31
-rw-r--r--server/xml/Makefile.am2
-rw-r--r--server/xml/courses/Makefile.am7
17 files changed, 473 insertions, 289 deletions
diff --git a/server/Makefile.am b/server/Makefile.am
index 34bd487..cf8151b 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -1,7 +1,7 @@
AUTOMAKE_OPTIONS = gnu
-SUBDIRS = src gentoo/init.d gentoo/logrotate.d \
- etc man xml xml/templates xml/macros $(DOC_DIR)
-DISTDIRS = src etc man xml xml/templates xml/macros $(DOC_DIR)
+SUBDIRS = src gentoo/init.d gentoo/logrotate.d tools \
+ etc man xml $(DOC_DIR)
+DISTDIRS = src etc man xml tools $(DOC_DIR)
.PHONY: doc
doc:
diff --git a/server/autogen.sh b/server/autogen.sh
index 5be400b..6e23e5b 100755
--- a/server/autogen.sh
+++ b/server/autogen.sh
@@ -52,7 +52,7 @@ if [ "$DIE" -eq 1 ]; then
fi
# Create testfiles
-TESTDIRS="src getdata"
+TESTDIRS="src"
for d in $TESTDIRS
do
if [ ! -f $d/Makefile.am.test ]
diff --git a/server/configure.in b/server/configure.in
index fcab921..63e2e24 100644
--- a/server/configure.in
+++ b/server/configure.in
@@ -2,7 +2,7 @@
AC_INIT(src/pracrod.cc)
-VERSION="`cat ../VERSION | cut -d'=' -f2`"
+VERSION="2.2.0"
AM_INIT_AUTOMAKE( pracrod, $VERSION )
dnl ======================
@@ -246,13 +246,14 @@ AC_SUBST(PTHREAD_LIBS)
AC_OUTPUT(
Makefile
src/Makefile
- getdata/Makefile
gentoo/init.d/Makefile
gentoo/init.d/pracrod
gentoo/logrotate.d/Makefile
etc/Makefile
man/Makefile
+ tools/Makefile
xml/templates/Makefile
xml/macros/Makefile
+ xml/courses/Makefile
xml/Makefile)
diff --git a/server/getdata/Makefile.am b/server/getdata/Makefile.am
deleted file mode 100644
index c0e6f09..0000000
--- a/server/getdata/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-bin_PROGRAMS = getdata convertdata
-
-getdata_LDADD = $(LD_EFENCE) $(PQXX_LIBS) $(CONFIG_LIBS)
-
-getdata_CXXFLAGS = $(PQXX_CXXFLAGS) $(CONFIG_CXXFLAGS)
-
-getdata_SOURCES = \
- getdata.cc
-
-convertdata_LDADD = $(LD_EFENCE) $(PQXX_LIBS) $(CONFIG_LIBS)
-
-convertdata_CXXFLAGS = $(PQXX_CXXFLAGS) $(CONFIG_CXXFLAGS)
-
-convertdata_SOURCES = \
- convertdata.cc
-
-EXTRA_DIST =
-
-################
-# Test Section #
-################
-
-TEST_SOURCE_DEPS = ${pracrod_SOURCES} ${EXTRA_DIST}
-TEST_SCRIPT_DIR = $(top_srcdir)/../tools
-
-include ${TEST_SCRIPT_DIR}/Makefile.am.test
-
-include Makefile.am.test \ No newline at end of file
diff --git a/server/getdata/getdata.cc b/server/getdata/getdata.cc
deleted file mode 100644
index 717d1a9..0000000
--- a/server/getdata/getdata.cc
+++ /dev/null
@@ -1,192 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set et sw=2 ts=2: */
-/***************************************************************************
- * getdata.cc
- *
- * Tue Jan 18 08:11:53 CET 2011
- * Copyright 2011 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Pracro.
- *
- * Pracro is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Pracro is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Pracro; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include <string>
-#include <pqxx/pqxx>
-#include <stdlib.h>
-/*
-Commits:
- patientid | template | version | timestamp | uid | status
-
-Transactions:
- macro | version | timestamp | user | uid | cid
-
-Fields:
- transaction | name | value
-*/
-
-#define SEP "\t"
-
-std::string escape(std::string str)
-{
- std::string out = "\"";
- std::string::iterator i = str.begin();
- while(i != str.end()) {
- if(*i == '\"') out += "''";
- else out += *i;
- i++;
- }
- out += "\"";
- return out;
-}
-
-int main()
-{
- std::vector<std::string> fields;
- fields.push_back("visus.egen_korr.mangler.odxt");
- fields.push_back("visus.egen_korr.kontrast.odxt");
- fields.push_back("visus.egen_korr.snellen.odxt");
- fields.push_back("visus.egen_korr.etdrs.odxt");
- fields.push_back("visus.egen_korr.korr.sf.odxt");
- fields.push_back("visus.egen_korr.korr.cyl.odxt");
- fields.push_back("visus.egen_korr.korr.grader.odxt");
- fields.push_back("visus.egen_korr.st_hul.odxt");
- fields.push_back("visus.egen_korr.st_hul.snellen.odxt");
- fields.push_back("visus.egen_korr.st_hul.etdrs.odxt");
- fields.push_back("visus.egen_korr.mangler.osin");
- fields.push_back("visus.egen_korr.kontrast.osin");
- fields.push_back("visus.egen_korr.snellen.osin");
- fields.push_back("visus.egen_korr.etdrs.osin");
- fields.push_back("visus.egen_korr.korr.sf.osin");
- fields.push_back("visus.egen_korr.korr.cyl.osin");
- fields.push_back("visus.egen_korr.korr.grader.osin");
- fields.push_back("visus.egen_korr.st_hul.osin");
- fields.push_back("visus.egen_korr.st_hul.snellen.osin");
- fields.push_back("visus.egen_korr.st_hul.etdrs.osin");
- fields.push_back("visus.egen_korr.ou");
- fields.push_back("visus.egen_korr.kontrast.ou");
- fields.push_back("visus.egen_korr.snellen.ou");
- fields.push_back("visus.egen_korr.etdrs.ou");
-
- std::string like = "ref";
-
- std::string host = "localhost";
- std::string port = "5432";
- std::string user = "pracro";
- std::string password = "pracro";
- std::string dbname = "pracro";
-
- std::string cs = "host="+host+" port="+port+
- " user="+user+" password="+password+" dbname="+dbname;
-
- pqxx::connection conn(cs);
- pqxx::work W(conn);
-
-
-
- std::map<std::string, int> fieldnames;
- int idx = 0;
- pqxx::result Rf = W.exec("SELECT DISTINCT name FROM fields ORDER BY name;");
- pqxx::result::const_iterator rfi = Rf.begin();
- for(unsigned int r = 0; r < Rf.size(); r++) {
- pqxx::result::tuple tuple = Rf.at(r);
- std::string name = tuple.at(0).c_str();
- fieldnames[name] = idx;
- idx++;
- }
-
- printf("patientid"SEP);
- printf("template"SEP);
- printf("macro"SEP);
- printf("version"SEP);
- printf("timestamp"SEP);
- printf("user"SEP);
- printf("uid"SEP);
- std::map<std::string, int>::iterator i = fieldnames.begin();
- while(i != fieldnames.end()) {
- printf("%s"SEP, i->first.c_str());
- i++;
- }
- printf("\n");
-
- pqxx::result R = W.exec("SELECT * FROM transactions WHERE template LIKE '"+like+"%';");
-
- pqxx::result::const_iterator ri = R.begin();
- for(unsigned int r = 0; r < R.size(); r++) {
-
- pqxx::result::tuple tuple = R.at(r);
-
- std::string patientid = tuple.at(PATIENTID).c_str();
- std::string macro = tuple.at(MACRO).c_str();
- std::string version = tuple.at(VERSION).c_str();
- std::string timestamp = tuple.at(TIMESTAMP).c_str();
- std::string user = tuple.at(USER).c_str();
- std::string uid = tuple.at(UID).c_str();
- std::string templ = tuple.at(TEMPLATE).c_str();
-
- pqxx::result Rf = W.exec("SELECT * FROM fields WHERE transaction="+uid+";");
-
- std::vector<std::string> values;
- values.insert(values.begin(), fieldnames.size(), "");
- pqxx::result::const_iterator rfi = Rf.begin();
- for(unsigned int r = 0; r < Rf.size(); r++) {
- pqxx::result::tuple tuple = Rf.at(r);
-
- std::string name = tuple.at(NAME).c_str();
- std::string value = tuple.at(VALUE).c_str();
- values[fieldnames[name]] = value;
- }
-
- printf("%s"SEP, escape(patientid).c_str());
- printf("%s"SEP, escape(templ).c_str());
- printf("%s"SEP, escape(macro).c_str());
- printf("%s"SEP, escape(version).c_str());
- time_t t = atol(timestamp.c_str());
- printf("%s"SEP, escape(ctime(&t)).c_str());
- printf("%s"SEP, escape(user).c_str());
- printf("%s"SEP, escape(uid).c_str());
- std::vector<std::string>::iterator vi = values.begin();
- while(vi != values.end()) {
- printf("%s"SEP, escape(*vi).c_str());
- vi++;
- }
- printf("\n");
-
- }
-
- return 0;
-}
-
-
-
-
-
-
-
-#ifdef TEST_GETDATA
-//deps:
-//cflags:
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
-
-TEST_END;
-
-#endif/*TEST_GETDATA*/
diff --git a/server/src/Makefile.am b/server/src/Makefile.am
index 9f3f100..167f4e4 100644
--- a/server/src/Makefile.am
+++ b/server/src/Makefile.am
@@ -113,6 +113,7 @@ EXTRA_DIST = \
queryhandlerpentominos.h \
queryhandlerpracro.h \
queryparser.h \
+ queryresult.h \
resumeparser.h \
saxparser.h \
semaphore.h \
@@ -120,9 +121,11 @@ EXTRA_DIST = \
session.h \
sessionparser.h \
sessionserialiser.h \
+ template.h \
templatelist.h \
templateheaderparser.h \
templateparser.h \
+ transaction.h \
transactionhandler.h \
transactionparser.h \
tcpsocket.h \
@@ -138,7 +141,7 @@ EXTRA_DIST = \
################
TEST_SOURCE_DEPS = ${pracrod_SOURCES} ${EXTRA_DIST}
-TEST_SCRIPT_DIR = $(top_srcdir)/../tools
+TEST_SCRIPT_DIR = $(top_srcdir)/tools
include ${TEST_SCRIPT_DIR}/Makefile.am.test
diff --git a/server/src/acl.h b/server/src/acl.h
deleted file mode 100644
index 6aaae22..0000000
--- a/server/src/acl.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set et sw=2 ts=2: */
-/***************************************************************************
- * acl.h
- *
- * Mon Apr 11 15:23:18 CEST 2011
- * Copyright 2011 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Pracro.
- *
- * Pracro is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Pracro is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Pracro; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#ifndef __PRACRO_ACL_H__
-#define __PRACRO_ACL_H__
-
-
-
-#endif/*__PRACRO_ACL_H__*/
diff --git a/server/src/client_connection.cc b/server/src/client_connection.cc
index 1ec7e7c..fe55efc 100644
--- a/server/src/client_connection.cc
+++ b/server/src/client_connection.cc
@@ -141,6 +141,18 @@ void ClientConnection::discard(Session *session)
bool ClientConnection::handle(const char *data, size_t size)
{
+ if(patientid == "") {
+ response = error_box(xml_encode("Missing patientid."));
+ parser_complete = true;
+ return true;
+ }
+
+ if(request.course == "") {
+ response = error_box(xml_encode("Missing course."));
+ parser_complete = true;
+ return true;
+ }
+
Session *session = NULL;
try {
if(sessionid == "") {
@@ -159,12 +171,14 @@ bool ClientConnection::handle(const char *data, size_t size)
ERR(connection, "Session already active.\n");
parser_complete = true;
response = error_box(xml_encode("Session "+e.sessionid+" already active."));
+ parser_complete = true;
return true;
}
if(session == NULL) {
ERR(connection, "New session could not be created.\n");
response = error_box(xml_encode("New session could not be created."));
+ parser_complete = true;
return true;
}
@@ -180,6 +194,9 @@ bool ClientConnection::handle(const char *data, size_t size)
return true;
}
+ // Force session discard on empty template name.
+ if(templ == "") dodiscard = true;
+
if(size == 0 || parser.parse(data, size)) {
parser_complete = true;
@@ -195,7 +212,7 @@ bool ClientConnection::handle(const char *data, size_t size)
return true;
}
} catch(...) {
- ERR(server, "Failed to parse data!\n");
+ ERR(connection, "Failed to parse data!\n");
response = error_box(xml_encode("XML Parse error."));
return true;
}
@@ -221,9 +238,9 @@ void ClientConnection::getReply(Httpd::Reply &reply)
}
#ifdef TEST_CLIENT_CONNECTION
-//deps: debug.cc transactionparser.cc session.cc xml_encode_decode.cc saxparser.cc transactionhandler.cc journal.cc mutex.cc templateparser.cc exception.cc configuration.cc macroparser.cc semaphore.cc entitylist.cc luaquerymapper.cc inotify.cc log.cc queryhandlerpentominos.cc widgetgenerator.cc queryhandlerpracro.cc resumeparser.cc journal_commit.cc versionstr.cc luaresume.cc luautil.cc artefact.cc environment.cc database.cc macrolist.cc templatelist.cc pracrodao.cc templateheaderparser.cc macroheaderparser.cc pracrodaotest.cc pracrodaopgsql.cc journal_uploadserver.cc sessionserialiser.cc sessionparser.cc widgetvalue.cc
-//cflags: -DWITHOUT_DATABASE -DWITHOUT_ARTEFACT -I.. $(LUA_CFLAGS) $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) $(PQXX_CXXFLAGS)
-//libs: $(LUA_LIBS) $(EXPAT_LIBS) $(PTHREAD_LIBS) $(PQXX_LIBS)
+//deps: debug.cc transactionparser.cc session.cc xml_encode_decode.cc saxparser.cc transactionhandler.cc journal.cc mutex.cc templateparser.cc exception.cc configuration.cc macroparser.cc semaphore.cc entitylist.cc luaquerymapper.cc inotify.cc log.cc queryhandlerpentominos.cc widgetgenerator.cc queryhandlerpracro.cc resumeparser.cc journal_commit.cc versionstr.cc luaresume.cc luautil.cc artefact.cc environment.cc database.cc macrolist.cc templatelist.cc pracrodao.cc templateheaderparser.cc macroheaderparser.cc pracrodaotest.cc pracrodaopgsql.cc journal_uploadserver.cc sessionserialiser.cc sessionparser.cc widgetvalue.cc courseparser.cc praxisd.cc luapraxisd.cc courselist.cc
+//cflags: -DWITHOUT_DATABASE -DWITHOUT_ARTEFACT -I.. $(LUA_CFLAGS) $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) $(PQXX_CXXFLAGS) $(CURL_CFLAGS)
+//libs: $(LUA_LIBS) $(EXPAT_LIBS) $(PTHREAD_LIBS) $(PQXX_LIBS) $(CURL_LIBS)
#include "test.h"
/*
static char xml_request[] =
@@ -258,8 +275,20 @@ static char xml_commit_p2[] =
"</pracro>\n"
;
*/
+
+static const char empty_reply[] =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<pracro version=\"1.0\">\n"
+ "</pracro>\n";
+
+#include "configuration.h"
+
TEST_BEGIN;
+debug_parse("-all,+connection,+session");
+
+Conf::xml_basedir = "../xml";
+
Environment env;
Httpd::Reply reply;
std::string sid;
@@ -267,28 +296,30 @@ std::string sid;
// Without data
{
headers_t hdrs;
- ClientConnection con(env, hdrs);
+ ClientConnection con(env, hdrs, hdrs, "/test");
TEST_TRUE(con.handle("", 0), "Test handler return value.");
con.getReply(reply);
- TEST_EQUAL_STR(reply.data, "", "Test response value.");
- TEST_NOTEQUAL_STR(reply.headers["SessionID"], "", "Test new session id.");
+ TEST_NOTEQUAL_STR(reply.data, empty_reply, "Did we get nonemtpy reply?");
+ TEST_NOTEQUAL_STR(reply.headers["SessionID"], "",
+ "Did we get a new session id?");
+ sid = reply.headers["SessionID"];
TEST_FALSE(did_commit, "No commit.");
}
{
headers_t hdrs;
- ClientConnection con(env, hdrs);
+ ClientConnection con(env, hdrs, hdrs, "/test/test");
TEST_TRUE(con.handle("", 0), "Test handler return value.");
con.getReply(reply);
- TEST_EQUAL_STR(reply.data, "", "Test response value.");
- TEST_NOTEQUAL_STR(reply.headers["SessionID"], "", "Test existing session id.");
- TEST_EQUAL_STR(reply.headers["SessionID"], sid, "Test existing session id.");
+ TEST_EQUAL_STR(reply.data, empty_reply, "Did we get an empty reponse?");
+ TEST_NOTEQUAL_STR(reply.headers["SessionID"], "", "Non empty session id?");
+ TEST_NOTEQUAL_STR(reply.headers["SessionID"], sid, "Not the same id!");
TEST_FALSE(did_commit, "No commit.");
}
-
+/*
{
headers_t hdrs;
- ClientConnection con(env, hdrs);
+ ClientConnection con(env, hdrs, hdrs, "");
TEST_TRUE(con.handle("", 0), "Test handler return value.");
con.getReply(reply);
TEST_EQUAL_STR(reply.data, "", "Test response value.");
@@ -298,7 +329,7 @@ std::string sid;
{
headers_t hdrs;
- ClientConnection con(env, hdrs);
+ ClientConnection con(env, hdrs, hdrs, "");
TEST_TRUE(con.handle("", 0), "Test handler return value.");
con.getReply(reply);
TEST_EQUAL_STR(reply.data, "", "Test response value.");
@@ -306,6 +337,7 @@ std::string sid;
TEST_NOTEQUAL_STR(reply.headers["SessionID"], sid, "Test new session id.");
TEST_FALSE(did_commit, "No commit.");
}
+*/
/*
// With commit partial data
{
diff --git a/server/src/praxisd.cc b/server/src/praxisd.cc
index a75ad9f..3ccdf0d 100644
--- a/server/src/praxisd.cc
+++ b/server/src/praxisd.cc
@@ -139,7 +139,7 @@ void Praxisd::journal_add(std::string cpr, std::string entry)
// Unset 'Expect' header, set by CURLOPT_POSTFIELDS
slist = curl_slist_append(slist, "Expect:");
slist = curl_slist_append(slist, "Content-Type: text/xml");
- slist = curl_slist_append(slist, "Connection: keep-alive");
+ // slist = curl_slist_append(slist, "Connection: keep-alive");
curl_easy_setopt(ch, CURLOPT_HTTPHEADER, slist);
std::string uri = host + "/praxisd/1.0/journal/add";
diff --git a/server/tools/Makefile.am b/server/tools/Makefile.am
new file mode 100644
index 0000000..8f54004
--- /dev/null
+++ b/server/tools/Makefile.am
@@ -0,0 +1,6 @@
+EXTRA_DIST = \
+ Makefile.am.test \
+ hexify.cc \
+ test \
+ test.h \
+ testlist
diff --git a/server/tools/Makefile.am.test b/server/tools/Makefile.am.test
new file mode 100644
index 0000000..cad2627
--- /dev/null
+++ b/server/tools/Makefile.am.test
@@ -0,0 +1,21 @@
+Makefile.am.test: ${TEST_SOURCE_DEPS}
+ ${TEST_SCRIPT_DIR}/testlist > Makefile.am.test
+ @touch Makefile.am
+
+test: Makefile.am.test $(TESTFILES)
+ @echo "All tests done."
+
+test_clean:
+ rm -Rf lgov
+ rm -f $(TESTFILES) $(TESTLOGS)
+
+test_report:
+ lcov --directory . --capture --output-file app.info
+ genhtml -o lcov app.info
+
+test_all: test_clean test test_report
+
+TESTLOGS = `for F in ${TESTFILES}; do echo $$F.log; done`
+
+CLEANFILES = $(TESTFILES) $(TESTLOGS) Makefile.am.test *~
+
diff --git a/server/src/acl.cc b/server/tools/hexify.cc
index ec9d7d2..8f8b308 100644
--- a/server/src/acl.cc
+++ b/server/tools/hexify.cc
@@ -1,9 +1,9 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set et sw=2 ts=2: */
/***************************************************************************
- * acl.cc
+ * hexify.cc
*
- * Mon Apr 11 15:23:18 CEST 2011
+ * Mon Feb 7 08:42:59 CET 2011
* Copyright 2011 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -25,21 +25,38 @@
* along with Pracro; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "acl.h"
+#include <stdio.h>
-#ifdef TEST_ACL
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
+#define WIDTH 12
-TEST_BEGIN;
+int main(int argc, char *argv[])
+{
+ if(argc < 2) {
+ printf("Usage %s file\n", argv[0]);
+ return 1;
+ }
+ FILE *fp = fopen(argv[1], "r");
+ if(!fp) {
+ printf("Could not open %s\n", argv[1]);
+ return 1;
+ }
+ int cnt = 0;
+ printf("static const char val[] = {");
+ while(!feof(fp)) {
+ unsigned char c;
+ int sz = fread(&c, 1, 1, fp);
+ if(cnt) printf(", ");
+ if(cnt % WIDTH == 0) printf("\n ");
+ printf("0x%02x", c);
+ cnt++;
+ }
+ printf("\n};\n");
+ printf("static int valsize = %d;\n", cnt);
-TEST_END;
+ fclose(fp);
+
+ return 0;
+}
-#endif/*TEST_ACL*/
diff --git a/server/tools/test b/server/tools/test
new file mode 100755
index 0000000..ec54e70
--- /dev/null
+++ b/server/tools/test
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+TEST=`echo -n $1 | cut -d'.' -f1`
+UPPER=`echo $TEST | tr 'a-z.' 'A-Z_'`
+OUTPUT=test_$TEST
+DEFINE=TEST_$UPPER
+
+SCRIPTDIR=`dirname $0`
+
+INFILE=$1
+shift
+OBJFILES=""
+for f in $TEST_DEPS
+do
+ of=`echo -n $f | cut -d'.' -f1`.o;
+ OBJFILES="$OBJFILES $of"
+done
+
+COMMON_FLAGS="-DHAVE_CONFIG_H -I$SCRIPTDIR -O0 -g -D$DEFINE $TEST_LIBS $TEST_CFLAGS"
+CLEAN="rm -f $OBJFILES"
+PRECOMPILE="g++ -c $TEST_DEPS $COMMON_FLAGS"
+COMPILE="g++ -fprofile-arcs -ftest-coverage -fno-elide-constructors -Wall -Werror $COMMON_FLAGS -o $OUTPUT $INFILE $OBJFILES"
+
+echo -e "\033[0;2mTesting $TEST:"
+echo Testing $TEST: > $OUTPUT.log
+
+echo -n "* Compiling $TEST test"
+echo Compiling $TEST test: > $OUTPUT.log
+
+echo ${CLEAN} >> $OUTPUT.log
+${CLEAN} >> ${OUTPUT}.log 2>&1
+echo ${PRECOMPILE} >> $OUTPUT.log
+${PRECOMPILE} >> ${OUTPUT}.log 2>&1
+echo ${COMPILE} >> $OUTPUT.log
+
+if ${COMPILE} >> ${OUTPUT}.log 2>&1; then
+ echo -e "\r\t\t\t\t\t\t[\033[1;32mSuccess\033[0;2m]"
+ echo "[Success]" >> $OUTPUT.log
+
+ echo -n "* Running $TEST test"
+ echo Running $TEST test: >> $OUTPUT.log
+ if ./$OUTPUT >> $OUTPUT.log 2>&1; then
+ echo -e "\r\t\t\t\t\t\t[\033[1;32mSuccess\033[0;2m]"
+ echo "[Success]" >> $OUTPUT.log
+ else
+ echo -e "\r\t\t\t\t\t\t[\033[1;31mFailure\033[0;2m]"
+ echo "[Failure]" >> $OUTPUT.log
+ rm -f $OUTPUT
+ fi
+else
+ echo -e "\r\t\t\t\t\t\t[\033[1;31mFailure\033[0;2m]"
+ echo "[Failure]" >> $OUTPUT.log
+fi
+
+echo \ No newline at end of file
diff --git a/server/tools/test.h b/server/tools/test.h
new file mode 100644
index 0000000..4770a1e
--- /dev/null
+++ b/server/tools/test.h
@@ -0,0 +1,262 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * test.h
+ *
+ * Wed Dec 16 12:33:19 CET 2009
+ * Copyright 2009 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_TEST_H__
+#define __PRACRO_TEST_H__
+
+#include <stdio.h>
+
+#define TEST_REPORT { \
+ fprintf(stderr, "\nTest report:\n%d tests\n%d test failed.\n", \
+ TEST_num_tests, TEST_num_fails); \
+ }
+
+#define TEST_BEGIN \
+ int main() { \
+ int TEST_num_fails = 0; \
+ int TEST_num_tests = 0; \
+ {}
+
+#define TEST_END { \
+ TEST_REPORT; \
+ return TEST_num_fails != 0; \
+ } }
+
+#define TEST_OK(m) { \
+ fprintf(stderr, " OK: "m"\n"); \
+ }
+
+#define TEST_FAIL(m) { \
+ fprintf(stderr, " FAIL: "m"\t\t\t<------------\n"); \
+ TEST_num_fails++; \
+ }
+
+#define TEST_FATAL(m) { \
+ fprintf(stderr, "FATAL: %s\t\t\t<============\n", m); \
+ TEST_num_fails++; \
+ { TEST_END; }
+
+#define TEST_MSG(fmt...) { \
+ fprintf(stderr, "\n"); \
+ fprintf(stderr, fmt); \
+ fprintf(stderr, " (line %d)\n", __LINE__); \
+ }
+
+#define TEST_BASE(fmt...) { \
+ TEST_num_tests++; \
+ TEST_MSG(fmt); \
+ }
+
+#define TEST_TRUE(x, fmt...) { \
+ TEST_BASE(fmt); \
+ if(x) { TEST_OK(#x" is true.") } \
+ else { TEST_FAIL(#x" is not true.") } \
+ }
+
+#define TEST_FALSE(x, fmt...) { \
+ TEST_BASE(fmt); \
+ if(!x) { TEST_OK(#x" is false.") } \
+ else { TEST_FAIL(#x" is not false.") } \
+ }
+
+#define TEST_EQUAL(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ if(x == y) { TEST_OK(#x" and "#y" are equal.") } \
+ else { TEST_FAIL(#x" and "#y" are not equal.") } \
+ }
+
+#define TEST_NOTEQUAL(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ if(x != y) { TEST_OK(#x" and "#y" are not equal.") } \
+ else { TEST_FAIL(#x" and "#y" are equal.") } \
+ }
+
+#define TEST_GREATER_THAN(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ if(x > y) { TEST_OK(#x" are greater than "#y".") } \
+ else { TEST_FAIL(#x" are not greater than "#y".") } \
+ }
+
+#define TEST_LESS_THAN(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ if(x < y) { TEST_OK(#x" are less than "#y".") } \
+ else { TEST_FAIL(#x" are not less than "#y".") } \
+ }
+
+#define TEST_EQUAL_STR(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ std::string __s1 = x; \
+ std::string __s2 = y; \
+ fprintf(stderr, "Comparing: \"%s\" == \"%s\"\n", \
+ __s1.c_str(), __s2.c_str()); \
+ if(__s1 == __s2) { \
+ TEST_OK(#x" and "#y" are equal."); \
+ } else { \
+ TEST_FAIL(#x" and "#y" are not equal."); \
+ } \
+ }
+
+#define TEST_NOTEQUAL_STR(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ std::string __s1 = x; \
+ std::string __s2 = y; \
+ fprintf(stderr, "Comparing: \"%s\" != \"%s\"\n", \
+ __s1.c_str(), __s2.c_str()); \
+ if(__s1 != __s2) { \
+ TEST_OK(#x" and "#y" not are equal."); \
+ } else { \
+ TEST_FAIL(#x" and "#y" are equal."); \
+ } \
+ }
+
+#define TEST_EQUAL_INT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ int i1 = x; \
+ int i2 = y; \
+ fprintf(stderr, "Comparing: \"%d\" == \"%d\"\n", i1, i2); \
+ if(i1 == i2) { \
+ TEST_OK(#x" and "#y" are equal."); \
+ } else { \
+ TEST_FAIL(#x" and "#y" are not equal."); \
+ } \
+ }
+
+#define TEST_NOTEQUAL_INT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ int i1 = x; \
+ int i2 = y; \
+ fprintf(stderr, "Comparing: \"%d\" != \"%d\"\n", i1, i2); \
+ if(i1 != i2) { \
+ TEST_OK(#x" and "#y" are not equal."); \
+ } else { \
+ TEST_FAIL(#x" and "#y" are equal."); \
+ } \
+ }
+
+#define TEST_EQUAL_FLOAT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ double d1 = x; \
+ double d2 = y; \
+ fprintf(stderr, "Comparing: \"%f\" == \"%f\"\n", d1, d2); \
+ if(d1 == d2) { \
+ TEST_OK(#x" and "#y" are equal."); \
+ } else { \
+ TEST_FAIL(#x" and "#y" are not equal."); \
+ } \
+ }
+
+#define TEST_NOTEQUAL_FLOAT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ double d1 = x; \
+ double d2 = y; \
+ fprintf(stderr, "Comparing: \"%f\" != \"%f\"\n", d1, d2); \
+ if(d1 != d2) { \
+ TEST_OK(#x" and "#y" are not equal."); \
+ } else { \
+ TEST_FAIL(#x" and "#y" are equal."); \
+ } \
+ }
+
+#define TEST_GREATER_THAN_INT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ int i1 = x; \
+ int i2 = y; \
+ fprintf(stderr, "Comparing: \"%d\" > \"%d\"\n", i1, i2); \
+ if(i1 > i2) { \
+ TEST_OK(#x" are greater than "#y"."); \
+ } else { \
+ TEST_FAIL(#x" are not greater than "#y"."); \
+ } \
+ }
+
+#define TEST_LESS_THAN_INT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ int i1 = x; \
+ int i2 = y; \
+ fprintf(stderr, "Comparing: \"%d\" < \"%d\"\n", i1, i2); \
+ if(i1 < i2) { \
+ TEST_OK(#x" are less than "#y"."); \
+ } else { \
+ TEST_FAIL(#x" are not less than "#y"."); \
+ } \
+ }
+
+#define TEST_GREATER_THAN_FLOAT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ double d1 = x; \
+ double d2 = y; \
+ fprintf(stderr, "Comparing: \"%f\" > \"%f\"\n", d1, d2); \
+ if(d1 > d2) { \
+ TEST_OK(#x" are greater than "#y"."); \
+ } else { \
+ TEST_FAIL(#x" are not greater than "#y"."); \
+ } \
+ }
+
+#define TEST_LESS_THAN_FLOAT(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ double d1 = x; \
+ double d2 = y; \
+ fprintf(stderr, "Comparing: \"%f\" < \"%f\"\n", d1, d2); \
+ if(d1 < d2) { \
+ TEST_OK(#x" are less than "#y"."); \
+ } else { \
+ TEST_FAIL(#x" are not less than "#y"."); \
+ } \
+ }
+
+#define TEST_EXCEPTION(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ try { \
+ x; \
+ TEST_FAIL("Exception "#y" was not trown."); \
+ } catch( y &e ) { \
+ TEST_OK("Exception "#y" was thrown as expected."); \
+ } \
+ }
+
+#define TEST_NOTEXCEPTION(x, y, fmt...) { \
+ TEST_BASE(fmt); \
+ try { \
+ x; \
+ TEST_OK("Exception "#y" was not trown as expected"); \
+ } catch( y &e ) { \
+ TEST_FAIL("Exception "#y" was thrown."); \
+ } \
+ }
+
+#define TEST_NOEXCEPTION(x, fmt...) { \
+ TEST_BASE(fmt); \
+ try { \
+ x; \
+ TEST_OK("Exception was not trown as expected"); \
+ } catch( ... ) { \
+ TEST_FAIL("Exception was thrown."); \
+ } \
+ }
+
+#endif/*__PRACRO_TEST_H__*/
diff --git a/server/tools/testlist b/server/tools/testlist
new file mode 100755
index 0000000..01a48e2
--- /dev/null
+++ b/server/tools/testlist
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+SCRIPTDIR=`dirname $0`
+
+grep -l "TEST_BEGIN" *.cc > tmp
+
+echo -n "TESTFILES="
+while read LINE
+do
+ FILE=$LINE
+ NAME=`echo $FILE | cut -d'.' -f1`
+ TEST=test_$NAME
+ echo -ne "$TEST "
+done < tmp
+echo ""
+echo ""
+
+while read LINE
+do
+ FILE=$LINE
+ NAME=`echo $FILE | cut -d'.' -f1`
+ DEPS=`cat $FILE | grep "deps:" | cut -d':' -f2`
+ LIBS=`cat $FILE | grep "libs:" | cut -d':' -f2`
+ CFLAGS=`cat $FILE | grep "cflags:" | cut -d':' -f2`
+ TEST=test_$NAME
+ echo "$TEST: $FILE $DEPS"
+ echo -e "\t@TEST_DEPS=\"$DEPS\" TEST_CFLAGS=\"$CFLAGS\" TEST_LIBS=\"$LIBS\" ${SCRIPTDIR}/test $FILE"
+ echo ""
+done < tmp
+
+rm -f tmp \ No newline at end of file
diff --git a/server/xml/Makefile.am b/server/xml/Makefile.am
index a478a79..350048a 100644
--- a/server/xml/Makefile.am
+++ b/server/xml/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = templates macros courses
+
EXTRA_DIST =
xmldir = $(datadir)/xml
diff --git a/server/xml/courses/Makefile.am b/server/xml/courses/Makefile.am
new file mode 100644
index 0000000..5f769c4
--- /dev/null
+++ b/server/xml/courses/Makefile.am
@@ -0,0 +1,7 @@
+EXTRA_DIST = \
+ test.xml
+
+xmldir = $(datadir)/xml/courses
+
+xml_DATA = \
+ test.xml