summaryrefslogtreecommitdiff
path: root/libcutl/tests/fs/path
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 15:21:29 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 15:21:29 +0200
commitbada6666c70977a058755ccf232e7d67b24adeed (patch)
tree1e92d50cebce96abaf9bce19e36026c47f77b9ba /libcutl/tests/fs/path
parenteaf34adcbd8095bc6d1f3371b1227f654c7b19fc (diff)
New upstream release
Diffstat (limited to 'libcutl/tests/fs/path')
-rw-r--r--libcutl/tests/fs/path/driver.cxx144
-rw-r--r--libcutl/tests/fs/path/makefile69
2 files changed, 213 insertions, 0 deletions
diff --git a/libcutl/tests/fs/path/driver.cxx b/libcutl/tests/fs/path/driver.cxx
new file mode 100644
index 0000000..6c77e67
--- /dev/null
+++ b/libcutl/tests/fs/path/driver.cxx
@@ -0,0 +1,144 @@
+// file : tests/fs/path/driver.cxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <cassert>
+#include <iostream>
+
+#include <cutl/fs/path.hxx>
+
+using std::cerr;
+using std::endl;
+
+using namespace cutl::fs;
+
+int
+main ()
+{
+ assert (path ("/").string () == "/");
+ assert (path ("//").string () == "/");
+ assert (path ("/tmp/foo/").string () == "/tmp/foo");
+#ifdef _WIN32
+ assert (path ("\\\\").string () == "\\");
+ assert (path ("/\\").string () == "/");
+ assert (path ("C:").string () == "C:");
+ assert (path ("C:\\").string () == "C:");
+ assert (path ("C:\\tmp\\foo\\").string () == "C:\\tmp\\foo");
+#endif
+
+ // abslote/relative/root
+ //
+#ifndef _WIN32
+ assert (path ("/").root ());
+ assert (path ("//").root ());
+ assert (path ("/").absolute ());
+ assert (path ("/foo/bar").absolute ());
+ assert (path ("bar/baz").relative ());
+#else
+ assert (path ("C:").root ());
+ assert (path ("C:\\").root ());
+ assert (path ("C:\\").absolute ());
+ assert (path ("C:\\foo\\bar").absolute ());
+ assert (path ("bar\\baz").relative ());
+#endif
+
+
+ // leaf
+ //
+#ifndef _WIN32
+ assert (path ("/").leaf ().string () == "");
+ assert (path ("/tmp").leaf ().string () == "tmp");
+ assert (path ("//tmp").leaf ().string () == "tmp");
+#else
+ assert (path ("C:").leaf ().string () == "C:");
+ assert (path ("C:\\tmp").leaf ().string () == "tmp");
+ assert (path ("C:\\\\tmp").leaf ().string () == "tmp");
+#endif
+
+ // directory
+ //
+#ifndef _WIN32
+ assert (path ("/").directory ().string () == "");
+ assert (path ("/tmp").directory ().string () == "/");
+ assert (path ("//tmp").directory ().string () == "/");
+#else
+ assert (path ("C:").directory ().string () == "");
+ assert (path ("C:\\tmp").directory ().string () == "C:");
+ assert (path ("C:\\\\tmp").directory ().string () == "C:");
+#endif
+
+ // base
+ //
+ assert (path ("/").base ().string () == "/");
+ assert (path ("/foo.txt").base ().string () == "/foo");
+ assert (path (".txt").base ().string () == ".txt");
+ assert (path ("/.txt").base ().string () == "/.txt");
+ assert (path ("foo.txt.orig").base ().string () == "foo.txt");
+#ifdef _WIN32
+ assert (path ("C:").base ().string () == "C:");
+ assert (path ("C:\\foo.txt").base ().string () == "C:\\foo");
+#endif
+
+ // operator/
+ //
+#ifndef _WIN32
+ assert ((path ("/") / path ("tmp")).string () == "/tmp");
+ assert ((path ("foo") / path ("bar")).string () == "foo/bar");
+#else
+ assert ((path ("\\") / path ("tmp")).string () == "\\tmp");
+ assert ((path ("C:\\") / path ("tmp")).string () == "C:\\tmp");
+ assert ((path ("foo") / path ("bar")).string () == "foo\\bar");
+#endif
+
+ // normalize
+ //
+#ifndef _WIN32
+ assert (path ("../foo").normalize ().string () == "../foo");
+ assert (path ("..///foo").normalize ().string () == "../foo");
+ assert (path ("../../foo").normalize ().string () == "../../foo");
+ assert (path (".././foo").normalize ().string () == "../foo");
+ assert (path (".").normalize ().string () == "");
+ assert (path ("./..").normalize ().string () == "..");
+ assert (path ("../.").normalize ().string () == "..");
+ assert (path ("foo/./..").normalize ().string () == "");
+ assert (path ("/foo/./..").normalize ().string () == "/");
+ assert (path ("./foo").normalize ().string () == "foo");
+#else
+ assert (path ("../foo").normalize ().string () == "..\\foo");
+ assert (path ("..///foo").normalize ().string () == "..\\foo");
+ assert (path ("..\\../foo").normalize ().string () == "..\\..\\foo");
+ assert (path (".././foo").normalize ().string () == "..\\foo");
+ assert (path (".").normalize ().string () == "");
+ assert (path ("./..").normalize ().string () == "..");
+ assert (path ("../.").normalize ().string () == "..");
+ assert (path ("foo/./..").normalize ().string () == "");
+ assert (path ("C:/foo/./..").normalize ().string () == "c:");
+ assert (path ("./foo").normalize ().string () == "foo");
+
+ assert (path ("C:").normalize ().string () == "c:");
+ assert (path ("C:\\Foo12//Bar").normalize ().string () == "c:\\foo12\\bar");
+#endif
+
+ // posix_string
+ //
+ assert (path ("foo/bar/../baz").posix_string () == "foo/bar/../baz");
+#ifdef _WIN32
+ assert (path ("foo\\bar\\..\\baz").posix_string () == "foo/bar/../baz");
+ try
+ {
+ path ("c:\\foo\\bar\\..\\baz").posix_string ();
+ assert (false);
+ }
+ catch (const invalid_path&) {}
+#endif
+
+ /*
+ path p ("../foo");
+ p.complete ();
+
+ cerr << path::current () << endl;
+ cerr << p << endl;
+ p.normalize ();
+ cerr << p << endl;
+ */
+}
diff --git a/libcutl/tests/fs/path/makefile b/libcutl/tests/fs/path/makefile
new file mode 100644
index 0000000..184510b
--- /dev/null
+++ b/libcutl/tests/fs/path/makefile
@@ -0,0 +1,69 @@
+# file : tests/fs/path/makefile
+# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+
+#
+#
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+cutl.l := $(out_root)/cutl/cutl.l
+cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Build.
+#
+$(driver): $(cxx_obj) $(cutl.l)
+$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options)
+
+
+$(call include-dep,$(cxx_od))
+
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+$(test): $(driver)
+ $(call message,test $<,$<)
+
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od))
+
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-e.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/cutl/makefile)