wait to be verified
diff --git a/tests/unit/app/name-caching-resolver.cpp b/tests/unit/app/name-caching-resolver.cpp
new file mode 100644
index 0000000..d886aee
--- /dev/null
+++ b/tests/unit/app/name-caching-resolver.cpp
@@ -0,0 +1,77 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "app/name-caching-resolver.hpp"
+#include "../boost-test.hpp"
+
+//#include <boost/test/test_tools.hpp>
+//#include <string>
+
+namespace ndn {
+namespace ndns {
+namespace tests {
+
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(nameCachingResolver)
+
+BOOST_AUTO_TEST_CASE(Protocol)
+{
+ string label = "nameCachingResolver::Protocol";
+ printbegin(label);
+
+ Name name = "/DNS-R/net/ndnsim/www/TXT";
+ Interest interest;
+ interest.setName(name);
+
+ NameCachingResolver resolver("resolver", "/DNS-R");
+ cout<<"onInterest"<<endl;
+ resolver.onInterest(name, interest);
+
+
+
+ printend(label);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace ndns
+} // namespace ndn
+
diff --git a/tests/unit/app/name-server.cpp b/tests/unit/app/name-server.cpp
new file mode 100644
index 0000000..da0dbfa
--- /dev/null
+++ b/tests/unit/app/name-server.cpp
@@ -0,0 +1,84 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "app/name-server.hpp"
+#include "../boost-test.hpp"
+#include <time.h>
+
+//#include <boost/test/test_tools.hpp>
+//#include <string>
+
+namespace ndn {
+namespace ndns {
+namespace tests {
+
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(nameServer)
+
+BOOST_AUTO_TEST_CASE(Protocol)
+{
+ string label = "nameServer::Protocol";
+ printbegin(label);
+
+ Name name("/DNS/net/NS");
+ Interest interest;
+ interest.setName(name);
+
+
+ string program = "name-server-daemon";
+ string prefix = "/";
+
+ const char* pro = program.c_str();
+ const char * pre = prefix.c_str();
+ NameServer server(pro, pre, pre);
+
+ server.onInterest(name, interest);
+
+
+
+ printend(label);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace ndns
+} // namespace ndn
+
diff --git a/tests/unit/boost-test.hpp b/tests/unit/boost-test.hpp
new file mode 100644
index 0000000..793d0f7
--- /dev/null
+++ b/tests/unit/boost-test.hpp
@@ -0,0 +1,35 @@
+#ifndef NDNS_TESTS_BOOST_TEST_HPP
+#define NDNS_TESTS_BOOST_TEST_HPP
+
+// suppress warnings from Boost.Test
+#pragma GCC system_header
+#pragma clang system_header
+
+#include <boost/test/test_tools.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/test/output_test_stream.hpp>
+
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/interest.hpp>
+
+namespace ndn {
+namespace ndns {
+namespace tests {
+
+ void inline
+ printbegin(std::string label)
+ {
+ std::cout<<std::endl<<"-->>>>>>>>>>>>>>"<<label<<" begins:"<<std::endl;
+ }
+
+ void inline
+ printend(std::string label)
+ {
+ std::cout<<"<<<<<<<<<<<<<<--"<<label<<" ends."<<std::endl;
+ }
+}//tests
+}//ndns
+}//ndn
+#endif // NDN_TESTS_BOOST_TEST_HPP
diff --git a/tests/unit/nameserver.cpp b/tests/unit/db/rr-mgr.cpp
similarity index 61%
copy from tests/unit/nameserver.cpp
copy to tests/unit/db/rr-mgr.cpp
index de9f726..4fd5d7d 100644
--- a/tests/unit/nameserver.cpp
+++ b/tests/unit/db/rr-mgr.cpp
@@ -17,12 +17,53 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "tool/nameServer.h"
+#include "../boost-test.hpp"
+#include "db/rr-mgr.hpp"
+
+//#include <ndn-cxx/name.hpp>
namespace ndn {
namespace ndns {
namespace tests {
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(rrMgr)
+
+BOOST_AUTO_TEST_CASE(db)
+{
+
+ string label = "rrMgr::db";
+ printbegin(label);
+
+ ndns::Query q;
+ Name n1("/net");
+ Name n2("/ndnsim");
+ q.setAuthorityZone(n1);
+ q.setRrLabel(n2);
+ q.setQueryType(ndns::Query::QUERY_DNS_R);
+
+
+ Zone zone;
+ zone.setAuthorizedName(Name("/net"));
+ zone.setId(2);
+
+ Response re;
+
+ RRMgr mgr(zone, q, re);
+ BOOST_CHECK_EQUAL(mgr.lookup(), 0);
+
+
+ zone.setId(23);
+ RRMgr mgr2(zone, q, re);
+ BOOST_CHECK_EQUAL(mgr2.lookup(), 0);
+
+
+
+ printend(label);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
} // namespace tests
} // namespace ndns
} // namespace ndn
diff --git a/tests/unit/db/zone-mgr.cpp b/tests/unit/db/zone-mgr.cpp
new file mode 100644
index 0000000..3d2bc0c
--- /dev/null
+++ b/tests/unit/db/zone-mgr.cpp
@@ -0,0 +1,68 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "../boost-test.hpp"
+
+#include "db/zone-mgr.hpp"
+#include "zone.hpp"
+
+//#include <ndn-cxx/name.hpp>
+namespace ndn {
+namespace ndns {
+namespace tests {
+
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(zoneMgr)
+
+BOOST_AUTO_TEST_CASE(db)
+{
+ string label = "zoneMgr::db";
+ printbegin(label);
+ Zone zone;
+ zone.setAuthorizedName(Name("/net"));
+ zone.setId(11);
+
+ ZoneMgr mgr(zone); //the construction will lookup zone.id, /net's id is 2
+ BOOST_CHECK_EQUAL(mgr.getZone().getId(), 2);
+ BOOST_CHECK_EQUAL(zone.getId(), 2);
+
+
+ zone.setId(11);
+ BOOST_CHECK_EQUAL(mgr.getZone().getId(), 11);
+
+ zone.setId(12);
+ BOOST_CHECK_EQUAL(mgr.getZone().getId(), 12);
+
+ mgr.lookupId();
+ cout<<"zone.name="<<mgr.getZone().getAuthorizedName()<<endl;
+ cout<<"zone.id="<<mgr.getZone().getId()<<endl;
+ cout<<"zone.id="<<mgr.getZone().getId()<<endl;
+ cout<<"&zone="<<&zone<<endl;
+ cout<<"&mgr.getZone()"<<&(mgr.getZone())<<endl;
+ BOOST_CHECK_EQUAL(mgr.getZone().getId(), 2);
+ BOOST_CHECK_EQUAL(zone.getId(), 2);
+
+ printend(label);
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace ndns
+} // namespace ndn
diff --git a/tests/unit/nameserver.cpp b/tests/unit/iterative-query.cpp
similarity index 75%
rename from tests/unit/nameserver.cpp
rename to tests/unit/iterative-query.cpp
index de9f726..a904cee 100644
--- a/tests/unit/nameserver.cpp
+++ b/tests/unit/iterative-query.cpp
@@ -17,12 +17,34 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "tool/nameServer.h"
+#include "iterative-query.hpp"
+#include "boost-test.hpp"
+
+//#include <boost/test/test_tools.hpp>
+//#include <string>
namespace ndn {
namespace ndns {
namespace tests {
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(iQuery)
+
+BOOST_AUTO_TEST_CASE(Protocol)
+{
+ string label = "iQuery::Protocol";
+ printbegin(label);
+
+ Query q;
+
+
+
+ printend(label);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
} // namespace tests
} // namespace ndns
} // namespace ndn
diff --git a/tests/unit/query.cpp b/tests/unit/query.cpp
index a92a5d1..aa2fe9b 100644
--- a/tests/unit/query.cpp
+++ b/tests/unit/query.cpp
@@ -17,12 +17,44 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "src/query.h"
+#include "query.hpp"
+
+#include "boost-test.hpp"
namespace ndn {
namespace ndns {
namespace tests {
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(query)
+
+BOOST_AUTO_TEST_CASE(UnderstandInterest)
+{
+ printbegin("query::UnderstandInterst");
+ ndns::Query q;
+ Name n1("/dns.google.com");
+ Name n2("/www.baidu.com");
+ q.setAuthorityZone(n1);
+ q.setRrLabel(n2);
+ q.setQueryType(ndns::Query::QUERY_DNS_R);
+
+ Interest interest = q.toInterest();
+ cout<<"InterestName="<<interest.getName()<<endl;
+
+
+ ndns::Query q2;
+ Name name;
+ q2.fromInterest(name, interest);
+ cout<<"AuthZone="<<q2.getAuthorityZone()<<" RRLable="<<q2.getRrLabel()<<endl;
+ BOOST_CHECK_EQUAL(q.getAuthorityZone(), q2.getAuthorityZone());
+ BOOST_CHECK_EQUAL(q.getRrLabel(), q2.getRrLabel());
+ BOOST_CHECK_EQUAL(q.getQueryType(), q2.getQueryType());
+ printend("query:UnderstandInterst");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
} // namespace tests
} // namespace ndns
} // namespace ndn
diff --git a/tests/unit/resolver.cpp b/tests/unit/resolver.cpp
index 959a58e..0c3a728 100644
--- a/tests/unit/resolver.cpp
+++ b/tests/unit/resolver.cpp
@@ -17,7 +17,7 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "resolver.h"
+// #include "resolver.h"
namespace ndn {
namespace ndns {
diff --git a/tests/unit/response.cpp b/tests/unit/response.cpp
new file mode 100644
index 0000000..bb976a0
--- /dev/null
+++ b/tests/unit/response.cpp
@@ -0,0 +1,104 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "response.hpp"
+#include "rr.hpp"
+#include "query.hpp"
+#include "rr.hpp"
+
+#include "boost-test.hpp"
+#include <string>
+
+
+namespace ndn {
+namespace ndns {
+namespace tests {
+
+
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(response)
+
+BOOST_AUTO_TEST_CASE(Encode)
+{
+
+ printbegin("response:Encode");
+
+ Response re, re2;
+ cout<<"construct a Response Instance"<<endl;
+ vector<RR> vec;
+
+ RR rr;
+ std::string ex3 = "www3.ex.com";
+ uint32_t id = 203;
+ rr.setRrdata(ex3);
+ rr.setId(id);
+ vec.push_back(rr);
+
+
+ RR rr2;
+ std::string ex4 = "www4.ex.com";
+ id = 204;
+ rr2.setRrdata(ex4);
+ rr2.setId(id);
+ vec.push_back(rr2);
+
+ ndns::Query q;
+ Name n1("/dns.google.com");
+ Name n2("/www.baidu.com");
+ q.setAuthorityZone(n1);
+ q.setRrLabel(n2);
+ q.setQueryType(ndns::Query::QUERY_DNS_R);
+ Interest interest = q.toInterest();
+ Name n3(q.toInterest().getName());
+ n3.appendNumber((uint64_t)1313344);
+
+ re.setQueryName(n3);
+ re.setFreshness(time::milliseconds(4444));
+ re.setRrs(vec);
+
+
+
+ cout<<"before encode"<<endl;
+ //ndn::Block block = re.wireEncode();
+ //re.wireEncode();
+ Data data = re.toData();
+ cout<<re.toData()<<endl;
+
+ cout<<"Encode finishes"<<endl;
+
+
+ re2.fromData(n2, data);
+ BOOST_CHECK_EQUAL(re.getQueryName(), re2.getQueryName());
+ BOOST_CHECK_EQUAL(re.getContentType(), re2.getContentType());
+ BOOST_CHECK_EQUAL(re.getResponseType(), re2.getResponseType());
+ BOOST_CHECK_EQUAL(re.getRrs().size(), re2.getRrs().size());
+ BOOST_CHECK_EQUAL(re.getRrs()[0], re2.getRrs()[0]);
+ BOOST_CHECK_EQUAL(re.getRrs()[1], re2.getRrs()[1]);
+
+
+ printend("response:Encode");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+
+} // namespace tests
+} // namespace ndns
+} // namespace ndn
diff --git a/tests/unit/rr.cpp b/tests/unit/rr.cpp
index 666aeeb..b5b915b 100644
--- a/tests/unit/rr.cpp
+++ b/tests/unit/rr.cpp
@@ -18,26 +18,41 @@
*/
#include "rr.hpp"
+#include "boost-test.hpp"
-#include <boost/test/unit_test.hpp>
+//#include <boost/test/test_tools.hpp>
+//#include <string>
namespace ndn {
namespace ndns {
namespace tests {
-BOOST_AUTO_TEST_SUITE(Rr)
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(rr)
BOOST_AUTO_TEST_CASE(Encode)
{
- ndn::RR rr;
- rr.setRrdata("www2.ex.com");
+ string label = "rr:Encode";
+ printbegin(label);
+ RR rr;
+ std::string ex = "www2.ex.com";
+ uint32_t id = 201;
+ rr.setRrdata(ex);
+ rr.setId(id);
+ cout<<"before encode"<<endl;
ndn::Block block = rr.wireEncode();
+ cout<<"Encode finishes with totalLenght="<<block.size()<<endl;
- ndn::RR rr2;
+
+
+ RR rr2;
rr2.wireDecode(block);
- BOOST_TEST_EQUAL(rr.getRrdata(), "?");
+ BOOST_CHECK_EQUAL(rr2.getRrdata(), ex);
+ BOOST_CHECK_EQUAL(rr2.getId(), id);
+ printend(label);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit/zone.cpp b/tests/unit/zone.cpp
index 252e22f..f697c02 100644
--- a/tests/unit/zone.cpp
+++ b/tests/unit/zone.cpp
@@ -17,7 +17,7 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "src/zone.h"
+// #include "src/zone.h"
namespace ndn {
namespace ndns {