aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/CMakeLists.txt2
-rw-r--r--tests/unit_tests/epee_utils.cpp4
-rw-r--r--tests/unit_tests/main.cpp31
-rw-r--r--tests/unit_tests/serialization.cpp8
4 files changed, 28 insertions, 17 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index d5f090700..c7efcf074 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -101,4 +101,4 @@ endif ()
add_test(
NAME unit_tests
- COMMAND unit_tests "${TEST_DATA_DIR}")
+ COMMAND unit_tests --data-dir "${TEST_DATA_DIR}")
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index f6cb0c163..a13081491 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -37,9 +37,7 @@
#include <sstream>
#include <vector>
-#ifdef _WIN32
-# include <winsock.h>
-#else
+#ifndef _WIN32
# include <arpa/inet.h>
#endif
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index b2abad942..1706c43c9 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -31,31 +31,44 @@
#include "gtest/gtest.h"
#include <boost/filesystem.hpp>
+#include <boost/program_options.hpp>
#include "include_base_utils.h"
+#include "common/command_line.h"
#include "unit_tests_utils.h"
+namespace po = boost::program_options;
+
boost::filesystem::path unit_test::data_dir;
int main(int argc, char** argv)
{
+ epee::string_tools::set_module_name_and_folder(argv[0]);
mlog_configure(mlog_get_default_log_path("unit_tests.log"), true);
epee::debug::get_set_enable_assert(true, false);
::testing::InitGoogleTest(&argc, argv);
- // Process remaining arguments
- if (argc == 2 && argv[1] != NULL) { // one arg: path to dir with test data
- unit_test::data_dir = argv[1];
- } else if (argc == 1) { // legacy: assume test binaries in 'build/release'
- epee::string_tools::set_module_name_and_folder(argv[0]);
+ po::options_description desc_options("Command line options");
+ const command_line::arg_descriptor<std::string> arg_data_dir = {"data-dir", "Data files directory", "", true};
+ command_line::add_arg(desc_options, command_line::arg_data_dir, "");
+
+ po::variables_map vm;
+ bool r = command_line::handle_error_helper(desc_options, [&]()
+ {
+ po::store(po::parse_command_line(argc, argv, desc_options), vm);
+ po::notify(vm);
+ return true;
+ });
+ if (! r)
+ return 1;
+
+ if (vm["data-dir"].defaulted())
unit_test::data_dir = boost::filesystem::path(epee::string_tools::get_current_module_folder())
.parent_path().parent_path().parent_path().parent_path()
.append("tests").append("data");
- } else {
- std::cerr << "Usage: " << argv[0] << " [<path-to-test-data-dir>]" << std::endl;
- return 1;
- }
+ else
+ unit_test::data_dir = command_line::get_arg(vm, arg_data_dir);
return RUN_ALL_TESTS();
}
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 202c8718f..011082d1c 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -677,7 +677,7 @@ TEST(Serialization, portability_wallet)
bool r = false;
try
{
- w.load(wallet_file.native(), password);
+ w.load(wallet_file.string(), password);
r = true;
}
catch (const exception& e)
@@ -794,7 +794,7 @@ TEST(Serialization, portability_outputs)
// read file
const boost::filesystem::path filename = unit_test::data_dir / "outputs";
std::string data;
- bool r = epee::file_io_utils::load_file_to_string(filename.native(), data);
+ bool r = epee::file_io_utils::load_file_to_string(filename.string(), data);
ASSERT_TRUE(r);
const size_t magiclen = strlen(OUTPUT_EXPORT_FILE_MAGIC);
ASSERT_FALSE(data.size() < magiclen || memcmp(data.data(), OUTPUT_EXPORT_FILE_MAGIC, magiclen));
@@ -910,7 +910,7 @@ TEST(Serialization, portability_unsigned_tx)
const boost::filesystem::path filename = unit_test::data_dir / "unsigned_monero_tx";
std::string s;
const bool testnet = true;
- bool r = epee::file_io_utils::load_file_to_string(filename.native(), s);
+ bool r = epee::file_io_utils::load_file_to_string(filename.string(), s);
ASSERT_TRUE(r);
const size_t magiclen = strlen(UNSIGNED_TX_PREFIX);
ASSERT_FALSE(strncmp(s.c_str(), UNSIGNED_TX_PREFIX, magiclen));
@@ -1058,7 +1058,7 @@ TEST(Serialization, portability_signed_tx)
const boost::filesystem::path filename = unit_test::data_dir / "signed_monero_tx";
const bool testnet = true;
std::string s;
- bool r = epee::file_io_utils::load_file_to_string(filename.native(), s);
+ bool r = epee::file_io_utils::load_file_to_string(filename.string(), s);
ASSERT_TRUE(r);
const size_t magiclen = strlen(SIGNED_TX_PREFIX);
ASSERT_FALSE(strncmp(s.c_str(), SIGNED_TX_PREFIX, magiclen));