aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-07-30 02:19:54 +0200
committerJay Berkenbilt <ejb@ql.org>2017-07-30 02:58:01 +0200
commit5993c3e83c6f83b36045c75a03ffb1da3d1d283c (patch)
tree8854661becc586fff8ba07a99d616153f508d43a /libtests/qutil.cc
parent885b8781cccdc9d4402af58176e826a354b5ef7a (diff)
downloadqpdf-5993c3e83c6f83b36045c75a03ffb1da3d1d283c.tar.zst
Detect input file = output file (fixes #29)
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index b0134e79..5e562b89 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -140,6 +140,36 @@ void get_whoami_test()
print_whoami("a\\b\\c\\quack4.exe");
}
+void assert_same_file(char const* file1, char const* file2, bool expected)
+{
+ bool actual = QUtil::same_file(file1, file2);
+ std::cout << "file1: -" << (file1 ? file1 : "(null)") << "-, file2: -"
+ << (file2 ? file2 : "(null)") << "-; same: "
+ << actual << ": " << ((actual == expected) ? "PASS" : "FAIL")
+ << std::endl;
+}
+
+void same_file_test()
+{
+ try
+ {
+ fclose(QUtil::safe_fopen("qutil.out", "r"));
+ fclose(QUtil::safe_fopen("other-file", "r"));
+ }
+ catch (std::exception)
+ {
+ std::cout << "same_file_test expects to have qutil.out and other-file"
+ " exist in the current directory\n";
+ return;
+ }
+ assert_same_file("qutil.out", "./qutil.out", true);
+ assert_same_file("qutil.out", "qutil.out", true);
+ assert_same_file("qutil.out", "other-file", false);
+ assert_same_file("qutil.out", "", false);
+ assert_same_file("qutil.out", 0, false);
+ assert_same_file("", "qutil.out", false);
+}
+
int main(int argc, char* argv[])
{
try
@@ -155,6 +185,8 @@ int main(int argc, char* argv[])
to_utf8_test();
std::cout << "----" << std::endl;
get_whoami_test();
+ std::cout << "----" << std::endl;
+ same_file_test();
}
catch (std::exception& e)
{