From 2b8bd0d2fa7c76282a772b75cb99e7bd5f2be13f Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sat, 2 Oct 2010 17:16:04 -0400 Subject: Moving XML output files from cppunit tests to $HOME/.gnuradio/unittests. This also adds a new utility gr_unittests.h, which sets up the path for output files. --- gruel/src/lib/test_gruel.cc | 53 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'gruel/src/lib') diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc index cb5f2d36b..f4b9fc4e2 100644 --- a/gruel/src/lib/test_gruel.cc +++ b/gruel/src/lib/test_gruel.cc @@ -22,14 +22,22 @@ #include #include + +#include +#include + #include "pmt/qa_pmt.h" +static void get_unittest_path (const char *filename, char *fullpath, size_t pathsize); + int main(int argc, char **argv) { + char path[200]; + get_unittest_path ("gruel.xml", path, 200); - CppUnit::TextTestRunner runner; - std::ofstream xmlfile("cppunit_gruel.xml"); + CppUnit::TextTestRunner runner; + std::ofstream xmlfile(path); CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile); runner.addTest(qa_pmt::suite ()); @@ -39,3 +47,44 @@ main(int argc, char **argv) return was_successful ? 0 : 1; } + + +// NOTE: These are defined in gr_unittest.h for the rest of the project; +// rewriting here since we don't depend on gnuradio-core in gruel + +#ifdef MKDIR_TAKES_ONE_ARG +#define gr_mkdir(pathname, mode) mkdir(pathname) +#else +#define gr_mkdir(pathname, mode) mkdir((pathname), (mode)) +#endif + +/* + * Mostly taken from gr_preferences.cc/h + * The simplest thing that could possibly work: + * the key is the filename; the value is the file contents. + */ + +static void +ensure_unittest_path (const char *grpath, const char *path) +{ + struct stat statbuf; + if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) + return; + + // blindly try to make it // FIXME make this robust. C++ SUCKS! + gr_mkdir (grpath, 0750); + gr_mkdir (path, 0750); +} + +static void +get_unittest_path (const char *filename, char *fullpath, size_t pathsize) +{ + char path[200]; + char grpath[200]; + snprintf (grpath, sizeof(grpath), "%s/.gnuradio", getenv ("HOME")); + snprintf (path, sizeof(path), "%s/unittests", grpath); + snprintf (fullpath, pathsize, "%s/%s", path, filename); + + ensure_unittest_path(grpath, path); +} + -- cgit