From f493180cb44933981e71daf4ebaca355cd35e07a Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 26 Jan 2021 00:30:06 +0100 Subject: [PATCH] lib_test - add functions and corresponding tests in c to be mirrored in python --- examples/lib/lib_test/Makefile | 4 +-- examples/lib/lib_test/README.md | 4 +-- examples/lib/lib_test/functions.h | 24 +++++------------- examples/lib/lib_test/lib_test.c | 37 ++++++++++++++++++++++++---- examples/lib/lib_test/main.c | 41 +++++++++++++++++++++++++++---- 5 files changed, 78 insertions(+), 32 deletions(-) diff --git a/examples/lib/lib_test/Makefile b/examples/lib/lib_test/Makefile index 81d5f88..2b3e1fd 100644 --- a/examples/lib/lib_test/Makefile +++ b/examples/lib/lib_test/Makefile @@ -3,8 +3,8 @@ TARGET_CXX=lib_test_cxx LIB_STATIC=liblib_test.a LIB_DYN=liblib_test.so -CFLAGS+=-std=c99 -g -CXXFLAGS+=-std=c++11 -g +CFLAGS+=-std=c99 -g -UNDEBUG +CXXFLAGS+=-std=c++11 -g -UNDEBUG SRCS+=$(wildcard *.c) OBJS_C+=$(SRCS:.c=.o99) diff --git a/examples/lib/lib_test/README.md b/examples/lib/lib_test/README.md index a3641c6..8256e81 100644 --- a/examples/lib/lib_test/README.md +++ b/examples/lib/lib_test/README.md @@ -61,8 +61,8 @@ X = Anonymous (enums onnly) -> enums.h a = Array (vars (all possible types) and struct fields) (//p = Pointer (vars (all possible types) and struct fields)) -func_ = Function -> functions.h -var_ = Variable -> vars.h +func__args_ = Function -> functions.h -> functions.h +var_ = Variable -> vars.h prefixed underline (e.g _E) means no typedef/alias exists for this item (enum in this case) diff --git a/examples/lib/lib_test/functions.h b/examples/lib/lib_test/functions.h index 12e039c..799569d 100644 --- a/examples/lib/lib_test/functions.h +++ b/examples/lib/lib_test/functions.h @@ -10,32 +10,20 @@ extern "C" { #endif -void func_void_void(); +void func_V_args_V(); -int func_int_void(); +int func_P_args_V(); -void func_void_int(int); +void func_V_args_P(int arg1_P); -int func_int_int(int); +int func_P_args_P(int arg1_P); -// struct -struct _PS func__PS_V(); +void func_V_args_pP(unsigned int* const arg1_pP); -// enum -enum _E func__E_V(); +int func_P_args_P_pP_pP(int arg1_P, int* arg2_pP, int* arg3_pP); -// typedef -T_P func_TP_V(); -void func_V_TP(T_P); -T_P func_TP_TP(T_P); -APS func_APS_V(); -void func_V_APS(APS); -APS func_APS_APS(APS); -TPS func_TPS_V(); -void func_V_TPS(TPS); -TPS func_TPS_TPS(TPS); #ifdef __cplusplus } diff --git a/examples/lib/lib_test/lib_test.c b/examples/lib/lib_test/lib_test.c index c3c16b5..ca0856a 100644 --- a/examples/lib/lib_test/lib_test.c +++ b/examples/lib/lib_test/lib_test.c @@ -1,5 +1,37 @@ #include "lib_test.h" +#include +// FUNCTIONS + + +void func_V_args_V() { + +} + +int func_P_args_V() { + return 23; +} + +void func_V_args_P(int arg1_P) { + printf("%i", arg1_P); +} + +int func_P_args_P(int arg1_P) { + printf("%i", arg1_P); + return ++arg1_P; +} + +void func_V_args_pP(unsigned int* const arg1_pP) { + ++(*arg1_pP); +} + +int func_P_args_P_pP_pP(int arg1_P, int* arg2_pP, int* arg3_pP) { + ++(*arg2_pP); + ++(*arg3_pP); + return *arg2_pP; +} + + // Variables // ========= // _V = Void @@ -551,9 +583,4 @@ extern TaTAXE var_aTaTAXE[3]; -// FUNCTIONS - -//struct _PS func__PS_V() { -// return var__PS; -//} diff --git a/examples/lib/lib_test/main.c b/examples/lib/lib_test/main.c index f3e5c2d..db68731 100644 --- a/examples/lib/lib_test/main.c +++ b/examples/lib/lib_test/main.c @@ -1,13 +1,44 @@ #include "lib_test.h" #include +#include int main() { printf("lib_test starting...\n"); - - TT_HHS a; - - TT_CCS b; - // printf("%i, %i\n", a.x, a.y); + { + printf("testing: func_V_args_V\n"); + func_V_args_V(); + } + { + printf("testing: func_P_args_V\n"); + int ret = func_P_args_V(); + assert(ret == 23); + } + { + printf("testing: func_V_args_P\n"); + func_V_args_P(23); + } + { + printf("testing: func_P_args_P\n"); + int ret = func_P_args_P(22); + assert(ret == 23); + } + { + printf("testing: func_V_args_pP\n"); + unsigned int i = 22; + func_V_args_pP(&i); + assert(i == 23); + } + { + printf("testing: func_P_args_P_pP_pP\n"); + int i = 23; + int j = 22; + int k = 22; + int ret = func_P_args_P_pP_pP(i,&j,&k); + assert(ret == 23); + assert(i == 23); + assert(j == 23); + assert(k == 23); + } }