dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unittest.cpp
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
25 
26 /*
27  * NOTE: This program uses the Google Test infrastructure to drive the unit test
28  *
29  * Main site for Google Test: http://code.google.com/p/googletest/
30  * Documentation and examples: http://code.google.com/p/googletest/wiki/Documentation
31  */
32 
33 #include "gtest/gtest.h"
34 
35 #include <time.h> /* time functions */
36 #include <stdio.h> /* printf */
37 #include <stdlib.h> /* abort */
38 #include <string.h> /* memset */
39 #include <stdint.h> /* uint*_t */
40 
41 extern "C" {
42 #include "timeutils.h" /* API for time conversion */
43 }
44 
45 
46 
47 // To use a test fixture, derive a class from testing::Test.
48 class Time : public testing::Test {
49 protected:
50  virtual void SetUp() {
51  }
52 
53  virtual void TearDown() {
54  }
55 };
56 
57 TEST_F(Time, DateSweep) {
58  struct tm *datetime1;
59  DateTimeT datetime2;
60  time_t timestamp = 0;
61 
62  // test every day from 1970 to 2100
63  struct tm tm;
64  memset((void*)&tm, 0, sizeof(tm));
65  tm.tm_year = 130;
66  time_t end_time = mktime(&tm);
67 
68  while (timestamp < end_time){
69  datetime1 = gmtime(&timestamp);
70  date_from_timestamp((uint32_t)timestamp, &datetime2);
71  EXPECT_EQ(datetime1->tm_year, datetime2.year);
72  EXPECT_EQ(datetime1->tm_mon, datetime2.mon);
73  EXPECT_EQ(datetime1->tm_mday, datetime2.mday);
74  EXPECT_EQ(datetime1->tm_hour, datetime2.hour);
75  EXPECT_EQ(datetime1->tm_min, datetime2.min);
76  EXPECT_EQ(datetime1->tm_sec, datetime2.sec);
77  EXPECT_EQ(datetime1->tm_wday, datetime2.wday);
78  timestamp += 86400 + 3600 + 42; // advance by one day, one hour, 42 seconds
79  }
80 }
81 
82 
TEST_F(RneFromLLATest, Equator)
Definition: unittest.cpp:68
void date_from_timestamp(uint32_t timestamp, DateTimeT *date_time)
Definition: timeutils.c:51
virtual void TearDown()
Definition: unittest.cpp:53
virtual void SetUp()
Definition: unittest.cpp:50
Time conversion functions.