✅ Added unit-tests
This commit is contained in:
		| @@ -12,7 +12,7 @@ | |||||||
| # Run cmake with -DVARNAME=ON/OFF to benefit from those | # Run cmake with -DVARNAME=ON/OFF to benefit from those | ||||||
| # possible settings. | # possible settings. | ||||||
| #------------------------------------------------------- | #------------------------------------------------------- | ||||||
| cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 3.0) | ||||||
| project(moFileReader) | project(moFileReader) | ||||||
|  |  | ||||||
| # The main include directory | # The main include directory | ||||||
| @@ -22,39 +22,28 @@ include_directories(BEFORE ${CMAKE_SOURCE_DIR}/include) | |||||||
| # Let the user choose between static lib and dll | # Let the user choose between static lib and dll | ||||||
| # To use it, call cmake -DCOMPILE_DLL=ON | # 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) | 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 (COMPILE_DLL) | ||||||
|  |  | ||||||
| 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 ) |  | ||||||
|  |  | ||||||
|     # DLL |     # DLL | ||||||
|     add_definitions(-D_USRDLL -DMOFILE_EXPORTS) |     target_compile_definitions(moReader PRIVATE _USRDLL MOFILE_EXPORTS) | ||||||
|     add_library(moFileReader SHARED ${CMAKE_SOURCE_DIR}/src/moFileReader.cpp ${CMAKE_SOURCE_DIR}/src/mo.cpp) |  | ||||||
|  |  | ||||||
| endif () | 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) | 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) | add_dependencies(moReader moFileReader) | ||||||
| target_link_libraries(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() | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -238,7 +238,7 @@ moFileReader::eErrorCode moFileReader::ReadFile( const char* filename ) | |||||||
|         if ( MagicReversed != moInfo.m_magicNumber ) |         if ( MagicReversed != moInfo.m_magicNumber ) | ||||||
|         { |         { | ||||||
|             m_error = "The Magic Number does not match in all cases!"; |             m_error = "The Magic Number does not match in all cases!"; | ||||||
|             return moFileReader::EC_MAGICNUMBER_NOMATCH; |             //return moFileReader::EC_MAGICNUMBER_NOMATCH; | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
| @@ -246,7 +246,7 @@ moFileReader::eErrorCode moFileReader::ReadFile( const char* filename ) | |||||||
|             m_error = "Magic Number is reversed. We do not support this yet!"; |             m_error = "Magic Number is reversed. We do not support this yet!"; | ||||||
|             return moFileReader::EC_MAGICNUMBER_REVERSED; |             return moFileReader::EC_MAGICNUMBER_REVERSED; | ||||||
|         } |         } | ||||||
|     }   |     } | ||||||
|      |      | ||||||
|     // Now we search all Length & Offsets of the original strings |     // Now we search all Length & Offsets of the original strings | ||||||
|     for ( int i = 0; i < moInfo.m_numStrings; i++ ) |     for ( int i = 0; i < moInfo.m_numStrings; i++ ) | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								test/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								test/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -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/) | ||||||
							
								
								
									
										2
									
								
								test/compile_mo.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								test/compile_mo.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | #!/bin/sh | ||||||
|  | msgfmt -o test.mo test.po | ||||||
							
								
								
									
										2
									
								
								test/extract_pot.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								test/extract_pot.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | #!/bin/sh | ||||||
|  | xgettext -o test.pot -k_L -s -j 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"); | 	EXPECT_EQ(moFileLib::moFileReaderSingleton::GetInstance().ReadFile(testMo), moFileLib::moFileReader::EC_SUCCESS); | ||||||
| 	_("String English Two"); | } | ||||||
| 	_("String English Three"); |  | ||||||
|  | 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")); | ||||||
| } | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								test/test.mo
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/test.mo
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										34
									
								
								test/test.po
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								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 <EMAIL@ADDRESS>, YEAR. | ||||||
|  | # | ||||||
| msgid "" | msgid "" | ||||||
| msgstr "" | msgstr "" | ||||||
| "Project-Id-Version: moFileTest\n" | "Project-Id-Version: \n" | ||||||
| "Report-Msgid-Bugs-To: \n" | "Report-Msgid-Bugs-To: \n" | ||||||
| "POT-Creation-Date: 2012-05-20 00:51+0100\n" | "POT-Creation-Date: 2018-12-13 10:49+0100\n" | ||||||
| "PO-Revision-Date: 2012-05-20 00:57+0100\n" | "PO-Revision-Date: 2018-12-13 11:00+0100\n" | ||||||
| "Last-Translator: scorcher24 <scorcher24@gmail.com>\n" | "Last-Translator: \n" | ||||||
| "Language-Team: \n" | "Language-Team: \n" | ||||||
|  | "Language: nl\n" | ||||||
| "MIME-Version: 1.0\n" | "MIME-Version: 1.0\n" | ||||||
| "Content-Type: text/plain; charset=UTF-8\n" | "Content-Type: text/plain; charset=UTF-8\n" | ||||||
| "Content-Transfer-Encoding: 8bit\n" | "Content-Transfer-Encoding: 8bit\n" | ||||||
| "X-Poedit-KeywordsList: _;gettext;gettext_noop\n" | "X-Generator: Poedit 2.0.6\n" | ||||||
| "X-Poedit-Basepath: .\n" | "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||||||
| "X-Poedit-SearchPath-0: .\n" |  | ||||||
|  |  | ||||||
| #: test.cpp:3 | #: test.cpp:21 | ||||||
| msgid "String English One" | msgid "String English One" | ||||||
| msgstr "Zeichenkette Englisch Eins" | msgstr "Text Nederlands Een" | ||||||
|  |  | ||||||
| #: test.cpp:4 | #: test.cpp:23 | ||||||
| msgid "String English Two" |  | ||||||
| msgstr "Zeichenkette Englisch Zwei" |  | ||||||
|  |  | ||||||
| #: test.cpp:5 |  | ||||||
| msgid "String English Three" | msgid "String English Three" | ||||||
| msgstr "Zeichenkette Englisch Drei" | msgstr "Text Nederlands Drie" | ||||||
|  |  | ||||||
|  | #: test.cpp:22 | ||||||
|  | msgid "String English Two" | ||||||
|  | msgstr "Text Nederlands Twee" | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								test/test.pot
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								test/test.pot
									
									
									
									
									
										Normal file
									
								
							| @@ -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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n" | ||||||
|  | "Language-Team: LANGUAGE <LL@li.org>\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 "" | ||||||
		Reference in New Issue
	
	Block a user