LCOV - code coverage report
Current view: top level - testsuite - DumpRestoreTest.cc (source / functions) Hit Total Coverage
Test: STX B+ Tree Testsuite Lines: 28 28 100.0 %
Date: 2011-05-18 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 18 50.0 %

           Branch data     Line data    Source code
       1                 :            : // $Id: DumpRestoreTest.cc 128 2011-05-18 07:23:35Z tb $
       2                 :            : 
       3                 :            : /*
       4                 :            :  * STX B+ Tree Template Classes v0.8.6
       5                 :            :  * Copyright (C) 2008-2011 Timo Bingmann
       6                 :            :  *
       7                 :            :  * This library is free software; you can redistribute it and/or modify it
       8                 :            :  * under the terms of the GNU Lesser General Public License as published by the
       9                 :            :  * Free Software Foundation; either version 2.1 of the License, or (at your
      10                 :            :  * option) any later version.
      11                 :            :  *
      12                 :            :  * This library is distributed in the hope that it will be useful, but WITHOUT
      13                 :            :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :            :  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
      15                 :            :  * for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU Lesser General Public License
      18                 :            :  * along with this library; if not, write to the Free Software Foundation,
      19                 :            :  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <cppunit/extensions/HelperMacros.h>
      23                 :            : 
      24                 :            : #include <stdlib.h>
      25                 :            : 
      26                 :            : #include <sstream>
      27                 :            : #include <iostream>
      28                 :            : 
      29                 :            : #include <stx/btree_multiset.h>
      30                 :            : 
      31                 :            : class DumpRestoreTest : public CPPUNIT_NS::TestFixture
      32 [ +  - ][ #  # ]:          2 : {
      33 [ +  - ][ +  - ]:          2 :     CPPUNIT_TEST_SUITE( DumpRestoreTest );
                 [ #  # ]
      34                 :          1 :     CPPUNIT_TEST(test_dump_restore_3200);
      35                 :          2 :     CPPUNIT_TEST_SUITE_END();
      36                 :            : 
      37                 :            : protected:
      38                 :            : 
      39                 :            :     struct traits_nodebug
      40                 :            :     {
      41                 :            :         static const bool       selfverify = true;
      42                 :            :         static const bool       debug = false;
      43                 :            : 
      44                 :            :         static const int        leafslots = 8;
      45                 :            :         static const int        innerslots = 8;
      46                 :            :     };
      47                 :            : 
      48                 :          1 :     void test_dump_restore_3200()
      49                 :            :     {
      50                 :            :         typedef stx::btree_multiset<unsigned int,
      51                 :            :             std::less<unsigned int>, struct traits_nodebug> btree_type;
      52                 :            : 
      53                 :          1 :         std::string dumpstr;
      54                 :            : 
      55                 :            :         {
      56                 :          1 :             btree_type bt;
      57                 :            : 
      58                 :          1 :             srand(34234235);
      59         [ +  + ]:       3201 :             for(unsigned int i = 0; i < 3200; i++)
      60                 :            :             {
      61                 :       3200 :                 bt.insert(rand() % 100);
      62                 :            :             }
      63                 :            : 
      64                 :          1 :             CPPUNIT_ASSERT(bt.size() == 3200);
      65                 :            : 
      66                 :          1 :             std::ostringstream os;
      67                 :          1 :             bt.dump(os);
      68                 :            : 
      69                 :          1 :             dumpstr = os.str();
      70                 :            :         }
      71                 :            : 
      72                 :            :         // Also cannot check the length, because it depends on the rand()
      73                 :            :         // algorithm in stdlib.
      74                 :            :         // CPPUNIT_ASSERT( dumpstr.size() == 47772 );
      75                 :            : 
      76                 :            :         // cannot check the string with a hash function, because it contains
      77                 :            :         // memory pointers
      78                 :            : 
      79                 :            :         { // restore the btree image
      80                 :          1 :             btree_type bt2;
      81                 :            : 
      82                 :          1 :             std::istringstream iss(dumpstr);
      83                 :          1 :             CPPUNIT_ASSERT( bt2.restore(iss) );
      84                 :            : 
      85                 :          1 :             CPPUNIT_ASSERT( bt2.size() == 3200 );
      86                 :            : 
      87                 :          1 :             srand(34234235);
      88         [ +  + ]:       3201 :             for(unsigned int i = 0; i < 3200; i++)
      89                 :            :             {
      90                 :       3200 :                 CPPUNIT_ASSERT( bt2.exists(rand() % 100) );
      91                 :          1 :             }
      92                 :            :         }
      93                 :            : 
      94                 :            :         { // try restore the btree image using a different instantiation
      95                 :            : 
      96                 :            :             typedef stx::btree_multiset<long long,
      97                 :            :                 std::less<long long>, struct traits_nodebug> otherbtree_type;
      98                 :            : 
      99                 :          1 :             otherbtree_type bt3;
     100                 :            : 
     101                 :          1 :             std::istringstream iss(dumpstr);
     102                 :          1 :             CPPUNIT_ASSERT( !bt3.restore(iss) );
     103                 :          1 :         }
     104                 :          1 :     }
     105                 :            : };
     106                 :            : 
     107 [ +  - ][ +  - ]:          3 : CPPUNIT_TEST_SUITE_REGISTRATION( DumpRestoreTest );

Generated by: LCOV version 1.9