diff options
Diffstat (limited to 'tools/slang-unit-test/unit-test-process.cpp')
| -rw-r--r-- | tools/slang-unit-test/unit-test-process.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tools/slang-unit-test/unit-test-process.cpp b/tools/slang-unit-test/unit-test-process.cpp index 3dccf1eaf..8a55b0b29 100644 --- a/tools/slang-unit-test/unit-test-process.cpp +++ b/tools/slang-unit-test/unit-test-process.cpp @@ -3,11 +3,75 @@ #include "../../source/core/slang-string-util.h" #include "../../source/core/slang-process-util.h" #include "../../source/core/slang-io.h" +#include "../../source/core/slang-http.h" +#include "../../source/core/slang-random-generator.h" #include "tools/unit-test/slang-unit-test.h" using namespace Slang; +static SlangResult _httpReflectTest(UnitTestContext* context) +{ + SlangResult finalRes = SLANG_OK; + + RefPtr<Process> process; + + { + CommandLine cmdLine; + cmdLine.setExecutable(context->executableDirectory, "test-proxy"); + cmdLine.addArg("http-reflect"); + SLANG_RETURN_ON_FAIL(Process::create(cmdLine, Process::Flag::AttachDebugger, process)); + } + + Stream* writeStream = process->getStream(Process::StreamType::StdIn); + RefPtr<BufferedReadStream> readStream( new BufferedReadStream(process->getStream(Process::StreamType::StdOut))); + + RefPtr<HTTPPacketConnection> connection = new HTTPPacketConnection(readStream, writeStream); + + RefPtr<RandomGenerator> rand = RandomGenerator::create(10000); + + for (Index i = 0; i < 100; i++) + { + if (process->isTerminated()) + { + return SLANG_FAIL; + } + + const Index size = Index(rand->nextInt32UpTo(8192)); + + List<Byte> buf; + buf.setCount(size); + // Build up a buffer + rand->nextData(buf.getBuffer(), size_t(size)); + + // Write the data + SLANG_RETURN_ON_FAIL(connection->write(buf.getBuffer(), size_t(size))); + + // Wait for the response + SLANG_RETURN_ON_FAIL(connection->waitForContent()); + + auto readContent = connection->getContent(); + + if (readContent != buf.getArrayView()) + { + finalRes = SLANG_FAIL; + break; + } + + // Consume that packet + connection->consumeContent(); + } + + // Send the end + { + const char end[] = "end"; + SLANG_RETURN_ON_FAIL(connection->write(end, SLANG_COUNT_OF(end) - 1)); + } + + process->waitForTermination(); + return finalRes; +} + static SlangResult _countTest(UnitTestContext* context, Index size, Index crashIndex = -1) { RefPtr<Process> process; @@ -122,4 +186,6 @@ SLANG_UNIT_TEST(CommandLineProcess) SLANG_CHECK(SLANG_SUCCEEDED(_countTests(unitTestContext))); SLANG_CHECK(SLANG_SUCCEEDED(_reflectTest(unitTestContext))); + + SLANG_CHECK(SLANG_SUCCEEDED(_httpReflectTest(unitTestContext))); } |
