guid_unittest_.h

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

H
113
字号

#if !defined(COMSTL_INCL_HPP_COMSTL_GUID)
# error This file cannot be directly included, and should only be included within comstl/guid.hpp
#endif /* !COMSTL_INCL_HPP_COMSTL_GUID */

#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_comstl_guid(unittest_reporter *r)
        {
            using stlsoft::unittest::unittest_initialiser;
            using stlsoft::null_exception_policy;

            ss_bool_t               bSuccess    =   true;

            unittest_initialiser    init(r, "COMSTL", "guid", __FILE__);

#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
            try
            {
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
                guid        g1;

#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
            }
            catch(com_exception &)
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
            if(GUID_NULL != g1)
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
            {
                r->report("default construction failed", __LINE__);
                bSuccess = false;
            }

            guid        g2(IID_IUnknown);

            if(IID_IUnknown != g2)
            {
                r->report("conversion construction failed", __LINE__);
                bSuccess = false;
            }

            guid        g3(g2);

            if(g2 != g3)
            {
                r->report("copy construction failed", __LINE__);
                bSuccess = false;
            }

            try
            {
                guid    g4(c_str_ptr_a(g3));

                if(g4 != g3)
                {
                    r->report("conversion construction from ANSI string failed", __LINE__);
                    bSuccess = false;
                }

                guid    g5(c_str_ptr_w(g3));

                if(g5 != g3)
                {
                    r->report("conversion construction from Unicode string failed", __LINE__);
                    bSuccess = false;
                }

                guid    g6(c_str_ptr(g3));

                if(g6 != g3)
                {
                    r->report("conversion construction from string failed", __LINE__);
                    bSuccess = false;
                }
            }
            catch(comstl::com_exception &/* x */)
            {
                r->report("conversion construction from string failed", __LINE__);
                bSuccess = false;
            }

            try
            {
                guid    g7("lemon scented");

#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
#else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
                if(m_guid != GUID_NULL)
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
                {
                    r->report("conversion construction from string succeeded when it should not", __LINE__);
                    bSuccess = false;
                }
            }
            catch(comstl::com_exception &/* x */)
            {
            }

            return bSuccess;
        }


        unittest_registrar    unittest_comstl_guid(test_comstl_guid);
    } // anonymous namespace

} // namespace unittest

⌨️ 快捷键说明

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