summaryrefslogtreecommitdiff
path: root/dwarfdump/testesb.c
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2012-10-20 14:42:03 +0400
committerIgor Pashev <pashev.igor@gmail.com>2012-10-20 14:42:03 +0400
commitbb1c3da3c12651f1c408d96dd6d33ae157bdadd6 (patch)
tree4a535b35500684ac6a928bf0fd661325b5a04697 /dwarfdump/testesb.c
downloaddwarfutils-bb1c3da3c12651f1c408d96dd6d33ae157bdadd6.tar.gz
Imported Upstream version 20120410upstream/20120410upstream
Diffstat (limited to 'dwarfdump/testesb.c')
-rw-r--r--dwarfdump/testesb.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/dwarfdump/testesb.c b/dwarfdump/testesb.c
new file mode 100644
index 0000000..c3ea2f0
--- /dev/null
+++ b/dwarfdump/testesb.c
@@ -0,0 +1,78 @@
+/* testesb.c
+ test code for esb.h esb.c
+
+ Not part of a compiled dwarfdump.
+
+*/
+
+#include <stdio.h>
+#include <string.h>
+typedef char *string;
+
+#include "esb.h"
+
+void
+check(string msg, struct esb_s *data, string v)
+{
+ string b = esb_get_string(data);
+ size_t l = 0;
+ size_t alloc = 0;
+
+ if (strcmp(b, v)) {
+ fprintf(stderr, "ERROR: %s content error %s != %s\n", msg, b,
+ v);
+ }
+
+ l = esb_string_len(data);
+
+ if (l != strlen(v)) {
+ fprintf(stderr, "ERROR: %s length error %lu != %lu\n", msg,
+ (unsigned long) l, (unsigned long) strlen(v));
+ }
+ alloc = esb_get_allocated_size(data);
+ if (l > alloc) {
+ fprintf(stderr, "ERROR: %s allocation error %lu > %lu\n", msg,
+ (unsigned long) l, (unsigned long) alloc);
+
+ }
+
+ return;
+}
+
+int
+main(void)
+{
+ struct esb_s data;
+
+
+ esb_alloc_size(2); /* small to get all code paths tested. */
+ esb_constructor(&data);
+
+ esb_append(&data, "a");
+ esb_appendn(&data, "bc", 1);
+ esb_append(&data, "d");
+ esb_append(&data, "e");
+ check("test 1", &data, "abde");
+
+ esb_destructor(&data);
+ esb_constructor(&data);
+
+ esb_append(&data, "abcdefghij" "0123456789");
+ check("test 2", &data, "abcdefghij" "0123456789");
+
+ esb_destructor(&data);
+ esb_constructor(&data);
+ esb_append(&data, "abcdefghij" "0123456789");
+
+ esb_append(&data, "abcdefghij" "0123456789");
+
+ esb_append(&data, "abcdefghij" "0123456789");
+
+ esb_append(&data, "abcdefghij" "0123456789");
+ check("test 3", &data, "abcdefghij"
+ "0123456789"
+ "abcdefghij"
+ "0123456789"
+ "abcdefghij" "0123456789" "abcdefghij" "0123456789");
+ return 0;
+}