added makefile to build an example, the documentation and the tests. Startet implementing Tests.
This commit is contained in:
parent
4dd1b0638f
commit
adcce55e83
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
output
|
||||
output
|
||||
|
140
example/main.c
Normal file
140
example/main.c
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Created on: Jun 10, 2019
|
||||
* Author: stefan
|
||||
*/
|
||||
|
||||
|
||||
#include "shellmatta.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <ncurses.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static bool exitRequest = false;
|
||||
int f;
|
||||
shellmatta_handle_t handle;
|
||||
|
||||
void
|
||||
set_blocking (int fd, int should_block)
|
||||
{
|
||||
struct termios tty;
|
||||
memset (&tty, 0, sizeof tty);
|
||||
if (tcgetattr (fd, &tty) != 0)
|
||||
{
|
||||
printf ("error %d from tggetattr", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
tty.c_cc[VMIN] = should_block ? 1 : 0;
|
||||
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
|
||||
|
||||
if (tcsetattr (fd, TCSANOW, &tty) != 0)
|
||||
printf ("error %d setting term attributes", errno);
|
||||
}
|
||||
|
||||
|
||||
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};
|
||||
|
||||
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;
|
||||
}
|
||||
shellmatta_cmd_t doSomeCmd = {"adoSome2", "adof2", "Function does something", "use me, please", doSome, NULL};
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
shellmatta_cmd_t quitCommand = {"quit", "q", "Function quits the shell", "", quit, NULL};
|
||||
|
||||
|
||||
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);
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static char buffer[1024];
|
||||
static char historyBuffer[0];
|
||||
static shellmatta_instance_t instance;
|
||||
|
||||
// initscr();
|
||||
// raw();
|
||||
// keypad(stdscr, TRUE);
|
||||
// noecho();
|
||||
f = open("/dev/pts/5", O_RDWR | O_SYNC);
|
||||
|
||||
if (f < 0)
|
||||
{
|
||||
printf("failure %d\n", errno);
|
||||
return f;
|
||||
}
|
||||
|
||||
set_blocking (f, 1);
|
||||
|
||||
shellmatta_doInit( &instance,
|
||||
&handle,
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
historyBuffer,
|
||||
sizeof(historyBuffer),
|
||||
"shellmatta->",
|
||||
NULL,
|
||||
writeFct);
|
||||
shellmatta_addCmd(&instance, &doSomethingCmd);
|
||||
shellmatta_addCmd(&instance, &doSomeCmd);
|
||||
shellmatta_addCmd(&instance, &quitCommand);
|
||||
|
||||
while(exitRequest == false)
|
||||
{
|
||||
char c;
|
||||
|
||||
int res = 0;
|
||||
res = read (f, &c, 1);
|
||||
|
||||
fprintf(stdout, "0x%02x \n", c);
|
||||
fflush(stdout);
|
||||
|
||||
shellmatta_processData(&instance, &c, res);
|
||||
}
|
||||
|
||||
// refresh();
|
||||
// endwin();
|
||||
close(f);
|
||||
|
||||
return 0;
|
||||
}
|
108
makefile
Normal file
108
makefile
Normal file
@ -0,0 +1,108 @@
|
||||
#
|
||||
# Copyright (c) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
|
||||
OBJ_DIR := output/
|
||||
|
||||
CC := gcc
|
||||
CPP := g++
|
||||
LN := ln
|
||||
|
||||
SOURCES := src/shellmatta.c \
|
||||
src/shellmatta_autocomplete.c \
|
||||
src/shellmatta_history.c \
|
||||
src/shellmatta_utils.c \
|
||||
src/shellmatta_escape.c
|
||||
|
||||
INCLUDES := api .
|
||||
|
||||
TEST_SOURCES := test/test_main.cpp \
|
||||
test/shellmatta_utils/itoa.cpp \
|
||||
test/shellmatta_utils/clearInput.cpp \
|
||||
test/shellmatta_utils/insertChars.cpp
|
||||
|
||||
TEST_CPPOBJ := $(patsubst %.cpp,$(OBJ_DIR)%.o,$(TEST_SOURCES))
|
||||
|
||||
CFLAGS := $(INCLUDES:%=-I%) -g
|
||||
TESTFLAGS := $(INCLUDES:%=-I%) -g -fprofile-arcs -ftest-coverage
|
||||
TESTLFLAGS := -fprofile-arcs -Wl,--allow-multiple-definition
|
||||
|
||||
DEPEND = -MT $@ -MF "$(@:%.o=%.d)" -MG -MM
|
||||
|
||||
COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(SOURCES))
|
||||
|
||||
EXAMPLE_SOURCES := example/main.c
|
||||
EXAMPLE_COBJ := $(patsubst %.c,$(OBJ_DIR)%.o,$(EXAMPLE_SOURCES))
|
||||
|
||||
EXAMPLE_TARGET := $(OBJ_DIR)example/example
|
||||
|
||||
TEST_TARGET := $(OBJ_DIR)test/test
|
||||
|
||||
OBJ := $(COBJ) $(EXAMPLE_COBJ) $(TEST_CPPOBJ)
|
||||
DEPS := $(OBJ:%.o=%.d)
|
||||
|
||||
export
|
||||
|
||||
help:
|
||||
@echo Shellmatta help
|
||||
@echo -------------------------
|
||||
@echo test - run all tests
|
||||
@echo example - build example
|
||||
@echo -------------------------
|
||||
|
||||
test: $(TEST_TARGET)
|
||||
- @mkdir -p output/test/report
|
||||
@echo running test:
|
||||
-output/test/test
|
||||
#gcov -o output/test $(TEST_CPPOBJ) -r
|
||||
gcovr --html-details --output output/test/report/report.html output/test -f src -f api
|
||||
#-rm *.gcov
|
||||
|
||||
example: $(EXAMPLE_TARGET)
|
||||
@echo building example
|
||||
|
||||
doc:
|
||||
- @mkdir -p output/doc/html
|
||||
- @mkdir -p output/doc/latex
|
||||
doxygen settings/doxygen/doxyfile
|
||||
|
||||
clean:
|
||||
- rm -rf $(OBJ_DIR)
|
||||
|
||||
$(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
|
||||
- @mkdir -p $(@D)
|
||||
$(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
|
||||
|
||||
$(TEST_TARGET): $(TEST_CPPOBJ)
|
||||
- @mkdir -p $(@D)
|
||||
$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
- @mkdir -p $(@D)
|
||||
$(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
|
||||
|
||||
$(COBJ):
|
||||
- @mkdir -p $(@D)
|
||||
@$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
|
||||
$(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
|
||||
|
||||
$(EXAMPLE_COBJ):
|
||||
- @mkdir -p $(@D)
|
||||
@$(CC) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
|
||||
$(CC) -c $(CFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
|
||||
|
||||
$(TEST_CPPOBJ):
|
||||
- @mkdir -p $(@D)
|
||||
@$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
|
||||
$(CPP) -c $(TESTFLAGS) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
|
||||
|
||||
%.o: %.cpp
|
||||
- @mkdir -p $(@D)
|
||||
@$(CPP) -c $(CFLAGS) $(DEPEND) -o $@ $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
|
||||
$(CPP) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
-include $(DEPS)
|
2536
settings/doxygen/doxyfile
Normal file
2536
settings/doxygen/doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
16865
test/framework/catch.hpp
Normal file
16865
test/framework/catch.hpp
Normal file
File diff suppressed because it is too large
Load Diff
26
test/shellmatta_utils/clearInput.cpp
Normal file
26
test/shellmatta_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);
|
||||
}
|
27
test/shellmatta_utils/insertChars.cpp
Normal file
27
test/shellmatta_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 == 4);
|
||||
REQUIRE( inst.inputCount == 4);
|
||||
}
|
||||
|
11
test/shellmatta_utils/itoa.cpp
Normal file
11
test/shellmatta_utils/itoa.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "test/framework/catch.hpp"
|
||||
#include "src/shellmatta_utils.c"
|
||||
#include <string.h>
|
||||
|
||||
TEST_CASE( "shellmatta_utils.c itoa - 123456" ) {
|
||||
char buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
CHECK( utils_shellItoa(123456, buffer, 16) == 5 );
|
||||
CHECK( "12345" == "12345");
|
||||
REQUIRE( strcmp(buffer, "123456") == 0);
|
||||
}
|
7
test/test_main.cpp
Normal file
7
test/test_main.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
// 010-TestCase.cpp
|
||||
|
||||
// Let Catch provide main():
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include "framework/catch.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user