added some integration tests
to test the integrated shellmatta using only the external api
This commit is contained in:
parent
d65765371b
commit
5ff3bfa12e
@ -44,8 +44,6 @@ set_blocking (int fd, int should_block)
|
||||
static shellmatta_retCode_t doSomething(shellmatta_handle_t handle, const char *arguments, uint32_t length)
|
||||
{
|
||||
|
||||
//shellmatta_printf(handle, "blubb\n\r");
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
shellmatta_cmd_t doSomethingCmd = {"doSomething", "do", "Function does something", "use me, please", doSomething, NULL};
|
||||
@ -53,7 +51,6 @@ shellmatta_cmd_t doSomethingCmd = {"doSomething", "do", "Function does something
|
||||
static shellmatta_retCode_t doSome(shellmatta_handle_t handle, const char *arguments, uint32_t length)
|
||||
{
|
||||
|
||||
//shellmatta_printf(handle, "blubb\n\r");
|
||||
shellmatta_write(handle, "blubb\r\n", 7u);
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
@ -63,9 +60,6 @@ shellmatta_cmd_t doSomeCmd = {"adoSome2", "adof2", "Function does something", "u
|
||||
|
||||
static shellmatta_retCode_t quit(shellmatta_handle_t handle, const char *arguments, uint32_t length)
|
||||
{
|
||||
|
||||
//shellmatta_printf(handle, "Bye\n\r");
|
||||
|
||||
exitRequest = true;
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
@ -75,13 +69,7 @@ shellmatta_cmd_t quitCommand = {"quit", "q", "Function quits the shell", "", qui
|
||||
|
||||
shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
||||
{
|
||||
// for(uint32_t i = 0u; i < length; i ++)
|
||||
// {
|
||||
write(f, data, length);
|
||||
//printf("%c", data[i]);
|
||||
// }
|
||||
|
||||
//fflush(stdout);
|
||||
write(f, data, length);
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
@ -92,11 +80,7 @@ int main(void)
|
||||
static char historyBuffer[4096];
|
||||
static shellmatta_instance_t instance;
|
||||
|
||||
// initscr();
|
||||
// raw();
|
||||
// keypad(stdscr, TRUE);
|
||||
// noecho();
|
||||
f = open("/dev/pts/2", O_RDWR | O_SYNC);
|
||||
f = open("/dev/pts/3", O_RDWR | O_SYNC);
|
||||
|
||||
if (f < 0)
|
||||
{
|
||||
@ -115,9 +99,9 @@ int main(void)
|
||||
"shellmatta->",
|
||||
NULL,
|
||||
writeFct);
|
||||
shellmatta_addCmd(&instance, &doSomethingCmd);
|
||||
shellmatta_addCmd(&instance, &doSomeCmd);
|
||||
shellmatta_addCmd(&instance, &quitCommand);
|
||||
shellmatta_addCmd(handle, &doSomethingCmd);
|
||||
shellmatta_addCmd(handle, &doSomeCmd);
|
||||
shellmatta_addCmd(handle, &quitCommand);
|
||||
|
||||
while(exitRequest == false)
|
||||
{
|
||||
@ -129,11 +113,9 @@ int main(void)
|
||||
fprintf(stdout, "0x%02x \n", c);
|
||||
fflush(stdout);
|
||||
|
||||
shellmatta_processData(&instance, &c, res);
|
||||
shellmatta_processData(handle, &c, res);
|
||||
}
|
||||
|
||||
// refresh();
|
||||
// endwin();
|
||||
close(f);
|
||||
|
||||
return 0;
|
||||
|
59
makefile
59
makefile
@ -20,18 +20,23 @@ SOURCES := src/shellmatta.c \
|
||||
|
||||
INCLUDES := api .
|
||||
|
||||
TEST_SOURCES := test/test_main.cpp \
|
||||
test/shellmatta_utils/test_utils_writeEcho.cpp \
|
||||
test/shellmatta_utils/test_utils_shellItoa.cpp \
|
||||
test/shellmatta_utils/test_utils_saveCursorPos.cpp \
|
||||
test/shellmatta_utils/test_utils_restoreCursorPos.cpp \
|
||||
test/shellmatta_utils/test_utils_eraseLine.cpp \
|
||||
test/shellmatta_utils/test_utils_rewindCursor.cpp \
|
||||
test/shellmatta_utils/test_utils_forwardCursor.cpp \
|
||||
test/shellmatta_utils/test_utils_clearInput.cpp \
|
||||
test/shellmatta_utils/test_utils_insertChars.cpp
|
||||
UNITTEST_SOURCES := test/unittest/test_main.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_writeEcho.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_shellItoa.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_restoreCursorPos.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_eraseLine.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_rewindCursor.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_forwardCursor.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_clearInput.cpp \
|
||||
test/unittest/shellmatta_utils/test_utils_insertChars.cpp
|
||||
|
||||
TEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(TEST_SOURCES))
|
||||
INTEGRATIONTEST_SOURCES := test/integrationtest/test_main.cpp \
|
||||
test/integrationtest/test_integration.cpp
|
||||
|
||||
UNITTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(UNITTEST_SOURCES))
|
||||
|
||||
INTEGRATIONTEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(INTEGRATIONTEST_SOURCES))
|
||||
|
||||
CFLAGS := $(INCLUDES:%=-I%) -g
|
||||
TESTFLAGS := $(INCLUDES:%=-I%) -g -fprofile-arcs -ftest-coverage
|
||||
@ -46,9 +51,11 @@ EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
|
||||
|
||||
EXAMPLE_TARGET := $(OBJ_DIR)example/example
|
||||
|
||||
TEST_TARGET := $(OBJ_DIR)test/test
|
||||
UNITTEST_TARGET := $(OBJ_DIR)test/unittest/unittest
|
||||
|
||||
OBJ := $(COBJ) $(EXAMPLE_COBJ) $(TEST_CPPOBJ)
|
||||
INTEGRATIONTEST_TARGET := $(OBJ_DIR)test/integrationtest/integrationtest
|
||||
|
||||
OBJ := $(COBJ) $(EXAMPLE_COBJ) $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ)
|
||||
DEPS := $(OBJ:%.o=%.d)
|
||||
|
||||
export
|
||||
@ -60,12 +67,22 @@ help:
|
||||
@echo example - build example
|
||||
@echo -------------------------
|
||||
|
||||
test: $(TEST_TARGET)
|
||||
- @mkdir -p output/test/report
|
||||
test: unittest integrationtest
|
||||
|
||||
unittest: $(UNITTEST_TARGET)
|
||||
- @mkdir -p output/test/unittest/report
|
||||
@echo running test:
|
||||
-output/test/test
|
||||
-$(UNITTEST_TARGET)
|
||||
#gcov -o output/test $(TEST_CPPOBJ) -r
|
||||
gcovr --html-details --output output/test/report/report.html output/test -f src -f api
|
||||
gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api
|
||||
#-rm *.gcov
|
||||
|
||||
integrationtest: $(INTEGRATIONTEST_TARGET)
|
||||
- @mkdir -p output/test/integrationtest/report
|
||||
@echo running test:
|
||||
-$(INTEGRATIONTEST_TARGET)
|
||||
#gcov -o output/test $(TEST_CPPOBJ) -r
|
||||
gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/test/integrationtest -f src -f api
|
||||
#-rm *.gcov
|
||||
|
||||
example: $(EXAMPLE_TARGET)
|
||||
@ -83,7 +100,11 @@ $(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
|
||||
- @mkdir -p $(@D)
|
||||
$(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
|
||||
|
||||
$(TEST_TARGET): $(TEST_CPPOBJ)
|
||||
$(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
|
||||
- @mkdir -p $(@D)
|
||||
$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
|
||||
|
||||
$(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(COBJ)
|
||||
- @mkdir -p $(@D)
|
||||
$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
|
||||
|
||||
@ -101,7 +122,7 @@ $(EXAMPLE_COBJ):
|
||||
@$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
|
||||
$(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
|
||||
|
||||
$(TEST_CPPOBJ):
|
||||
$(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ):
|
||||
- @mkdir -p $(@D)
|
||||
@$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
|
||||
$(CPP) -c $(TESTFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
|
||||
|
122
test/integrationtest/test_integration.cpp
Normal file
122
test/integrationtest/test_integration.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
#include "test/framework/catch.hpp"
|
||||
extern "C" {
|
||||
#include "shellmatta.h"
|
||||
}
|
||||
#include <string.h>
|
||||
|
||||
static uint32_t write_callCnt = 0u;
|
||||
static char write_data[1024];
|
||||
static uint32_t write_length;
|
||||
|
||||
static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
|
||||
{
|
||||
write_callCnt ++;
|
||||
while((length > 0) && (write_length < sizeof(write_data)))
|
||||
{
|
||||
write_data[write_length] = *data;
|
||||
data ++;
|
||||
length --;
|
||||
write_length ++;
|
||||
}
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
static shellmatta_retCode_t doSomething(shellmatta_handle_t handle, const char *arguments, uint32_t length)
|
||||
{
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
shellmatta_cmd_t doSomethingCmd = {"doSomething", "do", "Function does something", "use me, please", doSomething, NULL};
|
||||
|
||||
|
||||
TEST_CASE( "shellmatta empty function" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
shellmatta_handle_t handle;
|
||||
char buffer[1024];
|
||||
char historyBuffer[1024];
|
||||
char *dummyData = "\r\nshellmatta->";
|
||||
|
||||
shellmatta_doInit( &inst,
|
||||
&handle,
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
historyBuffer,
|
||||
sizeof(historyBuffer),
|
||||
"shellmatta->",
|
||||
NULL,
|
||||
writeFct);
|
||||
|
||||
write_callCnt = 0u;
|
||||
memset(write_data, 0, sizeof(write_data));
|
||||
write_length = 0u;
|
||||
|
||||
shellmatta_processData(handle, "\r", 1);
|
||||
|
||||
CHECK( write_length == 14u);
|
||||
REQUIRE( strcmp(dummyData, write_data) == 0);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta help function" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
shellmatta_handle_t handle;
|
||||
char buffer[1024];
|
||||
char historyBuffer[1024];
|
||||
char *dummyData = "h\r\n"
|
||||
"doSomething do Function does something use me, please\r\n"
|
||||
"help h Print this help text help\r\n"
|
||||
"\r\nshellmatta->";
|
||||
|
||||
shellmatta_doInit( &inst,
|
||||
&handle,
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
historyBuffer,
|
||||
sizeof(historyBuffer),
|
||||
"shellmatta->",
|
||||
NULL,
|
||||
writeFct);
|
||||
shellmatta_addCmd(handle, &doSomethingCmd);
|
||||
|
||||
write_callCnt = 0u;
|
||||
memset(write_data, 0, sizeof(write_data));
|
||||
write_length = 0u;
|
||||
|
||||
shellmatta_processData(handle, "h\r", 2);
|
||||
|
||||
CHECK( write_length == 123u);
|
||||
CHECK( strcmp(dummyData, write_data) == 0);
|
||||
|
||||
|
||||
write_callCnt = 0u;
|
||||
memset(write_data, 0, sizeof(write_data));
|
||||
write_length = 0u;
|
||||
|
||||
dummyData = "h 564 321 56 465 46\r\n"
|
||||
"doSomething do Function does something use me, please\r\n"
|
||||
"help h Print this help text help\r\n"
|
||||
"\r\nshellmatta->";
|
||||
|
||||
shellmatta_processData(handle, "h 564 321 56 465 46\r", 20);
|
||||
|
||||
CHECK( write_length == 141u);
|
||||
CHECK( strcmp(dummyData, write_data) == 0);
|
||||
|
||||
|
||||
write_callCnt = 0u;
|
||||
memset(write_data, 0, sizeof(write_data));
|
||||
write_length = 0u;
|
||||
|
||||
dummyData = "hr\r\n"
|
||||
"Command: hr not found"
|
||||
"\r\nshellmatta->";
|
||||
|
||||
shellmatta_processData(handle, "hr\r", 3);
|
||||
|
||||
CHECK( write_length == 39u);
|
||||
REQUIRE( strcmp(dummyData, write_data) == 0);
|
||||
}
|
||||
|
@ -3,5 +3,5 @@
|
||||
// Let Catch provide main():
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "framework/catch.hpp"
|
||||
#include "test/framework/catch.hpp"
|
||||
|
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"
|
||||
|
Loading…
Reference in New Issue
Block a user