summaryrefslogtreecommitdiffstats
path: root/tests/tst_FilePath.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-01-21 00:41:34 +0100
committerDavid Robillard <d@drobilla.net>2018-01-21 00:56:50 +0100
commita99b72e4adbc4c28fadc08d29299d99405f72db9 (patch)
treefb21f2cea8f5db1dc187cdbdd01f43e73bbddfff /tests/tst_FilePath.cpp
parent329f498d901f9be9c0c820749850f5277a17df5d (diff)
downloadingen-a99b72e4adbc4c28fadc08d29299d99405f72db9.tar.gz
ingen-a99b72e4adbc4c28fadc08d29299d99405f72db9.tar.bz2
ingen-a99b72e4adbc4c28fadc08d29299d99405f72db9.zip
Add FilePath class and remove use of glib path utilities
Diffstat (limited to 'tests/tst_FilePath.cpp')
-rw-r--r--tests/tst_FilePath.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/tst_FilePath.cpp b/tests/tst_FilePath.cpp
new file mode 100644
index 00000000..d3cf1efa
--- /dev/null
+++ b/tests/tst_FilePath.cpp
@@ -0,0 +1,103 @@
+/*
+ This file is part of Ingen.
+ Copyright 2018 David Robillard <http://drobilla.net/>
+
+ Ingen is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or any later version.
+
+ Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with Ingen. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <boost/utility/string_view.hpp>
+
+#include "ingen/FilePath.hpp"
+#include "test_utils.hpp"
+
+using Ingen::FilePath;
+
+int
+main(int, char**)
+{
+ EXPECT_EQ(FilePath("/").parent_path(), FilePath("/"));
+
+ EXPECT_TRUE(FilePath("/abs").is_absolute())
+ EXPECT_FALSE(FilePath("/abs").is_relative())
+ EXPECT_EQ(FilePath("/abs").root_name(), FilePath());
+ EXPECT_EQ(FilePath("/abs").root_directory(), FilePath("/"));
+ EXPECT_EQ(FilePath("/abs").root_path(), FilePath("/"));
+ EXPECT_EQ(FilePath("/abs").relative_path(), FilePath("abs"));
+ EXPECT_EQ(FilePath("/abs").parent_path(), FilePath("/"));
+ EXPECT_EQ(FilePath("/abs").filename(), FilePath("abs"));
+ EXPECT_EQ(FilePath("/abs").stem(), FilePath("abs"));
+ EXPECT_EQ(FilePath("/abs").extension(), FilePath());
+
+ EXPECT_FALSE(FilePath("rel").is_absolute())
+ EXPECT_TRUE(FilePath("rel").is_relative())
+ EXPECT_EQ(FilePath("rel").root_name(), FilePath());
+ EXPECT_EQ(FilePath("rel").root_directory(), FilePath());
+ EXPECT_EQ(FilePath("rel").root_path(), FilePath());
+ EXPECT_EQ(FilePath("rel").relative_path(), FilePath());
+ EXPECT_EQ(FilePath("rel").parent_path(), FilePath());
+ EXPECT_EQ(FilePath("rel").filename(), "rel");
+ EXPECT_EQ(FilePath("rel").stem(), "rel");
+ EXPECT_EQ(FilePath("rel").extension(), FilePath());
+
+ EXPECT_FALSE(FilePath("file.txt").is_absolute())
+ EXPECT_TRUE(FilePath("file.txt").is_relative())
+ EXPECT_EQ(FilePath("file.txt").filename(), "file.txt");
+ EXPECT_EQ(FilePath("file.txt").stem(), "file");
+ EXPECT_EQ(FilePath("file.txt").extension(), ".txt");
+
+ EXPECT_TRUE(FilePath("/abs/file.txt").is_absolute())
+ EXPECT_FALSE(FilePath("/abs/file.txt").is_relative())
+ EXPECT_EQ(FilePath("/abs/file.txt").filename(), "file.txt");
+ EXPECT_EQ(FilePath("/abs/file.txt").stem(), "file");
+ EXPECT_EQ(FilePath("/abs/file.txt").extension(), ".txt");
+
+ EXPECT_FALSE(FilePath("rel/file.txt").is_absolute())
+ EXPECT_TRUE(FilePath("rel/file.txt").is_relative())
+ EXPECT_EQ(FilePath("rel/file.txt").filename(), "file.txt");
+ EXPECT_EQ(FilePath("rel/file.txt").stem(), "file");
+ EXPECT_EQ(FilePath("rel/file.txt").extension(), ".txt");
+
+ FilePath path("/x");
+ EXPECT_EQ(path, "/x");
+ path = std::move(std::string("/a"));
+ EXPECT_EQ(path, "/a");
+
+ path /= FilePath("b");
+ EXPECT_EQ(path, "/a/b");
+
+ path += FilePath("ar");
+ EXPECT_EQ(path, "/a/bar");
+
+ path += std::string("/c");
+ EXPECT_EQ(path, "/a/bar/c");
+
+ path += "a";
+ EXPECT_EQ(path, "/a/bar/ca");
+
+ path += 'r';
+ EXPECT_EQ(path, "/a/bar/car");
+
+ path += boost::string_view("/d");
+ EXPECT_EQ(path, "/a/bar/car/d");
+
+ const FilePath apple("apple");
+ const FilePath zebra("zebra");
+ EXPECT_TRUE(apple == apple);
+ EXPECT_TRUE(apple != zebra);
+ EXPECT_TRUE(apple < zebra);
+ EXPECT_TRUE(apple <= zebra);
+ EXPECT_TRUE(apple <= apple);
+ EXPECT_TRUE(zebra > apple);
+ EXPECT_TRUE(zebra >= apple);
+ EXPECT_TRUE(zebra >= zebra);
+ return 0;
+}