bug+codestyle: Fix compile bugs and adjust code style
Change-Id: I008bb538441c099fa25b8b967fbf23ffce13a220
diff --git a/test/main.cc b/test/main.cpp
similarity index 100%
rename from test/main.cc
rename to test/main.cpp
diff --git a/test/test-contact-storage.cc b/test/test-contact-storage.cpp
similarity index 68%
rename from test/test-contact-storage.cc
rename to test/test-contact-storage.cpp
index 12b2a54..cc97e08 100644
--- a/test/test-contact-storage.cc
+++ b/test/test-contact-storage.cpp
@@ -7,29 +7,29 @@
#include <boost/test/unit_test.hpp>
-#include "contact-storage.h"
-#include <cryptopp/hex.h>
-#include <cryptopp/sha.h>
-#include <cryptopp/files.h>
+#include "contact-storage.hpp"
+#include "cryptopp.hpp"
#include <boost/filesystem.hpp>
-using namespace ndn;
+namespace chronos {
+
+using std::string;
namespace fs = boost::filesystem;
BOOST_AUTO_TEST_SUITE(TestContactStorage)
-const std::string dbName("chronos-20e9530008b27c661ad3429d1956fa1c509b652dce9273bfe81b7c91819c272c.db");
+const string dbName("chronos-20e9530008b27c661ad3429d1956fa1c509b652dce9273bfe81b7c91819c272c.db");
BOOST_AUTO_TEST_CASE(InitializeTable)
{
Name identity("/TestContactStorage/InitializeTable");
- chronos::ContactStorage contactStorage(identity);
+ ContactStorage contactStorage(identity);
fs::path dbPath = fs::path(getenv("HOME")) / ".chronos" / dbName;
BOOST_CHECK(boost::filesystem::exists(dbPath));
}
-
-
BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace chronos
diff --git a/test/test-endorse-certificate.cc b/test/test-endorse-certificate.cpp
similarity index 73%
rename from test/test-endorse-certificate.cc
rename to test/test-endorse-certificate.cpp
index 95bc012..09eb935 100644
--- a/test/test-endorse-certificate.cc
+++ b/test/test-endorse-certificate.cpp
@@ -15,16 +15,20 @@
#include <boost/test/unit_test.hpp>
-#include <ndn-cpp-dev/security/key-chain.hpp>
-#include <ndn-cpp-dev/util/time.hpp>
-#include <ndn-cpp-dev/util/io.hpp>
-#include <cryptopp/base64.h>
-#include <cryptopp/files.h>
-#include "endorse-certificate.h"
+#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <ndn-cxx/util/time.hpp>
+#include <ndn-cxx/util/io.hpp>
+#include "cryptopp.hpp"
+#include "endorse-certificate.hpp"
-using namespace ndn;
-using namespace std;
-using namespace chronos;
+namespace chronos {
+
+using std::vector;
+using std::string;
+
+using ndn::KeyChain;
+using ndn::IdentityCertificate;
BOOST_AUTO_TEST_SUITE(TestEndorseCertificate)
@@ -80,16 +84,18 @@
BOOST_AUTO_TEST_CASE(IdCert)
{
- boost::iostreams::stream<boost::iostreams::array_source> is (testIdCert.c_str(), testIdCert.size());
- shared_ptr<IdentityCertificate> idCert = io::load<IdentityCertificate>(is);
-
+ boost::iostreams::stream<boost::iostreams::array_source> is(testIdCert.c_str(),
+ testIdCert.size());
+ shared_ptr<IdentityCertificate> idCert = ndn::io::load<IdentityCertificate>(is);
+
BOOST_CHECK(static_cast<bool>(idCert));
- const Certificate::SubjectDescriptionList& subjectDescription = idCert->getSubjectDescriptionList();
+ const ndn::Certificate::SubjectDescriptionList& subjectDescription =
+ idCert->getSubjectDescriptionList();
BOOST_CHECK_EQUAL(subjectDescription.size(), 6);
- Certificate::SubjectDescriptionList::const_iterator it = subjectDescription.begin();
- Certificate::SubjectDescriptionList::const_iterator end = subjectDescription.end();
+ ndn::Certificate::SubjectDescriptionList::const_iterator it = subjectDescription.begin();
+ ndn::Certificate::SubjectDescriptionList::const_iterator end = subjectDescription.end();
int count = 0;
for(; it != end; it++)
{
@@ -126,49 +132,55 @@
}
BOOST_CHECK_EQUAL(count, 6);
- BOOST_CHECK_EQUAL(idCert->getName().toUri(), "/EndorseCertificateTests/KEY/EncodeDecode/ksk-1394072147335/ID-CERT/%FD%01D%95%2C%D5%E8");
+ BOOST_CHECK_EQUAL(idCert->getName().toUri(),
+ "/EndorseCertificateTests/KEY/EncodeDecode/ksk-1394072147335/ID-CERT/%FD%01D%95%2C%D5%E8");
- OBufferStream keyOs;
+ ndn::OBufferStream keyOs;
{
using namespace CryptoPP;
StringSource(testKey, true, new Base64Decoder(new FileSink(keyOs)));
}
- PublicKey key(keyOs.buf()->buf(), keyOs.buf()->size());
+ ndn::PublicKey key(keyOs.buf()->buf(), keyOs.buf()->size());
BOOST_CHECK(key == idCert->getPublicKeyInfo());
}
BOOST_AUTO_TEST_CASE(ConstructFromIdCert)
{
- boost::iostreams::stream<boost::iostreams::array_source> is (testIdCert.c_str(), testIdCert.size());
- shared_ptr<IdentityCertificate> idCert = io::load<IdentityCertificate>(is);
-
+ boost::iostreams::stream<boost::iostreams::array_source> is(testIdCert.c_str(),
+ testIdCert.size());
+ shared_ptr<IdentityCertificate> idCert = ndn::io::load<IdentityCertificate>(is);
+
Profile profile(*idCert);
vector<string> endorseList;
endorseList.push_back("email");
endorseList.push_back("homepage");
EndorseCertificate endorseCertificate(*idCert, profile, endorseList);
- KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
- keyChain.signWithSha256(endorseCertificate);
+ KeyChain keyChain("sqlite3", "file");
+ keyChain.signWithSha256(endorseCertificate);
const Block& endorseDataBlock = endorseCertificate.wireEncode();
Data decodedEndorseData;
decodedEndorseData.wireDecode(endorseDataBlock);
EndorseCertificate decodedEndorse(decodedEndorseData);
- BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("IDENTITY"), "/EndorseCertificateTests/EncodeDecode");
+ BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("IDENTITY"),
+ "/EndorseCertificateTests/EncodeDecode");
BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("name"), "MyName");
BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("homepage"), "MyHomePage");
BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().size(), 2);
BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().at(0), "email");
BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().at(1), "homepage");
- BOOST_CHECK_EQUAL(decodedEndorse.getSigner(), "/EndorseCertificateTests/EncodeDecode/ksk-1394072147335");
- BOOST_CHECK_EQUAL(decodedEndorse.getPublicKeyName(), "/EndorseCertificateTests/EncodeDecode/ksk-1394072147335");
+ BOOST_CHECK_EQUAL(decodedEndorse.getSigner(),
+ "/EndorseCertificateTests/EncodeDecode/ksk-1394072147335");
+ BOOST_CHECK_EQUAL(decodedEndorse.getPublicKeyName(),
+ "/EndorseCertificateTests/EncodeDecode/ksk-1394072147335");
}
BOOST_AUTO_TEST_CASE(ConstructFromEndorseCert)
{
- boost::iostreams::stream<boost::iostreams::array_source> is (testEndorseCert.c_str(), testEndorseCert.size());
- shared_ptr<Data> rawData = io::load<Data>(is);
+ boost::iostreams::stream<boost::iostreams::array_source> is(testEndorseCert.c_str(),
+ testEndorseCert.size());
+ shared_ptr<Data> rawData = ndn::io::load<Data>(is);
EndorseCertificate rawEndorse(*rawData);
vector<string> endorseList;
@@ -178,7 +190,7 @@
Name signer("/EndorseCertificateTests/Singer/ksk-1234567890");
EndorseCertificate endorseCertificate(rawEndorse, signer, endorseList);
- KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
+ KeyChain keyChain("sqlite3", "file");
keyChain.signWithSha256(endorseCertificate);
const Block& endorseDataBlock = endorseCertificate.wireEncode();
@@ -186,15 +198,20 @@
Data decodedEndorseData;
decodedEndorseData.wireDecode(endorseDataBlock);
EndorseCertificate decodedEndorse(decodedEndorseData);
- BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("IDENTITY"), "/EndorseCertificateTests/EncodeDecode");
+ BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("IDENTITY"),
+ "/EndorseCertificateTests/EncodeDecode");
BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("name"), "MyName");
BOOST_CHECK_EQUAL(decodedEndorse.getProfile().get("homepage"), "MyHomePage");
BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().size(), 3);
BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().at(0), "institution");
BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().at(1), "group");
BOOST_CHECK_EQUAL(decodedEndorse.getEndorseList().at(2), "advisor");
- BOOST_CHECK_EQUAL(decodedEndorse.getSigner(), "/EndorseCertificateTests/Singer/ksk-1234567890");
- BOOST_CHECK_EQUAL(decodedEndorse.getPublicKeyName(), "/EndorseCertificateTests/EncodeDecode/ksk-1394072147335");
+ BOOST_CHECK_EQUAL(decodedEndorse.getSigner(),
+ "/EndorseCertificateTests/Singer/ksk-1234567890");
+ BOOST_CHECK_EQUAL(decodedEndorse.getPublicKeyName(),
+ "/EndorseCertificateTests/EncodeDecode/ksk-1394072147335");
}
BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace chronos
diff --git a/test/test-profile.cc b/test/test-profile.cpp
similarity index 68%
rename from test/test-profile.cc
rename to test/test-profile.cpp
index 9c1b67a..9848685 100644
--- a/test/test-profile.cc
+++ b/test/test-profile.cpp
@@ -7,11 +7,12 @@
#include <boost/test/unit_test.hpp>
-#include "profile.h"
+#include "profile.hpp"
+#include <ndn-cxx/encoding/buffer-stream.hpp>
-using namespace ndn;
-using namespace std;
-using namespace chronos;
+namespace chronos {
+
+using std::string;
BOOST_AUTO_TEST_SUITE(TestProfile)
@@ -22,20 +23,23 @@
profile["name"] = "Yingdi Yu";
profile["school"] = "UCLA";
- OBufferStream os;
+ ndn::OBufferStream os;
profile.encode(os);
- shared_ptr<Buffer> encoded = os.buf();
-
- boost::iostreams::stream
- <boost::iostreams::array_source> is (reinterpret_cast<const char*>(encoded->buf ()), encoded->size ());
+ ndn::ConstBufferPtr encoded = os.buf();
- Profile decodedProfile;
+ boost::iostreams::stream
+ <boost::iostreams::array_source> is(reinterpret_cast<const char*>(encoded->buf()),
+ encoded->size ());
+
+ Profile decodedProfile;
decodedProfile.decode(is);
-
+
BOOST_CHECK_EQUAL(decodedProfile.getIdentityName().toUri(), string("/ndn/ucla/yingdi"));
BOOST_CHECK_EQUAL(decodedProfile["name"], string("Yingdi Yu"));
BOOST_CHECK_EQUAL(decodedProfile["school"], string("UCLA"));
}
BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace chronos