aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-02-18 13:55:39 +0100
committerJay Berkenbilt <ejb@ql.org>2021-02-18 15:59:03 +0100
commit0b1623d07db963ecf3789aba7163321812cba88e (patch)
tree93c9e387915ef9e8e500750a32f0ff650698f9ee /libtests/qutil.cc
parentf21e4f264ab285817bfad1698dbb8b8b300c9ece (diff)
downloadqpdf-0b1623d07db963ecf3789aba7163321812cba88e.tar.zst
Add QUtil::path_basename
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index abe05f35..7b1a8788 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -439,6 +439,29 @@ void same_file_test()
assert_same_file("", "qutil.out", false);
}
+void path_test()
+{
+ auto check = [](bool print, std::string const& a, std::string const& b) {
+ auto result = QUtil::path_basename(a);
+ if (print)
+ {
+ std::cout << a << " -> " << result << std::endl;
+ }
+ assert(result == b);
+ };
+
+#ifdef _WIN32
+ check(false, "asdf\\qwer", "qwer");
+ check(false, "asdf\\qwer/\\", "qwer");
+#endif
+ check(true, "////", "/");
+ check(true, "a/b/cdef", "cdef");
+ check(true, "a/b/cdef/", "cdef");
+ check(true, "/", "/");
+ check(true, "", "");
+ check(true, "quack", "quack");
+}
+
void read_from_file_test()
{
std::list<std::string> lines = QUtil::read_lines_from_file("other-file");
@@ -636,6 +659,8 @@ int main(int argc, char* argv[])
get_whoami_test();
std::cout << "---- file" << std::endl;
same_file_test();
+ std::cout << "---- path" << std::endl;
+ path_test();
std::cout << "---- read from file" << std::endl;
read_from_file_test();
std::cout << "---- hex encode/decode" << std::endl;