Increase timeout
[TortoiseGit.git] / test / UnitTests / LogDataVectorTest.cpp
blobfe5eabed985ffa8d20bffc89eaf37e1bdbd26af8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015 - 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.
20 #include "stdafx.h"
21 #include "RepositoryFixtures.h"
22 #include "LogDlgHelper.h"
24 class CLogDataVectorCBasicGitWithTestRepoFixture : public CBasicGitWithTestRepoFixture
28 class CLogDataVectorCBasicGitWithEmptyRepositoryFixturee : public CBasicGitWithEmptyRepositoryFixture
32 class CLogDataVectorCBasicGitWithTestRepoBareFixture : public CBasicGitWithTestRepoBareFixture
36 class CLogDataVectorCBasicGitWithEmptyBareRepositoryFixturee : public CBasicGitWithEmptyBareRepositoryFixture
40 INSTANTIATE_TEST_CASE_P(CLogDataVector, CLogDataVectorCBasicGitWithTestRepoFixture, testing::Values(LIBGIT));
41 INSTANTIATE_TEST_CASE_P(CLogDataVector, CLogDataVectorCBasicGitWithTestRepoBareFixture, testing::Values(LIBGIT));
42 INSTANTIATE_TEST_CASE_P(CLogDataVector, CLogDataVectorCBasicGitWithEmptyRepositoryFixturee, testing::Values(LIBGIT));
43 INSTANTIATE_TEST_CASE_P(CLogDataVector, CLogDataVectorCBasicGitWithEmptyBareRepositoryFixturee, testing::Values(LIBGIT));
45 TEST(CLogDataVector, Empty)
47 CLogDataVector logDataVector;
48 logDataVector.m_logOrderBy = CGit::LOG_ORDER_TOPOORDER;
50 EXPECT_EQ(0, logDataVector.size());
51 EXPECT_EQ(0, logDataVector.m_HashMap.size());
54 TEST(CLogCache, GetCacheData)
56 CLogCache logCache;
57 EXPECT_EQ(0, logCache.m_HashMap.size());
58 CGitHash hash1(L"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44");
59 GitRevLoglist* pRev = logCache.GetCacheData(hash1);
60 ASSERT_TRUE(pRev);
61 EXPECT_EQ(hash1, pRev->m_CommitHash);
62 EXPECT_EQ(1, logCache.m_HashMap.size());
64 CGitHash hash2(L"dead91b4aedeaddeaddead2a56d3c473c705dead");
65 pRev = logCache.GetCacheData(hash2);
66 ASSERT_TRUE(pRev);
67 EXPECT_EQ(hash2, pRev->m_CommitHash);
68 EXPECT_EQ(2, logCache.m_HashMap.size());
71 TEST(CLogCache, ClearAllParent)
73 CLogCache logCache;
74 CGitHash hash1(L"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44");
75 GitRevLoglist* pRev = logCache.GetCacheData(hash1);
76 ASSERT_TRUE(pRev);
77 pRev->m_ParentHash.push_back(CGitHash(L"0000000000000000000000000000000000000000"));
78 EXPECT_EQ(1, pRev->m_ParentHash.size());
79 pRev->m_Lanes.push_back(1);
80 pRev->m_Lanes.push_back(2);
81 pRev->m_Lanes.push_back(3);
82 EXPECT_EQ(3, pRev->m_Lanes.size());
83 CGitHash hash2(L"dead91b4aedeaddeaddead2a56d3c473c705dead");
84 pRev = logCache.GetCacheData(hash2);
85 ASSERT_TRUE(pRev);
86 pRev->m_ParentHash.push_back(CGitHash(L"1111111111111111111111111111111111111111"));
87 pRev->m_ParentHash.push_back(CGitHash(L"1111111111111111111111111111111111111112"));
88 EXPECT_EQ(2, pRev->m_ParentHash.size());
89 pRev->m_Lanes.push_back(4);
90 EXPECT_EQ(1, pRev->m_Lanes.size());
92 logCache.ClearAllParent();
93 pRev = logCache.GetCacheData(hash1);
94 ASSERT_TRUE(pRev);
95 EXPECT_EQ(0, pRev->m_ParentHash.size());
96 EXPECT_EQ(0, pRev->m_Lanes.size());
98 pRev = logCache.GetCacheData(hash2);
99 ASSERT_TRUE(pRev);
100 EXPECT_EQ(0, pRev->m_ParentHash.size());
101 EXPECT_EQ(0, pRev->m_Lanes.size());
104 TEST(CLogCache, ClearAllLanes)
106 CLogCache logCache;
107 CGitHash hash1(L"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44");
108 GitRevLoglist* pRev = logCache.GetCacheData(hash1);
109 ASSERT_TRUE(pRev);
110 pRev->m_ParentHash.push_back(CGitHash(L"0000000000000000000000000000000000000000"));
111 EXPECT_EQ(1, pRev->m_ParentHash.size());
112 pRev->m_Lanes.push_back(1);
113 pRev->m_Lanes.push_back(2);
114 pRev->m_Lanes.push_back(3);
115 EXPECT_EQ(3, pRev->m_Lanes.size());
116 CGitHash hash2(L"dead91b4aedeaddeaddead2a56d3c473c705dead");
117 pRev = logCache.GetCacheData(hash2);
118 ASSERT_TRUE(pRev);
119 pRev->m_ParentHash.push_back(CGitHash(L"1111111111111111111111111111111111111111"));
120 pRev->m_ParentHash.push_back(CGitHash(L"1111111111111111111111111111111111111112"));
121 EXPECT_EQ(2, pRev->m_ParentHash.size());
122 pRev->m_Lanes.push_back(4);
123 EXPECT_EQ(1, pRev->m_Lanes.size());
125 logCache.ClearAllLanes();
126 pRev = logCache.GetCacheData(hash1);
127 ASSERT_TRUE(pRev);
128 EXPECT_EQ(1, pRev->m_ParentHash.size());
129 EXPECT_EQ(0, pRev->m_Lanes.size());
131 pRev = logCache.GetCacheData(hash2);
132 ASSERT_TRUE(pRev);
133 EXPECT_EQ(2, pRev->m_ParentHash.size());
134 EXPECT_EQ(0, pRev->m_Lanes.size());
138 static void ParserFromLogTests()
140 CLogCache logCache;
141 CLogDataVector logDataVector;
142 logDataVector.m_logOrderBy = CGit::LOG_ORDER_TOPOORDER;
143 logDataVector.SetLogCache(&logCache);
145 EXPECT_EQ(0, logDataVector.ParserFromLog());
146 EXPECT_EQ(12, logDataVector.size());
147 EXPECT_EQ(12, logDataVector.m_HashMap.size());
148 EXPECT_EQ(12, logCache.m_HashMap.size());
150 logCache.m_HashMap.clear();
151 logDataVector.ClearAll();
152 EXPECT_EQ(0, logDataVector.size());
153 EXPECT_EQ(0, logDataVector.m_HashMap.size());
154 EXPECT_EQ(0, logCache.m_HashMap.size());
156 EXPECT_EQ(0, logDataVector.ParserFromLog(nullptr, 5));
157 ASSERT_EQ(5, logDataVector.size());
158 EXPECT_EQ(5, logDataVector.m_HashMap.size());
159 EXPECT_EQ(5, logCache.m_HashMap.size());
160 EXPECT_STREQ(L"Changed ASCII file", logDataVector.GetGitRevAt(0).GetSubject());
161 EXPECT_STREQ(L"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6", logDataVector.GetGitRevAt(0).m_CommitHash.ToString());
162 EXPECT_STREQ(L"49ecdfff36bfe2b9b499b33e5034f427e2fa54dd", logDataVector.GetGitRevAt(2).m_CommitHash.ToString());
163 EXPECT_STREQ(L"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector.GetGitRevAt(4).m_CommitHash.ToString());
165 logCache.m_HashMap.clear();
166 logDataVector.ClearAll();
167 EXPECT_EQ(0, logDataVector.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH));
168 ASSERT_EQ(23, logDataVector.size());
169 EXPECT_EQ(23, logDataVector.m_HashMap.size());
170 EXPECT_EQ(23, logCache.m_HashMap.size());
171 EXPECT_STREQ(L"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44", logDataVector.GetGitRevAt(0).m_CommitHash.ToString());
172 EXPECT_STREQ(L"4517b91ee8f7497d40cf93d112f12196a7cec995", logDataVector.GetGitRevAt(11).m_CommitHash.ToString());
173 EXPECT_STREQ(L"844309789a13614b52d5e7cbfe6350dd73d1dc72", logDataVector.GetGitRevAt(22).m_CommitHash.ToString());
175 logCache.m_HashMap.clear();
176 logDataVector.ClearAll();
177 CString range(L"does-not-exist");
178 EXPECT_EQ(-1, logDataVector.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH, &range));
179 EXPECT_EQ(0, logDataVector.size());
180 EXPECT_EQ(0, logDataVector.m_HashMap.size());
181 EXPECT_EQ(0, logCache.m_HashMap.size());
183 EXPECT_EQ(-1, logDataVector.ParserFromLog(nullptr, 0, 0, &range));
184 EXPECT_EQ(0, logDataVector.size());
185 EXPECT_EQ(0, logDataVector.m_HashMap.size());
186 EXPECT_EQ(0, logCache.m_HashMap.size());
188 logCache.m_HashMap.clear();
189 logDataVector.ClearAll();
190 range = L"master2..master";
191 EXPECT_EQ(0, logDataVector.ParserFromLog(nullptr, 0, 0, &range));
192 ASSERT_EQ(2, logDataVector.size());
193 EXPECT_EQ(2, logDataVector.m_HashMap.size());
194 EXPECT_EQ(2, logCache.m_HashMap.size());
195 EXPECT_STREQ(L"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6", logDataVector.GetGitRevAt(0).m_CommitHash.ToString());
196 EXPECT_STREQ(L"1fc3c9688e27596d8717b54f2939dc951568f6cb", logDataVector.GetGitRevAt(1).m_CommitHash.ToString());
198 logCache.m_HashMap.clear();
199 logDataVector.ClearAll();
200 EXPECT_EQ(0, logDataVector.ParserFromLog(nullptr, 0, CGit::LOG_INFO_ALL_BRANCH, &range));
201 ASSERT_EQ(13, logDataVector.size());
202 EXPECT_EQ(13, logDataVector.m_HashMap.size());
203 EXPECT_EQ(13, logCache.m_HashMap.size());
205 logCache.m_HashMap.clear();
206 logDataVector.ClearAll();
207 CTGitPath path(L"does-not-exist.txt");
208 EXPECT_EQ(0, logDataVector.ParserFromLog(&path));
209 EXPECT_EQ(0, logDataVector.size());
210 EXPECT_EQ(0, logDataVector.m_HashMap.size());
211 EXPECT_EQ(0, logCache.m_HashMap.size());
213 logCache.m_HashMap.clear();
214 logDataVector.ClearAll();
215 path = CTGitPath(L"copy/utf16-be-bom.txt");
216 EXPECT_EQ(0, logDataVector.ParserFromLog(&path));
217 ASSERT_EQ(2, logDataVector.size());
218 EXPECT_EQ(2, logDataVector.m_HashMap.size());
219 EXPECT_EQ(2, logCache.m_HashMap.size());
220 EXPECT_STREQ(L"49ecdfff36bfe2b9b499b33e5034f427e2fa54dd", logDataVector.GetGitRevAt(0).m_CommitHash.ToString());
221 EXPECT_STREQ(L"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector.GetGitRevAt(1).m_CommitHash.ToString());
223 logCache.m_HashMap.clear();
224 logDataVector.ClearAll();
225 EXPECT_EQ(0, logDataVector.ParserFromLog(&path, 0, CGit::LOG_INFO_FOLLOW));
226 ASSERT_EQ(4, logDataVector.size());
227 EXPECT_EQ(4, logDataVector.m_HashMap.size());
228 EXPECT_EQ(4, logCache.m_HashMap.size());
229 EXPECT_STREQ(L"49ecdfff36bfe2b9b499b33e5034f427e2fa54dd", logDataVector.GetGitRevAt(0).m_CommitHash.ToString());
230 EXPECT_STREQ(L"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector.GetGitRevAt(1).m_CommitHash.ToString());
231 EXPECT_STREQ(L"ff1fbef1a54a9849afd4a5e94d2ca4d80d5b96c2", logDataVector.GetGitRevAt(3).m_CommitHash.ToString());
233 logCache.m_HashMap.clear();
234 logDataVector.ClearAll();
235 range = L"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44";
236 EXPECT_EQ(0, logDataVector.ParserFromLog(&path, 0, CGit::LOG_INFO_FOLLOW, &range));
237 ASSERT_EQ(3, logDataVector.size());
238 EXPECT_EQ(3, logDataVector.m_HashMap.size());
239 EXPECT_EQ(3, logCache.m_HashMap.size());
240 EXPECT_STREQ(L"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector.GetGitRevAt(0).m_CommitHash.ToString());
241 EXPECT_STREQ(L"a9d53b535cb49640a6099860ac4999f5a0857b91", logDataVector.GetGitRevAt(1).m_CommitHash.ToString());
242 EXPECT_STREQ(L"ff1fbef1a54a9849afd4a5e94d2ca4d80d5b96c2", logDataVector.GetGitRevAt(2).m_CommitHash.ToString());
244 logCache.m_HashMap.clear();
245 logDataVector.ClearAll();
246 EXPECT_EQ(0, logDataVector.ParserFromLog(&path, 0, CGit::LOG_INFO_FULL_DIFF, &range));
247 ASSERT_EQ(1, logDataVector.size());
248 EXPECT_EQ(1, logDataVector.m_HashMap.size());
249 EXPECT_EQ(1, logCache.m_HashMap.size());
250 EXPECT_STREQ(L"560deea87853158b22d0c0fd73f60a458d47838a", logDataVector.GetGitRevAt(0).m_CommitHash.ToString());
253 TEST_P(CLogDataVectorCBasicGitWithTestRepoFixture, ParserFromLog)
255 ParserFromLogTests();
258 TEST_P(CLogDataVectorCBasicGitWithTestRepoBareFixture, ParserFromLog)
260 ParserFromLogTests();
263 static void ParserFromLogTests_EmptyRepo()
265 CLogCache logCache;
266 CLogDataVector logDataVector;
267 logDataVector.m_logOrderBy = CGit::LOG_ORDER_TOPOORDER;
268 logDataVector.SetLogCache(&logCache);
269 EXPECT_EQ(-1, logDataVector.ParserFromLog());
270 EXPECT_EQ(0, logDataVector.size());
271 EXPECT_EQ(0, logDataVector.m_HashMap.size());
272 EXPECT_EQ(0, logCache.m_HashMap.size());
275 TEST_P(CLogDataVectorCBasicGitWithEmptyRepositoryFixturee, ParserFromLog)
277 ParserFromLogTests_EmptyRepo();
280 TEST_P(CLogDataVectorCBasicGitWithEmptyBareRepositoryFixturee, ParserFromLog)
282 ParserFromLogTests_EmptyRepo();
285 static void FillTests()
287 CLogCache logCache;
288 CLogDataVector logDataVector;
289 logDataVector.m_logOrderBy = CGit::LOG_ORDER_TOPOORDER;
290 logDataVector.SetLogCache(&logCache);
292 std::set<CGitHash> hashes;
293 EXPECT_EQ(0, logDataVector.Fill(hashes));
294 EXPECT_EQ(0, logDataVector.size());
295 EXPECT_EQ(0, logCache.m_HashMap.size());
297 hashes.insert(CGitHash(L"35c91b4ae2f77f4f21a7aba56d3c473c705d89e6"));
298 logCache.m_HashMap.clear();
299 logDataVector.ClearAll();
300 EXPECT_EQ(0, logDataVector.Fill(hashes));
301 ASSERT_EQ(1, logDataVector.size());
302 EXPECT_TRUE(logDataVector.GetGitRevAt(0).m_CommitHash.ToString() == L"35c91b4ae2f77f4f21a7aba56d3c473c705d89e6");
303 EXPECT_EQ(1, logCache.m_HashMap.size());
305 hashes.insert(CGitHash(L"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6"));
306 logCache.m_HashMap.clear();
307 logDataVector.ClearAll();
308 EXPECT_EQ(0, logDataVector.Fill(hashes));
309 EXPECT_EQ(2, logDataVector.size());
310 EXPECT_EQ(2, logCache.m_HashMap.size());
312 hashes.insert(CGitHash(L"dead91b4aedeaddeaddead2a56d3c473c705dead")); // non-existent commit
313 logCache.m_HashMap.clear();
314 logDataVector.ClearAll();
315 EXPECT_EQ(-1, logDataVector.Fill(hashes));
316 EXPECT_EQ(0, logDataVector.size());
317 // size of logCache.m_HashMap.size() depends on the order of the set
321 TEST_P(CLogDataVectorCBasicGitWithTestRepoFixture, Fill)
323 FillTests();
326 TEST_P(CLogDataVectorCBasicGitWithTestRepoBareFixture, Fill)
328 FillTests();