4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
9 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10 Copyright (c) 2000-2017 Expat development team
11 Licensed under the MIT license:
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to permit
18 persons to whom the Software is furnished to do so, subject to the
21 The above copyright notice and this permission notice shall be included
22 in all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
29 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
30 USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #ifdef HAVE_EXPAT_CONFIG_H
34 # include "expat_config.h"
43 #include "structdata.h"
44 #include "minicheck.h"
46 #define STRUCT_EXTENSION_COUNT 8
48 #ifdef XML_UNICODE_WCHAR_T
50 # define XML_FMT_STR "ls"
51 # define xcstrlen(s) wcslen(s)
52 # define xcstrcmp(s, t) wcscmp((s), (t))
54 # define XML_FMT_STR "s"
55 # define xcstrlen(s) strlen(s)
56 # define xcstrcmp(s, t) strcmp((s), (t))
61 xmlstrdup(const XML_Char *s)
63 size_t byte_count = (xcstrlen(s) + 1) * sizeof(XML_Char);
64 XML_Char *dup = malloc(byte_count);
67 memcpy(dup, s, byte_count);
73 StructData_Init(StructData *storage)
75 assert(storage != NULL);
77 storage->max_count = 0;
78 storage->entries = NULL;
82 StructData_AddItem(StructData *storage,
88 StructDataEntry *entry;
90 assert(storage != NULL);
92 if (storage->count == storage->max_count) {
95 storage->max_count += STRUCT_EXTENSION_COUNT;
96 new = realloc(storage->entries,
97 storage->max_count * sizeof(StructDataEntry));
99 storage->entries = new;
102 entry = &storage->entries[storage->count];
103 entry->str = xmlstrdup(s);
104 entry->data0 = data0;
105 entry->data1 = data1;
106 entry->data2 = data2;
110 /* 'fail()' aborts the function via a longjmp, so there is no point
111 * in returning a value from this function.
114 StructData_CheckItems(StructData *storage,
115 const StructDataEntry *expected,
121 assert(storage != NULL);
122 assert(expected != NULL);
123 if (count != storage->count) {
124 sprintf(buffer, "wrong number of entries: got %d, expected %d",
125 storage->count, count);
126 StructData_Dispose(storage);
129 for (i = 0; i < count; i++)
131 const StructDataEntry *got = &storage->entries[i];
132 const StructDataEntry *want = &expected[i];
134 if (xcstrcmp(got->str, want->str) != 0) {
135 StructData_Dispose(storage);
136 fail("structure got bad string");
138 if (got->data0 != want->data0 ||
139 got->data1 != want->data1 ||
140 got->data2 != want->data2) {
142 "struct '%" XML_FMT_STR
143 "' expected (%d,%d,%d), got (%d,%d,%d)",
145 want->data0, want->data1, want->data2,
146 got->data0, got->data1, got->data2);
147 StructData_Dispose(storage);
154 StructData_Dispose(StructData *storage)
158 assert(storage != NULL);
159 for (i = 0; i < storage->count; i++)
160 free((void *)storage->entries[i].str);
161 free(storage->entries);