Commit 597a2f4a authored by kulvait's avatar kulvait

Test coverage

Improved paths for the test
Testing of I/O DenFileInfo and DenFile2DReader
parent bd9d9b7a
Subproject commit 2c869e17e4803d30b3d5ca5b0d76387b9db97fa5
Subproject commit d10b9bd02e098476670f5eb0527d2c7281476e8a
#define CATCH_CONFIG_RUNNER
#include "PlogSetup.h"
#include "catch.hpp"
#include "RunTimeInfo.hpp"
using namespace CTL;
......@@ -24,4 +25,11 @@ int main(int argc, char* argv[])
return result;
}
std::string basedir()
{
io::RunTimeInfo rti;
std::string path = rti.getExecutableDirectoryPath();//build dir
return io::getParent(path);
}
TEST_CASE("LOGGING SETUP", "catch_main.cpp") {}
......@@ -8,19 +8,23 @@
// Internal libs
#include "CTIOL.h"
#include "RunTimeInfo.hpp"
using namespace CTL;
std::string basedir();
uint8_t uint8Value(int i)
{
uint8_t buffer[100];
io::readFirstBytes("../tests/integerByteManipulations/uint8", buffer, 2);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/uint8", basedir().c_str()),
buffer, 2);
return util::nextUint8(&buffer[i]);
}
TEST_CASE("TEST: putUint8 function.", "convertEndians_test.cpp")
{
std::string file = "../tests/integerByteManipulations/uint8_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/uint8_", basedir().c_str());
uint8_t buffer[100];
util::putUint8(0, &buffer[0]);
util::putUint8(255, &buffer[1]);
......@@ -40,12 +44,13 @@ TEST_CASE("TEST: nextUint16 function.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/uint16", buffer, 4);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/uint16", basedir().c_str()),
buffer, 4);
REQUIRE(util::nextUint16(&buffer[0]) == 0);
REQUIRE(util::nextUint16(&buffer[2]) == 65535);
SECTION("Now testing writing")
{
std::string file = "../tests/integerByteManipulations/uint16_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/uint16_", basedir().c_str());
util::putUint16(0, &buffer[0]);
util::putUint16(65535, &buffer[2]);
util::putUint16(65533, &buffer[4]);
......@@ -61,12 +66,12 @@ TEST_CASE("TEST: nextUint32 function.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/uint32", buffer, 8);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/uint32", basedir().c_str()), buffer, 8);
REQUIRE(util::nextUint32(&buffer[0]) == 0);
REQUIRE(util::nextUint32(&buffer[4]) == 4294967295);
SECTION("Now testing writing")
{
std::string file = "../tests/integerByteManipulations/uint32_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/uint32_", basedir().c_str());
util::putUint32(0, &buffer[0]);
util::putUint32(4294967295, &buffer[4]);
util::putUint32(3294967195, &buffer[8]);
......@@ -82,13 +87,13 @@ TEST_CASE("TEST: nextUint64 function.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/uint64", buffer, 16);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/uint64", basedir().c_str()), buffer, 16);
REQUIRE(util::nextUint64(&buffer[0]) == 0);
uint64_t maxval = 18446744073709551615ULL;
REQUIRE(util::nextUint64(&buffer[8]) == maxval);
SECTION("Now testing writing")
{
std::string file = "../tests/integerByteManipulations/uint64_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/uint64_", basedir().c_str());
uint64_t valuesToWrite[9]
= { 0, 18446744073709551615ULL, 3294967195, 1, 50000000000ULL, 2, 3, 256, 4294967295 };
for(int i = 0; i != 9; i++)
......@@ -108,7 +113,7 @@ TEST_CASE("TEST: nextInt8 readBytesFrom.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/int8", buffer, 5);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/int8", basedir().c_str()), buffer, 5);
REQUIRE(util::nextInt8(buffer) == -128);
REQUIRE(util::nextInt8(&buffer[1]) == -1);
REQUIRE(util::nextInt8(&buffer[2]) == 0);
......@@ -117,7 +122,7 @@ TEST_CASE("TEST: nextInt8 readBytesFrom.", "convertEndians_test.cpp")
SECTION("Now testing writing")
{
int TYPESIZE = 1;
std::string file = "../tests/integerByteManipulations/int8_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/int8_", basedir().c_str());
int8_t valuesToWrite[9] = { -128, -1, 0, 1, 127, -2, -3, 33, 21 };
for(int i = 0; i != 9; i++)
{
......@@ -136,7 +141,7 @@ TEST_CASE("TEST: nextInt16 readBytesFrom.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/int16", buffer, 10);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/int16", basedir().c_str()), buffer, 10);
REQUIRE(util::nextInt16(buffer) == -32768);
REQUIRE(util::nextInt16(&buffer[2]) == -1);
REQUIRE(util::nextInt16(&buffer[4]) == 0);
......@@ -145,7 +150,7 @@ TEST_CASE("TEST: nextInt16 readBytesFrom.", "convertEndians_test.cpp")
SECTION("Now testing writing")
{
int TYPESIZE = 2;
std::string file = "../tests/integerByteManipulations/int16_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/int16_", basedir().c_str());
int16_t valuesToWrite[9] = { -128, -1, 0, 1, 127, -32768, 32767, -3, 999 };
for(int i = 0; i != 9; i++)
{
......@@ -164,7 +169,7 @@ TEST_CASE("TEST: nextInt32 readBytesFrom.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/int32", buffer, 20);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/int32", basedir().c_str()), buffer, 20);
REQUIRE(util::nextInt32(buffer) == -2147483648);
REQUIRE(util::nextInt32(&buffer[4]) == -1);
REQUIRE(util::nextInt32(&buffer[8]) == 0);
......@@ -173,7 +178,7 @@ TEST_CASE("TEST: nextInt32 readBytesFrom.", "convertEndians_test.cpp")
SECTION("Now testing writing")
{
int TYPESIZE = 4;
std::string file = "../tests/integerByteManipulations/int32_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/int32_", basedir().c_str());
int32_t valuesToWrite[9] = { -128, -1, 0, 1, 127, -32768, 32767, -2147483648, 2147483647 };
for(int i = 0; i != 9; i++)
{
......@@ -193,7 +198,7 @@ TEST_CASE("TEST: nextInt64, putInt64, readBytesFrom.", "convertEndians_test.cpp"
uint8_t buffer[100];
uint8_t xuffer[100];
int TYPESIZE = 8;
std::string file = "../tests/integerByteManipulations/int32_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/int32_", basedir().c_str());
int64_t valuesToWrite[11]
= { -128,
-1,
......@@ -224,7 +229,7 @@ TEST_CASE("TEST: nextFloat readBytesFrom.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/float", buffer, 20);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/float", basedir().c_str()), buffer, 20);
REQUIRE(util::nextFloat(buffer) == 1.1f);
REQUIRE(util::nextFloat(&buffer[4]) == 3.1f);
REQUIRE(util::nextFloat(&buffer[8]) == 340282300000000000000000000000000000000.0f);
......@@ -233,7 +238,7 @@ TEST_CASE("TEST: nextFloat readBytesFrom.", "convertEndians_test.cpp")
SECTION("Now test writing.")
{
int TYPESIZE = 4;
std::string file = "../tests/integerByteManipulations/float_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/float_", basedir().c_str());
float valuesToWrite[11] = { 1.1f,
3.1f,
340282300000000000000000000000000000000.0f,
......@@ -269,7 +274,7 @@ TEST_CASE("TEST: nextDouble readBytesFrom.", "convertEndians_test.cpp")
{
uint8_t buffer[100];
uint8_t xuffer[100];
io::readFirstBytes("../tests/integerByteManipulations/double", buffer, 40);
io::readFirstBytes(io::xprintf("%s/tests/integerByteManipulations/double", basedir().c_str()), buffer, 40);
REQUIRE(util::nextDouble(buffer) == 1.1);
REQUIRE(util::nextDouble(&buffer[8]) == 3.1);
REQUIRE(util::nextDouble(&buffer[16]) == 500.0);
......@@ -279,7 +284,7 @@ TEST_CASE("TEST: nextDouble readBytesFrom.", "convertEndians_test.cpp")
{
int TYPESIZE = 8;
std::string file = "../tests/integerByteManipulations/double_";
std::string file = io::xprintf("%s/tests/integerByteManipulations/double_", basedir().c_str());
double valuesToWrite[11] = { 1.1,
3.1,
500.0,
......
#include "catch.hpp"
//Internal libs
#include "rawop.h"
#include "stringFormatter.h"
#include "DEN/DenFileInfo.hpp"
#include "DEN/DenFrame2DReader.hpp"
#include "RunTimeInfo.hpp"
#include "littleEndianAlignment.h"
using namespace CTL;
std::string basedir();//Defined in main file so that it will be accessible to linker
TEST_CASE("TEST: CTL::io::DenFileInfo", "[denfileinfo][NOPRINT][NOVIZ]")
{
std::string fileName = io::xprintf("%s/tests/testFiles/CAMERA.matrices", basedir().c_str());
io::DenFileInfo di(fileName);
REQUIRE(di.getNumRows() == 3);
REQUIRE(di.getNumCols() == 4);
REQUIRE(di.getNumSlices() == 248);
REQUIRE(di.dimx() == 4);
REQUIRE(di.dimy() == 3);
REQUIRE(di.dimz() == 248);
REQUIRE(di.getSize() == 23808 + 6);
REQUIRE(di.getNumPixels() == 2976);
REQUIRE(di.getDataType() == io::DenSupportedType::double_);
REQUIRE(di.elementByteSize() == 8);
}
TEST_CASE("TEST: CTL::io::DenFrame2DReader", "[denframereader][NOPRINT][NOVIZ]")
{
std::string fileName = io::xprintf("%s/tests/testFiles/CAMERA.matrices", basedir().c_str());
io::DenFrame2DReader<double> dfr(fileName);
REQUIRE(dfr.dimx() == 4);
REQUIRE(dfr.dimy() == 3);
REQUIRE(dfr.dimz() == 248);
}
......@@ -11,10 +11,12 @@
using namespace CTL;
std::string basedir();//Included in main
TEST_CASE("TEST: concatenateTextFiles function.", "rawop.h")
{
std::string fileA = "../tests/testFiles/A";
std::string fileB = "../tests/testFiles/B";
std::string fileA = io::xprintf("%s/tests/testFiles/A", basedir().c_str());
std::string fileB = io::xprintf("%s/tests/testFiles/B", basedir().c_str());
std::string outputFile = "/tmp/AB";
io::concatenateTextFiles(outputFile, true, { fileA, fileB });
std::string content = io::fileToString(outputFile);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment