Project

General

Profile

Bug #3495 ยป memory_test.t.cpp

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

 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/**
3
* Copyright (c) 2016 Regents of the University of California.
4
*
5
* This file is part of the nTorrent codebase.
6
*
7
* nTorrent is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS for complete list of nTorrent authors and contributors.
20
*/
21

    
22
#include "boost-test.hpp"
23

    
24
#include <string>
25
#include <vector>
26
#include <iterator>
27

    
28
#include <ndn-cxx/data.hpp>
29
#include <ndn-cxx/encoding/block.hpp>
30
#include <ndn-cxx/name.hpp>
31
#include <ndn-cxx/security/key-chain.hpp>
32
#include <ndn-cxx/security/signing-helpers.hpp>
33
#include <ndn-cxx/signature.hpp>
34

    
35
#include <boost/filesystem.hpp>
36
#include <boost/filesystem/fstream.hpp>
37
#include <boost/lexical_cast.hpp>
38

    
39
#include <sys/types.h>
40
#include <unistd.h>
41

    
42
namespace fs = boost::filesystem;
43

    
44
namespace ndn {
45
namespace tests {
46

    
47
BOOST_AUTO_TEST_SUITE(MemoryTest)
48

    
49
BOOST_AUTO_TEST_CASE(Dummy)
50
{
51
  auto filePath = "tests/testdata/foo/huge_file";
52
  auto fileSize = fs::file_size(filePath);
53
  auto dataPacketSize = 10240;
54
  auto commonPrefix = "/foo/bar";
55
  std::ifstream is(filePath, std::ios::binary);
56
  auto bytesRead = 0;
57
  char *buffer = new char[dataPacketSize];
58
  unsigned int packetNum = 0;
59
  std::vector<ndn::Name> names;
60
  ndn::security::KeyChain keyChain;
61
  names.reserve(fileSize/dataPacketSize);
62
  while(bytesRead <  fileSize) {
63
    is.read(buffer, dataPacketSize);
64
    auto read_size = is.gcount();
65
    ndn::Name packetName = commonPrefix;
66
    packetName.appendSequenceNumber(packetNum++);
67
    ndn::Data d(packetName);
68
    d.setContent(ndn::encoding::makeBinaryBlock(ndn::tlv::Content, buffer, read_size));
69
    keyChain.sign(d, ndn::security::signingWithSha256());
70
    names.push_back(d.getName());
71
    bytesRead += read_size;
72
  }
73
  names.shrink_to_fit();
74
  delete buffer;
75
  std::cout << "size of vector: "
76
            << names.capacity() * names[0].wireEncode().value_size()
77
            << std::endl;
78
  sleep(5);
79
}
80

    
81
BOOST_AUTO_TEST_SUITE_END()
82

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