Web Wispers 1.2.0 C++ Unit Test Coverage
Current view: top level - tests/wispers/database - VectorBlobTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.0 C++ Unit Tests Lines: 32 32 100.0 %
Date: 2010-05-27 Functions: 23 25 92.0 %
Branches: 132 275 48.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2006-2009 Savarese Software Research Corporation
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at
       7                 :            :  *
       8                 :            :  *     http://www.savarese.com/software/ApacheLicense-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <tests/TestCommon.h>
      18                 :            : #include <ssrc/wispers/database/VectorBlob.h>
      19                 :            : #include <ssrc/wispers/database/RowOperations.h>
      20                 :            : #include <ssrc/wispers/database/InitializeLibrary.h>
      21                 :            : 
      22                 :            : using namespace NS_SSRC_WSPR_DATABASE;
      23                 :            : 
      24 [ +  -  +  -  # :         12 : WSPR_DB_ROW_WITH_KEY(Row, ((int, key))((VectorBlob<int>, value)), (0))
          #  #  #  #  #  
          #  +  -  +  - ]
      25                 :            : 
      26 [ +  -  +  -  - :          3 : class DatabaseTest : public TestCase {
                +  +  - ]
      27                 :            : 
      28                 :            :   InitializeLibrary _init_lib;
      29                 :            :   boost::scoped_ptr<Database> db;
      30                 :            : 
      31                 :            :   typedef RowOperations<Row> row_ops;
      32                 :            : 
      33                 :            : public:
      34                 :            : 
      35                 :          1 :   virtual void setUp() {
      36 [ +  -  +  -  + :          1 :     db.reset(new Database());
          -  +  -  +  - ]
      37                 :          1 :   }
      38                 :            : 
      39                 :          1 :   virtual void tearDown() {
      40                 :          1 :     db.reset();
      41                 :          1 :   }
      42                 :            : 
      43                 :          1 :   void init_table() {
      44 [ +  -  +  -  + :          1 :     db->execute("CREATE TABLE `Row` (`key` INTEGER PRIMARY KEY, `value` BLOB);");
                      - ]
      45                 :          1 :   }
      46                 :            : 
      47                 :          1 :   void test_row_ops() {
      48                 :          1 :     init_table();
      49                 :            : 
      50   [ +  -  +  - ]:          2 :     row_ops crud(*db);
      51   [ +  -  +  - ]:          2 :     Row row;
      52                 :          1 :     row.key = 9;
      53         [ +  - ]:          1 :     row.value.push_back(8);
      54         [ +  - ]:          1 :     row.value.push_back(7);
      55                 :            : 
      56 [ +  -  +  -  + :          1 :     CPPUNIT_ASSERT(crud.insert(row));
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      57                 :            : 
      58   [ +  -  +  - ]:          2 :     row_ops::find_result_type result = crud.find(row.key);
      59                 :            : 
      60 [ +  -  +  -  + :          1 :     CPPUNIT_ASSERT(result.first);
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      61 [ +  -  +  -  + :          1 :     CPPUNIT_ASSERT(result.second == row);
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      62 [ +  -  +  -  + :          1 :     CPPUNIT_ASSERT(result.second.key == 9);
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      63 [ +  -  +  -  + :          1 :     CPPUNIT_ASSERT(result.second.value.size() == 2);
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      64 [ +  -  +  -  + :          1 :     CPPUNIT_ASSERT(result.second.value[0] == 8);
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      65 [ +  -  +  -  + :          1 :     CPPUNIT_ASSERT(result.second.value[1] == 7);
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      66                 :          1 :   }
      67                 :            : 
      68 [ +  -  +  -  + :          4 :   CPPUNIT_TEST_SUITE(DatabaseTest);
                -  #  # ]
      69 [ +  -  +  -  + :          1 :   CPPUNIT_TEST(test_row_ops);
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      70 [ +  -  +  -  + :          2 :   CPPUNIT_TEST_SUITE_END();
          -  +  -  +  -  
                   +  - ]
      71                 :            : };
      72                 :            : 
      73   [ -  +  #  # ]:          1 : CPPUNIT_TEST_SUITE_REGISTRATION(DatabaseTest);
      74 [ +  -  +  -  + :          4 : WISP_TEST_MAIN()
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]