aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
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
parent885b8781cccdc9d4402af58176e826a354b5ef7a (diff)
downloadqpdf-5993c3e83c6f83b36045c75a03ffb1da3d1d283c.tar.zst
Detect input file = output file (fixes #29)
Diffstat (limited to 'libtests')
-rw-r--r--libtests/qtest/qutil/other-file1
-rw-r--r--libtests/qtest/qutil/qutil.out7
-rw-r--r--libtests/qutil.cc32
3 files changed, 40 insertions, 0 deletions
diff --git a/libtests/qtest/qutil/other-file b/libtests/qtest/qutil/other-file
new file mode 100644
index 00000000..9daeafb9
--- /dev/null
+++ b/libtests/qtest/qutil/other-file
@@ -0,0 +1 @@
+test
diff --git a/libtests/qtest/qutil/qutil.out b/libtests/qtest/qutil/qutil.out
index 4273fe11..453185d4 100644
--- a/libtests/qtest/qutil/qutil.out
+++ b/libtests/qtest/qutil/qutil.out
@@ -35,3 +35,10 @@ quack1
quack2
quack3
quack4
+----
+file1: -qutil.out-, file2: -./qutil.out-; same: 1: PASS
+file1: -qutil.out-, file2: -qutil.out-; same: 1: PASS
+file1: -qutil.out-, file2: -other-file-; same: 0: PASS
+file1: -qutil.out-, file2: --; same: 0: PASS
+file1: -qutil.out-, file2: -(null)-; same: 0: PASS
+file1: --, file2: -qutil.out-; same: 0: PASS
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)
{