Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - tests/wispers/utility - CircularFindTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 23 23 100.0 %
Date: 2012-04-09 Functions: 8 8 100.0 %
Branches: 58 112 51.8 %

           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/utility/CircularFind.h>
      17                 :            : #include <ssrc/wispers/utility/ToString.h>
      18                 :            : 
      19                 :            : #define BOOST_TEST_MODULE CircularFindTest
      20                 :            : #include <boost/test/unit_test.hpp>
      21                 :            : 
      22                 :            : using namespace NS_SSRC_WSPR_UTILITY;
      23                 :            : 
      24                 :            : struct StrCmp {
      25                 :            :   const string & str;
      26                 :            : 
      27                 :          5 :   StrCmp(const string & str) : str(str) { }
      28                 :            : 
      29                 :         25 :   bool operator()(const char *c_str) const {
      30                 :         25 :     return (str == c_str);
      31                 :            :   }
      32                 :            : };
      33                 :            : 
      34   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_find_int_array) {
      35                 :          1 :   int foo[5] = { 1, 2, 3, 4, 5 };
      36                 :          1 :   const CircularFind<int *> find(&foo[0], &foo[5]);
      37                 :            : 
      38         [ +  + ]:          6 :   for(int i = 5; i > 0; --i) {
      39   [ +  -  -  + ]:          5 :     BOOST_CHECK_EQUAL(*find.find(i), i);
      40                 :            :   }
      41                 :            : 
      42   [ +  -  +  -  :          1 :   BOOST_CHECK(find.find(10) == find.end());
          +  -  +  -  -  
                      + ]
      43   [ +  -  +  -  :          1 :   BOOST_CHECK(find.find(1) == find.begin());
          +  -  +  -  -  
                      + ]
      44                 :          1 : }
      45                 :            : 
      46   [ +  -  +  - ]:          3 : BOOST_AUTO_TEST_CASE(test_find_str_array) {
      47                 :          1 :   const char * const foo[5] = { "1", "2", "3", "4", "5" };
      48                 :          1 :   const CircularFind<const char * const *> find(&foo[0], &foo[5]);
      49                 :          2 :   ToString string_cast;
      50                 :            : 
      51         [ +  + ]:          6 :   for(int i = 5; i > 0; --i) {
      52   [ +  -  +  -  :         10 :     const string str = string_cast(i);
                   +  - ]
      53                 :            :     const CircularFind<const char * const *>::iterator it =
      54         [ +  - ]:          5 :       find.find_if(StrCmp(str));
      55                 :            : 
      56   [ +  -  +  -  :          5 :     BOOST_CHECK(it != find.end());
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
      57   [ +  -  +  -  :          5 :     BOOST_CHECK_EQUAL(*it, str);
          +  -  +  -  +  
                -  -  + ]
      58                 :            :   }
      59                 :            : 
      60   [ +  -  +  -  :          1 :   BOOST_CHECK(find.find("10") == find.end());
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      61   [ +  -  +  -  :          1 :   BOOST_CHECK(find.find("1") == find.begin());
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      62   [ +  -  +  - ]:          4 : }