LCOV - code coverage report
Current view: top level - dns - opcode.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 8 9 88.9 %
Date: 2012-05-15 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 6 66.7 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #include <string>
      16                 :            : #include <ostream>
      17                 :            : 
      18                 :            : #include <exceptions/exceptions.h>
      19                 :            : 
      20                 :            : #include <dns/opcode.h>
      21                 :            : 
      22                 :            : using namespace std;
      23                 :            : 
      24                 :            : namespace isc {
      25                 :            : namespace dns {
      26                 :            : namespace {
      27                 :            : const char *opcodetext[] = {
      28                 :            :     "QUERY",
      29                 :            :     "IQUERY",
      30                 :            :     "STATUS",
      31                 :            :     "RESERVED3",
      32                 :            :     "NOTIFY",
      33                 :            :     "UPDATE",
      34                 :            :     "RESERVED6",
      35                 :            :     "RESERVED7",
      36                 :            :     "RESERVED8",
      37                 :            :     "RESERVED9",
      38                 :            :     "RESERVED10",
      39                 :            :     "RESERVED11",
      40                 :            :     "RESERVED12",
      41                 :            :     "RESERVED13",
      42                 :            :     "RESERVED14",
      43                 :            :     "RESERVED15"
      44                 :            : };
      45                 :            : 
      46                 :            : // OPCODEs are 4-bit values.  So 15 is the highest code.
      47                 :            : const uint8_t MAX_OPCODE = 15;
      48                 :            : }
      49                 :            : 
      50                 :       2611 : Opcode::Opcode(const uint8_t code) : code_(static_cast<CodeValue>(code)) {
      51         [ +  + ]:       2611 :     if (code > MAX_OPCODE) {
      52         [ +  - ]:          6 :         isc_throw(OutOfRange,
      53                 :            :                   "DNS Opcode is too large to construct: " << code);
      54                 :            :     }
      55                 :       2609 : }
      56                 :            : 
      57                 :            : string
      58                 :        657 : Opcode::toText() const {
      59                 :        657 :     return (opcodetext[code_]);
      60                 :            : }
      61                 :            : 
      62                 :            : ostream&
      63                 :         15 : operator<<(std::ostream& os, const Opcode& opcode) {
      64         [ +  - ]:         15 :     return (os << opcode.toText());
      65                 :            : }
      66                 :            : }
      67                 :          0 : }

Generated by: LCOV version 1.9