diff --git a/compressed_pair_test.cpp b/compressed_pair_test.cpp new file mode 100644 index 0000000..ebbaa78 --- /dev/null +++ b/compressed_pair_test.cpp @@ -0,0 +1,140 @@ +// boost::compressed_pair test program + +// (C) Copyright John Maddock 2000. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +#include +#include +#include + +#include + +using namespace boost; + +#ifdef __BORLANDC__ +#pragma option -w-ccc -w-rch -w-eff -w-aus +#endif + +// +// define tests here +unsigned failures = 0; +unsigned test_count = 0; + +#define value_test(v, x) ++test_count;\ + if(v != x){++failures; std::cout << "checking value of " << #x << "...failed" << std::endl;} + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +#define type_test(v, x) ++test_count;\ + if(boost::is_same::value == false){\ + ++failures; \ + std::cout << "checking type of " << #x << "...failed" << std::endl; \ + std::cout << " expected type was " << #v << std::endl; \ + std::cout << " " << typeid(boost::is_same).name() << "::value is false" << std::endl; } +#else +#define type_test(v, x) ++test_count;\ + if(typeid(v) != typeid(x)){\ + ++failures; \ + std::cout << "checking type of " << #x << "...failed" << std::endl; \ + std::cout << " expected type was " << #v << std::endl; \ + std::cout << " " << "typeid(" #v ") != typeid(" #x ")" << std::endl; } +#endif + +struct empty_POD_UDT{}; +struct empty_UDT +{ + ~empty_UDT(){}; +}; +namespace boost { +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +template <> struct is_empty +{ static const bool value = true; }; +template <> struct is_empty +{ static const bool value = true; }; +template <> struct is_POD +{ static const bool value = true; }; +#else +template <> struct is_empty +{ enum{ value = true }; }; +template <> struct is_empty +{ enum{ value = true }; }; +template <> struct is_POD +{ enum{ value = true }; }; +#endif +} + + +int main() +{ + compressed_pair cp1(1, 1.3); + assert(cp1.first() == 1); + assert(cp1.second() == 1.3); + compressed_pair cp1b(2, 2.3); + assert(cp1b.first() == 2); + assert(cp1b.second() == 2.3); + swap(cp1, cp1b); + assert(cp1b.first() == 1); + assert(cp1b.second() == 1.3); + assert(cp1.first() == 2); + assert(cp1.second() == 2.3); +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + compressed_pair cp2(2); + assert(cp2.second() == 2); +#endif + compressed_pair cp3(1); + assert(cp3.first() ==1); + compressed_pair cp4; + compressed_pair cp5; +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + int i = 0; + compressed_pair cp6(i,i); + assert(cp6.first() == i); + assert(cp6.second() == i); + assert(&cp6.first() == &i); + assert(&cp6.second() == &i); + compressed_pair cp7; + cp7.first(); + double* pd = cp7.second(); +#endif + value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) + value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) + value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) + value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) + value_test(true, (sizeof(compressed_pair >) < sizeof(std::pair >))) + + std::cout << std::endl << test_count << " tests completed (" << failures << " failures)... press any key to exit"; + std::cin.get(); + return failures; +} + +// +// instanciate some compressed pairs: +template class boost::compressed_pair; +template class boost::compressed_pair; +template class boost::compressed_pair; +template class boost::compressed_pair; +template class boost::compressed_pair; +template class boost::compressed_pair; + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +// +// now some for which only a few specific members can be instantiated, +// first references: +template double& compressed_pair::first(); +template int& compressed_pair::second(); +template compressed_pair::compressed_pair(int&); +template compressed_pair::compressed_pair(call_traits::param_type,int&); +// +// and then arrays: +#ifndef __BORLANDC__ +template call_traits::reference compressed_pair::second(); +#endif +template call_traits::reference compressed_pair::first(); +template compressed_pair::compressed_pair(const double&); +template compressed_pair::compressed_pair(); +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + + +