Ver Fonte

added integration test for heredoc parsing

prozessorkern há 5 anos atrás
pai
commit
33e4e20474
1 ficheiros alterados com 42 adições e 1 exclusões
  1. 42 1
      test/integrationtest/test_integration.cpp

+ 42 - 1
test/integrationtest/test_integration.cpp

@@ -7,6 +7,8 @@ extern "C" {
 static uint32_t write_callCnt = 0u;
 static char write_data[1024];
 static uint32_t write_length;
+static const char *doSomethingArguments;
+static uint32_t doSomethingLength;
 
 static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
 {
@@ -24,7 +26,9 @@ static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
 
 static shellmatta_retCode_t doSomething(shellmatta_handle_t handle, const char *arguments, uint32_t length)
 {
-
+    doSomethingArguments = arguments;
+    doSomethingLength = length;
+    shellmatta_printf(handle, "%s - length: %u", arguments, length);
     return SHELLMATTA_OK;
 }
 shellmatta_cmd_t doSomethingCmd = {"doSomething", "do", "Function does something", "use me, please", doSomething, NULL};
@@ -120,3 +124,40 @@ TEST_CASE( "shellmatta help function" ) {
     REQUIRE( strcmp(dummyData, write_data) == 0);
 }
 
+
+
+TEST_CASE( "shellmatta heredoc test" ) {
+
+    shellmatta_instance_t inst;
+    shellmatta_handle_t handle;
+    char buffer[1024];
+    char historyBuffer[1024];
+    char *dummyData =   "do this \r\n"
+                        "asdf\r\n"
+                        "1234";
+
+    shellmatta_doInit(  &inst,
+                        &handle,
+                        buffer,
+                        sizeof(buffer),
+                        historyBuffer,
+                        sizeof(historyBuffer),
+                        "shellmatta->",
+                        NULL,
+                        writeFct);
+    shellmatta_addCmd(handle, &doSomethingCmd);
+
+    doSomethingArguments = NULL;
+    doSomethingLength = 0u;
+
+    shellmatta_processData(handle, "do this << EOF\r\n"
+                                    "asdf\r\n"
+                                    "1234\r\n"
+                                    "EOF\r\n"
+                                , 34);
+
+
+
+    CHECK( doSomethingLength == 20u);
+    REQUIRE( strcmp(dummyData, doSomethingArguments) == 0);
+}