mfc.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. // Boost.Range MFC Extension
  2. //
  3. // Copyright Shunsuke Sogame 2005-2006.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <afx.h> // must be here
  8. // #include <pstade/vodka/drink.hpp>
  9. #include <boost/test/test_tools.hpp>
  10. #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
  11. #define _ATL_NO_AUTOMATIC_NAMESPACE
  12. #define BOOST_LIB_NAME boost_test_exec_monitor
  13. #include <boost/config/auto_link.hpp>
  14. #define BOOST_RANGE_DETAIL_MICROSOFT_TEST
  15. #include <boost/range/mfc.hpp> // can be placed first
  16. #include <map>
  17. #include <boost/concept_check.hpp>
  18. // #include <boost/foreach.hpp>
  19. #include <boost/range/begin.hpp>
  20. #include <boost/range/concepts.hpp>
  21. #include <boost/range/end.hpp>
  22. #include <boost/static_assert.hpp>
  23. #include <boost/algorithm/string.hpp>
  24. #include <afx.h>
  25. #include <afxcoll.h>
  26. #include <afxtempl.h>
  27. #if !(_ATL_VER < 0x0700)
  28. #include <cstringt.h>
  29. #include <atlsimpstr.h>
  30. #include <atlstr.h>
  31. #endif
  32. namespace brdm = boost::range_detail_microsoft;
  33. // helpers
  34. //
  35. template< class MfcMapT, class MapT >
  36. bool test_mfc_map(MfcMapT& map, const MapT& sample)
  37. {
  38. typedef typename boost::range_iterator<MfcMapT>::type iter_t;
  39. typedef typename boost::range_const_iterator<MapT>::type siter_t;
  40. bool result = true;
  41. result = result && (boost::distance(map) == boost::distance(sample));
  42. if (!result)
  43. return false;
  44. {
  45. for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) {
  46. result = result && brdm::test_find_key_and_mapped(sample, *it);
  47. }
  48. }
  49. {
  50. for (siter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) {
  51. result = result && (map[it->first] == it->second);
  52. }
  53. }
  54. return result;
  55. }
  56. template< class MfcMapT, class MapT >
  57. bool test_mfc_cpair_map(MfcMapT& map, const MapT& sample)
  58. {
  59. typedef typename boost::range_iterator<MfcMapT>::type iter_t;
  60. typedef typename boost::range_const_iterator<MapT>::type siter_t;
  61. bool result = true;
  62. result = result && (boost::distance(map) == boost::distance(sample));
  63. if (!result)
  64. return false;
  65. {
  66. for (iter_t it = boost::begin(map), last = boost::end(map); it != last; ++it) {
  67. result = result && brdm::test_find_key_and_mapped(sample, std::make_pair(it->key, it->value));
  68. }
  69. }
  70. {
  71. for (siter_t it = boost::begin(sample), last = boost::end(sample); it != last; ++it) {
  72. result = result && (map[it->first] == it->second);
  73. }
  74. }
  75. return result;
  76. }
  77. // arrays
  78. //
  79. template< class Range >
  80. void test_CByteArray(const Range& sample)
  81. {
  82. typedef typename boost::range_value<Range>::type val_t;
  83. typedef ::CByteArray rng_t;
  84. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, BYTE *>::value ));
  85. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, BYTE const*>::value ));
  86. rng_t rng;
  87. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  88. BOOST_CHECK( brdm::test_random_access(rng) );
  89. BOOST_CHECK( brdm::test_emptiness(rng) );
  90. }
  91. template< class Range >
  92. void test_CDWordArray(const Range& sample)
  93. {
  94. typedef typename boost::range_value<Range>::type val_t;
  95. typedef ::CDWordArray rng_t;
  96. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, DWORD *>::value ));
  97. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, DWORD const*>::value ));
  98. rng_t rng;
  99. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  100. BOOST_CHECK( brdm::test_random_access(rng) );
  101. BOOST_CHECK( brdm::test_emptiness(rng) );
  102. }
  103. template< class Range >
  104. void test_CObArray(const Range& sample)
  105. {
  106. typedef typename boost::range_value<Range>::type val_t;
  107. typedef ::CObArray rng_t;
  108. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, brdm::mfc_ptr_array_iterator<rng_t, ::CObject *> >::value ));
  109. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, brdm::mfc_ptr_array_iterator<const rng_t, const ::CObject *> >::value ));
  110. rng_t rng;
  111. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  112. BOOST_CHECK( brdm::test_random_access(rng) );
  113. BOOST_CHECK( brdm::test_emptiness(rng) );
  114. }
  115. template< class Range >
  116. void test_CPtrArray(const Range& sample)
  117. {
  118. typedef typename boost::range_value<Range>::type val_t;
  119. typedef ::CPtrArray rng_t;
  120. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, brdm::mfc_ptr_array_iterator<rng_t, void *> >::value ));
  121. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, brdm::mfc_ptr_array_iterator<const rng_t, const void *> >::value ));
  122. rng_t rng;
  123. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  124. BOOST_CHECK( brdm::test_random_access(rng) );
  125. BOOST_CHECK( brdm::test_emptiness(rng) );
  126. }
  127. template< class Range >
  128. void test_CStringArray(const Range& sample)
  129. {
  130. typedef typename boost::range_value<Range>::type val_t;
  131. typedef ::CStringArray rng_t;
  132. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, ::CString *>::value ));
  133. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, ::CString const *>::value ));
  134. rng_t rng;
  135. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  136. BOOST_CHECK( brdm::test_random_access(rng) );
  137. BOOST_CHECK( brdm::test_emptiness(rng) );
  138. }
  139. template< class Range >
  140. void test_CUIntArray(const Range& sample)
  141. {
  142. typedef typename boost::range_value<Range>::type val_t;
  143. typedef ::CUIntArray rng_t;
  144. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, UINT *>::value ));
  145. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, UINT const *>::value ));
  146. rng_t rng;
  147. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  148. BOOST_CHECK( brdm::test_random_access(rng) );
  149. BOOST_CHECK( brdm::test_emptiness(rng) );
  150. }
  151. template< class Range >
  152. void test_CWordArray(const Range& sample)
  153. {
  154. typedef typename boost::range_value<Range>::type val_t;
  155. typedef ::CWordArray rng_t;
  156. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, WORD *>::value ));
  157. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, WORD const *>::value ));
  158. rng_t rng;
  159. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  160. BOOST_CHECK( brdm::test_random_access(rng) );
  161. BOOST_CHECK( brdm::test_emptiness(rng) );
  162. }
  163. // lists
  164. //
  165. template< class Range >
  166. void test_CObList(const Range& sample)
  167. {
  168. typedef typename boost::range_value<Range>::type val_t;
  169. typedef ::CObList rng_t;
  170. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator<rng_t, ::CObject *> >::value ));
  171. #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF)
  172. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, ::CObject const *> >::value ));
  173. #else
  174. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, ::CObject const * const, ::CObject const * const> >::value ));
  175. #endif
  176. rng_t rng;
  177. BOOST_CHECK( brdm::test_init_list(rng, sample) );
  178. BOOST_CHECK( brdm::test_bidirectional(rng) );
  179. BOOST_CHECK( brdm::test_emptiness(rng) );
  180. }
  181. template< class Range >
  182. void test_CPtrList(const Range& sample)
  183. {
  184. typedef typename boost::range_value<Range>::type val_t;
  185. typedef ::CPtrList rng_t;
  186. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator<rng_t, void *> >::value ));
  187. #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF)
  188. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, void const *> >::value ));
  189. #else
  190. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, void const * const, void const * const> >::value ));
  191. #endif
  192. rng_t rng;
  193. BOOST_CHECK( brdm::test_init_list(rng, sample) );
  194. BOOST_CHECK( brdm::test_bidirectional(rng) );
  195. BOOST_CHECK( brdm::test_emptiness(rng) );
  196. }
  197. template< class Range >
  198. void test_CStringList(const Range& sample)
  199. {
  200. typedef typename boost::range_value<Range>::type val_t;
  201. typedef ::CStringList rng_t;
  202. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator<rng_t, ::CString> >::value ));
  203. #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF)
  204. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, ::CString const> >::value ));
  205. #else
  206. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, ::CString const, ::CString const> >::value ));
  207. #endif
  208. rng_t rng;
  209. BOOST_CHECK( brdm::test_init_list(rng, sample) );
  210. BOOST_CHECK( brdm::test_bidirectional(rng) );
  211. BOOST_CHECK( brdm::test_emptiness(rng) );
  212. }
  213. // maps
  214. //
  215. template< class MapT >
  216. void test_CMapPtrToWord(const MapT& sample)
  217. {
  218. typedef ::CMapPtrToWord rng_t;
  219. rng_t rng;
  220. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  221. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  222. BOOST_CHECK( ::test_mfc_map(rng, sample) );
  223. BOOST_CHECK( brdm::test_emptiness(rng) );
  224. }
  225. template< class MapT >
  226. void test_CMapPtrToPtr(const MapT& sample)
  227. {
  228. typedef ::CMapPtrToPtr rng_t;
  229. rng_t rng;
  230. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  231. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  232. BOOST_CHECK( ::test_mfc_map(rng, sample) );
  233. BOOST_CHECK( brdm::test_emptiness(rng) );
  234. }
  235. template< class MapT >
  236. void test_CMapStringToOb(const MapT& sample)
  237. {
  238. typedef ::CMapStringToOb rng_t;
  239. rng_t rng;
  240. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  241. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  242. BOOST_CHECK( ::test_mfc_map(rng, sample) );
  243. BOOST_CHECK( brdm::test_emptiness(rng) );
  244. }
  245. template< class MapT >
  246. void test_CMapStringToPtr(const MapT& sample)
  247. {
  248. typedef ::CMapStringToPtr rng_t;
  249. rng_t rng;
  250. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  251. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  252. BOOST_CHECK( ::test_mfc_map(rng, sample) );
  253. BOOST_CHECK( brdm::test_emptiness(rng) );
  254. }
  255. template< class MapT >
  256. void test_CMapStringToString(const MapT& sample)
  257. {
  258. typedef ::CMapStringToString rng_t;
  259. rng_t rng;
  260. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  261. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  262. #if !defined(BOOST_RANGE_MFC_NO_CPAIR)
  263. BOOST_CHECK( ::test_mfc_cpair_map(rng, sample) );
  264. #endif
  265. BOOST_CHECK( brdm::test_emptiness(rng) );
  266. }
  267. template< class MapT >
  268. void test_CMapWordToOb(const MapT& sample)
  269. {
  270. typedef ::CMapWordToOb rng_t;
  271. rng_t rng;
  272. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  273. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  274. BOOST_CHECK( ::test_mfc_map(rng, sample) );
  275. BOOST_CHECK( brdm::test_emptiness(rng) );
  276. }
  277. template< class MapT >
  278. void test_CMapWordToPtr(const MapT& sample)
  279. {
  280. typedef ::CMapWordToPtr rng_t;
  281. rng_t rng;
  282. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  283. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  284. BOOST_CHECK( ::test_mfc_map(rng, sample) );
  285. BOOST_CHECK( brdm::test_emptiness(rng) );
  286. }
  287. // templates
  288. //
  289. template< class Range >
  290. void test_CArray(const Range& sample)
  291. {
  292. typedef typename boost::range_value<Range>::type val_t;
  293. typedef ::CArray<val_t, const val_t&> rng_t; // An old MFC needs the second template argument.
  294. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, val_t *>::value ));
  295. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, val_t const*>::value ));
  296. rng_t rng;
  297. BOOST_CHECK( brdm::test_init_array(rng, sample) );
  298. BOOST_CHECK( brdm::test_random_access(rng) );
  299. BOOST_CHECK( brdm::test_emptiness(rng) );
  300. }
  301. template< class Range >
  302. void test_CList(const Range& sample)
  303. {
  304. typedef typename boost::range_value<Range>::type val_t;
  305. typedef ::CList<val_t, const val_t&> rng_t;
  306. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter< rng_t, brdm::list_iterator<rng_t, val_t> >::value ));
  307. #if !defined(BOOST_RANGE_MFC_CONST_COL_RETURNS_NON_REF)
  308. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, val_t const> >::value ));
  309. #else
  310. BOOST_STATIC_ASSERT(( brdm::test_const_iter < rng_t, brdm::list_iterator<rng_t const, val_t const, val_t const> >::value ));
  311. #endif
  312. rng_t rng;
  313. BOOST_CHECK( brdm::test_init_list(rng, sample) );
  314. BOOST_CHECK( brdm::test_bidirectional(rng) );
  315. BOOST_CHECK( brdm::test_emptiness(rng) );
  316. }
  317. template< class MapT >
  318. void test_CMap(const MapT& sample)
  319. {
  320. typedef typename MapT::key_type k_t;
  321. typedef typename MapT::mapped_type m_t;
  322. typedef ::CMap<k_t, const k_t&, m_t, const m_t&> rng_t;
  323. rng_t rng;
  324. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  325. BOOST_CHECK( brdm::test_init_map(rng, sample) );
  326. #if !defined(BOOST_RANGE_MFC_NO_CPAIR)
  327. BOOST_CHECK( ::test_mfc_cpair_map(rng, sample) );
  328. #endif
  329. BOOST_CHECK( brdm::test_emptiness(rng) );
  330. }
  331. void test_CTypedPtrArray()
  332. {
  333. typedef ::CTypedPtrArray< ::CPtrArray, int * > rng_t;
  334. boost::function_requires< boost::RandomAccessRangeConcept<rng_t> >();
  335. rng_t rng;
  336. int o1, o2, o3, o4, o5;
  337. int *data[] = { &o1, &o2, &o3, &o4, &o5 };
  338. BOOST_CHECK( brdm::test_init_array(rng, boost::make_iterator_range(data, data+5)) );
  339. BOOST_CHECK( *(boost::begin(rng) + 2) == &o3 );
  340. BOOST_CHECK( *(boost::end(rng) - 1) == &o5 );
  341. // BOOST_CHECK( brdm::test_random_access(rng) ); this range is not mutable
  342. BOOST_CHECK( brdm::test_emptiness(rng) );
  343. }
  344. void test_CTypedPtrList()
  345. {
  346. typedef ::CTypedPtrList< ::CObList, ::CObList * > rng_t;
  347. boost::function_requires< boost::BidirectionalRangeConcept<rng_t> >();
  348. rng_t rng;
  349. ::CObList o1, o2, o3, o4, o5;
  350. ::CObList *data[] = { &o1, &o2, &o3, &o4, &o5 };
  351. BOOST_CHECK( brdm::test_init_list(rng, data) );
  352. boost::range_iterator<rng_t>::type it = boost::begin(rng);
  353. std::advance(it, 1);
  354. BOOST_CHECK( *it == &o2 );
  355. std::advance(it, 2);
  356. BOOST_CHECK( *it == &o4 );
  357. // BOOST_CHECK( brdm::test_bidirectional(rng) ); this range is not mutable
  358. BOOST_CHECK( brdm::test_emptiness(rng) );
  359. }
  360. void test_CTypedPtrMap()
  361. {
  362. typedef ::CTypedPtrMap< ::CMapStringToPtr, ::CString, int *> rng_t;
  363. boost::function_requires< boost::ForwardRangeConcept<rng_t> >();
  364. rng_t rng;
  365. ::CString o0(_T('a')), o1(_T('c')), o2(_T('f')), o3(_T('q')), o4(_T('g'));
  366. int d0, d1, d2, d3, d4;
  367. std::map< ::CString, int * > data;
  368. data[o0] = &d0, data[o1] = &d1, data[o2] = &d2, data[o3] = &d3, data[o4] = &d4;
  369. BOOST_CHECK( brdm::test_init_map(rng, data) );
  370. BOOST_CHECK( ::test_mfc_map(rng, data) );
  371. BOOST_CHECK( brdm::test_emptiness(rng) );
  372. }
  373. // strings
  374. //
  375. #if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING)
  376. template< class Range >
  377. void test_CString(const Range& sample)
  378. {
  379. typedef typename boost::range_value<Range>::type val_t;
  380. typedef ::CString rng_t; // An old MFC needs the second template argument.
  381. BOOST_STATIC_ASSERT(( brdm::test_mutable_iter<rng_t, TCHAR *>::value ));
  382. BOOST_STATIC_ASSERT(( brdm::test_const_iter <rng_t, TCHAR const*>::value ));
  383. rng_t rng;
  384. BOOST_CHECK( brdm::test_init_string(rng, sample) );
  385. BOOST_CHECK( brdm::test_random_access(rng) );
  386. BOOST_CHECK( brdm::test_emptiness(rng) );
  387. }
  388. #endif
  389. struct CPerson
  390. {
  391. void hello_range() { };
  392. };
  393. void test_mfc()
  394. {
  395. #if 0
  396. // overview
  397. //
  398. {
  399. CTypedPtrArray<CPtrArray, CList<CString> *> myArray;
  400. // ...
  401. BOOST_FOREACH (CList<CString> *theList, myArray)
  402. {
  403. BOOST_FOREACH (CString& str, *theList)
  404. {
  405. boost::to_upper(str);
  406. std::sort(boost::begin(str), boost::end(str));
  407. // ...
  408. }
  409. }
  410. }
  411. #endif
  412. // arrays
  413. //
  414. {
  415. BYTE data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 };
  416. ::test_CByteArray(boost::make_iterator_range(data, data+22));
  417. }
  418. {
  419. DWORD data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 };
  420. test_CDWordArray(boost::make_iterator_range(data, data+22));
  421. }
  422. {
  423. ::CObArray o1, o2, o3, o4, o5;
  424. ::CObject *data[] = { &o1, &o2, &o3, &o4, &o5 };
  425. ::test_CObArray(boost::make_iterator_range(data, data+5));
  426. }
  427. {
  428. ::CPtrArray o1, o2, o3, o4, o5;
  429. void *data[] = { &o1, &o2, &o3, &o4, &o5 };
  430. ::test_CPtrArray(boost::make_iterator_range(data, data+5));
  431. }
  432. {
  433. ::CString data[] = {
  434. ::CString(_T('0')), ::CString(_T('1')), ::CString(_T('2')), ::CString(_T('3')),
  435. ::CString(_T('4')), ::CString(_T('5')), ::CString(_T('6')), ::CString(_T('7'))
  436. };
  437. ::test_CStringArray(boost::make_iterator_range(data, data+8));
  438. }
  439. {
  440. ::CUIntArray rng;
  441. UINT data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 };
  442. ::test_CUIntArray(boost::make_iterator_range(data, data+22));
  443. }
  444. {
  445. ::CWordArray rng;
  446. WORD data[] = { 4,5,1,3,5,12,3,1,3,1,6,1,3,60,1,1,5,1,3,1,10 };
  447. ::test_CWordArray(boost::make_iterator_range(data, data+22));
  448. }
  449. // lists
  450. //
  451. {
  452. ::CObList rng;
  453. ::CObList o1, o2, o3, o4, o5;
  454. ::CObject *data[] = { &o1, &o2, &o3, &o4, &o5 };
  455. ::test_CObList(boost::make_iterator_range(data, data+5));
  456. }
  457. {
  458. ::CPtrList rng;
  459. ::CPtrList o1, o2, o3, o4, o5;
  460. void *data[] = { &o1, &o2, &o3, &o4, &o5 };
  461. ::test_CPtrList(boost::make_iterator_range(data, data+5));
  462. }
  463. {
  464. ::CString data[] = {
  465. ::CString(_T('0')), ::CString(_T('1')), ::CString(_T('2')), ::CString(_T('3')),
  466. ::CString(_T('4')), ::CString(_T('5')), ::CString(_T('6')), ::CString(_T('7'))
  467. };
  468. ::test_CStringList(boost::make_iterator_range(data, data+8));
  469. }
  470. // maps
  471. //
  472. {
  473. std::map<void *, WORD> data;
  474. int o0, o1, o2, o3, o4;
  475. data[&o0] = 15, data[&o1] = 14, data[&o2] = 3, data[&o3] = 6, data[&o4] = 1;
  476. ::test_CMapPtrToWord(data);
  477. }
  478. {
  479. std::map<void *, void*> data;
  480. int o0, o1, o2, o3, o4;
  481. data[&o0] = &o3, data[&o1] = &o2, data[&o2] = &o1, data[&o3] = &o0, data[&o4] = &o4;
  482. ::test_CMapPtrToPtr(data);
  483. }
  484. {
  485. std::map< ::CString, CObject * > data;
  486. CObArray o0, o1, o2, o3, o4;
  487. data[ ::CString('0') ] = &o0, data[ ::CString('1') ] = &o1, data[ ::CString('2') ] = &o2,
  488. data[ ::CString('3') ] = &o3, data[ ::CString('4') ] = &o4;
  489. ::test_CMapStringToOb(data);
  490. }
  491. {
  492. std::map< ::CString, void * > data;
  493. CObArray o0, o1, o2, o3, o4;
  494. data[ ::CString('0') ] = &o0, data[ ::CString('1') ] = &o1, data[ ::CString('2') ] = &o2,
  495. data[ ::CString('3') ] = &o3, data[ ::CString('4') ] = &o4;
  496. ::test_CMapStringToPtr(data);
  497. }
  498. {
  499. std::map< ::CString, ::CString > data;
  500. CString o0('a'), o1('b'), o2('c'), o3('d'), o4('e');
  501. data[ ::CString('0') ] = o0, data[ ::CString('1') ] = o1, data[ ::CString('2') ] = o2,
  502. data[ ::CString('3') ] = o3, data[ ::CString('4') ] = o4;
  503. ::test_CMapStringToString(data);
  504. }
  505. {
  506. std::map< WORD, CObject * > data;
  507. ::CDWordArray o0, o1, o2, o3, o4;
  508. data[21] = &o3, data[52] = &o2, data[12] = &o1, data[76] = &o0, data[54] = &o4;
  509. ::test_CMapWordToOb(data);
  510. }
  511. {
  512. std::map< WORD, void * > data;
  513. ::CDWordArray o0, o1, o2, o3, o4;
  514. data[21] = &o3, data[52] = &o2, data[12] = &o1, data[76] = &o0, data[54] = &o4;
  515. ::test_CMapWordToPtr(data);
  516. }
  517. // templates
  518. //
  519. {
  520. std::string data("0987654321qwertyuiop");
  521. ::test_CArray(data);
  522. ::test_CList(data);
  523. }
  524. {
  525. std::wstring data(L"asdfghjklzxcvbnm");
  526. ::test_CArray(data);
  527. ::test_CList(data);
  528. }
  529. {
  530. std::map< int, std::string > data;
  531. data[0] = "abcde", data[1] = "ajfie", data[2] = "lij", data[3] = "abc", data[4] = "ioiu";
  532. ::test_CMap(data);
  533. }
  534. // typed
  535. //
  536. {
  537. ::test_CTypedPtrArray();
  538. ::test_CTypedPtrList();
  539. ::test_CTypedPtrMap();
  540. }
  541. // strings
  542. //
  543. #if defined(BOOST_RANGE_MFC_HAS_LEGACY_STRING)
  544. {
  545. std::string data("123456789 abcdefghijklmn");
  546. ::test_CString(data);
  547. }
  548. #endif
  549. } // test_mfc
  550. #include <boost/test/unit_test.hpp>
  551. using boost::unit_test::test_suite;
  552. test_suite *
  553. init_unit_test_suite(int argc, char* argv[])
  554. {
  555. test_suite *test = BOOST_TEST_SUITE("MFC Range Test Suite");
  556. test->add(BOOST_TEST_CASE(&test_mfc));
  557. (void)argc, (void)argv; // unused
  558. return test;
  559. }