tests: Move last remaining handlers from common.{c,h} to handlers.{c,h}

This commit is contained in:
Sebastian Pipping 2024-09-22 00:39:40 +02:00
parent fe9251de69
commit 4d2e3b5f38
4 changed files with 37 additions and 39 deletions

View file

@ -51,6 +51,7 @@
#include "chardata.h"
#include "minicheck.h"
#include "common.h"
#include "handlers.h"
/* Common test data */
@ -221,30 +222,6 @@ _expect_failure(const char *text, enum XML_Error errorCode,
_xml_failure(g_parser, file, lineno);
}
/* Character data support for handlers, built on top of the code in
* chardata.c
*/
void XMLCALL
accumulate_characters(void *userData, const XML_Char *s, int len) {
CharData_AppendXMLChars((CharData *)userData, s, len);
}
void XMLCALL
accumulate_attribute(void *userData, const XML_Char *name,
const XML_Char **atts) {
CharData *storage = (CharData *)userData;
UNUSED_P(name);
/* Check there are attributes to deal with */
if (atts == NULL)
return;
while (storage->count < 0 && atts[0] != NULL) {
/* "accumulate" the value of the first attribute we see */
CharData_AppendXMLChars(storage, atts[1], -1);
atts += 2;
}
}
void
_run_character_check(const char *text, const XML_Char *expected,
const char *file, int line) {
@ -273,12 +250,6 @@ _run_attribute_check(const char *text, const XML_Char *expected,
CharData_CheckXMLChars(&storage, expected);
}
void XMLCALL
ext_accumulate_characters(void *userData, const XML_Char *s, int len) {
ExtTest *test_data = (ExtTest *)userData;
accumulate_characters(test_data->storage, s, len);
}
void
_run_ext_character_check(const char *text, ExtTest *test_data,
const XML_Char *expected, const char *file, int line) {

View file

@ -111,12 +111,6 @@ extern void _expect_failure(const char *text, enum XML_Error errorCode,
/* Support functions for handlers to collect up character and attribute data.
*/
extern void XMLCALL accumulate_characters(void *userData, const XML_Char *s,
int len);
extern void XMLCALL accumulate_attribute(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void _run_character_check(const char *text, const XML_Char *expected,
const char *file, int line);
@ -135,9 +129,6 @@ typedef struct ExtTest {
CharData *storage;
} ExtTest;
extern void XMLCALL ext_accumulate_characters(void *userData, const XML_Char *s,
int len);
extern void _run_ext_character_check(const char *text, ExtTest *test_data,
const XML_Char *expected, const char *file,
int line);

View file

@ -1906,6 +1906,33 @@ accumulate_start_element(void *userData, const XML_Char *name,
CharData_AppendXMLChars(storage, XCS(")\n"), 2);
}
void XMLCALL
accumulate_characters(void *userData, const XML_Char *s, int len) {
CharData_AppendXMLChars((CharData *)userData, s, len);
}
void XMLCALL
accumulate_attribute(void *userData, const XML_Char *name,
const XML_Char **atts) {
CharData *storage = (CharData *)userData;
UNUSED_P(name);
/* Check there are attributes to deal with */
if (atts == NULL)
return;
while (storage->count < 0 && atts[0] != NULL) {
/* "accumulate" the value of the first attribute we see */
CharData_AppendXMLChars(storage, atts[1], -1);
atts += 2;
}
}
void XMLCALL
ext_accumulate_characters(void *userData, const XML_Char *s, int len) {
ExtTest *test_data = (ExtTest *)userData;
accumulate_characters(test_data->storage, s, len);
}
void XMLCALL
checking_default_handler(void *userData, const XML_Char *s, int len) {
DefaultCheck *data = (DefaultCheck *)userData;

View file

@ -573,6 +573,15 @@ extern void XMLCALL accumulate_start_element(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL accumulate_characters(void *userData, const XML_Char *s,
int len);
extern void XMLCALL accumulate_attribute(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL ext_accumulate_characters(void *userData, const XML_Char *s,
int len);
typedef struct default_check {
const XML_Char *expected;
const int expectedLen;