]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3184] Changes after review:
authorTomek Mrugalski <tomasz@isc.org>
Fri, 11 Oct 2013 15:07:32 +0000 (17:07 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 11 Oct 2013 15:07:32 +0000 (17:07 +0200)
 - ASSERT added to unit-tests
 - packetFromCapture() created
 - comments changes

src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/dhcp4_test_utils.h
src/bin/dhcp4/tests/wireshark.cc

index 23bedb36ccbace5c72a72d525e1a18e0c003b30a..c1ea5f7916837c8e5d31582f9e4666ed71ddd3c9 100644 (file)
@@ -1604,7 +1604,8 @@ TEST_F(Dhcpv4SrvTest, relayAgentInfoEcho) {
     // Let's create a relayed DISCOVER. This particular relayed DISCOVER has
     // added option 82 (relay agent info) with 3 suboptions. The server
     // is supposed to echo it back in its response.
-    Pkt4Ptr dis = captureRelayedDiscover();
+    Pkt4Ptr dis;
+    ASSERT_NO_THROW(dis = captureRelayedDiscover());
 
     // Simulate that we have received that traffic
     srv.fakeReceive(dis);
index b02e4cec4ffb378581185ab205cc54fd188eb793..8939358d6d9e845616301d277a393b0da81feb5a 100644 (file)
@@ -144,6 +144,11 @@ public:
     /// @return relayed DISCOVER
     Pkt4Ptr captureRelayedDiscover();
 
+    /// @brief generates a DHCPv4 packet based on provided hex string
+    ///
+    /// @return created packet
+    Pkt4Ptr packetFromCapture(const std::string& hex_string);
+
     /// @brief Tests if Discover or Request message is processed correctly
     ///
     /// @param msg_type DHCPDISCOVER or DHCPREQUEST
@@ -173,4 +178,4 @@ public:
 }; // end of isc::dhcp namespace
 }; // end of isc namespace
 
-#endif // DHCP6_TEST_UTILS_H
+#endif // DHCP4_TEST_UTILS_H
index a338c377a51a8f9793acc9f2d15c6f0e110c6843..b563354d3bab526686216f84a3bb698ef4fa86f4 100644 (file)
@@ -19,9 +19,9 @@
 #include <util/encode/hex.h>
 
 /// @file   wireshark.cc
-/// 
+///
 /// @brief  contains packet captures imported from Wireshark
-/// 
+///
 /// These are actual packets captured over wire. They are used in various
 /// tests.
 ///
@@ -47,6 +47,19 @@ namespace isc {
 namespace dhcp {
 namespace test {
 
+Pkt4Ptr Dhcpv4SrvTest::packetFromCapture(const std::string& hex_string) {
+    std::vector<uint8_t> bin;
+
+    // Decode the hex string and store it in bin (which happens
+    // to be OptionBuffer format)
+    isc::util::encode::decodeHex(hex_string, bin);
+
+    Pkt4Ptr pkt(new Pkt4(&bin[0], bin.size()));
+    captureSetDefaultFields(pkt);
+
+    return (pkt);
+}
+
 void Dhcpv4SrvTest::captureSetDefaultFields(const Pkt4Ptr& pkt) {
     pkt->setRemotePort(546);
     pkt->setRemoteAddr(IOAddress("fe80::1"));
@@ -93,7 +106,7 @@ Bootstrap Protocol
     Option: (82) Agent Information Option
     Option: (255) End */
 
-    string hex_string = 
+    string hex_string =
         "010106015d05478d000000000000000000000000000000000afee20120e52ab8151400"
         "0000000000000000000000000000000000000000000000000000000000000000000000"
         "0000000000000000000000000000000000000000000000000000000000000000000000"
@@ -111,16 +124,7 @@ Bootstrap Protocol
         "140003000120e52ab81514390205dc5219010420000002020620e52ab8151409090000"
         "118b0401020300ff";
 
-    std::vector<uint8_t> bin;
-
-    // Decode the hex string and store it in bin (which happens
-    // to be OptionBuffer format)
-    isc::util::encode::decodeHex(hex_string, bin);
-
-    Pkt4Ptr pkt(new Pkt4(&bin[0], bin.size()));
-    captureSetDefaultFields(pkt);
-
-    return (pkt);
+    return (packetFromCapture(hex_string));
 }
 
 }; // end of isc::dhcp::test namespace