🎨 Convert to a header-only library (#6)

This commit is contained in:
2021-01-12 16:19:25 +01:00
committed by GitHub
parent f7fe31739e
commit c7b0151510
19 changed files with 1090 additions and 1404 deletions

View File

@ -1,17 +1,16 @@
if(NOT EXISTS "${CMAKE_BINARY_DIR}/catch/catch.hpp")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/catch")
message(STATUS "Downloading catch.hpp from https://github.com/catchorg/Catch2/")
file(DOWNLOAD "https://github.com/catchorg/Catch2/releases/download/v2.5.0/catch.hpp"
"${CMAKE_BINARY_DIR}/catch/catch.hpp")
endif()
project(moFileReaderTest)
find_package(Catch2 REQUIRED)
add_executable(moFileReaderTest test.cpp)
target_include_directories(moFileReaderTest PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/catch)
target_link_libraries(moFileReaderTest moFileReader)
add_test(NAME mo_test COMMAND moFileReaderTest)
include(CTest)
include(Catch)
add_executable(${PROJECT_NAME} test.cpp link_test.cpp)
target_include_directories(moFileReaderTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2)
catch_discover_tests(${PROJECT_NAME})
add_custom_command(
TARGET moFileReaderTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo $<TARGET_FILE_DIR:moFileReaderTest>/test.mo
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo ${CMAKE_CURRENT_BINARY_DIR}/test.mo
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo $<TARGET_FILE_DIR:moFileReaderTest>/test.mo
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/test.mo ${CMAKE_CURRENT_BINARY_DIR}/test.mo
)

17
test/link_test.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "catch.hpp"
#include "moFileReader.hpp"
using namespace moFileLib;
#define _L(str) moFileReaderSingleton::GetInstance().Lookup(str)
#define _LC(ctx, str) moFileReaderSingleton::GetInstance().LookupWithContext(ctx, str)
void test()
{
moFileReaderSingleton::GetInstance().ReadFile("test.mo");
/* This is the first comment. */
CHECK("Text Nederlands Een" == _L("String English One"));
/* This is the second comment. */
CHECK("Text Nederlands Twee" == _L("String English Two"));
/* This is the third comment. */
CHECK("Text Nederlands Drie" == _L("String English Three"));
}

View File

@ -1,36 +1,35 @@
#define CATCH_CONFIG_MAIN
#include "moFileReader.h"
#include "catch.hpp"
#include "moFileReader.hpp"
using namespace moFileLib;
#define _L(str) moFileReaderSingleton::GetInstance().Lookup(str)
#define _LC(ctx,str) moFileReaderSingleton::GetInstance().LookupWithContext(ctx,str)
#define _LC(ctx, str) moFileReaderSingleton::GetInstance().LookupWithContext(ctx, str)
TEST_CASE ("Load mo-file", "[ReadFile]")
TEST_CASE("Load mo-file", "[ReadFile]")
{
CHECK (moFileReaderSingleton::GetInstance ().ReadFile ("test.mo") == moFileLib::moFileReader::EC_SUCCESS);
CHECK(moFileReaderSingleton::GetInstance().ReadFile("test.mo") == moFileLib::moFileReader::EC_SUCCESS);
}
TEST_CASE ("Lookup string", "[Lookup]")
TEST_CASE("Lookup string", "[Lookup]")
{
moFileReaderSingleton::GetInstance ().ReadFile ("test.mo");
moFileReaderSingleton::GetInstance().ReadFile("test.mo");
/* This is the first comment. */
CHECK ("Text Nederlands Een" == _L ("String English One"));
CHECK("Text Nederlands Een" == _L("String English One"));
/* This is the second comment. */
CHECK ("Text Nederlands Twee" == _L ("String English Two"));
CHECK("Text Nederlands Twee" == _L("String English Two"));
/* This is the third comment. */
CHECK ("Text Nederlands Drie" == _L ("String English Three"));
CHECK("Text Nederlands Drie" == _L("String English Three"));
}
TEST_CASE ("Lookup string with context", "[LookupWithContext]")
TEST_CASE("Lookup string with context", "[LookupWithContext]")
{
moFileReaderSingleton::GetInstance ().ReadFile ("test.mo");
moFileReaderSingleton::GetInstance().ReadFile("test.mo");
/* This is the first comment. */
CHECK ("Text Nederlands Een" == _LC ("TEST|String|1", "String English"));
CHECK("Text Nederlands Een" == _LC("TEST|String|1", "String English"));
/* This is the second comment. */
CHECK ("Text Nederlands Twee" == _LC ("TEST|String|2", "String English"));
CHECK("Text Nederlands Twee" == _LC("TEST|String|2", "String English"));
/* This is the third comment. */
CHECK ("Text Nederlands Drie" == _LC ("TEST|String|3", "String English"));
CHECK("Text Nederlands Drie" == _LC("TEST|String|3", "String English"));
}

View File

@ -1,31 +0,0 @@
<!DOCTYPE HTML PUBLIC "- //W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><style type="text/css">
body { background-color: black; color: silver;}table {width: 80%;}th {background-color: orange;color: black;}hr { color: red;width: 80%; size: 5px; }a:link{color: gold;}a:visited{color: grey;}a:hover{color:blue;}.copyleft{ font-size: 12px; text-align: center;}
</style>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Dump of test.mo</title></head>
<body>
<center>
<h1>test.mo</h1>
<table border="1"><th colspan="2">Project Info</th>
<tr><td>Project-Id-Version</td><td>moFileTest</td></tr>
<tr><td>POT-Creation-Date</td><td>2012-05-20 00:51+0100</td></tr>
<tr><td>PO-Revision-Date</td><td>2012-05-20 00:57+0100</td></tr>
<tr><td>Last-Translator</td><td>scorcher24 &lt;scorcher24@gmail.&gt;om></td></tr>
<tr><td>MIME-Version</td><td>1.0</td></tr>
<tr><td>Content-Type</td><td>text/plain; charset=UTF-8</td></tr>
<tr><td>Content-Transfer-Encoding</td><td>8bit</td></tr>
<tr><td>X-Poedit-KeywordsList</td><td>_;gettext;gettext_noop</td></tr>
<tr><td>X-Poedit-Basepath</td><td>.</td></tr>
<tr><td>X-Poedit-SearchPath-0</td><td>.</td></tr>
</table>
<hr noshade/>
<table border="1"><th colspan="2">Content</th>
<tr><td>String English One</td><td>Zeichenkette Englisch Eins</td></tr>
<tr><td>String English Three</td><td>Zeichenkette Englisch Drei</td></tr>
<tr><td>String English Two</td><td>Zeichenkette Englisch Zwei </td></tr>
</table><br/>
</center>
<div class="copyleft">File generated by <a href="https://github.com/AnotherFoxGuy/MofileReader" target="_blank">moFileReaderSDK</a></div>
</body></html>