more tests

This commit is contained in:
tezc 2021-02-01 00:56:05 +03:00
parent bf7140bfc1
commit bfda37b2cd
3 changed files with 38 additions and 1 deletions

View File

@ -1,5 +1,7 @@
#include "sc_map.h"
#include <string.h>
#ifndef SC_SIZE_MAX
#define SC_SIZE_MAX UINT32_MAX
#endif

View File

@ -32,7 +32,8 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_compile_options(${PROJECT_NAME}_test PRIVATE -DSC_HAVE_WRAP)
target_compile_options(${PROJECT_NAME}_test PRIVATE -fno-builtin)
target_link_options(${PROJECT_NAME}_test PRIVATE
-Wl,--wrap=pthread_mutexattr_init)
-Wl,--wrap=pthread_mutexattr_init -Wl,--wrap=pthread_mutex_destroy
-Wl,--wrap=pthread_mutex_init)
endif ()
endif ()

View File

@ -38,6 +38,31 @@ int __wrap_pthread_mutexattr_init(pthread_mutexattr_t *attr)
return -1;
}
bool mock_mutexdestroy = false;
extern int __real_pthread_mutex_destroy(pthread_mutex_t *m);
int __wrap_pthread_mutex_destroy(pthread_mutex_t *m)
{
int rc;
rc = __real_pthread_mutex_destroy(m);
return mock_mutexdestroy ? -1 : rc;
}
bool mock_mutexinit = false;
extern int __real_pthread_mutex_init(pthread_mutex_t *__mutex,
const pthread_mutexattr_t *__mutexattr);
int __wrap_pthread_mutex_init(pthread_mutex_t *__mutex,
const pthread_mutexattr_t *__mutexattr)
{
if (!mock_mutexinit) {
return __real_pthread_mutex_init(__mutex, __mutexattr);
}
return -1;
}
#endif
int main(int argc, char *argv[])
@ -47,6 +72,15 @@ int main(int argc, char *argv[])
mock_attrinit = true;
assert(sc_mutex_init(&mutex) != 0);
mock_attrinit = false;
assert(sc_mutex_init(&mutex) == 0);
mock_mutexdestroy = true;
assert(sc_mutex_term(&mutex) == -1);
mock_mutexdestroy = false;
mock_mutexinit = true;
assert(sc_mutex_init(&mutex) != 0);
mock_mutexinit = false;
assert(sc_mutex_term(&mutex) == 0);
#endif
assert(sc_mutex_init(&mutex) == 0);
sc_mutex_lock(&mutex);