summaryrefslogtreecommitdiffstats
path: root/tests/ingen_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ingen_test.cpp')
-rw-r--r--tests/ingen_test.cpp58
1 files changed, 33 insertions, 25 deletions
diff --git a/tests/ingen_test.cpp b/tests/ingen_test.cpp
index 87e02e9f..b1705dfa 100644
--- a/tests/ingen_test.cpp
+++ b/tests/ingen_test.cpp
@@ -29,7 +29,6 @@
#include "ingen/URI.hpp"
#include "ingen/URIMap.hpp"
#include "ingen/World.hpp"
-#include "ingen/filesystem.hpp"
#include "ingen/fmt.hpp"
#include "ingen/memory.hpp"
#include "ingen/runtime_paths.hpp"
@@ -42,14 +41,14 @@
#include <cstdint>
#include <cstdlib>
#include <exception>
+#include <filesystem>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <utility>
-namespace ingen {
-namespace test {
+namespace ingen::test {
namespace {
std::unique_ptr<World> world;
@@ -67,8 +66,8 @@ ingen_try(bool cond, const char* msg)
FilePath
real_file_path(const char* path)
{
- std::unique_ptr<char, FreeDeleter<char>> real_path{realpath(path, nullptr),
- FreeDeleter<char>{}};
+ const std::unique_ptr<char, FreeDeleter<char>> real_path{realpath(path, nullptr),
+ FreeDeleter<char>{}};
return FilePath{real_path.get()};
}
@@ -78,10 +77,10 @@ run(int argc, char** argv)
{
// Create world
try {
- world = std::unique_ptr<World>{new World(nullptr, nullptr, nullptr)};
+ world = std::make_unique<World>(nullptr, nullptr, nullptr);
world->load_configuration(argc, argv);
- } catch (std::exception& e) {
- std::cout << "ingen: " << e.what() << std::endl;
+ } catch (const std::exception& e) {
+ std::cerr << "ingen: " << e.what() << std::endl;
return EXIT_FAILURE;
}
@@ -105,7 +104,9 @@ run(int argc, char** argv)
<< std::endl;
return EXIT_FAILURE;
- } else if (run_path.empty()) {
+ }
+
+ if (run_path.empty()) {
std::cerr << "error: command file '" << run_path << "' does not exist"
<< std::endl;
@@ -144,7 +145,7 @@ run(int argc, char** argv)
*world->interface());
// AtomWriter to serialise responses from the engine
- std::shared_ptr<Interface> client(new TestClient(world->log()));
+ const std::shared_ptr<Interface> client{new TestClient(world->log())};
world->interface()->set_respondee(client);
world->engine()->register_client(client);
@@ -160,13 +161,16 @@ run(int argc, char** argv)
SerdEnv* env = serd_env_new(&cmds_file_uri);
cmds->load_file(env, SERD_TURTLE, run_path);
- Sord::Node nil;
- int n_events = 0;
+ const Sord::Node nil;
+ int n_events = 0;
for (;; ++n_events) {
- std::string subject_str = fmt("msg%1%", n_events);
- Sord::URI subject(*world->rdf_world(), subject_str,
+ const std::string subject_str = fmt("msg%1%", n_events);
+
+ Sord::URI subject(*world->rdf_world(),
+ subject_str,
reinterpret_cast<const char*>(cmds_file_uri.buf));
- Sord::Iter iter = cmds->find(subject, nil, nil);
+
+ auto iter = cmds->find(subject, nil, nil);
if (iter.end()) {
break;
}
@@ -197,10 +201,10 @@ run(int argc, char** argv)
auto r = world->store()->find(raul::Path("/"));
const std::string base = run_path.stem();
const std::string out_name = base.substr(0, base.find('.')) + ".out.ingen";
- const FilePath out_path = filesystem::current_path() / out_name;
+ const FilePath out_path = std::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)
+ // Undo every event (makes the graph identical to the original)
for (int i = 0; i < n_events; ++i) {
world->interface()->undo();
world->engine()->flush_events(std::chrono::milliseconds(20));
@@ -209,10 +213,10 @@ run(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 FilePath undo_path = filesystem::current_path() / undo_name;
+ const FilePath undo_path = std::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)
+ // Redo every event (makes the graph identical to the pre-undo output)
for (int i = 0; i < n_events; ++i) {
world->interface()->redo();
world->engine()->flush_events(std::chrono::milliseconds(20));
@@ -221,7 +225,7 @@ run(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 FilePath redo_path = filesystem::current_path() / redo_name;
+ const FilePath redo_path = std::filesystem::current_path() / redo_name;
world->serialiser()->write_bundle(r->second, URI(redo_path));
serd_env_free(env);
@@ -234,14 +238,18 @@ run(int argc, char** argv)
}
} // namespace
-} // namespace test
-} // namespace ingen
+} // namespace ingen::test
int
main(int argc, char** argv)
{
- ingen::set_bundle_path_from_code(
- reinterpret_cast<void (*)()>(&ingen::test::ingen_try));
+ try {
+ ingen::set_bundle_path_from_code(
+ reinterpret_cast<void (*)()>(&ingen::test::ingen_try));
- return ingen::test::run(argc, argv);
+ return ingen::test::run(argc, argv);
+ } catch (const std::exception& e) {
+ std::cerr << "ingen: " << e.what() << std::endl;
+ return EXIT_FAILURE;
+ }
}