mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-08 06:29:23 +00:00
Move byte_character_handler out of runtests.c
This commit is contained in:
parent
bf11ca9025
commit
991924c7da
3 changed files with 39 additions and 34 deletions
|
@ -47,6 +47,8 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "expat_config.h"
|
||||
|
||||
#include "expat.h"
|
||||
#include "internal.h"
|
||||
#include "chardata.h"
|
||||
|
@ -704,6 +706,34 @@ rsqb_handler(void *userData, const XML_Char *s, int len) {
|
|||
*pfound = 1;
|
||||
}
|
||||
|
||||
void XMLCALL
|
||||
byte_character_handler(void *userData, const XML_Char *s, int len) {
|
||||
#ifdef XML_CONTEXT_BYTES
|
||||
int offset, size;
|
||||
const char *buffer;
|
||||
ByteTestData *data = (ByteTestData *)userData;
|
||||
|
||||
UNUSED_P(s);
|
||||
buffer = XML_GetInputContext(g_parser, &offset, &size);
|
||||
if (buffer == NULL)
|
||||
fail("Failed to get context buffer");
|
||||
if (offset != data->start_element_len)
|
||||
fail("Context offset in unexpected position");
|
||||
if (len != data->cdata_len)
|
||||
fail("CDATA length reported incorrectly");
|
||||
if (size != data->total_string_len)
|
||||
fail("Context size is not full buffer");
|
||||
if (XML_GetCurrentByteIndex(g_parser) != offset)
|
||||
fail("Character byte index incorrect");
|
||||
if (XML_GetCurrentByteCount(g_parser) != len)
|
||||
fail("Character byte count incorrect");
|
||||
#else
|
||||
UNUSED_P(s);
|
||||
UNUSED_P(userData);
|
||||
UNUSED_P(len);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Handlers that record their invocation by single characters */
|
||||
|
||||
void XMLCALL
|
||||
|
|
|
@ -249,6 +249,15 @@ extern void XMLCALL cr_cdata_handler(void *userData, const XML_Char *s,
|
|||
|
||||
extern void XMLCALL rsqb_handler(void *userData, const XML_Char *s, int len);
|
||||
|
||||
typedef struct ByteTestData {
|
||||
int start_element_len;
|
||||
int cdata_len;
|
||||
int total_string_len;
|
||||
} ByteTestData;
|
||||
|
||||
extern void XMLCALL byte_character_handler(void *userData, const XML_Char *s,
|
||||
int len);
|
||||
|
||||
/* Handlers that record their invocation by single characters */
|
||||
|
||||
extern void XMLCALL record_default_handler(void *userData, const XML_Char *s,
|
||||
|
|
|
@ -75,40 +75,6 @@
|
|||
XML_Parser g_parser = NULL;
|
||||
|
||||
/* Test position information in handler */
|
||||
typedef struct ByteTestData {
|
||||
int start_element_len;
|
||||
int cdata_len;
|
||||
int total_string_len;
|
||||
} ByteTestData;
|
||||
|
||||
static void
|
||||
byte_character_handler(void *userData, const XML_Char *s, int len) {
|
||||
#ifdef XML_CONTEXT_BYTES
|
||||
int offset, size;
|
||||
const char *buffer;
|
||||
ByteTestData *data = (ByteTestData *)userData;
|
||||
|
||||
UNUSED_P(s);
|
||||
buffer = XML_GetInputContext(g_parser, &offset, &size);
|
||||
if (buffer == NULL)
|
||||
fail("Failed to get context buffer");
|
||||
if (offset != data->start_element_len)
|
||||
fail("Context offset in unexpected position");
|
||||
if (len != data->cdata_len)
|
||||
fail("CDATA length reported incorrectly");
|
||||
if (size != data->total_string_len)
|
||||
fail("Context size is not full buffer");
|
||||
if (XML_GetCurrentByteIndex(g_parser) != offset)
|
||||
fail("Character byte index incorrect");
|
||||
if (XML_GetCurrentByteCount(g_parser) != len)
|
||||
fail("Character byte count incorrect");
|
||||
#else
|
||||
UNUSED_P(s);
|
||||
UNUSED_P(userData);
|
||||
UNUSED_P(len);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define START_ELEMENT "<e>"
|
||||
#define CDATA_TEXT "Hello"
|
||||
#define END_ELEMENT "</e>"
|
||||
|
|
Loading…
Add table
Reference in a new issue