Web Wispers 1.2.1 C++ Unit Test Coverage
Current view: top level - tests/wispers/utility - BindPropertiesTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.1 C++ Unit Tests Lines: 42 42 100.0 %
Date: 2011-11-11 Functions: 20 22 90.9 %
Branches: 154 312 49.4 %

           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/PropertiesToString.h>
      19                 :            : #include <ssrc/wispers/utility/BindProperties.h>
      20                 :            : 
      21                 :            : #include <boost/variant/get.hpp>
      22                 :            : 
      23                 :            : using namespace NS_SSRC_WSPR_UTILITY;
      24                 :            : 
      25                 :         14 : WISP_STRUCT(IntPair, ((int, first))((int, second)));
      26                 :          2 : WISP_STRUCT(NestedPair, ((IntPair, first))((IntPair, second)));
      27                 :            : 
      28                 :            : typedef std::vector<IntPair> IntPairV;
      29                 :            : 
      30                 :            : WSPR_IS_BINDABLE_SEQUENCE(IntPairV)
      31                 :            : 
      32                 :            : typedef std::vector<IntPairV> IntPairVV;
      33                 :            : 
      34                 :            : WSPR_IS_BINDABLE_SEQUENCE(IntPairVV)
      35                 :            : 
      36                 :            : WSPR_IS_PRIMITIVE_BINDABLE_SEQUENCE(std::vector<int>)
      37                 :            : 
      38                 :            : typedef std::vector<std::vector<int> > IntVV;
      39                 :            : 
      40                 :            : WSPR_IS_BINDABLE_SEQUENCE(IntVV)
      41                 :            : 
      42   [ +  -  +  -  :          1 : WISP_STRUCT(FooStruct,
                   +  - ]
      43                 :            :             ((IntPair, first))
      44                 :            :             ((IntPairV, second))
      45                 :            :             ((std::vector<int>, intv))
      46                 :            :             ((IntVV, third))
      47   [ +  -  +  -  :          2 :             ((IntPairVV, fourth)));
                   +  - ]
      48                 :            : 
      49         [ -  + ]:          6 : struct BindPropertiesTest : public TestCase {
      50                 :            : 
      51                 :          1 :   void test_bind_properties() {
      52                 :          2 :     Properties props;
      53                 :          1 :     NestedPair pair(IntPair(1, 2), IntPair(3, 4));
      54                 :            : 
      55   [ +  -  +  - ]:          2 :     const string expected("{[\"first\"]={[\"first\"]=1,[\"second\"]=2},[\"second\"]={[\"first\"]=3,[\"second\"]=4}}");
      56         [ +  - ]:          1 :     pair.visit(BindProperties(props));
      57                 :            : 
      58   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT_EQUAL(expected, to_string(props));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      59                 :          1 :   }
      60                 :            : 
      61                 :          1 :   void test_bindable_sequence() {
      62                 :          2 :     Properties props;
      63   [ +  -  +  - ]:          2 :     FooStruct foo;
      64                 :            : 
      65                 :          1 :     foo.first.first  = 1;
      66                 :          1 :     foo.first.second = 2;
      67         [ +  - ]:          1 :     foo.second.push_back(IntPair(3, 4));
      68         [ +  - ]:          1 :     foo.second.push_back(IntPair(5, 6));
      69                 :            : 
      70         [ +  - ]:          1 :     foo.intv.push_back(13);
      71         [ +  - ]:          1 :     foo.intv.push_back(14);
      72                 :            : 
      73         [ +  - ]:          1 :     foo.third.resize(2);
      74   [ +  -  +  - ]:          1 :     foo.third[0].push_back(11);
      75   [ +  -  +  - ]:          1 :     foo.third[1].push_back(12);
      76                 :            : 
      77         [ +  - ]:          1 :     foo.fourth.resize(2);
      78   [ +  -  +  - ]:          1 :     foo.fourth[0].push_back(IntPair(7, 8));
      79   [ +  -  +  - ]:          1 :     foo.fourth[1].push_back(IntPair(9, 10));
      80                 :            : 
      81         [ +  - ]:          1 :     foo.visit(BindProperties(props));
      82                 :            : 
      83                 :            :     // This stuff is just a sanity check in case to_string doesn't print
      84                 :            :     // nested sequences properly.
      85   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(props.get_ptr<property_vector>("third") != 0);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
      86   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(props.get_ptr<property_vector>("third")->size() == 2);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      87   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(props.get_ptr<property_vector>("third")->at(0).get_ptr<primitive_property_vector>() != 0);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      88   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(props.get_ptr<property_vector>("third")->at(0).get_ptr<primitive_property_vector>()->size() == 1);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      89   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT(boost::get<int>(props.get_ptr<property_vector>("third")->at(0).get_ptr<primitive_property_vector>()->at(0)) == 11);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
      90                 :            : 
      91                 :            :     const string expected("{[\"first\"]={[\"first\"]=1,[\"second\"]=2},"
      92                 :            :                           "[\"fourth\"]={{{[\"first\"]=7,[\"second\"]=8}},"
      93                 :            :                           "{{[\"first\"]=9,[\"second\"]=10}}},"
      94                 :            :                           "[\"intv\"]={13,14},"
      95                 :            :                           "[\"second\"]={{[\"first\"]=3,[\"second\"]=4},{[\"first\"]=5,[\"second\"]=6}},"
      96   [ +  -  +  - ]:          2 :                           "[\"third\"]={{11},{12}}}");
      97                 :            : 
      98   [ +  -  +  -  :          1 :     CPPUNIT_ASSERT_EQUAL(expected, to_string(props));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      99                 :          1 :   }
     100                 :            : 
     101   [ +  -  +  -  :          4 :   CPPUNIT_TEST_SUITE(BindPropertiesTest);
             +  -  #  # ]
     102   [ +  -  +  -  :          1 :   CPPUNIT_TEST(test_bind_properties);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     103   [ +  -  +  -  :          1 :   CPPUNIT_TEST(test_bindable_sequence);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     104   [ +  -  +  -  :          2 :   CPPUNIT_TEST_SUITE_END();
          +  -  +  -  +  
                -  +  - ]
     105                 :            : };
     106                 :            : 
     107   [ -  +  #  # ]:          1 : CPPUNIT_TEST_SUITE_REGISTRATION(BindPropertiesTest);
     108   [ +  -  +  -  :          4 : WISP_TEST_MAIN()
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]