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

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test of timespec_get() function.
   2    Copyright (C) 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 Bruno Haible.  */
  18 
  19 #include <config.h>
  20 
  21 #include <time.h>
  22 
  23 #include "signature.h"
  24 SIGNATURE_CHECK (timespec_get, int, (struct timespec *ts, int base));
  25 
  26 #include "macros.h"
  27 
  28 int
  29 main (void)
     /* [previous][next][first][last][top][bottom][index][help] */
  30 {
  31   struct timespec ts1;
  32   time_t tt2;
  33   struct timespec ts3;
  34   time_t tt4;
  35 
  36   ASSERT (timespec_get (&ts1, TIME_UTC));
  37   tt2 = time (NULL);
  38   ASSERT (timespec_get (&ts3, TIME_UTC));
  39   tt4 = time (NULL);
  40 
  41   /* Verify monotonicity of timespec_get().  */
  42   ASSERT (ts1.tv_sec < ts3.tv_sec
  43           || (ts1.tv_sec == ts3.tv_sec && ts1.tv_nsec <= ts3.tv_nsec));
  44 
  45   /* Verify monotonicity of time().  */
  46   ASSERT (tt2 <= tt4);
  47 
  48   /* Verify that the tv_sec field of the result is the same as time(NULL).  */
  49   ASSERT (ts1.tv_sec <= tt2);
  50   ASSERT (tt2 <= ts3.tv_sec);
  51   ASSERT (ts3.tv_sec <= tt4);
  52 
  53   return 0;
  54 }

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