-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'task/#24323-implement-safuTimeSpecInTimeRange' into 'in…
…tegration' Task #24323 - Implement safuTimeSpecInTimeRange See merge request elektrobit/base-os/safu!37
- Loading branch information
Showing
8 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/utest/safu/time/safuTimeSpecInTimeRange/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-License-Identifier: MIT | ||
find_package(cmocka_extensions 0.53.1 REQUIRED) | ||
|
||
create_unit_test( | ||
NAME | ||
test_common_safuTimeSpecInTimeRange_utest | ||
SOURCES | ||
case_real_timestamps.c | ||
safuTimeSpecInTimeRange_utest.c | ||
LIBRARIES | ||
safu_weak | ||
) |
64 changes: 64 additions & 0 deletions
64
test/utest/safu/time/safuTimeSpecInTimeRange/case_real_timestamps.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <limits.h> | ||
#include <safu/result.h> | ||
#include <safu/time.h> | ||
|
||
#include "safuTimeSpecInTimeRange_utest.h" | ||
|
||
int safuTestSafuTimeSpecInTimeRangeRealTimestampsSetup(void **state) { | ||
struct timespec *times = *state; | ||
int ret = clock_gettime(CLOCK_REALTIME, ×[MIDDLE]); | ||
assert_int_equal(ret, 0); | ||
return 0; | ||
} | ||
|
||
int safuTestSafuTimeSpecInTimeRangeRealTimestampsTeardown(UNUSED void **state) { | ||
return 0; | ||
} | ||
|
||
void safuTestSafuTimeSpecInTimeRangeRealTimestamps(void **state) { | ||
TEST("safuTimeSpecInTimeRangeRealTimestamp"); | ||
SHOULD("%s", "check if a timespec struct is inside a time range, using timestamps gotten from system clock"); | ||
|
||
bool result; | ||
struct timespec *times = *state; | ||
int ret = clock_gettime(CLOCK_REALTIME, ×[NEWEST]); | ||
assert_int_equal(ret, 0); | ||
|
||
PARAM("newest >= middle > oldest"); | ||
result = safuTimeSpecInTimeRange(times[NEWEST], times[MIDDLE], times[OLDEST]); | ||
assert_int_equal(result, true); | ||
|
||
PARAM("{0,0} middle > oldest"); | ||
result = safuTimeSpecInTimeRange(times[NOTSET], times[MIDDLE], times[OLDEST]); | ||
assert_int_equal(result, true); | ||
|
||
PARAM("{0,0} middle !> middle"); | ||
result = safuTimeSpecInTimeRange(times[NOTSET], times[MIDDLE], times[MIDDLE]); | ||
assert_int_equal(result, false); | ||
|
||
PARAM("{0,0} middle {0,0}"); | ||
result = safuTimeSpecInTimeRange(times[NEWEST], times[MIDDLE], times[NOTSET]); | ||
assert_int_equal(result, true); | ||
|
||
PARAM("newest >= oldest {0,0}"); | ||
result = safuTimeSpecInTimeRange(times[NEWEST], times[OLDEST], times[NOTSET]); | ||
assert_int_equal(result, true); | ||
|
||
PARAM("oldest !>= newest {0,0}"); | ||
result = safuTimeSpecInTimeRange(times[OLDEST], times[NEWEST], times[NOTSET]); | ||
assert_int_equal(result, false); | ||
|
||
PARAM("newest >= newest > oldest"); | ||
result = safuTimeSpecInTimeRange(times[NEWEST], times[NEWEST], times[OLDEST]); | ||
assert_int_equal(result, true); | ||
|
||
PARAM("newest >= newest !> newest"); | ||
result = safuTimeSpecInTimeRange(times[NEWEST], times[NEWEST], times[NEWEST]); | ||
assert_int_equal(result, false); | ||
|
||
PARAM("middle >= oldest !> oldest"); | ||
result = safuTimeSpecInTimeRange(times[MIDDLE], times[OLDEST], times[OLDEST]); | ||
assert_int_equal(result, false); | ||
} |
31 changes: 31 additions & 0 deletions
31
test/utest/safu/time/safuTimeSpecInTimeRange/safuTimeSpecInTimeRange_utest.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
#include "safuTimeSpecInTimeRange_utest.h" | ||
|
||
#include <time.h> | ||
|
||
TEST_SUITE_FUNC_PROTOTYPES(_testSuiteSafuTimeSpecInTimeRange) | ||
|
||
int main() { | ||
const struct CMUnitTest tests[] = { | ||
TEST_CASE(safuTestSafuTimeSpecInTimeRangeRealTimestamps), | ||
}; | ||
return RUN_TEST_SUITE(tests, _testSuiteSafuTimeSpecInTimeRange); | ||
} | ||
|
||
static int _testSuiteSafuTimeSpecInTimeRangeSetup(void **state) { | ||
struct timespec *times = calloc(4, sizeof(struct timespec)); | ||
assert_non_null(times); | ||
int ret = clock_gettime(CLOCK_REALTIME, ×[OLDEST]); | ||
assert_int_equal(ret, 0); | ||
|
||
times[NOTSET].tv_sec = 0; | ||
times[NOTSET].tv_nsec = 0; | ||
|
||
*state = times; | ||
return 0; | ||
} | ||
static int _testSuiteSafuTimeSpecInTimeRangeTeardown(void **state) { | ||
free(*state); | ||
*state = NULL; | ||
return 0; | ||
} |
14 changes: 14 additions & 0 deletions
14
test/utest/safu/time/safuTimeSpecInTimeRange/safuTimeSpecInTimeRange_utest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
#ifndef __SAFU_TIME_SPEC_IN_TIME_RANGE_UTEST_H__ | ||
#define __SAFU_TIME_SPEC_IN_TIME_RANGE_UTEST_H__ | ||
|
||
#include <cmocka_extensions/cmocka_extensions.h> | ||
|
||
#define NOTSET 0 | ||
#define OLDEST 1 | ||
#define MIDDLE 2 | ||
#define NEWEST 3 | ||
|
||
TEST_CASE_FUNC_PROTOTYPES(safuTestSafuTimeSpecInTimeRangeRealTimestamps) | ||
|
||
#endif /* __SAFU_TIME_SPEC_IN_TIME_RANGE_UTEST_H__*/ |