added some integration tests
to test the integrated shellmatta using only the external api
This commit is contained in:
26
test/unittest/shellmatta_utils/test_utils_clearInput.cpp
Normal file
26
test/unittest/shellmatta_utils/test_utils_clearInput.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "test/framework/catch.hpp"
|
||||
#include "src/shellmatta_utils.c"
|
||||
#include <string.h>
|
||||
|
||||
shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
||||
{
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_clearInput normal call" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
char buffer[20];
|
||||
|
||||
inst.buffer = buffer;
|
||||
inst.bufferSize = 20;
|
||||
inst.cursor = 10;
|
||||
inst.inputCount = 10;
|
||||
|
||||
inst.write = writeFct;
|
||||
|
||||
utils_clearInput(&inst);
|
||||
|
||||
CHECK( inst.cursor == 0);
|
||||
REQUIRE( inst.inputCount == 0);
|
||||
}
|
41
test/unittest/shellmatta_utils/test_utils_eraseLine.cpp
Normal file
41
test/unittest/shellmatta_utils/test_utils_eraseLine.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#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_eraseLine" ) {
|
||||
|
||||
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_eraseLine(&inst);
|
||||
|
||||
CHECK( write_callCnt == 1u);
|
||||
CHECK( write_length == 3u);
|
||||
REQUIRE( strncmp("\e[K", write_data, 3u) == 0);
|
||||
}
|
117
test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp
Normal file
117
test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
#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];
|
||||
char dummyData[29];
|
||||
|
||||
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("\e[5C", write_data, 4u) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils_forwardCursor normal echo off" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
char buffer[20];
|
||||
char dummyData[29];
|
||||
|
||||
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];
|
||||
char dummyData[29];
|
||||
|
||||
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("\e[5C", write_data, 4u) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils_forwardCursor forward by 0" ) {
|
||||
|
||||
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_forwardCursor(&inst, 0u);
|
||||
|
||||
CHECK( write_callCnt == 0u);
|
||||
CHECK( write_length == 0u);
|
||||
REQUIRE( strncmp("\0\0\0\0\0", write_data, 4u) == 0);
|
||||
}
|
27
test/unittest/shellmatta_utils/test_utils_insertChars.cpp
Normal file
27
test/unittest/shellmatta_utils/test_utils_insertChars.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "test/framework/catch.hpp"
|
||||
#include "src/shellmatta_utils.c"
|
||||
#include <string.h>
|
||||
|
||||
shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
||||
{
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_insertChars normal call" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
char buffer[20];
|
||||
|
||||
inst.buffer = buffer;
|
||||
inst.bufferSize = 20;
|
||||
inst.cursor = 8;
|
||||
inst.inputCount = 10;
|
||||
|
||||
inst.write = writeFct;
|
||||
|
||||
utils_insertChars(&inst, "blksdflsd kfjlk", 4);
|
||||
|
||||
CHECK( inst.cursor == 12);
|
||||
REQUIRE( inst.inputCount == 14);
|
||||
}
|
||||
|
@@ -0,0 +1,41 @@
|
||||
#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);
|
||||
}
|
92
test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp
Normal file
92
test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#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_rewindCursor normal" ) {
|
||||
|
||||
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_rewindCursor(&inst, 5u);
|
||||
|
||||
CHECK( write_callCnt == 1u);
|
||||
CHECK( write_length == 4u);
|
||||
REQUIRE( strncmp("\e[5D", write_data, 4u) == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE( "shellmatta_utils_rewindCursor rewind by 12 with cursor at 10" ) {
|
||||
|
||||
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_rewindCursor(&inst, 12u);
|
||||
|
||||
CHECK( write_callCnt == 1u);
|
||||
CHECK( write_length == 5u);
|
||||
REQUIRE( strncmp("\e[10D", write_data, 5u) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils_rewindCursor rewind by 0" ) {
|
||||
|
||||
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_rewindCursor(&inst, 0u);
|
||||
|
||||
CHECK( write_callCnt == 0u);
|
||||
CHECK( write_length == 0u);
|
||||
REQUIRE( strncmp("\0\0\0\0\0", write_data, 4u) == 0);
|
||||
}
|
41
test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp
Normal file
41
test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#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_saveCursorPos" ) {
|
||||
|
||||
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_saveCursorPos(&inst);
|
||||
|
||||
CHECK( write_callCnt == 1u);
|
||||
CHECK( write_length == 3u);
|
||||
REQUIRE( strncmp("\e[s", write_data, 3u) == 0);
|
||||
}
|
52
test/unittest/shellmatta_utils/test_utils_shellItoa.cpp
Normal file
52
test/unittest/shellmatta_utils/test_utils_shellItoa.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "test/framework/catch.hpp"
|
||||
#include "src/shellmatta_utils.c"
|
||||
#include <string.h>
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c - itoa - 123456 base 10" ) {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(123456, buffer, 10) == 6 );
|
||||
REQUIRE( strcmp(buffer, "123456") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c - itoa - 0x0ABBCCDD base 16") {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(0x0ABBCCDD, buffer, 16) == 7 );
|
||||
REQUIRE( strcmp(buffer, "ABBCCDD") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c - itoa - -574236 base 10") {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(-574236, buffer, 10) == 7 );
|
||||
REQUIRE( strcmp(buffer, "-574236") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c - itoa - 0x80000000 base 2") {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(0x80000000, buffer, 2) == 33 );
|
||||
REQUIRE( strcmp(buffer, "-10000000000000000000000000000000") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 2") {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(0x7FFFFFFF, buffer, 2) == 31 );
|
||||
REQUIRE( strcmp(buffer, "1111111111111111111111111111111") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 1 - wrong base") {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(0x7FFFFFFF, buffer, 1) == 0 );
|
||||
REQUIRE( strcmp(buffer, "\0") == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c - itoa - 0x7FFFFFFF base 17 - wrong base") {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(0x7FFFFFFF, buffer, 17) == 0 );
|
||||
REQUIRE( strcmp(buffer, "\0") == 0);
|
||||
}
|
65
test/unittest/shellmatta_utils/test_utils_writeEcho.cpp
Normal file
65
test/unittest/shellmatta_utils/test_utils_writeEcho.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "test/framework/catch.hpp"
|
||||
#include "src/shellmatta_utils.c"
|
||||
#include <string.h>
|
||||
|
||||
static uint32_t write_callCnt = 0u;
|
||||
static const char *write_data;
|
||||
static uint32_t write_length;
|
||||
|
||||
static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
||||
{
|
||||
write_callCnt ++;
|
||||
write_data = data;
|
||||
write_length = length;
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_writeEcho echo enabled" ) {
|
||||
|
||||
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;
|
||||
write_data = 0u;
|
||||
write_length = 0u;
|
||||
|
||||
utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
|
||||
|
||||
CHECK( write_callCnt == 1u );
|
||||
CHECK( write_data == (char*)&dummyData );
|
||||
REQUIRE( write_length == sizeof(dummyData));
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta_writeEcho echo disabled" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
char buffer[20];
|
||||
char dummyData[29];
|
||||
|
||||
inst.buffer = buffer;
|
||||
inst.bufferSize = 20;
|
||||
inst.cursor = 10;
|
||||
inst.inputCount = 10;
|
||||
inst.echoEnabled = false;
|
||||
|
||||
inst.write = writeFct;
|
||||
|
||||
write_callCnt = 0u;
|
||||
write_data = 0u;
|
||||
write_length = 0u;
|
||||
|
||||
utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
|
||||
|
||||
CHECK( write_callCnt == 0u );
|
||||
CHECK( write_data == (char*)0u );
|
||||
REQUIRE( write_length == 0u );
|
||||
}
|
7
test/unittest/test_main.cpp
Normal file
7
test/unittest/test_main.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
// 010-TestCase.cpp
|
||||
|
||||
// Let Catch provide main():
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "test/framework/catch.hpp"
|
||||
|
Reference in New Issue
Block a user