Clean up some test files.

This commit is contained in:
James Grogan 2022-11-30 18:28:50 +00:00
parent 1adc9272f8
commit b45385e8c7
51 changed files with 485 additions and 281 deletions

View file

@ -12,6 +12,13 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(FALSE)
set(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
set(GCC_COVERAGE_LINK_FLAGS "-lgcov")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
endif()
add_subdirectory(src) add_subdirectory(src)
add_subdirectory(apps) add_subdirectory(apps)
add_subdirectory(test) add_subdirectory(test)

View file

@ -5,78 +5,78 @@
#include <iostream> #include <iostream>
TemplatingEngine::TemplatingEngine(const Path& workingDirectory) TemplatingEngine::TemplatingEngine(const Path& workingDirectory)
: mWorkingDirectory(workingDirectory) : mWorkingDirectory(workingDirectory)
{ {
} }
void TemplatingEngine::loadTemplateFiles() void TemplatingEngine::loadTemplateFiles()
{ {
const auto files = Directory::getFilesWithExtension(mWorkingDirectory, mTemplateExtension); const auto files = Directory::getFilesWithExtension(mWorkingDirectory, mTemplateExtension);
for (const auto& file : files) for (const auto& file : files)
{ {
mTemplateFiles.push_back(std::make_unique<TemplateFile>(file)); mTemplateFiles.push_back(std::make_unique<TemplateFile>(file));
} }
} }
std::string TemplatingEngine::processTemplate(const std::string& name) std::string TemplatingEngine::processTemplate(const std::string& name)
{ {
if (auto file = getTemplateFile(name)) if (auto file = getTemplateFile(name))
{ {
return processTemplate(file); return processTemplate(file);
} }
return {}; return {};
} }
TemplateFile* TemplatingEngine::getTemplateFile(const Path& path) TemplateFile* TemplatingEngine::getTemplateFile(const Path& path)
{ {
return getTemplateFile(path.stem().string()); return getTemplateFile(path.stem().string());
} }
TemplateFile* TemplatingEngine::getTemplateFile(const std::string& name) TemplateFile* TemplatingEngine::getTemplateFile(const std::string& name)
{ {
std::cout << "Looking for template file with name: " << name << std::endl; //std::cout << "Looking for template file with name: " << name << std::endl;
for (const auto& file : mTemplateFiles) for (const auto& file : mTemplateFiles)
{ {
if (file->getName() == name) if (file->getName() == name)
{ {
return file.get(); return file.get();
} }
} }
return nullptr; return nullptr;
} }
std::string TemplatingEngine::processTemplate(TemplateFile* file, TemplateNode* parent) std::string TemplatingEngine::processTemplate(TemplateFile* file, TemplateNode* parent)
{ {
file->loadContent(); file->loadContent();
file->dumpContent(); file->dumpContent();
auto content = file->getContent(); auto content = file->getContent();
if (parent) if (parent)
{ {
content->setExtensionParent(parent); content->setExtensionParent(parent);
} }
if (auto extension_node = content->getFirstChildShallow<TemplateExtends>()) if (auto extension_node = content->getFirstChildShallow<TemplateExtends>())
{ {
std::cout << "Found extension node" << std::endl; //std::cout << "Found extension node" << std::endl;
if (auto extension_template = getTemplateFile(Path(extension_node->getPath()))) if (auto extension_template = getTemplateFile(Path(extension_node->getPath())))
{ {
std::cout << "Found extension template" << std::endl; //std::cout << "Found extension template" << std::endl;
return processTemplate(extension_template, parent); return processTemplate(extension_template, parent);
} }
else else
{ {
return render(content); return render(content);
} }
} }
else else
{ {
return render(content); return render(content);
} }
} }
std::string TemplatingEngine::render(TemplateNode* content) std::string TemplatingEngine::render(TemplateNode* content)
{ {
return content->render(); return content->render();
} }

View file

@ -51,7 +51,7 @@ std::string ZlibEncoder::toString(CompressionMethod method) const
void ZlibEncoder::parseCompressionMethod(unsigned char method) void ZlibEncoder::parseCompressionMethod(unsigned char method)
{ {
std::cout << "Got compression input " << static_cast<int>(method) << std::endl; //std::cout << "Got compression input " << static_cast<int>(method) << std::endl;
mCompressionMethod = static_cast<CompressionMethod>(ByteUtils::getLowerNBits(method, 4)); mCompressionMethod = static_cast<CompressionMethod>(ByteUtils::getLowerNBits(method, 4));
auto compression_info = ByteUtils::getHigherNBits(method, 4); auto compression_info = ByteUtils::getHigherNBits(method, 4);
@ -63,12 +63,12 @@ void ZlibEncoder::parseCompressionMethod(unsigned char method)
void ZlibEncoder::parseExtraFlags(unsigned char extraFlags, unsigned char compression_byte) void ZlibEncoder::parseExtraFlags(unsigned char extraFlags, unsigned char compression_byte)
{ {
std::cout << "Got flags " << static_cast<int>(extraFlags) << std::endl; //std::cout << "Got flags " << static_cast<int>(extraFlags) << std::endl;
auto mod = ((static_cast<unsigned>(compression_byte) << 8) | extraFlags) % 31; auto mod = ((static_cast<unsigned>(compression_byte) << 8) | extraFlags) % 31;
if (mod != 0) if (mod != 0)
{ {
std::cout << "Invalid header. Mod is " << mod << std::endl; //std::cout << "Invalid header. Mod is " << mod << std::endl;
} }
mFlagCheck = ByteUtils::getLowerNBits(extraFlags, 5); mFlagCheck = ByteUtils::getLowerNBits(extraFlags, 5);
@ -111,7 +111,7 @@ bool ZlibEncoder::encode()
auto compression_info = static_cast<unsigned char>(log2(mWindowSize) - 8); auto compression_info = static_cast<unsigned char>(log2(mWindowSize) - 8);
const unsigned char compression_byte = (compression_info << 4) | static_cast<unsigned char>(mCompressionMethod); const unsigned char compression_byte = (compression_info << 4) | static_cast<unsigned char>(mCompressionMethod);
std::cout << "ZlibEncoder Writing compression byte " << static_cast<int>(compression_byte) << " with info " << static_cast<int>(compression_info) << std::endl; //std::cout << "ZlibEncoder Writing compression byte " << static_cast<int>(compression_byte) << " with info " << static_cast<int>(compression_info) << std::endl;
mOutputStream->writeByte(compression_byte); mOutputStream->writeByte(compression_byte);
unsigned char flag_byte{0}; unsigned char flag_byte{0};
@ -121,7 +121,7 @@ bool ZlibEncoder::encode()
const auto mod = (unsigned(compression_byte)*256 + flag_byte) % 31; const auto mod = (unsigned(compression_byte)*256 + flag_byte) % 31;
flag_byte += (31 - mod); flag_byte += (31 - mod);
std::cout << "ZlibEncoder Writing Flag byte " << static_cast<int>(flag_byte) << std::endl; //std::cout << "ZlibEncoder Writing Flag byte " << static_cast<int>(flag_byte) << std::endl;
mOutputStream->writeByte(flag_byte); mOutputStream->writeByte(flag_byte);
if(!mWorkingEncoder->encode()) if(!mWorkingEncoder->encode())
@ -131,7 +131,7 @@ bool ZlibEncoder::encode()
} }
const auto checksum = mChecksumCalculator->getChecksum(); const auto checksum = mChecksumCalculator->getChecksum();
std::cout << "ZlibEncoder Writing Adler32 Checksum " << checksum << std::endl; //std::cout << "ZlibEncoder Writing Adler32 Checksum " << checksum << std::endl;
mOutputStream->write(checksum); mOutputStream->write(checksum);
return true; return true;
} }
@ -164,7 +164,7 @@ bool ZlibEncoder::decode()
unsigned char byte3 = *mInputStream->readNextByte(); unsigned char byte3 = *mInputStream->readNextByte();
uint32_t adler32 = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3; uint32_t adler32 = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3;
std::cout << "Got adler 32 checksum " << adler32 << std::endl; //std::cout << "Got adler 32 checksum " << adler32 << std::endl;
return valid; return valid;
} }

View file

@ -39,8 +39,8 @@ bool DeflateBlock::read()
{ {
auto working_byte = *mInputStream->readNextByte(); auto working_byte = *mInputStream->readNextByte();
std::cout << mInputStream->logNextNBytes(60); //std::cout << mInputStream->logNextNBytes(60);
std::cout << "DeflateBlock::read location " << mInputStream->logLocation(); //std::cout << "DeflateBlock::read location " << mInputStream->logLocation();
unsigned char final_block{0}; unsigned char final_block{0};
mInputStream->readNextNBits(1, final_block); mInputStream->readNextNBits(1, final_block);
@ -78,8 +78,8 @@ bool DeflateBlock::readUncompressedStream()
auto byte3 = *mInputStream->readNextByte(); auto byte3 = *mInputStream->readNextByte();
uint16_t len_check = (byte2 << 8) | byte3; uint16_t len_check = (byte2 << 8) | byte3;
std::cout << "Check block 2: " << ByteUtils::toString(byte2) << std::endl; //std::cout << "Check block 2: " << ByteUtils::toString(byte2) << std::endl;
std::cout << "Check block 3: " << ByteUtils::toString(byte3) << std::endl; //std::cout << "Check block 3: " << ByteUtils::toString(byte3) << std::endl;
//if (!(byte0 ==(~byte2) && byte1 ==(~byte3))) //if (!(byte0 ==(~byte2) && byte1 ==(~byte3)))
//{ //{
//std::cout << "Uncompressed block length check failed - aborting." << std::endl; //std::cout << "Uncompressed block length check failed - aborting." << std::endl;
@ -97,7 +97,7 @@ bool DeflateBlock::readUncompressedStream()
bool DeflateBlock::readFixedHuffmanStream() bool DeflateBlock::readFixedHuffmanStream()
{ {
std::cout << "Reading fixed huffman stream" << std::endl; //std::cout << "Reading fixed huffman stream" << std::endl;
mHuffmanStream = std::make_unique<HuffmanStream>(mInputStream, mOutputStream); mHuffmanStream = std::make_unique<HuffmanStream>(mInputStream, mOutputStream);
mHuffmanStream->generateFixedCodeMapping(); mHuffmanStream->generateFixedCodeMapping();
@ -139,13 +139,13 @@ void DeflateBlock::write(uint16_t datalength)
void DeflateBlock::writeUncompressedStream(unsigned char working_byte, uint16_t datalength) void DeflateBlock::writeUncompressedStream(unsigned char working_byte, uint16_t datalength)
{ {
std::cout << "Writing compression block header " << ByteUtils::toString(working_byte) << std::endl; //std::cout << "Writing compression block header " << ByteUtils::toString(working_byte) << std::endl;
mOutputStream->writeByte(working_byte); mOutputStream->writeByte(working_byte);
std::cout << "Writing data length " << mUncompressedBlockLength << " " << ByteUtils::toString(mUncompressedBlockLength) << std::endl; //std::cout << "Writing data length " << mUncompressedBlockLength << " " << ByteUtils::toString(mUncompressedBlockLength) << std::endl;
mOutputStream->writeWord(datalength); mOutputStream->writeWord(datalength);
std::cout << "Writing iverse data length " << ~mUncompressedBlockLength << " " << ByteUtils::toString(~mUncompressedBlockLength) << std::endl; //std::cout << "Writing iverse data length " << ~mUncompressedBlockLength << " " << ByteUtils::toString(~mUncompressedBlockLength) << std::endl;
mOutputStream->writeWord(static_cast<uint16_t>(~mUncompressedBlockLength)); mOutputStream->writeWord(static_cast<uint16_t>(~mUncompressedBlockLength));
for(unsigned idx=0; idx<mUncompressedBlockLength;idx++) for(unsigned idx=0; idx<mUncompressedBlockLength;idx++)

View file

@ -28,7 +28,7 @@ bool DeflateEncoder::encode()
AbstractChecksumCalculator* checksum_calc; AbstractChecksumCalculator* checksum_calc;
if (mChecksumCalculators.size() > 0) if (mChecksumCalculators.size() > 0)
{ {
std::cout << "Setting checksum calculator " << std::endl; //std::cout << "Setting checksum calculator " << std::endl;
mOutputStream->setChecksumCalculator(mChecksumCalculators[0]); mOutputStream->setChecksumCalculator(mChecksumCalculators[0]);
} }
@ -36,7 +36,7 @@ bool DeflateEncoder::encode()
{ {
if (count == mMaxBlockSize) if (count == mMaxBlockSize)
{ {
std::cout << working_block->getMetaData(); //std::cout << working_block->getMetaData();
working_block->write(count); working_block->write(count);
working_block = std::make_unique<DeflateBlock>(&stream, mOutputStream); working_block = std::make_unique<DeflateBlock>(&stream, mOutputStream);
@ -46,7 +46,7 @@ bool DeflateEncoder::encode()
if (auto byte = mInputStream->readNextByte()) if (auto byte = mInputStream->readNextByte())
{ {
std::cout << "Adding byte " << ByteUtils::toString(*byte) << " to deflate block input" << std::endl; //std::cout << "Adding byte " << ByteUtils::toString(*byte) << " to deflate block input" << std::endl;
stream.writeByte(*byte); stream.writeByte(*byte);
} }
else else
@ -59,7 +59,7 @@ bool DeflateEncoder::encode()
stream.resetOffsets(); stream.resetOffsets();
working_block->setIsFinalBlock(true); working_block->setIsFinalBlock(true);
std::cout << working_block->getMetaData(); //std::cout << working_block->getMetaData();
working_block->write(count); working_block->write(count);
break; break;
} }
@ -75,7 +75,7 @@ bool DeflateEncoder::decode()
auto working_block = std::make_unique<DeflateBlock>(mInputStream, mOutputStream); auto working_block = std::make_unique<DeflateBlock>(mInputStream, mOutputStream);
working_block->read(); working_block->read();
std::cout << working_block->getMetaData() << std::endl; //std::cout << working_block->getMetaData() << std::endl;
DeflateBlock* raw_block = working_block.get(); DeflateBlock* raw_block = working_block.get();

View file

@ -15,7 +15,7 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
for (const auto& entry : rle_encoded) for (const auto& entry : rle_encoded)
{ {
std::cout << "Got rle " << static_cast<int>(entry.first) << " | " << entry.second << std::endl; //std::cout << "Got rle " << static_cast<int>(entry.first) << " | " << entry.second << std::endl;
} }
mCompressedLengthSequence.clear(); mCompressedLengthSequence.clear();
@ -152,7 +152,7 @@ bool HuffmanCodeLengthTable::readNextSymbol(unsigned& result, BitStream* stream)
} }
else else
{ {
std::cout << "SYMBOL NOT FOUND " << " with bits " << ByteUtils::toString(working_bits) << " and index " << working_index << std::endl; //std::cout << "SYMBOL NOT FOUND " << " with bits " << ByteUtils::toString(working_bits) << " and index " << working_index << std::endl;
return false; return false;
} }
} }
@ -193,7 +193,7 @@ void HuffmanCodeLengthTable::buildPrefixCodes()
} }
} }
mTree.sortTable(); mTree.sortTable();
std::cout << dumpPrefixCodes(); //std::cout << dumpPrefixCodes();
} }
const PrefixCode& HuffmanCodeLengthTable::getCode(std::size_t index) const const PrefixCode& HuffmanCodeLengthTable::getCode(std::size_t index) const

View file

@ -22,18 +22,18 @@ void HuffmanEncoder::dumpNode(RawNode<CountPair>* node, unsigned depth) const
if (node->isLeaf()) if (node->isLeaf())
{ {
std::cout << prefix << "Leaf with value: " << data.first << " and sum " << data.second << std::endl; //std::cout << prefix << "Leaf with value: " << data.first << " and sum " << data.second << std::endl;
} }
else else
{ {
std::cout << prefix << "Intermediate with sum " << data.second << std::endl; //std::cout << prefix << "Intermediate with sum " << data.second << std::endl;
std::cout << prefix << "Doing Left.." << std::endl; //std::cout << prefix << "Doing Left.." << std::endl;
dumpNode(node->getLeftChild(), depth+1); dumpNode(node->getLeftChild(), depth+1);
std::cout << prefix << "Doing Right.." << std::endl; //std::cout << prefix << "Doing Right.." << std::endl;
dumpNode(node->getRightChild(), depth+1); dumpNode(node->getRightChild(), depth+1);
std::cout << prefix << "*****" << std::endl; //std::cout << prefix << "*****" << std::endl;
} }
} }
@ -84,9 +84,9 @@ void HuffmanEncoder::encode(const std::vector<unsigned>& counts)
//using TableEntry = std::tuple<> //using TableEntry = std::tuple<>
dumpTree(tree); //dumpTree(tree);
std::cout << "********" << std::endl; //std::cout << "********" << std::endl;
} }
void HuffmanEncoder::encode(const std::unordered_map<unsigned char, unsigned>& counts) void HuffmanEncoder::encode(const std::unordered_map<unsigned char, unsigned>& counts)
@ -165,7 +165,7 @@ void HuffmanEncoder::initializeLiteralLengthTable(const std::vector<Hit>& hits)
{ {
if (counts[idx]>0) if (counts[idx]>0)
{ {
std::cout << "Count for " << idx << " is " << counts[idx] << std::endl; //std::cout << "Count for " << idx << " is " << counts[idx] << std::endl;
} }
} }

View file

@ -106,7 +106,7 @@ void HuffmanStream::readCodeLengths()
if (!valid) if (!valid)
{ {
std::cout << "Hit unknown symbol - bailing out" << std::endl; //std::cout << "Hit unknown symbol - bailing out" << std::endl;
break; break;
} }
@ -119,7 +119,7 @@ void HuffmanStream::readCodeLengths()
unsigned char num_reps{0}; unsigned char num_reps{0};
mInputStream->readNextNBits(2, num_reps); mInputStream->readNextNBits(2, num_reps);
std::cout << "Got val 16 doing " << 3 + num_reps << std::endl; //std::cout << "Got val 16 doing " << 3 + num_reps << std::endl;
for(unsigned idx=0; idx< 3 + num_reps; idx++) for(unsigned idx=0; idx< 3 + num_reps; idx++)
{ {
addValue(last_value, count, last_value, literal_lengths, mNumLiterals, distance_lengths); addValue(last_value, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
@ -130,7 +130,7 @@ void HuffmanStream::readCodeLengths()
unsigned char num_reps{0}; unsigned char num_reps{0};
mInputStream->readNextNBits(3, num_reps); mInputStream->readNextNBits(3, num_reps);
std::cout << "Got val 17 doing " << 3 + num_reps << std::endl; //std::cout << "Got val 17 doing " << 3 + num_reps << std::endl;
for(unsigned idx=0; idx< 3 + num_reps; idx++) for(unsigned idx=0; idx< 3 + num_reps; idx++)
{ {
addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths); addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
@ -141,7 +141,7 @@ void HuffmanStream::readCodeLengths()
unsigned char num_reps{0}; unsigned char num_reps{0};
mInputStream->readNextNBits(7, num_reps); mInputStream->readNextNBits(7, num_reps);
std::cout << "Got val 18 doing " << 11 + num_reps << std::endl; //std::cout << "Got val 18 doing " << 11 + num_reps << std::endl;
for(unsigned idx=0; idx< 11 + num_reps; idx++) for(unsigned idx=0; idx< 11 + num_reps; idx++)
{ {
addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths); addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
@ -149,19 +149,19 @@ void HuffmanStream::readCodeLengths()
} }
} }
std::cout << "Got final literal length sequence " << std::endl; //std::cout << "Got final literal length sequence " << std::endl;
for(unsigned idx=0; idx<literal_lengths.size(); idx++) for(unsigned idx=0; idx<literal_lengths.size(); idx++)
{ {
std::cout << static_cast<int>(literal_lengths[idx]) << "," ; //std::cout << static_cast<int>(literal_lengths[idx]) << "," ;
} }
std::cout << std::endl; //std::cout << std::endl;
std::cout << "Got final distance length sequence " << std::endl; //std::cout << "Got final distance length sequence " << std::endl;
for(unsigned idx=0; idx<distance_lengths.size(); idx++) for(unsigned idx=0; idx<distance_lengths.size(); idx++)
{ {
std::cout << static_cast<int>(distance_lengths[idx]) << "," ; //std::cout << static_cast<int>(distance_lengths[idx]) << "," ;
} }
std::cout << std::endl; //std::cout << std::endl;
mLiteralTable.setInputLengthSequence(literal_lengths, false); mLiteralTable.setInputLengthSequence(literal_lengths, false);
mLiteralTable.buildPrefixCodes(); mLiteralTable.buildPrefixCodes();
@ -192,11 +192,11 @@ void HuffmanStream::readSymbols()
const auto valid = readNextLiteralSymbol(symbol); const auto valid = readNextLiteralSymbol(symbol);
if (!valid) if (!valid)
{ {
std::cout << "Hit unknown symbol - bailing out" << std::endl; //std::cout << "Hit unknown symbol - bailing out" << std::endl;
break; break;
} }
std::cout << "Got symbol " << symbol << std::endl; //std::cout << "Got symbol " << symbol << std::endl;
if(symbol <= 255) if(symbol <= 255)
{ {
@ -269,7 +269,7 @@ void HuffmanStream::readSymbols()
if (hit_end_stream) if (hit_end_stream)
{ {
std::cout << "Found end of stream ok" << std::endl; //std::cout << "Found end of stream ok" << std::endl;
} }
} }
@ -281,7 +281,7 @@ bool HuffmanStream::decode()
readSymbols(); readSymbols();
std::cout << "Got final buffer size " << mBuffer.size() << std::endl; //std::cout << "Got final buffer size " << mBuffer.size() << std::endl;
for(unsigned idx=0; idx< 100; idx++) for(unsigned idx=0; idx< 100; idx++)
{ {
//std::cout << idx << " | " << mBuffer[idx] << std::endl; //std::cout << idx << " | " << mBuffer[idx] << std::endl;
@ -297,7 +297,7 @@ bool HuffmanStream::decode()
if (!valid) if (!valid)
{ {
std::cout << "Hit unknown symbol - bailing out" << std::endl; //std::cout << "Hit unknown symbol - bailing out" << std::endl;
break; break;
} }
@ -317,25 +317,25 @@ void HuffmanStream::readCodingsTable()
unsigned char h_lit{0}; unsigned char h_lit{0};
mInputStream->readNextNBits(5, h_lit); mInputStream->readNextNBits(5, h_lit);
mNumLiterals = h_lit + 257; mNumLiterals = h_lit + 257;
std::cout << "Got HLIT " << mNumLiterals << std::endl; //std::cout << "Got HLIT " << mNumLiterals << std::endl;
unsigned char h_dist{0}; unsigned char h_dist{0};
mInputStream->readNextNBits(5, h_dist); mInputStream->readNextNBits(5, h_dist);
mNumDistances = h_dist + 1; mNumDistances = h_dist + 1;
std::cout << "Got HDIST " << mNumDistances << std::endl; //std::cout << "Got HDIST " << mNumDistances << std::endl;
unsigned char h_clen{0}; unsigned char h_clen{0};
mInputStream->readNextNBits(4, h_clen); mInputStream->readNextNBits(4, h_clen);
auto num_code_lengths = h_clen + 4; auto num_code_lengths = h_clen + 4;
std::cout << "Got HCLEN " << num_code_lengths << std::endl; //std::cout << "Got HCLEN " << num_code_lengths << std::endl;
auto sequence = std::vector<unsigned char>(num_code_lengths, 0); auto sequence = std::vector<unsigned char>(num_code_lengths, 0);
unsigned char buffer{0}; unsigned char buffer{0};
for(unsigned idx = 0; idx< num_code_lengths; idx++) for(unsigned idx = 0; idx< num_code_lengths; idx++)
{ {
mInputStream->readNextNBits(3, buffer); mInputStream->readNextNBits(3, buffer);
std::cout << "Got coding table value " << idx << " | " << static_cast<int>(buffer) << " | " << ByteUtils::toString(buffer) << std::endl; //std::cout << "Got coding table value " << idx << " | " << static_cast<int>(buffer) << " | " << ByteUtils::toString(buffer) << std::endl;
sequence[idx] = buffer; sequence[idx] = buffer;
} }

View file

@ -36,6 +36,11 @@ void FileLogger::Close()
void FileLogger::LogLine(const std::ostringstream& line) void FileLogger::LogLine(const std::ostringstream& line)
{ {
if (mDisabled)
{
return;
}
if (!mFileStream.is_open()) if (!mFileStream.is_open())
{ {
Open(); Open();
@ -43,8 +48,18 @@ void FileLogger::LogLine(const std::ostringstream& line)
mFileStream << line.str() << std::endl; mFileStream << line.str() << std::endl;
} }
void FileLogger::disable()
{
mDisabled = true;
}
void FileLogger::LogLine(const std::string& logType, const std::ostringstream& line, const std::string& fileName, const std::string& functionName, int lineNumber) void FileLogger::LogLine(const std::string& logType, const std::ostringstream& line, const std::string& fileName, const std::string& functionName, int lineNumber)
{ {
if (mDisabled)
{
return;
}
std::time_t t = std::time(nullptr); std::time_t t = std::time(nullptr);
const std::string cleanedFileName = fileName.substr(fileName.find_last_of("/\\") + 1); const std::string cleanedFileName = fileName.substr(fileName.find_last_of("/\\") + 1);
std::tm time_buf = { 0 }; std::tm time_buf = { 0 };

View file

@ -14,10 +14,6 @@
class FileLogger class FileLogger
{ {
std::string mWorkDirectory;
std::string mFileName;
std::ofstream mFileStream;
FileLogger() FileLogger()
:mWorkDirectory(), :mWorkDirectory(),
mFileName("MT_Log.txt"), mFileName("MT_Log.txt"),
@ -27,7 +23,6 @@ class FileLogger
} }
public: public:
static FileLogger& GetInstance() static FileLogger& GetInstance()
{ {
static FileLogger instance; static FileLogger instance;
@ -39,6 +34,8 @@ public:
~FileLogger(); ~FileLogger();
void disable();
void SetWorkDirectory(const std::string& workDir); void SetWorkDirectory(const std::string& workDir);
void SetFileName(const std::string& fileName); void SetFileName(const std::string& fileName);
@ -50,7 +47,11 @@ public:
void LogLine(const std::ostringstream& line); void LogLine(const std::ostringstream& line);
void LogLine(const std::string& logType, const std::ostringstream& line, const std::string& fileName = "", const std::string& functionName = "", int lineNumber=-1); void LogLine(const std::string& logType, const std::ostringstream& line, const std::string& fileName = "", const std::string& functionName = "", int lineNumber=-1);
private:
bool mDisabled{false};
std::string mWorkDirectory;
std::string mFileName;
std::ofstream mFileStream;
}; };
using FileLoggerPtr = std::shared_ptr<FileLogger>; using FileLoggerPtr = std::shared_ptr<FileLogger>;

View file

@ -10,9 +10,11 @@ list(APPEND database_LIB_INCLUDES
add_library(database SHARED ${database_LIB_INCLUDES}) add_library(database SHARED ${database_LIB_INCLUDES})
target_include_directories(database PUBLIC target_include_directories(database PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/database_interfaces" ${CMAKE_CURRENT_SOURCE_DIR}/database_interfaces
"${SQLite3_INCLUDE_DIR}" ${SQLite3_INCLUDE_DIR}
) )
target_link_libraries(database core)
set_property(TARGET database PROPERTY FOLDER src) set_property(TARGET database PROPERTY FOLDER src)
set_target_properties( database PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) set_target_properties( database PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )

View file

@ -1,6 +1,6 @@
#include "SqliteInterface.h" #include "SqliteInterface.h"
#include <iostream> #include "FileLogger.h"
SqliteInterface::SqliteInterface() SqliteInterface::SqliteInterface()
: mSqliteDb(nullptr) : mSqliteDb(nullptr)
@ -23,7 +23,7 @@ void SqliteInterface::Open(const DatabasePtr& db)
int rc = sqlite3_open(db->GetPath().c_str(), &mSqliteDb); int rc = sqlite3_open(db->GetPath().c_str(), &mSqliteDb);
if( rc ) if( rc )
{ {
std::cout << "Can't open database: %s\n" << sqlite3_errmsg(mSqliteDb) << std::endl; MLOG_ERROR("Can't open database: %s\n" << sqlite3_errmsg(mSqliteDb));
sqlite3_close(mSqliteDb); sqlite3_close(mSqliteDb);
} }
} }
@ -34,7 +34,7 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{ {
//std::cout << "%s = %s\n" << azColName[i] << argv[i] ? argv[i] : "NULL" << std::endl; //std::cout << "%s = %s\n" << azColName[i] << argv[i] ? argv[i] : "NULL" << std::endl;
std::cout << "NULL" << std::endl; MLOG_ERROR("NULL");
} }
return 0; return 0;
} }
@ -45,7 +45,7 @@ void SqliteInterface::Run(const std::string& statement)
int rc = sqlite3_exec(mSqliteDb, statement.c_str(), callback, 0, &zErrMsg); int rc = sqlite3_exec(mSqliteDb, statement.c_str(), callback, 0, &zErrMsg);
if (rc != SQLITE_OK) if (rc != SQLITE_OK)
{ {
std::cout << "SQL error: %s\n" << zErrMsg << std::endl; MLOG_ERROR("SQL error: %s\n" << zErrMsg);
sqlite3_free(zErrMsg); sqlite3_free(zErrMsg);
} }
} }

View file

@ -4,7 +4,7 @@
#include "File.h" #include "File.h"
#include "BinaryStream.h" #include "BinaryStream.h"
#include <iostream> //#include <iostream>
#include <sstream> #include <sstream>
FontReader::~FontReader() FontReader::~FontReader()
@ -51,7 +51,7 @@ void FontReader::logOffsetSubtable()
sstr << "range_shift: " << mOffsetSubtable.range_shift << "\n"; sstr << "range_shift: " << mOffsetSubtable.range_shift << "\n";
sstr << "************\n"; sstr << "************\n";
std::cout << sstr.str() << std::endl; //std::cout << sstr.str() << std::endl;
} }
void FontReader::readTableDirectory() void FontReader::readTableDirectory()
@ -89,7 +89,7 @@ void FontReader::logTable(const Table& table)
sstr << "length: " << table.length << "\n"; sstr << "length: " << table.length << "\n";
sstr << "************\n"; sstr << "************\n";
std::cout << sstr.str() << std::endl; //std::cout << sstr.str() << std::endl;
} }
void FontReader::readTable() void FontReader::readTable()
@ -113,7 +113,7 @@ void FontReader::readTable()
void FontReader::readHeadTable() void FontReader::readHeadTable()
{ {
std::cout << "Reading head table" << std::endl; //std::cout << "Reading head table" << std::endl;
TrueTypeFont::HeadTable table; TrueTypeFont::HeadTable table;
@ -145,7 +145,7 @@ void FontReader::readHeadTable()
auto working_ttf_font = dynamic_cast<TrueTypeFont*>(mWorkingFont.get()); auto working_ttf_font = dynamic_cast<TrueTypeFont*>(mWorkingFont.get());
working_ttf_font->setHeadTable(table); working_ttf_font->setHeadTable(table);
std::cout << working_ttf_font->logHeadTable() << std::endl; //std::cout << working_ttf_font->logHeadTable() << std::endl;
} }
@ -157,17 +157,17 @@ std::unique_ptr<IFont> FontReader::read()
mFile->Open(true); mFile->Open(true);
readOffsetSubtable(); readOffsetSubtable();
std::cout << "Current offset: " << mCurrentOffset << std::endl; //std::cout << "Current offset: " << mCurrentOffset << std::endl;
logOffsetSubtable(); logOffsetSubtable();
readTableDirectory(); readTableDirectory();
std::cout << "Current offset: " << mCurrentOffset << std::endl; //std::cout << "Current offset: " << mCurrentOffset << std::endl;
for (unsigned idx=0; idx<mOffsetSubtable.num_tables; idx++) for (unsigned idx=0; idx<mOffsetSubtable.num_tables; idx++)
{ {
readTable(); readTable();
std::cout << "Current offset: " << mCurrentOffset << std::endl; //std::cout << "Current offset: " << mCurrentOffset << std::endl;
break; break;
} }

View file

@ -6,6 +6,8 @@
#include "BasicFontEngine.h" #include "BasicFontEngine.h"
#endif #endif
#include "FontGlyph.h"
FontsManager::FontsManager() FontsManager::FontsManager()
{ {

View file

@ -43,7 +43,7 @@ public:
void dumpInfo() override void dumpInfo() override
{ {
std::cout << "Got ttf" << std::endl; //std::cout << "Got ttf" << std::endl;
} }
private: private:

View file

@ -56,7 +56,7 @@ bool PngReader::readChunk()
std::string chunkType; std::string chunkType;
BinaryStream::getNextString(mFile->GetInHandle(), chunkType, 4); BinaryStream::getNextString(mFile->GetInHandle(), chunkType, 4);
std::cout << "Got chunk with type: " << chunkType << " and length: " << length << std::endl; //std::cout << "Got chunk with type: " << chunkType << " and length: " << length << std::endl;
bool lastChunk = false; bool lastChunk = false;
if (chunkType == "IHDR") if (chunkType == "IHDR")
{ {
@ -118,10 +118,10 @@ bool PngReader::readHeaderChunk()
uint32_t file_crc = *BinaryStream::getNextDWord(mFile->GetInHandle()); uint32_t file_crc = *BinaryStream::getNextDWord(mFile->GetInHandle());
auto crc_calc = mHeader.getCrc(); auto crc_calc = mHeader.getCrc();
std::cout << mHeader.toString() << "*************\n"; //std::cout << mHeader.toString() << "*************\n";
if (file_crc != crc_calc) if (file_crc != crc_calc)
{ {
std::cout << "Header crc calc does not match file value. File: " << file_crc << " Header: " << crc_calc << std::endl;; //std::cout << "Header crc calc does not match file value. File: " << file_crc << " Header: " << crc_calc << std::endl;;
return false; return false;
} }
else else
@ -152,7 +152,7 @@ bool PngReader::readIDATChunk(unsigned length)
if (file_crc != crc_calc) if (file_crc != crc_calc)
{ {
std::cout << "IDAT crc calc does not match file value. File: " << file_crc << " Header: " << crc_calc << std::endl;; //std::cout << "IDAT crc calc does not match file value. File: " << file_crc << " Header: " << crc_calc << std::endl;;
return false; return false;
} }
else else
@ -170,7 +170,7 @@ std::unique_ptr<Image<unsigned char> > PngReader::read()
if (!checkSignature()) if (!checkSignature())
{ {
std::cout << "Signature check failed" << std::endl; //std::cout << "Signature check failed" << std::endl;
return image; return image;
} }
@ -199,5 +199,5 @@ std::unique_ptr<Image<unsigned char> > PngReader::read()
void PngReader::decodeData() void PngReader::decodeData()
{ {
mEncoder->decode(); mEncoder->decode();
std::cout << mEncoder->getData() << "***********" << std::endl; //std::cout << mEncoder->getData() << "***********" << std::endl;
} }

View file

@ -91,13 +91,13 @@ void PngWriter::writeHeader()
auto crc = mPngHeader.getCrc(); auto crc = mPngHeader.getCrc();
std::cout << mPngHeader.toString() << "*********" << std::endl; //std::cout << mPngHeader.toString() << "*********" << std::endl;
mOutStream->write(crc); mOutStream->write(crc);
} }
void PngWriter::writeEndChunk() void PngWriter::writeEndChunk()
{ {
std::cout << "Start writing end chunk" << std::endl; //std::cout << "Start writing end chunk" << std::endl;
unsigned length{0}; unsigned length{0};
mOutStream->write(length); mOutStream->write(length);
@ -112,7 +112,7 @@ void PngWriter::writeEndChunk()
auto crc = crc_check.getChecksum(); auto crc = crc_check.getChecksum();
mOutStream->write(crc); mOutStream->write(crc);
std::cout << "Writing end chunk" << std::endl; //std::cout << "Writing end chunk" << std::endl;
} }
void PngWriter::writeDataChunks(const BufferBitStream& buffer) void PngWriter::writeDataChunks(const BufferBitStream& buffer)
@ -130,7 +130,7 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
length = num_bytes - num_dat_chunks*num_bytes; length = num_bytes - num_dat_chunks*num_bytes;
} }
std::cout << "Writing idat length " << num_bytes << std::endl; //std::cout << "Writing idat length " << num_bytes << std::endl;
mOutStream->write(num_bytes); mOutStream->write(num_bytes);
std::vector<unsigned char> char_data = StringUtils::toBytes("IDAT"); std::vector<unsigned char> char_data = StringUtils::toBytes("IDAT");
@ -150,9 +150,9 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
} }
auto crc = crc_check.getChecksum(); auto crc = crc_check.getChecksum();
std::cout << "Writing idat crc" << crc << std::endl; //std::cout << "Writing idat crc" << crc << std::endl;
mOutStream->write(crc); mOutStream->write(crc);
std::cout << "Finished Writing idat crc" << crc << std::endl; //std::cout << "Finished Writing idat crc" << crc << std::endl;
} }
} }

View file

@ -107,7 +107,7 @@ std::unique_ptr<TriMesh> MeshPrimitives::buildRoundedRectangleAsTriMesh(double r
// Inner rect edges // Inner rect edges
unsigned edge_offset = num_edges_per_fan*num_fans; unsigned edge_offset = num_edges_per_fan*num_fans;
return nullptr;
} }
std::unique_ptr<LineMesh> MeshPrimitives::buildRectangleAsLineMesh() std::unique_ptr<LineMesh> MeshPrimitives::buildRectangleAsLineMesh()

View file

@ -31,7 +31,6 @@ void NetworkManager::Initialize()
void NetworkManager::RunHttpServer() void NetworkManager::RunHttpServer()
{ {
std::cout << "Running http server" << std::endl;
if (!mSocketInterface) if (!mSocketInterface)
{ {
Initialize(); Initialize();
@ -45,7 +44,6 @@ void NetworkManager::RunHttpServer()
void NetworkManager::RunHttpClient() void NetworkManager::RunHttpClient()
{ {
std::cout << "Running http client" << std::endl;
if (!mSocketInterface) if (!mSocketInterface)
{ {
Initialize(); Initialize();

View file

@ -1,9 +1,10 @@
#include "UnixSocketInterface.h" #include "UnixSocketInterface.h"
#include "HttpResponse.h" #include "HttpResponse.h"
#include "HttpMessageHandler.h" #include "HttpMessageHandler.h"
#include "FileLogger.h"
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -43,7 +44,7 @@ void UnixSocketInterface::Write(const SocketPtr& socket, const std::string& mess
{ {
if(socket->GetHandle() < 0) if(socket->GetHandle() < 0)
{ {
std::cerr << "Error opening socket" << std::endl; MLOG_ERROR("Error opening socket" );
return; return;
} }
@ -58,7 +59,7 @@ void UnixSocketInterface::Write(const SocketPtr& socket, const std::string& mess
int result = connect(socket->GetHandle(), (struct sockaddr *)&serv_addr, sizeof(serv_addr)); int result = connect(socket->GetHandle(), (struct sockaddr *)&serv_addr, sizeof(serv_addr));
if(result< 0) if(result< 0)
{ {
std::cerr << "Error connecting to socket" << std::endl; MLOG_ERROR("Error connecting to socket" );
return; return;
} }

View file

@ -1,76 +1,27 @@
add_library(test_utils STATIC add_subdirectory(test_utils)
test_utils/TestCase.h
test_utils/TestCaseRunner.cpp
)
target_include_directories(test_utils PUBLIC set(TEST_MODULES
"${CMAKE_CURRENT_SOURCE_DIR}/test_utils" audio
) compiler
compression
core
database
fonts
graphics
image
ipc
network
publishing
video
web
windows)
list(APPEND TestFiles foreach(module ${TEST_MODULES})
audio/TestAudioWriter.cpp add_subdirectory(${module})
audio/TestMidiReader.cpp string(TOUPPER ${module} MODULE_UPPER)
compiler/TestTemplatingEngine.cpp list(APPEND UNIT_TEST_FILES ${${MODULE_UPPER}_UNIT_TEST_FILES})
compression/TestStreamCompressor.cpp list(APPEND UNIT_TEST_DEPENDENCIES ${${MODULE_UPPER}_UNIT_TEST_DEPENDENCIES})
compression/TestHuffmanStream.cpp endforeach()
compression/TestLz77Encoder.cpp
core/TestByteUtils.cpp
core/TestBitStream.cpp
core/TestTomlReader.cpp
core/TestDataStructures.cpp
database/TestDatabase.cpp
fonts/TestFontReader.cpp
graphics/TestRasterizer.cpp
image/TestPngReader.cpp
image/TestPngWriter.cpp
network/TestNetworkManagerClient.cpp
network/TestNetworkManagerServer.cpp
publishing/TestPdfWriter.cpp
web/TestMarkdownParser.cpp
web/TestXmlParser.cpp
)
if (${HAS_FFMPEG})
list(APPEND TestFiles
video/TestVideoDecoder.cpp
)
endif()
find_package(Wayland QUIET) add_executable(unit_tests test_runner.cpp ${UNIT_TEST_FILES})
if(WAYLAND_FOUND) target_link_libraries(unit_tests PUBLIC test_utils ${UNIT_TEST_DEPENDENCIES})
list(APPEND TestFiles
windows/TestWaylandWindow.cpp
)
endif()
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL QUIET)
if (OpenGL_FOUND)
list(APPEND TestFiles
graphics/TestOpenGlRendering.cpp
)
endif()
find_package(PkgConfig)
pkg_check_modules(DBUS dbus-1 QUIET)
if (DBUS_FOUND)
include_directories(${DBUS_INCLUDE_DIRS})
link_directories(${DBUS_LIBRARY_DIRS})
list(APPEND TestFiles
ipc/TestDbus.cpp
)
endif()
if(UNIX)
find_package(Freetype QUIET)
if(Freetype_FOUND)
list(APPEND TestFiles
fonts/TestFreeTypeFontEngine.cpp
)
endif()
endif()
add_executable(test_runner test_runner.cpp ${TestFiles})
target_link_libraries(test_runner PUBLIC test_utils publishing core compiler fonts network database geometry audio graphics web client)

10
test/audio/CMakeLists.txt Normal file
View file

@ -0,0 +1,10 @@
set(AUDIO_UNIT_TEST_FILES
audio/TestAudioWriter.cpp
audio/TestMidiReader.cpp
PARENT_SCOPE
)
set(AUDIO_UNIT_TEST_DEPENDENCIES
audio
PARENT_SCOPE
)

View file

@ -0,0 +1,9 @@
set(COMPILER_UNIT_TEST_FILES
compiler/TestTemplatingEngine.cpp
PARENT_SCOPE
)
set(COMPILER_UNIT_TEST_DEPENDENCIES
compiler
PARENT_SCOPE
)

View file

@ -1,6 +1,6 @@
#include "TemplatingEngine.h" #include "TemplatingEngine.h"
#include <File.h> #include "File.h"
#include "TestFramework.h" #include "TestFramework.h"
#include <filesystem> #include <filesystem>
@ -8,12 +8,12 @@
TEST_CASE(TestTemplatingEngine, "compiler") TEST_CASE(TestTemplatingEngine, "compiler")
{ {
const auto data_loc = std::filesystem::path(__FILE__) / "../../data"; const auto data_loc = std::filesystem::path(__FILE__) / "../../data";
auto engine = TemplatingEngine(data_loc); auto engine = TemplatingEngine(data_loc);
engine.loadTemplateFiles(); engine.loadTemplateFiles();
const auto content = engine.processTemplate("index"); const auto content = engine.processTemplate("index");
File outfile("index.html"); File outfile("index.html");
outfile.WriteText(content); outfile.WriteText(content);
} }

View file

@ -0,0 +1,11 @@
set(COMPRESSION_UNIT_TEST_FILES
compression/TestStreamCompressor.cpp
compression/TestHuffmanStream.cpp
compression/TestLz77Encoder.cpp
PARENT_SCOPE
)
set(COMPRESSION_UNIT_TEST_DEPENDENCIES
compression
PARENT_SCOPE
)

View file

@ -28,7 +28,7 @@ TEST_CASE(TestLz77Encoder, "compression")
for(const auto& hit : hit_buffer) for(const auto& hit : hit_buffer)
{ {
const auto& [length, distance, next_char] = hit; const auto& [length, distance, next_char] = hit;
std::cout << "Got hit " << length << " | " << distance << " | " << static_cast<int>(next_char) << std::endl; //std::cout << "Got hit " << length << " | " << distance << " | " << static_cast<int>(next_char) << std::endl;
} }
HuffmanEncoder huffman_encoder; HuffmanEncoder huffman_encoder;

View file

@ -54,7 +54,7 @@ TEST_CASE(TestLz77Encoder, "compression")
Lz77Encoder encoder(&input_stream, &output_stream); Lz77Encoder encoder(&input_stream, &output_stream);
encoder.encode(); encoder.encode();
std::cout << "Encoded: " << StringUtils::toString(output_stream.getBuffer()) << std::endl; //std::cout << "Encoded: " << StringUtils::toString(output_stream.getBuffer()) << std::endl;
//auto decoded = encoder.decode(encoded); //auto decoded = encoder.decode(encoded);

12
test/core/CMakeLists.txt Normal file
View file

@ -0,0 +1,12 @@
set(CORE_UNIT_TEST_FILES
core/TestByteUtils.cpp
core/TestBitStream.cpp
core/TestTomlReader.cpp
core/TestDataStructures.cpp
PARENT_SCOPE
)
set(CORE_UNIT_TEST_DEPENDENCIES
core
PARENT_SCOPE
)

View file

@ -21,22 +21,22 @@ TEST_CASE(TestReadBitStream, "core")
unsigned char buffer{0} ; unsigned char buffer{0} ;
auto valid = stream.readNextNBits(1, buffer); auto valid = stream.readNextNBits(1, buffer);
std::cout << "Slice0 is " << ByteUtils::toString(buffer) << std::endl; //std::cout << "Slice0 is " << ByteUtils::toString(buffer) << std::endl;
valid = stream.readNextNBits(2, buffer); valid = stream.readNextNBits(2, buffer);
std::cout << "Slice1 is " << ByteUtils::toString(buffer) << std::endl; //std::cout << "Slice1 is " << ByteUtils::toString(buffer) << std::endl;
valid = stream.readNextNBits(5, buffer); valid = stream.readNextNBits(5, buffer);
std::cout << "Slice2 is " << ByteUtils::toString(buffer) << std::endl; //std::cout << "Slice2 is " << ByteUtils::toString(buffer) << std::endl;
valid = stream.readNextNBits(5, buffer); valid = stream.readNextNBits(5, buffer);
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl; //std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
valid = stream.readNextNBits(4, buffer); valid = stream.readNextNBits(4, buffer);
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << " and int " << static_cast<int>(buffer) << std::endl; //std::cout << "Slice3 is " << ByteUtils::toString(buffer) << " and int " << static_cast<int>(buffer) << std::endl;
valid = stream.readNextNBits(3, buffer); valid = stream.readNextNBits(3, buffer);
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl; //std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
} }
TEST_CASE(TestWritingBitStream, "core") TEST_CASE(TestWritingBitStream, "core")
@ -68,9 +68,9 @@ TEST_CASE(TestWritingBitStream, "core")
auto byte3 = ByteUtils::toString(*stream.readNextByte()); auto byte3 = ByteUtils::toString(*stream.readNextByte());
auto byte4 = ByteUtils::toString(*stream.readNextByte()); auto byte4 = ByteUtils::toString(*stream.readNextByte());
std::cout << "Got bytes 0 " << byte0 << std::endl; //std::cout << "Got bytes 0 " << byte0 << std::endl;
std::cout << "Got bytes 1 " << byte1 << std::endl; //std::cout << "Got bytes 1 " << byte1 << std::endl;
std::cout << "Got bytes 2 " << byte2 << std::endl; //std::cout << "Got bytes 2 " << byte2 << std::endl;
std::cout << "Got bytes 3 " << byte3 << std::endl; //std::cout << "Got bytes 3 " << byte3 << std::endl;
std::cout << "Got bytes 4 " << byte4 << std::endl; //std::cout << "Got bytes 4 " << byte4 << std::endl;
} }

View file

@ -7,13 +7,13 @@
TEST_CASE(TestReadByteUtils, "core") TEST_CASE(TestReadByteUtils, "core")
{ {
auto byte = ByteUtils::getFromString("00110101"); auto byte = ByteUtils::getFromString("00110101");
std::cout << "Value is " << static_cast<unsigned>(byte) << std::endl; //std::cout << "Value is " << static_cast<unsigned>(byte) << std::endl;
auto string_rep = ByteUtils::toString(byte); auto string_rep = ByteUtils::toString(byte);
std::cout << "String rep is " << string_rep << std::endl; //std::cout << "String rep is " << string_rep << std::endl;
auto slice = ByteUtils::getMBitsAtN(byte, 3, 3); auto slice = ByteUtils::getMBitsAtN(byte, 3, 3);
std::cout << "Slice is " << ByteUtils::toString(slice) << std::endl; //std::cout << "Slice is " << ByteUtils::toString(slice) << std::endl;
uint32_t input {12345678}; uint32_t input {12345678};
auto byte0 = ByteUtils::getByteN(input, 0); auto byte0 = ByteUtils::getByteN(input, 0);
@ -21,17 +21,17 @@ TEST_CASE(TestReadByteUtils, "core")
auto byte2 = ByteUtils::getByteN(input, 2); auto byte2 = ByteUtils::getByteN(input, 2);
auto byte3 = ByteUtils::getByteN(input, 3); auto byte3 = ByteUtils::getByteN(input, 3);
std::cout << "Byte0 is " << ByteUtils::toString(byte0) << std::endl; //std::cout << "Byte0 is " << ByteUtils::toString(byte0) << std::endl;
std::cout << "Byte1 is " << ByteUtils::toString(byte1) << std::endl; //std::cout << "Byte1 is " << ByteUtils::toString(byte1) << std::endl;
std::cout << "Byte2 is " << ByteUtils::toString(byte2) << std::endl; //std::cout << "Byte2 is " << ByteUtils::toString(byte2) << std::endl;
std::cout << "Byte3 is " << ByteUtils::toString(byte3) << std::endl; //std::cout << "Byte3 is " << ByteUtils::toString(byte3) << std::endl;
std::cout << "Mirroring" << std::endl; //std::cout << "Mirroring" << std::endl;
auto out = ByteUtils::mirror(byte); auto out = ByteUtils::mirror(byte);
std::cout << "Mirror is " << ByteUtils::toString(out) << std::endl; //std::cout << "Mirror is " << ByteUtils::toString(out) << std::endl;
unsigned hold = byte; unsigned hold = byte;
hold = (hold << 5) + 3; hold = (hold << 5) + 3;
std::cout << "Big val is " << ByteUtils::toString(hold, 16) << std::endl; //std::cout << "Big val is " << ByteUtils::toString(hold, 16) << std::endl;
} }

View file

@ -10,25 +10,25 @@ TEST_CASE(TestCircleBuffer, "core")
for (auto item : {1, 2, 3}) for (auto item : {1, 2, 3})
{ {
std::cout << "Add item: " << item << std::endl; //std::cout << "Add item: " << item << std::endl;
buffer.addItem(item); buffer.addItem(item);
} }
for (std::size_t idx=0; idx<3; idx++) for (std::size_t idx=0; idx<3; idx++)
{ {
auto item = buffer.getItem(idx); auto item = buffer.getItem(idx);
std::cout << "Got item: " << idx << " " << item << std::endl; //std::cout << "Got item: " << idx << " " << item << std::endl;
} }
for (auto item : {4, 5}) for (auto item : {4, 5})
{ {
std::cout << "Add item: " << item << std::endl; //std::cout << "Add item: " << item << std::endl;
buffer.addItem(item); //buffer.addItem(item);
} }
for (std::size_t idx=0; idx<3; idx++) for (std::size_t idx=0; idx<3; idx++)
{ {
auto item = buffer.getItem(idx); auto item = buffer.getItem(idx);
std::cout << "Got item: " << idx << " " << item << std::endl; //std::cout << "Got item: " << idx << " " << item << std::endl;
} }
} }

View file

@ -14,6 +14,9 @@ TEST_CASE(TestTomlReader, "core")
reader.read(sample_toml_file); reader.read(sample_toml_file);
auto themes_table = reader.getContent()->getTable("themes"); auto themes_table = reader.getContent()->getTable("themes");
REQUIRE(themes_table);
for (const auto& items : themes_table->getKeyValuePairs()) for (const auto& items : themes_table->getKeyValuePairs())
{ {
std::cout << "Got entry with key: " << items.first << " and val " << items.second << std::endl; std::cout << "Got entry with key: " << items.first << " and val " << items.second << std::endl;

View file

@ -0,0 +1,9 @@
set(DATABASE_UNIT_TEST_FILES
database/TestDatabase.cpp
PARENT_SCOPE
)
set(DATABASE_UNIT_TEST_DEPENDENCIES
database
PARENT_SCOPE
)

22
test/fonts/CMakeLists.txt Normal file
View file

@ -0,0 +1,22 @@
set(PLATFORM_UNIT_TEST_FILES)
if(UNIX)
find_package(Freetype QUIET)
if(Freetype_FOUND)
set(PLATFORM_UNIT_TEST_FILES
fonts/TestFreeTypeFontEngine.cpp
)
endif()
endif()
set(FONTS_UNIT_TEST_FILES
fonts/TestFontReader.cpp
${PLATFORM_UNIT_TEST_FILES}
PARENT_SCOPE
)
set(FONTS_UNIT_TEST_DEPENDENCIES
fonts
PARENT_SCOPE
)

View file

@ -0,0 +1,20 @@
set(PLATFORM_UNIT_TEST_FILES)
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL QUIET)
if (OpenGL_FOUND)
set(PLATFORM_UNIT_TEST_FILES
graphics/TestOpenGlRendering.cpp
)
endif()
set(GRAPHICS_UNIT_TEST_FILES
graphics/TestRasterizer.cpp
${PLATFORM_UNIT_TEST_FILES}
PARENT_SCOPE
)
set(GRAPHICS_UNIT_TEST_DEPENDENCIES
graphics client
PARENT_SCOPE
)

View file

@ -15,5 +15,7 @@ TEST_CASE(TestOpenGlRendering, "graphics")
app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11); app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11);
//app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER); //app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER);
app->run();
//app->run();
}; };

10
test/image/CMakeLists.txt Normal file
View file

@ -0,0 +1,10 @@
set(IMAGE_UNIT_TEST_FILES
image/TestPngReader.cpp
image/TestPngWriter.cpp
PARENT_SCOPE
)
set(IMAGE_UNIT_TEST_DEPENDENCIES
image
PARENT_SCOPE
)

View file

@ -40,7 +40,7 @@ TEST_CASE(TestCompressedPng, "image")
while(auto byte = test_file.readNextByte()) while(auto byte = test_file.readNextByte())
{ {
std::cout << static_cast<unsigned>(*byte) << std::endl; //std::cout << static_cast<unsigned>(*byte) << std::endl;
} }
test_file.Close(); test_file.Close();
} }
@ -71,7 +71,7 @@ TEST_CASE(TestFixedPng, "image")
//return; //return;
File test_file("test_fixed.png"); File test_file("test_fixed.png");
std::cout << test_file.dumpBinary(); //std::cout << test_file.dumpBinary();
} }
@ -100,5 +100,5 @@ TEST_CASE(TestDynamicCompressedPng, "image")
//return; //return;
File test_file("test_dynamic.png"); File test_file("test_dynamic.png");
std::cout << test_file.dumpBinary(); //std::cout << test_file.dumpBinary();
} }

20
test/ipc/CMakeLists.txt Normal file
View file

@ -0,0 +1,20 @@
set(PLATFORM_UNIT_TEST_FILES)
find_package(PkgConfig)
pkg_check_modules(DBUS dbus-1 QUIET)
if (DBUS_FOUND)
include_directories(${DBUS_INCLUDE_DIRS})
link_directories(${DBUS_LIBRARY_DIRS})
set(PLATFORM_UNIT_TEST_FILES
ipc/TestDbus.cpp
)
endif()
set(IPC_UNIT_TEST_FILES
${PLATFORM_UNIT_TEST_FILES}
PARENT_SCOPE
)
set(IPC_UNIT_TEST_DEPENDENCIES
PARENT_SCOPE
)

View file

@ -0,0 +1,10 @@
set(NETWORK_UNIT_TEST_FILES
network/TestNetworkManagerClient.cpp
network/TestNetworkManagerServer.cpp
PARENT_SCOPE
)
set(NETWORK_UNIT_TEST_DEPENDENCIES
network
PARENT_SCOPE
)

View file

@ -6,7 +6,6 @@
TEST_CASE(TestNetworkManagerClient, "network") TEST_CASE(TestNetworkManagerClient, "network")
{ {
std::cout << "into main" << std::endl;
auto network_manager = NetworkManager::Create(); auto network_manager = NetworkManager::Create();
network_manager->RunHttpClient(); network_manager->RunHttpClient();

View file

@ -2,12 +2,9 @@
#include "TestFramework.h" #include "TestFramework.h"
#include <iostream>
TEST_CASE(TestNetworkManagerServer, "network") TEST_CASE(TestNetworkManagerServer, "network")
{ {
std::cout << "into main" << std::endl;
auto network_manager = NetworkManager::Create(); auto network_manager = NetworkManager::Create();
network_manager->RunHttpServer(); //network_manager->RunHttpServer();
} }

View file

@ -0,0 +1,9 @@
set(PUBLISHING_UNIT_TEST_FILES
publishing/TestPdfWriter.cpp
PARENT_SCOPE
)
set(PUBLISHING_UNIT_TEST_DEPENDENCIES
publishing
PARENT_SCOPE
)

View file

@ -11,8 +11,7 @@ int main()
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
#endif #endif
auto test_runner = TestCaseRunner::getInstance(); auto result = TestCaseRunner::getInstance().run();
test_runner.run();
#ifdef _WIN32 #ifdef _WIN32
CoUninitialize(); CoUninitialize();

View file

@ -0,0 +1,9 @@
add_library(test_utils SHARED
TestCase.h
TestCaseRunner.cpp
)
target_include_directories(test_utils PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(test_utils core)

View file

@ -1,14 +1,27 @@
#include "TestCaseRunner.h" #include "TestCaseRunner.h"
#include "FileLogger.h"
#include <vector> #include <vector>
#include <iostream> #include <iostream>
bool TestCaseRunner::sLastTestFailed = false;
std::string TestCaseRunner::sFailureLine = {};
TestCaseRunner::TestCaseRunner()
{
}
TestCaseRunner::~TestCaseRunner() TestCaseRunner::~TestCaseRunner()
{ {
for (auto testCase : mCases)
{ }
//delete testCase;
} TestCaseRunner& TestCaseRunner::getInstance()
{
static TestCaseRunner instance;
return instance;
} }
void TestCaseRunner::addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func) void TestCaseRunner::addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func)
@ -17,28 +30,35 @@ void TestCaseRunner::addTestCase(const std::string& label, const std::string& ta
mCases.push_back(test_case); mCases.push_back(test_case);
} }
void TestCaseRunner::markTestFailure(const std::string& line)
{
sLastTestFailed = true;
sFailureLine = line;
}
bool TestCaseRunner::run() bool TestCaseRunner::run()
{ {
FileLogger::GetInstance().disable();
for (auto test_case : mCases) for (auto test_case : mCases)
{ {
sLastTestFailed = false;
std::cout << "TestFramework: Running Test - " << test_case->getName() << std::endl; std::cout << "TestFramework: Running Test - " << test_case->getName() << std::endl;
test_case->run(); test_case->run();
} if (sLastTestFailed)
bool testsPassed = true;
/*
for(const auto& test : mCases)
{
std::cout << "Running " << test->getName() << std::endl;
const auto result = test->Run();
if (!result)
{ {
std::cout << test->getName() << " Failed" << std::endl; std::cout << "Failed at line: " << sLastTestFailed << std::endl;
testsPassed = false; mFailingTests.push_back(test_case->getName());
break;
} }
} }
return testsPassed;
*/ if (mFailingTests.size() > 0)
{
std::cout << mFailingTests.size() << " failing tests: " << std::endl;
for(const auto& name : mFailingTests)
{
std::cout << name << std::endl;
}
}
return true; return true;
} }

View file

@ -8,20 +8,21 @@
class TestCaseRunner class TestCaseRunner
{ {
public: public:
TestCaseRunner() = default; TestCaseRunner();
static TestCaseRunner& getInstance() static TestCaseRunner& getInstance();
{
static TestCaseRunner instance;
return instance;
}
~TestCaseRunner(); ~TestCaseRunner();
void addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func); void addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func);
void markTestFailure(const std::string& line);
bool run(); bool run();
private: private:
std::vector<std::string> mFailingTests;
static bool sLastTestFailed;
static std::string sFailureLine;
std::vector<TestCase*> mCases; std::vector<TestCase*> mCases;
}; };

View file

@ -16,3 +16,13 @@ struct Holder
static void Test##NAME() \ static void Test##NAME() \
#define REQUIRE(predicate) \
if(!predicate) \
{ \
TestCaseRunner::getInstance().markTestFailure(std::to_string(__LINE__)); \
return; \
} \

17
test/video/CMakeLists.txt Normal file
View file

@ -0,0 +1,17 @@
set(PLATFORM_UNIT_TEST_FILES)
if (${HAS_FFMPEG})
set(PLATFORM_UNIT_TEST_FILES
video/TestVideoDecoder.cpp
)
endif()
set(VIDEO_UNIT_TEST_FILES
${PLATFORM_UNIT_TEST_FILES}
PARENT_SCOPE
)
set(VIDEO_UNIT_TEST_DEPENDENCIES
video
PARENT_SCOPE
)

10
test/web/CMakeLists.txt Normal file
View file

@ -0,0 +1,10 @@
set(WEB_UNIT_TEST_FILES
web/TestMarkdownParser.cpp
web/TestXmlParser.cpp
PARENT_SCOPE
)
set(WEB_UNIT_TEST_DEPENDENCIES
web
PARENT_SCOPE
)

View file

@ -0,0 +1,18 @@
set(PLATFORM_UNIT_TEST_FILES)
find_package(Wayland QUIET)
if(WAYLAND_FOUND)
set( PLATFORM_UNIT_TEST_FILES
windows/TestWaylandWindow.cpp
)
endif()
set(WINDOWS_UNIT_TEST_FILES
${PLATFORM_UNIT_TEST_FILES}
PARENT_SCOPE
)
set(WINDOWS_UNIT_TEST_DEPENDENCIES
windows
PARENT_SCOPE
)