2019-12-05 22:55:28 +01:00
|
|
|
#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_idx;
|
|
|
|
|
|
|
|
static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
|
|
|
{
|
|
|
|
write_callCnt ++;
|
2020-03-01 17:53:27 +01:00
|
|
|
memcpy(&write_data[write_idx], data, length);
|
2019-12-05 22:55:28 +01:00
|
|
|
write_idx += length;
|
|
|
|
return SHELLMATTA_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE( "shellmatta_utils_terminateInput" ) {
|
|
|
|
|
|
|
|
shellmatta_instance_t inst;
|
|
|
|
char buffer[20];
|
|
|
|
|
|
|
|
inst.buffer = buffer;
|
|
|
|
inst.bufferSize = 20;
|
|
|
|
inst.cursor = 10;
|
|
|
|
inst.inputCount = 10;
|
|
|
|
inst.echoEnabled = true;
|
|
|
|
inst.prompt = "->";
|
|
|
|
|
|
|
|
inst.write = writeFct;
|
|
|
|
|
|
|
|
write_callCnt = 0u;
|
|
|
|
memset(write_data, 0, sizeof(write_data));
|
|
|
|
write_idx = 0u;
|
|
|
|
|
|
|
|
utils_terminateInput(&inst);
|
|
|
|
|
|
|
|
CHECK( inst.cursor == 0u );
|
|
|
|
CHECK( inst.inputCount == 0u );
|
|
|
|
CHECK( write_callCnt == 2u );
|
|
|
|
CHECK( write_idx == 4u );
|
|
|
|
REQUIRE( strncmp("\r\n->", write_data, 4u) == 0);
|
|
|
|
}
|