42 lines
916 B
C++
42 lines
916 B
C++
|
#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_restoreCursorPos" ) {
|
||
|
|
||
|
shellmatta_instance_t inst;
|
||
|
char buffer[20];
|
||
|
char dummyData[29];
|
||
|
|
||
|
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_restoreCursorPos(&inst);
|
||
|
|
||
|
CHECK( write_callCnt == 1u);
|
||
|
CHECK( write_length == 3u);
|
||
|
REQUIRE( strncmp("\e[u", write_data, 3u) == 0);
|
||
|
}
|