diff --git a/test/Makefile.in b/test/Makefile.in new file mode 100644 index 00000000..ba09faf8 --- /dev/null +++ b/test/Makefile.in @@ -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 diff --git a/test/parser.c b/test/parser.c new file mode 100644 index 00000000..a347a632 --- /dev/null +++ b/test/parser.c @@ -0,0 +1,238 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +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=&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\" ", "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: ", "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: '' +markHTML utan: ' ' +markHTML elott: '' +markHTML utan: ' ' +markHTML elott: '
' +markHTML utan: ' ' +markHTML elott: '

' +markHTML utan: ' ' +markHTML elott: ' ' +markHTML utan: ' ' +markHTML elott: ' ' +markHTML utan: '' + +markHTML elott: ' - =F4=F8=F1=ED =E7=E9=F0=ED!

' +markHTML utan: ' ' +markHTML elott: '

' +markHTML utan: '' + +markHTML elott: '

' +markHTML utan: '' +markHTML elott: ' +

' +markHTML utan: ' + ' + + +markHTML elott: ' xxxxxx =E4=F6=F2=E5=FA =F2=E1=E5=E3=E4, =E3=E9=F8=E5=FA,' +markHTML utan: ', =E3=E9=F8=E5=FA ,' + +markHTML elott: ' =F8=EB=E1, =E9=E3 =F9=F0=E9=E9=E4 ,=' +markHTML utan: ' =F8=EB=E1 , =E9=E3 =F9=F0=E9=E9=E4 ,=' +markHTML elott: 'http://www.vipplayerp.com/<=' +markHTML utan: 'http://www.vipplayerp.com/ ' +markHTML elott: '/p>' +markHTML utan: '' +markHTML elott: '
' +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("", " ", &state); + count += test_html("jackpot!

", "jackpot! ", &state); + count += test_html("

Enjoy your game, and then enjoy your =", " Enjoy your game, and then enjoy your =", &state); + count += test_html("

ooooo", " ooooo", &state); + count += test_html(" ", " ", &state); + count += test_html("

", " ", &state); + count += test_html("
", " ", &state); + count += test_html("Viagra50/100mg - $1.85 |BUY NOW|
", " Viagra50/100mg - $1.85 |BUY NOW| ", &state); + count += test_html("High Qua1ityMedications + Discount On All Reorders +
", "High Qua1ityMedications + Discount On All Reorders + ", &state); + count += test_html("Free Shipping Options + Free Pills With Every Order = Best Deal Ever!
''''''''''click here''''''''''

", " 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("", " ", &state); + count += test_html("