Skip to content

Commit

Permalink
Merge pull request #79 from knixeur/reactivate_tests
Browse files Browse the repository at this point in the history
Reactivate tests
  • Loading branch information
raboof authored Apr 23, 2019
2 parents 735cee0 + 12a6920 commit 744d698
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ utils/ion-statusd/ion-statusd
utils/ion-completefile/ion-completefile
cscope.*
test/integration/libXinerama.so.1.0
libextl/test/extltest
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ dist:
test:
$(MAKE) -C mod_xrandr test
$(MAKE) -C mod_xinerama test
$(MAKE) -C libtu test
$(MAKE) -C libextl test
$(MAKE) -C test
11 changes: 5 additions & 6 deletions libextl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ CFLAGS += $(XOPEN_SOURCE) $(C99_SOURCE)

SOURCES=readconfig.c luaextl.c misc.c

LIBS += $(LIBTU_LIBS) $(LUA_LIBS) $(DL_LIBS) -lm

HEADERS=readconfig.h extl.h luaextl.h private.h types.h

TARGETS=libextl.a libextl-mkexports

SUBDIRS = test

.PHONY : libextl-mkexports test

######################################
Expand Down Expand Up @@ -63,9 +67,4 @@ install:
done

test:
rm test/extltest
gcc -g -o test/extltest test/extltest.c `pkg-config --libs lua5.1` `pkg-config --cflags lua5.1` -ltu
test/extltest
rm test/extltest
gcc -g -o test/extltest test/extltest.c `pkg-config --libs lua5.2` `pkg-config --cflags lua5.2` -ltu
test/extltest
$(MAKE) -C test test
21 changes: 17 additions & 4 deletions libextl/luaextl.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ static bool extl_stack_get(lua_State *st, int pos, char type,
void *valret)
{
double d=0;
bool b=FALSE;
const char *str;

if(wasdeadobject!=NULL)
Expand Down Expand Up @@ -667,7 +668,19 @@ static bool extl_stack_get(lua_State *st, int pos, char type,
*((double*)valret)=d;
}
return TRUE;

case LUA_TBOOLEAN:
// type=='b' case is handled above before the switch
if(type!='a')
return FALSE;

if(type=='a'){
b=lua_toboolean(st, pos);
if(valret){
((ExtlAny*)valret)->type='b';
((ExtlAny*)valret)->value.b=b;
}
}
return TRUE;
case LUA_TNIL:
case LUA_TNONE:
if(type=='a'){
Expand Down Expand Up @@ -1015,7 +1028,7 @@ bool extl_table_eq(ExtlTab t1, ExtlTab t2)
/*}}}*/


/*{{{ Table/get */
/*{{{ Table/get */


typedef struct{
Expand Down Expand Up @@ -1191,7 +1204,7 @@ int extl_table_get_n(ExtlTab ref)
/*}}}*/


/*{{{ Table/set */
/*{{{ Table/set */


static bool extl_table_dodo_set2(lua_State *st, TableParams2 *params)
Expand Down Expand Up @@ -1314,7 +1327,7 @@ bool extl_table_seti_t(ExtlTab ref, int entry, ExtlTab val)
/*}}}*/


/*{{{ Table/clear entry */
/*{{{ Table/clear entry */


static bool extl_table_dodo_clear2(lua_State *st, TableParams2 *params)
Expand Down
30 changes: 30 additions & 0 deletions libextl/test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# System-specific configuration is in system.mk
TOPDIR=../..
include $(TOPDIR)/build/system-inc.mk

######################################

# SOURCES=../readconfig.c ../misc.c

#LIBS += $(LUA_LIBS) $(DL_LIBS) -lm
INCLUDES += -I.. $(LIBTU_INCLUDES) $(LUA_INCLUDES)
CFLAGS += $(XOPEN_SOURCE) $(C99_SOURCE)

SOURCES=../readconfig.c ../misc.c

LIBS += $(LIBTU_LIBS) $(LUA_LIBS) $(DL_LIBS) -lm

HEADERS=readconfig.h extl.h luaextl.h private.h types.h


######################################

include $(TOPDIR)/build/rules.mk

######################################

test: $(SOURCES)
$(CC) $(CFLAGS) -o extltest $(SOURCES) extltest.c $(INCLUDES) $(LIBS)
./extltest
# $(RM) extltest

74 changes: 69 additions & 5 deletions libextl/test/extltest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../luaextl.c"
#include "../readconfig.c"
#include "../readconfig.h"
#include "libtu/errorlog.h"

static const char tostringstr[]=
"local arg = {...}\n"
Expand Down Expand Up @@ -30,7 +31,8 @@ int test_tostring()

if(!extl_loadstring("print('testing\\n'); return 'test'", &fn))
return 2;
fprintf(stderr, "Calling extl_call...\n");

fprintf(stderr, "Calling extl_call...\n");
if(!extl_call(tostringfn, "f", "s", fn, &retstr))
return 3;

Expand All @@ -45,16 +47,78 @@ fprintf(stderr, "Calling extl_call...\n");
return 0;
}

int test_stack_get_bool()
{
ErrorLog el;
ExtlAny bool_any;
bool bool_test;
bool bool_push;

errorlog_begin(&el);

// true
bool_push=TRUE;
extl_stack_push(l_st, 'b', &bool_push);
bool_test=FALSE;
if(extl_stack_get(l_st, -1, 'b', FALSE, NULL, &bool_test) != TRUE)
return 1;
if (bool_test != TRUE)
return 2;

if(extl_stack_get(l_st, -1, 'a', FALSE, NULL, &bool_any) != TRUE)
return 3;
if (bool_any.type != 'b')
return 4;
if (bool_any.value.b != TRUE)
return 5;

// false
bool_push=FALSE;
extl_stack_push(l_st, 'b', &bool_push);
bool_test=TRUE;
if(extl_stack_get(l_st, -1, 'b', FALSE, NULL, &bool_test) != TRUE)
return 6;
if (bool_test != FALSE)
return 7;

if(extl_stack_get(l_st, -1, 'a', FALSE, NULL, &bool_any) != TRUE)
return 8;
if (bool_any.type != 'b')
return 9;
if (bool_any.value.b != FALSE)
return 10;

return 0;
}

int main()
{
fprintf(stdout, "[TESTING] libextl ====\n");

int result = 0;
int err = 0;

extl_init();

result += test_tostring();
fprintf(stdout, "[TEST] test_tostring: ");
result = test_tostring();
if (result != 0) {
fprintf(stdout, "[ERROR]: %d\n", result);
err += 1;
} else {
fprintf(stdout, "[OK]\n");
}

fprintf(stdout, "[TEST] test_stack_get_bool: ");
result = test_stack_get_bool();
if (result != 0) {
fprintf(stdout, "[ERROR]: %d\n", result);
err += 1;
} else {
fprintf(stdout, "[OK]\n");
}

fprintf(stderr, "Result: %d\n", result);
extl_deinit();

return result;
return err;
}
7 changes: 7 additions & 0 deletions libtu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ HEADERS=debug.h errorlog.h locale.h minmax.h obj.h objp.h output.

TARGETS=libtu.a

SUBDIRS = test

######################################

include $(TOPDIR)/build/rules.mk

######################################

.PHONY: test

libtu.a: $(OBJS)
$(AR) $(ARFLAGS) $@ $+
$(RANLIB) $@
Expand All @@ -41,3 +45,6 @@ install:
for h in $(HEADERS); do \
$(INSTALL) -m $(DATA_MODE) $$h $(DESTDIR)$(INCDIR)/libtu; \
done

test:
$(MAKE) -C test test
22 changes: 22 additions & 0 deletions libtu/test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# System-specific configuration is in system.mk
TOPDIR=../..
include $(TOPDIR)/build/system-inc.mk

######################################

SOURCES=../misc.c ../tokenizer.c ../util.c ../output.c

LIBS += $(LUA_LIBS) $(DL_LIBS) -lm
INCLUDES += $(LIBTU_INCLUDES)
CFLAGS += $(XOPEN_SOURCE) $(C99_SOURCE)

######################################

include $(TOPDIR)/build/rules.mk

######################################

test: $(SOURCES)
$(CC) $(CFLAGS) -o tutest $(SOURCES) tutest.c $(LIBS)
./tutest
$(RM) ./tutest
3 changes: 3 additions & 0 deletions libtu/test/data_gettoken
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1
2.3 # comment ignored
# realcomment
111 changes: 111 additions & 0 deletions libtu/test/tutest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* libtu/tester.c
*
* Copyright (c) Tuomo Valkonen 1999-2002.
*
* You may distribute and modify this library under the terms of either
* the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
*/

#include <stdio.h>

#include "../misc.h"
#include "../tokenizer.h"
#include "../util.h"

int test_get_token() {
Tokenizer*tokz;
Token tok=TOK_INIT;

if(!(tokz=tokz_open("data_gettoken")))
return 1;

// 1
if(tokz_get_token(tokz, &tok) == FALSE)
return 11;
if (tok.type != TOK_LONG)
return 12;
if (TOK_LONG_VAL(&tok) != 1)
return 13;

// \n
if(tokz_get_token(tokz, &tok) == FALSE)
return 21;
if (tok.type != TOK_OP)
return 22;

// 2.3
if(tokz_get_token(tokz, &tok) == FALSE)
return 31;
if (tok.type != TOK_DOUBLE)
return 32;
if (TOK_DOUBLE_VAL(&tok) != 2.3)
return 33;

// ignore comment and go to next line
if(tokz_get_token(tokz, &tok) == FALSE)
return 41;
if (tok.type != TOK_OP)
return 42;
if (TOK_OP_VAL(&tok) != OP_NEXTLINE)
return 43;

// ignore line
if(tokz_get_token(tokz, &tok) == FALSE)
return 51;
if (tok.type != TOK_OP)
return 52;
if (TOK_OP_VAL(&tok) != OP_EOF)
return 53;

tokz_close(tokz);
/*
while(tokz_get_token(tokz, &tok)){
switch(tok.type){
case TOK_LONG:
printf("long - %ld\n", TOK_LONG_VAL(&tok));
break;
case TOK_DOUBLE:
printf("double - %g\n", TOK_DOUBLE_VAL(&tok));
break;
case TOK_CHAR:
printf("char - '%c'\n", TOK_CHAR_VAL(&tok));
break;
case TOK_STRING:
printf("string - \"%s\"\n", TOK_STRING_VAL(&tok));
break;
case TOK_IDENT:
printf("ident - %s\n", TOK_IDENT_VAL(&tok));
break;
case TOK_COMMENT:
printf("comment - %s\n", TOK_COMMENT_VAL(&tok));
break;
case TOK_OP:
printf("operator - %03x\n", TOK_OP_VAL(&tok));
break;
}
}
*/
return 0;
}

int main(int argc, char *argv[])
{
fprintf(stdout, "[TESTING] libtu ====\n");
libtu_init(argv[0]);

int result = 0;
int err = 0;

fprintf(stdout, "[TEST] test_get_token: ");
result = test_get_token();
if (result != 0) {
fprintf(stdout, "[ERROR]: %d\n", result);
err += 1;
} else {
fprintf(stdout, "[OK]\n");
}

return err;
}

2 changes: 1 addition & 1 deletion test/integration/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ libXinerama.so.1.0: Xinerama.c
gcc -O2 -Wall Xinerama.c -fPIC -o libXinerama.so.1.0 -shared

test: libXinerama.so.1.0
LD_PRELOAD=`pwd`/libXinerama.so.1.0 lua ./runtests.lua
LD_PRELOAD=`pwd`/libXinerama.so.1.0 $(LUA) ./runtests.lua

0 comments on commit 744d698

Please sign in to comment.