Project

General

Profile

Bug #3495 ยป memory_test.t.cpp

little test - Michael Sweatt, 03/02/2016 10:32 AM

 
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2016 Regents of the University of California.
*
* This file is part of the nTorrent codebase.
*
* nTorrent is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* nTorrent 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 Lesser General Public License for more details.
*
* You should have received copies of the GNU General Public License and GNU Lesser
* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
* <http://www.gnu.org/licenses/>.
*
* See AUTHORS for complete list of nTorrent authors and contributors.
*/

#include "boost-test.hpp"

#include <string>
#include <vector>
#include <iterator>

#include <ndn-cxx/data.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/signature.hpp>

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/lexical_cast.hpp>

#include <sys/types.h>
#include <unistd.h>

namespace fs = boost::filesystem;

namespace ndn {
namespace tests {

BOOST_AUTO_TEST_SUITE(MemoryTest)

BOOST_AUTO_TEST_CASE(Dummy)
{
auto filePath = "tests/testdata/foo/huge_file";
auto fileSize = fs::file_size(filePath);
auto dataPacketSize = 10240;
auto commonPrefix = "/foo/bar";
std::ifstream is(filePath, std::ios::binary);
auto bytesRead = 0;
char *buffer = new char[dataPacketSize];
unsigned int packetNum = 0;
std::vector<ndn::Name> names;
ndn::security::KeyChain keyChain;
names.reserve(fileSize/dataPacketSize);
while(bytesRead < fileSize) {
is.read(buffer, dataPacketSize);
auto read_size = is.gcount();
ndn::Name packetName = commonPrefix;
packetName.appendSequenceNumber(packetNum++);
ndn::Data d(packetName);
d.setContent(ndn::encoding::makeBinaryBlock(ndn::tlv::Content, buffer, read_size));
keyChain.sign(d, ndn::security::signingWithSha256());
names.push_back(d.getName());
bytesRead += read_size;
}
names.shrink_to_fit();
delete buffer;
std::cout << "size of vector: "
<< names.capacity() * names[0].wireEncode().value_size()
<< std::endl;
sleep(5);
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace tests
} // namespace ndn
    (1-1/1)