diff options
author | Josh Blum <josh@joshknows.com> | 2011-01-18 01:00:15 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-01-18 01:00:15 -0800 |
commit | 05cc02cec03507c47846a668c92e6dcc4ba2e71e (patch) | |
tree | 8576c0c9977400aaaf26470766b6e9c9c3e83ce3 /gruel | |
parent | 31bbbec88b19230eb37b197d7623c3671e57837e (diff) |
cleanup mkdir usage with boost filesystem:
Replaced copy/pasted code and MKDIR_TAKES_ONE_ARG #ifdefs
with portable boost filesystem path and directory creation.
Gets the correct home directory on windows systems: APPDATA.
Replaces large amounts of copypasta with single lines of code.
Removes MKDIR_TAKES_ONE_ARG configuration checks from m4 files.
Adds boost filesystem and system library as build dependencies.
Diffstat (limited to 'gruel')
-rw-r--r-- | gruel/src/lib/Makefile.am | 2 | ||||
-rw-r--r-- | gruel/src/lib/test_gruel.cc | 51 |
2 files changed, 10 insertions, 43 deletions
diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index 5c3302f199..876e7ab3da 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -51,6 +51,8 @@ libgruel_la_SOURCES = \ libgruel_la_LIBADD = \ $(BOOST_THREAD_LIB) \ + $(BOOST_SYSTEM_LIB) \ + $(BOOST_FILESYSTEM_LIB) \ $(PMT_LIB) \ $(MSG_LIB) \ -lstdc++ diff --git a/gruel/src/lib/test_gruel.cc b/gruel/src/lib/test_gruel.cc index 2c9528b0ab..efb6cb7776 100644 --- a/gruel/src/lib/test_gruel.cc +++ b/gruel/src/lib/test_gruel.cc @@ -28,16 +28,19 @@ #include "pmt/qa_pmt.h" -static void get_unittest_path (const char *filename, char *fullpath, size_t pathsize); +#include <boost/filesystem/operations.hpp> +#include <boost/filesystem/path.hpp> +namespace fs = boost::filesystem; int main(int argc, char **argv) { - char path[200]; - get_unittest_path ("gruel.xml", path, 200); - + fs::path path = fs::current_path() / ".unittests"; + if (!fs::is_directory(path)) fs::create_directory(path); + path = path / "gruel.xml"; + CppUnit::TextTestRunner runner; - std::ofstream xmlfile(path); + std::ofstream xmlfile(path.string().c_str()); CppUnit::XmlOutputter *xmlout = new CppUnit::XmlOutputter(&runner.result(), xmlfile); runner.addTest(qa_pmt::suite ()); @@ -47,41 +50,3 @@ 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 *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 (path, 0750); -} - -static void -get_unittest_path (const char *filename, char *fullpath, size_t pathsize) -{ - char path[200]; - snprintf (path, sizeof(path), "./.unittests"); - snprintf (fullpath, pathsize, "%s/%s", path, filename); - - ensure_unittest_path(path); -} - |