123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #include "test/framework/catch.hpp"
- #include "src/shellmatta_utils.c"
- #include <string.h>
- static uint32_t write_callCnt = 0u;
- static char write_data[10];
- static uint32_t write_length;
- static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
- {
- write_callCnt ++;
- strncpy(write_data, data, length);
- write_length = length;
- return SHELLMATTA_OK;
- }
- TEST_CASE( "shellmatta_utils_forwardCursor normal" ) {
- shellmatta_instance_t inst;
- char buffer[20];
- inst.buffer = buffer;
- inst.bufferSize = 20;
- inst.cursor = 10;
- inst.inputCount = 20;
- inst.echoEnabled = true;
- inst.write = writeFct;
- write_callCnt = 0u;
- memset(write_data, 0, sizeof(write_data));
- write_length = 0u;
- utils_forwardCursor(&inst, 5u);
- CHECK( write_callCnt == 1u);
- CHECK( write_length == 4u);
- REQUIRE( strncmp("\x1b[5C", write_data, 4u) == 0);
- }
- TEST_CASE( "shellmatta_utils_forwardCursor normal echo off" ) {
- shellmatta_instance_t inst;
- char buffer[20];
- inst.buffer = buffer;
- inst.bufferSize = 20;
- inst.cursor = 10;
- inst.inputCount = 20;
- inst.echoEnabled = false;
- inst.write = writeFct;
- write_callCnt = 0u;
- memset(write_data, 0, sizeof(write_data));
- write_length = 0u;
- utils_forwardCursor(&inst, 5u);
- CHECK( write_callCnt == 0u);
- CHECK( write_length == 0u);
- REQUIRE( strncmp("\0\0\0\0", write_data, 4u) == 0);
- }
- TEST_CASE( "shellmatta_utils_forwardCursor forward by 12 with cursor at 5 and input count at 10" ) {
- shellmatta_instance_t inst;
- char buffer[20];
- inst.buffer = buffer;
- inst.bufferSize = 20;
- inst.cursor = 5;
- inst.inputCount = 10;
- inst.echoEnabled = true;
- inst.write = writeFct;
- write_callCnt = 0u;
- memset(write_data, 0, sizeof(write_data));
- write_length = 0u;
- utils_forwardCursor(&inst, 12u);
- CHECK( write_callCnt == 1u);
- CHECK( write_length == 4u);
- REQUIRE( strncmp("\x1b[5C", write_data, 4u) == 0);
- }
- TEST_CASE( "shellmatta_utils_forwardCursor forward by 0" ) {
- shellmatta_instance_t inst;
- char buffer[20];
- inst.buffer = buffer;
- inst.bufferSize = 20;
- inst.cursor = 10;
- inst.inputCount = 10;
- inst.echoEnabled = true;
- inst.write = writeFct;
- write_callCnt = 0u;
- memset(write_data, 0, sizeof(write_data));
- write_length = 0u;
- utils_forwardCursor(&inst, 0u);
- CHECK( write_callCnt == 0u);
- CHECK( write_length == 0u);
- REQUIRE( strncmp("\0\0\0\0\0", write_data, 4u) == 0);
- }
|