awtk/tests/mutex_nest_test.cc

26 lines
676 B
C++
Raw Normal View History

2020-06-24 08:20:25 +08:00
#include "gtest/gtest.h"
#include "tkc/mutex_nest.h"
#include "tkc/thread.h"
#include "tkc/platform.h"
TEST(MutexNest, basic) {
2021-09-16 16:06:55 +08:00
int32_t i = 0;
2020-06-24 08:20:25 +08:00
tk_mutex_nest_t* mutex_nest = tk_mutex_nest_create();
2020-06-24 12:02:20 +08:00
for (i = 0; i < 100; i++) {
2020-06-24 08:20:25 +08:00
ASSERT_EQ(mutex_nest->ref, i);
ASSERT_EQ(tk_mutex_nest_lock(mutex_nest), RET_OK);
ASSERT_EQ(mutex_nest->owner, tk_thread_self());
}
2020-06-24 12:02:20 +08:00
for (i = 0; i < 100; i++) {
ASSERT_EQ(mutex_nest->ref, 100 - i);
2020-06-24 08:20:25 +08:00
ASSERT_EQ(mutex_nest->owner, tk_thread_self());
ASSERT_EQ(tk_mutex_nest_unlock(mutex_nest), RET_OK);
}
ASSERT_EQ(mutex_nest->ref, 0);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(mutex_nest->owner, 0u);
2020-06-24 08:20:25 +08:00
tk_mutex_nest_destroy(mutex_nest);
}