aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-11-25 10:12:08 +0100
committerMartin Ridgers <[email protected]>2021-11-25 10:17:49 +0100
commit3a414555d305d10ec4f7a9dadd9738f7a1dbc0ef (patch)
tree8f471169128bdd314dc9b4155bf139b061a0c802 /zencore/thread.cpp
parentA nullptr terminator ArgV only applies on Linux (diff)
downloadzen-3a414555d305d10ec4f7a9dadd9738f7a1dbc0ef.tar.xz
zen-3a414555d305d10ec4f7a9dadd9738f7a1dbc0ef.zip
Tests for building ArgV for a fork-exec
Diffstat (limited to 'zencore/thread.cpp')
-rw-r--r--zencore/thread.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index 08808e79e..aadb51194 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -1015,6 +1015,57 @@ TEST_CASE("Thread")
CHECK(IsProcessRunning(Pid));
}
+TEST_CASE("BuildArgV")
+{
+ const char* Words[] = { "one", "two", "three", "four", "five" };
+ struct {
+ int WordCount;
+ const char* Input;
+ } Cases[] = {
+ { 0, "" },
+ { 0, " " },
+ { 1, "one" },
+ { 1, " one" },
+ { 1, "one " },
+ { 2, "one two" },
+ { 2, " one two" },
+ { 2, "one two " },
+ { 2, " one two" },
+ { 2, "one two " },
+ { 2, "one two " },
+ { 3, "one two three" },
+ { 3, "\"one\" two \"three\"" },
+ { 5, "one two three four five" },
+ };
+
+ for (const auto& Case : Cases)
+ {
+ std::vector<char*> OutArgs;
+ StringBuilder<64> Mutable;
+ Mutable << Case.Input;
+ BuildArgV(OutArgs, Mutable.Data());
+
+ CHECK_EQ(OutArgs.size(), Case.WordCount);
+
+ for (int i = 0, n = int(OutArgs.size()); i < n; ++i)
+ {
+ const char* Truth = Words[i];
+ size_t TruthLen = strlen(Truth);
+
+ const char* Candidate = OutArgs[i];
+ bool bQuoted = (Candidate[0] == '\"');
+ Candidate += bQuoted;
+
+ CHECK(strncmp(Truth, Candidate, TruthLen) == 0);
+
+ if (bQuoted)
+ {
+ CHECK_EQ(Candidate[TruthLen], '\"');
+ }
+ }
+ }
+}
+
TEST_CASE("ipc")
{
using namespace fmt::literals;