aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2020-04-04 03:34:45 +0200
committerJay Berkenbilt <ejb@ql.org>2020-04-04 03:39:44 +0200
commit2100b4ce152e9c70b3ce8760112d5a24ead4e52d (patch)
tree0dc298af6870f9635dd4b52b9ec8a528b01e01f6 /libtests
parent6a4117add996eeaaf330bd700e30380295daab93 (diff)
downloadqpdf-2100b4ce152e9c70b3ce8760112d5a24ead4e52d.tar.zst
Allow qpdf to be built on systems without wchar_t (fixes #406)
Diffstat (limited to 'libtests')
-rw-r--r--libtests/build.mk1
-rw-r--r--libtests/main_from_wmain.cc34
-rw-r--r--libtests/qtest/qutil.test18
-rw-r--r--libtests/qtest/qutil/qutil.out4
-rw-r--r--libtests/qtest/qutil/wmain.out3
-rw-r--r--libtests/qutil.cc13
6 files changed, 55 insertions, 18 deletions
diff --git a/libtests/build.mk b/libtests/build.mk
index 8eea8d2d..f039fd65 100644
--- a/libtests/build.mk
+++ b/libtests/build.mk
@@ -13,6 +13,7 @@ BINS_libtests = \
input_source \
json \
lzw \
+ main_from_wmain \
matrix \
md5 \
numrange \
diff --git a/libtests/main_from_wmain.cc b/libtests/main_from_wmain.cc
new file mode 100644
index 00000000..c3e2a716
--- /dev/null
+++ b/libtests/main_from_wmain.cc
@@ -0,0 +1,34 @@
+#include <qpdf/QUtil.hh>
+#include <iostream>
+
+#ifndef QPDF_NO_WCHAR_T
+void wmain_test()
+{
+ auto realmain = [](int argc, char* argv[]) {
+ for (int i = 0; i < argc; ++i) {
+ std::cout << argv[i] << std::endl;
+ } return 0;
+ };
+ wchar_t* argv[3];
+ argv[0] = const_cast<wchar_t*>(L"ascii");
+ argv[1] = const_cast<wchar_t*>(L"10 \xf7 2 = 5");
+ argv[2] = const_cast<wchar_t*>(L"qwww\xf7\x03c0");
+ QUtil::call_main_from_wmain(3, argv, realmain);
+}
+#endif // QPDF_NO_WCHAR_T
+
+int main(int argc, char* argv[])
+{
+#ifndef QPDF_NO_WCHAR_T
+ try
+ {
+ wmain_test();
+ }
+ catch (std::exception& e)
+ {
+ std::cout << "unexpected exception: " << e.what() << std::endl;
+ }
+#endif // QPDF_NO_WCHAR_T
+
+ return 0;
+}
diff --git a/libtests/qtest/qutil.test b/libtests/qtest/qutil.test
index 34b0067c..3487236c 100644
--- a/libtests/qtest/qutil.test
+++ b/libtests/qtest/qutil.test
@@ -15,4 +15,20 @@ $td->runtest("QUtil",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES | $td->RM_WS_ONLY_LINES);
-$td->report(1);
+my $mfw = `main_from_wmain`;
+if ($mfw eq '')
+{
+ $td->runtest("skipping main_from_wmain",
+ {$td->STRING => ""},
+ {$td->STRING => ""})
+}
+else
+{
+ $td->runtest("main_from_wmain",
+ {$td->COMMAND => "main_from_wmain"},
+ {$td->FILE => "wmain.out",
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES | $td->RM_WS_ONLY_LINES);
+}
+
+$td->report(2);
diff --git a/libtests/qtest/qutil/qutil.out b/libtests/qtest/qutil/qutil.out
index 9da8cecf..5fe841ac 100644
--- a/libtests/qtest/qutil/qutil.out
+++ b/libtests/qtest/qutil/qutil.out
@@ -105,7 +105,3 @@ rename file
create file
rename over existing
delete file
----- wmain
-ascii
-10 ÷ 2 = 5
-qwww÷π
diff --git a/libtests/qtest/qutil/wmain.out b/libtests/qtest/qutil/wmain.out
new file mode 100644
index 00000000..261b1c56
--- /dev/null
+++ b/libtests/qtest/qutil/wmain.out
@@ -0,0 +1,3 @@
+ascii
+10 ÷ 2 = 5
+qwww÷π
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index b8429a44..935cdfc2 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -543,17 +543,6 @@ void rename_delete_test()
assert_no_file("old\xcf\x80.~tmp");
}
-void wmain_test()
-{
- auto realmain = [](int argc, char* argv[]) {
- for (int i = 0; i < argc; ++i) { std::cout << argv[i] << std::endl; } return 0; };
- wchar_t* argv[3];
- argv[0] = const_cast<wchar_t*>(L"ascii");
- argv[1] = const_cast<wchar_t*>(L"10 \xf7 2 = 5");
- argv[2] = const_cast<wchar_t*>(L"qwww\xf7\x03c0");
- QUtil::call_main_from_wmain(3, argv, realmain);
-}
-
int main(int argc, char* argv[])
{
try
@@ -584,8 +573,6 @@ int main(int argc, char* argv[])
hex_encode_decode_test();
std::cout << "---- rename/delete" << std::endl;
rename_delete_test();
- std::cout << "---- wmain" << std::endl;
- wmain_test();
}
catch (std::exception& e)
{