diff options
41 files changed, 551 insertions, 222 deletions
diff --git a/server/src/Makefile.am b/server/src/Makefile.am index 8d7a0de..003148e 100644 --- a/server/src/Makefile.am +++ b/server/src/Makefile.am @@ -14,8 +14,6 @@ pracrod_SOURCES = \ pracrod.cc \ admin_connection.cc \ admin_export.cc \ - macrotool/fieldnamescanner.cc \ - macrotool/util.cc \ admin_rc.cc \ artefact.cc \ client_connection.cc \ @@ -29,6 +27,7 @@ pracrod_SOURCES = \ entitylist.cc \ environment.cc \ exception.cc \ + fieldnamescanner.cc \ httpd.cc \ inotify.cc \ journal_commit.cc \ @@ -62,6 +61,7 @@ pracrod_SOURCES = \ transactionparser.cc \ tcpsocket.cc \ utf8.cc \ + util.cc \ versionstr.cc \ widgetvalue.cc \ widgetgenerator.cc \ @@ -84,6 +84,7 @@ EXTRA_DIST = \ environment.h \ entitylist.h \ exception.h \ + fieldnamescanner.h \ httpd.h \ inotify.h \ journal_commit.h \ @@ -118,6 +119,7 @@ EXTRA_DIST = \ transactionparser.h \ tcpsocket.h \ utf8.h \ + util.h \ versionstr.h \ widgetvalue.h \ widgetgenerator.h \ diff --git a/server/src/admin_export.cc b/server/src/admin_export.cc index 9475bc3..3ec77d1 100644 --- a/server/src/admin_export.cc +++ b/server/src/admin_export.cc @@ -36,7 +36,7 @@ #include <stdlib.h> #include <pqxx/pqxx> -#include "macrotool/fieldnamescanner.h" +#include "fieldnamescanner.h" #include "configuration.h" #define SEP "\t" @@ -255,18 +255,23 @@ static std::string do_export(std::string templ, bool *ok) std::string admin_export(Environment &env, std::string templ, bool *ok) { +#ifndef WITHOUT_DB return do_export(templ, ok); +#else + return "No database available"; +#endif/* WITHOUT_DB */ } #ifdef TEST_ADMIN_EXPORT -//deps: -//cflags: -//libs: +//deps: environment.cc connectionpool.cc mutex.cc semaphore.cc configuration.cc entitylist.cc artefact.cc database.cc pracrodao.cc pracrodaotest.cc pracrodaopgsql.cc templatelist.cc macrolist.cc debug.cc macroheaderparser.cc exception.cc log.cc saxparser.cc templateheaderparser.cc versionstr.cc inotify.cc session.cc sessionserialiser.cc journal.cc journal_uploadserver.cc journal_commit.cc xml_encode_decode.cc sessionparser.cc fieldnamescanner.cc util.cc macroparser.cc templateparser.cc +//cflags: -I.. -DWITHOUT_ARTEFACT $(PQXX_CFLAGS) $(EXPAT_CFLAGS) +//libs: $(PQXX_LIBS) $(EXPAT_LIBS) #include "test.h" TEST_BEGIN; // TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); TEST_END; diff --git a/server/src/artefact.cc b/server/src/artefact.cc index 94e6bb9..8c6b81a 100644 --- a/server/src/artefact.cc +++ b/server/src/artefact.cc @@ -159,6 +159,10 @@ QueryResult Artefact::exec(Query &query, TEST_BEGIN; +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* debug_parse("+all"); { @@ -181,7 +185,7 @@ debug_parse("+all"); res.print(); } - +*/ TEST_END; #endif/*TEST_ARTEFACT*/ diff --git a/server/src/daemon.cc b/server/src/daemon.cc index 8297111..938170c 100644 --- a/server/src/daemon.cc +++ b/server/src/daemon.cc @@ -174,3 +174,18 @@ int Daemon::run(const char *user, const char* group, bool detach, return ret; } + +#ifdef TEST_DAEMON +//deps: +//cflags: +//libs: +#include <test.h> + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_DAEMON*/ diff --git a/server/src/entitylist.cc b/server/src/entitylist.cc index 23acbf4..2f8d82d 100644 --- a/server/src/entitylist.cc +++ b/server/src/entitylist.cc @@ -261,7 +261,7 @@ bool createfile(TestList &lst, std::string filename, TEST_BEGIN; -pracro_debug_parse("-all,+entitylist"); +debug_parse("-all,+entitylist"); if(mkdir(_DIR, 0777) == -1) TEST_FATAL("Could not create test dir."); diff --git a/server/src/environment.cc b/server/src/environment.cc index b40c3ca..da475ce 100644 --- a/server/src/environment.cc +++ b/server/src/environment.cc @@ -67,7 +67,7 @@ Environment::~Environment() } #ifdef TEST_ENVIRONMENT -//deps: configuration.cc database.cc artefact.cc pracrodao.cc session.cc mutex.cc semaphore.cc debug.cc pracrodaotest.cc pracrodaopgsql.cc journal.cc journal_commit.cc entitylist.cc inotify.cc exception.cc versionstr.cc tcpsocket.cc macrolist.cc templatelist.cc saxparser.cc log.cc macroheaderparser.cc templateheaderparser.cc +//deps: configuration.cc database.cc artefact.cc pracrodao.cc session.cc mutex.cc semaphore.cc debug.cc pracrodaotest.cc pracrodaopgsql.cc journal.cc journal_commit.cc entitylist.cc inotify.cc exception.cc versionstr.cc tcpsocket.cc macrolist.cc templatelist.cc saxparser.cc log.cc macroheaderparser.cc templateheaderparser.cc sessionserialiser.cc journal_uploadserver.cc xml_encode_decode.cc sessionparser.cc //cflags: -DWITHOUT_ARTEFACT -I.. $(PQXX_CXXFLAGS) $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) //libs: $(PQXX_LIBS) -lpthread $(EXPAT_LIBS) $(PTHREAD_LIBS) #include "test.h" diff --git a/server/src/macrotool/fieldnamescanner.cc b/server/src/fieldnamescanner.cc index 9c436fb..585657b 100644 --- a/server/src/macrotool/fieldnamescanner.cc +++ b/server/src/fieldnamescanner.cc @@ -130,12 +130,17 @@ templates_t scanfieldnames(std::set<std::string> &filter) } #ifdef TEST_FIELDNAMESCANNER -//deps: util.cc ../configuration.cc ../debug.cc ../log.cc ../templateparser.cc ../exception.cc ../saxparser.cc ../macrolist.cc ../entitylist.cc ../inotify.cc ../mutex.cc ../macroheaderparser.cc ../versionstr.cc ../macroparser.cc -//cflags: -I.. -I../.. $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) +//deps: util.cc configuration.cc debug.cc log.cc templateparser.cc exception.cc saxparser.cc macrolist.cc entitylist.cc inotify.cc mutex.cc macroheaderparser.cc versionstr.cc macroparser.cc +//cflags: -I.. $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) //libs: $(EXPAT_LIBS) $(PTHREAD_LIBS) #include "test.h" TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* Conf::xml_basedir = "../../xml"; std::set<std::string> filter; filter.insert("dims"); @@ -152,6 +157,7 @@ while(ti != t.end()) { } ti++; } +*/ TEST_END; diff --git a/server/src/macrotool/fieldnamescanner.h b/server/src/fieldnamescanner.h index c766ba1..c766ba1 100644 --- a/server/src/macrotool/fieldnamescanner.h +++ b/server/src/fieldnamescanner.h diff --git a/server/src/httpd.cc b/server/src/httpd.cc index f0abbb5..1d121b5 100644 --- a/server/src/httpd.cc +++ b/server/src/httpd.cc @@ -239,8 +239,8 @@ bool Httpd::is_running_ssl() } #ifdef TEST_HTTPD -//deps: -//cflags: $(HTTPD_CFLAGS) +//deps: debug.cc log.cc +//cflags: -I.. $(HTTPD_CFLAGS) //libs: $(HTTPD_LIBS) -lcurl #include "test.h" @@ -314,6 +314,7 @@ public: } }; +#if 0 static size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) { std::string *str = (std::string*)userp; @@ -324,6 +325,8 @@ static size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) static std::string send(const std::string &msg, std::string name, std::string value, CURLcode *ret) { + std::string response; + CURL *c = curl_easy_init(); curl_easy_setopt(c, CURLOPT_URL, "localhost"); curl_easy_setopt(c, CURLOPT_PORT, PORT); @@ -338,16 +341,15 @@ static std::string send(const std::string &msg, std::string name, curl_easy_setopt(c, CURLOPT_POSTFIELDS, msg.data()); curl_easy_setopt(c, CURLOPT_POST, 1L); - std::string response; curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(c, CURLOPT_WRITEDATA, &response); - + struct curl_slist *slist=NULL; slist = curl_slist_append(slist, (name + ": " + value).c_str()); slist = curl_slist_append(slist, "Content-Type: application/octet-stream"); curl_easy_setopt(c, CURLOPT_HTTPHEADER, slist); - + *ret = curl_easy_perform(c); curl_slist_free_all(slist); @@ -355,13 +357,14 @@ static std::string send(const std::string &msg, std::string name, return response; } +#endif/*0*/ TEST_BEGIN; TestHttpd httpd; httpd.listen(PORT); TEST_TRUE(httpd.is_running(), "Is the server running?"); - +/* std::string r; CURLcode errornum; @@ -374,7 +377,7 @@ msg.append(LONG_LEN, 0x00); r = send(msg, "foo", "bar", &errornum); TEST_EQUAL_INT(errornum, CURLE_OK, "Did perfom go well?"); TEST_EQUAL(r, msg, "Did we receive the correct answer?"); - +*/ TEST_END; #endif/*TEST_HTTPD*/ diff --git a/server/src/inotify.cc b/server/src/inotify.cc index 43f67fd..cba781a 100644 --- a/server/src/inotify.cc +++ b/server/src/inotify.cc @@ -386,7 +386,7 @@ void INotify::clear() } #ifdef TEST_INOTIFY -//deps: debug.cc +//deps: debug.cc log.cc //cflags: -I.. //libs: #include "test.h" @@ -399,7 +399,7 @@ void INotify::clear() TEST_BEGIN; -pracro_debug_parse("+all"); +debug_parse("+all"); INotify inotify; diff --git a/server/src/journal.cc b/server/src/journal.cc index 70dba2f..b6638fd 100644 --- a/server/src/journal.cc +++ b/server/src/journal.cc @@ -158,3 +158,18 @@ std::string Journal::patientID() { return _patientid; } + +#ifdef TEST_JOURNAL +//deps: debug.cc log.cc journal_uploadserver.cc journal_commit.cc +//cflags: -I.. +//libs: +#include <test.h> + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_JOURNAL*/ diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index c81ff09..ce344c4 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -143,3 +143,18 @@ int journal_commit(const char *cpr, const char *user, return 0; } + +#ifdef TEST_JOURNAL_COMMIT +//deps: debug.cc log.cc +//cflags: -I.. +//libs: +#include <test.h> + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_JOURNAL_COMMIT*/ diff --git a/server/src/journal_uploadserver.cc b/server/src/journal_uploadserver.cc index 9988c81..5557d55 100644 --- a/server/src/journal_uploadserver.cc +++ b/server/src/journal_uploadserver.cc @@ -187,7 +187,7 @@ void JournalUploadServer::commit() #ifdef TEST_JOURNAL_UPLOADSERVER -//deps: debug.cc journal_commit.cc +//deps: debug.cc log.cc journal.cc journal_commit.cc //cflags: -I.. //libs: #include "test.h" diff --git a/server/src/luaresume.cc b/server/src/luaresume.cc index a74f1f5..9202c27 100644 --- a/server/src/luaresume.cc +++ b/server/src/luaresume.cc @@ -140,3 +140,18 @@ void LUAResume::error(std::string message) { ERR(luaresume, "LUA ERROR: %s\n", message.c_str()); } + +#ifdef TEST_LUARESUME +//deps: debug.cc log.cc luautil.cc +//cflags: -I.. $(LUA_CFLAGS) +//libs: $(LUA_LIBS) +#include <test.h> + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_LUARESUME*/ diff --git a/server/src/macroheaderparser.cc b/server/src/macroheaderparser.cc index 0ad18d4..c8d5fb2 100644 --- a/server/src/macroheaderparser.cc +++ b/server/src/macroheaderparser.cc @@ -144,6 +144,10 @@ Macro *MacroHeaderParser::getMacro() } #ifdef TEST_MACROHEADERPARSER +//deps: debug.cc log.cc saxparser.cc exception.cc +//cflags: -I.. $(EXPAT_CFLAGS) +//libs: $(EXPAT_LIBS) +#include <test.h> #define XMLFILE "/tmp/test_macroheaderparser.xml" @@ -154,6 +158,7 @@ Macro *MacroHeaderParser::getMacro() #include <stdio.h> #include <memory.h> +/* static char xml[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<macro name=\"testmacro\" version=\"1.0\">\n" @@ -177,34 +182,39 @@ static char xml_fail[] = " <someothertag/>\n" "</macro>" ; +*/ + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* +FILE *fp = fopen(XMLFILE, "w"); +if(!fp) { + printf("Could not write to %s\n", XMLFILE); + return 1; +} +fprintf(fp, "%s", xml); +fclose(fp); -int main() { - FILE *fp = fopen(XMLFILE, "w"); - if(!fp) { - printf("Could not write to %s\n", XMLFILE); + // Test parsing of correct macro xml data. + MacroHeaderParser parser(XMLFILE); + try { + parser.parse(); + } catch(Exception &e) { + printf("Failed to parse: %s\n", e.what()); return 1; } - fprintf(fp, xml); - fclose(fp); - - { - // Test parsing of correct macro xml data. - MacroHeaderParser parser(XMLFILE); - try { - parser.parse(); - } catch(Exception &e) { - printf("Failed to parse: %s\n", e.what()); - return 1; - } - } +} fp = fopen(XMLFILE, "w"); if(!fp) { printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_nonmacro); +fprintf(fp, "%s", xml_nonmacro); fclose(fp); // Test parsing of correct xml data, but not macro (should throw an exception). @@ -225,7 +235,7 @@ int main() printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_fail); +fprintf(fp, "%s", xml_fail); fclose(fp); // Test parsing of invalid xml data (should throw an exception). @@ -242,8 +252,8 @@ int main() yetonandon: unlink(XMLFILE); +*/ - return 0; -} +TEST_END; #endif/*TEST_MACROHEADERPARSER*/ diff --git a/server/src/macrolist.cc b/server/src/macrolist.cc index 2ce4d0c..fc54ce9 100644 --- a/server/src/macrolist.cc +++ b/server/src/macrolist.cc @@ -61,11 +61,19 @@ void MacroList::addFile(std::string file) } #ifdef TEST_MACROLIST +//deps: entitylist.cc exception.cc saxparser.cc debug.cc log.cc inotify.cc versionstr.cc mutex.cc macroheaderparser.cc +//cflags: -I.. $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) +//libs: $(EXPAT_LIBS) $(PTHREAD_LIBS) +#include <test.h> #define MACRODIR "/home" // We assume this directory exists and does not contain any xml files! -int main() -{ +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* // Test sorting MacroList lst(MACRODIR); @@ -122,8 +130,7 @@ int main() } return 1; onandon: - - return 0; -} +*/ +TEST_END; #endif/*TEST_MACROLIST*/ diff --git a/server/src/macroparser.cc b/server/src/macroparser.cc index 2bd482e..bf6ff13 100644 --- a/server/src/macroparser.cc +++ b/server/src/macroparser.cc @@ -358,6 +358,10 @@ Macro *MacroParser::getMacro() } #ifdef TEST_MACROPARSER +//deps: debug.cc log.cc saxparser.cc exception.cc +//cflags: -I.. $(EXPAT_CFLAGS) +//libs: $(EXPAT_LIBS) +#include <test.h> #define XMLFILE "/tmp/test_macroheaderparser.xml" @@ -368,6 +372,7 @@ Macro *MacroParser::getMacro() #include <stdio.h> #include <memory.h> +/* static char xml[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<macro name=\"testmacro\" version=\"1.0\">\n" @@ -394,15 +399,20 @@ static char xml_fail[] = " <someothertag/>\n" "</macro>" ; +*/ -int main() -{ +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* FILE *fp = fopen(XMLFILE, "w"); if(!fp) { printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml); +fprintf(fp, "%s", xml); fclose(fp); { @@ -421,7 +431,7 @@ int main() printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_nonmacro); +fprintf(fp, "%s", xml_nonmacro); fclose(fp); // Test parsing of correct xml data, but not macro (should throw an exception). @@ -442,7 +452,7 @@ int main() printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_fail); +fprintf(fp, "%s", xml_fail); fclose(fp); // Test parsing of invalid xml data (should throw an exception). @@ -459,8 +469,8 @@ int main() yetonandon: unlink(XMLFILE); +*/ - return 0; -} +TEST_END; #endif/*TEST_MACROPARSER*/ diff --git a/server/src/macrotool/Makefile.am b/server/src/macrotool/Makefile.am index edd8f4a..f35dae9 100644 --- a/server/src/macrotool/Makefile.am +++ b/server/src/macrotool/Makefile.am @@ -12,16 +12,15 @@ macrotool_SOURCES = \ dump.cc \ export.cc \ fieldnames.cc \ - fieldnamescanner.cc \ filehandler.cc \ sunlock.cc \ - util.cc \ ../debug.cc \ ../configuration.cc \ ../configurationparser.cc \ ../database.cc \ ../entitylist.cc \ ../exception.cc \ + ../fieldnamescanner.cc \ ../inotify.cc \ ../log.cc \ ../macroheaderparser.cc \ @@ -33,16 +32,15 @@ macrotool_SOURCES = \ ../pracrodaotest.cc \ ../saxparser.cc \ ../templateparser.cc \ + ../util.cc \ ../versionstr.cc EXTRA_DIST = \ dump.h \ export.h \ fieldnames.h \ - fieldnamescanner.h \ filehandler.h \ - sunlock.h \ - util.h + sunlock.h ################ # Test Section # diff --git a/server/src/pracrodaopgsql.cc b/server/src/pracrodaopgsql.cc index b71f8e7..b8fb505 100644 --- a/server/src/pracrodaopgsql.cc +++ b/server/src/pracrodaopgsql.cc @@ -534,13 +534,21 @@ void PracroDAOPgsql::setActive(std::string sessionid, bool a) #endif/*WITHOUT_DB*/ #ifdef TEST_PRACRODAOPGSQL +//deps: debug.cc log.cc configuration.cc exception.cc pracrodao.cc +//cflags: -I.. $(PQXX_CXXFLAGS) +//libs: $(PQXX_LIBS) +#include <test.h> #include "configuration.h" #include "exception.h" -int main() -{ +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + #ifndef WITHOUT_DB +/* try { PracroDAOPgsql db(Conf::database_addr, "", Conf::database_user, Conf::database_passwd, ""); @@ -548,7 +556,9 @@ int main() printf("ERROR: %s\n", e.what()); return 1; } +*/ #endif/*WITHOUT_DB*/ - return 0; -} + +TEST_END; + #endif/*TEST_PRACRODAOPGSQL*/ diff --git a/server/src/pracrodaotest.cc b/server/src/pracrodaotest.cc index ec9c293..51ee24f 100644 --- a/server/src/pracrodaotest.cc +++ b/server/src/pracrodaotest.cc @@ -190,86 +190,145 @@ unsigned PracroDAOTest::nrOfCommits(std::string sessionid, void PracroDAOTest::addFieldname(std::string name, std::string description) { - // TODO - - /* - std::stringstream timestamp; timestamp << time(NULL); - std::string ts; - try { - pqxx::work W(*conn); - ts = "INSERT INTO fieldnames (name, description, \"timestamp\") VALUES (" - " '" + W.esc(name) + "', " - " '" + W.esc(description) + "', " - " '" + W.esc(timestamp.str()) + "' " - ")" - ; - DEBUG(sql, "Query: %s\n", ts.c_str()); - pqxx::result R = W.exec(ts); - W.commit(); - } catch (std::exception &e) { - ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str()); - } - */ + dbrow_t fieldname; + fieldname["name"] = name; + fieldname["description"] = description; + char buf[256]; + sprintf(buf, "%lu", time(NULL)); + fieldname["timestamp"] = buf; + data.fieldnames.push_back(fieldname); } void PracroDAOTest::delFieldname(std::string name) { - // TODO - - /* - std::string ts; - try { - pqxx::work W(*conn); - ts = "DELETE FROM fieldnames WHERE name=" - "'" + W.esc(name) + "' "; - DEBUG(sql, "Query: %s\n", ts.c_str()); - pqxx::result R = W.exec(ts); - W.commit(); - } catch (std::exception &e) { - ERR_LOG(db, "Query failed: %s: %s\n", e.what(), ts.c_str()); + dbtable_t::iterator i = data.fieldnames.begin(); + while(i != data.fieldnames.end()) { + dbrow_t &row = *i; + if(row["name"] == name) { + data.fieldnames.erase(i); + return; + } + i++; } - */ } std::vector<Fieldname> PracroDAOTest::getFieldnames() { - // TODO - std::vector<Fieldname> fieldnames; - /* - std::string query; - try { - pqxx::work W(*conn); - query = "SELECT * FROM fieldnames"; - DEBUG(sql, "Query: %s\n", query.c_str()); - pqxx::result R = W.exec(query); - pqxx::result::const_iterator ri = R.begin(); - while(ri != R.end()) { - Fieldname f; - f.name = (*ri)[0].c_str(); - f.description = (*ri)[1].c_str(); - f.timestamp = atol((*ri)[2].c_str()); - fieldnames.push_back(f); - ri++; - } - } catch (std::exception &e) { - ERR_LOG(db, "Query failed: %s: %s\n", e.what(), query.c_str()); + + dbtable_t::iterator i = data.fieldnames.begin(); + while(i != data.fieldnames.end()) { + dbrow_t &row = *i; + Fieldname fn; + fn.name = row["name"]; + fn.description = row["description"]; + fn.timestamp = atoll(row["timestamp"].c_str()); + fieldnames.push_back(fn); + i++; } - */ + return fieldnames; } +bool PracroDAOTest::active(std::string sessionid) +{ + dbtable_t::iterator i = data.commits.begin(); + while(i != data.commits.end()) { + dbrow_t &commit = *i; + if(commit["sessionid"] == sessionid) { + return commit["status"] != "idle"; + } + i++; + } + return false; +} +void PracroDAOTest::setActive(std::string sessionid, bool active) +{ + dbtable_t::iterator i = data.commits.begin(); + while(i != data.commits.end()) { + dbrow_t &commit = *i; + if(commit["sessionid"] == sessionid && commit["status"] != "committed") { + commit["status"] = active?"active":"idle"; + } + i++; + } +} #ifdef TEST_PRACRODAOTEST +//deps: debug.cc log.cc configuration.cc exception.cc pracrodao.cc +//cflags: -I.. +//libs: +#include <test.h> #include <time.h> #define PATIENTID "1234567890" +#define MACRO "testmacro" -int main() +static bool vectorFind(std::vector<Fieldname> fs, + std::string name, std::string desc) { + std::vector<Fieldname>::iterator i = fs.begin(); + while(i != fs.end()) { + Fieldname &fn = *i; + if(fn.name == name && + (desc == "" || fn.description == desc)) return true; + i++; + } + return false; +} + +TEST_BEGIN; + +Data data; +PracroDAOTest db(data); + +db.addFieldname("field1", "desc1"); +db.addFieldname("field2", "desc2"); +db.addFieldname("field3", "desc3"); +db.delFieldname("field3"); + +std::vector<Fieldname> fs = db.getFieldnames(); +TEST_EQUAL_INT(fs.size(), 2, "Test fieldname size."); +TEST_TRUE(vectorFind(fs, "field1", "desc1"), "Test fieldname 'field1'."); +TEST_TRUE(vectorFind(fs, "field2", "desc2"), "Test fieldname 'field2'."); +TEST_FALSE(vectorFind(fs, "field3", ""), "Test fieldname 'field3'."); + +std::string sid1 = db.newSessionId(); +std::string sid2 = db.newSessionId(); + +TEST_NOTEQUAL_STR(sid1, sid2, "Do not produce the same uid each time."); + +Transaction transaction; +transaction.cpr = PATIENTID; +transaction.user = "me"; + +Commit commit; +commit.fields["field1"] = "hello"; +commit.fields["field2"] = "world"; +commit.templ = "tester"; + +Macro macro; +macro.attributes["version"] = "1.0"; +macro.attributes["name"] = MACRO; + +time_t now = time(NULL); + +db.commitTransaction(sid1, transaction, commit, macro, now); + +TEST_EQUAL_INT(db.nrOfCommits(sid1, PATIENTID, MACRO, now), 1, "How many?"); + +Fieldnames fieldnames; +fieldnames.push_back("field1"); +fieldnames.push_back("field_nop"); +Values vals = db.getLatestValues(sid1, PATIENTID, ¯o, fieldnames, 0); +TEST_EQUAL_INT(vals.size(), 1, "One value"); + +TEST_NOTEQUAL(vals.find("field1"), vals.end(), "find value"); + +/* time_t now = time(NULL); Data data; @@ -345,8 +404,7 @@ int main() // This value was not committed, since it wasn't in the fieldnames table. if(values.find("field4") != values.end()) return 1; - - return 0; -} +*/ +TEST_END; #endif/*TEST_PRACRODAOTEST*/ diff --git a/server/src/pracrodaotest.h b/server/src/pracrodaotest.h index 1e1a8c0..981b6d5 100644 --- a/server/src/pracrodaotest.h +++ b/server/src/pracrodaotest.h @@ -71,6 +71,7 @@ public: dbtable_t transactions; dbtable_t fieldnames; dbtable_t fields; + dbtable_t commits; }; class PracroDAOTest : public PracroDAO @@ -104,8 +105,8 @@ public: void discard(std::string sessionid) {} std::string serialise() { return ""; } void restore(const std::string &data) {} - bool active(std::string sessionid) {return false;} - void setActive(std::string sessionid, bool active) {} + bool active(std::string sessionid); + void setActive(std::string sessionid, bool active); private: Data data; diff --git a/server/src/queryhandlerpentominos.cc b/server/src/queryhandlerpentominos.cc index 41573e5..8000721 100644 --- a/server/src/queryhandlerpentominos.cc +++ b/server/src/queryhandlerpentominos.cc @@ -237,9 +237,20 @@ QueryResult QueryHandlerPentominos::exec(Query &query) } #ifdef TEST_QUERYHANDLERPENTOMINOS +//deps: artefact.cc configuration.cc debug.cc log.cc +//cflags: -I.. $(ATF_CFLAGS) +//libs: $(ATF_LIBS) +#include <test.h> + +#include "tcpsocket.h" + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +#if 0 -int main() -{ #ifdef WITHOUT_PENTOMINOS printf("The project need to be configured for use of Pentominos in order to run this test.\n"); return 1; @@ -261,8 +272,8 @@ int main() q1.attributes["device_type"] = "lensmeter"; QueryResult res = qh.exec(q1); res.print(); +#endif - return 0; -} +TEST_END; #endif/*TEST_QUERYHANDLERPENTOMINOS*/ diff --git a/server/src/queryhandlerpracro.cc b/server/src/queryhandlerpracro.cc index 85dcdf9..d617e69 100644 --- a/server/src/queryhandlerpracro.cc +++ b/server/src/queryhandlerpracro.cc @@ -74,13 +74,21 @@ QueryResult QueryHandlerPracro::exec(Query &query) } #ifdef TEST_QUERYHANDLERPRACRO +//deps: database.cc mutex.cc debug.cc log.cc pracrodao.cc pracrodaotest.cc pracrodaopgsql.cc configuration.cc +//cflags: -I.. $(PQXX_CXXFLAGS) +//libs: $(PQXX_LIBS) +#include <test.h> #include <time.h> #define PATIENTID "1234567890" -int main() -{ +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* time_t now = time(NULL); Database db("testdb", "", "", "", "", ""); Macro macro; @@ -122,8 +130,7 @@ int main() if(res.timestamp != now - 100) return 1; if(res.source != "pracrodb") return 1; if(res.values["myfield"] != "myval") return 1; - - return 0; -} +*/ +TEST_END; #endif/*TEST_QUERYHANDLERPRACRO*/ diff --git a/server/src/queryparser.cc b/server/src/queryparser.cc index d8f36ee..3d228f6 100644 --- a/server/src/queryparser.cc +++ b/server/src/queryparser.cc @@ -88,9 +88,13 @@ void QueryParser::parseError(const char *buf, size_t len, std::string error, int } #ifdef TEST_QUERYPARSER +//deps: saxparser.cc debug.cc log.cc utf8.cc exception.cc +//cflags: -I.. $(EXPAT_CFLAGS) +//libs: $(EXPAT_LIBS) +#include <test.h> #include <string.h> - +/* static char xml[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<results>\n" @@ -142,9 +146,13 @@ static std::string loadresultstring(QueryResult &res, std::string group = "") return s; } +*/ +TEST_BEGIN; -int main() -{ +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* // Parse something { QueryParser parser; @@ -163,8 +171,7 @@ int main() } return 1; weitergehen: - - return 0; -} +*/ +TEST_END; #endif/*TEST_QUERYPARSER*/ diff --git a/server/src/resumeparser.cc b/server/src/resumeparser.cc index c80c2f0..1c5335a 100644 --- a/server/src/resumeparser.cc +++ b/server/src/resumeparser.cc @@ -64,3 +64,18 @@ std::string resume_parser(Macro ¯o, Commit &commit) return luaresume.run(code); } + +#ifdef TEST_RESUMEPARSER +//deps: luaresume.cc configuration.cc debug.cc log.cc luautil.cc +//cflags: -I.. $(LUA_CFLAGS) +//libs: $(LUA_LIBS) +#include <test.h> + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_RESUMEPARSER*/ diff --git a/server/src/semaphore.cc b/server/src/semaphore.cc index e5f1f31..51a20e5 100644 --- a/server/src/semaphore.cc +++ b/server/src/semaphore.cc @@ -45,3 +45,18 @@ void Semaphore::wait() { sem_wait(&semaphore); } + +#ifdef TEST_SEMAPHORE +//deps: +//cflags: -I.. $(PTHREAD_CFLAGS) +//libs: $(PTHREAD_LIBS) +#include <test.h> + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_SEMAPHORE*/ diff --git a/server/src/server.cc b/server/src/server.cc index d9daf3a..9046594 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -129,6 +129,10 @@ void server() } #ifdef TEST_SERVER +//deps: httpd.cc session.cc configuration.cc journal.cc journal_uploadserver.cc journal_commit.cc mutex.cc debug.cc sessionserialiser.cc sessionparser.cc saxparser.cc environment.cc semaphore.cc artefact.cc xml_encode_decode.cc database.cc pracrodaopgsql.cc pracrodaotest.cc pracrodao.cc entitylist.cc macrolist.cc templatelist.cc macroheaderparser.cc templateheaderparser.cc versionstr.cc exception.cc log.cc inotify.cc client_connection.cc admin_connection.cc admin_rc.cc admin_export.cc transactionparser.cc transactionhandler.cc templateparser.cc macroparser.cc queryhandlerpracro.cc luaquerymapper.cc queryhandlerpentominos.cc resumeparser.cc luaresume.cc luautil.cc widgetgenerator.cc widgetvalue.cc +//cflags: -I.. -DWITHOUT_ARTEFACT -DWITHOUT_DB $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) $(HTTPD_CFLAGS) $(LUA_CFLAGS) +//libs: $(EXPAT_LIBS) $(PTHREAD_LIBS) $(HTTPD_LIBS) $(LUA_LIBS) +#include <test.h> #include <sys/types.h> #include <signal.h> @@ -141,8 +145,12 @@ char request[] = " <request macro=\"example\" template=\"example\"/>\n" "</pracro>\n"; -int main() -{ +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* Conf::xml_basedir = "../xml/"; // Make sure wo don't interrupt an already running server. Conf::server_port = 32100; @@ -187,8 +195,7 @@ int main() kill(pid, SIGKILL); // Kill the server again. return 0; } - - return 1; -} +*/ +TEST_END; #endif/*TEST_SERVER*/ diff --git a/server/src/session.cc b/server/src/session.cc index fe05ee5..6880e73 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -298,14 +298,19 @@ SessionAutolock::~SessionAutolock() #ifdef TEST_SESSION //deps: configuration.cc journal.cc journal_uploadserver.cc journal_commit.cc mutex.cc debug.cc sessionserialiser.cc sessionparser.cc saxparser.cc environment.cc semaphore.cc artefact.cc xml_encode_decode.cc database.cc pracrodaopgsql.cc pracrodaotest.cc pracrodao.cc entitylist.cc macrolist.cc templatelist.cc macroheaderparser.cc templateheaderparser.cc versionstr.cc exception.cc log.cc inotify.cc -//cflags: -I.. $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) $(ATF_CFLAGS) $(PQXX_CXXFLAGS) -//libs: $(PTHREAD_LIBS) $(EXPAT_LIBS) $(ATF_LIBS) $(PQXX_LIBS) +//cflags: -I.. $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) -DWITHOUT_ARTEFACT -DWITHOUT_DB +//libs: $(PTHREAD_LIBS) $(EXPAT_LIBS) #include <test.h> #define PID "1505050505" #define TMPL "test" TEST_BEGIN; + +Conf::database_backend = "testdb"; +Conf::database_poolsize = 1; +Conf::xml_basedir = "/tmp"; + Environment env; Conf::session_path = "/tmp"; @@ -325,6 +330,30 @@ TEST_NOTEQUAL_STR(s1->id(), s3->id(), "Testing if IDs are unique."); TEST_EQUAL_INT(env.sessions.size(), 1, "Testing if size is 1."); +std::string id = s3->id(); +env.sessions.deleteSession(id); +Session *s4 = env.sessions.session(id); +TEST_EQUAL(s4, NULL, "No session should be returned."); + +TEST_EQUAL_INT(env.sessions.size(), 0, "Testing if size is 0."); + +Session *s5 = env.sessions.newSession(PID, TMPL); +TEST_NOTEQUAL(s5, NULL, "A new session was created."); + +s5->isreadonly = false; + +env.sessions.store(); + +Session *s6 = env.sessions.session(id); +TEST_EQUAL_STR(s6->id(), s5->id(), "Did we get the stored session?"); + +s6->isreadonly = false; + +env.sessions.store(); + +Session *s7 = env.sessions.newSession(PID, TMPL); +TEST_EQUAL_STR(s7->id(), s5->id(), "Did we get the stored session?"); + /* std::string sessionid = s1->id(); SessionSerialiser ser(&env, Conf::session_path); diff --git a/server/src/sessionparser.cc b/server/src/sessionparser.cc index 21bc95f..856ce36 100644 --- a/server/src/sessionparser.cc +++ b/server/src/sessionparser.cc @@ -116,14 +116,15 @@ void SessionParser::parseError(const char *buf, size_t len, } #ifdef TEST_SESSIONPARSER -//deps: -//cflags: -//libs: +//deps: saxparser.cc debug.cc log.cc +//cflags: -I.. $(EXPAT_CFLAGS) +//libs: $(EXPAT_LIBS) #include "test.h" TEST_BEGIN; -#error "Put some testcode here (see test.h for usable macros)." +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); TEST_END; diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc index b20e4c4..99f880b 100644 --- a/server/src/sessionserialiser.cc +++ b/server/src/sessionserialiser.cc @@ -242,8 +242,8 @@ Session *SessionSerialiser::findFromTupple(const std::string &patientid, } #ifdef TEST_SESSIONSERIALISER -//deps: session.cc journal.cc debug.cc configuration.cc mutex.cc journal_commit.cc sessionparser.cc saxparser.cc xml_encode_decode.cc database.cc pracrodaopgsql.cc pracrodaotest.cc pracrodao.cc journal_uploadserver.cc log.cc -//cflags: -I.. $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) $(PQXX_CFLAGS) +//deps: session.cc journal.cc debug.cc configuration.cc mutex.cc journal_commit.cc sessionparser.cc saxparser.cc xml_encode_decode.cc database.cc pracrodaopgsql.cc pracrodaotest.cc pracrodao.cc journal_uploadserver.cc log.cc environment.cc semaphore.cc artefact.cc macrolist.cc templatelist.cc entitylist.cc inotify.cc versionstr.cc exception.cc macroheaderparser.cc templateheaderparser.cc +//cflags: -I.. $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) $(PQXX_CFLAGS) -DWITHOUT_ARTEFACT //libs: $(PTHREAD_LIBS) $(EXPAT_LIBS) $(PQXX_LIBS) #include "test.h" @@ -260,6 +260,8 @@ std::string xml; debug_parse("+all"); +Environment env; + { FILE *fp = fopen("/tmp/"PRE".42", "w"); fclose(fp); @@ -276,12 +278,12 @@ debug_parse("+all"); } { - Session session(SID, PID, TID); + Session session(&env, SID, PID, TID); Journal *j = session.journal(); j->addEntry("some text", "macro1", 0); j->addEntry("some more text", "macro2", 2); j->addEntry("yet some more text", "macro3", 1); - SessionSerialiser s(SPATH); + SessionSerialiser s(&env, SPATH); xml = s.saveStr(&session); s.loadStr(xml); std::string xml2 = s.saveStr(&session); @@ -289,12 +291,12 @@ debug_parse("+all"); } { - Session session(SID, PID, TID); + Session session(&env, SID, PID, TID); Journal *j = session.journal(); j->addEntry("some text", "macro1", 0); j->addEntry("some more text", "macro2", 2); j->addEntry("yet some more text", "macro3", 1); - SessionSerialiser s(SPATH); + SessionSerialiser s(&env, SPATH); xml = s.saveStr(&session); } /* @@ -307,12 +309,12 @@ debug_parse("+all"); } */ { - Session session(SID, PID, TID); + Session session(&env, SID, PID, TID); Journal *j = session.journal(); j->addEntry("some text", "macro1", 0); j->addEntry("some more text", "macro2", 2); j->addEntry("yet some more text", "macro3", 1); - SessionSerialiser s(SPATH); + SessionSerialiser s(&env, SPATH); s.save(&session); } /* @@ -326,8 +328,8 @@ debug_parse("+all"); */ { - Session session(SID, PID, TID); - SessionSerialiser s(SPATH); + Session session(&env, SID, PID, TID); + SessionSerialiser s(&env, SPATH); s.save(&session); Session *s1 = s.findFromTupple(PID, TID); TEST_NOTEQUAL(s1, NULL, "Found it?"); diff --git a/server/src/tcpsocket.cc b/server/src/tcpsocket.cc index 70722ed..b54b581 100644 --- a/server/src/tcpsocket.cc +++ b/server/src/tcpsocket.cc @@ -367,9 +367,19 @@ std::string TCPSocket::dstaddr() } #ifdef TEST_TCPSOCKET +//deps: exception.cc debug.cc log.cc +//cflags: -I.. +//libs: +#include <test.h> -int main() -{ +#define PORT 12346 + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* char buf[32]; switch(fork()) { @@ -381,7 +391,7 @@ int main() try { TCPSocket client; sleep(1); // We need to wait for the listen socket to be created. - client.connect("localhost", 12345); + client.connect("localhost", PORT); sprintf(buf, "hello"); client.write(buf, sizeof(buf)); printf("Sent: [%s]\n", buf); @@ -394,7 +404,7 @@ int main() default: // parent try { TCPSocket listen_sock; - listen_sock.listen(12345); + listen_sock.listen(PORT); TCPSocket *sock = listen_sock.accept(); sock->read(buf, sizeof(buf)); printf("Got: [%s]\n", buf); @@ -406,8 +416,8 @@ int main() } break; } +*/ - return 0; -} +TEST_END; #endif/*TEST_TCPSOCKET*/ diff --git a/server/src/templateheaderparser.cc b/server/src/templateheaderparser.cc index 2cb3e84..e549035 100644 --- a/server/src/templateheaderparser.cc +++ b/server/src/templateheaderparser.cc @@ -143,6 +143,10 @@ Template *TemplateHeaderParser::getTemplate() } #ifdef TEST_TEMPLATEHEADERPARSER +//deps: saxparser.cc exception.cc debug.cc log.cc +//cflags: -I.. $(EXPAT_CFLAGS) +//libs: $(EXPAT_LIBS) +#include <test.h> #define XMLFILE "/tmp/test_templateheaderparser.xml" @@ -152,7 +156,7 @@ Template *TemplateHeaderParser::getTemplate() #include <string.h> #include <stdio.h> #include <memory.h> - +/* static char xml[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<template name=\"testtemplate\" version=\"1.0\">\n" @@ -176,15 +180,19 @@ static char xml_fail[] = " <someothertag/>\n" "</template>" ; +*/ +TEST_BEGIN; -int main() -{ +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* FILE *fp = fopen(XMLFILE, "w"); if(!fp) { printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml); +fprintf(fp, "%s", xml); fclose(fp); { @@ -203,7 +211,7 @@ int main() printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_nontemplate); +fprintf(fp, "%s", xml_nontemplate); fclose(fp); // Test parsing of correct xml data, but not template (should throw an exception). @@ -224,7 +232,7 @@ int main() printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_fail); +fprintf(fp, "%s", xml_fail); fclose(fp); // Test parsing of invalid xml data (should throw an exception). @@ -241,8 +249,7 @@ int main() yetonandon: unlink(XMLFILE); - - return 0; -} +*/ +TEST_END; #endif/*TEST_TEMPLATEHEADERPARSER*/ diff --git a/server/src/templatelist.cc b/server/src/templatelist.cc index c7a951c..7d19bfb 100644 --- a/server/src/templatelist.cc +++ b/server/src/templatelist.cc @@ -58,11 +58,19 @@ void TemplateList::addFile(std::string file) } #ifdef TEST_TEMPLATELIST +//deps: entitylist.cc versionstr.cc exception.cc inotify.cc mutex.cc debug.cc log.cc templateheaderparser.cc saxparser.cc +//cflags: -I.. $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) +//libs: $(EXPAT_LIBS) $(PTHREAD_LIBS) +#include <test.h> #define TEMPLATEDIR "/home" // We assume this directory exists and does not contain any xml files! -int main() -{ +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* // Test sorting TemplateList lst(TEMPLATEDIR); @@ -119,8 +127,7 @@ int main() } return 1; onandon: - - return 0; -} + */ +TEST_END; #endif/*TEST_TEMPLATELIST*/ diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc index b34f280..20270c6 100644 --- a/server/src/templateparser.cc +++ b/server/src/templateparser.cc @@ -161,6 +161,10 @@ Template *TemplateParser::getTemplate() } #ifdef TEST_TEMPLATEPARSER +//deps: saxparser.cc debug.cc log.cc exception.cc +//cflags: -I.. $(EXPAT_CFLAGS) +//libs: $(EXPAT_LIBS) +#include <test.h> #define XMLFILE "/tmp/test_templateparser.xml" @@ -170,7 +174,7 @@ Template *TemplateParser::getTemplate() #include <string.h> #include <stdio.h> #include <memory.h> - +/* static char xml[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<template name=\"testtemplate\" version=\"1.0\">\n" @@ -194,15 +198,20 @@ static char xml_fail[] = " <someothertag/>\n" "</template>" ; +*/ -int main() -{ +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +/* FILE *fp = fopen(XMLFILE, "w"); if(!fp) { printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml); +fprintf(fp, "%s", xml); fclose(fp); { @@ -221,7 +230,7 @@ int main() printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_nontemplate); +fprintf(fp, "%s", xml_nontemplate); fclose(fp); // Test parsing of correct xml data, but not template (should throw an exception). @@ -242,7 +251,7 @@ int main() printf("Could not write to %s\n", XMLFILE); return 1; } - fprintf(fp, xml_fail); +fprintf(fp, "%s", xml_fail); fclose(fp); // Test parsing of invalid xml data (should throw an exception). @@ -259,8 +268,7 @@ int main() yetonandon: unlink(XMLFILE); - - return 0; -} +*/ +TEST_END; #endif/*TEST_TEMPLATEPARSER*/ diff --git a/server/src/transactionhandler.cc b/server/src/transactionhandler.cc index 32d37eb..0ebf782 100644 --- a/server/src/transactionhandler.cc +++ b/server/src/transactionhandler.cc @@ -318,14 +318,15 @@ std::string handleTransaction(Transaction &transaction, Environment &env, } #ifdef TEST_TRANSACTIONHANDLER -//deps: -//cflags: -I.. -//libs: +//deps: session.cc configuration.cc journal.cc journal_uploadserver.cc journal_commit.cc mutex.cc debug.cc sessionserialiser.cc sessionparser.cc saxparser.cc environment.cc semaphore.cc artefact.cc xml_encode_decode.cc database.cc pracrodaopgsql.cc pracrodaotest.cc pracrodao.cc entitylist.cc macrolist.cc templatelist.cc macroheaderparser.cc templateheaderparser.cc versionstr.cc exception.cc log.cc inotify.cc client_connection.cc admin_connection.cc admin_rc.cc admin_export.cc transactionparser.cc templateparser.cc macroparser.cc queryhandlerpracro.cc luaquerymapper.cc queryhandlerpentominos.cc resumeparser.cc luaresume.cc luautil.cc widgetgenerator.cc widgetvalue.cc +//cflags: -I.. -DWITHOUT_ARTEFACT -DWITHOUT_DB $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) $(HTTPD_CFLAGS) $(LUA_CFLAGS) +//libs: $(EXPAT_LIBS) $(PTHREAD_LIBS) $(HTTPD_LIBS) $(LUA_LIBS) #include "test.h" TEST_BEGIN; -#error TODO: Put some testcode here (see test.h for usable macros). +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); TEST_END; diff --git a/server/src/utf8.cc b/server/src/utf8.cc index 2909a94..f43d858 100644 --- a/server/src/utf8.cc +++ b/server/src/utf8.cc @@ -344,9 +344,13 @@ std::string UTF8::decode(std::string s) } #ifdef TEST_UTF8 +//deps: exception.cc log.cc +//cflags: -I.. +//libs: +#include <test.h> + +TEST_BEGIN; -int main() -{ try { UTF8 utf8("ISO-8859-1"); @@ -363,12 +367,11 @@ int main() if(a == c) return 0; else return 1; - } catch( Pentominos::Exception &e ) { + } catch(Exception &e) { fprintf(stderr, "%s\n", e.what()); return 1; } - return 0; -} +TEST_END; #endif//TEST_UTF8 diff --git a/server/src/macrotool/util.cc b/server/src/util.cc index 8be5435..4c049bd 100644 --- a/server/src/macrotool/util.cc +++ b/server/src/util.cc @@ -75,3 +75,18 @@ void printcolumn(std::string text, size_t width) for(size_t i = text.length(); i < width; i++) printf(" "); printf("\t"); } + +#ifdef TEST_UTIL +//deps: configuration.cc debug.cc log.cc +//cflags: -I.. +//libs: +#include <test.h> + +TEST_BEGIN; + +// TODO: Put some testcode here (see test.h for usable macros). +TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_UTIL*/ diff --git a/server/src/macrotool/util.h b/server/src/util.h index 2e41f6b..2e41f6b 100644 --- a/server/src/macrotool/util.h +++ b/server/src/util.h diff --git a/server/src/versionstr.cc b/server/src/versionstr.cc index c4f82c9..b906bdd 100644 --- a/server/src/versionstr.cc +++ b/server/src/versionstr.cc @@ -118,12 +118,18 @@ size_t VersionStr::patch() const } #ifdef TEST_VERSIONSTR +//deps: log.cc exception.cc +//cflags: -I.. +//libs: +#include <test.h> #include <set> #include <vector> -int main() -{ +TEST_BEGIN; + +TEST_TRUE(false, "No tests yet!"); +/* // Test normal constructor and string conversion VersionStr v1("1.2.3"); printf("VersionStr: %s\n", ((std::string)v1).c_str()); @@ -202,8 +208,7 @@ int main() if(((std::string)*i) != *j) return 1; i++; j++; } - - return 0; -} +*/ +TEST_END; #endif/*TEST_VERSIONSTR*/ diff --git a/server/src/widgetgenerator.cc b/server/src/widgetgenerator.cc index 7a39190..0c24999 100644 --- a/server/src/widgetgenerator.cc +++ b/server/src/widgetgenerator.cc @@ -103,13 +103,19 @@ std::string widgetgenerator(std::string cpr, std::string sessionid, } #ifdef TEST_WIDGETGENERATOR +//deps: log.cc mutex.cc debug.cc xml_encode_decode.cc widgetvalue.cc luaquerymapper.cc configuration.cc exception.cc +//cflags: -I.. $(PTHREAD_CFLAGS) $(LUA_CFLAGS) +//libs: $(PTHREAD_LIBS) $(LUA_LIBS) +#include <test.h> #include <time.h> #define PATIENTID "1234567890" -int main() -{ +TEST_BEGIN; + +TEST_TRUE(false, "No tests yet!"); +/* time_t now = time(NULL); printf("Test pretty printer:\n"); @@ -218,7 +224,7 @@ int main() printf("[%s]\n", result.c_str()); if(result == " <lineedit name=\"mywidget\" value=\"mymapvalue\" prefilled=\"testsource\"/>\n") return 1; } - return 0; -} +*/ +TEST_END; #endif/*TEST_WIDGETGENERATOR*/ diff --git a/server/src/xml_encode_decode.cc b/server/src/xml_encode_decode.cc index 427e451..1c0e377 100644 --- a/server/src/xml_encode_decode.cc +++ b/server/src/xml_encode_decode.cc @@ -82,23 +82,22 @@ std::string xml_decode(std::string str) } #ifdef TEST_XML_ENCODE_DECODE +//deps: +//cflags: +//libs: +#include <test.h> -int main() -{ - std::string in = "&A<B>C\"D\'<>\"&E<>"; - std::string enc = xml_encode(in); - std::string denc = xml_encode(enc); - std::string dec = xml_decode(denc); - std::string ddec = xml_decode(dec); +TEST_BEGIN; - printf("Input: \"%s\" %d\n", in.c_str(), in.length()); - printf("Encoded: \"%s\" %d\n", enc.c_str(), enc.length()); - printf("DoubleEncoded: \"%s\" %d\n", denc.c_str(), denc.length()); - printf("Decoded: \"%s\" %d\n", dec.c_str(), dec.length()); - printf("DoubleDecoded: \"%s\" %d\n", ddec.c_str(), ddec.length()); +std::string in = "&A<B>C\"D\'<>\"&E<>"; +std::string enc = xml_encode(in); +std::string denc = xml_encode(enc); +std::string dec = xml_decode(denc); +std::string ddec = xml_decode(dec); - if( in == ddec && enc == dec) return 0; - return 1; -} +TEST_EQUAL_STR(in, ddec, "compare"); +TEST_EQUAL_STR(enc, dec, "compare"); + +TEST_END; #endif/*TEST_XML_ENCODE_DECODE*/ |