Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/ws - types.h (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 6 11 54.5 %
Date: 2012-04-09 Functions: 3 5 60.0 %
Branches: 2 10 20.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                 :            :  *     https://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                 :            : /**
      18                 :            :  * @file
      19                 :            :  * This header defines types used by Web services.
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef __SSRC_WSPR_WS_TYPES_H
      23                 :            : #define __SSRC_WSPR_WS_TYPES_H
      24                 :            : 
      25                 :            : #include <ssrc/wispers/ws/protocol.h>
      26                 :            : #include <boost/regex.hpp>
      27                 :            : #include <boost/ptr_container/ptr_vector.hpp>
      28                 :            : 
      29                 :            : __BEGIN_NS_SSRC_WSPR_WS
      30                 :            : 
      31                 :            : typedef
      32                 :            : boost::function<void (const WebServiceCall &,
      33                 :            :                       const NS_SSRC_WISP_PROTOCOL::MessageInfo &)>
      34                 :            : call_handler_type;
      35                 :            : 
      36                 :            : typedef std::unordered_map<string, call_handler_type> call_handler_map;
      37                 :            : 
      38                 :          2 : struct CallParameter {
      39                 :            :   /*
      40                 :            :     enum ParameterType {
      41                 :            :     Nil           = LUA_TNIL,
      42                 :            :     Boolean       = LUA_TBOOLEAN,
      43                 :            :     LightUserData = LUA_TLIGHTUSERDATA,
      44                 :            :     Number        = LUA_TNUMBER,
      45                 :            :     String        = LUA_TSTRING,
      46                 :            :     Table         = LUA_TTABLE,
      47                 :            :     Function      = LUA_TFUNCTION,
      48                 :            :     UserData      = LUA_TUSERDATA,
      49                 :            :     Thread        = LUA_TTHREAD
      50                 :            :     };
      51                 :            : 
      52                 :            :     parameter_type type;
      53                 :            :   */
      54                 :            :   const bool multi_value;
      55                 :            :   const bool optional;
      56                 :            :   const unsigned int min_size;
      57                 :            :   const unsigned int max_size;
      58                 :            :   const string name;
      59                 :            : 
      60                 :          2 :   CallParameter(const string & name,
      61                 :            :                 const unsigned int min_size = 1,
      62                 :            :                 const unsigned int max_size = 128,
      63                 :            :                 const bool multi_value = false,
      64                 :            :                 const bool optional = false) :
      65                 :            :     multi_value(multi_value), optional(optional),
      66                 :          2 :     min_size(min_size), max_size(max_size), name(name)
      67                 :          2 :   { }
      68                 :            : 
      69                 :          1 :   inline virtual bool validate(const string & value) const {
      70   [ +  -  +  - ]:          1 :     return (value.size() >= min_size && value.size() <= max_size);
      71                 :            :   }
      72                 :            : };
      73                 :            : 
      74                 :            : struct PatternParameter : public CallParameter {
      75                 :            :   typedef CallParameter super;
      76                 :            :   const boost::regex pattern;
      77                 :            : 
      78                 :          0 :   PatternParameter(const string & name,
      79                 :            :                    const string & pattern,
      80                 :            :                    const unsigned int min_size = 1,
      81                 :            :                    const unsigned int max_size = 128,
      82                 :            :                    const bool multi_value = false,
      83                 :            :                    const bool optional = false) :
      84                 :            :     super(name, min_size, max_size, multi_value, optional),
      85         [ #  # ]:          0 :     pattern(pattern)
      86                 :          0 :   { }
      87                 :            : 
      88                 :          0 :   inline virtual bool validate(const string & value) const {
      89   [ #  #  #  # ]:          0 :     return (super::validate(value) && boost::regex_match(value, pattern));
      90                 :            :   }
      91                 :            : };
      92                 :            : 
      93                 :            : typedef boost::ptr_vector<CallParameter> parameter_sequence;
      94                 :            : 
      95                 :            : __END_NS_SSRC_WSPR_WS
      96                 :            : 
      97                 :            : #endif