📄 atl.cpp
字号:
BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, typename rng_t::PCXSTR>::value )); rng_t rng; BOOST_CHECK( brdm::test_init_string(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class Range >void test_CStaticString(const Range& sample){#if !defined(BOOST_RANGE_ATL_NO_TEST_UNDOCUMENTED_RANGE) { typedef ATL::CStaticString<char, 20> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, char const *>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, char const *>::value )); rng_t rng("hello static string"); BOOST_CHECK( *(boost::begin(rng)+4) == 'o' ); BOOST_CHECK( *(boost::end(rng)-3) == 'i' ); } { typedef ATL::CStaticString<wchar_t, 40> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, wchar_t const *>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, wchar_t const *>::value )); rng_t rng(L"hello static string"); BOOST_CHECK( *(boost::begin(rng)+4) == L'o' ); BOOST_CHECK( *(boost::end(rng)-3) == L'i' ); }#endif (void)sample; // unused}#endif // !(_ATL_VER < 0x0700) template< class Range >void test_CComBSTR(const Range& sample){ typedef ATL::CComBSTR rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, OLECHAR *>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, OLECHAR const*>::value )); rng_t rng(OLESTR("hello CComBSTR range!")); BOOST_CHECK( brdm::test_equals(rng, std::string("hello CComBSTR range!")) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) ); (void)sample; // unused}// simples//template< class Range >void test_CSimpleArray(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef ATL::CSimpleArray<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, val_t *>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, val_t const*>::value )); rng_t rng; BOOST_CHECK( brdm::test_init_array(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}template< class Range >void test_CSimpleMap(const Range& sample){#if !defined(BOOST_RANGE_ATL_NO_TEST_UNDOCUMENTED_RANGE) typedef ATL::CSimpleMap<int, double> rng_t; rng_t rng; rng.Add(3, 3.0); rng.Add(4, 2.0); BOOST_CHECK( boost::begin(rng)->get<0>() == 3.0 ); BOOST_CHECK( (boost::end(rng)-1)->get<1>() == 2.0 );#endif (void)sample; // unused}template< class Range >void test_CSimpleValArray(const Range& sample){ typedef typename boost::range_value<Range>::type val_t; typedef ATL::CSimpleArray<val_t> rng_t; BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, val_t *>::value )); BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, val_t const*>::value )); rng_t rng; BOOST_CHECK( brdm::test_init_array(rng, sample) ); BOOST_CHECK( brdm::test_random_access(rng) ); BOOST_CHECK( brdm::test_emptiness(rng) );}// maps//template< class MapT >void test_CAtlMap(const MapT& sample){ typedef typename MapT::key_type k_t; typedef typename MapT::mapped_type m_t; typedef ATL::CAtlMap<k_t, m_t> rng_t; rng_t rng; boost::function_requires< boost::ForwardRangeConcept<rng_t> >(); BOOST_CHECK( brdm::test_init_map(rng, sample) ); BOOST_CHECK( ::test_atl_map(rng, sample) );}template< class MapT >void test_CRBTree(const MapT& sample){ typedef typename MapT::key_type k_t; typedef typename MapT::mapped_type m_t; typedef ATL::CRBMap<k_t, m_t> derived_t; typedef ATL::CRBTree<k_t, m_t> rng_t; derived_t drng; rng_t& rng = drng; boost::function_requires< boost::BidirectionalRangeConcept<rng_t> >(); BOOST_CHECK( brdm::test_init_map(drng, sample) ); BOOST_CHECK( ::test_atl_map(rng, sample) );}template< class MapT >void test_CRBMap(const MapT& sample){ typedef typename MapT::key_type k_t; typedef typename MapT::mapped_type m_t; typedef ATL::CRBMap<k_t, m_t> rng_t; rng_t rng; boost::function_requires< boost::BidirectionalRangeConcept<rng_t> >(); BOOST_CHECK( brdm::test_init_map(rng, sample) ); BOOST_CHECK( ::test_atl_map(rng, sample) );}template< class MapT >void test_CRBMultiMap(const MapT& sample){ typedef typename MapT::key_type k_t; typedef typename MapT::mapped_type m_t; typedef ATL::CRBMultiMap<k_t, m_t> rng_t; rng_t rng; boost::function_requires< boost::BidirectionalRangeConcept<rng_t> >(); BOOST_CHECK( ::test_init_atl_multimap(rng, sample) ); BOOST_CHECK( ::test_atl_map(rng, sample) );}// main test//void test_atl(){ // ordinary ranges // { std::string sample("rebecca judy and mary whiteberry chat monchy");#if !(_ATL_VER < 0x0700) ::test_CAtlArray(sample); ::test_CAtlList(sample); ::test_CSimpleStringT(sample); ::test_CFixedStringT<44>(sample); ::test_CStringT(sample); ::test_CStaticString(sample);#endif ::test_CComBSTR(sample); ::test_CSimpleArray(sample); ::test_CSimpleMap(sample); ::test_CSimpleValArray(sample); } { std::wstring sample(L"rebecca judy and mary whiteberry chat monchy");#if !(_ATL_VER < 0x0700) ::test_CAtlArray(sample); ::test_CAtlList(sample); ::test_CSimpleStringT(sample); ::test_CFixedStringT<44>(sample); ::test_CStringT(sample); ::test_CStaticString(sample);#endif ::test_CComBSTR(sample); ::test_CSimpleArray(sample); ::test_CSimpleMap(sample); ::test_CSimpleValArray(sample); } // pointer ranges //#if !(_ATL_VER < 0x0700) { typedef ATL::CAutoPtr<int> ptr_t; ptr_t ptr0(new int(3)), ptr1(new int(4)), ptr2(new int(5)), ptr3(new int(4)), ptr4(new int(1)), ptr5(new int(2)), ptr6(new int(4)), ptr7(new int(0)); ptr_t ptrs[8] = { ptr0, ptr1, ptr2, ptr3, ptr4, ptr5, ptr6, ptr7 }; boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+8); ::test_CAutoPtrArray<int>(workaround); } { typedef ATL::CAutoPtr<int> ptr_t; ptr_t ptr0(new int(3)), ptr1(new int(4)), ptr2(new int(5)), ptr3(new int(4)), ptr4(new int(1)), ptr5(new int(2)), ptr6(new int(4)), ptr7(new int(0)); ptr_t ptrs[8] = { ptr0, ptr1, ptr2, ptr3, ptr4, ptr5, ptr6, ptr7 }; boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+8); ::test_CAutoPtrList<int>(workaround); } { typedef ATL::CHeapPtr<int> ptr_t; ptr_t ptrs[5]; { ptrs[0].AllocateBytes(sizeof(int)); ptrs[1].AllocateBytes(sizeof(int)); ptrs[2].AllocateBytes(sizeof(int)); ptrs[3].AllocateBytes(sizeof(int)); ptrs[4].AllocateBytes(sizeof(int)); } boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+5); ::test_CHeapPtrList<int>(workaround); } { typedef ATL::CComQIPtr<IDispatch> ptr_t; ptr_t ptrs[8]; boost::iterator_range< ptr_t * > workaround(ptrs, ptrs+8); ::test_CInterfaceArray<IDispatch>(workaround); ::test_CInterfaceList<IDispatch>(workaround); }#endif // maps // {#if !(_ATL_VER < 0x0700) std::map<int, std::string> sample; { sample[0] = "hello"; sample[1] = "range"; sample[2] = "atl"; sample[3] = "mfc"; sample[4] = "collections"; } ::test_CAtlMap(sample); ::test_CRBTree(sample); ::test_CRBMap(sample); ::test_CRBMultiMap(sample);#endif }} // test_atl#include <boost/test/unit_test.hpp>using boost::unit_test::test_suite;test_suite *init_unit_test_suite(int argc, char* argv[]){ test_suite *test = BOOST_TEST_SUITE("ATL Range Test Suite"); test->add(BOOST_TEST_CASE(&test_atl)); (void)argc, (void)argv; // unused return test;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -