usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-stack.c
blob2350eadddfdbb58cc72543fc81b492c35181edc1
1 /* Test of the type-safe stack data type.
2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de>, 2020. */
19 #include <config.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include "assure.h"
24 #include "xalloc.h"
26 #include "macros.h"
28 #define GL_STACK_ELEMENT int
29 #define GL_STACK_STORAGECLASS static
30 #include "stack.h"
32 #define GL_STACK_ELEMENT const char *
33 #define GL_STACK_STORAGECLASS static
34 #define GL_STACK_NAME string_stack
35 #include "stack.h"
37 int
38 main (void)
40 stack_type int_stack;
41 stack_init (&int_stack);
42 ASSERT (stack_size (&int_stack) == 0);
43 ASSERT (stack_empty (&int_stack));
44 stack_push (&int_stack, 0);
45 stack_push (&int_stack, 1);
46 stack_push (&int_stack, 2);
47 stack_push (&int_stack, 3);
48 stack_push (&int_stack, 4);
49 stack_push (&int_stack, 5);
50 stack_push (&int_stack, 6);
51 stack_push (&int_stack, 7);
52 stack_push (&int_stack, 8);
53 stack_push (&int_stack, 9);
54 ASSERT (stack_size (&int_stack) == 10);
55 ASSERT (!stack_empty (&int_stack));
56 ASSERT (stack_top (&int_stack) == 9);
57 ASSERT (stack_size (&int_stack) == 10);
58 ASSERT (stack_pop (&int_stack) == 9);
59 ASSERT (stack_size (&int_stack) == 9);
60 stack_discard (&int_stack);
61 ASSERT (stack_size (&int_stack) == 8);
62 ASSERT (stack_top (&int_stack) == 7);
63 stack_destroy (&int_stack);
65 string_stack_type string_stack [1];
66 string_stack_init (string_stack);
67 string_stack_push (string_stack, "foo");
68 ASSERT (STREQ (string_stack_pop (string_stack), "foo"));
69 ASSERT (string_stack_empty (string_stack));
70 string_stack_destroy (string_stack);
72 return test_exit_status;