1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "preextstl.h" 29*cdf0e10cSrcweir #include "cppunit/TestAssert.h" 30*cdf0e10cSrcweir #include "cppunit/TestFixture.h" 31*cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 32*cdf0e10cSrcweir #include "postextstl.h" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <o3tl/range.hxx> 35*cdf0e10cSrcweir #include <vector> 36*cdf0e10cSrcweir #include <deque> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using o3tl::range; 41*cdf0e10cSrcweir using o3tl::make_range; 42*cdf0e10cSrcweir using o3tl::range_of; 43*cdf0e10cSrcweir using std::size_t; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir class range_test : public CppUnit::TestFixture 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir public: 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir void int_test() 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir range<int> 53*cdf0e10cSrcweir t1(12,88); 54*cdf0e10cSrcweir range<int> 55*cdf0e10cSrcweir t2(33,33); 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // ctor 58*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor1", t1.begin() == 12); 59*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor2", t1.end() == 88); 60*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor3", t2.begin() == 33); 61*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int ctor4", t2.end() == 33); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // make_range 64*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int make_range1", make_range(0,8).begin() == 0); 65*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int make_range2", make_range(0,8).end() == 8); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir // size 68*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int size1", t1.size() == size_t(t1.end() - t1.begin()) ); 69*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int size2", t2.size() == size_t(0) ); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // contains 72*cdf0e10cSrcweir range<int> t3(0,10); 73*cdf0e10cSrcweir range<int> t4(7, 15); 74*cdf0e10cSrcweir range<int> t5(12, 12); 75*cdf0e10cSrcweir range<int> t6(13, 77); 76*cdf0e10cSrcweir range<int> t7(87, 87); 77*cdf0e10cSrcweir range<int> t8(87, 88); 78*cdf0e10cSrcweir range<int> t9(88, 88); 79*cdf0e10cSrcweir range<int> t10(33, 120); 80*cdf0e10cSrcweir range<int> t11(90, 100); 81*cdf0e10cSrcweir range<int> t12(200,200); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains1", t1.contains(t1)); 84*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains2", t1.contains(t2)); 85*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains3", ! t1.contains(t3)); 86*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains4", ! t1.contains(t4)); 87*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains5", t1.contains(t5)); 88*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains6", t1.contains(t6)); 89*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains7", t1.contains(t7)); 90*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains8", t1.contains(t8)); 91*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains9", ! t1.contains(t9)); 92*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains10", ! t1.contains(t10)); 93*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains11", ! t1.contains(t11)); 94*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains12", ! t1.contains(t12)); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n1", t1.contains(50)); 97*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n2", t1.contains(12)); 98*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n3", t1.contains(87)); 99*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n4", ! t1.contains(3)); 100*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n5", ! t1.contains(11)); 101*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n6", ! t1.contains(88)); 102*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int contains n7", ! t1.contains(100)); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // overlaps 105*cdf0e10cSrcweir range<int> t13(88,99); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps1", t1.overlaps(t1)); 108*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps2", t1.overlaps(t2)); 109*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps3", ! t1.overlaps(t3)); 110*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps4", t1.overlaps(t4)); 111*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps5", t1.overlaps(t5)); 112*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps6", t1.overlaps(t6)); 113*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps7", t1.overlaps(t7)); 114*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps8", t1.overlaps(t8)); 115*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps9", ! t1.overlaps(t9)); 116*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps10", t1.overlaps(t10)); 117*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps11", ! t1.overlaps(t11)); 118*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps12", ! t1.overlaps(t12)); 119*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int overlaps13", ! t1.overlaps(t13)); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // distance_to 122*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to1", t1.distance_to(t13) == 0); 123*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to2", t1.distance_to(t9) == 0); 124*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to3", t1.distance_to(t11) == 2); 125*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to4", t1.distance_to(t8) == -1); 126*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("int distance_to5", t1.distance_to(t3) == -88); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir void iterator_test() 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir typedef std::vector<char>::const_iterator test_it; 132*cdf0e10cSrcweir const std::vector<char> hv(200,'x'); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir test_it hit1 = hv.begin() + 12; 136*cdf0e10cSrcweir test_it hit2 = hv.begin() + 88; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir range<test_it> 139*cdf0e10cSrcweir t1(hit1, hit2); 140*cdf0e10cSrcweir range<test_it> 141*cdf0e10cSrcweir t2(hv.begin()+33, hv.begin()+33); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // ctor 144*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor1", t1.begin() == hit1); 145*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor2", t1.end() == hit2); 146*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor3", t2.begin() == hv.begin()+33); 147*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec ctor4", t2.end() == hv.begin()+33); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // make_range 150*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec make_range1", make_range(hv.begin(), hv.begin()+8).begin() == hv.begin()); 151*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec make_range2", make_range(hv.begin(), hv.begin()+8).end() == hv.begin()+8); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // size 154*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec size1", t1.size() == size_t(t1.end() - t1.begin()) ); 155*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec size2", t2.size() == size_t(0) ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // contains 158*cdf0e10cSrcweir range<test_it> t3(hv.begin(), hv.begin() + 10); 159*cdf0e10cSrcweir range<test_it> t4(hv.begin() + 7, hv.begin() + 15); 160*cdf0e10cSrcweir range<test_it> t5(hit1, hit1); 161*cdf0e10cSrcweir range<test_it> t6(hv.begin() + 13, hv.begin() + 77); 162*cdf0e10cSrcweir range<test_it> t7(hv.begin() + 87, hv.begin() + 87); 163*cdf0e10cSrcweir range<test_it> t8(hv.begin() + 87, hit2); 164*cdf0e10cSrcweir range<test_it> t9(hit2, hit2); 165*cdf0e10cSrcweir range<test_it> t10(hv.begin() + 33, hv.begin() + 120); 166*cdf0e10cSrcweir range<test_it> t11(hv.begin() + 90, hv.begin() + 100); 167*cdf0e10cSrcweir range<test_it> t12(hv.begin() + 200,hv.begin() + 200); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains1", t1.contains(t1)); 170*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains2", t1.contains(t2)); 171*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains3", ! t1.contains(t3)); 172*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains4", ! t1.contains(t4)); 173*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains5", t1.contains(t5)); 174*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains6", t1.contains(t6)); 175*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains7", t1.contains(t7)); 176*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains8", t1.contains(t8)); 177*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains9", ! t1.contains(t9)); 178*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains10", ! t1.contains(t10)); 179*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains11", ! t1.contains(t11)); 180*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains12", ! t1.contains(t12)); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n1", t1.contains(hv.begin() + 50)); 183*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n2", t1.contains(hit1)); 184*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n3", t1.contains(hv.begin() + 87)); 185*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n4", ! t1.contains(hv.begin() + 3)); 186*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n5", ! t1.contains(hv.begin() + 11)); 187*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n6", ! t1.contains(hit2)); 188*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec contains n7", ! t1.contains(hv.begin() + 100)); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir // overlaps 191*cdf0e10cSrcweir range<test_it> t13(hit2, hv.begin() + 99); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps1", t1.overlaps(t1)); 194*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps2", t1.overlaps(t2)); 195*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps3", ! t1.overlaps(t3)); 196*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps4", t1.overlaps(t4)); 197*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps5", t1.overlaps(t5)); 198*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps6", t1.overlaps(t6)); 199*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps7", t1.overlaps(t7)); 200*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps8", t1.overlaps(t8)); 201*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps9", ! t1.overlaps(t9)); 202*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps10", t1.overlaps(t10)); 203*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps11", ! t1.overlaps(t11)); 204*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps12", ! t1.overlaps(t12)); 205*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec overlaps13", ! t1.overlaps(t13)); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // distance_to 208*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to1", t1.distance_to(t13) == 0); 209*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to2", t1.distance_to(t8) == -1); 210*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to3", t1.distance_to(t9) == 0); 211*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to4", t1.distance_to(t11) == 2); 212*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ivec distance_to5", t1.distance_to(t3) == -88); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir const std::vector< int* > h2(20, (int*)0); 215*cdf0e10cSrcweir std::deque< double > h3(30, 0.0); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("range_of1", range_of(h2).begin() == h2.begin()); 218*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("range_of2", range_of(h3).end() == h3.end()); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // insert your test code here. 222*cdf0e10cSrcweir void global() 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir int_test(); 225*cdf0e10cSrcweir iterator_test(); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // These macros are needed by auto register mechanism. 230*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(range_test); 231*cdf0e10cSrcweir CPPUNIT_TEST(global); 232*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 233*cdf0e10cSrcweir }; // class range_test 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 236*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(range_test); 237