Rest regular stack_resize as well
This commit is contained in:
parent
12590533a7
commit
ad0246a4f8
1 changed files with 10 additions and 8 deletions
18
stack.c
18
stack.c
|
|
@ -196,12 +196,11 @@ int main(void) {
|
|||
}
|
||||
|
||||
{
|
||||
uint8_t buf[32];
|
||||
Stack st;
|
||||
if (stack_init_raw(&st, (uint8_t *)buf, 32, sizeof(int)) != Ok) {
|
||||
if (stack_init(&st, 8, sizeof(int)) != Ok) {
|
||||
printf("Error: stack_init_raw did not init properly...");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = 1; stack_push(&st, &i) == Ok; i++);
|
||||
|
||||
|
|
@ -210,10 +209,12 @@ int main(void) {
|
|||
assert(stack_length(&st) == 8);
|
||||
assert(!stack_empty(&st));
|
||||
|
||||
/* Make sure to not call stack_destroy or free here, since buf[] is static */
|
||||
uint8_t buf2[64];
|
||||
uint8_t *old_buf = stack_resize_raw(&st, buf2, 64);
|
||||
|
||||
uint8_t buf2[64];
|
||||
stack_resize_raw(&st, buf2, 64);
|
||||
assert(old_buf);
|
||||
if (old_buf)
|
||||
free(old_buf);
|
||||
|
||||
assert(stack_capacity(&st) == 16);
|
||||
assert(stack_length(&st) == 8);
|
||||
|
|
@ -223,10 +224,11 @@ int main(void) {
|
|||
int r;
|
||||
for (int i = 8; i >= 0; i--) {
|
||||
if (stack_pop(&st, &r) != Ok)
|
||||
return 1;
|
||||
break;
|
||||
|
||||
printf("%d == %d\n", i, r);
|
||||
assert(r == i);
|
||||
}
|
||||
}
|
||||
|
||||
printf("All tests passed!\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue