LTP GCOV extension - code coverage report
Current view: directory - testsuite - DumpRestoreTest.cc
Test: STX B+ Tree Testsuite
Date: 2007-05-08 Instrumented lines: 31
Code covered: 96.8 % Executed lines: 30

       1                 : // $Id: DumpRestoreTest.cc 35 2007-04-27 11:26:33Z tb $
       2                 : 
       3                 : /*
       4                 :  * STX B+ Tree Template Classes v0.7
       5                 :  * Copyright (C) 2007 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               3 :     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                 :         // std::cerr << "dumpstr: size = " << dumpstr.size() << "\n";
      73               1 :         CPPUNIT_ASSERT( dumpstr.size() == 47772 );
      74                 : 
      75                 :         // cannot check the string with a hash function, because it contains
      76                 :         // memory pointers
      77                 : 
      78                 :         { // restore the btree image
      79               1 :             btree_type bt2;
      80                 : 
      81               1 :             std::istringstream iss(dumpstr);
      82               1 :             CPPUNIT_ASSERT( bt2.restore(iss) );
      83                 : 
      84               2 :             CPPUNIT_ASSERT( bt2.size() == 3200 );
      85                 : 
      86               1 :             srand(34234235);
      87            6402 :             for(unsigned int i = 0; i < 3200; i++)
      88                 :             {
      89            3200 :                 CPPUNIT_ASSERT( bt2.exists(rand() % 100) );
      90               1 :             }
      91                 :         }
      92                 : 
      93                 :         { // try restore the btree image using a different instantiation
      94                 : 
      95                 :             typedef stx::btree_multiset<long long,
      96                 :                 std::less<unsigned int>, struct traits_nodebug> otherbtree_type;
      97                 : 
      98               1 :             otherbtree_type bt3;
      99                 : 
     100               1 :             std::istringstream iss(dumpstr);
     101               1 :             CPPUNIT_ASSERT( !bt3.restore(iss) );
     102               1 :         }
     103               1 :     }
     104                 : };
     105               0 : 
     106               3 : CPPUNIT_TEST_SUITE_REGISTRATION( DumpRestoreTest );

Generated by: LTP GCOV extension version 1.4