refactor(test): Use the fake clock also for non-monotonic time-source

The subscription tests depend on a deterministic clock.
This commit is contained in:
Julius Pfrommer 2023-12-26 00:13:07 +01:00
parent 1365c3f204
commit 054420cf33
5 changed files with 14 additions and 8 deletions

View File

@ -89,7 +89,8 @@ START_TEST(ClientConfig_Copy){
UA_ClientConfig srcConfig;
memset(&srcConfig, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefault(&srcConfig);
srcConfig.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake;
srcConfig.eventLoop->dateTime_now = UA_DateTime_now_fake;
srcConfig.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake;
UA_StatusCode retval = UA_ClientConfig_copy(&srcConfig, &dstConfig);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);

View File

@ -192,7 +192,8 @@ registerServer(void) {
memset(&cc, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0);
UA_CertificateVerification_AcceptAll(&cc.certificateVerification);
cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake;
cc.eventLoop->dateTime_now = UA_DateTime_now_fake;
cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake;
*running_register = false;
THREAD_JOIN(server_thread_register);
@ -222,7 +223,8 @@ unregisterServer(void) {
memset(&cc, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0);
UA_CertificateVerification_AcceptAll(&cc.certificateVerification);
cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake;
cc.eventLoop->dateTime_now = UA_DateTime_now_fake;
cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake;
*running_register = false;
THREAD_JOIN(server_thread_register);
@ -266,7 +268,8 @@ Server_register_semaphore(void) {
memset(&cc, 0, sizeof(UA_ClientConfig));
UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0);
UA_CertificateVerification_AcceptAll(&cc.certificateVerification);
cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake;
cc.eventLoop->dateTime_now = UA_DateTime_now_fake;
cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake;
*running_register = false;
THREAD_JOIN(server_thread_register);

View File

@ -16,7 +16,8 @@ UA_Server * UA_Server_newForUnitTest(void) {
return NULL;
UA_ServerConfig *config = UA_Server_getConfig(server);
/* Manually set the eventloop clock to the fake clock */
config->eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake;
config->eventLoop->dateTime_now = UA_DateTime_now_fake;
config->eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake;
return server;
}
@ -27,7 +28,8 @@ UA_Client * UA_Client_newForUnitTest(void) {
return NULL;
UA_ClientConfig *config = UA_Client_getConfig(client);
/* Manually set the eventloop clock to the fake clock */
config->eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake;
config->eventLoop->dateTime_now = UA_DateTime_now_fake;
config->eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake;
return client;
}

View File

@ -31,6 +31,6 @@ UA_realSleep(UA_UInt32 duration) {
#endif
}
UA_DateTime UA_DateTime_nowMonotonic_fake(UA_EventLoop *el) {
UA_DateTime UA_DateTime_now_fake(UA_EventLoop *el) {
return testingClock;
}

View File

@ -22,6 +22,6 @@ void UA_fakeSleep(UA_UInt32 duration);
void UA_realSleep(UA_UInt32 duration);
/* To be hooked into the EventLoop for unit tests that need deterministic timings */
UA_DateTime UA_DateTime_nowMonotonic_fake(UA_EventLoop *el);
UA_DateTime UA_DateTime_now_fake(UA_EventLoop *el);
#endif /* TESTING_CLOCK_H_ */