Clean up some test files.
This commit is contained in:
parent
1adc9272f8
commit
b45385e8c7
51 changed files with 485 additions and 281 deletions
|
@ -12,6 +12,13 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
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(apps)
|
||||
add_subdirectory(test)
|
|
@ -5,78 +5,78 @@
|
|||
#include <iostream>
|
||||
|
||||
TemplatingEngine::TemplatingEngine(const Path& workingDirectory)
|
||||
: mWorkingDirectory(workingDirectory)
|
||||
: mWorkingDirectory(workingDirectory)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TemplatingEngine::loadTemplateFiles()
|
||||
{
|
||||
const auto files = Directory::getFilesWithExtension(mWorkingDirectory, mTemplateExtension);
|
||||
for (const auto& file : files)
|
||||
{
|
||||
mTemplateFiles.push_back(std::make_unique<TemplateFile>(file));
|
||||
}
|
||||
const auto files = Directory::getFilesWithExtension(mWorkingDirectory, mTemplateExtension);
|
||||
for (const auto& file : files)
|
||||
{
|
||||
mTemplateFiles.push_back(std::make_unique<TemplateFile>(file));
|
||||
}
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::processTemplate(const std::string& name)
|
||||
{
|
||||
if (auto file = getTemplateFile(name))
|
||||
{
|
||||
return processTemplate(file);
|
||||
}
|
||||
return {};
|
||||
if (auto file = getTemplateFile(name))
|
||||
{
|
||||
return processTemplate(file);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
TemplateFile* TemplatingEngine::getTemplateFile(const Path& path)
|
||||
{
|
||||
return getTemplateFile(path.stem().string());
|
||||
return getTemplateFile(path.stem().string());
|
||||
}
|
||||
|
||||
TemplateFile* TemplatingEngine::getTemplateFile(const std::string& name)
|
||||
{
|
||||
std::cout << "Looking for template file with name: " << name << std::endl;
|
||||
for (const auto& file : mTemplateFiles)
|
||||
{
|
||||
if (file->getName() == name)
|
||||
{
|
||||
return file.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
//std::cout << "Looking for template file with name: " << name << std::endl;
|
||||
for (const auto& file : mTemplateFiles)
|
||||
{
|
||||
if (file->getName() == name)
|
||||
{
|
||||
return file.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::processTemplate(TemplateFile* file, TemplateNode* parent)
|
||||
{
|
||||
file->loadContent();
|
||||
file->dumpContent();
|
||||
file->loadContent();
|
||||
file->dumpContent();
|
||||
|
||||
auto content = file->getContent();
|
||||
if (parent)
|
||||
{
|
||||
content->setExtensionParent(parent);
|
||||
}
|
||||
auto content = file->getContent();
|
||||
if (parent)
|
||||
{
|
||||
content->setExtensionParent(parent);
|
||||
}
|
||||
|
||||
if (auto extension_node = content->getFirstChildShallow<TemplateExtends>())
|
||||
{
|
||||
std::cout << "Found extension node" << std::endl;
|
||||
if (auto extension_template = getTemplateFile(Path(extension_node->getPath())))
|
||||
{
|
||||
std::cout << "Found extension template" << std::endl;
|
||||
return processTemplate(extension_template, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return render(content);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return render(content);
|
||||
}
|
||||
if (auto extension_node = content->getFirstChildShallow<TemplateExtends>())
|
||||
{
|
||||
//std::cout << "Found extension node" << std::endl;
|
||||
if (auto extension_template = getTemplateFile(Path(extension_node->getPath())))
|
||||
{
|
||||
//std::cout << "Found extension template" << std::endl;
|
||||
return processTemplate(extension_template, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
return render(content);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return render(content);
|
||||
}
|
||||
}
|
||||
|
||||
std::string TemplatingEngine::render(TemplateNode* content)
|
||||
{
|
||||
return content->render();
|
||||
}
|
||||
return content->render();
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ std::string ZlibEncoder::toString(CompressionMethod method) const
|
|||
|
||||
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));
|
||||
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)
|
||||
{
|
||||
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;
|
||||
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);
|
||||
|
@ -111,7 +111,7 @@ bool ZlibEncoder::encode()
|
|||
auto compression_info = static_cast<unsigned char>(log2(mWindowSize) - 8);
|
||||
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);
|
||||
|
||||
unsigned char flag_byte{0};
|
||||
|
@ -121,7 +121,7 @@ bool ZlibEncoder::encode()
|
|||
const auto mod = (unsigned(compression_byte)*256 + flag_byte) % 31;
|
||||
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);
|
||||
|
||||
if(!mWorkingEncoder->encode())
|
||||
|
@ -131,7 +131,7 @@ bool ZlibEncoder::encode()
|
|||
}
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ bool ZlibEncoder::decode()
|
|||
unsigned char byte3 = *mInputStream->readNextByte();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ bool DeflateBlock::read()
|
|||
{
|
||||
auto working_byte = *mInputStream->readNextByte();
|
||||
|
||||
std::cout << mInputStream->logNextNBytes(60);
|
||||
std::cout << "DeflateBlock::read location " << mInputStream->logLocation();
|
||||
//std::cout << mInputStream->logNextNBytes(60);
|
||||
//std::cout << "DeflateBlock::read location " << mInputStream->logLocation();
|
||||
|
||||
unsigned char final_block{0};
|
||||
mInputStream->readNextNBits(1, final_block);
|
||||
|
@ -78,8 +78,8 @@ bool DeflateBlock::readUncompressedStream()
|
|||
auto byte3 = *mInputStream->readNextByte();
|
||||
uint16_t len_check = (byte2 << 8) | byte3;
|
||||
|
||||
std::cout << "Check block 2: " << ByteUtils::toString(byte2) << std::endl;
|
||||
std::cout << "Check block 3: " << ByteUtils::toString(byte3) << std::endl;
|
||||
//std::cout << "Check block 2: " << ByteUtils::toString(byte2) << std::endl;
|
||||
//std::cout << "Check block 3: " << ByteUtils::toString(byte3) << std::endl;
|
||||
//if (!(byte0 ==(~byte2) && byte1 ==(~byte3)))
|
||||
//{
|
||||
//std::cout << "Uncompressed block length check failed - aborting." << std::endl;
|
||||
|
@ -97,7 +97,7 @@ bool DeflateBlock::readUncompressedStream()
|
|||
|
||||
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->generateFixedCodeMapping();
|
||||
|
@ -139,13 +139,13 @@ void DeflateBlock::write(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);
|
||||
|
||||
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);
|
||||
|
||||
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));
|
||||
|
||||
for(unsigned idx=0; idx<mUncompressedBlockLength;idx++)
|
||||
|
|
|
@ -28,7 +28,7 @@ bool DeflateEncoder::encode()
|
|||
AbstractChecksumCalculator* checksum_calc;
|
||||
if (mChecksumCalculators.size() > 0)
|
||||
{
|
||||
std::cout << "Setting checksum calculator " << std::endl;
|
||||
//std::cout << "Setting checksum calculator " << std::endl;
|
||||
mOutputStream->setChecksumCalculator(mChecksumCalculators[0]);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ bool DeflateEncoder::encode()
|
|||
{
|
||||
if (count == mMaxBlockSize)
|
||||
{
|
||||
std::cout << working_block->getMetaData();
|
||||
//std::cout << working_block->getMetaData();
|
||||
working_block->write(count);
|
||||
|
||||
working_block = std::make_unique<DeflateBlock>(&stream, mOutputStream);
|
||||
|
@ -46,7 +46,7 @@ bool DeflateEncoder::encode()
|
|||
|
||||
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);
|
||||
}
|
||||
else
|
||||
|
@ -59,7 +59,7 @@ bool DeflateEncoder::encode()
|
|||
stream.resetOffsets();
|
||||
working_block->setIsFinalBlock(true);
|
||||
|
||||
std::cout << working_block->getMetaData();
|
||||
//std::cout << working_block->getMetaData();
|
||||
working_block->write(count);
|
||||
break;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ bool DeflateEncoder::decode()
|
|||
auto working_block = std::make_unique<DeflateBlock>(mInputStream, mOutputStream);
|
||||
working_block->read();
|
||||
|
||||
std::cout << working_block->getMetaData() << std::endl;
|
||||
//std::cout << working_block->getMetaData() << std::endl;
|
||||
|
||||
DeflateBlock* raw_block = working_block.get();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
|
|||
|
||||
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();
|
||||
|
||||
|
@ -152,7 +152,7 @@ bool HuffmanCodeLengthTable::readNextSymbol(unsigned& result, BitStream* stream)
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ void HuffmanCodeLengthTable::buildPrefixCodes()
|
|||
}
|
||||
}
|
||||
mTree.sortTable();
|
||||
std::cout << dumpPrefixCodes();
|
||||
//std::cout << dumpPrefixCodes();
|
||||
}
|
||||
|
||||
const PrefixCode& HuffmanCodeLengthTable::getCode(std::size_t index) const
|
||||
|
|
|
@ -22,18 +22,18 @@ void HuffmanEncoder::dumpNode(RawNode<CountPair>* node, unsigned depth) const
|
|||
|
||||
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
|
||||
{
|
||||
std::cout << prefix << "Intermediate with sum " << data.second << std::endl;
|
||||
std::cout << prefix << "Doing Left.." << std::endl;
|
||||
//std::cout << prefix << "Intermediate with sum " << data.second << std::endl;
|
||||
//std::cout << prefix << "Doing Left.." << std::endl;
|
||||
dumpNode(node->getLeftChild(), depth+1);
|
||||
|
||||
std::cout << prefix << "Doing Right.." << std::endl;
|
||||
//std::cout << prefix << "Doing Right.." << std::endl;
|
||||
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<>
|
||||
|
||||
dumpTree(tree);
|
||||
//dumpTree(tree);
|
||||
|
||||
std::cout << "********" << std::endl;
|
||||
//std::cout << "********" << std::endl;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::cout << "Count for " << idx << " is " << counts[idx] << std::endl;
|
||||
//std::cout << "Count for " << idx << " is " << counts[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ void HuffmanStream::readCodeLengths()
|
|||
|
||||
if (!valid)
|
||||
{
|
||||
std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
//std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ void HuffmanStream::readCodeLengths()
|
|||
unsigned char num_reps{0};
|
||||
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++)
|
||||
{
|
||||
addValue(last_value, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
|
||||
|
@ -130,7 +130,7 @@ void HuffmanStream::readCodeLengths()
|
|||
unsigned char num_reps{0};
|
||||
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++)
|
||||
{
|
||||
addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
|
||||
|
@ -141,7 +141,7 @@ void HuffmanStream::readCodeLengths()
|
|||
unsigned char num_reps{0};
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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.buildPrefixCodes();
|
||||
|
@ -192,11 +192,11 @@ void HuffmanStream::readSymbols()
|
|||
const auto valid = readNextLiteralSymbol(symbol);
|
||||
if (!valid)
|
||||
{
|
||||
std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
//std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "Got symbol " << symbol << std::endl;
|
||||
//std::cout << "Got symbol " << symbol << std::endl;
|
||||
|
||||
if(symbol <= 255)
|
||||
{
|
||||
|
@ -269,7 +269,7 @@ void HuffmanStream::readSymbols()
|
|||
|
||||
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();
|
||||
|
||||
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++)
|
||||
{
|
||||
//std::cout << idx << " | " << mBuffer[idx] << std::endl;
|
||||
|
@ -297,7 +297,7 @@ bool HuffmanStream::decode()
|
|||
|
||||
if (!valid)
|
||||
{
|
||||
std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
//std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -317,25 +317,25 @@ void HuffmanStream::readCodingsTable()
|
|||
unsigned char h_lit{0};
|
||||
mInputStream->readNextNBits(5, h_lit);
|
||||
mNumLiterals = h_lit + 257;
|
||||
std::cout << "Got HLIT " << mNumLiterals << std::endl;
|
||||
//std::cout << "Got HLIT " << mNumLiterals << std::endl;
|
||||
|
||||
unsigned char h_dist{0};
|
||||
mInputStream->readNextNBits(5, h_dist);
|
||||
mNumDistances = h_dist + 1;
|
||||
std::cout << "Got HDIST " << mNumDistances << std::endl;
|
||||
//std::cout << "Got HDIST " << mNumDistances << std::endl;
|
||||
|
||||
unsigned char h_clen{0};
|
||||
mInputStream->readNextNBits(4, h_clen);
|
||||
|
||||
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);
|
||||
unsigned char buffer{0};
|
||||
for(unsigned idx = 0; idx< num_code_lengths; idx++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,11 @@ void FileLogger::Close()
|
|||
|
||||
void FileLogger::LogLine(const std::ostringstream& line)
|
||||
{
|
||||
if (mDisabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mFileStream.is_open())
|
||||
{
|
||||
Open();
|
||||
|
@ -43,8 +48,18 @@ void FileLogger::LogLine(const std::ostringstream& line)
|
|||
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)
|
||||
{
|
||||
if (mDisabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::time_t t = std::time(nullptr);
|
||||
const std::string cleanedFileName = fileName.substr(fileName.find_last_of("/\\") + 1);
|
||||
std::tm time_buf = { 0 };
|
||||
|
|
|
@ -14,10 +14,6 @@
|
|||
|
||||
class FileLogger
|
||||
{
|
||||
std::string mWorkDirectory;
|
||||
std::string mFileName;
|
||||
std::ofstream mFileStream;
|
||||
|
||||
FileLogger()
|
||||
:mWorkDirectory(),
|
||||
mFileName("MT_Log.txt"),
|
||||
|
@ -27,7 +23,6 @@ class FileLogger
|
|||
}
|
||||
|
||||
public:
|
||||
|
||||
static FileLogger& GetInstance()
|
||||
{
|
||||
static FileLogger instance;
|
||||
|
@ -39,6 +34,8 @@ public:
|
|||
|
||||
~FileLogger();
|
||||
|
||||
void disable();
|
||||
|
||||
void SetWorkDirectory(const std::string& workDir);
|
||||
|
||||
void SetFileName(const std::string& fileName);
|
||||
|
@ -50,7 +47,11 @@ public:
|
|||
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);
|
||||
|
||||
private:
|
||||
bool mDisabled{false};
|
||||
std::string mWorkDirectory;
|
||||
std::string mFileName;
|
||||
std::ofstream mFileStream;
|
||||
};
|
||||
|
||||
using FileLoggerPtr = std::shared_ptr<FileLogger>;
|
||||
|
|
|
@ -10,9 +10,11 @@ list(APPEND database_LIB_INCLUDES
|
|||
add_library(database SHARED ${database_LIB_INCLUDES})
|
||||
|
||||
target_include_directories(database PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/database_interfaces"
|
||||
"${SQLite3_INCLUDE_DIR}"
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/database_interfaces
|
||||
${SQLite3_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(database core)
|
||||
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 )
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "SqliteInterface.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "FileLogger.h"
|
||||
|
||||
SqliteInterface::SqliteInterface()
|
||||
: mSqliteDb(nullptr)
|
||||
|
@ -23,7 +23,7 @@ void SqliteInterface::Open(const DatabasePtr& db)
|
|||
int rc = sqlite3_open(db->GetPath().c_str(), &mSqliteDb);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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 << "NULL" << std::endl;
|
||||
MLOG_ERROR("NULL");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ void SqliteInterface::Run(const std::string& statement)
|
|||
int rc = sqlite3_exec(mSqliteDb, statement.c_str(), callback, 0, &zErrMsg);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
std::cout << "SQL error: %s\n" << zErrMsg << std::endl;
|
||||
MLOG_ERROR("SQL error: %s\n" << zErrMsg);
|
||||
sqlite3_free(zErrMsg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "File.h"
|
||||
#include "BinaryStream.h"
|
||||
|
||||
#include <iostream>
|
||||
//#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
FontReader::~FontReader()
|
||||
|
@ -51,7 +51,7 @@ void FontReader::logOffsetSubtable()
|
|||
|
||||
sstr << "range_shift: " << mOffsetSubtable.range_shift << "\n";
|
||||
sstr << "************\n";
|
||||
std::cout << sstr.str() << std::endl;
|
||||
//std::cout << sstr.str() << std::endl;
|
||||
}
|
||||
|
||||
void FontReader::readTableDirectory()
|
||||
|
@ -89,7 +89,7 @@ void FontReader::logTable(const Table& table)
|
|||
|
||||
sstr << "length: " << table.length << "\n";
|
||||
sstr << "************\n";
|
||||
std::cout << sstr.str() << std::endl;
|
||||
//std::cout << sstr.str() << std::endl;
|
||||
}
|
||||
|
||||
void FontReader::readTable()
|
||||
|
@ -113,7 +113,7 @@ void FontReader::readTable()
|
|||
|
||||
void FontReader::readHeadTable()
|
||||
{
|
||||
std::cout << "Reading head table" << std::endl;
|
||||
//std::cout << "Reading head table" << std::endl;
|
||||
|
||||
TrueTypeFont::HeadTable table;
|
||||
|
||||
|
@ -145,7 +145,7 @@ void FontReader::readHeadTable()
|
|||
|
||||
auto working_ttf_font = dynamic_cast<TrueTypeFont*>(mWorkingFont.get());
|
||||
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);
|
||||
|
||||
readOffsetSubtable();
|
||||
std::cout << "Current offset: " << mCurrentOffset << std::endl;
|
||||
//std::cout << "Current offset: " << mCurrentOffset << std::endl;
|
||||
|
||||
logOffsetSubtable();
|
||||
|
||||
readTableDirectory();
|
||||
std::cout << "Current offset: " << mCurrentOffset << std::endl;
|
||||
//std::cout << "Current offset: " << mCurrentOffset << std::endl;
|
||||
|
||||
for (unsigned idx=0; idx<mOffsetSubtable.num_tables; idx++)
|
||||
{
|
||||
readTable();
|
||||
std::cout << "Current offset: " << mCurrentOffset << std::endl;
|
||||
//std::cout << "Current offset: " << mCurrentOffset << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "BasicFontEngine.h"
|
||||
#endif
|
||||
|
||||
#include "FontGlyph.h"
|
||||
|
||||
|
||||
FontsManager::FontsManager()
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
|
||||
void dumpInfo() override
|
||||
{
|
||||
std::cout << "Got ttf" << std::endl;
|
||||
//std::cout << "Got ttf" << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -56,7 +56,7 @@ bool PngReader::readChunk()
|
|||
std::string chunkType;
|
||||
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;
|
||||
if (chunkType == "IHDR")
|
||||
{
|
||||
|
@ -118,10 +118,10 @@ bool PngReader::readHeaderChunk()
|
|||
uint32_t file_crc = *BinaryStream::getNextDWord(mFile->GetInHandle());
|
||||
auto crc_calc = mHeader.getCrc();
|
||||
|
||||
std::cout << mHeader.toString() << "*************\n";
|
||||
//std::cout << mHeader.toString() << "*************\n";
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
@ -152,7 +152,7 @@ bool PngReader::readIDATChunk(unsigned length)
|
|||
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
@ -170,7 +170,7 @@ std::unique_ptr<Image<unsigned char> > PngReader::read()
|
|||
|
||||
if (!checkSignature())
|
||||
{
|
||||
std::cout << "Signature check failed" << std::endl;
|
||||
//std::cout << "Signature check failed" << std::endl;
|
||||
return image;
|
||||
}
|
||||
|
||||
|
@ -199,5 +199,5 @@ std::unique_ptr<Image<unsigned char> > PngReader::read()
|
|||
void PngReader::decodeData()
|
||||
{
|
||||
mEncoder->decode();
|
||||
std::cout << mEncoder->getData() << "***********" << std::endl;
|
||||
//std::cout << mEncoder->getData() << "***********" << std::endl;
|
||||
}
|
||||
|
|
|
@ -91,13 +91,13 @@ void PngWriter::writeHeader()
|
|||
|
||||
auto crc = mPngHeader.getCrc();
|
||||
|
||||
std::cout << mPngHeader.toString() << "*********" << std::endl;
|
||||
//std::cout << mPngHeader.toString() << "*********" << std::endl;
|
||||
mOutStream->write(crc);
|
||||
}
|
||||
|
||||
void PngWriter::writeEndChunk()
|
||||
{
|
||||
std::cout << "Start writing end chunk" << std::endl;
|
||||
//std::cout << "Start writing end chunk" << std::endl;
|
||||
unsigned length{0};
|
||||
mOutStream->write(length);
|
||||
|
||||
|
@ -112,7 +112,7 @@ void PngWriter::writeEndChunk()
|
|||
auto crc = crc_check.getChecksum();
|
||||
mOutStream->write(crc);
|
||||
|
||||
std::cout << "Writing end chunk" << std::endl;
|
||||
//std::cout << "Writing end chunk" << std::endl;
|
||||
}
|
||||
|
||||
void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
||||
|
@ -130,7 +130,7 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
|||
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);
|
||||
|
||||
std::vector<unsigned char> char_data = StringUtils::toBytes("IDAT");
|
||||
|
@ -150,9 +150,9 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
|||
}
|
||||
|
||||
auto crc = crc_check.getChecksum();
|
||||
std::cout << "Writing idat crc" << crc << std::endl;
|
||||
//std::cout << "Writing idat crc" << crc << std::endl;
|
||||
mOutStream->write(crc);
|
||||
std::cout << "Finished Writing idat crc" << crc << std::endl;
|
||||
//std::cout << "Finished Writing idat crc" << crc << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ std::unique_ptr<TriMesh> MeshPrimitives::buildRoundedRectangleAsTriMesh(double r
|
|||
|
||||
// Inner rect edges
|
||||
unsigned edge_offset = num_edges_per_fan*num_fans;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<LineMesh> MeshPrimitives::buildRectangleAsLineMesh()
|
||||
|
|
|
@ -31,7 +31,6 @@ void NetworkManager::Initialize()
|
|||
|
||||
void NetworkManager::RunHttpServer()
|
||||
{
|
||||
std::cout << "Running http server" << std::endl;
|
||||
if (!mSocketInterface)
|
||||
{
|
||||
Initialize();
|
||||
|
@ -45,7 +44,6 @@ void NetworkManager::RunHttpServer()
|
|||
|
||||
void NetworkManager::RunHttpClient()
|
||||
{
|
||||
std::cout << "Running http client" << std::endl;
|
||||
if (!mSocketInterface)
|
||||
{
|
||||
Initialize();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "UnixSocketInterface.h"
|
||||
|
||||
#include "HttpResponse.h"
|
||||
|
||||
#include "HttpMessageHandler.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
@ -43,7 +44,7 @@ void UnixSocketInterface::Write(const SocketPtr& socket, const std::string& mess
|
|||
{
|
||||
if(socket->GetHandle() < 0)
|
||||
{
|
||||
std::cerr << "Error opening socket" << std::endl;
|
||||
MLOG_ERROR("Error opening socket" );
|
||||
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));
|
||||
if(result< 0)
|
||||
{
|
||||
std::cerr << "Error connecting to socket" << std::endl;
|
||||
MLOG_ERROR("Error connecting to socket" );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,76 +1,27 @@
|
|||
add_library(test_utils STATIC
|
||||
test_utils/TestCase.h
|
||||
test_utils/TestCaseRunner.cpp
|
||||
)
|
||||
add_subdirectory(test_utils)
|
||||
|
||||
target_include_directories(test_utils PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test_utils"
|
||||
)
|
||||
set(TEST_MODULES
|
||||
audio
|
||||
compiler
|
||||
compression
|
||||
core
|
||||
database
|
||||
fonts
|
||||
graphics
|
||||
image
|
||||
ipc
|
||||
network
|
||||
publishing
|
||||
video
|
||||
web
|
||||
windows)
|
||||
|
||||
list(APPEND TestFiles
|
||||
audio/TestAudioWriter.cpp
|
||||
audio/TestMidiReader.cpp
|
||||
compiler/TestTemplatingEngine.cpp
|
||||
compression/TestStreamCompressor.cpp
|
||||
compression/TestHuffmanStream.cpp
|
||||
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()
|
||||
foreach(module ${TEST_MODULES})
|
||||
add_subdirectory(${module})
|
||||
string(TOUPPER ${module} MODULE_UPPER)
|
||||
list(APPEND UNIT_TEST_FILES ${${MODULE_UPPER}_UNIT_TEST_FILES})
|
||||
list(APPEND UNIT_TEST_DEPENDENCIES ${${MODULE_UPPER}_UNIT_TEST_DEPENDENCIES})
|
||||
endforeach()
|
||||
|
||||
find_package(Wayland QUIET)
|
||||
if(WAYLAND_FOUND)
|
||||
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)
|
||||
add_executable(unit_tests test_runner.cpp ${UNIT_TEST_FILES})
|
||||
target_link_libraries(unit_tests PUBLIC test_utils ${UNIT_TEST_DEPENDENCIES})
|
||||
|
|
10
test/audio/CMakeLists.txt
Normal file
10
test/audio/CMakeLists.txt
Normal 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
|
||||
)
|
9
test/compiler/CMakeLists.txt
Normal file
9
test/compiler/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
set(COMPILER_UNIT_TEST_FILES
|
||||
compiler/TestTemplatingEngine.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(COMPILER_UNIT_TEST_DEPENDENCIES
|
||||
compiler
|
||||
PARENT_SCOPE
|
||||
)
|
|
@ -1,6 +1,6 @@
|
|||
#include "TemplatingEngine.h"
|
||||
|
||||
#include <File.h>
|
||||
#include "File.h"
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
@ -8,12 +8,12 @@
|
|||
|
||||
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);
|
||||
engine.loadTemplateFiles();
|
||||
const auto content = engine.processTemplate("index");
|
||||
auto engine = TemplatingEngine(data_loc);
|
||||
engine.loadTemplateFiles();
|
||||
const auto content = engine.processTemplate("index");
|
||||
|
||||
File outfile("index.html");
|
||||
outfile.WriteText(content);
|
||||
File outfile("index.html");
|
||||
outfile.WriteText(content);
|
||||
}
|
||||
|
|
11
test/compression/CMakeLists.txt
Normal file
11
test/compression/CMakeLists.txt
Normal 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
|
||||
)
|
|
@ -28,7 +28,7 @@ TEST_CASE(TestLz77Encoder, "compression")
|
|||
for(const auto& hit : hit_buffer)
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -54,7 +54,7 @@ TEST_CASE(TestLz77Encoder, "compression")
|
|||
Lz77Encoder encoder(&input_stream, &output_stream);
|
||||
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);
|
||||
|
||||
|
|
12
test/core/CMakeLists.txt
Normal file
12
test/core/CMakeLists.txt
Normal 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
|
||||
)
|
|
@ -21,22 +21,22 @@ TEST_CASE(TestReadBitStream, "core")
|
|||
|
||||
unsigned char buffer{0} ;
|
||||
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);
|
||||
std::cout << "Slice1 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice1 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
|
||||
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);
|
||||
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
|
||||
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);
|
||||
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
}
|
||||
|
||||
TEST_CASE(TestWritingBitStream, "core")
|
||||
|
@ -68,9 +68,9 @@ TEST_CASE(TestWritingBitStream, "core")
|
|||
auto byte3 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte4 = ByteUtils::toString(*stream.readNextByte());
|
||||
|
||||
std::cout << "Got bytes 0 " << byte0 << std::endl;
|
||||
std::cout << "Got bytes 1 " << byte1 << std::endl;
|
||||
std::cout << "Got bytes 2 " << byte2 << std::endl;
|
||||
std::cout << "Got bytes 3 " << byte3 << std::endl;
|
||||
std::cout << "Got bytes 4 " << byte4 << std::endl;
|
||||
//std::cout << "Got bytes 0 " << byte0 << std::endl;
|
||||
//std::cout << "Got bytes 1 " << byte1 << std::endl;
|
||||
//std::cout << "Got bytes 2 " << byte2 << std::endl;
|
||||
//std::cout << "Got bytes 3 " << byte3 << std::endl;
|
||||
//std::cout << "Got bytes 4 " << byte4 << std::endl;
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
TEST_CASE(TestReadByteUtils, "core")
|
||||
{
|
||||
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);
|
||||
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);
|
||||
std::cout << "Slice is " << ByteUtils::toString(slice) << std::endl;
|
||||
//std::cout << "Slice is " << ByteUtils::toString(slice) << std::endl;
|
||||
|
||||
uint32_t input {12345678};
|
||||
auto byte0 = ByteUtils::getByteN(input, 0);
|
||||
|
@ -21,17 +21,17 @@ TEST_CASE(TestReadByteUtils, "core")
|
|||
auto byte2 = ByteUtils::getByteN(input, 2);
|
||||
auto byte3 = ByteUtils::getByteN(input, 3);
|
||||
|
||||
std::cout << "Byte0 is " << ByteUtils::toString(byte0) << std::endl;
|
||||
std::cout << "Byte1 is " << ByteUtils::toString(byte1) << std::endl;
|
||||
std::cout << "Byte2 is " << ByteUtils::toString(byte2) << std::endl;
|
||||
std::cout << "Byte3 is " << ByteUtils::toString(byte3) << std::endl;
|
||||
//std::cout << "Byte0 is " << ByteUtils::toString(byte0) << std::endl;
|
||||
//std::cout << "Byte1 is " << ByteUtils::toString(byte1) << std::endl;
|
||||
//std::cout << "Byte2 is " << ByteUtils::toString(byte2) << 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);
|
||||
std::cout << "Mirror is " << ByteUtils::toString(out) << std::endl;
|
||||
//std::cout << "Mirror is " << ByteUtils::toString(out) << std::endl;
|
||||
|
||||
unsigned hold = byte;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -10,25 +10,25 @@ TEST_CASE(TestCircleBuffer, "core")
|
|||
|
||||
for (auto item : {1, 2, 3})
|
||||
{
|
||||
std::cout << "Add item: " << item << std::endl;
|
||||
//std::cout << "Add item: " << item << std::endl;
|
||||
buffer.addItem(item);
|
||||
}
|
||||
|
||||
for (std::size_t idx=0; idx<3; 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})
|
||||
{
|
||||
std::cout << "Add item: " << item << std::endl;
|
||||
buffer.addItem(item);
|
||||
//std::cout << "Add item: " << item << std::endl;
|
||||
//buffer.addItem(item);
|
||||
}
|
||||
|
||||
for (std::size_t idx=0; idx<3; idx++)
|
||||
{
|
||||
auto item = buffer.getItem(idx);
|
||||
std::cout << "Got item: " << idx << " " << item << std::endl;
|
||||
//std::cout << "Got item: " << idx << " " << item << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@ TEST_CASE(TestTomlReader, "core")
|
|||
reader.read(sample_toml_file);
|
||||
|
||||
auto themes_table = reader.getContent()->getTable("themes");
|
||||
|
||||
REQUIRE(themes_table);
|
||||
|
||||
for (const auto& items : themes_table->getKeyValuePairs())
|
||||
{
|
||||
std::cout << "Got entry with key: " << items.first << " and val " << items.second << std::endl;
|
||||
|
|
9
test/database/CMakeLists.txt
Normal file
9
test/database/CMakeLists.txt
Normal 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
22
test/fonts/CMakeLists.txt
Normal 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
|
||||
)
|
20
test/graphics/CMakeLists.txt
Normal file
20
test/graphics/CMakeLists.txt
Normal 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
|
||||
)
|
|
@ -15,5 +15,7 @@ TEST_CASE(TestOpenGlRendering, "graphics")
|
|||
|
||||
app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11);
|
||||
//app->setUiInterfaceBackend(UiInterfaceFactory::Backend::X11_RASTER);
|
||||
app->run();
|
||||
|
||||
|
||||
//app->run();
|
||||
};
|
||||
|
|
10
test/image/CMakeLists.txt
Normal file
10
test/image/CMakeLists.txt
Normal 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
|
||||
)
|
|
@ -40,7 +40,7 @@ TEST_CASE(TestCompressedPng, "image")
|
|||
|
||||
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();
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ TEST_CASE(TestFixedPng, "image")
|
|||
|
||||
//return;
|
||||
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;
|
||||
File test_file("test_dynamic.png");
|
||||
std::cout << test_file.dumpBinary();
|
||||
//std::cout << test_file.dumpBinary();
|
||||
}
|
||||
|
|
20
test/ipc/CMakeLists.txt
Normal file
20
test/ipc/CMakeLists.txt
Normal 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
|
||||
)
|
10
test/network/CMakeLists.txt
Normal file
10
test/network/CMakeLists.txt
Normal 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
|
||||
)
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
TEST_CASE(TestNetworkManagerClient, "network")
|
||||
{
|
||||
std::cout << "into main" << std::endl;
|
||||
auto network_manager = NetworkManager::Create();
|
||||
|
||||
network_manager->RunHttpClient();
|
||||
|
|
|
@ -2,12 +2,9 @@
|
|||
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE(TestNetworkManagerServer, "network")
|
||||
{
|
||||
std::cout << "into main" << std::endl;
|
||||
auto network_manager = NetworkManager::Create();
|
||||
|
||||
network_manager->RunHttpServer();
|
||||
//network_manager->RunHttpServer();
|
||||
}
|
||||
|
|
9
test/publishing/CMakeLists.txt
Normal file
9
test/publishing/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
set(PUBLISHING_UNIT_TEST_FILES
|
||||
publishing/TestPdfWriter.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(PUBLISHING_UNIT_TEST_DEPENDENCIES
|
||||
publishing
|
||||
PARENT_SCOPE
|
||||
)
|
|
@ -11,8 +11,7 @@ int main()
|
|||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
#endif
|
||||
|
||||
auto test_runner = TestCaseRunner::getInstance();
|
||||
test_runner.run();
|
||||
auto result = TestCaseRunner::getInstance().run();
|
||||
|
||||
#ifdef _WIN32
|
||||
CoUninitialize();
|
||||
|
|
9
test/test_utils/CMakeLists.txt
Normal file
9
test/test_utils/CMakeLists.txt
Normal 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)
|
|
@ -1,14 +1,27 @@
|
|||
#include "TestCaseRunner.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
bool TestCaseRunner::sLastTestFailed = false;
|
||||
std::string TestCaseRunner::sFailureLine = {};
|
||||
|
||||
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)
|
||||
|
@ -17,28 +30,35 @@ void TestCaseRunner::addTestCase(const std::string& label, const std::string& ta
|
|||
mCases.push_back(test_case);
|
||||
}
|
||||
|
||||
void TestCaseRunner::markTestFailure(const std::string& line)
|
||||
{
|
||||
sLastTestFailed = true;
|
||||
sFailureLine = line;
|
||||
}
|
||||
|
||||
bool TestCaseRunner::run()
|
||||
{
|
||||
FileLogger::GetInstance().disable();
|
||||
for (auto test_case : mCases)
|
||||
{
|
||||
sLastTestFailed = false;
|
||||
std::cout << "TestFramework: Running Test - " << test_case->getName() << std::endl;
|
||||
test_case->run();
|
||||
}
|
||||
|
||||
bool testsPassed = true;
|
||||
/*
|
||||
for(const auto& test : mCases)
|
||||
{
|
||||
std::cout << "Running " << test->getName() << std::endl;
|
||||
const auto result = test->Run();
|
||||
if (!result)
|
||||
if (sLastTestFailed)
|
||||
{
|
||||
std::cout << test->getName() << " Failed" << std::endl;
|
||||
testsPassed = false;
|
||||
break;
|
||||
std::cout << "Failed at line: " << sLastTestFailed << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -8,20 +8,21 @@
|
|||
class TestCaseRunner
|
||||
{
|
||||
public:
|
||||
TestCaseRunner() = default;
|
||||
TestCaseRunner();
|
||||
|
||||
static TestCaseRunner& getInstance()
|
||||
{
|
||||
static TestCaseRunner instance;
|
||||
return instance;
|
||||
}
|
||||
static TestCaseRunner& getInstance();
|
||||
|
||||
~TestCaseRunner();
|
||||
|
||||
void addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func);
|
||||
|
||||
void markTestFailure(const std::string& line);
|
||||
|
||||
bool run();
|
||||
|
||||
private:
|
||||
std::vector<std::string> mFailingTests;
|
||||
static bool sLastTestFailed;
|
||||
static std::string sFailureLine;
|
||||
std::vector<TestCase*> mCases;
|
||||
};
|
||||
|
|
|
@ -16,3 +16,13 @@ struct Holder
|
|||
static void Test##NAME() \
|
||||
|
||||
|
||||
#define REQUIRE(predicate) \
|
||||
if(!predicate) \
|
||||
{ \
|
||||
TestCaseRunner::getInstance().markTestFailure(std::to_string(__LINE__)); \
|
||||
return; \
|
||||
} \
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
17
test/video/CMakeLists.txt
Normal file
17
test/video/CMakeLists.txt
Normal 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
10
test/web/CMakeLists.txt
Normal 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
|
||||
)
|
18
test/windows/CMakeLists.txt
Normal file
18
test/windows/CMakeLists.txt
Normal 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
|
||||
)
|
Loading…
Reference in a new issue