Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - tests/wispers/database - VectorBlobTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 22 22 100.0 %
Date: 2012-04-09 Functions: 17 19 89.5 %
Branches: 89 187 47.6 %

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