From: Jean-Philippe Orsini Date: Wed, 14 Dec 2011 02:20:20 +0000 (+0000) Subject: added test for url_normalize X-Git-Tag: v0.8.0.5~502 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=psensor.git;a=commitdiff_plain;h=a889b0b1a8233103aac529105dc0db9c5864a592 added test for url_normalize --- diff --git a/tests/Makefile.am b/tests/Makefile.am index aa957a0..a030cd1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,8 +4,13 @@ check-local: checkpatch.pl EXTRA_DIST = checkpatch.pl -check_PROGRAMS = test-url-encode +check_PROGRAMS = test-url-encode test-url-normalize + test_url_encode_SOURCES = test_url_encode.c test_url_encode_LDADD = ../src/lib/libpsensor.a -TESTS = test-url-encode \ No newline at end of file +test_url_normalize_SOURCES = test_url_normalize.c +test_url_normalize_LDADD = ../src/lib/libpsensor.a + +TESTS = test-url-encode \ + test-url-normalize \ No newline at end of file diff --git a/tests/Makefile.in b/tests/Makefile.in index 85ec185..4674ec8 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -33,8 +33,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -check_PROGRAMS = test-url-encode$(EXEEXT) -TESTS = test-url-encode$(EXEEXT) +check_PROGRAMS = test-url-encode$(EXEEXT) test-url-normalize$(EXEEXT) +TESTS = test-url-encode$(EXEEXT) test-url-normalize$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -48,6 +48,9 @@ CONFIG_CLEAN_VPATH_FILES = am_test_url_encode_OBJECTS = test_url_encode.$(OBJEXT) test_url_encode_OBJECTS = $(am_test_url_encode_OBJECTS) test_url_encode_DEPENDENCIES = ../src/lib/libpsensor.a +am_test_url_normalize_OBJECTS = test_url_normalize.$(OBJEXT) +test_url_normalize_OBJECTS = $(am_test_url_normalize_OBJECTS) +test_url_normalize_DEPENDENCIES = ../src/lib/libpsensor.a DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -56,8 +59,9 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(test_url_encode_SOURCES) -DIST_SOURCES = $(test_url_encode_SOURCES) +SOURCES = $(test_url_encode_SOURCES) $(test_url_normalize_SOURCES) +DIST_SOURCES = $(test_url_encode_SOURCES) \ + $(test_url_normalize_SOURCES) ETAGS = etags CTAGS = ctags am__tty_colors = \ @@ -212,6 +216,8 @@ top_srcdir = @top_srcdir@ EXTRA_DIST = checkpatch.pl test_url_encode_SOURCES = test_url_encode.c test_url_encode_LDADD = ../src/lib/libpsensor.a +test_url_normalize_SOURCES = test_url_normalize.c +test_url_normalize_LDADD = ../src/lib/libpsensor.a all: all-am .SUFFIXES: @@ -252,6 +258,9 @@ clean-checkPROGRAMS: test-url-encode$(EXEEXT): $(test_url_encode_OBJECTS) $(test_url_encode_DEPENDENCIES) @rm -f test-url-encode$(EXEEXT) $(LINK) $(test_url_encode_OBJECTS) $(test_url_encode_LDADD) $(LIBS) +test-url-normalize$(EXEEXT): $(test_url_normalize_OBJECTS) $(test_url_normalize_DEPENDENCIES) + @rm -f test-url-normalize$(EXEEXT) + $(LINK) $(test_url_normalize_OBJECTS) $(test_url_normalize_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -260,6 +269,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_encode.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_url_normalize.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/tests/test_url_normalize.c b/tests/test_url_normalize.c new file mode 100644 index 0000000..1a76209 --- /dev/null +++ b/tests/test_url_normalize.c @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2010-2011 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + *02110-1301 USA + */ + + +#include +#include +#include +#include + +#include "../src/lib/url.h" + + +int test_url_normalize(const char *url, const char *ref_url) +{ + int ret; + char *tmp = url_normalize(url); + + if (!strcmp(tmp, ref_url)) { + ret = 1; + } else { + fprintf(stderr, + "FAILURE: " + "url_normalize(%s) returns %s instead of %s\n", + url, + tmp, + ref_url); + ret = 0; + } + + free(tmp); + + return ret; +} + + +int tests_url_normalize() +{ + int failures; + + failures = 0; + + if (!test_url_normalize("http://test/test", "http://test/test")) + failures++; + + if (!test_url_normalize("http://test/test/", "http://test/test")) + failures++; + + return failures; +} + +int main(int argc, char **argv) +{ + int failures; + + failures = 0; + + failures += tests_url_normalize(); + + if (failures) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); +}