root/maint/gnulib/tests/test-stack.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test of the type-safe stack data type.
   2    Copyright (C) 2020-2021 Free Software Foundation, Inc.
   3 
   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.
   8 
   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.
  13 
  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/>.  */
  16 
  17 /* Written by Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de>, 2020.  */
  18 
  19 #include <config.h>
  20 
  21 #include <stdbool.h>
  22 #include <stdlib.h>
  23 #include <string.h>
  24 #include "assure.h"
  25 #include "xalloc.h"
  26 
  27 #include "macros.h"
  28 
  29 #define GL_STACK_ELEMENT int
  30 #define GL_STACK_STORAGECLASS static
  31 #include "stack.h"
  32 
  33 #define GL_STACK_ELEMENT const char *
  34 #define GL_STACK_STORAGECLASS static
  35 #define GL_STACK_NAME string_stack
  36 #include "stack.h"
  37 
  38 int
  39 main (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  40 {
  41   stack_type int_stack;
  42   stack_init (&int_stack);
  43   ASSERT (stack_size (&int_stack) == 0);
  44   ASSERT (stack_empty (&int_stack));
  45   stack_push (&int_stack, 0);
  46   stack_push (&int_stack, 1);
  47   stack_push (&int_stack, 2);
  48   stack_push (&int_stack, 3);
  49   stack_push (&int_stack, 4);
  50   stack_push (&int_stack, 5);
  51   stack_push (&int_stack, 6);
  52   stack_push (&int_stack, 7);
  53   stack_push (&int_stack, 8);
  54   stack_push (&int_stack, 9);
  55   ASSERT (stack_size (&int_stack) == 10);
  56   ASSERT (!stack_empty (&int_stack));
  57   ASSERT (stack_top (&int_stack) == 9);
  58   ASSERT (stack_size (&int_stack) == 10);
  59   ASSERT (stack_pop (&int_stack) == 9);
  60   ASSERT (stack_size (&int_stack) == 9);
  61   stack_discard (&int_stack);
  62   ASSERT (stack_size (&int_stack) == 8);
  63   ASSERT (stack_top (&int_stack) == 7);
  64   stack_destroy (&int_stack);
  65 
  66   string_stack_type string_stack [1];
  67   string_stack_init (string_stack);
  68   string_stack_push (string_stack, "foo");
  69   ASSERT (STREQ (string_stack_pop (string_stack), "foo"));
  70   ASSERT (string_stack_empty (string_stack));
  71   string_stack_destroy (string_stack);
  72 
  73   return EXIT_SUCCESS;
  74 }

/* [previous][next][first][last][top][bottom][index][help] */