diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
commit | 8286ac511144e4f17d34eac9affb97e50646344a (patch) | |
tree | f1af7320d7b6be6be059216d0ad08ac7b4f73fd0 /libcutl/tests/fs/path/driver.cxx | |
parent | a15cf65c44d5c224169c32ef5495b68c758134b7 (diff) |
Imported Upstream version 4.0.0upstream/4.0.0
Diffstat (limited to 'libcutl/tests/fs/path/driver.cxx')
-rw-r--r-- | libcutl/tests/fs/path/driver.cxx | 144 |
1 files changed, 144 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; + */ +} |