core: define NFD version

refs #1316

Change-Id: I56046cb7482a771d8d25fe1f0b78e201855b8eed
diff --git a/daemon/core/version.hpp b/daemon/core/version.hpp
new file mode 100644
index 0000000..748ef7e
--- /dev/null
+++ b/daemon/core/version.hpp
@@ -0,0 +1,39 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NFD_CORE_VERSION_HPP
+#define NFD_CORE_VERSION_HPP
+
+#include "common.hpp"
+
+namespace nfd {
+
+/** NFD version follows Semantic Versioning 2.0.0 specification
+ *  http://semver.org/
+ */
+
+/** \brief NFD version represented as an integer
+ *
+ *  MAJOR*1000000 + MINOR*1000 + PATCH
+ */
+#define NFD_VERSION 1000
+
+/** \brief NFD version represented as a string
+ *
+ *  MAJOR.MINOR.PATCH
+ */
+#define NFD_VERSION_STRING "0.1.0"
+
+/// MAJOR version
+#define NFD_VERSION_MAJOR (NFD_VERSION / 1000000)
+/// MINOR version
+#define NFD_VERSION_MINOR (NFD_VERSION % 1000000 / 1000)
+/// PATCH version
+#define NFD_VERSION_PATCH (NFD_VERSION % 1000)
+
+} // namespace nfd
+
+#endif // NFD_CORE_VERSION_HPP
diff --git a/tests/core/version.cpp b/tests/core/version.cpp
new file mode 100644
index 0000000..fb551e3
--- /dev/null
+++ b/tests/core/version.cpp
@@ -0,0 +1,42 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "core/version.hpp"
+#include "core/logger.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(CoreVersion, BaseFixture)
+
+NFD_LOG_INIT("VersionTest");
+
+BOOST_AUTO_TEST_CASE(Version)
+{
+  NFD_LOG_INFO("NFD_VERSION " << NFD_VERSION);
+  
+  BOOST_CHECK_EQUAL(NFD_VERSION, NFD_VERSION_MAJOR * 1000000 +
+                                 NFD_VERSION_MINOR * 1000 +
+                                 NFD_VERSION_PATCH);
+}
+
+BOOST_AUTO_TEST_CASE(VersionString)
+{
+  NFD_LOG_INFO("NFD_VERSION_STRING " << NFD_VERSION_STRING);
+  
+  BOOST_STATIC_ASSERT(NFD_VERSION_MAJOR < 1000);
+  char buf[12];
+  snprintf(buf, sizeof(buf), "%d.%d.%d", NFD_VERSION_MAJOR, NFD_VERSION_MINOR, NFD_VERSION_PATCH);
+  
+  BOOST_CHECK_EQUAL(std::string(NFD_VERSION_STRING), std::string(buf));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace nfd