LCOV - code coverage report
Current view: top level - testutils - dnsmessage_test.cc (source / functions) Hit Total Coverage
Test: report.info Lines: 44 58 75.9 %
Date: 2012-05-15 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 56 298 18.8 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  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 <dns/message.h>
      16                 :            : #include <dns/opcode.h>
      17                 :            : #include <dns/rdata.h>
      18                 :            : #include <dns/rcode.h>
      19                 :            : #include <dns/rrset.h>
      20                 :            : #include <dns/rrttl.h>
      21                 :            : 
      22                 :            : #include <gtest/gtest.h>
      23                 :            : 
      24                 :            : #include <testutils/dnsmessage_test.h>
      25                 :            : 
      26                 :            : #include <boost/bind.hpp>
      27                 :            : 
      28                 :            : #include <string>
      29                 :            : #include <sstream>
      30                 :            : 
      31                 :            : using namespace std;
      32                 :            : using namespace isc::dns;
      33                 :            : 
      34                 :            : namespace isc {
      35                 :            : namespace testutils {
      36                 :            : const unsigned int QR_FLAG = 0x1;
      37                 :            : const unsigned int AA_FLAG = 0x2;
      38                 :            : const unsigned int TC_FLAG = 0x4;
      39                 :            : const unsigned int RD_FLAG = 0x8;
      40                 :            : const unsigned int RA_FLAG = 0x10;
      41                 :            : const unsigned int AD_FLAG = 0x20;
      42                 :            : const unsigned int CD_FLAG = 0x40;
      43                 :            : 
      44                 :            : void
      45                 :        184 : headerCheck(const Message& message, const qid_t qid, const Rcode& rcode,
      46                 :            :             const uint16_t opcodeval, const unsigned int flags,
      47                 :            :             const unsigned int qdcount,
      48                 :            :             const unsigned int ancount, const unsigned int nscount,
      49                 :            :             const unsigned int arcount)
      50                 :            : {
      51 [ -  + ][ #  # ]:        368 :     EXPECT_EQ(qid, message.getQid());
         [ #  # ][ #  # ]
                 [ #  # ]
      52 [ -  + ][ #  # ]:        368 :     EXPECT_EQ(rcode, message.getRcode());
         [ #  # ][ #  # ]
                 [ #  # ]
      53 [ -  + ][ #  # ]:        368 :     EXPECT_EQ(opcodeval, message.getOpcode().getCode());
         [ #  # ][ #  # ]
                 [ #  # ]
      54 [ -  + ][ #  # ]:        368 :     EXPECT_EQ((flags & QR_FLAG) != 0,
         [ #  # ][ #  # ]
      55         [ #  # ]:          0 :               message.getHeaderFlag(Message::HEADERFLAG_QR));
      56 [ -  + ][ #  # ]:        368 :     EXPECT_EQ((flags & AA_FLAG) != 0,
         [ #  # ][ #  # ]
      57         [ #  # ]:          0 :               message.getHeaderFlag(Message::HEADERFLAG_AA));
      58 [ -  + ][ #  # ]:        368 :     EXPECT_EQ((flags & TC_FLAG) != 0,
         [ #  # ][ #  # ]
      59         [ #  # ]:          0 :               message.getHeaderFlag(Message::HEADERFLAG_TC));
      60 [ -  + ][ #  # ]:        368 :     EXPECT_EQ((flags & RA_FLAG) != 0,
         [ #  # ][ #  # ]
      61         [ #  # ]:          0 :               message.getHeaderFlag(Message::HEADERFLAG_RA));
      62 [ -  + ][ #  # ]:        368 :     EXPECT_EQ((flags & RD_FLAG) != 0,
         [ #  # ][ #  # ]
      63         [ #  # ]:          0 :               message.getHeaderFlag(Message::HEADERFLAG_RD));
      64 [ -  + ][ #  # ]:        368 :     EXPECT_EQ((flags & AD_FLAG) != 0,
         [ #  # ][ #  # ]
      65         [ #  # ]:          0 :               message.getHeaderFlag(Message::HEADERFLAG_AD));
      66 [ -  + ][ #  # ]:        368 :     EXPECT_EQ((flags & CD_FLAG) != 0,
         [ #  # ][ #  # ]
      67         [ #  # ]:          0 :               message.getHeaderFlag(Message::HEADERFLAG_CD));
      68                 :            : 
      69 [ -  + ][ #  # ]:        368 :     EXPECT_EQ(qdcount, message.getRRCount(Message::SECTION_QUESTION));
         [ #  # ][ #  # ]
                 [ #  # ]
      70 [ -  + ][ #  # ]:        368 :     EXPECT_EQ(ancount, message.getRRCount(Message::SECTION_ANSWER));
         [ #  # ][ #  # ]
                 [ #  # ]
      71 [ -  + ][ #  # ]:        368 :     EXPECT_EQ(nscount, message.getRRCount(Message::SECTION_AUTHORITY));
         [ #  # ][ #  # ]
                 [ #  # ]
      72 [ -  + ][ #  # ]:        368 :     EXPECT_EQ(arcount, message.getRRCount(Message::SECTION_ADDITIONAL));
         [ #  # ][ #  # ]
                 [ #  # ]
      73                 :        184 : }
      74                 :            : 
      75                 :            : namespace {
      76                 :            : ::testing::AssertionResult
      77                 :       1549 : matchRdata(const char*, const char*,
      78                 :            :            const rdata::Rdata& expected, const rdata::Rdata& actual)
      79                 :            : {
      80 [ -  + ][ #  # ]:       1549 :     if (expected.compare(actual) != 0) {
      81                 :          0 :         ::testing::Message msg;
      82                 :          0 :         msg << "Two RDATAs are expected to be equal but not:\n"
      83 [ #  # ][ #  # ]:          0 :             << "  Actual: " << actual.toText() << "\n"
      84 [ #  # ][ #  # ]:          0 :             << "Expected: " << expected.toText();
      85   [ #  #  #  # ]:          0 :         return (::testing::AssertionFailure(msg));
      86                 :            :     }
      87                 :       1549 :     return (::testing::AssertionSuccess());
      88                 :            : }
      89                 :            : 
      90                 :            : // A helper callback of masterLoad() used by textToRRset() below.
      91                 :            : void
      92                 :         95 : setRRset(RRsetPtr rrset, RRsetPtr* rrsetp) {
      93         [ -  + ]:         95 :     if (*rrsetp) {
      94         [ #  # ]:          0 :         isc_throw(isc::Unexpected,
      95                 :            :                   "multiple RRsets are given to textToRRset");
      96                 :            :     }
      97                 :         95 :     *rrsetp = rrset;
      98                 :         95 : }
      99                 :            : }
     100                 :            : 
     101                 :            : RRsetPtr
     102                 :         95 : textToRRset(const string& text_rrset, const RRClass& rrclass,
     103                 :            :             const Name& origin)
     104                 :            : {
     105                 :        190 :     stringstream ss(text_rrset);
     106                 :            :     RRsetPtr rrset;
     107         [ +  - ]:         95 :     masterLoad(ss, origin, rrclass, boost::bind(setRRset, _1, &rrset));
     108                 :         95 :     return (rrset);
     109                 :            : }
     110                 :            : 
     111                 :            : void
     112                 :       1436 : rrsetCheck(isc::dns::ConstRRsetPtr expected_rrset,
     113                 :            :            isc::dns::ConstRRsetPtr actual_rrset)
     114                 :            : {
     115 [ +  - ][ +  - ]:       7180 :     SCOPED_TRACE("Comparing RRsets\n"
                 [ +  - ]
     116                 :            :                  "  Actual: " + actual_rrset->toText() +
     117                 :            :                  "  Expected: " + expected_rrset->toText());
     118 [ +  - ][ +  - ]:       2872 :     EXPECT_EQ(expected_rrset->getName(), actual_rrset->getName());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     119 [ +  - ][ +  - ]:       2872 :     EXPECT_EQ(expected_rrset->getClass(), actual_rrset->getClass());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     120 [ +  - ][ +  - ]:       2872 :     EXPECT_EQ(expected_rrset->getType(), actual_rrset->getType());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     121 [ +  - ][ +  - ]:       2872 :     EXPECT_EQ(expected_rrset->getTTL(), actual_rrset->getTTL());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     122                 :            : 
     123         [ +  - ]:       1436 :     isc::dns::RdataIteratorPtr rdata_it = actual_rrset->getRdataIterator();
     124                 :            :     isc::dns::RdataIteratorPtr expected_rdata_it =
     125         [ +  - ]:       1436 :         expected_rrset->getRdataIterator();
     126 [ +  - ][ +  + ]:       2985 :     while (!expected_rdata_it->isLast()) {
     127 [ +  - ][ -  + ]:       1549 :         EXPECT_FALSE(rdata_it->isLast());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     128 [ +  - ][ +  - ]:       1549 :         if (rdata_it->isLast()) {
     129                 :            :             // buggy case, should stop here
     130                 :            :             break;
     131                 :            :         }
     132                 :            : 
     133 [ +  - ][ +  - ]:       1549 :         EXPECT_PRED_FORMAT2(matchRdata, expected_rdata_it->getCurrent(),
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     134         [ #  # ]:          0 :                             rdata_it->getCurrent());
     135                 :            : 
     136         [ +  - ]:       1549 :         expected_rdata_it->next();
     137         [ +  - ]:       1549 :         rdata_it->next();
     138                 :            :     }
     139                 :            : 
     140                 :            :     // Make sure we have examined all sets of rrset RDATA
     141 [ +  - ][ -  + ]:       1436 :     EXPECT_TRUE(rdata_it->isLast());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
     142                 :       1436 : }
     143                 :            : } // end of namespace testutils
     144                 :          3 : } // end of namespace isc

Generated by: LCOV version 1.9