1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "PersonalDictionary.h"
22 #include "StringUtils.h"
23 #include "PathUtils.h"
25 #define LCID_INVALID 11 // use 11 here which is not a valid language code so that we don't overwrite dictionaries
27 static CString
GetPath(LONG languageID
)
30 path
.Format(L
"%s%ld.dic", (LPCTSTR
)CPathUtils::GetAppDataDirectory(), languageID
);
34 TEST(CPersonalDictionary
, UseDictionary
)
36 ASSERT_FALSE(PathFileExists(GetPath(LCID_INVALID
)));
37 CPersonalDictionary dict
;
38 dict
.Init(LCID_INVALID
);
40 for (const CString
& word
: { L
"", L
"Test", L
"Täst", L
"рефакторинг" })
41 EXPECT_FALSE(dict
.FindWord(word
));
43 const CString in
[] = { L
"Test", L
"Täst", L
"рефакторинг" };
45 EXPECT_FALSE(dict
.AddWord(L
""));
46 for (const CString
& word
: in
)
48 EXPECT_TRUE(dict
.AddWord(word
));
49 EXPECT_TRUE(dict
.FindWord(word
));
50 EXPECT_TRUE(dict
.AddWord(word
));
53 TCHAR tooLong
[PDICT_MAX_WORD_LENGTH
+ 5] = { 0 };
54 for (int i
= 0; i
< _countof(tooLong
); ++i
)
56 EXPECT_FALSE(dict
.AddWord(tooLong
));
57 EXPECT_FALSE(dict
.FindWord(tooLong
));
60 EXPECT_FALSE(dict
.FindWord(L
"test"));
61 EXPECT_TRUE(dict
.AddWord(L
"test"));
63 EXPECT_TRUE(dict
.Save());
64 EXPECT_TRUE(dict
.FindWord(L
"test")); // Save does not clear the list
65 EXPECT_TRUE(PathFileExists(GetPath(LCID_INVALID
)));
67 // load safed words in ne dictionary
68 CPersonalDictionary dict2
;
69 dict2
.Init(LCID_INVALID
);
70 for (const CString
& word
: in
)
71 EXPECT_TRUE(dict2
.FindWord(word
));
72 EXPECT_TRUE(dict2
.FindWord(L
"test"));
73 EXPECT_FALSE(dict2
.FindWord(L
"test2"));
75 EXPECT_TRUE(DeleteFile(GetPath(LCID_INVALID
)));
78 TEST(CPersonalDictionary
, LoadDictionary
)
80 ASSERT_FALSE(PathFileExists(GetPath(LCID_INVALID
)));
81 CPersonalDictionary dict
;
82 dict
.Init(LCID_INVALID
);
84 ASSERT_TRUE(CStringUtils::WriteStringToTextFile(GetPath(LCID_INVALID
), L
"\nTest\n\u0440\u0435\u0444\u0430\u043A\u0442\u043E\u0440\u0438\u043D\u0433\r\nTäst\n"));
86 EXPECT_FALSE(dict
.FindWord(L
""));
87 for (const CString
& word
: { L
"Test", L
"Täst", L
"\u0440\u0435\u0444\u0430\u043A\u0442\u043E\u0440\u0438\u043D\u0433" })
88 EXPECT_TRUE(dict
.FindWord(word
));
90 EXPECT_FALSE(dict
.FindWord(L
"something"));
92 EXPECT_TRUE(DeleteFile(GetPath(LCID_INVALID
)));