diff options
Diffstat (limited to 'tests/ingen_test.cpp')
-rw-r--r-- | tests/ingen_test.cpp | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/tests/ingen_test.cpp b/tests/ingen_test.cpp index df7e9d34..215d20a1 100644 --- a/tests/ingen_test.cpp +++ b/tests/ingen_test.cpp @@ -16,40 +16,41 @@ #include "TestClient.hpp" -#include "ingen/Atom.hpp" -#include "ingen/AtomForge.hpp" -#include "ingen/AtomReader.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/EngineBase.hpp" -#include "ingen/FilePath.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Parser.hpp" -#include "ingen/Serialiser.hpp" -#include "ingen/Store.hpp" -#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" -#include "raul/Path.hpp" -#include "serd/serd.h" -#include "sord/sordmm.hpp" -#include "sratom/sratom.h" +#include <ingen/Atom.hpp> +#include <ingen/AtomForge.hpp> +#include <ingen/AtomReader.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/EngineBase.hpp> +#include <ingen/FilePath.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Parser.hpp> +#include <ingen/Serialiser.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/World.hpp> +#include <ingen/fmt.hpp> +#include <ingen/memory.hpp> +#include <ingen/runtime_paths.hpp> +#include <raul/Path.hpp> +#include <serd/serd.h> +#include <sord/sordmm.hpp> +#include <sratom/sratom.h> #include <chrono> #include <cstdint> #include <cstdlib> #include <exception> +#include <filesystem> #include <iostream> #include <map> #include <memory> #include <string> #include <utility> -namespace ingen { -namespace test { +// #define DUMP_EVENTS 1 + +namespace ingen::test { namespace { std::unique_ptr<World> world; @@ -58,7 +59,7 @@ void ingen_try(bool cond, const char* msg) { if (!cond) { - std::cerr << "ingen: Error: " << msg << std::endl; + std::cerr << "ingen: Error: " << msg << "\n"; world.reset(); exit(EXIT_FAILURE); } @@ -67,8 +68,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()}; } @@ -80,8 +81,8 @@ run(int argc, char** argv) try { 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() << "\n"; return EXIT_FAILURE; } @@ -90,8 +91,7 @@ run(int argc, char** argv) const Atom& execute = world->conf().option("execute"); if (!load.is_valid() || !execute.is_valid()) { std::cerr - << "Usage: ingen_test --load START_GRAPH --execute COMMANDS_FILE" - << std::endl; + << "Usage: ingen_test --load START_GRAPH --execute COMMANDS_FILE\n"; return EXIT_FAILURE; } @@ -101,16 +101,12 @@ run(int argc, char** argv) const FilePath run_path = real_file_path(static_cast<const char*>(execute.get_body())); if (load_path.empty()) { - std::cerr << "error: initial graph '" << load_path << "' does not exist" - << std::endl; - + std::cerr << "error: initial graph '" << load_path << "' does not exist\n"; return EXIT_FAILURE; } if (run_path.empty()) { - std::cerr << "error: command file '" << run_path << "' does not exist" - << std::endl; - + std::cerr << "error: command file '" << run_path << "' does not exist\n"; return EXIT_FAILURE; } @@ -119,16 +115,14 @@ run(int argc, char** argv) "Unable to load server module"); // Initialise engine - ingen_try(bool(world->engine()), + ingen_try(!!world->engine(), "Unable to create engine"); world->engine()->init(48000.0, 4096, 4096); world->engine()->activate(); // Load graph if (!world->parser()->parse_file(*world, *world->interface(), load_path)) { - std::cerr << "error: failed to load initial graph " << load_path - << std::endl; - + std::cerr << "error: failed to load initial graph " << load_path << "\n"; return EXIT_FAILURE; } world->engine()->flush_events(std::chrono::milliseconds(20)); @@ -146,7 +140,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); @@ -162,10 +156,10 @@ 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); + const std::string subject_str = fmt("msg%1%", n_events); Sord::URI subject(*world->rdf_world(), subject_str, @@ -179,9 +173,9 @@ run(int argc, char** argv) forge.clear(); forge.read(*world->rdf_world(), cmds->c_obj(), subject.c_obj()); -#if 0 +#ifdef DUMP_EVENTS const LV2_Atom* atom = forge.atom(); - cerr << "READ " << atom->size << " BYTES" << endl; + cerr << "READ " << atom->size << " BYTES\n"; cerr << sratom_to_turtle( sratom, &world->uri_map().urid_unmap_feature()->urid_unmap, @@ -190,6 +184,7 @@ run(int argc, char** argv) #endif if (!atom_reader.write(forge.atom(), n_events + 1)) { + delete cmds; return EXIT_FAILURE; } @@ -202,7 +197,7 @@ 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 (makes the graph identical to the original) @@ -214,7 +209,7 @@ 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 (makes the graph identical to the pre-undo output) @@ -226,7 +221,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); @@ -239,14 +234,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() << "\n"; + return EXIT_FAILURE; + } } |