You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ts...@apache.org on 2020/02/10 09:04:13 UTC
[logging-log4cxx] 06/07: Implement fail-fast,
to make the "if" easier to read. Things might get outsourced into
functions this way easier as well.
This is an automated email from the ASF dual-hosted git repository.
tschoening pushed a commit to branch ghpr_14_replace-ant-build-with-cmake
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit e8fe4890beee121adbd1a78969f792af4b0ad747
Author: Thorsten Schöning <ts...@am-soft.de>
AuthorDate: Mon Feb 10 09:43:28 2020 +0100
Implement fail-fast, to make the "if" easier to read. Things might get outsourced into functions this way easier as well.
---
src/test/cpp/net/socketserverstarter.cpp | 117 ++++++++++++++++---------------
1 file changed, 60 insertions(+), 57 deletions(-)
diff --git a/src/test/cpp/net/socketserverstarter.cpp b/src/test/cpp/net/socketserverstarter.cpp
index a8c2ae0..32257ed 100644
--- a/src/test/cpp/net/socketserverstarter.cpp
+++ b/src/test/cpp/net/socketserverstarter.cpp
@@ -67,95 +67,98 @@ public:
if (stat != APR_SUCCESS)
LOGUNIT_FAIL("apr_procattr_cmdtype_set failed");
+ if (!(cmd && *cmd) && !(param_file && *param_file))
+ {
+ fputs("Either:\n", stderr);
+ fputs(" The environment variable SOCKET_SERVER_COMMAND"
+ " must contain the server process path"
+ " followed by space separated command arguments\n", stderr);
+ fputs("Or:\n", stderr);
+ fputs(" The file named in the environment variable SOCKET_SERVER_PARAMETER_FILE"
+ " must contain a line per argument starting with the server process path"
+ " followed by lines containing command arguments\n", stderr);
+ LOGUNIT_FAIL("Neither SOCKET_SERVER_COMMAND nor SOCKET_SERVER_PARAMETER_FILE available.");
+ }
+
if (cmd && *cmd)
{
- // convert the space separated cmd string to the argument list
- //
- static const int MaxArgumentCount = 14;
- char** argv = (char**)apr_palloc(pool, (MaxArgumentCount + 1) * sizeof(*argv));
- char* pcmd = apr_pstrdup(pool, cmd);
- int i = 0;
- for (; i < MaxArgumentCount && pcmd && *pcmd; ++i)
- {
- char separ = ' ';
- while(separ == *pcmd)
- {
- *pcmd = 0;
- ++pcmd;
- }
- if ('"' == *pcmd || '\'' == *pcmd)
- {
+ // convert the space separated cmd string to the argument list
+ //
+ static const int MaxArgumentCount = 14;
+ char** argv = (char**)apr_palloc(pool, (MaxArgumentCount + 1) * sizeof(*argv));
+ char* pcmd = apr_pstrdup(pool, cmd);
+ int i = 0;
+ for (; i < MaxArgumentCount && pcmd && *pcmd; ++i)
+ {
+ char separ = ' ';
+ while(separ == *pcmd)
+ {
+ *pcmd = 0;
+ ++pcmd;
+ }
+ if ('"' == *pcmd || '\'' == *pcmd)
+ {
separ = *pcmd;
++pcmd;
- }
- argv[i] = pcmd;
- if (NULL != (pcmd = strchr(pcmd, separ)))
- {
- *pcmd = 0;
- ++pcmd;
- while(' ' == *pcmd)
- {
- *pcmd = 0;
- ++pcmd;
- }
- }
+ }
+ argv[i] = pcmd;
+ if (NULL != (pcmd = strchr(pcmd, separ)))
+ {
+ *pcmd = 0;
+ ++pcmd;
+ while(' ' == *pcmd)
+ {
+ *pcmd = 0;
+ ++pcmd;
+ }
+ }
}
argv[i] = 0;
stat = apr_proc_create(&server_pid, argv[0], argv, NULL, attr, pool);
-
if (stat == APR_SUCCESS) // Allow server time to load
apr_sleep(1000000); // 1 seconds
else
fprintf(stderr, "apr_proc_create failed to start %s\n", argv[0]);
}
- else if (param_file && *param_file)
+
+ if (param_file && *param_file)
{
- // Build the argument list from param_file
- //
- //fprintf(stderr, "Processing: %s\n", param_file);
- std::ifstream in(param_file);
- std::vector<std::string> params;
- while (in)
- {
- params.push_back(std::string());
- std::string& line = params.back();
- std::getline(in, line);
- while (!line.empty() && (' ' == line[0] || '\t' == line[0]))
+ // Build the argument list from param_file
+ //
+ //fprintf(stderr, "Processing: %s\n", param_file);
+ std::ifstream in(param_file);
+ std::vector<std::string> params;
+ while (in)
+ {
+ params.push_back(std::string());
+ std::string& line = params.back();
+ std::getline(in, line);
+ while (!line.empty() && (' ' == line[0] || '\t' == line[0]))
line.erase(0, 1);
- while (!line.empty() && (' ' == line[line.size() - 1] || '\t' == line[line.size() - 1]))
+ while (!line.empty() && (' ' == line[line.size() - 1] || '\t' == line[line.size() - 1]))
line.erase(line.size() - 1, 1);
- if (line.empty())
- params.pop_back();
+ if (line.empty())
+ params.pop_back();
}
+
const char** argv = (const char**)apr_palloc(pool, (params.size() + 1) * sizeof(*argv));
int i = 0;
+
for (; i < params.size(); ++i)
{
argv[i] = params[i].c_str();
//fprintf(stderr, "argv[%i]: %s\n", i, argv[i]);
}
+
argv[i] = 0;
stat = apr_proc_create(&server_pid, argv[0], argv, NULL, attr, pool);
-
if (stat == APR_SUCCESS) // Allow server time to load
apr_sleep(1000000); // 1 seconds
else
fprintf(stderr, "apr_proc_create failed to start %s\n", argv[0]);
}
- else
- {
- fputs("Either:\n", stderr);
- fputs(" The environment variable SOCKET_SERVER_COMMAND"
- " must contain the server process path"
- " followed by space separated command arguments\n", stderr);
- fputs("Or:\n", stderr);
- fputs(" The file named in the environment variable SOCKET_SERVER_PARAMETER_FILE"
- " must contain a line per argument starting with the server process path"
- " followed by lines containing command arguments\n", stderr);
- stat = -1;
- }
LOGUNIT_ASSERT(stat == APR_SUCCESS);
}