2019-06-25 23:37:13 +02:00
|
|
|
#include "test/framework/catch.hpp"
|
|
|
|
#include "src/shellmatta_utils.c"
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-12-05 22:55:28 +01:00
|
|
|
static uint32_t write_callCnt = 0u;
|
|
|
|
static char write_data[20];
|
|
|
|
static uint32_t write_idx;
|
|
|
|
|
|
|
|
static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
2019-06-25 23:37:13 +02:00
|
|
|
{
|
2019-12-05 22:55:28 +01:00
|
|
|
write_callCnt ++;
|
|
|
|
strncpy(&write_data[write_idx], data, length);
|
|
|
|
write_idx += length;
|
2019-06-25 23:37:13 +02:00
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "shellmatta_insertChars normal call" ) {
|
|
|
|
|
|
|
|
shellmatta_instance_t inst;
|
2019-12-05 22:55:28 +01:00
|
|
|
char buffer[20] = "abcdefghij\0\0\0\0\0\0\0\0\0";
|
|
|
|
|
2020-03-16 22:08:06 +01:00
|
|
|
memset(&inst, 0, sizeof(inst));
|
2019-12-05 22:55:28 +01:00
|
|
|
inst.buffer = buffer;
|
|
|
|
inst.bufferSize = 20;
|
|
|
|
inst.cursor = 8;
|
|
|
|
inst.inputCount = 10;
|
|
|
|
inst.echoEnabled = true;
|
|
|
|
|
|
|
|
inst.write = writeFct;
|
|
|
|
|
|
|
|
write_callCnt = 0u;
|
|
|
|
memset(write_data, 0, sizeof(write_data));
|
|
|
|
write_idx = 0u;
|
|
|
|
|
|
|
|
utils_insertChars(&inst, (char*)"blksdflsd kfjlk", 4u);
|
|
|
|
|
|
|
|
CHECK( inst.cursor == 12);
|
|
|
|
CHECK( inst.inputCount == 14);
|
|
|
|
CHECK( write_callCnt == 5u );
|
2020-02-03 20:45:19 +01:00
|
|
|
CHECK( strncmp("blks\x1b[K\x1b[sij\x1b[u", write_data, 15u) == 0);
|
2019-12-05 22:55:28 +01:00
|
|
|
REQUIRE( strncmp("abcdefghblksij\0\0\0\0\0\0\0", buffer, sizeof(buffer)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "shellmatta_insertChars overwrite" ) {
|
|
|
|
|
|
|
|
shellmatta_instance_t inst;
|
|
|
|
char buffer[20] = "abcdefghij\0\0\0\0\0\0\0\0\0";
|
2019-06-25 23:37:13 +02:00
|
|
|
|
2020-03-16 22:08:06 +01:00
|
|
|
memset(&inst, 0, sizeof(inst));
|
2019-06-25 23:37:13 +02:00
|
|
|
inst.buffer = buffer;
|
|
|
|
inst.bufferSize = 20;
|
|
|
|
inst.cursor = 8;
|
|
|
|
inst.inputCount = 10;
|
2019-12-05 22:55:28 +01:00
|
|
|
inst.echoEnabled = true;
|
|
|
|
inst.mode = SHELLMATTA_MODE_OVERWRITE;
|
2019-06-25 23:37:13 +02:00
|
|
|
|
|
|
|
inst.write = writeFct;
|
|
|
|
|
2019-12-05 22:55:28 +01:00
|
|
|
write_callCnt = 0u;
|
|
|
|
memset(write_data, 0, sizeof(write_data));
|
|
|
|
write_idx = 0u;
|
|
|
|
|
|
|
|
utils_insertChars(&inst, (char*)"blksdflsd kfjlk", 4u);
|
2019-06-25 23:37:13 +02:00
|
|
|
|
2019-06-27 22:56:03 +02:00
|
|
|
CHECK( inst.cursor == 12);
|
2020-03-08 19:56:04 +01:00
|
|
|
CHECK( inst.inputCount == 12);
|
2019-12-05 22:55:28 +01:00
|
|
|
CHECK( write_callCnt == 1u );
|
|
|
|
CHECK( strncmp("blks", write_data, 5u) == 0);
|
|
|
|
REQUIRE( strncmp("abcdefghblks\0\0\0\0\0\0\0\0\0", buffer, sizeof(buffer)) == 0);
|
2019-06-25 23:37:13 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 22:55:28 +01:00
|
|
|
TEST_CASE( "shellmatta_insertChars append" ) {
|
|
|
|
|
|
|
|
shellmatta_instance_t inst;
|
|
|
|
char buffer[20] = "abcdefghij\0\0\0\0\0\0\0\0\0";
|
|
|
|
|
2020-03-16 22:08:06 +01:00
|
|
|
memset(&inst, 0, sizeof(inst));
|
2019-12-05 22:55:28 +01:00
|
|
|
inst.buffer = buffer;
|
|
|
|
inst.bufferSize = 20;
|
|
|
|
inst.cursor = 10;
|
|
|
|
inst.inputCount = 10;
|
|
|
|
inst.echoEnabled = true;
|
|
|
|
inst.mode = SHELLMATTA_MODE_INSERT;
|
|
|
|
|
|
|
|
inst.write = writeFct;
|
|
|
|
|
|
|
|
write_callCnt = 0u;
|
|
|
|
memset(write_data, 0, sizeof(write_data));
|
|
|
|
write_idx = 0u;
|
|
|
|
|
|
|
|
utils_insertChars(&inst, (char*)"blksdflsd kfjlk", 4u);
|
|
|
|
|
|
|
|
CHECK( inst.cursor == 14);
|
|
|
|
CHECK( inst.inputCount == 14);
|
|
|
|
CHECK( write_callCnt == 1u );
|
|
|
|
CHECK( strncmp("blks", write_data, 5u) == 0);
|
|
|
|
REQUIRE( strncmp("abcdefghijblks\0\0\0\0\0\0\0", buffer, sizeof(buffer)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "shellmatta_insertChars 0 length" ) {
|
|
|
|
|
|
|
|
shellmatta_instance_t inst;
|
|
|
|
char buffer[20] = "abcdefghij\0\0\0\0\0\0\0\0\0";
|
|
|
|
|
2020-03-16 22:08:06 +01:00
|
|
|
memset(&inst, 0, sizeof(inst));
|
2019-12-05 22:55:28 +01:00
|
|
|
inst.buffer = buffer;
|
|
|
|
inst.bufferSize = 20;
|
|
|
|
inst.cursor = 8;
|
|
|
|
inst.inputCount = 10;
|
|
|
|
inst.echoEnabled = true;
|
|
|
|
|
|
|
|
inst.write = writeFct;
|
|
|
|
|
|
|
|
write_callCnt = 0u;
|
|
|
|
memset(write_data, 0, sizeof(write_data));
|
|
|
|
write_idx = 0u;
|
|
|
|
|
|
|
|
utils_insertChars(&inst, (char*)"blksdflsd kfjlk", 0u);
|
|
|
|
|
|
|
|
CHECK( inst.cursor == 8u );
|
|
|
|
CHECK( inst.inputCount == 10u );
|
|
|
|
CHECK( write_callCnt == 0u );
|
|
|
|
CHECK( memcmp("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", write_data, sizeof(write_data) ) == 0u );
|
|
|
|
REQUIRE( memcmp("abcdefghij\0\0\0\0\0\0\0\0\0", buffer, sizeof(buffer)) == 0);
|
|
|
|
}
|