| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#include "util.h" |
| 32 |
|
| 33 |
#include "asm.h" |
| 34 |
#include "errors.h" |
| 35 |
|
| 36 |
#include <assert.h> |
| 37 |
#include <stdlib.h> |
| 38 |
#include <string.h> |
| 39 |
|
| 40 |
#if 0 |
| 41 |
#if defined(TEST) |
| 42 |
|
| 43 |
void new_panic(error_t _error, const char *s) |
| 44 |
{ |
| 45 |
(void) printf("Simulated Panic: %s\n", s); |
| 46 |
} |
| 47 |
void debug(error_t _error, const char *s) |
| 48 |
{ |
| 49 |
(void) printf("Simulated Debug: %s\n", s); |
| 50 |
} |
| 51 |
#endif |
| 52 |
#endif |
| 53 |
|
| 54 |
|
| 55 |
FILE *FI_listfile = NULL; |
| 56 |
char *F_listfile = NULL; |
| 57 |
INCFILE *pIncfile = NULL; |
| 58 |
|
| 59 |
int main(int argc, char *argv[]) |
| 60 |
{ |
| 61 |
char *one; |
| 62 |
char *two; |
| 63 |
union align { long l; void *p; void (*fp)(void); }; |
| 64 |
const size_t BIG = ((size_t) 1) << 31; |
| 65 |
char buffer[256]; |
| 66 |
char fuffer[256]; |
| 67 |
char poop[5] = {'a', 'b', 'c', 'd', 'X'}; |
| 68 |
size_t res; |
| 69 |
char* excellent = NULL; |
| 70 |
assert(argc == 1); |
| 71 |
setprogname(argv[0]); |
| 72 |
|
| 73 |
|
| 74 |
excellent = checked_strdup("Peter's own thing!"); |
| 75 |
assert(excellent != NULL); |
| 76 |
assert(strcmp(excellent, "Peter's own thing!") == 0); |
| 77 |
|
| 78 |
res = strlcpy(poop, "Hello 47!", sizeof(poop)-1); |
| 79 |
assert(res == 9); |
| 80 |
assert(poop[0] == 'H'); |
| 81 |
assert(poop[1] == 'e'); |
| 82 |
assert(poop[2] == 'l'); |
| 83 |
assert(poop[3] == '\0'); |
| 84 |
assert(poop[4] == 'X'); |
| 85 |
|
| 86 |
res = strlcpy(buffer, "Hello 47!", sizeof(buffer)); |
| 87 |
assert(res == 9); |
| 88 |
assert(strcmp(buffer, "Hello 47!") == 0); |
| 89 |
|
| 90 |
assert(!match_either_case(buffer, "hello 47!")); |
| 91 |
|
| 92 |
res = strlower(fuffer, buffer, sizeof(fuffer)); |
| 93 |
assert(res == 9); |
| 94 |
assert(strcmp(fuffer, "hello 47!") == 0); |
| 95 |
|
| 96 |
assert(match_either_case(fuffer, "hello 47!")); |
| 97 |
|
| 98 |
res = strupper(buffer, fuffer, sizeof(buffer)); |
| 99 |
assert(res == 9); |
| 100 |
assert(strcmp(buffer, "HELLO 47!") == 0); |
| 101 |
|
| 102 |
assert(match_either_case(buffer, "hello 47!")); |
| 103 |
|
| 104 |
res = strlcpy(buffer, "\r\t\n ", sizeof(buffer)); |
| 105 |
assert(res == 7); |
| 106 |
|
| 107 |
res = strip_whitespace(poop, buffer, sizeof(poop)-1); |
| 108 |
assert(res == 0); |
| 109 |
assert(poop[0] == '\0'); |
| 110 |
assert(poop[1] == 'e'); |
| 111 |
assert(poop[2] == 'l'); |
| 112 |
assert(poop[3] == '\0'); |
| 113 |
assert(poop[4] == 'X'); |
| 114 |
|
| 115 |
res = strlcpy(buffer, "\rThere are\tso\nmany good things! ", sizeof(buffer)); |
| 116 |
assert(res == 35); |
| 117 |
|
| 118 |
res = strip_whitespace(poop, buffer, sizeof(poop)-1); |
| 119 |
assert(res == 25); |
| 120 |
assert(poop[0] == 'T'); |
| 121 |
assert(poop[1] == 'h'); |
| 122 |
assert(poop[2] == 'e'); |
| 123 |
assert(poop[3] == '\0'); |
| 124 |
assert(poop[4] == 'X'); |
| 125 |
|
| 126 |
res = strip_whitespace(fuffer, buffer, sizeof(fuffer)); |
| 127 |
assert(res == 25); |
| 128 |
assert(strcmp(fuffer, "Therearesomanygoodthings!") == 0); |
| 129 |
|
| 130 |
|
| 131 |
pIncfile = malloc(sizeof(INCFILE)); |
| 132 |
pIncfile->next = NULL; |
| 133 |
pIncfile->name = checked_strdup("someFileName"); |
| 134 |
pIncfile->lineno = 47; |
| 135 |
|
| 136 |
set_error_level(ERRORLEVEL_DEBUG); |
| 137 |
|
| 138 |
puts(getprogname()); |
| 139 |
setprogname(argv[0]); |
| 140 |
puts(getprogname()); |
| 141 |
printf("sizeof(align)==%zu\n", sizeof(union align)); |
| 142 |
one = checked_malloc(BIG); |
| 143 |
puts("First malloc()ed!"); |
| 144 |
two = checked_malloc(BIG); |
| 145 |
puts("Second malloc()ed! Should have caused a panic?"); |
| 146 |
if (two) free(two); |
| 147 |
puts("Second free()d!"); |
| 148 |
if (one) free(one); |
| 149 |
puts("First free()d!"); |
| 150 |
one = small_alloc(4096); |
| 151 |
printf("First small_alloc()ed returned %p!\n", one); |
| 152 |
two = small_alloc(4096); |
| 153 |
assert(one < two); |
| 154 |
printf("Second small_alloc()ed returned %p!\n", two); |
| 155 |
one = small_alloc(10240); |
| 156 |
small_free_all(); |
| 157 |
return EXIT_SUCCESS; |
| 158 |
} |
| 159 |
|
| 160 |
|