LCOV - code coverage report
Current view: top level - testsuite - DumpRestoreTest.cc (source / functions) Hit Total Coverage
Test: STX B+ Tree Testsuite Lines: 26 26 100.0 %
Date: 2013-05-05 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10