Skip to content

Commit 94c6b17

Browse files
Fix tests for ubuntu and changed to _EPROSIMA_WINDOWS_PLATFORM macro
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
1 parent 90579c6 commit 94c6b17

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

cpp_utils/src/cpp/time/time_utils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ Timestamp now() noexcept
4141

4242
Timestamp the_end_of_time() noexcept
4343
{
44-
#if defined(_WIN32) // In Windows std::gmtime does not support negative values nor values greater than 2^32
44+
#if _EPROSIMA_WINDOWS_PLATFORM // In Windows std::gmtime does not support negative values nor values greater than 2^32
4545
return Timeclock::from_time_t(std::numeric_limits<long>::max());
4646
#else
4747
return Timestamp::max();
48-
#endif // if defined(_WIN32)
48+
#endif // if _EPROSIMA_WINDOWS_PLATFORM
4949
}
5050

5151
Timestamp the_beginning_of_time() noexcept
5252
{
53-
#if defined(_WIN32) // In Windows std::gmtime does not support negative values nor values greater than 2^32
53+
#if _EPROSIMA_WINDOWS_PLATFORM // In Windows std::gmtime does not support negative values nor values greater than 2^32
5454
return Timeclock::from_time_t(0);
5555
#else
5656
return Timestamp::min();
57-
#endif // if defined(_WIN32)
57+
#endif // if _EPROSIMA_WINDOWS_PLATFORM
5858
}
5959

6060
Timestamp date_to_timestamp(
@@ -105,10 +105,10 @@ std::string timestamp_to_string(
105105
std::ostringstream ss;
106106
time_t duration_seconds = std::chrono::duration_cast<std::chrono::seconds>(timestamp.time_since_epoch()).count();
107107

108-
#if defined(_WIN32) // In Windows std::gmtime does not support negative values nor values greater than 2^32
108+
#if _EPROSIMA_WINDOWS_PLATFORM // In Windows std::gmtime does not support negative values nor values greater than 2^32
109109
time_t max_value = std::numeric_limits<long>::max();
110110
duration_seconds = std::max((time_t) 0, std::min(max_value, duration_seconds));
111-
#endif // if defined(_WIN32)
111+
#endif // if _EPROSIMA_WINDOWS_PLATFORM
112112

113113
std::tm* tm = nullptr;
114114
if (local_time)

cpp_utils/test/unittest/time/time_utils_test.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ TEST(time_utils_test, timestamp_to_string_to_timestamp)
9797
Timestamp old_time = date_to_timestamp(1970u, 7u, 20u, 6u, 39u, 42u);
9898
std::string old_time_str = timestamp_to_string(old_time);
9999

100-
std::ostringstream expected_string_os;
100+
std::ostringstream expected_string_os;
101101
expected_string_os
102102
<< 1970
103103
<< "-" << "07"
@@ -121,13 +121,24 @@ TEST(time_utils_test, timestamp_to_string_to_timestamp)
121121
std::string beginning_time_str = timestamp_to_string(beginning_time);
122122

123123
std::ostringstream expected_string_os;
124+
#if _EPROSIMA_WINDOWS_PLATFORM
124125
expected_string_os
125126
<< 1970
126127
<< "-" << "01"
127128
<< "-" << "01"
128129
<< "_" << "00"
129130
<< "-" << "00"
130131
<< "-" << "00";
132+
#else //1677-09-21_00-12-44
133+
expected_string_os
134+
<< 1677
135+
<< "-" << "09"
136+
<< "-" << "21"
137+
<< "_" << "00"
138+
<< "-" << "12"
139+
<< "-" << "44";
140+
#endif // _EPROSIMA_WINDOWS_PLATFORM
141+
131142

132143
// Test timestamp_to_string
133144
ASSERT_EQ(beginning_time_str, expected_string_os.str());
@@ -167,13 +178,24 @@ TEST(time_utils_test, timestamp_to_string_to_timestamp)
167178
std::string end_time_str = timestamp_to_string(end_time);
168179

169180
std::ostringstream expected_string_os;
181+
#if _EPROSIMA_WINDOWS_PLATFORM
170182
expected_string_os
171183
<< 2038
172184
<< "-" << "01"
173185
<< "-" << 19
174186
<< "_" << "03"
175187
<< "-" << "14"
176188
<< "-" << "07";
189+
#else // 2262-04-11 23:47:16
190+
expected_string_os
191+
<< 2262
192+
<< "-" << "04"
193+
<< "-" << 11
194+
<< "_" << "23"
195+
<< "-" << "47"
196+
<< "-" << "16";
197+
#endif // _EPROSIMA_WINDOWS_PLATFORM
198+
177199

178200
// Test timestamp_to_string
179201
ASSERT_EQ(end_time_str, expected_string_os.str());

0 commit comments

Comments
 (0)