btrtest.cpp File Reference

A test suite for the whole ByteTree module which is intended to be used in coordination with a python script. More...

#include <gmp.h>
#include <gmpxx.h>
#include <fstream>
#include <cstring>
#include "verifierutils.hpp"

Go to the source code of this file.

Macros

#define PATH_TO_INPUT_FILE   "./input.txt"
#define PATH_TO_OUTPUT_FILE   "./actual_output.txt"

Functions

void test_ByteTree_parseString (std::ifstream &input, std::ofstream &output)
 Reads hexadecimal string representation of ByteTrees from input.txt and outputs the same representation on actual_output.txt.
void test_ByteTree_parseFile (std::ifstream &input, std::ofstream &output)
 Reads in input.txt the path to a file containing a bytetree, parses it and outputs the content of it on actual_output.txt.
void test_Leaf_toInteger (std::ifstream &input, std::ofstream &output)
 Reads decimal representations of large integers, constructs Leaf's instances from them and then turns them into integers again.
void test_Leaf_toBoolArray (std::ifstream &input, std::ofstream &output)
 Reads the decimal representations of large integers, constructs Leaf's instances from them and then turns them into boolean arrays.
void printHelp ()
 Prints the help of this program, including a list of the functions that can be tested.
int main (int argc, char **argv)

Detailed Description

A test suite for the whole ByteTree module which is intended to be used in coordination with a python script.

Author
Léo Perrin leope.nosp@m.rrin.nosp@m.@pica.nosp@m.rres.nosp@m.ursix.nosp@m..fr
Date
Time-stamp: <2012-08-26 14:38:40 leo>

It is meant to be used in coordination with the unitarytest.py python script so as to compare its behaviour with that of the reference implmentation. The functions in this file are sort of interfaces between the actual classes tested and the unitary tests provided by the python script and based on the reference implementation (which is in python). This script produces a test vector, "./input.txt", and a file containing what this program should output, "./ideal_out.txt".

For each non-virtual function in this module, there is a unitary test reading its data line by line. It reads one line of the "./input.txt" file, processes it, writes one line in "./actual_out.txt" and continues until the end of the input file is found.

In the end, the differences between "ideal_out.txt" and "actual_out.txt" are computed. If there is even one error, then you have a problem.

Definition in file btrtest.cpp.

Macro Definition Documentation

#define PATH_TO_INPUT_FILE   "./input.txt"

Definition at line 38 of file btrtest.cpp.

#define PATH_TO_OUTPUT_FILE   "./actual_output.txt"

Definition at line 39 of file btrtest.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 163 of file btrtest.cpp.

{
if (argc<2)
else
{
std::ifstream input(PATH_TO_INPUT_FILE,
std::ifstream::in);
std::ofstream output(PATH_TO_OUTPUT_FILE);
if (strcmp(argv[1],"ByteTree::parseString") == 0)
else if (strcmp(argv[1],"ByteTree::parseFile") == 0)
test_ByteTree_parseFile(input,output);
else if (strcmp(argv[1],"Leaf.toInteger") == 0)
test_Leaf_toInteger(input,output);
else if (strcmp(argv[1],"Leaf.toBoolArray") == 0)
test_Leaf_toBoolArray(input,output);
else
output.close();
}
return 0;
}
void printHelp ( )

Prints the help of this program, including a list of the functions that can be tested.

Definition at line 147 of file btrtest.cpp.

{
std::cout<<"Run ./bt_test <function to test> and it will parse the"
<<PATH_TO_INPUT_FILE<< "file to produce the "
<<PATH_TO_OUTPUT_FILE<<" file. If this is giberish to you,"
<<"you\nshould read the documentation ^^"<<"\n\n"
<<"Available functions are:"<<"\n"
<<" - ByteTree::parseString\n"
<<" - ByteTree::parseFile\n"
<<" - Leaf.toInteger\n"
<<" - Leaf.toBoolArray\n"
<<"\n"<<std::endl;
}
void test_ByteTree_parseFile ( std::ifstream &  input,
std::ofstream &  output 
)

Reads in input.txt the path to a file containing a bytetree, parses it and outputs the content of it on actual_output.txt.

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 69 of file btrtest.cpp.

{
ByteTree * bt;
std::string line;
while (input>>line)
{
bt = ByteTree::parseFile(line);
output<<bt->toString()<<std::endl;
}
}
void test_ByteTree_parseString ( std::ifstream &  input,
std::ofstream &  output 
)

Reads hexadecimal string representation of ByteTrees from input.txt and outputs the same representation on actual_output.txt.

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 49 of file btrtest.cpp.

{
ByteTree * bt;
std::string line;
while (input>>line)
{
bt = ByteTree::parseString(line);
output<<bt->toString()<<std::endl;
}
}
void test_Leaf_toBoolArray ( std::ifstream &  input,
std::ofstream &  output 
)

Reads the decimal representations of large integers, constructs Leaf's instances from them and then turns them into boolean arrays.

Integers are read from input.txt and boolean arrays are output in actual_output.txt.

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 115 of file btrtest.cpp.

{
ByteTree * bt;
unsigned int number;
while (input>>number)
{
std::vector<uint8_t> content(number);
for (unsigned int i=0; i<number; i++)
{
bool b;
input>>b;
if (b)
content[i] = 1;
else
content[i] = 0;
}
bt = new Leaf(content);
std::vector<bool> array = bt->toBoolArray();
for (unsigned int i=0; i<array.size(); i++)
if (array[i])
output<<"1";
else
output<<"0";
output<<std::endl;
}
}
void test_Leaf_toInteger ( std::ifstream &  input,
std::ofstream &  output 
)

Reads decimal representations of large integers, constructs Leaf's instances from them and then turns them into integers again.

Integers are read from input.txt and output in actual_output.txt.

Parameters
inputThe input file at PATH_TO_INPUT_FILE (read).
outputThe output file at PATH_TO_OUTPUT_FILE (write).

Definition at line 91 of file btrtest.cpp.

{
ByteTree * bt;
std::string line;
while (input>>line)
{
mpz_class integer(line,10);
bt = new Leaf(integer);
output<<bt->toInteger()<<std::endl;
}
}