summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ingen_test.cpp23
-rw-r--r--tests/test_utils.hpp40
-rw-r--r--tests/tst_FilePath.cpp103
3 files changed, 152 insertions, 14 deletions
diff --git a/tests/ingen_test.cpp b/tests/ingen_test.cpp
index ab7cbc7d..beac1a7f 100644
--- a/tests/ingen_test.cpp
+++ b/tests/ingen_test.cpp
@@ -22,11 +22,6 @@
#include <boost/optional.hpp>
-#include <glibmm/convert.h>
-#include <glibmm/miscutils.h>
-#include <glibmm/thread.h>
-#include <glibmm/timer.h>
-
#include "raul/Path.hpp"
#include "serd/serd.h"
@@ -48,6 +43,7 @@
#include "ingen/URIMap.hpp"
#include "ingen/World.hpp"
#include "ingen/client/ThreadedSigClientInterface.hpp"
+#include "ingen/filesystem.hpp"
#include "ingen/runtime_paths.hpp"
#include "ingen/types.hpp"
@@ -71,7 +67,6 @@ ingen_try(bool cond, const char* msg)
int
main(int argc, char** argv)
{
- Glib::thread_init();
set_bundle_path_from_code((void*)&ingen_try);
// Create world
@@ -100,7 +95,7 @@ main(int argc, char** argv)
}
const std::string start_graph = real_start_graph;
- const std::string cmds_file_path = (const char*)execute.get_body();
+ const FilePath cmds_file_path = (const char*)execute.get_body();
free(real_start_graph);
// Load modules
@@ -188,10 +183,10 @@ main(int argc, char** argv)
// Save resulting graph
auto r = world->store()->find(Raul::Path("/"));
- const std::string base = Glib::path_get_basename(cmds_file_path);
+ const std::string base = cmds_file_path.stem();
const std::string out_name = base.substr(0, base.find('.')) + ".out.ingen";
- const std::string out_path = Glib::build_filename(Glib::get_current_dir(), out_name);
- world->serialiser()->write_bundle(r->second, URI(Glib::filename_to_uri(out_path)));
+ const FilePath out_path = filesystem::current_path() / out_name;
+ world->serialiser()->write_bundle(r->second, URI(out_path));
// Undo every event (should result in a graph identical to the original)
for (int i = 0; i < n_events; ++i) {
@@ -202,8 +197,8 @@ main(int argc, char** argv)
// Save completely undone graph
r = world->store()->find(Raul::Path("/"));
const std::string undo_name = base.substr(0, base.find('.')) + ".undo.ingen";
- const std::string undo_path = Glib::build_filename(Glib::get_current_dir(), undo_name);
- world->serialiser()->write_bundle(r->second, URI(Glib::filename_to_uri(undo_path)));
+ const FilePath undo_path = filesystem::current_path() / undo_name;
+ world->serialiser()->write_bundle(r->second, URI(undo_path));
// Redo every event (should result in a graph identical to the pre-undo output)
for (int i = 0; i < n_events; ++i) {
@@ -214,8 +209,8 @@ main(int argc, char** argv)
// Save completely redone graph
r = world->store()->find(Raul::Path("/"));
const std::string redo_name = base.substr(0, base.find('.')) + ".redo.ingen";
- const std::string redo_path = Glib::build_filename(Glib::get_current_dir(), redo_name);
- world->serialiser()->write_bundle(r->second, URI(Glib::filename_to_uri(redo_path)));
+ const FilePath redo_path = filesystem::current_path() / redo_name;
+ world->serialiser()->write_bundle(r->second, URI(redo_path));
serd_env_free(env);
sratom_free(sratom);
diff --git a/tests/test_utils.hpp b/tests/test_utils.hpp
new file mode 100644
index 00000000..a0cc53ac
--- /dev/null
+++ b/tests/test_utils.hpp
@@ -0,0 +1,40 @@
+/*
+ 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 <iostream>
+
+#include <boost/format.hpp>
+
+typedef boost::basic_format<char> fmt;
+
+#define EXPECT_TRUE(value) \
+ if (!(value)) { \
+ std::cerr << (fmt("error: %1%:%2%: !%3%\n") % __FILE__ % \
+ __LINE__ % (#value)); \
+ }
+
+#define EXPECT_FALSE(value) \
+ if ((value)) { \
+ std::cerr << (fmt("error: %1%:%2%: !%3%\n") % __FILE__ % \
+ __LINE__ % (#value)); \
+ }
+
+#define EXPECT_EQ(value, expected) \
+ if (!((value) == (expected))) { \
+ std::cerr << (fmt("error: %1%:%2%: %3% != %4%\n") % __FILE__ % \
+ __LINE__ % (#value) % (#expected)); \
+ std::cerr << "note: actual value: " << value << std::endl; \
+ }
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;
+}