2013-12-06 22:29:25 +01:00
|
|
|
#include "tests/unit-tests/unit_tests_globals.hpp"
|
|
|
|
#include "concordia/common/utils.hpp"
|
|
|
|
#include "concordia/common/config.hpp"
|
|
|
|
#include "tests/common/test_resources_manager.hpp"
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
2014-02-20 18:46:04 +01:00
|
|
|
#include "divsufsort.h"
|
2013-12-06 22:29:25 +01:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(utils)
|
|
|
|
|
2013-12-14 15:23:17 +01:00
|
|
|
BOOST_AUTO_TEST_CASE( WriteReadSingleCharacter )
|
2013-12-06 22:29:25 +01:00
|
|
|
{
|
|
|
|
ofstream testFileOutput;
|
|
|
|
testFileOutput.open(TestResourcesManager::getTestFilePath("temp","temp_file.bin").c_str(),
|
|
|
|
ios::out|ios::binary);
|
|
|
|
INDEX_CHARACTER_TYPE testCharacter = 123456789; //in hex: 75BCD15
|
|
|
|
Utils::writeIndexCharacter(testFileOutput,testCharacter);
|
|
|
|
testFileOutput.close();
|
|
|
|
|
|
|
|
ifstream testFileInput;
|
|
|
|
testFileInput.open(TestResourcesManager::getTestFilePath("temp","temp_file.bin").c_str(),ios::in|ios::binary);
|
|
|
|
INDEX_CHARACTER_TYPE retrievedCharacter = Utils::readIndexCharacter(testFileInput);
|
|
|
|
BOOST_CHECK_EQUAL(retrievedCharacter, testCharacter);
|
|
|
|
testFileInput.close();
|
|
|
|
|
|
|
|
boost::filesystem::remove(TestResourcesManager::getTestFilePath("temp","temp_file.bin"));
|
|
|
|
}
|
|
|
|
|
2013-12-14 15:23:17 +01:00
|
|
|
BOOST_AUTO_TEST_CASE( IndexVectorToSaucharArray )
|
2013-12-06 22:29:25 +01:00
|
|
|
{
|
2013-12-14 15:23:17 +01:00
|
|
|
boost::shared_ptr<vector<INDEX_CHARACTER_TYPE> > hash(new vector<INDEX_CHARACTER_TYPE>());
|
|
|
|
hash->push_back(123456789); // in hex: 75BCD15
|
|
|
|
// in memory: 15 cd 5b 07
|
|
|
|
// in memory DEC: 21 205 91 7
|
|
|
|
|
|
|
|
hash->push_back(987654321); // in hex: 3ADE68B1
|
|
|
|
// in memory: b1 68 de 3a
|
|
|
|
// in memory DEC: 177 104 222 58
|
2013-12-06 22:29:25 +01:00
|
|
|
sauchar_t * dataArray = Utils::indexVectorToSaucharArray(hash);
|
|
|
|
|
2013-12-14 15:23:17 +01:00
|
|
|
boost::shared_ptr<vector<INDEX_CHARACTER_TYPE> > result(new vector<INDEX_CHARACTER_TYPE>());
|
2013-12-06 22:29:25 +01:00
|
|
|
for (int i=0;i<8;i++) {
|
|
|
|
INDEX_CHARACTER_TYPE a = dataArray[i];
|
2013-12-14 15:23:17 +01:00
|
|
|
result->push_back(a);
|
2013-12-06 22:29:25 +01:00
|
|
|
}
|
|
|
|
|
2013-12-14 15:23:17 +01:00
|
|
|
boost::shared_ptr<vector<INDEX_CHARACTER_TYPE> > expected(new vector<INDEX_CHARACTER_TYPE>());
|
|
|
|
expected->push_back(21);
|
|
|
|
expected->push_back(205);
|
|
|
|
expected->push_back(91);
|
|
|
|
expected->push_back(7);
|
|
|
|
expected->push_back(177);
|
|
|
|
expected->push_back(104);
|
|
|
|
expected->push_back(222);
|
|
|
|
expected->push_back(58);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(result->begin(), result->end(), expected->begin(), expected->end());
|
2013-12-06 22:29:25 +01:00
|
|
|
}
|
|
|
|
|
2014-06-24 18:23:46 +02:00
|
|
|
BOOST_AUTO_TEST_CASE( IndexVectorToSaucharVector )
|
|
|
|
{
|
|
|
|
boost::shared_ptr<vector<INDEX_CHARACTER_TYPE> > hash(new vector<INDEX_CHARACTER_TYPE>());
|
|
|
|
hash->push_back(123456789); // in hex: 75BCD15
|
|
|
|
// in memory: 15 cd 5b 07
|
|
|
|
// in memory DEC: 21 205 91 7
|
|
|
|
|
|
|
|
hash->push_back(987654321); // in hex: 3ADE68B1
|
|
|
|
// in memory: b1 68 de 3a
|
|
|
|
// in memory DEC: 177 104 222 58
|
|
|
|
boost::shared_ptr<vector<sauchar_t> > result = Utils::indexVectorToSaucharVector(hash);
|
|
|
|
|
|
|
|
boost::shared_ptr<vector<sauchar_t> > expected(new vector<sauchar_t>());
|
|
|
|
expected->push_back(21);
|
|
|
|
expected->push_back(205);
|
|
|
|
expected->push_back(91);
|
|
|
|
expected->push_back(7);
|
|
|
|
expected->push_back(177);
|
|
|
|
expected->push_back(104);
|
|
|
|
expected->push_back(222);
|
|
|
|
expected->push_back(58);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(result->begin(), result->end(), expected->begin(), expected->end());
|
|
|
|
}
|
|
|
|
|
2015-04-09 22:17:19 +02:00
|
|
|
BOOST_AUTO_TEST_CASE( MaxSentenceSize )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL(Utils::maxSentenceSize, 65536);
|
|
|
|
}
|
|
|
|
|
|
|
|
//The below examples use the following marker:
|
|
|
|
//00000000|00000000|00000000|00000011|00000000|00000101|00000000|00000111
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( CreateMarker )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL(Utils::createMarker(3,5,7), 12885229575);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( GetIdFromMarker )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL(Utils::getIdFromMarker(12885229575), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( GetOffsetFromMarker )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL(Utils::getOffsetFromMarker(12885229575), 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( GetLengthFromMarker )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL(Utils::getLengthFromMarker(12885229575), 7);
|
|
|
|
}
|
2013-12-06 22:29:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|