1 // Copyright (C) 2009-2017 Internet Systems Consortium, Inc. ("ISC") 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, v. 2.0. If a copy of the MPL was not distributed with this 5 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 #ifndef UNITTEST_UTIL_H 8 #define UNITTEST_UTIL_H 1 9 10 #include <vector> 11 #include <string> 12 13 #include <dns/name.h> 14 #include <dns/message.h> 15 16 #include <gtest/gtest.h> 17 18 namespace isc { 19 20 class UnitTestUtil { 21 public: 22 /// 23 /// read text format wire data from a file and put it to the given vector. 24 /// 25 static void readWireData(const char* datafile, 26 std::vector<unsigned char>& data); 27 28 /// 29 /// add a path that \c readWireData() will search for test data files. 30 /// 31 static void addDataPath(const std::string& directory); 32 33 /// 34 /// convert a sequence of hex strings into the corresponding list of 35 /// 8-bit integers, and append them to the vector. 36 /// 37 static void readWireData(const std::string& datastr, 38 std::vector<unsigned char>& data); 39 40 /// 41 /// Compare two names. 42 /// 43 /// This check method uses \c Name::compare() for comparison, which performs 44 /// deeper checks including the equality of offsets, and should be better 45 /// than EXPECT_EQ, which uses operator==. Like the \c matchWireData() 46 /// method, the usage is a bit awkward; the caller should use 47 /// \c EXPECT_PRED_FORMAT2. 48 /// 49 static ::testing::AssertionResult 50 matchName(const char* nameexp1, const char* nameexp2, 51 const isc::dns::Name& name1, const isc::dns::Name& name2); 52 53 /// 54 /// Populate a request message 55 /// 56 /// Create a request message in 'request_message' using the 57 /// opcode 'opcode' and the name/class/type query tuple specified in 58 /// 'name', 'rrclass' and 'rrtype. 59 static void 60 createRequestMessage(isc::dns::Message& request_message, 61 const isc::dns::Opcode& opcode, 62 const uint16_t qid, 63 const isc::dns::Name& name, 64 const isc::dns::RRClass& rrclass, 65 const isc::dns::RRType& rrtype); 66 67 /// 68 /// Populate a DNSSEC request message 69 /// 70 /// Create a request message in 'request_message' using the 71 /// opcode 'opcode' and the name/class/type query tuple specified in 72 /// 'name', 'rrclass' and 'rrtype. 73 /// EDNS will be added with DO=1 and bufsize 4096 74 static void 75 createDNSSECRequestMessage(isc::dns::Message& request_message, 76 const isc::dns::Opcode& opcode, 77 const uint16_t qid, 78 const isc::dns::Name& name, 79 const isc::dns::RRClass& rrclass, 80 const isc::dns::RRType& rrtype); 81 82 }; 83 } 84 #endif // UNITTEST_UTIL_H 85 86 // Local Variables: 87 // mode: c++ 88 // End: 89