PageRenderTime 33ms CodeModel.GetById 13ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/LangFileTests.cpp

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