Bläddra i källkod

fixed transport search function - added test

stefan 9 månader sedan
förälder
incheckning
d613984e9d

+ 9 - 7
src/shellmatta_transport.c

@@ -67,30 +67,32 @@ static bool shellmatta_transport_search(shellmatta_transport_layer_t *transportL
                                                         shellmatta_transport_packet_t *packet)
 {
     bool match = true;
+    bool sure = false;
     uint32_t i;
     uint8_t *uuid1;
     uint8_t *uuid2;
 
-    /** -# check packet length */
-    if(SHELLMATTA_TRANPORT_UUID_LENGTH != packet->header.payloadLength)
-    {
-        return false;
-    }
-
     uuid1 = (uint8_t *)&packet->payload[0u];
     uuid2 = (uint8_t *)&packet->payload[SHELLMATTA_TRANPORT_UUID_LENGTH];
 
     /** -# compare UUID with range */
     for(i = 0u; i < (SHELLMATTA_TRANPORT_UUID_LENGTH - 1u); i ++)
     {
+        /** -# stop match if we are outside of the range with the current digit */
         if((transportLayer->uuid[i] < uuid1[i]) || (transportLayer->uuid[i] > uuid2[i]))
         {
             match = false;
         }
+        /** -# stop comparison when we are definitely in the range (lower than the top limit and inside) */
+        else if(transportLayer->uuid[i] < uuid2[i])
+        {
+            sure = true;
+            break;
+        }
     }
 
     /** -# explicitly check lowest digit - this is not inclusive to the lower limit */
-    if((transportLayer->uuid[i] <= uuid1[i]) || (transportLayer->uuid[i] > uuid2[i]))
+    if((false == sure) && ((transportLayer->uuid[i] <= uuid1[i]) || (transportLayer->uuid[i] > uuid2[i])))
     {
         match = false;
     }

+ 66 - 0
test/integrationtest_transport/test_integration_transport.cpp

@@ -438,3 +438,69 @@ SCENARIO("Integration test of Transport layer - reset transport layer", "[integr
         }
     }
 }
+
+SCENARIO("Integration test of Transport layer - addressing", "[integration, transport]")
+{
+    GIVEN("Shellmatta up and running with one command - transport layer with UUID")
+    {
+        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);
+
+        ret = shellmatta_transport_configure(handle, true, false, (uint8_t *)"123456789012345", NULL);
+        CHECK(ret == SHELLMATTA_OK);
+
+        write_callCnt = 0u;
+        memset(write_data, 0, sizeof(write_data));
+        write_length = 0u;
+
+        WHEN("The shellmatta is searched using an invalid range") {
+            ret = shellmatta_transport_configure(handle, true, false, NULL, NULL);
+
+            /* check with valid payload - disable echo to reduce cluttering */
+            shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+            shellmatta_processData(handle, (char*)"\x01\x01\x03\x20\x00\x00\x00\x00"
+                                                    "234567890123456\0"
+                                                    "345678901234567\0"
+                                                    "\x93\x0c\xc3\x04", 44u);
+
+            THEN("The shellmatta does not respond")
+            {
+                CHECK(write_length == 0);
+                CHECK(inst.transportLayer.sequenceH2S == 1);
+                REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_WAIT);
+            }
+        }
+
+        WHEN("The shellmatta is searched using a valid range") {
+            ret = shellmatta_transport_configure(handle, true, false, NULL, NULL);
+
+            /* check with valid payload - disable echo to reduce cluttering */
+            shellmatta_configure(handle, SHELLMATTA_MODE_INSERT, false, '\r');
+            shellmatta_processData(handle, (char*)"\x01\x01\x03\x20\x00\x00\x00\x00"
+                                                    "123456789012344\0"
+                                                    "345678901234567\0"
+                                                    "\x9b\x69\x59\x5f", 44u);
+
+            THEN("The shellmatta does not respond")
+            {
+                CHECK(write_length == 28);
+                CHECK(inst.transportLayer.sequenceH2S == 1);
+                REQUIRE(inst.transportLayer.state == SHELLMATTA_TRANSPORT_STATE_WAIT);
+            }
+        }
+    }
+}