1 /* Copyright (c) 1998-2003 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
7 #ifdef HAVE_EXPAT_CONFIG_H
8 #include <expat_config.h>
13 #include "minicheck.h"
24 xmlstrlen(const XML_Char *s)
35 CharData_Init(CharData *storage)
37 assert(storage != NULL);
42 CharData_AppendString(CharData *storage, const char *s)
44 int maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
49 if (storage->count < 0)
51 if ((len + storage->count) > maxchars) {
52 len = (maxchars - storage->count);
54 if (len + storage->count < sizeof(storage->data)) {
55 memcpy(storage->data + storage->count, s, len);
56 storage->count += len;
61 CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len)
65 assert(storage != NULL);
67 maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
68 if (storage->count < 0)
72 if ((len + storage->count) > maxchars) {
73 len = (maxchars - storage->count);
75 if (len + storage->count < sizeof(storage->data)) {
76 memcpy(storage->data + storage->count, s,
77 len * sizeof(storage->data[0]));
78 storage->count += len;
83 CharData_CheckString(CharData *storage, const char *expected)
89 assert(storage != NULL);
90 assert(expected != NULL);
91 count = (storage->count < 0) ? 0 : storage->count;
92 len = strlen(expected);
94 if (sizeof(XML_Char) == 1)
95 sprintf(buffer, "wrong number of data characters:"
96 " got %d, expected %d:\n%s", count, len, storage->data);
99 "wrong number of data characters: got %d, expected %d",
104 if (memcmp(expected, storage->data, len) != 0) {
105 fail("got bad data bytes");
112 CharData_CheckXMLChars(CharData *storage, const XML_Char *expected)
115 int len = xmlstrlen(expected);
118 assert(storage != NULL);
119 count = (storage->count < 0) ? 0 : storage->count;
121 sprintf(buffer, "wrong number of data characters: got %d, expected %d",
126 if (memcmp(expected, storage->data, len * sizeof(storage->data[0])) != 0) {
127 fail("got bad data bytes");