Browse Source

Fixed QDnsRecordData clone() method and tests

develop
Robin Thoni 6 years ago
parent
commit
7c556f9699

+ 7
- 1
src/modules/dns-base/CMakeLists.txt View File

@@ -30,7 +30,13 @@ add_library(${PROJECT_NAME}
30 30
         src/RecordData/QDnsRecordDataRaw.cpp
31 31
         includes/dns-base/RecordData/QDnsRecordDataRaw.h
32 32
         src/RecordData/QDnsRecordDataAAAA.cpp
33
-        includes/dns-base/RecordData/QDnsRecordDataAAAA.h src/RecordData/QDnsRecordDataMX.cpp includes/dns-base/RecordData/QDnsRecordDataMX.h src/RecordData/QDnsRecordDataSOA.cpp includes/dns-base/RecordData/QDnsRecordDataSOA.h src/RecordData/QDnsRecordDataPTR.cpp includes/dns-base/RecordData/QDnsRecordDataPTR.h)
33
+        includes/dns-base/RecordData/QDnsRecordDataAAAA.h
34
+        src/RecordData/QDnsRecordDataMX.cpp
35
+        includes/dns-base/RecordData/QDnsRecordDataMX.h
36
+        src/RecordData/QDnsRecordDataSOA.cpp
37
+        includes/dns-base/RecordData/QDnsRecordDataSOA.h
38
+        src/RecordData/QDnsRecordDataPTR.cpp
39
+        includes/dns-base/RecordData/QDnsRecordDataPTR.h)
34 40
 
35 41
 target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network)
36 42
 

+ 1
- 1
src/modules/dns-base/src/RecordData/QDnsRecordDataA.cpp View File

@@ -59,7 +59,7 @@ namespace QDns
59 59
             auto data = new QDnsRecordDataA();
60 60
             data->m_isValid = m_isValid;
61 61
             data->m_ip = m_ip;
62
-            return nullptr;
62
+            return data;
63 63
         }
64 64
 
65 65
         const QHostAddress &QDnsRecordDataA::getIp() const

+ 1
- 1
src/modules/dns-base/src/RecordData/QDnsRecordDataAAAA.cpp View File

@@ -68,7 +68,7 @@ namespace QDns
68 68
             auto data = new QDnsRecordDataAAAA();
69 69
             data->m_isValid = m_isValid;
70 70
             data->m_ip = m_ip;
71
-            return nullptr;
71
+            return data;
72 72
         }
73 73
 
74 74
         const QHostAddress &QDnsRecordDataAAAA::getIp() const

+ 1
- 1
src/modules/dns-base/src/RecordData/QDnsRecordDataMX.cpp View File

@@ -66,7 +66,7 @@ namespace QDns
66 66
             data->m_isValid = m_isValid;
67 67
             data->m_preference = m_preference;
68 68
             data->m_mx = m_mx;
69
-            return nullptr;
69
+            return data;
70 70
         }
71 71
 
72 72
         quint16 QDnsRecordDataMX::getPreference() const

+ 7
- 5
src/modules/dns-base/tests/RecordData/DnsRDataA.cpp View File

@@ -25,15 +25,17 @@ TEST_P(DnsRDataATest, parseAndGetters)
25 25
 {
26 26
     auto params = GetParam();
27 27
     auto data = QByteArray::fromHex(params.hexData);
28
-    auto rdata = QDns::Base::QDnsRecordDataA(data, params.pos);
29
-    ASSERT_EQ(rdata.isValid(), params.isValid);
28
+    auto rdata = dynamic_cast<QDns::Base::QDnsRecordDataA*>(QDns::Base::QDnsRecordDataA(data, params.pos).clone());
29
+    ASSERT_NE(rdata, nullptr);
30
+    ASSERT_EQ(rdata->isValid(), params.isValid);
30 31
     
31
-    if (rdata.isValid())
32
+    if (rdata->isValid())
32 33
     {
33
-        ASSERT_EQ(rdata.getIp().toIPv4Address(), params.ip);
34
+        ASSERT_EQ(rdata->getIp().toIPv4Address(), params.ip);
34 35
         
35
-        ASSERT_EQ(rdata.serialize().toHex(), QString(params.hexData).remove(" "));
36
+        ASSERT_EQ(rdata->serialize().toHex(), QString(params.hexData).remove(" "));
36 37
     }
38
+    delete rdata;
37 39
 }
38 40
 
39 41
 INSTANTIATE_TEST_CASE_P(DnsRDataATestInst,

+ 7
- 5
src/modules/dns-base/tests/RecordData/DnsRDataAAAA.cpp View File

@@ -25,18 +25,20 @@ TEST_P(DnsRDataAAAATest, parseAndGetters)
25 25
 {
26 26
     auto params = GetParam();
27 27
     auto data = QByteArray::fromHex(params.hexData);
28
-    auto rdata = QDns::Base::QDnsRecordDataAAAA(data, params.pos);
29
-    ASSERT_EQ(rdata.isValid(), params.isValid);
28
+    auto rdata = dynamic_cast<QDns::Base::QDnsRecordDataAAAA*>(QDns::Base::QDnsRecordDataAAAA(data, params.pos).clone());
29
+    ASSERT_NE(rdata, nullptr);
30
+    ASSERT_EQ(rdata->isValid(), params.isValid);
30 31
     
31
-    if (rdata.isValid())
32
+    if (rdata->isValid())
32 33
     {
33 34
         for (int i = 0; i < 16; ++i)
34 35
         {
35
-            ASSERT_EQ(rdata.getIp().toIPv6Address()[i], params.ip[i]);
36
+            ASSERT_EQ(rdata->getIp().toIPv6Address()[i], params.ip[i]);
36 37
         }
37 38
         
38
-        ASSERT_EQ(rdata.serialize().toHex(), QString(params.hexData).remove(" "));
39
+        ASSERT_EQ(rdata->serialize().toHex(), QString(params.hexData).remove(" "));
39 40
     }
41
+    delete rdata;
40 42
 }
41 43
 
42 44
 INSTANTIATE_TEST_CASE_P(DnsRDataAAAATestInst,

+ 8
- 6
src/modules/dns-base/tests/RecordData/DnsRDataMX.cpp View File

@@ -26,16 +26,18 @@ TEST_P(DnsRDataMXTest, parseAndGetters)
26 26
 {
27 27
     auto params = GetParam();
28 28
     auto data = QByteArray::fromHex(params.hexData);
29
-    auto rdata = QDns::Base::QDnsRecordDataMX(data, params.pos);
30
-    ASSERT_EQ(rdata.isValid(), params.isValid);
29
+    auto rdata = dynamic_cast<QDns::Base::QDnsRecordDataMX*>(QDns::Base::QDnsRecordDataMX(data, params.pos).clone());
30
+    ASSERT_NE(rdata, nullptr);
31
+    ASSERT_EQ(rdata->isValid(), params.isValid);
31 32
     
32
-    if (rdata.isValid())
33
+    if (rdata->isValid())
33 34
     {
34
-        ASSERT_EQ(params.preference, rdata.getPreference());
35
-        ASSERT_EQ(params.mx, rdata.getMx());
35
+        ASSERT_EQ(params.preference, rdata->getPreference());
36
+        ASSERT_EQ(params.mx, rdata->getMx());
36 37
 
37
-        ASSERT_EQ(rdata.serialize().toHex(), QString(params.hexData).remove(" "));
38
+        ASSERT_EQ(rdata->serialize().toHex(), QString(params.hexData).remove(" "));
38 39
     }
40
+    delete rdata;
39 41
 }
40 42
 
41 43
 INSTANTIATE_TEST_CASE_P(DnsRDataMXTestInst,

+ 7
- 5
src/modules/dns-base/tests/RecordData/DnsRDataPTR.cpp View File

@@ -25,15 +25,17 @@ TEST_P(DnsRDataPTRTest, parseAndGetters)
25 25
 {
26 26
     auto params = GetParam();
27 27
     auto data = QByteArray::fromHex(params.hexData);
28
-    auto rdata = QDns::Base::QDnsRecordDataPTR(data, params.pos);
29
-    ASSERT_EQ(rdata.isValid(), params.isValid);
28
+    auto rdata = dynamic_cast<QDns::Base::QDnsRecordDataPTR*>(QDns::Base::QDnsRecordDataPTR(data, params.pos).clone());
29
+    ASSERT_NE(rdata, nullptr);
30
+    ASSERT_EQ(rdata->isValid(), params.isValid);
30 31
 
31
-    if (rdata.isValid())
32
+    if (rdata->isValid())
32 33
     {
33
-        ASSERT_EQ(params.hostname, rdata.getHostname());
34
+        ASSERT_EQ(params.hostname, rdata->getHostname());
34 35
 
35
-        ASSERT_EQ(rdata.serialize().toHex(), QString(params.hexData).remove(" "));
36
+        ASSERT_EQ(rdata->serialize().toHex(), QString(params.hexData).remove(" "));
36 37
     }
38
+    delete rdata;
37 39
 }
38 40
 
39 41
 INSTANTIATE_TEST_CASE_P(DnsRDataPTRTestInst,

+ 14
- 12
src/modules/dns-base/tests/RecordData/DnsRDataSOA.cpp View File

@@ -31,21 +31,23 @@ TEST_P(DnsRDataSOATest, parseAndGetters)
31 31
 {
32 32
     auto params = GetParam();
33 33
     auto data = QByteArray::fromHex(params.hexData);
34
-    auto rdata = QDns::Base::QDnsRecordDataSOA(data, params.pos);
35
-    ASSERT_EQ(rdata.isValid(), params.isValid);
34
+    auto rdata = dynamic_cast<QDns::Base::QDnsRecordDataSOA*>(QDns::Base::QDnsRecordDataSOA(data, params.pos).clone());
35
+    ASSERT_NE(rdata, nullptr);
36
+    ASSERT_EQ(rdata->isValid(), params.isValid);
36 37
 
37
-    if (rdata.isValid())
38
+    if (rdata->isValid())
38 39
     {
39
-        ASSERT_EQ(params.primaryNs, rdata.getPrimaryNs());
40
-        ASSERT_EQ(params.adminMb, rdata.getAdminMb());
41
-        ASSERT_EQ(params.serialNumber, rdata.getSerialNumber());
42
-        ASSERT_EQ(params.refreshInterval, rdata.getRefreshInterval());
43
-        ASSERT_EQ(params.retryInterval, rdata.getRetryInterval());
44
-        ASSERT_EQ(params.expirationLimit, rdata.getExpirationLimit());
45
-        ASSERT_EQ(params.minimumTtl, rdata.getMinimumTtl());
46
-
47
-        ASSERT_EQ(rdata.serialize().toHex(), QString(params.hexData).remove(" "));
40
+        ASSERT_EQ(params.primaryNs, rdata->getPrimaryNs());
41
+        ASSERT_EQ(params.adminMb, rdata->getAdminMb());
42
+        ASSERT_EQ(params.serialNumber, rdata->getSerialNumber());
43
+        ASSERT_EQ(params.refreshInterval, rdata->getRefreshInterval());
44
+        ASSERT_EQ(params.retryInterval, rdata->getRetryInterval());
45
+        ASSERT_EQ(params.expirationLimit, rdata->getExpirationLimit());
46
+        ASSERT_EQ(params.minimumTtl, rdata->getMinimumTtl());
47
+
48
+        ASSERT_EQ(rdata->serialize().toHex(), QString(params.hexData).remove(" "));
48 49
     }
50
+    delete rdata;
49 51
 }
50 52
 
51 53
 INSTANTIATE_TEST_CASE_P(DnsRDataSOATestInst,

Loading…
Cancel
Save