From: Remi Gacogne Date: Tue, 19 Feb 2019 09:20:04 +0000 (+0100) Subject: Add more unit tests for removal from a SuffixMatchTree X-Git-Tag: rec-4.2.0-beta1~7^2~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68bcc8d0c8413c658bca9b2f815afd64cfb7c21e;p=thirdparty%2Fpdns.git Add more unit tests for removal from a SuffixMatchTree --- diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index ac81e6679c..833f2fc31e 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -568,6 +568,61 @@ BOOST_AUTO_TEST_CASE(test_suffixmatch_tree) { smt.remove(net); BOOST_CHECK(smt.lookup(net) == nullptr); BOOST_CHECK_EQUAL(*smt.lookup(examplenet), examplenet); + + smt = SuffixMatchTree(); + smt.add(examplenet, examplenet); + smt.add(net, net); + smt.add(DNSName("news.bbc.co.uk."), DNSName("news.bbc.co.uk.")); + smt.add(apowerdnscom, apowerdnscom); + + smt.remove(DNSName("not-such-entry.news.bbc.co.uk.")); + BOOST_REQUIRE(smt.lookup(DNSName("news.bbc.co.uk."))); + smt.remove(DNSName("news.bbc.co.uk.")); + BOOST_CHECK(smt.lookup(DNSName("news.bbc.co.uk.")) == nullptr); + + smt.remove(net); + BOOST_REQUIRE(smt.lookup(examplenet)); + BOOST_CHECK_EQUAL(*smt.lookup(examplenet), examplenet); + BOOST_CHECK(smt.lookup(net) == nullptr); + + smt.remove(examplenet); + BOOST_CHECK(smt.lookup(net) == nullptr); + BOOST_CHECK(smt.lookup(examplenet) == nullptr); + + smt.add(examplenet, examplenet); + smt.add(net, net); + BOOST_REQUIRE(smt.lookup(examplenet)); + BOOST_CHECK_EQUAL(*smt.lookup(examplenet), examplenet); + BOOST_REQUIRE(smt.lookup(net)); + BOOST_CHECK_EQUAL(*smt.lookup(net), net); + + smt.remove(examplenet); + BOOST_CHECK_EQUAL(*smt.lookup(examplenet), net); + BOOST_CHECK_EQUAL(*smt.lookup(net), net); + smt.remove(examplenet); + BOOST_CHECK_EQUAL(*smt.lookup(examplenet), net); + BOOST_CHECK_EQUAL(*smt.lookup(net), net); + smt.remove(net); + BOOST_CHECK(smt.lookup(net) == nullptr); + BOOST_CHECK(smt.lookup(examplenet) == nullptr); + smt.remove(net); + + size_t count = 0; + smt.visit([apowerdnscom, &count](const SuffixMatchTree& smt) { + count++; + BOOST_CHECK_EQUAL(smt.d_value, apowerdnscom); + }); + BOOST_CHECK_EQUAL(count, 1); + + BOOST_CHECK_EQUAL(*smt.lookup(apowerdnscom), apowerdnscom); + smt.remove(apowerdnscom); + BOOST_CHECK(smt.lookup(apowerdnscom) == nullptr); + + count = 0; + smt.visit([&count](const SuffixMatchTree& smt) { + count++; + }); + BOOST_CHECK_EQUAL(count, 0); }