re-organize files and remove DbMgr
Change-Id: I6667dad558994f1ebcdfb54ab0ec0ed61e2cccb6
diff --git a/src/rrset.cpp b/src/daemon/rrset.cpp
similarity index 100%
rename from src/rrset.cpp
rename to src/daemon/rrset.cpp
diff --git a/src/rrset.hpp b/src/daemon/rrset.hpp
similarity index 100%
rename from src/rrset.hpp
rename to src/daemon/rrset.hpp
diff --git a/src/zone.cpp b/src/daemon/zone.cpp
similarity index 97%
rename from src/zone.cpp
rename to src/daemon/zone.cpp
index 3c7fd1a..46a8bb1 100644
--- a/src/zone.cpp
+++ b/src/daemon/zone.cpp
@@ -23,8 +23,6 @@
namespace ndn {
namespace ndns {
-NDNS_LOG_INIT("Zone")
-
Zone::Zone()
: m_id(0)
, m_ttl(3600)
diff --git a/src/zone.hpp b/src/daemon/zone.hpp
similarity index 100%
rename from src/zone.hpp
rename to src/daemon/zone.hpp
diff --git a/src/db-mgr.cpp b/src/db-mgr.cpp
deleted file mode 100644
index 691299e..0000000
--- a/src/db-mgr.cpp
+++ /dev/null
@@ -1,341 +0,0 @@
-/* -*- 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 "db-mgr.hpp"
-#include "logger.hpp"
-
-#include <boost/algorithm/string/predicate.hpp>
-
-#include <iostream>
-#include <fstream>
-
-namespace ndn {
-namespace ndns {
-
-NDNS_LOG_INIT("DbMgr");
-
-static const std::string NDNS_SCHEMA = "\
-CREATE TABLE IF NOT EXISTS zones ( \n\
- id INTEGER NOT NULL PRIMARY KEY, \n\
- name blob NOT NULL UNIQUE, \n\
- ttl integer(10) NOT NULL); \n\
- \n\
-CREATE TABLE IF NOT EXISTS rrsets ( \n\
- id INTEGER NOT NULL PRIMARY KEY, \n\
- zone_id integer(10) NOT NULL, \n\
- label blob NOT NULL, \n\
- type blob NOT NULL, \n\
- version blob NOT NULL, \n\
- ttl integer(10) NOT NULL, \n\
- data blob NOT NULL, \n\
- FOREIGN KEY(zone_id) REFERENCES zones(id) ON UPDATE Cascade ON DELETE Cascade); \n\
- \n\
-CREATE UNIQUE INDEX rrsets_zone_id_label_type_version \n\
- ON rrsets (zone_id, label, type, version); \n\
-";
-
-DbMgr::DbMgr(const std::string& dbFile/* = DEFAULT_CONFIG_PATH "/" "ndns.conf"*/)
- : m_dbFile(dbFile)
- , m_conn(0)
- , m_status(DB_CLOSED)
-{
- this->open();
-}
-
-
-DbMgr::~DbMgr()
-{
- if (m_status != DB_CLOSED) {
- this->close();
- }
-}
-
-void
-DbMgr::open()
-{
- if (m_status == DB_CONNECTED)
- return;
-
- int res = sqlite3_open_v2(m_dbFile.c_str(), &m_conn,
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
-#ifdef DISABLE_SQLITE3_FS_LOCKING
- "unix-dotfile"
-#else
- 0
-#endif
- );
-
- if (res != SQLITE_OK) {
- m_err = "Cannot open the db file: " + m_dbFile;
- NDNS_LOG_FATAL(m_err);
- m_status = DB_ERROR;
- }
-
- // ignore any errors from DB creation (command will fail for the existing database, which is ok)
- sqlite3_exec(m_conn, NDNS_SCHEMA.c_str(), 0, 0, 0);
-
- m_status = DB_CONNECTED;
-}
-
-void
-DbMgr::close()
-{
- if (m_status == DB_CLOSED)
- return;
-
- int ret = sqlite3_close(m_conn);
- if (ret != SQLITE_OK) {
- m_err = "Cannot close the db: " + m_dbFile;
- NDNS_LOG_FATAL(m_err);
- m_status = DB_ERROR;
- }
- m_status = DB_CLOSED;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Zone
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-void
-DbMgr::insert(Zone& zone)
-{
- if (zone.getId() > 0)
- return;
-
- sqlite3_stmt* stmt;
- const char* sql = "INSERT INTO zones (name, ttl) VALUES (?, ?)";
- int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
- if (rc != SQLITE_OK) {
- throw PrepareError(sql);
- }
-
- const Block& zoneName = zone.getName().wireEncode();
- sqlite3_bind_blob(stmt, 1, zoneName.wire(), zoneName.size(), SQLITE_STATIC);
- sqlite3_bind_int(stmt, 2, zone.getTtl().count());
-
- rc = sqlite3_step(stmt);
- if (rc != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- throw ExecuteError(sql);
- }
-
- zone.setId(sqlite3_last_insert_rowid(m_conn));
- sqlite3_finalize(stmt);
-}
-
-bool
-DbMgr::find(Zone& zone)
-{
- sqlite3_stmt* stmt;
- const char* sql = "SELECT id, ttl FROM zones WHERE name=?";
- int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
- if (rc != SQLITE_OK) {
- throw PrepareError(sql);
- }
-
- const Block& zoneName = zone.getName().wireEncode();
- sqlite3_bind_blob(stmt, 1, zoneName.wire(), zoneName.size(), SQLITE_STATIC);
-
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- zone.setId(sqlite3_column_int64(stmt, 0));
- zone.setTtl(time::seconds(sqlite3_column_int(stmt, 1)));
- } else {
- zone.setId(0);
- }
-
- sqlite3_finalize(stmt);
-
- return zone.getId() != 0;
-}
-
-void
-DbMgr::remove(Zone& zone)
-{
- if (zone.getId() == 0)
- return;
-
- sqlite3_stmt* stmt;
- const char* sql = "DELETE FROM zones where id=?";
- int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
- if (rc != SQLITE_OK) {
- throw PrepareError(sql);
- }
-
- sqlite3_bind_int64(stmt, 1, zone.getId());
-
- rc = sqlite3_step(stmt);
- if (rc != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- throw ExecuteError(sql);
- }
-
- sqlite3_finalize(stmt);
-
- zone = Zone();
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Rrset
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-void
-DbMgr::insert(Rrset& rrset)
-{
- if (rrset.getId() != 0)
- return;
-
- if (rrset.getZone() == 0) {
- throw RrsetError("Rrset has not been assigned to a zone");
- }
-
- if (rrset.getZone()->getId() == 0) {
- insert(*rrset.getZone());
- }
-
- const char* sql =
- "INSERT INTO rrsets (zone_id, label, type, version, ttl, data)"
- " VALUES (?, ?, ?, ?, ?, ?)";
-
- sqlite3_stmt* stmt;
- int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
- if (rc != SQLITE_OK) {
- throw PrepareError(sql);
- }
-
- sqlite3_bind_int64(stmt, 1, rrset.getZone()->getId());
-
- const Block& label = rrset.getLabel().wireEncode();
- sqlite3_bind_blob(stmt, 2, label.wire(), label.size(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 3, rrset.getType().wire(), rrset.getType().size(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 4, rrset.getVersion().wire(), rrset.getVersion().size(), SQLITE_STATIC);
- sqlite3_bind_int64(stmt, 5, rrset.getTtl().count());
- sqlite3_bind_blob(stmt, 6, rrset.getData().wire(), rrset.getData().size(), SQLITE_STATIC);
-
- rc = sqlite3_step(stmt);
- if (rc != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- throw ExecuteError(sql);
- }
-
- rrset.setId(sqlite3_last_insert_rowid(m_conn));
- sqlite3_finalize(stmt);
-}
-
-bool
-DbMgr::find(Rrset& rrset)
-{
- if (rrset.getZone() == 0) {
- throw RrsetError("Rrset has not been assigned to a zone");
- }
-
- if (rrset.getZone()->getId() == 0) {
- bool isFound = find(*rrset.getZone());
- if (!isFound) {
- return false;
- }
- }
-
- sqlite3_stmt* stmt;
- const char* sql =
- "SELECT id, ttl, version, data FROM rrsets"
- " WHERE zone_id=? and label=? and type=?";
- int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
-
- if (rc != SQLITE_OK) {
- throw PrepareError(sql);
- }
-
- sqlite3_bind_int64(stmt, 1, rrset.getZone()->getId());
-
- const Block& label = rrset.getLabel().wireEncode();
- sqlite3_bind_blob(stmt, 2, label.wire(), label.size(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 3, rrset.getType().wire(), rrset.getType().size(), SQLITE_STATIC);
-
- if (sqlite3_step(stmt) == SQLITE_ROW) {
- rrset.setId(sqlite3_column_int64(stmt, 0));
- rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
- rrset.setVersion(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
- sqlite3_column_bytes(stmt, 2)));
- rrset.setData(Block(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
- sqlite3_column_bytes(stmt, 3)));
- } else {
- rrset.setId(0);
- }
- sqlite3_finalize(stmt);
-
- return rrset.getId() != 0;
-}
-
-void
-DbMgr::remove(Rrset& rrset)
-{
- if (rrset.getId() == 0)
- throw RrsetError("Attempting to remove Rrset that has no assigned id");
-
- sqlite3_stmt* stmt;
- const char* sql = "DELETE FROM rrsets WHERE id=?";
- int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
-
- if (rc != SQLITE_OK) {
- throw PrepareError(sql);
- }
-
- sqlite3_bind_int64(stmt, 1, rrset.getId());
-
- rc = sqlite3_step(stmt);
- if (rc != SQLITE_DONE) {
- sqlite3_finalize(stmt);
- throw ExecuteError(sql);
- }
-
- sqlite3_finalize(stmt);
-
- rrset = Rrset(rrset.getZone());
-}
-
-void
-DbMgr::modify(Rrset& rrset)
-{
- if (rrset.getId() == 0) {
- throw RrsetError("Attempting to replace Rrset that has no assigned id");
- }
-
- if (rrset.getZone() == 0) {
- throw RrsetError("Rrset has not been assigned to a zone");
- }
-
- sqlite3_stmt* stmt;
- const char* sql = "UPDATE rrsets SET ttl=?, version=?, data=? WHERE id=?";
- int rc = sqlite3_prepare_v2(m_conn, sql, -1, &stmt, 0);
-
- if (rc != SQLITE_OK) {
- throw PrepareError(sql);
- }
-
- sqlite3_bind_int64(stmt, 1, rrset.getTtl().count());
- sqlite3_bind_blob(stmt, 2, rrset.getVersion().wire(), rrset.getVersion().size(), SQLITE_STATIC);
- sqlite3_bind_blob(stmt, 3, rrset.getData().wire(), rrset.getData().size(), SQLITE_STATIC);
- sqlite3_bind_int64(stmt, 4, rrset.getId());
-
- sqlite3_step(stmt);
- sqlite3_finalize(stmt);
-}
-
-} // namespace ndns
-} // namespace ndn
diff --git a/src/db-mgr.hpp b/src/db-mgr.hpp
deleted file mode 100644
index 29738be..0000000
--- a/src/db-mgr.hpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/* -*- 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/>.
- */
-
-#ifndef NDNS_DB_MGR_HPP
-#define NDNS_DB_MGR_HPP
-
-#include "config.hpp"
-#include "zone.hpp"
-#include "rrset.hpp"
-
-#include <ndn-cxx/common.hpp>
-#include <sqlite3.h>
-
-namespace ndn {
-namespace ndns {
-
-#define DEFINE_ERROR(Name, Base) \
-class Name : public Base \
-{ \
- public: \
- explicit \
- Name(const std::string& what) \
- : Base(what) \
- { \
- } \
-};
-
-/**
- * @brief Database Manager, which provides some common DB functionalities
- *
- * @note Function naming here follows MongoDB
- */
-class DbMgr : noncopyable
-{
-public:
- /**
- * @brief The Database Status
- */
- enum DbStatus {
- DB_CONNECTED,
- DB_CLOSED,
- DB_ERROR
- };
-
- DEFINE_ERROR(Error, std::runtime_error);
- DEFINE_ERROR(PrepareError, Error);
- DEFINE_ERROR(ExecuteError, Error);
-
-public:
- /**
- * @brief constructor
- */
- explicit
- DbMgr(const std::string& dbFile = DEFAULT_CONFIG_PATH "/" "ndns.db");
-
- /**
- * @brief destructor
- */
- ~DbMgr();
-
- /**
- * @brief connect to the database
- */
- void
- open();
-
- /**
- * @brief close the database connection
- */
- void
- close();
-
- /**
- * @brief get error message
- *
- * only valid when some db-related error happens,
- * such as db file does not exist, wrong SQL, etc
- */
- const std::string&
- getErr() const
- {
- return m_err;
- }
-
- /**
- * @brief get Database connection status
- */
- DbStatus
- getStatus() const
- {
- return m_status;
- }
-
-public: // Zone manipulation
- DEFINE_ERROR(ZoneError, Error);
-
- /**
- * @brief insert the m_zone to the database, and set the zone's id.
- * If the zone is already in the db, handle the exception without leaving it to upper level,
- * meanwhile, set the zone's id too.
- * @pre m_zone.getId() == 0
- * @post m_zone.getId() > 0
- */
- void
- insert(Zone& zone);
-
- /**
- * @brief lookup the zone by name, fill the m_id and m_ttl
- * @post whatever the previous id is
- * @return true if the record exist
- */
- bool
- find(Zone& zone);
-
- /**
- * @brief remove the zone
- * @pre m_zone.getId() > 0
- * @post m_zone.getId() == 0
- */
- void
- remove(Zone& zone);
-
-public: // Rrset manipulation
- DEFINE_ERROR(RrsetError, Error);
-
- /**
- * @brief add the rrset
- * @pre m_rrset.getId() == 0
- * @post m_rrset.getId() > 0
- */
- void
- insert(Rrset& rrset);
-
- /**
- * @brief get the data from db according to `m_zone`, `m_label`, `m_type`.
- *
- * If record exists, `m_ttl`, `m_version` and `m_data` is set
- *
- * @pre m_rrset.getZone().getId() > 0
- * @post whatever the previous id is,
- * m_rrset.getId() > 0 if record exists, otherwise m_rrset.getId() == 0
- * @return true if the record exist
- */
- bool
- find(Rrset& rrset);
-
- /**
- * @brief remove the rrset
- * @pre m_rrset.getId() > 0
- * @post m_rrset.getId() == 0
- */
- void
- remove(Rrset& rrset);
-
- /**
- * @brief replace ttl, version, and Data with new values
- * @pre m_rrset.getId() > 0
- */
- void
- modify(Rrset& rrset);
-
-private:
- /**
- * @brief set error message
- *
- * only valid when some db-related error happens,
- * such as db file does not exist, wrong SQL, etc
- */
- void
- setErr(const std::string& err)
- {
- this->m_err = err;
- }
-
- /**
- * @brief set Database connection status
- */
- void
- setStatus(DbStatus status)
- {
- this->m_status = status;
- }
-
-private:
- std::string m_dbFile;
- sqlite3* m_conn;
-
- std::string m_err;
- DbStatus m_status;
-};
-
-} // namespace ndns
-} // namespace ndn
-
-#endif // NDNS_DB_MGR_HPP
diff --git a/src/ndns-enum.cpp b/src/ndns-enum.cpp
index efc1bbf..2631e38 100644
--- a/src/ndns-enum.cpp
+++ b/src/ndns-enum.cpp
@@ -32,8 +32,8 @@
return "NDNS-Nack";
case NDNS_AUTH:
return "NDNS-Auth";
- case NDNS_NULL:
- return "NDNS-Null";
+ case NDNS_RAW:
+ return "NDNS-Raw";
default:
return "UNKNOWN";
}
diff --git a/src/ndns-enum.hpp b/src/ndns-enum.hpp
index c2bee36..617be9c 100644
--- a/src/ndns-enum.hpp
+++ b/src/ndns-enum.hpp
@@ -29,7 +29,7 @@
* @brief NdnsType defined in Response.NdnsMetaInfo.NdnsType
*/
enum NdnsType {
- NDNS_NULL = 0, ///< this is not a real type, just mean that MetaInfo does not contain NdnsType
+ NDNS_RAW = 0, ///< this is not a real type, just mean that MetaInfo does not contain NdnsType
NDNS_RESP = 1, ///< response type means there are requested RR
NDNS_NACK = 2, ///< no requested RR
NDNS_AUTH = 3, ///< only has RR for detailed (longer) label
diff --git a/tests/unit/rrset.cpp b/tests/unit/daemon/rrset.cpp
similarity index 97%
rename from tests/unit/rrset.cpp
rename to tests/unit/daemon/rrset.cpp
index 735ff81..db51d27 100644
--- a/tests/unit/rrset.cpp
+++ b/tests/unit/daemon/rrset.cpp
@@ -17,8 +17,8 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "rrset.hpp"
-#include "../boost-test.hpp"
+#include "daemon/rrset.hpp"
+#include "../../boost-test.hpp"
#include <ndn-cxx/name.hpp>
diff --git a/tests/unit/zone.cpp b/tests/unit/daemon/zone.cpp
similarity index 96%
rename from tests/unit/zone.cpp
rename to tests/unit/daemon/zone.cpp
index 62dcb20..3d60cd2 100644
--- a/tests/unit/zone.cpp
+++ b/tests/unit/daemon/zone.cpp
@@ -17,8 +17,8 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "zone.hpp"
-#include "../boost-test.hpp"
+#include "daemon/zone.hpp"
+#include "../../boost-test.hpp"
#include <ndn-cxx/name.hpp>
diff --git a/tests/unit/db-mgr.cpp b/tests/unit/db-mgr.cpp
deleted file mode 100644
index 4116ffb..0000000
--- a/tests/unit/db-mgr.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/* -*- 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 "db-mgr.hpp"
-#include "../boost-test.hpp"
-
-#include <boost/filesystem.hpp>
-
-namespace ndn {
-namespace ndns {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(DbMgr)
-
-static const boost::filesystem::path TEST_DATABASE = BUILDDIR "/tests/unit/db-mgr-ndns.db";
-
-class DbMgrFixture
-{
-public:
- DbMgrFixture()
- : session(TEST_DATABASE.string().c_str())
- {
- }
-
- ~DbMgrFixture()
- {
- session.close();
- boost::filesystem::remove(TEST_DATABASE);
- }
-
-public:
- ndns::DbMgr session;
-};
-
-
-BOOST_FIXTURE_TEST_CASE(Basic, DbMgrFixture)
-{
- BOOST_CHECK_EQUAL(session.getStatus(), ndns::DbMgr::DB_CONNECTED);
-
- session.close();
- BOOST_CHECK_EQUAL(session.getStatus(), ndns::DbMgr::DB_CLOSED);
-
- // reopen
- session.open();
- BOOST_CHECK_EQUAL(session.getStatus(), ndns::DbMgr::DB_CONNECTED);
-}
-
-BOOST_FIXTURE_TEST_CASE(Zones, DbMgrFixture)
-{
- Zone zone1;
- zone1.setName("/net");
- zone1.setTtl(time::seconds(4600));
- BOOST_CHECK_NO_THROW(session.insert(zone1));
- BOOST_CHECK_GT(zone1.getId(), 0);
-
- Zone zone2;
- zone2.setName("/net");
- session.find(zone2);
- BOOST_CHECK_EQUAL(zone2.getId(), zone1.getId());
- BOOST_CHECK_EQUAL(zone2.getTtl(), zone1.getTtl());
-
- BOOST_CHECK_NO_THROW(session.insert(zone2)); // zone2 already has id. Nothing to execute
-
- zone2.setId(0);
- BOOST_CHECK_THROW(session.insert(zone2), ndns::DbMgr::ExecuteError);
-
- BOOST_CHECK_NO_THROW(session.remove(zone1));
- BOOST_CHECK_EQUAL(zone1.getId(), 0);
-
- // record shouldn't exist at this point
- BOOST_CHECK_NO_THROW(session.find(zone2));
- BOOST_CHECK_EQUAL(zone2.getId(), 0);
-}
-
-BOOST_FIXTURE_TEST_CASE(Rrsets, DbMgrFixture)
-{
- Zone zone("/net");
- Rrset rrset1(&zone);
-
- // Add
-
- rrset1.setLabel("/net/ksk-123");
- rrset1.setType(name::Component("ID-CERT"));
- rrset1.setVersion(name::Component::fromVersion(567));
- rrset1.setTtl(time::seconds(4600));
-
- static const std::string DATA1 = "SOME DATA";
- rrset1.setData(dataBlock(ndn::tlv::Content, DATA1.c_str(), DATA1.size()));
-
- BOOST_CHECK_EQUAL(rrset1.getId(), 0);
- BOOST_CHECK_NO_THROW(session.insert(rrset1));
- BOOST_CHECK_GT(rrset1.getId(), 0);
- BOOST_CHECK_GT(rrset1.getZone()->getId(), 0);
-
- // Lookup
-
- Rrset rrset2(&zone);
- rrset2.setLabel("/net/ksk-123");
- rrset2.setType(name::Component("ID-CERT"));
-
- bool isFound = false;
- BOOST_CHECK_NO_THROW(isFound = session.find(rrset2));
- BOOST_CHECK_EQUAL(isFound, true);
-
- BOOST_CHECK_EQUAL(rrset2.getId(), rrset1.getId());
- BOOST_CHECK_EQUAL(rrset2.getLabel(), rrset1.getLabel());
- BOOST_CHECK_EQUAL(rrset2.getType(), rrset1.getType());
- BOOST_CHECK_EQUAL(rrset2.getVersion(), rrset1.getVersion());
- BOOST_CHECK_EQUAL(rrset2.getTtl(), rrset1.getTtl());
- BOOST_CHECK(rrset2.getData() == rrset1.getData());
-
- // Replace
-
- rrset1.setVersion(name::Component::fromVersion(890));
- static const std::string DATA2 = "ANOTHER DATA";
- rrset1.setData(dataBlock(ndn::tlv::Content, DATA2.c_str(), DATA2.size()));
-
- BOOST_CHECK_NO_THROW(session.modify(rrset1));
-
- rrset2 = Rrset(&zone);
- rrset2.setLabel("/net/ksk-123");
- rrset2.setType(name::Component("ID-CERT"));
-
- isFound = false;
- BOOST_CHECK_NO_THROW(isFound = session.find(rrset2));
- BOOST_CHECK_EQUAL(isFound, true);
-
- BOOST_CHECK_EQUAL(rrset2.getId(), rrset1.getId());
- BOOST_CHECK_EQUAL(rrset2.getLabel(), rrset1.getLabel());
- BOOST_CHECK_EQUAL(rrset2.getType(), rrset1.getType());
- BOOST_CHECK_EQUAL(rrset2.getVersion(), rrset1.getVersion());
- BOOST_CHECK_EQUAL(rrset2.getTtl(), rrset1.getTtl());
- BOOST_CHECK(rrset2.getData() == rrset1.getData());
-
- // Remove
-
- BOOST_CHECK_NO_THROW(session.remove(rrset1));
-
- rrset2 = Rrset(&zone);
- rrset2.setLabel("/net/ksk-123");
- rrset2.setType(name::Component("ID-CERT"));
-
- isFound = false;
- BOOST_CHECK_NO_THROW(isFound = session.find(rrset2));
- BOOST_CHECK_EQUAL(isFound, false);
-
- // Check error handling
-
- rrset1 = Rrset();
- BOOST_CHECK_THROW(session.insert(rrset1), ndns::DbMgr::RrsetError);
- BOOST_CHECK_THROW(session.find(rrset1), ndns::DbMgr::RrsetError);
-
- rrset1.setId(1);
- BOOST_CHECK_THROW(session.modify(rrset1), ndns::DbMgr::RrsetError);
-
- rrset1.setId(0);
- rrset1.setZone(&zone);
- BOOST_CHECK_THROW(session.modify(rrset1), ndns::DbMgr::RrsetError);
-
- BOOST_CHECK_THROW(session.remove(rrset1), ndns::DbMgr::RrsetError);
-
- rrset1.setId(1);
- BOOST_CHECK_NO_THROW(session.remove(rrset1));
-
- rrset1.setZone(0);
- rrset1.setId(1);
- BOOST_CHECK_NO_THROW(session.remove(rrset1));
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace ndns
-} // namespace ndn
diff --git a/tests/unit/ndns-enum.cpp b/tests/unit/ndns-enum.cpp
index c396b6b..7559448 100644
--- a/tests/unit/ndns-enum.cpp
+++ b/tests/unit/ndns-enum.cpp
@@ -31,7 +31,7 @@
BOOST_CHECK_EQUAL(toString(NDNS_RESP), "NDNS-Resp");
BOOST_CHECK_EQUAL(toString(NDNS_AUTH), "NDNS-Auth");
BOOST_CHECK_EQUAL(toString(NDNS_NACK), "NDNS-Nack");
- BOOST_CHECK_EQUAL(toString(NDNS_NULL), "NDNS-Null");
+ BOOST_CHECK_EQUAL(toString(NDNS_RAW), "NDNS-Raw");
BOOST_CHECK_EQUAL(toString(static_cast<NdnsType>(254)), "UNKNOWN");
BOOST_CHECK_EQUAL(toString(static_cast<NdnsType>(255)), "UNKNOWN");