Clean up some tests.
This commit is contained in:
parent
b17ba8b3a7
commit
c102ebb6da
64 changed files with 615 additions and 541 deletions
|
@ -1,5 +1,7 @@
|
|||
add_subdirectory(test_utils)
|
||||
|
||||
file(COPY data/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_data)
|
||||
|
||||
set(TEST_MODULES
|
||||
audio
|
||||
compiler
|
||||
|
@ -21,7 +23,13 @@ foreach(module ${TEST_MODULES})
|
|||
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})
|
||||
|
||||
list(APPEND INTEGRATION_TEST_FILES ${${MODULE_UPPER}_INTEGRATION_TEST_FILES})
|
||||
list(APPEND INTEGRATION_TEST_DEPENDENCIES ${${MODULE_UPPER}_INTEGRATION_TEST_DEPENDENCIES})
|
||||
endforeach()
|
||||
|
||||
add_executable(unit_tests test_runner.cpp ${UNIT_TEST_FILES})
|
||||
target_link_libraries(unit_tests PUBLIC test_utils ${UNIT_TEST_DEPENDENCIES})
|
||||
|
||||
add_executable(integration_tests test_runner.cpp ${INTEGRATION_TEST_FILES})
|
||||
target_link_libraries(integration_tests PUBLIC test_utils ${INTEGRATION_TEST_DEPENDENCIES})
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
set(AUDIO_UNIT_TEST_FILES
|
||||
audio/TestAudioWriter.cpp
|
||||
audio/TestMidiReader.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(AUDIO_UNIT_TEST_DEPENDENCIES
|
||||
audio
|
||||
PARENT_SCOPE
|
||||
)
|
||||
set(MODULE_NAME audio)
|
||||
|
||||
set(UNIT_TESTS
|
||||
${MODULE_NAME}/unit/TestAudioWriter.cpp
|
||||
${MODULE_NAME}/unit/TestMidiReader.cpp
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
set(INTEGETATION_TESTS
|
||||
${MODULE_NAME}/integration/TestAlsaInterface.cpp
|
||||
)
|
||||
else()
|
||||
set(INTEGETATION_TESTS
|
||||
${MODULE_NAME}/integration/TestWasapiInterface.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
set(AUDIO_UNIT_TEST_FILES ${UNIT_TESTS} PARENT_SCOPE)
|
||||
set(AUDIO_INTEGRATION_TEST_FILES ${INTEGETATION_TESTS} PARENT_SCOPE)
|
||||
|
||||
set(AUDIO_UNIT_TEST_DEPENDENCIES ${MODULE_NAME} PARENT_SCOPE)
|
||||
set(AUDIO_INTEGRATION_TEST_DEPENDENCIES ${MODULE_NAME} PARENT_SCOPE)
|
|
@ -1,34 +0,0 @@
|
|||
#include "AudioSample.h"
|
||||
#include "AudioSynth.h"
|
||||
#include "AudioWriter.h"
|
||||
#include "WasapiInterface.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE(TestWriteWav, "audio")
|
||||
{
|
||||
AudioWriter writer;
|
||||
writer.SetPath("test.wav");
|
||||
|
||||
AudioSynth synth;
|
||||
auto sample = synth.GetSineWave(240, 5);
|
||||
|
||||
writer.Write(sample);
|
||||
};
|
||||
|
||||
TEST_CASE(TestAudioRender, "audio")
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
WasapiInterface audio_interface;
|
||||
auto device = AudioDevice::Create();
|
||||
audio_interface.Play(device);
|
||||
#endif
|
||||
};
|
|
@ -1,16 +0,0 @@
|
|||
#include "MidiReader.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE(TestReadMidi, "audio")
|
||||
{
|
||||
MidiReader reader;
|
||||
reader.Read("/home/jmsgrogan/Downloads/test.mid");
|
||||
|
||||
auto document = reader.GetDocument();
|
||||
// std::cout << document->Serialize() << std::endl;
|
||||
};
|
0
test/audio/integration/TestAlsaInterface.cpp
Normal file
0
test/audio/integration/TestAlsaInterface.cpp
Normal file
13
test/audio/integration/TestWasapiInterface.cpp
Normal file
13
test/audio/integration/TestWasapiInterface.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
#include "AudioSample.h"
|
||||
#include "AudioSynth.h"
|
||||
#include "WasapiInterface.h"
|
||||
|
||||
TEST_CASE(TestWasapiInterface, "audio")
|
||||
{
|
||||
WasapiInterface audio_interface;
|
||||
auto device = AudioDevice::Create();
|
||||
audio_interface.Play(device);
|
||||
};
|
17
test/audio/unit/TestAudioWriter.cpp
Normal file
17
test/audio/unit/TestAudioWriter.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
#include "AudioSample.h"
|
||||
#include "AudioSynth.h"
|
||||
#include "AudioWriter.h"
|
||||
|
||||
TEST_CASE(TestAudioWriterWav, "audio")
|
||||
{
|
||||
AudioWriter writer;
|
||||
writer.setPath(TestUtils::getTestOutputDir() / "TestAudioWriterWav.wav");
|
||||
|
||||
AudioSynth synth;
|
||||
const auto sample = synth.getSineWave(240, 5);
|
||||
|
||||
writer.write(sample);
|
||||
};
|
12
test/audio/unit/TestMidiReader.cpp
Normal file
12
test/audio/unit/TestMidiReader.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include "MidiReader.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
TEST_CASE(TestReadMidi, "audio")
|
||||
{
|
||||
MidiReader reader;
|
||||
reader.read(TestUtils::getTestDataDir() / "test.mid");
|
||||
|
||||
auto document = reader.getDocument();
|
||||
};
|
|
@ -1,19 +1,16 @@
|
|||
#include "TemplatingEngine.h"
|
||||
|
||||
#include "File.h"
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
TEST_CASE(TestTemplatingEngine, "compiler")
|
||||
{
|
||||
const auto data_loc = std::filesystem::path(__FILE__) / "../../data";
|
||||
|
||||
auto engine = TemplatingEngine(data_loc);
|
||||
auto engine = TemplatingEngine(TestUtils::getTestDataDir());
|
||||
engine.loadTemplateFiles();
|
||||
const auto content = engine.processTemplate("index");
|
||||
|
||||
File outfile("index.html");
|
||||
outfile.WriteText(content);
|
||||
File outfile(TestUtils::getTestOutputDir() / "index.html");
|
||||
outfile.writeText(content);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
#include "TomlReader.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "TestUtils.h"
|
||||
|
||||
TEST_CASE(TestTomlReader, "core")
|
||||
{
|
||||
const auto data_loc = std::filesystem::path(__FILE__) / "../../data";
|
||||
const auto sample_toml_file = data_loc / "sample_toml.toml";
|
||||
|
||||
auto reader = TomlReader();
|
||||
reader.read(sample_toml_file);
|
||||
reader.read(TestUtils::getTestDataDir() / "sample_toml.toml");
|
||||
|
||||
auto themes_table = reader.getContent()->getTable("themes");
|
||||
|
||||
|
@ -19,6 +14,6 @@ TEST_CASE(TestTomlReader, "core")
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
BIN
test/data/index.png
Normal file
BIN
test/data/index.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
BIN
test/data/test.mid
Normal file
BIN
test/data/test.mid
Normal file
Binary file not shown.
BIN
test/data/test.png
Normal file
BIN
test/data/test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
BIN
test/data/test_fixed.png
Normal file
BIN
test/data/test_fixed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 B |
|
@ -1,12 +1,13 @@
|
|||
#include "DatabaseManager.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
TEST_CASE(TestDatabaseManager, "database")
|
||||
{
|
||||
DatabaseManager db_manager;
|
||||
db_manager.CreateDatabase("test.db");
|
||||
db_manager.openDatabase(TestUtils::getTestOutputDir() / "test.db");
|
||||
|
||||
std::string statement = "CREATE TABLE corporation;";
|
||||
db_manager.Run(statement);
|
||||
db_manager.run(statement);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "TrueTypeFont.h"
|
||||
#include "FontReader.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
TEST_CASE(TestFontReader, "fonts")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "PngReader.h"
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
#include "Image.h"
|
||||
#include <iostream>
|
||||
|
@ -9,7 +10,7 @@
|
|||
|
||||
TEST_CASE(TestThirdPartyPng, "image")
|
||||
{
|
||||
const auto path = "/home/jmsgrogan/Downloads/test.png";
|
||||
const auto path = TestUtils::getTestDataDir() / "test.png";
|
||||
|
||||
//const auto path = "/home/jmsgrogan/Downloads/index.png";
|
||||
|
||||
|
@ -30,7 +31,7 @@ TEST_CASE(TestThirdPartyPng, "image")
|
|||
|
||||
TEST_CASE(TestFxedCodePng, "image")
|
||||
{
|
||||
const auto path = "/home/jmsgrogan/code/MediaTool-build/bin/test_fixed.png";
|
||||
const auto path = TestUtils::getTestDataDir() / "test_fixed.png";
|
||||
|
||||
//File file(path);
|
||||
//std::cout << file.dumpBinary();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "ImagePrimitives.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
#include "TestUtils.h"
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE(TestCompressedPng, "image")
|
||||
|
@ -29,20 +29,18 @@ TEST_CASE(TestCompressedPng, "image")
|
|||
image->setData(data);
|
||||
|
||||
PngWriter writer;
|
||||
writer.setPath("test_compressed.png");
|
||||
writer.setPath(TestUtils::getTestOutputDir() / "test_compressed.png");
|
||||
writer.setCompressionMethod(Deflate::CompressionMethod::NONE);
|
||||
writer.write(image);
|
||||
|
||||
return;
|
||||
File test_file("test_compressed.png");
|
||||
test_file.SetAccessMode(File::AccessMode::Read);
|
||||
test_file.Open(true);
|
||||
File test_file(TestUtils::getTestOutputDir() / "test_compressed.png");
|
||||
test_file.open(File::AccessMode::Read);
|
||||
|
||||
while(auto byte = test_file.readNextByte())
|
||||
{
|
||||
//std::cout << static_cast<unsigned>(*byte) << std::endl;
|
||||
}
|
||||
test_file.Close();
|
||||
}
|
||||
|
||||
TEST_CASE(TestFixedPng, "image")
|
||||
|
@ -65,12 +63,12 @@ TEST_CASE(TestFixedPng, "image")
|
|||
image->setData(data);
|
||||
|
||||
PngWriter writer;
|
||||
writer.setPath("test_fixed.png");
|
||||
writer.setPath(TestUtils::getTestOutputDir() / "test_fixed.png");
|
||||
writer.setCompressionMethod(Deflate::CompressionMethod::FIXED_HUFFMAN);
|
||||
writer.write(image);
|
||||
|
||||
//return;
|
||||
File test_file("test_fixed.png");
|
||||
File test_file(TestUtils::getTestOutputDir() / "test_fixed.png");
|
||||
//std::cout << test_file.dumpBinary();
|
||||
|
||||
}
|
||||
|
@ -95,10 +93,10 @@ TEST_CASE(TestDynamicCompressedPng, "image")
|
|||
image->setData(data);
|
||||
|
||||
PngWriter writer;
|
||||
writer.setPath("test_dynamic.png");
|
||||
writer.setPath(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
||||
writer.write(image);
|
||||
|
||||
//return;
|
||||
File test_file("test_dynamic.png");
|
||||
File test_file(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
||||
//std::cout << test_file.dumpBinary();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "File.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
TEST_CASE(TestPdfWriter, "publishing")
|
||||
{
|
||||
|
@ -12,8 +13,7 @@ TEST_CASE(TestPdfWriter, "publishing")
|
|||
PdfWriter writer;
|
||||
const auto output = writer.ToString(document);
|
||||
|
||||
File pdf_file("TestPdfWriter.pdf");
|
||||
pdf_file.SetAccessMode(File::AccessMode::Write);
|
||||
pdf_file.Open();
|
||||
pdf_file.WriteText(output);
|
||||
File pdf_file(TestUtils::getTestOutputDir() / "TestPdfWriter.pdf");
|
||||
pdf_file.open(File::AccessMode::Write);
|
||||
pdf_file.writeText(output);
|
||||
}
|
||||
|
|
19
test/test_utils/TestUtils.h
Normal file
19
test/test_utils/TestUtils.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
class TestUtils
|
||||
{
|
||||
public:
|
||||
static Path getTestOutputDir()
|
||||
{
|
||||
return std::filesystem::current_path() / "test_output";
|
||||
}
|
||||
|
||||
static Path getTestDataDir()
|
||||
{
|
||||
return std::filesystem::current_path() / "test_data";
|
||||
}
|
||||
};
|
|
@ -2,24 +2,22 @@
|
|||
#include "Image.h"
|
||||
#include "FfmpegInterface.h"
|
||||
#include "PngWriter.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "TestFramework.h"
|
||||
|
||||
TEST_CASE(TestVideoDecoder, "video")
|
||||
{
|
||||
auto video = Video::Create();
|
||||
video->SetPath("/home/jmsgrogan/test.mp4");
|
||||
video->SetPath(TestUtils::getTestDataDir() / "test.mp4");
|
||||
|
||||
FfmpegInterface decoder;
|
||||
auto images = decoder.decodeToImages(video, 4);
|
||||
std::cout << "Got " << std::to_string(images.size()) << std::endl;
|
||||
|
||||
PngWriter writer;
|
||||
for(unsigned idx=0; idx<20; idx++)
|
||||
{
|
||||
auto filename = "test_out" + std::to_string(idx) + ".png";
|
||||
writer.SetPath(filename);
|
||||
writer.Write(images[idx]);
|
||||
writer.setPath(filename);
|
||||
writer.write(images[idx]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,23 +3,21 @@
|
|||
#include "HtmlWriter.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
TEST_CASE(TestMarkdownParser, "web")
|
||||
{
|
||||
File md_file("/home/jmsgrogan/code/MediaTool/test/data/sample_markdown.md");
|
||||
md_file.Open();
|
||||
const auto md_content = md_file.ReadText();
|
||||
File md_file(TestUtils::getTestDataDir() / "sample_markdown.md");
|
||||
const auto md_content = md_file.readText();
|
||||
|
||||
MarkdownParser parser;
|
||||
parser.Run(md_content);
|
||||
parser.run(md_content);
|
||||
|
||||
auto html = parser.GetHtml();
|
||||
auto html = parser.getHtml();
|
||||
|
||||
HtmlWriter writer;
|
||||
const auto html_string = writer.ToString(html);
|
||||
|
||||
File html_file("TestMarkdownParserOut.html");
|
||||
html_file.SetAccessMode(File::AccessMode::Write);
|
||||
html_file.Open();
|
||||
html_file.WriteText(html_string);
|
||||
File html_file(TestUtils::getTestOutputDir() / "TestMarkdownParserOut.html");
|
||||
html_file.writeText(html_string);
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
#include "File.h"
|
||||
|
||||
#include "TestFramework.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
TEST_CASE(TestXmlParser, "web")
|
||||
{
|
||||
XmlParser parser;
|
||||
|
||||
std::ifstream xml_file;
|
||||
xml_file.open("/home/jmsgrogan/test.xml", std::ifstream::in);
|
||||
xml_file.open(TestUtils::getTestDataDir() / "test.xml", std::ifstream::in);
|
||||
while(xml_file.good())
|
||||
{
|
||||
std::string line;
|
||||
|
@ -21,11 +22,9 @@ TEST_CASE(TestXmlParser, "web")
|
|||
}
|
||||
xml_file.close();
|
||||
|
||||
auto outFile = std::make_unique<File>("test_out.xml");
|
||||
outFile->SetAccessMode(File::AccessMode::Write);
|
||||
outFile->Open();
|
||||
|
||||
XmlWriter writer;
|
||||
auto content = writer.ToString(parser.GetDocument().get());
|
||||
outFile->WriteText(content);
|
||||
|
||||
auto outFile = std::make_unique<File>(TestUtils::getTestOutputDir() / "test_out.xml");
|
||||
outFile->writeText(content);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue