✨ Added LookupWithContext
This commit is contained in:
		| @@ -8,8 +8,13 @@ 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) | ||||
| add_executable(moFileReaderTest test.cpp) | ||||
| target_include_directories(moFileReaderTest PRIVATE ${CMAKE_SOURCE_DIR}/include) | ||||
| target_link_libraries(moFileReaderTest CONAN_PKG::gtest moFileReader) | ||||
| add_test(NAME mo_test COMMAND moFileReaderTest) | ||||
|  | ||||
| file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test.mo DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin/) | ||||
| 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 | ||||
| ) | ||||
|   | ||||
| @@ -1,2 +1,2 @@ | ||||
| #!/bin/sh | ||||
| xgettext -o test.pot -k_L -s -j test.cpp | ||||
| xgettext -o test.pot -k_ -k"_LC:1c,2" -s -c --package-name=moFileReader test.cpp | ||||
| @@ -2,19 +2,35 @@ | ||||
| #include "moFileReader.h" | ||||
| #include "gtest/gtest.h" | ||||
|  | ||||
| #define _L(str) moFileLib::moFileReaderSingleton::GetInstance().Lookup(str) | ||||
| using namespace moFileLib; | ||||
| #define _LC(ctx,str) moFileReaderSingleton::GetInstance().LookupWithContext(ctx,str) | ||||
|  | ||||
| auto testMo = "test.mo"; | ||||
|  | ||||
| TEST(moFileReader, setup) | ||||
| { | ||||
| 	EXPECT_EQ(moFileLib::moFileReaderSingleton::GetInstance().ReadFile(testMo), moFileLib::moFileReader::EC_SUCCESS); | ||||
| 	EXPECT_EQ(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")); | ||||
|     moFileReaderSingleton::GetInstance ().ReadFile (testMo); | ||||
|     /* This is the first comment. */ | ||||
|     EXPECT_EQ ("Text Nederlands Een", _ ("String English One")); | ||||
|     /* This is the second comment. */ | ||||
|     EXPECT_EQ ("Text Nederlands Twee", _ ("String English Two")); | ||||
|     /* This is the third comment.  */ | ||||
|     EXPECT_EQ ("Text Nederlands Drie", _ ("String English Three")); | ||||
| } | ||||
|  | ||||
|  | ||||
| TEST (moFileReader, LookupWithContext) | ||||
| { | ||||
|     moFileReaderSingleton::GetInstance ().ReadFile (testMo); | ||||
|     /* This is the first comment. */ | ||||
|     EXPECT_EQ ("Text Nederlands Een", _LC ("TEST|String|1", "String English")); | ||||
|     /* This is the second comment. */ | ||||
|     EXPECT_EQ ("Text Nederlands Twee", _LC ("TEST|String|2", "String English")); | ||||
|     /* This is the third comment.  */ | ||||
|     EXPECT_EQ ("Text Nederlands Drie", _LC ("TEST|String|3", "String English")); | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								test/test.mo
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/test.mo
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										51
									
								
								test/test.po
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								test/test.po
									
									
									
									
									
								
							| @@ -5,27 +5,64 @@ | ||||
| # | ||||
| msgid "" | ||||
| msgstr "" | ||||
| "Project-Id-Version: \n" | ||||
| "Project-Id-Version: moFileReader\n" | ||||
| "Report-Msgid-Bugs-To: \n" | ||||
| "POT-Creation-Date: 2018-12-13 10:49+0100\n" | ||||
| "PO-Revision-Date: 2018-12-13 11:00+0100\n" | ||||
| "POT-Creation-Date: 2018-12-13 14:39+0100\n" | ||||
| "PO-Revision-Date: 2018-12-13 14:40+0100\n" | ||||
| "Last-Translator: \n" | ||||
| "Language-Team: \n" | ||||
| "Language-Team: Test\n" | ||||
| "Language: nl\n" | ||||
| "MIME-Version: 1.0\n" | ||||
| "Content-Type: text/plain; charset=UTF-8\n" | ||||
| "Content-Transfer-Encoding: 8bit\n" | ||||
| "X-Generator: Poedit 2.0.6\n" | ||||
| "Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||||
| "X-Generator: Poedit 2.2\n" | ||||
|  | ||||
| #: test.cpp:21 | ||||
| #. This is the first comment. | ||||
| #: test.cpp:31 | ||||
| msgctxt "TEST|String|1" | ||||
| msgid "String English" | ||||
| msgstr "Text Nederlands Een" | ||||
|  | ||||
| #. This is the second comment. | ||||
| #: test.cpp:33 | ||||
| msgctxt "TEST|String|2" | ||||
| msgid "String English" | ||||
| msgstr "Text Nederlands Twee" | ||||
|  | ||||
| #. This is the third comment. | ||||
| #: test.cpp:35 | ||||
| msgctxt "TEST|String|3" | ||||
| msgid "String English" | ||||
| msgstr "Text Nederlands Drie" | ||||
|  | ||||
| #. This is the first comment. | ||||
| #: test.cpp:19 | ||||
| msgid "String English One" | ||||
| msgstr "Text Nederlands Een" | ||||
|  | ||||
| #. This is the third comment. | ||||
| #: test.cpp:23 | ||||
| msgid "String English Three" | ||||
| msgstr "Text Nederlands Drie" | ||||
|  | ||||
| #: test.cpp:22 | ||||
| #. This is the second comment. | ||||
| #: test.cpp:21 | ||||
| msgid "String English Two" | ||||
| msgstr "Text Nederlands Twee" | ||||
|  | ||||
| #~ msgctxt "TEST|String|1" | ||||
| #~ msgid "String English One" | ||||
| #~ msgstr "Text Nederlands Een" | ||||
|  | ||||
| #~ msgctxt "TEST|String|3" | ||||
| #~ msgid "String English Three" | ||||
| #~ msgstr "Text Nederlands Drie" | ||||
|  | ||||
| #~ msgctxt "TEST|String|2" | ||||
| #~ msgid "String English Two" | ||||
| #~ msgstr "Text Nederlands Twee" | ||||
|  | ||||
| #~ msgctxt "Menu|" | ||||
| #~ msgid "File" | ||||
| #~ msgstr "Bestand" | ||||
|   | ||||
| @@ -1,30 +1,51 @@ | ||||
| # SOME DESCRIPTIVE TITLE. | ||||
| # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||||
| # This file is distributed under the same license as the PACKAGE package. | ||||
| # This file is distributed under the same license as the moFileReader package. | ||||
| # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||||
| # | ||||
| #, fuzzy | ||||
| msgid "" | ||||
| msgstr "" | ||||
| "Project-Id-Version: PACKAGE VERSION\n" | ||||
| "Project-Id-Version: moFileReader\n" | ||||
| "Report-Msgid-Bugs-To: \n" | ||||
| "POT-Creation-Date: 2018-12-13 10:49+0100\n" | ||||
| "POT-Creation-Date: 2018-12-13 14:39+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-Type: text/plain; charset=CHARSET\n" | ||||
| "Content-Transfer-Encoding: 8bit\n" | ||||
|  | ||||
| #: test.cpp:21 | ||||
| #. This is the first comment. | ||||
| #: test.cpp:31 | ||||
| msgctxt "TEST|String|1" | ||||
| msgid "String English" | ||||
| msgstr "" | ||||
|  | ||||
| #. This is the second comment. | ||||
| #: test.cpp:33 | ||||
| msgctxt "TEST|String|2" | ||||
| msgid "String English" | ||||
| msgstr "" | ||||
|  | ||||
| #. This is the third comment. | ||||
| #: test.cpp:35 | ||||
| msgctxt "TEST|String|3" | ||||
| msgid "String English" | ||||
| msgstr "" | ||||
|  | ||||
| #. This is the first comment. | ||||
| #: test.cpp:19 | ||||
| msgid "String English One" | ||||
| msgstr "" | ||||
|  | ||||
| #. This is the third comment. | ||||
| #: test.cpp:23 | ||||
| msgid "String English Three" | ||||
| msgstr "" | ||||
|  | ||||
| #: test.cpp:22 | ||||
| #. This is the second comment. | ||||
| #: test.cpp:21 | ||||
| msgid "String English Two" | ||||
| msgstr "" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user