spin_mutex_unittest_.h

来自「用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、W」· C头文件 代码 · 共 51 行

H
51
字号

#if !defined(WINSTL_INCL_WINSTL_SYNCH_HPP_SPIN_MUTEX)
# error This file cannot be directly included, and should only be included within winstl/synch/spin_mutex.hpp
#endif /* !WINSTL_INCL_WINSTL_SYNCH_HPP_SPIN_MUTEX */

#if !defined(STLSOFT_UNITTEST)
# error This file cannot be included when not unit-testing STLSoft
#endif /* !STLSOFT_UNITTEST */

namespace unittest
{
    namespace
    {
        ss_bool_t test_winstl_synch_spin_mutex(unittest_reporter *r)
        {
            using stlsoft::unittest::unittest_initialiser;

            ss_bool_t               bSuccess    =   true;

            unittest_initialiser    init(r, "WinSTL", "synch/spin_mutex", __FILE__);

            spin_mutex::atomic_int_type i   =   0;
            spin_mutex                  mx(&i);

            mx.lock();
            if(1 != mx.spun_count())
            {
                r->report("lock() - unlock() sequence failed: wrong spun count", __LINE__);
                bSuccess = false;
            }
            mx.unlock();
            if(0 != mx.spun_count())
            {
                r->report("lock() - unlock() sequence failed: wrong spun count", __LINE__);
                bSuccess = false;
            }

            if(0 != i)
            {
                r->report("lock() - unlock() sequence failed", __LINE__);
                bSuccess = false;
            }

            return bSuccess;
        }

        unittest_registrar    unittest_winstl_synch_spin_mutex(test_winstl_synch_spin_mutex);
    } // anonymous namespace

} // namespace unittest

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?