summaryrefslogtreecommitdiff
path: root/expat/tests/structdata.c
diff options
context:
space:
mode:
authorclang-format <clang-format@example.org>2019-08-03 20:34:54 +0200
committerSebastian Pipping <sebastian@pipping.org>2019-08-03 21:31:44 +0200
commitd248bbd940014d5ef98c97e4733022275e087901 (patch)
tree8c1701b9fa66b32a5eafe71418588c91e4cc0c04 /expat/tests/structdata.c
parentc951711d750db6fd75641f39de9ae9aebef19e86 (diff)
downloadlibexpat-git-d248bbd940014d5ef98c97e4733022275e087901.tar.gz
Mass-apply clang-format 9 using ./apply-clang-format.sh
Diffstat (limited to 'expat/tests/structdata.c')
-rw-r--r--expat/tests/structdata.c183
1 files changed, 84 insertions, 99 deletions
diff --git a/expat/tests/structdata.c b/expat/tests/structdata.c
index 86a5349e..e81b7b18 100644
--- a/expat/tests/structdata.c
+++ b/expat/tests/structdata.c
@@ -31,10 +31,9 @@
*/
#ifdef HAVE_EXPAT_CONFIG_H
-# include "expat_config.h"
+# include "expat_config.h"
#endif
-
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
@@ -46,125 +45,111 @@
#define STRUCT_EXTENSION_COUNT 8
#ifdef XML_UNICODE_WCHAR_T
-# include <wchar.h>
-# define XML_FMT_STR "ls"
-# define xcstrlen(s) wcslen(s)
-# define xcstrcmp(s, t) wcscmp((s), (t))
+# include <wchar.h>
+# define XML_FMT_STR "ls"
+# define xcstrlen(s) wcslen(s)
+# define xcstrcmp(s, t) wcscmp((s), (t))
#else
-# define XML_FMT_STR "s"
-# define xcstrlen(s) strlen(s)
-# define xcstrcmp(s, t) strcmp((s), (t))
+# define XML_FMT_STR "s"
+# define xcstrlen(s) strlen(s)
+# define xcstrcmp(s, t) strcmp((s), (t))
#endif
-
static XML_Char *
-xmlstrdup(const XML_Char *s)
-{
- size_t byte_count = (xcstrlen(s) + 1) * sizeof(XML_Char);
- XML_Char *dup = malloc(byte_count);
-
- assert(dup != NULL);
- memcpy(dup, s, byte_count);
- return dup;
-}
+xmlstrdup(const XML_Char *s) {
+ size_t byte_count = (xcstrlen(s) + 1) * sizeof(XML_Char);
+ XML_Char *dup = malloc(byte_count);
+ assert(dup != NULL);
+ memcpy(dup, s, byte_count);
+ return dup;
+}
void
-StructData_Init(StructData *storage)
-{
- assert(storage != NULL);
- storage->count = 0;
- storage->max_count = 0;
- storage->entries = NULL;
+StructData_Init(StructData *storage) {
+ assert(storage != NULL);
+ storage->count = 0;
+ storage->max_count = 0;
+ storage->entries = NULL;
}
void
-StructData_AddItem(StructData *storage,
- const XML_Char *s,
- int data0,
- int data1,
- int data2)
-{
- StructDataEntry *entry;
-
- assert(storage != NULL);
- assert(s != NULL);
- if (storage->count == storage->max_count) {
- StructDataEntry *new;
-
- storage->max_count += STRUCT_EXTENSION_COUNT;
- new = realloc(storage->entries,
- storage->max_count * sizeof(StructDataEntry));
- assert(new != NULL);
- storage->entries = new;
- }
-
- entry = &storage->entries[storage->count];
- entry->str = xmlstrdup(s);
- entry->data0 = data0;
- entry->data1 = data1;
- entry->data2 = data2;
- storage->count++;
+StructData_AddItem(StructData *storage, const XML_Char *s, int data0, int data1,
+ int data2) {
+ StructDataEntry *entry;
+
+ assert(storage != NULL);
+ assert(s != NULL);
+ if (storage->count == storage->max_count) {
+ StructDataEntry *new;
+
+ storage->max_count += STRUCT_EXTENSION_COUNT;
+ new = realloc(storage->entries,
+ storage->max_count * sizeof(StructDataEntry));
+ assert(new != NULL);
+ storage->entries = new;
+ }
+
+ entry = &storage->entries[storage->count];
+ entry->str = xmlstrdup(s);
+ entry->data0 = data0;
+ entry->data1 = data1;
+ entry->data2 = data2;
+ storage->count++;
}
/* 'fail()' aborts the function via a longjmp, so there is no point
* in returning a value from this function.
*/
void
-StructData_CheckItems(StructData *storage,
- const StructDataEntry *expected,
- int count)
-{
- char buffer[1024];
- int i;
-
- assert(storage != NULL);
- assert(expected != NULL);
- if (count != storage->count) {
- sprintf(buffer, "wrong number of entries: got %d, expected %d",
- storage->count, count);
+StructData_CheckItems(StructData *storage, const StructDataEntry *expected,
+ int count) {
+ char buffer[1024];
+ int i;
+
+ assert(storage != NULL);
+ assert(expected != NULL);
+ if (count != storage->count) {
+ sprintf(buffer, "wrong number of entries: got %d, expected %d",
+ storage->count, count);
+ StructData_Dispose(storage);
+ fail(buffer);
+ } else {
+ for (i = 0; i < count; i++) {
+ const StructDataEntry *got = &storage->entries[i];
+ const StructDataEntry *want = &expected[i];
+
+ assert(got != NULL);
+ assert(want != NULL);
+
+ if (xcstrcmp(got->str, want->str) != 0) {
StructData_Dispose(storage);
- fail(buffer);
- } else {
- for (i = 0; i < count; i++)
- {
- const StructDataEntry *got = &storage->entries[i];
- const StructDataEntry *want = &expected[i];
-
- assert(got != NULL);
- assert(want != NULL);
-
- if (xcstrcmp(got->str, want->str) != 0) {
- StructData_Dispose(storage);
- fail("structure got bad string");
- } else {
- if (got->data0 != want->data0 ||
- got->data1 != want->data1 ||
- got->data2 != want->data2) {
- sprintf(buffer,
- "struct '%" XML_FMT_STR
- "' expected (%d,%d,%d), got (%d,%d,%d)",
- got->str,
- want->data0, want->data1, want->data2,
- got->data0, got->data1, got->data2);
- StructData_Dispose(storage);
- fail(buffer);
- }
- }
+ fail("structure got bad string");
+ } else {
+ if (got->data0 != want->data0 || got->data1 != want->data1
+ || got->data2 != want->data2) {
+ sprintf(buffer,
+ "struct '%" XML_FMT_STR
+ "' expected (%d,%d,%d), got (%d,%d,%d)",
+ got->str, want->data0, want->data1, want->data2, got->data0,
+ got->data1, got->data2);
+ StructData_Dispose(storage);
+ fail(buffer);
}
+ }
}
+ }
}
void
-StructData_Dispose(StructData *storage)
-{
- int i;
+StructData_Dispose(StructData *storage) {
+ int i;
- assert(storage != NULL);
- for (i = 0; i < storage->count; i++)
- free((void *)storage->entries[i].str);
- free(storage->entries);
+ assert(storage != NULL);
+ for (i = 0; i < storage->count; i++)
+ free((void *)storage->entries[i].str);
+ free(storage->entries);
- storage->count = 0;
- storage->entries = NULL;
+ storage->count = 0;
+ storage->entries = NULL;
}