diff options
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 51 |
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; |