Moving XML output files from cppunit tests to $HOME/.gnuradio/unittests.
[debian/gnuradio] / gruel / src / lib / test_gruel.cc
index cb5f2d36bc2f7d624a4f4077b528690b591981c0..f4b9fc4e2d7d03ebb23a53c3285d6a1cc6a85ade 100644 (file)
 
 #include <cppunit/TextTestRunner.h>
 #include <cppunit/XmlOutputter.h>
+
+#include <stdlib.h>
+#include <sys/stat.h>
+
 #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);
+}
+