/tests/LangFileTests.cpp

http://crashrpt.googlecode.com/ · C++ · 176 lines · 111 code · 41 blank · 24 comment · 7 complexity · e85f6d2ecb2c54b731be632c9d84ba58 MD5 · raw file

  1. /*************************************************************************************
  2. This file is a part of CrashRpt library.
  3. Copyright (c) 2003-2013 The CrashRpt project authors. All Rights Reserved.
  4. Use of this source code is governed by a BSD-style license
  5. that can be found in the License.txt file in the root of the source
  6. tree. All contributing project authors may
  7. be found in the Authors.txt file in the root of the source tree.
  8. ***************************************************************************************/
  9. #include "stdafx.h"
  10. #include "Tests.h"
  11. #include "CrashRpt.h"
  12. #include "Utility.h"
  13. #include "strconv.h"
  14. #include "TestUtils.h"
  15. #define MIN(a,b) (a<=b?a:b)
  16. class LangFileTests : public CTestSuite
  17. {
  18. BEGIN_TEST_MAP(LangFileTests, "CrashRpt language file tests")
  19. REGISTER_TEST(Test_lang_file_versions);
  20. REGISTER_TEST(Test_lang_file_strings);
  21. END_TEST_MAP()
  22. public:
  23. void SetUp();
  24. void TearDown();
  25. void Test_lang_file_versions();
  26. void Test_lang_file_strings();
  27. private:
  28. std::vector<CString> m_asLangAbbr; // The list of lang file abbreviations
  29. };
  30. REGISTER_TEST_SUITE( LangFileTests );
  31. void LangFileTests::SetUp()
  32. {
  33. m_asLangAbbr.push_back(_T("DE"));
  34. m_asLangAbbr.push_back(_T("EN"));
  35. m_asLangAbbr.push_back(_T("ES"));
  36. m_asLangAbbr.push_back(_T("FR"));
  37. m_asLangAbbr.push_back(_T("HI"));
  38. m_asLangAbbr.push_back(_T("IT"));
  39. m_asLangAbbr.push_back(_T("PT"));
  40. m_asLangAbbr.push_back(_T("RU"));
  41. m_asLangAbbr.push_back(_T("ZH-CN"));
  42. }
  43. void LangFileTests::TearDown()
  44. {
  45. }
  46. void LangFileTests::Test_lang_file_versions()
  47. {
  48. // This test ensures that CrashRptVersion field of all CrashRpt language files
  49. // equals to CRASHRPT_VER constant value
  50. if(g_bRunningFromUNICODEFolder)
  51. return; // Skip this test if running from another process
  52. const int BUFF_SIZE = 1024;
  53. TCHAR szBuffer[BUFF_SIZE]=_T("");
  54. UINT i;
  55. for(i=0; i<m_asLangAbbr.size(); i++)
  56. {
  57. CString sExePath = Utility::GetModulePath(NULL);
  58. CString sFileName;
  59. #ifndef WIN64
  60. sFileName.Format(_T("%s\\..\\lang_files\\crashrpt_lang_%s.ini"),
  61. sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
  62. #else
  63. sFileName.Format(_T("%s\\..\\..\\lang_files\\crashrpt_lang_%s.ini"),
  64. sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
  65. #endif //!WIN64
  66. GetPrivateProfileString(_T("Settings"), _T("CrashRptVersion"), _T(""), szBuffer, BUFF_SIZE, sFileName);
  67. int nActualVer = _ttoi(szBuffer);
  68. TEST_ASSERT(nActualVer==CRASHRPT_VER);
  69. }
  70. __TEST_CLEANUP__;
  71. }
  72. void LangFileTests::Test_lang_file_strings()
  73. {
  74. // This test ensures that all lang files have the same count of
  75. // sections and the same count of strings in each section.
  76. if(g_bRunningFromUNICODEFolder)
  77. return; // Skip this test if running from another process
  78. strconv_t strconv;
  79. CString sExePath = Utility::GetModulePath(NULL);
  80. // Use EN lang file as template for comparison
  81. CString sTemplateFileName;
  82. #ifndef WIN64
  83. sTemplateFileName.Format(_T("%s\\..\\lang_files\\crashrpt_lang_EN.ini"),
  84. sExePath.GetBuffer(0));
  85. #else
  86. sTemplateFileName.Format(_T("%s\\..\\..\\lang_files\\crashrpt_lang_EN.ini"),
  87. sExePath.GetBuffer(0));
  88. #endif //!WIN64
  89. UINT i;
  90. for(i=0; i<m_asLangAbbr.size(); i++)
  91. {
  92. if(m_asLangAbbr[i]==_T("EN"))
  93. continue; // Skip EN file
  94. // Format i-th file name
  95. CString sFileName;
  96. #ifndef WIN64
  97. sFileName.Format(_T("%s\\..\\lang_files\\crashrpt_lang_%s.ini"),
  98. sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
  99. #else
  100. sFileName.Format(_T("%s\\..\\..\\lang_files\\crashrpt_lang_%s.ini"),
  101. sExePath.GetBuffer(0), m_asLangAbbr[i].GetBuffer(0));
  102. #endif //!WIN64
  103. // Get count of sections in EN file
  104. std::vector<CString> asTemplateSections;
  105. int nTemplateSectionCount = TestUtils::EnumINIFileSections(sTemplateFileName, asTemplateSections);
  106. // Get count of sections in i-th file
  107. std::vector<CString> asSections;
  108. int nSectionCount = TestUtils::EnumINIFileSections(sFileName, asSections);
  109. // Ensure section count is the same
  110. TEST_ASSERT_MSG(nTemplateSectionCount==nSectionCount, "Count of INI sections is different in lang files EN and %s", strconv.t2a(m_asLangAbbr[i]));
  111. // Now compare strings in each section
  112. int nSection = 0;
  113. for(nSection = 0; nSection<nTemplateSectionCount; nSection++)
  114. {
  115. // Get count of strings in n-th section in EN file
  116. std::vector<CString> asTemplateStrings;
  117. int nTemplateStringCount = TestUtils::EnumINIFileStrings(sTemplateFileName, asTemplateSections[nSection], asTemplateStrings);
  118. // Get count of strings in n-th section in i-th file
  119. std::vector<CString> asStrings;
  120. int nStringCount = TestUtils::EnumINIFileStrings(sFileName, asTemplateSections[nSection], asStrings);
  121. // Compare string names
  122. size_t nStr;
  123. for(nStr=0; nStr<MIN(asTemplateStrings.size(), asStrings.size()); nStr++)
  124. {
  125. // Ensure string names are the same
  126. TEST_ASSERT_MSG(asTemplateStrings[nStr]==asStrings[nStr], "Names of INI strings #%d in section %s are different in lang files EN and %s : %s and %s",
  127. nStr, strconv.t2a(asTemplateSections[nSection]), strconv.t2a(m_asLangAbbr[i]), strconv.t2a(asTemplateStrings[nStr]), strconv.t2a(asStrings[nStr]));
  128. }
  129. // Ensure string count is the same
  130. TEST_ASSERT_MSG(nTemplateStringCount==nStringCount, "Count of INI strings in section %s is different in lang files EN and %s", strconv.t2a(asTemplateSections[nSection]), strconv.t2a(m_asLangAbbr[i]));
  131. }
  132. }
  133. __TEST_CLEANUP__;
  134. }