aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2018-02-16 18:21:44 -0800
committerMartin Braun <martin.braun@ettus.com>2018-02-20 16:23:46 -0800
commita99e89a689490aa03e2bbd8153b61e394cd55a6e (patch)
treedb28c00c4d5b44bba918eb4fc52a6683e52fa181 /host/tests
parent2ff296c99760628c4b0042cf6d2b32a0e3986364 (diff)
downloaduhd-a99e89a689490aa03e2bbd8153b61e394cd55a6e.tar.gz
uhd-a99e89a689490aa03e2bbd8153b61e394cd55a6e.tar.bz2
uhd-a99e89a689490aa03e2bbd8153b61e394cd55a6e.zip
lib: Add path_expandvars() internal API call
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/CMakeLists.txt23
-rw-r--r--host/tests/paths_test.cpp72
2 files changed, 95 insertions, 0 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index 437a697d0..7d53b50c4 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -125,6 +125,29 @@ UHD_INSTALL(TARGETS
COMPONENT tests
)
+ADD_EXECUTABLE(paths_test
+ paths_test.cpp
+ ${CMAKE_SOURCE_DIR}/lib/utils/pathslib.cpp
+)
+# Careful: This is to satisfy the out-of-library build of paths.cpp. This is
+# duplicate code from lib/utils/CMakeLists.txt, and it's been simplified.
+SET(UHD_LIB_DIR "lib")
+FILE(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" UHD_PKG_PATH)
+STRING(REPLACE "\\" "\\\\" UHD_PKG_PATH "${UHD_PKG_PATH}")
+SET_SOURCE_FILES_PROPERTIES(
+ ${CMAKE_SOURCE_DIR}/lib/utils/paths.cpp
+ PROPERTIES COMPILE_DEFINITIONS
+ "UHD_PKG_PATH=\"${UHD_PKG_PATH}\";UHD_LIB_DIR=\"${UHD_LIB_DIR}\""
+)
+TARGET_LINK_LIBRARIES(paths_test uhd ${Boost_LIBRARIES})
+UHD_ADD_TEST(paths_test paths_test)
+UHD_INSTALL(TARGETS
+ paths_test
+ RUNTIME
+ DESTINATION ${PKG_LIB_DIR}/tests
+ COMPONENT tests
+)
+
########################################################################
# demo of a loadable module
########################################################################
diff --git a/host/tests/paths_test.cpp b/host/tests/paths_test.cpp
new file mode 100644
index 000000000..0ccebd333
--- /dev/null
+++ b/host/tests/paths_test.cpp
@@ -0,0 +1,72 @@
+//
+// Copyright 2018 Ettus Research, a National Instruments Company
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhd/config.hpp>
+#include <uhd/exception.hpp>
+#include <uhd/utils/paths.hpp>
+#include <uhdlib/utils/paths.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <vector>
+#include <iostream>
+
+BOOST_AUTO_TEST_CASE(test_paths_expandvars) {
+#ifdef UHD_PLATFORM_WIN32
+ const std::string path_to_expand("\%programdata%/uhd/uhd.conf");
+#else
+ const std::string path_to_expand("$HOME/.uhd/uhd.conf");
+#endif
+ const std::string expanded_path = uhd::path_expandvars(path_to_expand);
+
+ std::cout << "Expanded path: " << path_to_expand << " -> "
+ << expanded_path << std::endl;
+ BOOST_CHECK(path_to_expand != expanded_path);
+
+#ifdef UHD_PLATFORM_WIN32
+ const std::string var_identifier = "%";
+#else
+ const std::string var_identifier = "$";
+#endif
+
+ BOOST_CHECK(expanded_path.find(var_identifier) == std::string::npos);
+}
+
+
+BOOST_AUTO_TEST_CASE(test_get_paths) {
+ using namespace uhd;
+
+ const std::string tmp_path = get_tmp_path();
+ const std::string app_path = get_app_path();
+ const std::string pkg_path = get_pkg_path();
+ const auto module_paths = get_module_paths();
+
+ std::cout << "tmp_path: " << tmp_path << std::endl;
+ std::cout << "app_path: " << app_path << std::endl;
+ std::cout << "pkg_path: " << pkg_path << std::endl;
+ for (const auto& module_path : module_paths) {
+ std::cout << "module path: " << module_path << std::endl;
+ }
+
+ const std::string images_dir_search_path = "";
+ const std::string images_dir = get_images_dir(images_dir_search_path);
+ BOOST_REQUIRE_THROW(
+ find_image_path("this_device_does_not_exist.bit", ""),
+ uhd::io_error
+ );
+
+ const std::string utility_path = find_utility(
+ "uhd_images_downloader"
+ );
+ std::cout << "utility_path: " << utility_path << std::endl;
+
+ const std::string utility_error = print_utility_error(
+ "uhd_images_downloader",
+ "--help"
+ );
+ std::cout << "utility_error: " << tmp_path << std::endl;
+
+}
+