1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

renaming & moving stuff around; psyc logo

This commit is contained in:
tg(x) 2011-04-21 14:20:24 +02:00
parent ca844efdb4
commit 9fd39c72a1
29 changed files with 153 additions and 73 deletions

12
test/Makefile Normal file
View file

@ -0,0 +1,12 @@
CFLAGS=-I../include -DDEBUG -g -O0 -Wall
LDFLAGS=-L../src
LOADLIBES=-lpsyc
TARGETS=testParser testMatch
all: $(TARGETS)
test:
for f in packets/*; do echo -e "\n>> $$f"; ./testParser $$f; done
clean:
rm -f $(TARGETS)

7
test/packets/binary.txt Normal file
View file

@ -0,0 +1,7 @@
:_source some_source
:_length
_method
1234567
|

View file

@ -0,0 +1,15 @@
|
:_target psyc://p5B084547.dip.t-dialin.net/@test
:_source something
_request_context_enter
|
:_target psyc://p5B084547.dip.t-dialin.net/@test
:_more vars
:_bin 6 "1
3
"
:_entity variablevalue
_notice_context_leave
|

View file

@ -0,0 +1,6 @@
|
:_source psyc://heise.de/~user
_request_some_things
content!
|

View file

@ -0,0 +1,6 @@
|
:_source psyc://nonexisting.dns.tld/~user
_request_some_things
|

View file

@ -0,0 +1,3 @@
:_source psyc://test.psyc.eu/
:_target psyc://test.psyc.eu/
|

14
test/packets/test-1 Normal file
View file

@ -0,0 +1,14 @@
|
:_source psyc://foo/~bar
:_target psyc://bar/~baz
:_tag sch1828hu3r2cm
:_foo bar baz
:_abc_def 11 foo bar
baz
:_foo_bar yay
_message_foo_bar
ohai there!
\o/
|
|

View file

@ -0,0 +1,14 @@
|
:_source psyc://foo/~bar
:_target psyc://bar/~baz
:_tag sch1828hu3r2cm
85
:_foo bar baz
:_abc_def 11 foo bar
baz
:_foo_bar yay
_message_foo_bar
ohai there!
\o/
|
|

View file

@ -0,0 +1,14 @@
|
:_source psyc://foo/~bar
:_target psyc://bar/~baz
:_tag sch1828hu3r2cm
80
:_foo bar baz
:_abc_def 11 foo bar
baz
:_foo_bar yay
_message_foo_bar
ohai there!
\o/
|
|

14
test/packets/test-1-utf8 Normal file
View file

@ -0,0 +1,14 @@
|
:_source psyc://foo/~bar
:_target psyc://bar/~baz
:_tag sch1828hu3r2cm
:_foo bar baz
:_abc_def 15 fóö bär
báz
:_foo_bar yay
_message_foo_bar
ohai there!
\o/
|
|

25
test/packets/test-2-list Normal file
View file

@ -0,0 +1,25 @@
|
=_source psyc://foo/~bar
:_target psyc://bar/~baz
=_list_foo |foo|bar|baz
:_tag sch1828hu3r2cm
=_foo bar baz
=_abc_def 11 ghi jkl
xq
=_list_bar 36 3 foo|3 bar|7 foo
bar|11 foo
bar
baz
:_foo_bar yay
_message_foo_bar
ohai there!
\o/
|
:_target psyc://foo.bar/~baz
:_test 123
_message_test
ohai!
|

View file

@ -0,0 +1,26 @@
|
=_source psyc://foo/~bar
:_target psyc://bar/~baz
=_list_foo foo|bar|baz
=_listfoo foo|bar|baz
:_tag sch1828hu3r2cm
=_foo bar baz
=_abc_def 11 ghi jkl
xq
=_list_bar 36 2 foo|3 bar|7 foo
bar|11 foo
bar
baz
:_foo_bar yay
_message_foo_bar
ohai there!
\o/
|
:_target psyc://foo.bar/~baz
:_test 123
_message_test
ohai!
|

34
test/packets/test-3-list Normal file
View file

@ -0,0 +1,34 @@
|
=_source psyc://foo/~bar
:_target psyc://bar/~baz
=_list_foo |foo|bar|baz
:_tag sch1828hu3r2cm
?_test ignored
=_foo bar baz
=_abc_def 11 ghi jkl
xq
=_list_bar 36 3 foo|3 bar|7 foo
bar|11 foo
b|r
baz
:_foo_bar yay
=_amount_x 10
_message_foo_bar
ohai there!
\o/
|
:_target psyc://foo.bar/~baz
:_test 123
_message_test
ohai!
|
:_target psyc://foo.bar/~baz
+_list_foo yay
-_amount_x 2
_notice_test
test!
|

View file

@ -0,0 +1,5 @@
|
:_list_understand_modules _state|_fragments|_context
_request_features
|

View file

@ -0,0 +1,4 @@
:_list_understand_modules _state|_fragments|_context
_request_features
|

View file

@ -0,0 +1,9 @@
|
:_source psyc://test.psyc.eu/~foo
:_target psyc://test.psyc.eu/~bar
:_tag f00b4rb4z
:_foo bar
_message_private
OHAI
|

View file

@ -0,0 +1,9 @@
|
:_source psyc://test.psyc.eu/~foo
:_target psyc://test2.psyc.eu/~bar
:_tag f00b4rb4z
:_foo bar
_message_private
OHAI
|

20
test/testMatch.c Normal file
View file

@ -0,0 +1,20 @@
#include <stdio.h>
#include "../include/psyc/lib.h"
int main() {
if (PSYC_matches("_failure_delivery", 0, "_failure_unsuccessful_delivery_death", 0)) return -1;
if (PSYC_matches("_failure_trash", 8, "_failure_unsuccessful_delivery_death", 0)) return -2;
if (PSYC_matches("_unsuccessful", 0, "_failure_unsuccessful_delivery_death", 0)) return -3;
unless (PSYC_matches("_fail", 0, "_failure_unsuccessful_delivery_death", 0)) return -4;
unless (PSYC_matches("_truthahn", 0, "_failure_unsuccessful_delivery_death", 0)) return -5;
puts("PSYC_matches passed all tests.");
unless (PSYC_inherits("_failure_delivery", 0, "_failure_unsuccessful_delivery_death", 0)) return -11;
if (PSYC_inherits("_failure_unsuccessful", 0, "_failure_unsuccessful_delivery_death", 0)) return -12;
unless (PSYC_inherits("_fail", 0, "_failure_unsuccessful_delivery_death", 0)) return -13;
puts("PSYC_inherits passed all tests.");
return 0; // passed all tests
}

81
test/testParser.c Normal file
View file

@ -0,0 +1,81 @@
#include <psyc.h>
#include <psyc/parser.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char** argv)
{
int index, ret;
uint8_t buffer[2048], modifier;
PSYC_Array name, value, elem;
PSYC_ParseState state;
PSYC_ParseListState listState;
int file = open(argv[1],O_RDONLY);
if(file < 0)
return -1;
index = read(file,(void*)buffer,sizeof(buffer));
write(1, ">> INPUT\n", 9);
write(1, buffer, index);
write(1, ">> PARSE\n", 9);
PSYC_initState(&state);
PSYC_nextBuffer(&state, PSYC_createArray(buffer, index));
// try parsing that now
while ((ret = PSYC_parse(&state, &modifier, &name, &value)))
{
switch (ret)
{
case PSYC_ROUTING:
case PSYC_ENTITY:
write(1, &modifier, 1);
case PSYC_BODY:
// printf("the string is '%.*s'\n", name);
write(1, name.ptr, name.length);
write(1, " = ", 3);
write(1, value.ptr, value.length);
write(1, "\n", 1);
if (memcmp(name.ptr, "_list", 5) == 0)
{
write(1, ">>> LIST START\n", 15);
PSYC_initListState(&listState);
PSYC_nextListBuffer(&listState, value);
while ((ret = PSYC_parseList(&listState, &name, &value, &elem)))
{
switch (ret)
{
case PSYC_LIST_END:
case PSYC_LIST_ELEM:
write(1, "|", 1);
write(1, elem.ptr, elem.length);
write(1, "\n", 1);
break;
default:
printf("Error while parsing list: %i\n", ret);
return 1;
}
if (ret == PSYC_LIST_END)
{
write(1, ">>> LIST END\n", 13);
break;
}
}
}
break;
case PSYC_COMPLETE:
printf("Done parsing.\n");
continue;
case PSYC_INSUFFICIENT:
printf("Insufficient data.\n");
return 0;
default:
printf("Error while parsing: %i\n", ret);
return 1;
}
}
return 0;
}