Wisp 1.3.1 C++ Unit Test Coverage
Current view: top level - tests/wisp/utility - wisp_struct_test.cc (source / functions) Hit Total Coverage
Test: Wisp 1.3.1 C++ Unit Tests Lines: 18 18 100.0 %
Date: 2017-01-16 Functions: 12 12 100.0 %
Branches: 51 102 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* Copyright 2006-2011 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                 :            :  *     http://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/wisp/utility/wisp_struct.h>
      17                 :            : #include <sstream>
      18                 :            : 
      19                 :            : #define BOOST_TEST_MODULE wisp_struct_test
      20                 :            : #include <boost/test/unit_test.hpp>
      21                 :            : 
      22                 :          4 : struct StringVisitor {
      23                 :            :   mutable std::ostringstream str;
      24                 :            : 
      25   [ +  -  +  - ]:          1 :   StringVisitor & reset() { str.str(""); return *this; }
      26                 :            : 
      27                 :            :   template<typename V>
      28                 :            :   const StringVisitor &
      29                 :          6 :   operator()(const char * const key, const V & value) const {
      30                 :          6 :     str << key << " : " << value << '\n';
      31                 :          6 :     return *this;
      32                 :            :   }
      33                 :            : };
      34                 :            : 
      35                 :          5 : WISP_STRUCT(IntPair, ((int, first))((int, second)));
      36                 :            : 
      37   [ +  -  +  -  :          3 : BOOST_AUTO_TEST_CASE(test_visit) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      38         [ +  - ]:          2 :   StringVisitor visitor;
      39                 :          1 :   IntPair pair(3, 11);
      40         [ +  - ]:          2 :   const std::string expected_pair("first : 3\nsecond : 11\n");
      41                 :          1 :   const IntPair const_pair(4, 10);
      42         [ +  - ]:          2 :   const std::string expected_const_pair("first : 4\nsecond : 10\n");
      43                 :            : 
      44         [ +  - ]:          1 :   pair.visit(visitor);
      45   [ +  -  +  -  :          1 :   BOOST_CHECK(visitor.str.str() == expected_pair);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
      46                 :            : 
      47   [ +  -  +  - ]:          1 :   const_pair.visit(visitor.reset());
      48   [ +  -  +  -  :          1 :   BOOST_CHECK(visitor.str.str() == expected_const_pair);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
      49                 :            : 
      50                 :            :   // This is a test to make sure it compiles, not a runtime test.
      51   [ +  -  +  - ]:          1 :   const_pair.visit(StringVisitor());
      52   [ +  -  +  - ]:          4 : }