Web Wispers 1.2.1 C++ Unit Test Coverage
Current view: top level - tests/wispers/utility - CircularFindTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.1 C++ Unit Tests Lines: 30 30 100.0 %
Date: 2011-11-11 Functions: 14 15 93.3 %
Branches: 125 250 50.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/utility/CircularFind.h>
      19                 :            : #include <ssrc/wispers/utility/ToString.h>
      20                 :            : 
      21                 :            : using namespace NS_SSRC_WSPR_UTILITY;
      22                 :            : 
      23                 :            : struct StrCmp {
      24                 :            :   const string & str;
      25                 :            : 
      26                 :          5 :   StrCmp(const string & str) : str(str) { }
      27                 :            : 
      28                 :         25 :   bool operator()(const char *c_str) const {
      29                 :         25 :     return (str == c_str);
      30                 :            :   }
      31                 :            : };
      32                 :            : 
      33         [ -  + ]:          6 : struct CircularFindTest : public TestCase {
      34                 :            : 
      35                 :          1 :   void test_find_int_array() {
      36                 :          1 :     int foo[5] = { 1, 2, 3, 4, 5 };
      37                 :          1 :     const CircularFind<int *> find(&foo[0], &foo[5]);
      38                 :            : 
      39         [ +  + ]:          6 :     for(int i = 5; i > 0; --i) {
      40   [ +  -  +  -  :          5 :       CPPUNIT_ASSERT_EQUAL(i, *find.find(i));
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      41                 :            :     }
      42                 :            : 
      43   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(find.find(10) == find.end());
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      44   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(find.find(1) == find.begin());
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      45                 :          1 :   }
      46                 :            : 
      47                 :          1 :   void test_find_str_array() {
      48                 :          1 :     const char * const foo[5] = { "1", "2", "3", "4", "5" };
      49                 :          1 :     const CircularFind<const char * const *> find(&foo[0], &foo[5]);
      50                 :          2 :     ToString string_cast;
      51                 :            : 
      52         [ +  + ]:          6 :     for(int i = 5; i > 0; --i) {
      53   [ +  -  +  -  :         10 :       const string str = string_cast(i);
                   +  - ]
      54                 :            :       const CircularFind<const char * const *>::iterator it =
      55         [ +  - ]:          5 :         find.find_if(StrCmp(str));
      56                 :            : 
      57   [ +  -  +  -  :          5 :       CPPUNIT_ASSERT(it != find.end());
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
      58   [ +  -  +  -  :          5 :       CPPUNIT_ASSERT(str == *it);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      59                 :            :     }
      60                 :            : 
      61   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(find.find("10") == find.end());
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      62   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(find.find("1") == find.begin());
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      63                 :            : 
      64                 :          1 :   }
      65                 :            : 
      66   [ +  -  +  -  :          4 :   CPPUNIT_TEST_SUITE(CircularFindTest);
             +  -  #  # ]
      67   [ +  -  +  -  :          1 :   CPPUNIT_TEST(test_find_int_array);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      68   [ +  -  +  -  :          1 :   CPPUNIT_TEST(test_find_str_array);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      69   [ +  -  +  -  :          2 :   CPPUNIT_TEST_SUITE_END();
          +  -  +  -  +  
                -  +  - ]
      70                 :            : };
      71                 :            : 
      72   [ -  +  #  # ]:          1 : CPPUNIT_TEST_SUITE_REGISTRATION(CircularFindTest);
      73   [ +  -  +  -  :          4 : WISP_TEST_MAIN()
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]