tools/elf4rom/libs/dwarf-20071209/dwarfdump/testesb.c
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /* testesb.c 
       
     2    test code for esb.h esb.c
       
     3 
       
     4    Not part of a compiled dwarfdump.
       
     5 
       
     6 */
       
     7 
       
     8 #include <stdio.h>
       
     9 #include <string.h>
       
    10 typedef char *string;
       
    11 
       
    12 #include "esb.h"
       
    13 
       
    14 void
       
    15 check(string msg, struct esb_s *data, string v)
       
    16 {
       
    17     string b = esb_get_string(data);
       
    18     size_t l = 0;
       
    19     size_t alloc = 0;
       
    20 
       
    21     if (strcmp(b, v)) {
       
    22 	fprintf(stderr, "ERROR: %s  content error  %s != %s\n", msg, b,
       
    23 		v);
       
    24     }
       
    25 
       
    26     l = esb_string_len(data);
       
    27 
       
    28     if (l != strlen(v)) {
       
    29 	fprintf(stderr, "ERROR: %s length error  %lu != %lu\n", msg,
       
    30 		(unsigned long) l, (unsigned long) strlen(v));
       
    31     }
       
    32     alloc = esb_get_allocated_size(data);
       
    33     if (l > alloc) {
       
    34 	fprintf(stderr, "ERROR: %s allocation error  %lu > %lu\n", msg,
       
    35 		(unsigned long) l, (unsigned long) alloc);
       
    36 
       
    37     }
       
    38 
       
    39     return;
       
    40 }
       
    41 
       
    42 int
       
    43 main(void)
       
    44 {
       
    45     struct esb_s data;
       
    46 
       
    47 
       
    48     esb_alloc_size(2);		/* small to get all code paths tested. */
       
    49     esb_constructor(&data);
       
    50 
       
    51     esb_append(&data, "a");
       
    52     esb_appendn(&data, "bc", 1);
       
    53     esb_append(&data, "d");
       
    54     esb_append(&data, "e");
       
    55     check("test 1", &data, "abde");
       
    56 
       
    57     esb_destructor(&data);
       
    58     esb_constructor(&data);
       
    59 
       
    60     esb_append(&data, "abcdefghij" "0123456789");
       
    61     check("test 2", &data, "abcdefghij" "0123456789");
       
    62 
       
    63     esb_destructor(&data);
       
    64     esb_constructor(&data);
       
    65     esb_append(&data, "abcdefghij" "0123456789");
       
    66 
       
    67     esb_append(&data, "abcdefghij" "0123456789");
       
    68 
       
    69     esb_append(&data, "abcdefghij" "0123456789");
       
    70 
       
    71     esb_append(&data, "abcdefghij" "0123456789");
       
    72     check("test 3", &data, "abcdefghij"
       
    73 	  "0123456789"
       
    74 	  "abcdefghij"
       
    75 	  "0123456789"
       
    76 	  "abcdefghij" "0123456789" "abcdefghij" "0123456789");
       
    77     return 0;
       
    78 }