diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bbc950..ab046a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ # Run cmake with -DVARNAME=ON/OFF to benefit from those # possible settings. #------------------------------------------------------- -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.0) project(moFileReader) # The main include directory @@ -22,39 +22,28 @@ include_directories(BEFORE ${CMAKE_SOURCE_DIR}/include) # Let the user choose between static lib and dll # To use it, call cmake -DCOMPILE_DLL=ON option(COMPILE_DLL "Set this to ON if you want to compile the library as an DLL. When this is OFF, a static library is created (default)." OFF) - - -if ( NOT COMPILE_DLL ) - - # Static build - add_library(moFileReader.static STATIC ${CMAKE_SOURCE_DIR}/src/moFileReader.cpp ${CMAKE_SOURCE_DIR}/src/mo.cpp) - -else ( COMPILE_DLL ) - +if (COMPILE_DLL) # DLL - add_definitions(-D_USRDLL -DMOFILE_EXPORTS) - add_library(moFileReader SHARED ${CMAKE_SOURCE_DIR}/src/moFileReader.cpp ${CMAKE_SOURCE_DIR}/src/mo.cpp) - + target_compile_definitions(moReader PRIVATE _USRDLL MOFILE_EXPORTS) endif () +add_library(moFileReader STATIC ${CMAKE_SOURCE_DIR}/src/moFileReader.cpp ${CMAKE_SOURCE_DIR}/src/mo.cpp) add_executable(moReader ${CMAKE_SOURCE_DIR}/src/mo.cpp) -if ( NOT COMPILE_DLL ) +if (COMPILE_DLL) + target_compile_definitions(moReader PRIVATE _CONSOLE MOFILE_IMPORT) +else () + target_compile_definitions(moReader PRIVATE _CONSOLE) +endif () -add_definitions(-D_CONSOLE) -add_dependencies(moReader moFileReader.static) -target_link_libraries(moReader moFileReader.static) - -else ( COMPILE_DLL ) - -add_definitions(-D_CONSOLE -DMOFILE_IMPORT) add_dependencies(moReader moFileReader) target_link_libraries(moReader moFileReader) -endif () - - - +option(BUILD_TEST "Set this to ON if you want to build the test" OFF) + +if(BUILD_TEST) + add_subdirectory(test) +endif() diff --git a/src/moFileReader.cpp b/src/moFileReader.cpp index 1c95380..12b3633 100644 --- a/src/moFileReader.cpp +++ b/src/moFileReader.cpp @@ -238,7 +238,7 @@ moFileReader::eErrorCode moFileReader::ReadFile( const char* filename ) if ( MagicReversed != moInfo.m_magicNumber ) { m_error = "The Magic Number does not match in all cases!"; - return moFileReader::EC_MAGICNUMBER_NOMATCH; + //return moFileReader::EC_MAGICNUMBER_NOMATCH; } else { @@ -246,7 +246,7 @@ moFileReader::eErrorCode moFileReader::ReadFile( const char* filename ) m_error = "Magic Number is reversed. We do not support this yet!"; return moFileReader::EC_MAGICNUMBER_REVERSED; } - } + } // Now we search all Length & Offsets of the original strings for ( int i = 0; i < moInfo.m_numStrings; i++ ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..8fef661 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,15 @@ +if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") + message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") + file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.13/conan.cmake" + "${CMAKE_BINARY_DIR}/conan.cmake") +endif() + +include(${CMAKE_BINARY_DIR}/conan.cmake) + +conan_cmake_run(REQUIRES gtest/1.8.1@bincrafters/stable BASIC_SETUP CMAKE_TARGETS BUILD missing) + +add_executable(test test.cpp) +target_link_libraries(test CONAN_PKG::gtest moFileReader) +add_test(NAME mo_test COMMAND test) + +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test.mo DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin/) \ No newline at end of file diff --git a/test/compile_mo.sh b/test/compile_mo.sh new file mode 100644 index 0000000..64bf65c --- /dev/null +++ b/test/compile_mo.sh @@ -0,0 +1,2 @@ +#!/bin/sh +msgfmt -o test.mo test.po \ No newline at end of file diff --git a/test/extract_pot.sh b/test/extract_pot.sh new file mode 100644 index 0000000..6c06cbe --- /dev/null +++ b/test/extract_pot.sh @@ -0,0 +1,2 @@ +#!/bin/sh +xgettext -o test.pot -k_L -s -j test.cpp \ No newline at end of file diff --git a/test/test.cpp b/test/test.cpp index 309d8d6..d7c1d7d 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,6 +1,20 @@ -void foo() + +#include "moFileReader.h" +#include "gtest/gtest.h" + +#define _L(str) moFileLib::moFileReaderSingleton::GetInstance().Lookup(str) + +auto testMo = "test.mo"; + +TEST(moFileReader, setup) { - _("String English One"); - _("String English Two"); - _("String English Three"); + EXPECT_EQ(moFileLib::moFileReaderSingleton::GetInstance().ReadFile(testMo), moFileLib::moFileReader::EC_SUCCESS); +} + +TEST(moFileReader, Lookup) +{ + moFileLib::moFileReaderSingleton::GetInstance().ReadFile(testMo); + EXPECT_EQ("Text Nederlands Een", _L("String English One")); + EXPECT_EQ("Text Nederlands Twee", _L("String English Two")); + EXPECT_EQ("Text Nederlands Drie", _L("String English Three")); } \ No newline at end of file diff --git a/test/test.mo b/test/test.mo index 8c91434..f7e6bd5 100644 Binary files a/test/test.mo and b/test/test.mo differ diff --git a/test/test.po b/test/test.po index 0a793be..0b94561 100644 --- a/test/test.po +++ b/test/test.po @@ -1,27 +1,31 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# msgid "" msgstr "" -"Project-Id-Version: moFileTest\n" +"Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-05-20 00:51+0100\n" -"PO-Revision-Date: 2012-05-20 00:57+0100\n" -"Last-Translator: scorcher24 \n" +"POT-Creation-Date: 2018-12-13 10:49+0100\n" +"PO-Revision-Date: 2018-12-13 11:00+0100\n" +"Last-Translator: \n" "Language-Team: \n" +"Language: nl\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Poedit-KeywordsList: _;gettext;gettext_noop\n" -"X-Poedit-Basepath: .\n" -"X-Poedit-SearchPath-0: .\n" +"X-Generator: Poedit 2.0.6\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: test.cpp:3 +#: test.cpp:21 msgid "String English One" -msgstr "Zeichenkette Englisch Eins" +msgstr "Text Nederlands Een" -#: test.cpp:4 -msgid "String English Two" -msgstr "Zeichenkette Englisch Zwei " - -#: test.cpp:5 +#: test.cpp:23 msgid "String English Three" -msgstr "Zeichenkette Englisch Drei" +msgstr "Text Nederlands Drie" +#: test.cpp:22 +msgid "String English Two" +msgstr "Text Nederlands Twee" diff --git a/test/test.pot b/test/test.pot new file mode 100644 index 0000000..71502d2 --- /dev/null +++ b/test/test.pot @@ -0,0 +1,30 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-12-13 10:49+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: test.cpp:21 +msgid "String English One" +msgstr "" + +#: test.cpp:23 +msgid "String English Three" +msgstr "" + +#: test.cpp:22 +msgid "String English Two" +msgstr ""