[beast: 22/57] SFI: tests: add Path unit tests
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 22/57] SFI: tests: add Path unit tests
- Date: Sun, 23 Jul 2017 09:59:38 +0000 (UTC)
commit 6f7a4b805b3decd883abe71656c5ac9591668955
Author: Tim Janik <timj gnu org>
Date: Mon Jul 17 11:13:56 2017 +0200
SFI: tests: add Path unit tests
Signed-off-by: Tim Janik <timj gnu org>
sfi/tests/Makefile.am | 1 +
sfi/tests/misctests.cc | 105 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 106 insertions(+), 0 deletions(-)
---
diff --git a/sfi/tests/Makefile.am b/sfi/tests/Makefile.am
index b197dae..aa99c80 100644
--- a/sfi/tests/Makefile.am
+++ b/sfi/tests/Makefile.am
@@ -2,6 +2,7 @@
include $(top_srcdir)/Makefile.decl
AM_CPPFLAGS += -I$(top_srcdir) -I$(top_builddir) -I.
+DEFS += -D__TOPDIR__="\"$(abs_top_srcdir)/\""
DEFS += @DEFINE__FILE_DIR__@ -DG_LOG_DOMAIN='"$(basename $(@F))"' -DPARANOID #
-DG_DISABLE_CONST_RETURNS
AM_CXXFLAGS += $(SFI_CPPFLAGS) $(RAPICORN_CFLAGS) -DBSE_CONVENIENCE
diff --git a/sfi/tests/misctests.cc b/sfi/tests/misctests.cc
index ac28386..3ecd7b6 100644
--- a/sfi/tests/misctests.cc
+++ b/sfi/tests/misctests.cc
@@ -3,6 +3,7 @@
#define G_LOG_DOMAIN __FILE__
// #define TEST_VERBOSE
#include <sfi/sfitests.hh>
+#include <sfi/path.hh>
#include <unistd.h>
#include <string.h>
#include <signal.h> /* G_BREAKPOINT() */
@@ -10,6 +11,109 @@
using namespace Bse;
+struct TestChain;
+static const TestChain *global_test_chain = NULL;
+
+struct TestChain {
+ std::string name;
+ std::function<void()> func;
+ const TestChain *const next;
+ TestChain (std::function<void()> tfunc, const std::string &tname) :
+ name (tname), func (tfunc), next (global_test_chain)
+ {
+ assert_return (next == global_test_chain);
+ global_test_chain = this;
+ }
+};
+
+static void
+run_test_chain()
+{
+ for (const TestChain *t = global_test_chain; t; t = t->next)
+ {
+ printout (" .... %s", t->name);
+ fflush (stdout);
+ t->func();
+ printout ("\r PASS %s\n", t->name);
+ }
+}
+
+#define ADD_TEST(fun) static const TestChain RAPICORN_CPP_PASTE2_ (__testchain__, __LINE__) (fun,
RAPICORN_CPP_STRINGIFY (fun))
+
+static void
+test_paths()
+{
+ String p, s;
+ // Path::join
+ s = Path::join ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
+#if BSE_DIRCHAR == '/'
+ p = "0/1/2/3/4/5/6/7/8/9/a/b/c/d/e/f";
+#else
+ p = "0\\1\\2\\3\\4\\5\\6\\7\\8\\9\\a\\b\\c\\d\\e\\f";
+#endif
+ TCMP (s, ==, p);
+ // Path::searchpath_join
+ s = Path::searchpath_join ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
+#if BSE_SEARCHPATH_SEPARATOR == ';'
+ p = "0;1;2;3;4;5;6;7;8;9;a;b;c;d;e;f";
+#else
+ p = "0:1:2:3:4:5:6:7:8:9:a:b:c:d:e:f";
+#endif
+ TCMP (s, ==, p);
+ // Path
+ bool b = Path::isabs (p);
+ TCMP (b, ==, false);
+ const char dirsep[2] = { BSE_DIRCHAR, 0 };
+#if BSE_DIRCHAR == '/'
+ s = Path::join (dirsep, s);
+#else
+ s = Path::join ("C:\\", s);
+#endif
+ b = Path::isabs (s);
+ TCMP (b, ==, true);
+ s = Path::skip_root (s);
+ TCMP (s, ==, p);
+ // TASSERT (Path::dir_separator == "/" || Path::dir_separator == "\\");
+ TASSERT (BSE_SEARCHPATH_SEPARATOR == ':' || BSE_SEARCHPATH_SEPARATOR == ';');
+ TCMP (Path::basename ("simple"), ==, "simple");
+ TCMP (Path::basename ("skipthis" + String (dirsep) + "file"), ==, "file");
+ TCMP (Path::basename (String (dirsep) + "skipthis" + String (dirsep) + "file"), ==, "file");
+ TCMP (Path::dirname ("file"), ==, ".");
+ TCMP (Path::dirname ("dir" + String (dirsep)), ==, "dir");
+ TCMP (Path::dirname ("dir" + String (dirsep) + "file"), ==, "dir");
+ TCMP (Path::cwd(), !=, "");
+ TCMP (Path::check (Path::join (Path::cwd(), "..", Path::basename (Path::cwd())), "rd"), ==, true); // ../.
should be a readable directory
+ TCMP (Path::isdirname (""), ==, false);
+ TCMP (Path::isdirname ("foo"), ==, false);
+ TCMP (Path::isdirname ("foo/"), ==, true);
+ TCMP (Path::isdirname ("/foo"), ==, false);
+ TCMP (Path::isdirname ("foo/."), ==, true);
+ TCMP (Path::isdirname ("foo/.."), ==, true);
+ TCMP (Path::isdirname ("foo/..."), ==, false);
+ TCMP (Path::isdirname ("foo/..../"), ==, true);
+ TCMP (Path::isdirname ("/."), ==, true);
+ TCMP (Path::isdirname ("/.."), ==, true);
+ TCMP (Path::isdirname ("/"), ==, true);
+ TCMP (Path::isdirname ("."), ==, true);
+ TCMP (Path::isdirname (".."), ==, true);
+ TCMP (Path::expand_tilde (""), ==, "");
+ const char *env_home = getenv ("HOME");
+ if (env_home)
+ TCMP (Path::expand_tilde ("~"), ==, env_home);
+ const char *env_logname = getenv ("LOGNAME");
+ if (env_home && env_logname)
+ TCMP (Path::expand_tilde ("~" + String (env_logname)), ==, env_home);
+ TCMP (Path::searchpath_multiply ("/:/tmp", "foo:bar"), ==, "/foo:/bar:/tmp/foo:/tmp/bar");
+ const String abs__file__ = Path::abspath (__TOPDIR__ "sfi/tests/" __FILE__);
+ TCMP (Path::searchpath_list ("/:" + abs__file__, "e"), ==, StringVector ({ "/", abs__file__ }));
+ TCMP (Path::searchpath_contains ("/foo/:/bar", "/"), ==, false);
+ TCMP (Path::searchpath_contains ("/foo/:/bar", "/foo"), ==, false); // false because "/foo" is file search
+ TCMP (Path::searchpath_contains ("/foo/:/bar", "/foo/"), ==, true); // true because "/foo/" is dir search
+ TCMP (Path::searchpath_contains ("/foo/:/bar", "/bar"), ==, true); // file search matches /bar
+ TCMP (Path::searchpath_contains ("/foo/:/bar", "/bar/"), ==, true); // dir search matches /bar
+}
+ADD_TEST (test_paths);
+
/* provide IDL type initializers */
#define sfidl_pspec_Real(group, name, nick, blurb, dflt, min, max, step, hints) \
sfi_pspec_real (name, nick, blurb, dflt, min, max, step, hints)
@@ -742,6 +846,7 @@ main (int argc,
generate_vmarshal_code ();
return 0;
}
+ run_test_chain();
test_notes ();
test_time ();
test_renames ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]