diff options
author | Dodji Seketeli <dodji@src.gnome.org> | 2003-03-05 23:16:57 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-03-05 23:16:57 +0000 |
commit | 0477c340c8e20f1d32164f1f193134777ddf3d44 (patch) | |
tree | 673b51819b1674d55c34c9cddc3151c6c79e66c3 | |
parent | d1650e53ce528e1a03cc646dc97a60c81186bad9 (diff) | |
download | libcroco-0477c340c8e20f1d32164f1f193134777ddf3d44.tar.gz |
added the test5 to test the selection engine.
-rw-r--r-- | tests/Makefile.in | 405 | ||||
-rw-r--r-- | tests/test5-main.c | 233 |
2 files changed, 233 insertions, 405 deletions
diff --git a/tests/Makefile.in b/tests/Makefile.in deleted file mode 100644 index 38341d4..0000000 --- a/tests/Makefile.in +++ /dev/null @@ -1,405 +0,0 @@ -# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am - -# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -#SUBDIRS=test-inputs - - -SHELL = @SHELL@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include - -DESTDIR = - -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ - -top_builddir = .. - -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - -INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -transform = @program_transform_name@ - -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -host_alias = @host_alias@ -host_triplet = @host@ -AS = @AS@ -AWK = @AWK@ -CC = @CC@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CROCO_CFLAGS = @CROCO_CFLAGS@ -CROCO_LIBS = @CROCO_LIBS@ -DLLTOOL = @DLLTOOL@ -ECHO = @ECHO@ -EXEEXT = @EXEEXT@ -LIBCROCO_MAJOR_VERSION = @LIBCROCO_MAJOR_VERSION@ -LIBCROCO_MICRO_VERSION = @LIBCROCO_MICRO_VERSION@ -LIBCROCO_MINOR_VERSION = @LIBCROCO_MINOR_VERSION@ -LIBCROCO_VERSION = @LIBCROCO_VERSION@ -LIBCROCO_VERSION_INFO = @LIBCROCO_VERSION_INFO@ -LIBCROCO_VERSION_NUMBER = @LIBCROCO_VERSION_NUMBER@ -LIBTOOL = @LIBTOOL@ -LIBXML2_CFLAGS = @LIBXML2_CFLAGS@ -LIBXML2_LIBS = @LIBXML2_LIBS@ -LN_S = @LN_S@ -MAKEINFO = @MAKEINFO@ -OBJDUMP = @OBJDUMP@ -OBJEXT = @OBJEXT@ -PACKAGE = @PACKAGE@ -PKG_CONFIG = @PKG_CONFIG@ -RANLIB = @RANLIB@ -REQUIRE_LIBXML2 = @REQUIRE_LIBXML2@ -STRIP = @STRIP@ -U = @U@ -VERSION = @VERSION@ -WITH_SELENG = @WITH_SELENG@ - -noinst_PROGRAMS = test0 test1 test2 test3 test4 test5 -test0_SOURCES = test0-main.c -test1_SOURCES = test1-main.c -test2_SOURCES = test2-main.c cr-test-utils.c cr-test-utils.h -test3_SOURCES = test3-main.c cr-test-utils.c cr-test-utils.h -test4_SOURCES = test4-main.c cr-test-utils.c cr-test-utils.h -test5_SOURCES = test5-main.c cr-test-utils.c cr-test-utils.h - -LDADD = $(top_srcdir)/src/libcroco.la - -INCLUDES = -I$(top_srcdir)/intl -I$(top_srcdir)/src `pkg-config --cflags glib-2.0` - - -LDFLAGS = `pkg-config --libs glib-2.0` @LIBXML2_LIBS@ -AM_CFLAGS = -Wall -I. @LIBXML2_CFLAGS@ -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = ../libcroco-config.h -CONFIG_CLEAN_FILES = -noinst_PROGRAMS = test0$(EXEEXT) test1$(EXEEXT) test2$(EXEEXT) \ -test3$(EXEEXT) test4$(EXEEXT) test5$(EXEEXT) -PROGRAMS = $(noinst_PROGRAMS) - - -DEFS = @DEFS@ -I. -I$(srcdir) -I.. -CPPFLAGS = @CPPFLAGS@ -LIBS = @LIBS@ -test0_OBJECTS = test0-main.$(OBJEXT) -test0_LDADD = $(LDADD) -test0_DEPENDENCIES = $(top_srcdir)/src/libcroco.la -test0_LDFLAGS = -test1_OBJECTS = test1-main.$(OBJEXT) -test1_LDADD = $(LDADD) -test1_DEPENDENCIES = $(top_srcdir)/src/libcroco.la -test1_LDFLAGS = -test2_OBJECTS = test2-main.$(OBJEXT) cr-test-utils.$(OBJEXT) -test2_LDADD = $(LDADD) -test2_DEPENDENCIES = $(top_srcdir)/src/libcroco.la -test2_LDFLAGS = -test3_OBJECTS = test3-main.$(OBJEXT) cr-test-utils.$(OBJEXT) -test3_LDADD = $(LDADD) -test3_DEPENDENCIES = $(top_srcdir)/src/libcroco.la -test3_LDFLAGS = -test4_OBJECTS = test4-main.$(OBJEXT) cr-test-utils.$(OBJEXT) -test4_LDADD = $(LDADD) -test4_DEPENDENCIES = $(top_srcdir)/src/libcroco.la -test4_LDFLAGS = -test5_OBJECTS = test5-main.$(OBJEXT) cr-test-utils.$(OBJEXT) -test5_LDADD = $(LDADD) -test5_DEPENDENCIES = $(top_srcdir)/src/libcroco.la -test5_LDFLAGS = -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -DIST_COMMON = Makefile.am Makefile.in - - -DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) - -TAR = gtar -GZIP_ENV = --best -DEP_FILES = .deps/cr-test-utils.P .deps/test0-main.P .deps/test1-main.P \ -.deps/test2-main.P .deps/test3-main.P .deps/test4-main.P \ -.deps/test5-main.P -SOURCES = $(test0_SOURCES) $(test1_SOURCES) $(test2_SOURCES) $(test3_SOURCES) $(test4_SOURCES) $(test5_SOURCES) -OBJECTS = $(test0_OBJECTS) $(test1_OBJECTS) $(test2_OBJECTS) $(test3_OBJECTS) $(test4_OBJECTS) $(test5_OBJECTS) - -all: all-redirect -.SUFFIXES: -.SUFFIXES: .S .c .lo .o .obj .s -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && $(AUTOMAKE) --gnu tests/Makefile - -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) - cd $(top_builddir) \ - && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status - - -mostlyclean-noinstPROGRAMS: - -clean-noinstPROGRAMS: - -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) - -distclean-noinstPROGRAMS: - -maintainer-clean-noinstPROGRAMS: - -# FIXME: We should only use cygpath when building on Windows, -# and only if it is available. -.c.obj: - $(COMPILE) -c `cygpath -w $<` - -.s.o: - $(COMPILE) -c $< - -.S.o: - $(COMPILE) -c $< - -mostlyclean-compile: - -rm -f *.o core *.core - -rm -f *.$(OBJEXT) - -clean-compile: - -distclean-compile: - -rm -f *.tab.c - -maintainer-clean-compile: - -.s.lo: - $(LIBTOOL) --mode=compile $(COMPILE) -c $< - -.S.lo: - $(LIBTOOL) --mode=compile $(COMPILE) -c $< - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -distclean-libtool: - -maintainer-clean-libtool: - -test0$(EXEEXT): $(test0_OBJECTS) $(test0_DEPENDENCIES) - @rm -f test0$(EXEEXT) - $(LINK) $(test0_LDFLAGS) $(test0_OBJECTS) $(test0_LDADD) $(LIBS) - -test1$(EXEEXT): $(test1_OBJECTS) $(test1_DEPENDENCIES) - @rm -f test1$(EXEEXT) - $(LINK) $(test1_LDFLAGS) $(test1_OBJECTS) $(test1_LDADD) $(LIBS) - -test2$(EXEEXT): $(test2_OBJECTS) $(test2_DEPENDENCIES) - @rm -f test2$(EXEEXT) - $(LINK) $(test2_LDFLAGS) $(test2_OBJECTS) $(test2_LDADD) $(LIBS) - -test3$(EXEEXT): $(test3_OBJECTS) $(test3_DEPENDENCIES) - @rm -f test3$(EXEEXT) - $(LINK) $(test3_LDFLAGS) $(test3_OBJECTS) $(test3_LDADD) $(LIBS) - -test4$(EXEEXT): $(test4_OBJECTS) $(test4_DEPENDENCIES) - @rm -f test4$(EXEEXT) - $(LINK) $(test4_LDFLAGS) $(test4_OBJECTS) $(test4_LDADD) $(LIBS) - -test5$(EXEEXT): $(test5_OBJECTS) $(test5_DEPENDENCIES) - @rm -f test5$(EXEEXT) - $(LINK) $(test5_LDFLAGS) $(test5_OBJECTS) $(test5_LDADD) $(LIBS) - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - here=`pwd` && cd $(srcdir) \ - && mkid -f$$here/ID $$unique $(LISP) - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS)'; \ - unique=`for i in $$list; do echo $$i; done | \ - awk ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ - || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) - -mostlyclean-tags: - -clean-tags: - -distclean-tags: - -rm -f TAGS ID - -maintainer-clean-tags: - -distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) - -subdir = tests - -distdir: $(DISTFILES) - here=`cd $(top_builddir) && pwd`; \ - top_distdir=`cd $(top_distdir) && pwd`; \ - distdir=`cd $(distdir) && pwd`; \ - cd $(top_srcdir) \ - && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu tests/Makefile - @for file in $(DISTFILES); do \ - d=$(srcdir); \ - if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ - else \ - test -f $(distdir)/$$file \ - || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ - || cp -p $$d/$$file $(distdir)/$$file || :; \ - fi; \ - done - -DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) - --include $(DEP_FILES) - -mostlyclean-depend: - -clean-depend: - -distclean-depend: - -rm -rf .deps - -maintainer-clean-depend: - -%.o: %.c - @echo '$(COMPILE) -c $<'; \ - $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< - @-cp .deps/$(*F).pp .deps/$(*F).P; \ - tr ' ' '\012' < .deps/$(*F).pp \ - | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ - >> .deps/$(*F).P; \ - rm .deps/$(*F).pp - -%.lo: %.c - @echo '$(LTCOMPILE) -c $<'; \ - $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< - @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ - < .deps/$(*F).pp > .deps/$(*F).P; \ - tr ' ' '\012' < .deps/$(*F).pp \ - | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ - >> .deps/$(*F).P; \ - rm -f .deps/$(*F).pp -info-am: -info: info-am -dvi-am: -dvi: dvi-am -check-am: all-am -check: check-am -installcheck-am: -installcheck: installcheck-am -install-exec-am: -install-exec: install-exec-am - -install-data-am: -install-data: install-data-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -install: install-am -uninstall-am: -uninstall: uninstall-am -all-am: Makefile $(PROGRAMS) -all-redirect: all-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install -installdirs: - - -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) - -rm -f config.cache config.log stamp-h stamp-h[0-9]* - -maintainer-clean-generic: -mostlyclean-am: mostlyclean-noinstPROGRAMS mostlyclean-compile \ - mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ - mostlyclean-generic - -mostlyclean: mostlyclean-am - -clean-am: clean-noinstPROGRAMS clean-compile clean-libtool clean-tags \ - clean-depend clean-generic mostlyclean-am - -clean: clean-am - -distclean-am: distclean-noinstPROGRAMS distclean-compile \ - distclean-libtool distclean-tags distclean-depend \ - distclean-generic clean-am - -rm -f libtool - -distclean: distclean-am - -maintainer-clean-am: maintainer-clean-noinstPROGRAMS \ - maintainer-clean-compile maintainer-clean-libtool \ - maintainer-clean-tags maintainer-clean-depend \ - maintainer-clean-generic distclean-am - @echo "This command is intended for maintainers to use;" - @echo "it deletes files that may require special tools to rebuild." - -maintainer-clean: maintainer-clean-am - -.PHONY: mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \ -clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \ -mostlyclean-compile distclean-compile clean-compile \ -maintainer-clean-compile mostlyclean-libtool distclean-libtool \ -clean-libtool maintainer-clean-libtool tags mostlyclean-tags \ -distclean-tags clean-tags maintainer-clean-tags distdir \ -mostlyclean-depend distclean-depend clean-depend \ -maintainer-clean-depend info-am info dvi-am dvi check check-am \ -installcheck-am installcheck install-exec-am install-exec \ -install-data-am install-data install-am install uninstall-am uninstall \ -all-redirect all-am all installdirs mostlyclean-generic \ -distclean-generic clean-generic maintainer-clean-generic clean \ -mostlyclean distclean maintainer-clean - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/tests/test5-main.c b/tests/test5-main.c new file mode 100644 index 0000000..4121596 --- /dev/null +++ b/tests/test5-main.c @@ -0,0 +1,233 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ + +/* + *This file is part of the Croco Library + * + *The Croco Library 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, + *or (at your option) any later version. + * + *The Croco Library 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 The Croco Library; + *see the file COPYING. If not, write to + *the Free Software Foundation, Inc., + *59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + *Copyright 2002-2003 Dodji Seketeli <dodji@seketeli.org> + */ + +/* + *$Id$ + */ + +#include <string.h> +#include "cr-test-utils.h" +#include "libcroco.h" + + +/** + *@file + *Some test facilities for the #CRParser class. + */ + +CRDocHandler * gv_test_handler = {0} ; + +const guchar *xml_content= +"<document>" +"<E0>text0</E0>" +"<E1><E1-1>text1</E1-1></E1>" +"<E2 attr2=\"val2\">text2</E2>" +"</document>"; + +static void +display_help (char *prg_name) ; + +static void +display_about (char *prg_name) ; + +static enum CRStatus +test_sel_eng (guchar * a_file_uri) ; + +/** + *Displays the usage of the test + *facility. + *@param a_argc the argc variable passed to the main function. + *@param a_argv the argv variable passed to the main function. + */ +static void +display_help (char *prg_name) +{ + g_print ("\n\n") ; + g_print ("usage: %s <file-to-parse>\n", prg_name) ; + g_print ("\t <file-to-parse>: the file to parse\n") ; + g_print ("\n\n") ; + g_print ("Tests the cr_parser_parse () method.\n") ; + g_print ("Tests the parsing following the css core syntax\n") ; + g_print ("Returns OK if the status is CR_OK, KO otherwise\n") ; + g_print ("\n\n") ; +} + +/** + *Displays the about text. + *@param a_argc the argc variable passed to the main function. + *@param a_argv the argv variable passed to the main function. + */ +static void +display_about (char *prg_name) +{ + g_print ("\n\n") ; + g_print ("%s is a libcroco CROMParser class test program.\n", + prg_name) ; + g_print ("%s Parses a file and builds a CSS object model", + prg_name) ; + g_print ("It should run on GNU compliants systems.\n") ; + g_print ("\n\n") ; + g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n") ; + g_print ("\n\n") ; +} + + +/** + *The test of the cr_input_read_byte() method. + *Reads the each byte of a_file_uri using the + *cr_input_read_byte() method. Each byte is send to + *stdout. + *@param a_file_uri the file to read. + *@return CR_OK upon successfull completion of the + *function, an error code otherwise. + */ +static enum CRStatus +test_sel_eng (guchar * a_file_uri) +{ + enum CRStatus status = CR_OK ; + CROMParser *parser = NULL ; + CRStyleSheet *stylesheet = NULL ; + xmlDoc * xml_doc = NULL ; + xmlNode *cur_node = NULL ; + CRSelEng *selection_engine = NULL ; + CRStatement **stmts_tab = NULL ; + gulong tab_len = 0 ; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; + + parser = cr_om_parser_new (NULL) ; + status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, + &stylesheet) ; + if (status != CR_OK || !stylesheet) + { + cr_utils_trace_info ("Could not parse xml content") ; + goto error ; + } + + xml_doc = xmlParseMemory (xml_content, strlen (xml_content)) ; + if (!xml_doc) + { + cr_utils_trace_info ("Could not parse xml content") ; + goto error ; + + } + + selection_engine = cr_sel_eng_new () ; + + cur_node = xml_doc->children->children ; + + status = cr_sel_eng_sel_get_matched_rulesets + (selection_engine, stylesheet, + cur_node, &stmts_tab, &tab_len) ; + + if (parser) + { + cr_om_parser_destroy (parser) ; + parser = NULL ; + } + + if (xml_doc) + { + xmlFreeDoc (xml_doc) ; + xml_doc = NULL ; + } + + if (stylesheet) + { + cr_stylesheet_destroy (stylesheet) ; + stylesheet = NULL ; + } + + xmlCleanupParser () ; + return status ; + + error: + + if (parser) + { + cr_om_parser_destroy (parser) ; + parser = NULL ; + } + + if (xml_doc) + { + xmlFreeDoc (xml_doc) ; + xml_doc = NULL ; + } + + if (stylesheet) + { + cr_stylesheet_destroy (stylesheet) ; + stylesheet = NULL ; + } + + xmlCleanupParser () ; + return CR_ERROR ; +} + + +/** + *The entry point of the testing routine. + */ +int +main (int argc, char ** argv) +{ + struct Options options ; + enum CRStatus status = CR_OK ; + + cr_test_utils_parse_cmd_line (argc, argv, &options) ; + + if (options.display_help == TRUE) + { + display_help (argv[0]) ; + return 0 ; + } + + if (options.display_about == TRUE) + { + display_about (argv[0]) ; + return 0 ; + } + + if (options.files_list == NULL) + { + display_help (argv[0]) ; + return 0 ; + } + + status = test_sel_eng (options.files_list[0]) ; + + if (status == CR_OK) + { + g_print ("\nOK\n") ; + } + else + { + g_print ("\nKO\n") ; + } + + return 0 ; +} |