diff options
author | Ivan Zhakov <ivan@apache.org> | 2024-09-23 09:54:22 +0000 |
---|---|---|
committer | Ivan Zhakov <ivan@apache.org> | 2024-09-23 09:54:22 +0000 |
commit | 16d7aaf1fcf58fb8a083d4ac4bf0251b642f898b (patch) | |
tree | 09df1fb2864c12229873e03db6009ab8083139f8 | |
parent | 27b0370222bbeea6443ace8557a4d8779cc9cdbd (diff) | |
download | apr-16d7aaf1fcf58fb8a083d4ac4bf0251b642f898b.tar.gz apr-16d7aaf1fcf58fb8a083d4ac4bf0251b642f898b.zip |
Add basic tests for apr_proc_create() for Windows batch files.
* CMakeLists.txt: Copy echoargs.bat to build dir.
* test/echoargs.bat: Windows batch file that just prints passed arguments.
* test/testproc.c:
(test_proc_args_winbatch): New test.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1920854 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | test/echoargs.bat | 10 | ||||
-rw-r--r-- | test/testproc.c | 73 |
3 files changed, 87 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ab211b2c7..57109a0da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -605,6 +605,10 @@ IF(APR_BUILD_TESTAPR) ${PROJECT_SOURCE_DIR}/test/data/mmap_large_datafile.txt ${PROJECT_BINARY_DIR}/data/mmap_large_datafile.txt) + EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${PROJECT_SOURCE_DIR}/test/echoargs.bat + ${PROJECT_BINARY_DIR}/echoargs.bat) + ADD_EXECUTABLE(testapp test/testapp.c) TARGET_LINK_LIBRARIES(testapp ${apr_libname} libaprapp-2) SET_TARGET_PROPERTIES(testapp PROPERTIES LINK_FLAGS /entry:wmainCRTStartup) diff --git a/test/echoargs.bat b/test/echoargs.bat new file mode 100644 index 000000000..953281ef7 --- /dev/null +++ b/test/echoargs.bat @@ -0,0 +1,10 @@ +@echo off
+echo 1: [%1]
+echo 2: [%2]
+echo 3: [%3]
+echo 4: [%4]
+echo 5: [%5]
+echo 6: [%6]
+echo 7: [%7]
+echo 8: [%8]
+echo 9: [%9]
diff --git a/test/testproc.c b/test/testproc.c index 80f719546..57bb7bee1 100644 --- a/test/testproc.c +++ b/test/testproc.c @@ -230,6 +230,76 @@ static void test_proc_args(abts_case* tc, void* data) ABTS_STR_EQUAL(tc, expected, actual); } +static void test_proc_args_winbatch(abts_case* tc, void* data) +{ + const char* args[10]; + apr_procattr_t* attr; + apr_status_t rv; + char *progname; + const char *expected; + const char *actual; + + apr_filepath_merge(&progname, NULL, "echoargs.bat", 0, p); + + rv = apr_procattr_create(&attr, p); + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + + rv = apr_procattr_io_set(attr, APR_NO_PIPE, APR_FULL_BLOCK, APR_NO_PIPE); + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + + rv = apr_procattr_cmdtype_set(attr, APR_PROGRAM_ENV); + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + + args[0] = progname; + args[1] = "arg1"; + args[2] = "arg2"; + args[3] = "arg3"; + args[4] = "arg4"; + args[5] = "arg5"; + args[6] = "arg6"; + args[7] = "arg7"; + args[8] = "arg8"; + args[9] = NULL; + + rv = apr_proc_create(&newproc, progname, args, NULL, attr, p); + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + + actual = ""; + while (1) + { + char buf[1024]; + apr_size_t length = sizeof(buf); + + rv = apr_file_read(newproc.out, buf, &length); + if (APR_STATUS_IS_EOF(rv)) { + break; + } + else if (rv != APR_SUCCESS) + { + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + break; + } + + buf[length] = 0; + actual = apr_pstrcat(p, actual, buf, NULL); + } + + abts_log_message("Invoked command line: %s\n", newproc.invoked); + + expected = + "1: [arg1]" "\r\n" + "2: [arg2]" "\r\n" + "3: [arg3]" "\r\n" + "4: [arg4]" "\r\n" + "5: [arg5]" "\r\n" + "6: [arg6]" "\r\n" + "7: [arg7]" "\r\n" + "8: [arg8]" "\r\n" + "9: []" "\r\n"; + + ABTS_STR_EQUAL(tc, expected, actual); +} + abts_suite *testproc(abts_suite *suite) { suite = ADD_SUITE(suite) @@ -239,6 +309,9 @@ abts_suite *testproc(abts_suite *suite) abts_run_test(suite, test_proc_wait, NULL); abts_run_test(suite, test_file_redir, NULL); abts_run_test(suite, test_proc_args, NULL); +#ifdef WIN32 + abts_run_test(suite, test_proc_args_winbatch, NULL); +#endif return suite; } |