svn commit: r1920854 - in /apr/apr/trunk: CMakeLists.txt test/echoargs.bat test/testproc.c
[email protected] Mon, 23 Sep 2024 09:54:22 -0000
Newsgroups
gmane.comp.apache.apr.cvs
Message-ID
<[email protected] >
Author: ivan
Date: Mon Sep 23 09:54:22 2024
New Revision: 1920854
URL: http://svn.apache.org/viewvc?rev=1920854&view=rev
Log:
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.
Added:
apr/apr/trunk/test/echoargs.bat
Modified:
apr/apr/trunk/CMakeLists.txt
apr/apr/trunk/test/testproc.c
Modified: apr/apr/trunk/CMakeLists.txt
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CMakeLists.txt?rev=1920854&r1=1920853&r2=1920854&view=diff
==============================================================================
--- apr/apr/trunk/CMakeLists.txt (original)
+++ apr/apr/trunk/CMakeLists.txt Mon Sep 23 09:54:22 2024
@@ -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)
Added: apr/apr/trunk/test/echoargs.bat
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/echoargs.bat?rev=1920854&view=auto
==============================================================================
--- apr/apr/trunk/test/echoargs.bat (added)
+++ apr/apr/trunk/test/echoargs.bat Mon Sep 23 09:54:22 2024
@@ -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]
Modified: apr/apr/trunk/test/testproc.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testproc.c?rev=1920854&r1=1920853&r2=1920854&view=diff
==============================================================================
--- apr/apr/trunk/test/testproc.c (original)
+++ apr/apr/trunk/test/testproc.c Mon Sep 23 09:54:22 2024
@@ -230,6 +230,76 @@ static void test_proc_args(abts_case* tc
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;
}