From d10796d12fd477215fc024078c0f2d83abc6515e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 Dec 2020 20:15:05 +0100 Subject: Avoid "using namespace" --- tests/ingen_bench.cpp | 50 ++++++++++++++++++++++++++++++++++---------------- tests/ingen_test.cpp | 51 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 70 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/ingen_bench.cpp b/tests/ingen_bench.cpp index 83fbef31..2af53f89 100644 --- a/tests/ingen_bench.cpp +++ b/tests/ingen_bench.cpp @@ -32,22 +32,23 @@ #include #include -using namespace std; -using namespace ingen; +namespace ingen { +namespace bench { +namespace { -static unique_ptr world; +std::unique_ptr world; -static void +void ingen_try(bool cond, const char* msg) { if (!cond) { - cerr << "ingen: Error: " << msg << endl; + std::cerr << "ingen: Error: " << msg << std::endl; world.reset(); exit(EXIT_FAILURE); } } -static std::string +std::string real_path(const char* path) { char* const c_real_path = realpath(path, nullptr); @@ -57,19 +58,19 @@ real_path(const char* path) } int -main(int argc, char** argv) +run(int argc, char** argv) { - set_bundle_path_from_code(reinterpret_cast(&ingen_try)); - // Create world try { - world = unique_ptr{new World(nullptr, nullptr, nullptr)}; + world = std::unique_ptr{ + new ingen::World(nullptr, nullptr, nullptr)}; + world->conf().add( "output", "output", 'O', "File to write benchmark output", ingen::Configuration::SESSION, world->forge().String, Atom()); world->load_configuration(argc, argv); } catch (std::exception& e) { - cout << "ingen: " << e.what() << endl; + std::cout << "ingen: " << e.what() << std::endl; return EXIT_FAILURE; } @@ -77,7 +78,9 @@ main(int argc, char** argv) const Atom& load = world->conf().option("load"); const Atom& out = world->conf().option("output"); if (!load.is_valid() || !out.is_valid()) { - cerr << "Usage: ingen_bench --load START_GRAPH --output OUT_FILE" << endl; + std::cerr << "Usage: ingen_bench --load START_GRAPH --output OUT_FILE" + << std::endl; + return EXIT_FAILURE; } @@ -87,9 +90,9 @@ main(int argc, char** argv) const std::string out_file = static_cast(out.get_body()); if (start_graph.empty()) { - cerr << "error: initial graph '" - << static_cast(load.get_body()) - << "' does not exist" << endl; + std::cerr << "error: initial graph '" + << static_cast(load.get_body()) + << "' does not exist" << std::endl; return EXIT_FAILURE; } @@ -105,7 +108,9 @@ main(int argc, char** argv) // Load graph if (!world->parser()->parse_file(*world, *world->interface(), start_graph)) { - cerr << "error: failed to load initial graph " << start_graph << endl; + std::cerr << "error: failed to load initial graph " << start_graph + << std::endl; + return EXIT_FAILURE; } world->engine()->flush_events(std::chrono::milliseconds(20)); @@ -139,3 +144,16 @@ main(int argc, char** argv) return EXIT_SUCCESS; } + +} // namespace +} // namespace bench +} // namespace ingen + +int +main(int argc, char** argv) +{ + ingen::set_bundle_path_from_code( + reinterpret_cast(&ingen::bench::ingen_try)); + + return ingen::bench::run(argc, argv); +} diff --git a/tests/ingen_test.cpp b/tests/ingen_test.cpp index 291c725e..16dc0a0a 100644 --- a/tests/ingen_test.cpp +++ b/tests/ingen_test.cpp @@ -46,22 +46,23 @@ #include #include -using namespace std; -using namespace ingen; +namespace ingen { +namespace test { +namespace { -static unique_ptr world; +std::unique_ptr world; -static void +void ingen_try(bool cond, const char* msg) { if (!cond) { - cerr << "ingen: Error: " << msg << endl; + std::cerr << "ingen: Error: " << msg << std::endl; world.reset(); exit(EXIT_FAILURE); } } -static FilePath +FilePath real_file_path(const char* path) { std::unique_ptr> real_path{realpath(path, nullptr)}; @@ -70,16 +71,14 @@ real_file_path(const char* path) } int -main(int argc, char** argv) +run(int argc, char** argv) { - set_bundle_path_from_code(reinterpret_cast(&ingen_try)); - // Create world try { - world = unique_ptr{new World(nullptr, nullptr, nullptr)}; + world = std::unique_ptr{new World(nullptr, nullptr, nullptr)}; world->load_configuration(argc, argv); } catch (std::exception& e) { - cout << "ingen: " << e.what() << endl; + std::cout << "ingen: " << e.what() << std::endl; return EXIT_FAILURE; } @@ -87,7 +86,10 @@ main(int argc, char** argv) const Atom& load = world->conf().option("load"); const Atom& execute = world->conf().option("execute"); if (!load.is_valid() || !execute.is_valid()) { - cerr << "Usage: ingen_test --load START_GRAPH --execute COMMANDS_FILE" << endl; + std::cerr + << "Usage: ingen_test --load START_GRAPH --execute COMMANDS_FILE" + << std::endl; + return EXIT_FAILURE; } @@ -96,10 +98,14 @@ main(int argc, char** argv) const FilePath run_path = real_file_path(static_cast(execute.get_body())); if (load_path.empty()) { - cerr << "error: initial graph '" << load_path << "' does not exist" << endl; + std::cerr << "error: initial graph '" << load_path << "' does not exist" + << std::endl; + return EXIT_FAILURE; } else if (run_path.empty()) { - cerr << "error: command file '" << run_path << "' does not exist" << endl; + std::cerr << "error: command file '" << run_path << "' does not exist" + << std::endl; + return EXIT_FAILURE; } @@ -115,7 +121,9 @@ main(int argc, char** argv) // Load graph if (!world->parser()->parse_file(*world, *world->interface(), load_path)) { - cerr << "error: failed to load initial graph " << load_path << endl; + std::cerr << "error: failed to load initial graph " << load_path + << std::endl; + return EXIT_FAILURE; } world->engine()->flush_events(std::chrono::milliseconds(20)); @@ -221,3 +229,16 @@ main(int argc, char** argv) return EXIT_SUCCESS; } + +} // namespace +} // namespace test +} // namespace ingen + +int +main(int argc, char** argv) +{ + ingen::set_bundle_path_from_code( + reinterpret_cast(&ingen::test::ingen_try)); + + return ingen::test::run(argc, argv); +} -- cgit v1.2.1