Ver código fonte

added test cases for transport layer

Strobel, Stefan | Friedrich Lütze GmbH 1 ano atrás
pai
commit
39ab206bb2

+ 21 - 0
.vscode/launch.json

@@ -87,6 +87,27 @@
             ],
             "preLaunchTask": "make integrationtest_auth",
             "miDebuggerPath": "/usr/bin/gdb"
+        },
+        {
+            "name": "debug integrationtest_transport",
+            "type": "cppdbg",
+            "request": "launch",
+            "program": "${workspaceFolder}/output/test/integrationtest_transport/integrationtest_transport",
+            "args": [],
+            "stopAtEntry": false,
+            "cwd": "${workspaceFolder}",
+            "environment": [],
+            "externalConsole": false,
+            "MIMode": "gdb",
+            "setupCommands": [
+                {
+                    "description": "Enable pretty-printing for gdb",
+                    "text": "-enable-pretty-printing",
+                    "ignoreFailures": true
+                }
+            ],
+            "preLaunchTask": "make integrationtest_transport",
+            "miDebuggerPath": "/usr/bin/gdb"
         }
     ]
 }

+ 7 - 0
.vscode/settings.json

@@ -0,0 +1,7 @@
+{
+    "files.associations": {
+        "sstream": "cpp",
+        "regex": "cpp"
+    },
+    "C_Cpp.default.defines": ["SHELLMATTA_AUTH", "SHELLMATTA_TRANSPORT_ENABLE"]
+}

+ 8 - 0
.vscode/tasks.json

@@ -46,6 +46,14 @@
                 "$gcc"
             ]
         },
+        {
+            "label": "make integrationtest_transport",
+            "type": "shell",
+            "command": "make integrationtest_transport",
+            "problemMatcher": [
+                "$gcc"
+            ]
+        },
         {
             "label": "make test",
             "type": "shell",

+ 113 - 0
test/integrationtest_transport/test_integration_transport.cpp

@@ -327,3 +327,116 @@ SCENARIO("Integration test of Transport layer", "[integration, transport]")
         }
     }
 }
+
+SCENARIO("Integration test of Transport layer with mandatory transport layer", "[integration, transport]")
+{
+    GIVEN("Shellmatta up and running with one command")
+    {
+        shellmatta_instance_t inst;
+        shellmatta_handle_t handle;
+        shellmatta_retCode_t ret;
+        char buffer[1024];
+        char historyBuffer[1024];
+
+        shellmatta_doInit(  &inst,
+                            &handle,
+                            buffer,
+                            sizeof(buffer),
+                            historyBuffer,
+                            sizeof(historyBuffer),
+                            "shellmatta->",
+                            NULL,
+                            writeFct);
+        shellmatta_addCmd(handle, &doSomethingCmd);
+
+        write_callCnt = 0u;
+        memset(write_data, 0, sizeof(write_data));
+        write_length = 0u;
+
+        WHEN("The tansport layer is set to mandatory") {
+            ret = shellmatta_transport_configure(handle, true, false, NULL);
+            CHECK(ret == SHELLMATTA_OK);
+
+            AND_WHEN("manual mode is used after transport layer mode")
+            {
+                /* check with valid payload - disable echo to reduce cluttering */
+                shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+                shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                    "doSomething argument\r\n"
+                                                    "\x7b\x49\xfa\x72", 34u);
+                shellmatta_processData(handle, (char*)"doSomething argument\r\n", 22u);
+                THEN("The shellmatta responds only to the first command - and waits for a new telegram to start")
+                {
+                    char *dummyData =   (char*)"\x01\x01\x00\x2f\x00\x00\x01\x01"
+                                            "doSomething argument - length: 20"
+                                            "\r\n"
+                                            "shellmatta->"
+                                            "\xc8\xae\xc0\x56";
+
+                    CHECK(write_length == 59);
+                    CHECK(memcmp(write_data, dummyData, write_length) == 0);
+                    REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_WAIT);
+                }
+            }
+        }
+    }
+}
+
+SCENARIO("Integration test of Transport layer - reset transport layer", "[integration, transport]")
+{
+    GIVEN("Shellmatta up and running with one command")
+    {
+        shellmatta_instance_t inst;
+        shellmatta_handle_t handle;
+        shellmatta_retCode_t ret;
+        char buffer[1024];
+        char historyBuffer[1024];
+
+        shellmatta_doInit(  &inst,
+                            &handle,
+                            buffer,
+                            sizeof(buffer),
+                            historyBuffer,
+                            sizeof(historyBuffer),
+                            "shellmatta->",
+                            NULL,
+                            writeFct);
+        shellmatta_addCmd(handle, &doSomethingCmd);
+
+        write_callCnt = 0u;
+        memset(write_data, 0, sizeof(write_data));
+        write_length = 0u;
+
+        WHEN("The tansport layer is set to mandatory") {
+            ret = shellmatta_transport_configure(handle, true, false, NULL);
+            CHECK(ret == SHELLMATTA_OK);
+
+            AND_WHEN("A partial telegram is passed")
+            {
+                /* check with valid payload - disable echo to reduce cluttering */
+                shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+                shellmatta_processData(handle, (char*)"\x01\x01\x00\x16\x00\x00\x00\x00"
+                                                    "doSomething argument", 28u);
+                THEN("The transport layer is in state SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD")
+                {
+                    CHECK(write_length == 0);
+                    CHECK_THAT(inst.transportLayer.inPacket.payload, Catch::Matchers::Equals("doSomething argument"));
+                    REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_GET_PAYLOAD);
+
+                    AND_WHEN("The transport layer is resetted")
+                    {
+                        ret = shellmatta_transport_reset(handle);
+                        CHECK(ret == SHELLMATTA_OK);
+
+                        THEN("The transport layer is in state wait again and no payload is set") {
+                            CHECK(write_length == 0);
+                            CHECK(inst.transportLayer.inPacket.payload[0] == '\0');
+                            REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_WAIT);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+