mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 18:40:13 +01:00
added some parser tests
This commit is contained in:
parent
a4be8eef0d
commit
5324e138f4
44
test/Makefile.in
Normal file
44
test/Makefile.in
Normal file
@ -0,0 +1,44 @@
|
||||
SHELL = @SHELL@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
includedir = @includedir@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
mandir = @mandir@
|
||||
datarootdir = @datarootdir@
|
||||
localstatedir = @localstatedir@
|
||||
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@ @CPPFLAGS@
|
||||
DEFS = @defs@
|
||||
INCDIR = -I. -I.. -I../.. -I../../src -I../src @INCDIR@ @mysql_includes@
|
||||
LIBDIR = -L. @LIBDIR@ @LDFLAGS@ -L../../src
|
||||
LIBS = @LIBS@ @mysql_libs@
|
||||
RUNNING_USER = @RUNNING_USER@
|
||||
RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)`
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
|
||||
all: parser view
|
||||
|
||||
parser: parser.c ../src/libpiler.a
|
||||
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ -lpiler $(LIBS) $(LIBDIR)
|
||||
|
||||
view: view.c ../src/libpiler.a
|
||||
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $^ -lpiler $(LIBS) $(LIBDIR)
|
||||
|
||||
install:
|
||||
|
||||
test:
|
||||
./parser
|
||||
|
||||
clean:
|
||||
rm -f parser view
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile
|
238
test/parser.c
Normal file
238
test/parser.c
Normal file
@ -0,0 +1,238 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
int test_url(char *url, char *expected_result){
|
||||
char buf[SMALLBUFSIZE];
|
||||
|
||||
snprintf(buf, sizeof(buf)-1, "%s", url);
|
||||
fixURL(buf);
|
||||
|
||||
if(strcmp(buf, expected_result)){
|
||||
printf("FAILED: '%s' => fixed: '%s', expected: '%s'\n", url, buf, expected_result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int test_translate(char *what, char *expected, struct _state *state){
|
||||
char buf[SMALLBUFSIZE];
|
||||
|
||||
snprintf(buf, sizeof(buf)-1, "%s", what);
|
||||
|
||||
translateLine((unsigned char*)buf, state);
|
||||
|
||||
if(strcmp(buf, expected)){
|
||||
printf("FAILED: '%s' => fixed: '%s', expected: '%s'\n", what, buf, expected);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int test_urls(){
|
||||
int count=0;
|
||||
|
||||
count += test_url("http://sourceforge.net/projects/blogsmanager/", "__URL__sourceforgeXnet ");
|
||||
count += test_url("http://localhost/blogs/_authors_list.php?a=search&value=1&SearchFor=muuratsalo&SearchOption=Contains&SearchField=[SQL", "__URL__localhost ");
|
||||
count += test_url("http://www.debian.org/security/faq", "__URL__wwwXdebianXorg ");
|
||||
count += test_url("http://www.debian.org/", "__URL__wwwXdebianXorg ");
|
||||
count += test_url("https://www.debian.org", "__URL__wwwXdebianXorg ");
|
||||
count += test_url("HTTP://www.debian.o", "__URL__wwwXdebianXo ");
|
||||
count += test_url("http://www.debian.", "__URL__wwwXdebian ");
|
||||
count += test_url("www.debian.org", "__URL__wwwXdebianXorg ");
|
||||
count += test_url("http://web.nvd.nist.gov/view/vuln/detail?vulnId=3DCVE-2011-3892", "__URL__webXnvdXnistXgov ");
|
||||
count += test_url("http://bugs.sitracker.org/view.php?id=1737", "__URL__bugsXsitrackerXorg ");
|
||||
count += test_url("http://googlechromereleases.blogspot.com/2011/11/stable-channel-update.ht", "__URL__googlechromereleasesXblogspotXcom ");
|
||||
count += test_url("http://security.gentoo.org/glsa/glsa-201111-05.xml", "__URL__securityXgentooXorg ");
|
||||
count += test_url("https://bugs.gentoo.org.", "__URL__bugsXgentooXorg ");
|
||||
count += test_url("https://bugs.gentoo.org./ajajajajaaj", "__URL__bugsXgentooXorg ");
|
||||
count += test_url("http://creativecommons.org/licenses/by-sa/2.5", "__URL__creativecommonsXorg ");
|
||||
count += test_url("http://www.site.com/[path]/wp-content/plugins/advanced-text-widget/advancedtext.php?page=[xss]", "__URL__wwwXsiteXcom ");
|
||||
count += test_url("http://canadamedshealth.ru", "__URL__canadamedshealthXru ");
|
||||
count += test_url("http://[HOSTNAME]:4848/configuration/httpListenerEdit.jsf?name=<script>alert(document.cookie);</script>&configName=server-config", "__URL__[HOSTNAME]:4848 ");
|
||||
count += test_url("http://go.theregister.com/news/http://www.theregister.co.uk/2007/07/", "__URL__goXtheregisterXcom ");
|
||||
count += test_url("http://dl.shadowserver.org/IpE6yFKxIPARB8447vAQoyeVtbs?Rq123jTRTTrzApVs0vTzyQ", "__URL__dlXshadowserverXorg ");
|
||||
count += test_url("http://dl.shadowserver.org/IpE6yFKx%EAPARB8447vAQoyeVtbs?Rq123jTRTTrzApVs0vTzyQ", "__URL__dlXshadowserverXorg ");
|
||||
count += test_url("", "");
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
int test_translates(){
|
||||
int count=0;
|
||||
struct _state state;
|
||||
|
||||
init_state(&state);
|
||||
|
||||
count += test_translate("To: \"Suto, Janos\" <Janos.Suto@foo.bar>", "To Suto Janos Janos.Suto@foo.bar", &state);
|
||||
count += test_translate("Ez most akkor beteg, vagy sem?", "Ez most akkor beteg vagy sem ", &state);
|
||||
count += test_translate("MAIL FROM: <zoltan.szabo@zte.com.cn>", "MAIL FROM zoltan.szabo@zte.com.cn ", &state);
|
||||
count += test_translate("Enjoy your game, and then enjoy your jackpot!", "Enjoy your game and then enjoy your jackpot!", &state);
|
||||
count += test_translate("Az Ãn által megküldött,", "Az Ãn által megküldött ", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
count += test_translate("", "", &state);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
markHTML elott: '</head>'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: '<body>'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: '<div class=3D"Section1">'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: ' <p class=3D"style1">'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: ' <b>'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: ' <span dir=3D"rtl" lang=3D"HE"=20'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: ' style=3D"FONT-SIZE: 14pt; FONT-FAMILY: Arial; mso-fareast-l='
|
||||
markHTML utan: ''
|
||||
markHTML elott: 'anguage: EN-US">'
|
||||
markHTML utan: ''
|
||||
|
||||
markHTML elott: ' - </span><span class=3D"style5">=F4=F8=F1=ED =E7=E9=F0=ED!</span></spa='
|
||||
markHTML utan: ' - =F4=F8=F1=ED =E7=E9=F0=ED! '
|
||||
markHTML elott: 'n><o:p></o:p></p>'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: ' <p class=3D"style1"=20'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: ' style=3D"FONT-WEIGHT: bold; FONT-SIZE: x-large; COLOR: #ff0000;='
|
||||
markHTML utan: ''
|
||||
markHTML elott: ' FONT-FAMILY: Arial">'
|
||||
markHTML utan: ''
|
||||
|
||||
markHTML elott: ' <p class=3D"style1"=20'
|
||||
markHTML utan: ' '
|
||||
markHTML elott: ' style=3D"FONT-WEIGHT: bold; FONT-SIZE: x-large; COLOR: #ff0000;='
|
||||
markHTML utan: ''
|
||||
markHTML elott: ' FONT-FAMILY: Arial">'
|
||||
markHTML utan: ''
|
||||
markHTML elott: ' +</p>'
|
||||
markHTML utan: ' + '
|
||||
|
||||
|
||||
markHTML elott: ' <span class=3D"style">xxxxxx =E4=F6=F2=E5=FA =F2=E1=E5=E3=E4</span><s='
|
||||
markHTML utan: ' xxxxxx =E4=F6=F2=E5=FA =F2=E1=E5=E3=E4 '
|
||||
markHTML elott: 'pan class=3D"style1">, <b><i>=E3=E9=F8=E5=FA</i></b>,'
|
||||
markHTML utan: ', =E3=E9=F8=E5=FA ,'
|
||||
|
||||
markHTML elott: ' <b><i>=F8=EB=E1</i></b>, <b><i>=E9=E3 =F9=F0=E9=E9=E4</i></b> ,='
|
||||
markHTML utan: ' =F8=EB=E1 , =E9=E3 =F9=F0=E9=E9=E4 ,='
|
||||
markHTML elott: '</span></span><span class=3D"style1"></span><span=20'
|
||||
markHTML utan: ' '
|
||||
|
||||
markHTML elott: '<p class=3DMsoNormal><o:p><a ='
|
||||
markHTML utan: ' '
|
||||
markHTML elott: 'href=3D"http://www.ipplayerp.com/">http://www.vipplayerp.com/</a></o:p><='
|
||||
markHTML utan: 'http://www.vipplayerp.com/ '
|
||||
markHTML elott: '/p>'
|
||||
markHTML utan: ''
|
||||
markHTML elott: '</div>'
|
||||
markHTML utan: ' '*/
|
||||
|
||||
|
||||
|
||||
int test_html(char *what, char *expected, struct _state *state){
|
||||
char buf[SMALLBUFSIZE];
|
||||
|
||||
snprintf(buf, sizeof(buf)-1, "%s", what);
|
||||
|
||||
markHTML(buf, state);
|
||||
|
||||
if(strcmp(buf, expected)){
|
||||
printf("FAILED: '%s' => fixed: '%s', expected: '%s'\n", what, buf, expected);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//printf("OK: '%s' => fixed: '%s', expected: '%s'\n", what, buf, expected);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int test_htmls(){
|
||||
int count=0;
|
||||
struct _state state;
|
||||
|
||||
init_state(&state);
|
||||
|
||||
count += test_html("</div>", " ", &state);
|
||||
count += test_html("jackpot!</o:p></p>", "jackpot! ", &state);
|
||||
count += test_html("<p class=3DMsoNormal><o:p>Enjoy your game, and then enjoy your =", " Enjoy your game, and then enjoy your =", &state);
|
||||
count += test_html(" <p class style>ooooo", " ooooo", &state);
|
||||
count += test_html(" ", " ", &state);
|
||||
count += test_html("<html><center><table border=10 cellspacing=0 cellpadding=10 bordercolor=C0C0C0 width=600>", " ", &state);
|
||||
count += test_html("<td bgcolor=FFFFFF align=center><font size=3 face=Dotum color=5F5F5F>", " ", &state);
|
||||
count += test_html("<font size=5 color=0000FF><b>Viagra50/100mg - $1.85 |BUY NOW|</b></font><br>", " Viagra50/100mg - $1.85 |BUY NOW| ", &state);
|
||||
count += test_html("High Qua1ityMedications + Discount On All Reorders +<br>", "High Qua1ityMedications + Discount On All Reorders + ", &state);
|
||||
count += test_html("<a href=http://canadamedshealth.ru target=_blank><img src = http://aaa.fu/1.gif><font size=2 color=D90000><b>Free Shipping Options + Free Pills With Every Order = Best Deal Ever!<br>''''''''''click here''''''''''</b></font></a><br></font></td></tr></table></center></html>", " Free Shipping Options + Free Pills With Every Order = Best Deal Ever! ''''''''''click here'''''''''", &state);
|
||||
count += test_html("http://bbb.fu/2.gif", "http://bbb.fu/2.gif", &state);
|
||||
|
||||
count += test_html("<html>", " ", &state);
|
||||
count += test_html(" <style type=3D\"text/css\">", " ", &state);
|
||||
count += test_html(" <span class=3D\"style3\">=E2=ED =E1=F1=FA=E9=E5 =E9=F9 =EE=E1=F6=F2=", " =E2=ED =E1=F1=FA=E9=E5 =E9=F9 =EE=E1=F6=F2=", &state);
|
||||
count += test_html("=E9=ED =E1</span> <a href=3D\"http://www=2Eybay=2Eco=2Eil/\">=E0=E9=F0=E3=", "=E9=ED =E1 =E0=E9=F0=E3=", &state);
|
||||
count += test_html("=F7=F1 =F2=F1=F7=E9=ED</a><o:p></o:p></span></b></p>", "=F7=F1 =F2=F1=F7=E9=ED ", &state);
|
||||
count += test_html(" <span dir=3D\"rtl\" lang=3D\"HE\"=20", " ", &state);
|
||||
count += test_html("", "", &state);
|
||||
count += test_html("", "", &state);
|
||||
count += test_html("", "", &state);
|
||||
count += test_html("", "", &state);
|
||||
count += test_html("", "", &state);
|
||||
|
||||
state.htmltag = 1;
|
||||
count += test_html("span></p>llll", " llll", &state);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int n;
|
||||
struct __config cfg;
|
||||
|
||||
cfg = read_config(CONFIG_FILE);
|
||||
|
||||
n = test_urls();
|
||||
printf("testing fixURL(), errors: %d\n", n);
|
||||
|
||||
|
||||
n = test_translates();
|
||||
printf("testing translateLine(), errors: %d\n", n);
|
||||
|
||||
|
||||
n = test_htmls();
|
||||
printf("testing markHTML(), errors: %d\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
60
test/view.c
Normal file
60
test/view.c
Normal file
@ -0,0 +1,60 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
struct stat st;
|
||||
struct session_data sdata;
|
||||
struct _state state;
|
||||
struct __config cfg;
|
||||
|
||||
|
||||
if(argc < 2){
|
||||
fprintf(stderr, "usage: %s <message>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(stat(argv[1], &st) != 0){
|
||||
fprintf(stderr, "%s is not found\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
cfg = read_config(CONFIG_FILE);
|
||||
|
||||
|
||||
init_session_data(&sdata);
|
||||
|
||||
sdata.sent = 0;
|
||||
sdata.tot_len = st.st_size;
|
||||
|
||||
snprintf(sdata.ttmpfile, SMALLBUFSIZE-1, "%s", argv[1]);
|
||||
snprintf(sdata.filename, SMALLBUFSIZE-1, "%s", argv[1]);
|
||||
snprintf(sdata.tmpframe, SMALLBUFSIZE-1, "%s.m", argv[1]);
|
||||
|
||||
state = parse_message(&sdata, 0, &cfg);
|
||||
post_parse(&sdata, &state, &cfg);
|
||||
|
||||
printf("message-id: %s\n", state.message_id);
|
||||
printf("from: *%s (%s)*\n", state.b_from, state.b_from_domain);
|
||||
printf("to: *%s (%s)*\n", state.b_to, state.b_to_domain);
|
||||
printf("reference: *%s*\n", state.reference);
|
||||
printf("subject: *%s*\n", state.b_subject);
|
||||
printf("body: *%s*\n", state.b_body);
|
||||
|
||||
printf("sent: %ld\n", sdata.sent);
|
||||
|
||||
make_digests(&sdata, &cfg);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user