Skip to content

Commit 744d698

Browse files
authored
Merge pull request #79 from knixeur/reactivate_tests
Reactivate tests
2 parents 735cee0 + 12a6920 commit 744d698

File tree

11 files changed

+268
-16
lines changed

11 files changed

+268
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ utils/ion-statusd/ion-statusd
2121
utils/ion-completefile/ion-completefile
2222
cscope.*
2323
test/integration/libXinerama.so.1.0
24+
libextl/test/extltest

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ dist:
6565
test:
6666
$(MAKE) -C mod_xrandr test
6767
$(MAKE) -C mod_xinerama test
68+
$(MAKE) -C libtu test
69+
$(MAKE) -C libextl test
6870
$(MAKE) -C test

libextl/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ CFLAGS += $(XOPEN_SOURCE) $(C99_SOURCE)
1919

2020
SOURCES=readconfig.c luaextl.c misc.c
2121

22+
LIBS += $(LIBTU_LIBS) $(LUA_LIBS) $(DL_LIBS) -lm
23+
2224
HEADERS=readconfig.h extl.h luaextl.h private.h types.h
2325

2426
TARGETS=libextl.a libextl-mkexports
2527

28+
SUBDIRS = test
29+
2630
.PHONY : libextl-mkexports test
2731

2832
######################################
@@ -63,9 +67,4 @@ install:
6367
done
6468

6569
test:
66-
rm test/extltest
67-
gcc -g -o test/extltest test/extltest.c `pkg-config --libs lua5.1` `pkg-config --cflags lua5.1` -ltu
68-
test/extltest
69-
rm test/extltest
70-
gcc -g -o test/extltest test/extltest.c `pkg-config --libs lua5.2` `pkg-config --cflags lua5.2` -ltu
71-
test/extltest
70+
$(MAKE) -C test test

libextl/luaextl.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ static bool extl_stack_get(lua_State *st, int pos, char type,
634634
void *valret)
635635
{
636636
double d=0;
637+
bool b=FALSE;
637638
const char *str;
638639

639640
if(wasdeadobject!=NULL)
@@ -667,7 +668,19 @@ static bool extl_stack_get(lua_State *st, int pos, char type,
667668
*((double*)valret)=d;
668669
}
669670
return TRUE;
670-
671+
case LUA_TBOOLEAN:
672+
// type=='b' case is handled above before the switch
673+
if(type!='a')
674+
return FALSE;
675+
676+
if(type=='a'){
677+
b=lua_toboolean(st, pos);
678+
if(valret){
679+
((ExtlAny*)valret)->type='b';
680+
((ExtlAny*)valret)->value.b=b;
681+
}
682+
}
683+
return TRUE;
671684
case LUA_TNIL:
672685
case LUA_TNONE:
673686
if(type=='a'){
@@ -1015,7 +1028,7 @@ bool extl_table_eq(ExtlTab t1, ExtlTab t2)
10151028
/*}}}*/
10161029

10171030

1018-
/*{{{ Table/get */
1031+
/*{{{ Table/get */
10191032

10201033

10211034
typedef struct{
@@ -1191,7 +1204,7 @@ int extl_table_get_n(ExtlTab ref)
11911204
/*}}}*/
11921205

11931206

1194-
/*{{{ Table/set */
1207+
/*{{{ Table/set */
11951208

11961209

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

13161329

1317-
/*{{{ Table/clear entry */
1330+
/*{{{ Table/clear entry */
13181331

13191332

13201333
static bool extl_table_dodo_clear2(lua_State *st, TableParams2 *params)

libextl/test/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# System-specific configuration is in system.mk
2+
TOPDIR=../..
3+
include $(TOPDIR)/build/system-inc.mk
4+
5+
######################################
6+
7+
# SOURCES=../readconfig.c ../misc.c
8+
9+
#LIBS += $(LUA_LIBS) $(DL_LIBS) -lm
10+
INCLUDES += -I.. $(LIBTU_INCLUDES) $(LUA_INCLUDES)
11+
CFLAGS += $(XOPEN_SOURCE) $(C99_SOURCE)
12+
13+
SOURCES=../readconfig.c ../misc.c
14+
15+
LIBS += $(LIBTU_LIBS) $(LUA_LIBS) $(DL_LIBS) -lm
16+
17+
HEADERS=readconfig.h extl.h luaextl.h private.h types.h
18+
19+
20+
######################################
21+
22+
include $(TOPDIR)/build/rules.mk
23+
24+
######################################
25+
26+
test: $(SOURCES)
27+
$(CC) $(CFLAGS) -o extltest $(SOURCES) extltest.c $(INCLUDES) $(LIBS)
28+
./extltest
29+
# $(RM) extltest
30+

libextl/test/extltest.c

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../luaextl.c"
2-
#include "../readconfig.c"
2+
#include "../readconfig.h"
3+
#include "libtu/errorlog.h"
34

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

3132
if(!extl_loadstring("print('testing\\n'); return 'test'", &fn))
3233
return 2;
33-
fprintf(stderr, "Calling extl_call...\n");
34+
35+
fprintf(stderr, "Calling extl_call...\n");
3436
if(!extl_call(tostringfn, "f", "s", fn, &retstr))
3537
return 3;
3638

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

50+
int test_stack_get_bool()
51+
{
52+
ErrorLog el;
53+
ExtlAny bool_any;
54+
bool bool_test;
55+
bool bool_push;
56+
57+
errorlog_begin(&el);
58+
59+
// true
60+
bool_push=TRUE;
61+
extl_stack_push(l_st, 'b', &bool_push);
62+
bool_test=FALSE;
63+
if(extl_stack_get(l_st, -1, 'b', FALSE, NULL, &bool_test) != TRUE)
64+
return 1;
65+
if (bool_test != TRUE)
66+
return 2;
67+
68+
if(extl_stack_get(l_st, -1, 'a', FALSE, NULL, &bool_any) != TRUE)
69+
return 3;
70+
if (bool_any.type != 'b')
71+
return 4;
72+
if (bool_any.value.b != TRUE)
73+
return 5;
74+
75+
// false
76+
bool_push=FALSE;
77+
extl_stack_push(l_st, 'b', &bool_push);
78+
bool_test=TRUE;
79+
if(extl_stack_get(l_st, -1, 'b', FALSE, NULL, &bool_test) != TRUE)
80+
return 6;
81+
if (bool_test != FALSE)
82+
return 7;
83+
84+
if(extl_stack_get(l_st, -1, 'a', FALSE, NULL, &bool_any) != TRUE)
85+
return 8;
86+
if (bool_any.type != 'b')
87+
return 9;
88+
if (bool_any.value.b != FALSE)
89+
return 10;
90+
91+
return 0;
92+
}
4893

4994
int main()
5095
{
96+
fprintf(stdout, "[TESTING] libextl ====\n");
97+
5198
int result = 0;
99+
int err = 0;
52100

53101
extl_init();
54102

55-
result += test_tostring();
103+
fprintf(stdout, "[TEST] test_tostring: ");
104+
result = test_tostring();
105+
if (result != 0) {
106+
fprintf(stdout, "[ERROR]: %d\n", result);
107+
err += 1;
108+
} else {
109+
fprintf(stdout, "[OK]\n");
110+
}
111+
112+
fprintf(stdout, "[TEST] test_stack_get_bool: ");
113+
result = test_stack_get_bool();
114+
if (result != 0) {
115+
fprintf(stdout, "[ERROR]: %d\n", result);
116+
err += 1;
117+
} else {
118+
fprintf(stdout, "[OK]\n");
119+
}
56120

57-
fprintf(stderr, "Result: %d\n", result);
121+
extl_deinit();
58122

59-
return result;
123+
return err;
60124
}

libtu/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ HEADERS=debug.h errorlog.h locale.h minmax.h obj.h objp.h output.
2424

2525
TARGETS=libtu.a
2626

27+
SUBDIRS = test
28+
2729
######################################
2830

2931
include $(TOPDIR)/build/rules.mk
3032

3133
######################################
3234

35+
.PHONY: test
36+
3337
libtu.a: $(OBJS)
3438
$(AR) $(ARFLAGS) $@ $+
3539
$(RANLIB) $@
@@ -41,3 +45,6 @@ install:
4145
for h in $(HEADERS); do \
4246
$(INSTALL) -m $(DATA_MODE) $$h $(DESTDIR)$(INCDIR)/libtu; \
4347
done
48+
49+
test:
50+
$(MAKE) -C test test

libtu/test/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# System-specific configuration is in system.mk
2+
TOPDIR=../..
3+
include $(TOPDIR)/build/system-inc.mk
4+
5+
######################################
6+
7+
SOURCES=../misc.c ../tokenizer.c ../util.c ../output.c
8+
9+
LIBS += $(LUA_LIBS) $(DL_LIBS) -lm
10+
INCLUDES += $(LIBTU_INCLUDES)
11+
CFLAGS += $(XOPEN_SOURCE) $(C99_SOURCE)
12+
13+
######################################
14+
15+
include $(TOPDIR)/build/rules.mk
16+
17+
######################################
18+
19+
test: $(SOURCES)
20+
$(CC) $(CFLAGS) -o tutest $(SOURCES) tutest.c $(LIBS)
21+
./tutest
22+
$(RM) ./tutest

libtu/test/data_gettoken

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
2.3 # comment ignored
3+
# realcomment

libtu/test/tutest.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* libtu/tester.c
3+
*
4+
* Copyright (c) Tuomo Valkonen 1999-2002.
5+
*
6+
* You may distribute and modify this library under the terms of either
7+
* the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
8+
*/
9+
10+
#include <stdio.h>
11+
12+
#include "../misc.h"
13+
#include "../tokenizer.h"
14+
#include "../util.h"
15+
16+
int test_get_token() {
17+
Tokenizer*tokz;
18+
Token tok=TOK_INIT;
19+
20+
if(!(tokz=tokz_open("data_gettoken")))
21+
return 1;
22+
23+
// 1
24+
if(tokz_get_token(tokz, &tok) == FALSE)
25+
return 11;
26+
if (tok.type != TOK_LONG)
27+
return 12;
28+
if (TOK_LONG_VAL(&tok) != 1)
29+
return 13;
30+
31+
// \n
32+
if(tokz_get_token(tokz, &tok) == FALSE)
33+
return 21;
34+
if (tok.type != TOK_OP)
35+
return 22;
36+
37+
// 2.3
38+
if(tokz_get_token(tokz, &tok) == FALSE)
39+
return 31;
40+
if (tok.type != TOK_DOUBLE)
41+
return 32;
42+
if (TOK_DOUBLE_VAL(&tok) != 2.3)
43+
return 33;
44+
45+
// ignore comment and go to next line
46+
if(tokz_get_token(tokz, &tok) == FALSE)
47+
return 41;
48+
if (tok.type != TOK_OP)
49+
return 42;
50+
if (TOK_OP_VAL(&tok) != OP_NEXTLINE)
51+
return 43;
52+
53+
// ignore line
54+
if(tokz_get_token(tokz, &tok) == FALSE)
55+
return 51;
56+
if (tok.type != TOK_OP)
57+
return 52;
58+
if (TOK_OP_VAL(&tok) != OP_EOF)
59+
return 53;
60+
61+
tokz_close(tokz);
62+
/*
63+
while(tokz_get_token(tokz, &tok)){
64+
switch(tok.type){
65+
case TOK_LONG:
66+
printf("long - %ld\n", TOK_LONG_VAL(&tok));
67+
break;
68+
case TOK_DOUBLE:
69+
printf("double - %g\n", TOK_DOUBLE_VAL(&tok));
70+
break;
71+
case TOK_CHAR:
72+
printf("char - '%c'\n", TOK_CHAR_VAL(&tok));
73+
break;
74+
case TOK_STRING:
75+
printf("string - \"%s\"\n", TOK_STRING_VAL(&tok));
76+
break;
77+
case TOK_IDENT:
78+
printf("ident - %s\n", TOK_IDENT_VAL(&tok));
79+
break;
80+
case TOK_COMMENT:
81+
printf("comment - %s\n", TOK_COMMENT_VAL(&tok));
82+
break;
83+
case TOK_OP:
84+
printf("operator - %03x\n", TOK_OP_VAL(&tok));
85+
break;
86+
}
87+
}
88+
*/
89+
return 0;
90+
}
91+
92+
int main(int argc, char *argv[])
93+
{
94+
fprintf(stdout, "[TESTING] libtu ====\n");
95+
libtu_init(argv[0]);
96+
97+
int result = 0;
98+
int err = 0;
99+
100+
fprintf(stdout, "[TEST] test_get_token: ");
101+
result = test_get_token();
102+
if (result != 0) {
103+
fprintf(stdout, "[ERROR]: %d\n", result);
104+
err += 1;
105+
} else {
106+
fprintf(stdout, "[OK]\n");
107+
}
108+
109+
return err;
110+
}
111+

0 commit comments

Comments
 (0)