summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-14 20:15:05 +0100
committerDavid Robillard <d@drobilla.net>2020-12-14 22:04:29 +0100
commitd10796d12fd477215fc024078c0f2d83abc6515e (patch)
tree2e317aeca3bbf96adafc83612c1768650d126c9f /tests
parent337ca8a63882c43b086f5049cc3c03230953a063 (diff)
downloadingen-d10796d12fd477215fc024078c0f2d83abc6515e.tar.gz
ingen-d10796d12fd477215fc024078c0f2d83abc6515e.tar.bz2
ingen-d10796d12fd477215fc024078c0f2d83abc6515e.zip
Avoid "using namespace"
Diffstat (limited to 'tests')
-rw-r--r--tests/ingen_bench.cpp50
-rw-r--r--tests/ingen_test.cpp51
2 files changed, 70 insertions, 31 deletions
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 <memory>
#include <string>
-using namespace std;
-using namespace ingen;
+namespace ingen {
+namespace bench {
+namespace {
-static unique_ptr<World> world;
+std::unique_ptr<ingen::World> 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<void(*)()>(&ingen_try));
-
// Create world
try {
- world = unique_ptr<World>{new World(nullptr, nullptr, nullptr)};
+ world = std::unique_ptr<ingen::World>{
+ 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<const char*>(out.get_body());
if (start_graph.empty()) {
- cerr << "error: initial graph '"
- << static_cast<const char*>(load.get_body())
- << "' does not exist" << endl;
+ std::cerr << "error: initial graph '"
+ << static_cast<const char*>(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<void (*)()>(&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 <string>
#include <utility>
-using namespace std;
-using namespace ingen;
+namespace ingen {
+namespace test {
+namespace {
-static unique_ptr<World> world;
+std::unique_ptr<World> 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<char, FreeDeleter<char>> 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<void(*)()>(&ingen_try));
-
// Create world
try {
- world = unique_ptr<World>{new World(nullptr, nullptr, nullptr)};
+ world = std::unique_ptr<World>{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<const char*>(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<void (*)()>(&ingen::test::ingen_try));
+
+ return ingen::test::run(argc, argv);
+}