gwenhywfar 5.14.1
timestamp-t.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Wed Mar 22 2023
3 copyright : (C) 2023 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 * *
23 ***************************************************************************/
24
25
26#ifdef GWENHYWFAR_ENABLE_TESTCODE
27
28
29
30/* ------------------------------------------------------------------------------------------------
31 * forward declarations
32 * ------------------------------------------------------------------------------------------------
33 */
34
35static int GWENHYWFAR_CB test1(GWEN_TEST_MODULE *mod);
36
37
38
39/* ------------------------------------------------------------------------------------------------
40 * implementations
41 * ------------------------------------------------------------------------------------------------
42 */
43
44
45
47{
48 GWEN_TEST_MODULE *newMod;
49
50 newMod=GWEN_Test_Module_AddModule(mod, "GWEN_Timestamp", NULL);
51
52 GWEN_Test_Module_AddTest(newMod, "test GWEN_Timestamp_toTimeT() and GWEN_Timestamp_fromLocalTime()", test1, NULL);
53
54 return 0;
55}
56
57
58
60{
61 GWEN_TIMESTAMP *ts1;
62 time_t t1;
63 const char *s1;
64 GWEN_TIMESTAMP *ts2;
65 time_t t2;
66 const char *s2;
67
72
75
76 if (strcasecmp(s1, s2)!=0) {
77 DBG_ERROR(GWEN_LOGDOMAIN, "Times as string not equal (%s != %s)", s1, s2);
78 return GWEN_ERROR_GENERIC;
79 }
80
81 if (t1!=t2) {
83 "Times in time_t not equal (%llu != %llu)",
84 (unsigned long long int) t1,
85 (unsigned long long int) t2);
86 return GWEN_ERROR_GENERIC;
87 }
88
89 return 0;
90}
91
92
93
94#else
95
97{
98 DBG_ERROR(GWEN_LOGDOMAIN, "Gwenhywfar was compiled without test code enabled.");
99 return GWEN_ERROR_GENERIC;
100}
101
102
103#endif
104
105
106
#define NULL
Definition binreloc.c:300
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
#define GWEN_ERROR_GENERIC
Definition error.h:62
#define GWEN_UNUSED
#define GWENHYWFAR_CB
int test1()
Definition libtest.m:63
#define GWEN_LOGDOMAIN
Definition logger.h:32
GWEN_TEST_MODULE * GWEN_Test_Module_AddModule(GWEN_TEST_MODULE *st, const char *tName, const char *tDescr)
Definition testmodule.c:440
GWEN_TEST_MODULE * GWEN_Test_Module_AddTest(GWEN_TEST_MODULE *st, const char *tName, GWEN_TEST_MODULE_TEST_FN fn, const char *tDescr)
Definition testmodule.c:424
struct GWEN_TEST_MODULE GWEN_TEST_MODULE
Definition testmodule.h:65
int GWEN_Timestamp_AddTests(GWEN_UNUSED GWEN_TEST_MODULE *mod)
Definition timestamp-t.c:96
GWEN_TIMESTAMP * GWEN_Timestamp_fromLocalTime(time_t ti)
Definition timestamp.c:153
const char * GWEN_Timestamp_GetString(const GWEN_TIMESTAMP *tstamp)
Definition timestamp.c:90
time_t GWEN_Timestamp_toTimeT(const GWEN_TIMESTAMP *tstamp)
Definition timestamp.c:167
GWEN_TIMESTAMP * GWEN_Timestamp_NowInLocalTime()
Definition timestamp.c:194
struct GWEN_TIMESTAMP GWEN_TIMESTAMP
Definition timestamp.h:36