Skip to content
Snippets Groups Projects
Commit 234f05fc authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Validator: add initializer

There is a method to add a set of tags to a validator on initialisation.
First this removes a user application from the burden of maintaining the
html spec and also is more performant, as a lot of tags are to be
inserted at once, so there aren't multiple allocation calls.
As the validator needs the tags to be in order, the tags must be sorted
on insertion. Of course it would be easier for the code, if the tags
were already in order, but first there could be easily a mistake and
second sorting the tags by an algorithm allows the tags to be specified
in a logically grouped and those more maintainable order.
For the sorting, insertion sort is used. Of course it has a worse
quadratic time complexity, but in a constructor, I wouldn't introduce
the overhead of memory managment a heap- or mergesort would introduce
and in-place sorting is also out, because the data lies in ro-memory.
Thus I choose an algorithm with constant space complexity. Also the
'long' running time is not so important, as the initilization only runs
at startup once and the tags are not likely to exceed a few hundred so
even a quadratic time isn't that bad.
parent 19177ddc
No related branches found
No related tags found
No related merge requests found
......@@ -28,13 +28,13 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=5
current_page=32
FILE_NAME_0=139;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2FREADME;0;8
FILE_NAME_1=134;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitignore;0;8
FILE_NAME_2=1737;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fconfigure.ac;0;8
FILE_NAME_3=73;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2FMakefile.am;0;8
FILE_NAME_4=19;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Fmain.c;0;8
FILE_NAME_5=1131;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2FMakefile.am;0;8
FILE_NAME_5=1091;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2FMakefile.am;0;8
FILE_NAME_6=18;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fcms.c;0;8
FILE_NAME_7=18;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fcms.h;0;8
FILE_NAME_8=19;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fdata.c;0;8
......@@ -58,30 +58,31 @@ FILE_NAME_25=8479;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_26=1083;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_segment.h;0;8
FILE_NAME_27=900;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_segment_mark.c;0;8
FILE_NAME_28=1867;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext_mark_static.c;0;8
FILE_NAME_29=977;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
FILE_NAME_29=1005;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
FILE_NAME_30=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.h;0;8
FILE_NAME_31=995;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8
FILE_NAME_32=1148;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8
FILE_NAME_33=1124;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag_data.h;0;8
FILE_NAME_34=924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fstatus.h;0;8
FILE_NAME_35=18;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Flog.h;0;4
FILE_NAME_36=20;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fmacro.h;0;8
FILE_NAME_37=20;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fsefht.h;0;8
FILE_NAME_38=2902;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2FMakefile.am;0;8
FILE_NAME_39=218;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Fno_test.sh.in;0;8
FILE_NAME_40=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
FILE_NAME_41=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
FILE_NAME_42=8232;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_fragment.c;0;8
FILE_NAME_43=33;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_44=5714;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_fragment.c;0;8
FILE_NAME_45=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_46=4221;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_47=994;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_mark.c;0;8
FILE_NAME_48=3101;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_49=536;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
FILE_NAME_50=201;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4
FILE_NAME_51=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8
FILE_NAME_52=806;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Frelease.sh.in;0;4
FILE_NAME_31=1111;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_html.h;0;8
FILE_NAME_32=5802;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8
FILE_NAME_33=1148;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8
FILE_NAME_34=1124;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag_data.h;0;8
FILE_NAME_35=924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fstatus.h;0;8
FILE_NAME_36=18;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Flog.h;0;4
FILE_NAME_37=20;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fmacro.h;0;8
FILE_NAME_38=20;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fsefht.h;0;8
FILE_NAME_39=2902;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2FMakefile.am;0;8
FILE_NAME_40=218;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Fno_test.sh.in;0;8
FILE_NAME_41=23;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
FILE_NAME_42=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
FILE_NAME_43=8232;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_fragment.c;0;8
FILE_NAME_44=33;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_45=5714;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_fragment.c;0;8
FILE_NAME_46=24;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_47=4221;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_48=994;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_mark.c;0;8
FILE_NAME_49=10556;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_50=536;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
FILE_NAME_51=201;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4
FILE_NAME_52=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8
FILE_NAME_53=806;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Frelease.sh.in;0;4
[VTE]
last_dir=/home/jonathan/Documents/projects/prgm/internet/web/SeFHT/tests
......
......@@ -26,6 +26,7 @@ EXTRA_DIST += sefht/text_data.h
EXTRA_DIST += sefht/text_mark_static.c
EXTRA_DIST += sefht/text_segment.c sefht/text_segment.h
EXTRA_DIST += sefht/text_segment_mark.c
EXTRA_DIST += sefht/validator_html.h
EXTRA_DIST += sefht/validator_tag.c
EXTRA_DIST += sefht/validator_tag_data.h
......
......@@ -68,6 +68,33 @@ SH_Validator_new (/*@null@*/ /*@out@*/ struct SH_Status * status)
return validator;
}
/*@null@*/
/*@only@*/
struct SH_Validator *
SH_Validator_new_html5 (/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
struct SH_Validator * validator;
validator = malloc (sizeof (struct SH_Validator));
if (NULL == validator)
{
set_status (status, E_ALLOC, 4, "malloc failed");
return NULL;
}
if (!init_tags_spec_html5 (validator, status))
{
free (validator);
return NULL;
}
set_success (status);
return validator;
}
/*@null@*/
/*@only@*/
struct SH_Validator *
......
/*
* validator_html.h
*
* Copyright 2023 Jonathan Schöbel <jonathan@xn--schbel-yxa.info>
*
* 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.
*
*
*/
#ifndef SEFHT_VALIDATOR_HTML_H
#define SEFHT_VALIDATOR_HTML_H
#if !defined (SEFHT_COMPILATION)
#error "Only <sefht/sefht.h> can be included directly."
#endif
struct HTML_TAG_DEFINITION
{
/*@observer@*/ const char * tag;
};
const struct HTML_TAG_DEFINITION HTML5[] = {
};
#endif /* SEFHT_VALIDATOR_HTML_H */
......@@ -33,6 +33,8 @@
#include "validator_tag.h"
#include "validator_html.h"
static inline
void
......@@ -44,6 +46,36 @@ init_tags (/*@special@*/ struct SH_Validator * validator)
/*@modifies validator->tag_n@*/
/*@modifies validator->last_tag@*/;
static inline
bool
init_tags_from_spec (/*@special@*/ struct SH_Validator * validator,
const struct HTML_TAG_DEFINITION * tags,
const size_t size,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@defines validator->tags,
validator->tag_n,
validator->last_tag@*/
/*@modifies validator->tags@*/
/*@modifies validator->tag_n@*/
/*@modifies validator->last_tag@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/;
static inline
bool
init_tags_spec_html5 (/*@special@*/ struct SH_Validator * validator,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@defines validator->tags,
validator->tag_n,
validator->last_tag@*/
/*@modifies validator->tags@*/
/*@modifies validator->tag_n@*/
/*@modifies validator->last_tag@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/;
static inline
bool
copy_tags (/*@special@*/ struct SH_Validator * copy,
......@@ -142,6 +174,110 @@ init_tags (/*@special@*/ struct SH_Validator * validator)
return;
}
static inline
bool
init_tags_spec_html5 (/*@special@*/ struct SH_Validator * validator,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@defines validator->tags,
validator->tag_n,
validator->last_tag@*/
/*@modifies validator->tags@*/
/*@modifies validator->tag_n@*/
/*@modifies validator->last_tag@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
size_t size;
size = sizeof (HTML5) / sizeof (HTML5[0]);
return init_tags_from_spec (validator, HTML5, size, status);
}
static inline
bool
init_tags_from_spec (/*@special@*/ struct SH_Validator * validator,
const struct HTML_TAG_DEFINITION * spec,
const size_t size,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@defines validator->tags,
validator->tag_n,
validator->last_tag@*/
/*@modifies validator->tags@*/
/*@modifies validator->tag_n@*/
/*@modifies validator->last_tag@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
size_t index;
Tag id;
/* overflow detection */
if ((size > TAG_MAX - 1)
|| (size >= (SIZE_MAX / sizeof (struct tag_info))))
{
set_status (status, E_DOMAIN, 2,
"maximum number of tags reached");
return FALSE;
}
validator->tags = malloc (sizeof (struct tag_info) * size);
if (NULL == validator->tags)
{
set_status (status, E_ALLOC, 3, "malloc failed");
return FALSE;
}
validator->tag_n = 0;
/* insertion sort */
#define tags validator->tags
#define tag_n validator->tag_n
for (index = 0; index < size; index++)
{
size_t position;
/* ignore duplicate tags */
if (!find_tag (validator, spec[index].tag, &position))
{
char * name;
size_t index2;
name = strdup (spec[index].tag);
if (NULL == name)
{
set_status (status, E_ALLOC, 3,
"strdup failed");
free_tags (validator);
return FALSE;
}
/* only names are initialized */
for (index2 = tag_n; index2 > position; index2--)
{
tags[index2].name = tags[index2-1].name;
}
tags[position].name = name;
tag_n++;
}
}
#undef tag_n
#undef tags
/* initialize ids */
id = TAG_ERR;
for (index = 0; index < validator->tag_n; index++)
{
validator->tags[index].id = id = NEXT_TAG (id);
}
validator->last_tag = id;
set_success (status);
return TRUE;
}
static inline
bool
copy_tag (/*@special@*/ struct tag_info * copy,
......
......@@ -37,6 +37,16 @@
#include "macro.h"
#include "status.h"
/* override HTML spec */
#include "validator_html.h"
const struct HTML_TAG_DEFINITION HTML_[] = {
{"html"},
{"aside"},
{"html"},
{"body"}
};
#define HTML5 HTML_
/* C file is needed, because we want to override SIZE_MAX */
#include "validator.c"
......@@ -72,6 +82,67 @@ START_TEST(test_validator_with_status)
}
END_TEST
START_TEST(test_validator_spec_no_status)
{
struct SH_Validator * validator;
/* test */
validator = SH_Validator_new_html5 (NULL);
ck_assert_ptr_ne (NULL, validator);
ck_assert_ptr_ne (NULL, validator->tags);
ck_assert_int_eq (3, validator->tag_n);
ck_assert_int_eq (3, validator->last_tag);
ck_assert_int_eq (1, validator->tags[0].id);
ck_assert_ptr_ne (HTML_[1].tag, validator->tags[0].name);
ck_assert_str_eq (HTML_[1].tag, validator->tags[0].name);
ck_assert_int_eq (2, validator->tags[1].id);
ck_assert_ptr_ne (HTML_[3].tag, validator->tags[1].name);
ck_assert_str_eq (HTML_[3].tag, validator->tags[1].name);
ck_assert_int_eq (3, validator->tags[2].id);
ck_assert_ptr_ne (HTML_[0].tag, validator->tags[2].name);
ck_assert_str_eq (HTML_[0].tag, validator->tags[2].name);
/* cleanup */
SH_Validator_free (validator);
}
END_TEST
START_TEST(test_validator_spec_with_status)
{
struct SH_Status status;
struct SH_Validator * validator;
/* test */
_status_preinit (status);
validator = SH_Validator_new_html5 (&status);
ck_assert_ptr_ne (NULL, validator);
ck_assert_int_eq (SUCCESS, status.status);
ck_assert_ptr_ne (NULL, validator->tags);
ck_assert_int_eq (3, validator->tag_n);
ck_assert_int_eq (3, validator->last_tag);
ck_assert_int_eq (1, validator->tags[0].id);
ck_assert_ptr_ne (HTML_[1].tag, validator->tags[0].name);
ck_assert_str_eq (HTML_[1].tag, validator->tags[0].name);
ck_assert_int_eq (2, validator->tags[1].id);
ck_assert_ptr_ne (HTML_[3].tag, validator->tags[1].name);
ck_assert_str_eq (HTML_[3].tag, validator->tags[1].name);
ck_assert_int_eq (3, validator->tags[2].id);
ck_assert_ptr_ne (HTML_[0].tag, validator->tags[2].name);
ck_assert_str_eq (HTML_[0].tag, validator->tags[2].name);
/* cleanup */
SH_Validator_free (validator);
}
END_TEST
START_TEST(test_validator_tag_register_no_status)
{
struct SH_Validator * validator;
......@@ -322,6 +393,8 @@ Suite * validator_suite (void)
tcase_add_test (tc_core, test_validator_no_status);
tcase_add_test (tc_core, test_validator_with_status);
tcase_add_test (tc_core, test_validator_spec_no_status);
tcase_add_test (tc_core, test_validator_spec_with_status);
tcase_add_test (tc_core, test_validator_tag_register_no_status);
tcase_add_test (tc_core, test_validator_tag_register_with_status);
tcase_add_test (tc_core, test_validator_tag_check);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment