Skip to content

Commit

Permalink
test app
Browse files Browse the repository at this point in the history
  • Loading branch information
voivoid committed Apr 9, 2017
1 parent 523540b commit e881a24
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "Bson/bson.h"

#include <iostream>
#include <iterator>

#include <boost/filesystem.hpp>

int main(int argc, char** argv)
{
if(argc != 2)
{
std::cerr << "Usage: " << argv[0] << " <filename>\n";
return -1;
}

boost::filesystem::path filePath = argv[1];
assert(!filePath.empty());

if(!boost::filesystem::exists(filePath))
{
std::cerr << "File " << filePath << " doesn't exist\n";
return -1;
}

if(!boost::filesystem::is_regular_file(filePath))
{
std::cerr << "File " << filePath << " is not regular file\n";
return -1;
}

const auto fileSize = boost::filesystem::file_size(filePath);

boost::filesystem::ifstream fstream(filePath, std::ios_base::binary);
assert(fstream);

Bson::Bytes content;
content.reserve(fileSize);
content.insert(content.begin(),
std::istream_iterator<Bson::Byte>(fstream),
std::istream_iterator<Bson::Byte>());
assert(content.size() == fileSize);

std::cout << "Content size: " << content.size() << "\n";

Bson::Bytes result = Bson::encode(Bson::decode(content));
std::cout << "Result: " << std::boolalpha << (result == content) << "\n";

return 0;
}

0 comments on commit e881a24

Please sign in to comment.