aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/main_from_wmain.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-01 19:37:31 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-01 19:50:58 +0100
commitb02d37bc0ae0b7af6077637f855be8579c768c22 (patch)
treea1dbfdd033951afcd41e7a7e36dfbaa0dd903776 /libtests/main_from_wmain.cc
parentbc4e2320e7dafea8b6d6b6150c808ed2a98d7d03 (diff)
downloadqpdf-b02d37bc0ae0b7af6077637f855be8579c768c22.tar.zst
Make QPDFArgParser accept const argv
This makes it much more convention to use the initializeFromArgv functions since you can use string literals.
Diffstat (limited to 'libtests/main_from_wmain.cc')
-rw-r--r--libtests/main_from_wmain.cc29
1 files changed, 25 insertions, 4 deletions
diff --git a/libtests/main_from_wmain.cc b/libtests/main_from_wmain.cc
index c3e2a716..6b8a9c05 100644
--- a/libtests/main_from_wmain.cc
+++ b/libtests/main_from_wmain.cc
@@ -4,17 +4,37 @@
#ifndef QPDF_NO_WCHAR_T
void wmain_test()
{
+ // writable args and function args
auto realmain = [](int argc, char* argv[]) {
- for (int i = 0; i < argc; ++i) {
- std::cout << argv[i] << std::endl;
- } return 0;
- };
+ for (int i = 0; i < argc; ++i) {
+ std::cout << argv[i] << std::endl;
+ } return 0;
+ };
wchar_t* argv[3];
+ // This works because call_main_from_wmain doesn't actually write
+ // to the arguments and neither does our function. Otherwise, this
+ // cast would be unsafe.
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);
}
+
+void cwmain_test()
+{
+ // const args and function args
+ auto realmain = [](int argc, char const* const argv[]) {
+ for (int i = 0; i < argc; ++i) {
+ std::cout << "const " << argv[i] << std::endl;
+ } return 0;
+ };
+ wchar_t const* argv[3] = {
+ L"ascii",
+ L"10 \xf7 2 = 5",
+ L"qwww\xf7\x03c0",
+ };
+ QUtil::call_main_from_wmain(3, argv, realmain);
+}
#endif // QPDF_NO_WCHAR_T
int main(int argc, char* argv[])
@@ -23,6 +43,7 @@ int main(int argc, char* argv[])
try
{
wmain_test();
+ cwmain_test();
}
catch (std::exception& e)
{