Drop unused charset
[TortoiseGit.git] / test / UnitTests / GitRevTest.cpp
blobdd3233e16ce29ce0e449c509d226fa2b52bae387
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2017 - 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 "GitRev.h"
24 class GitRevCBasicGitWithTestRepoFixture : public CBasicGitWithTestRepoFixture
28 class GitRevCBasicGitWithTestRepoBareFixture : public CBasicGitWithTestRepoBareFixture
32 INSTANTIATE_TEST_CASE_P(GitRev, GitRevCBasicGitWithTestRepoFixture, testing::Values(LIBGIT, LIBGIT2, LIBGIT2_ALL));
33 INSTANTIATE_TEST_CASE_P(GitRev, GitRevCBasicGitWithTestRepoBareFixture, testing::Values(LIBGIT, LIBGIT2, LIBGIT2_ALL));
35 static void GetRevParsingTests()
37 GitRev rev;
38 EXPECT_TRUE(rev.m_CommitHash.IsEmpty());
39 EXPECT_EQ(0, rev.GetCommit(L"HEAD"));
40 EXPECT_STREQ(L"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6", rev.m_CommitHash.ToString());
41 EXPECT_STREQ(L"Sven Strickroth", rev.GetAuthorName());
42 EXPECT_STREQ(L"email@cs-ware.de", rev.GetAuthorEmail());
43 EXPECT_STREQ(L"2015-03-07 18:03:58", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
44 EXPECT_STREQ(L"Sven Strickroth", rev.GetCommitterName());
45 EXPECT_STREQ(L"email@cs-ware.de", rev.GetCommitterEmail());
46 EXPECT_STREQ(L"2015-03-07 18:03:58", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
47 EXPECT_STREQ(L"Changed ASCII file", rev.GetSubject());
48 EXPECT_STREQ(L"", rev.GetBody());
49 EXPECT_STREQ(L"", rev.GetLastErr());
50 EXPECT_EQ(0, rev.ParentsCount());
51 EXPECT_EQ(0, rev.GetParentFromHash(rev.m_CommitHash));
52 ASSERT_EQ(1, rev.ParentsCount());
53 EXPECT_STREQ(L"1fc3c9688e27596d8717b54f2939dc951568f6cb", rev.m_ParentHash[0].ToString());
54 EXPECT_STREQ(L"", rev.GetLastErr());
55 rev.Clear();
56 EXPECT_EQ(0, rev.GetCommit(GitRev::GetWorkingCopy()));
57 EXPECT_TRUE(rev.m_CommitHash.IsEmpty());
58 EXPECT_STREQ(L"", rev.GetAuthorName());
59 EXPECT_STREQ(L"", rev.GetAuthorEmail());
60 EXPECT_STREQ(L"", rev.GetCommitterName());
61 EXPECT_STREQ(L"", rev.GetCommitterEmail());
62 EXPECT_STREQ(L"Working Tree", rev.GetSubject());
63 EXPECT_STREQ(L"", rev.GetBody());
64 EXPECT_EQ(0, rev.ParentsCount());
65 EXPECT_STREQ(L"", rev.GetLastErr());
66 rev.Clear();
67 EXPECT_STREQ(L"", rev.GetLastErr());
68 EXPECT_EQ(0, rev.GetCommit(L"aa5b97f89cea6863222823c8289ce392d06d1691"));
69 EXPECT_STREQ(L"aa5b97f89cea6863222823c8289ce392d06d1691", rev.m_CommitHash.ToString());
70 EXPECT_STREQ(L"Another dummy with ümlaut", rev.GetAuthorName());
71 EXPECT_STREQ(L"anotherduemmy@example.com", rev.GetAuthorEmail());
72 EXPECT_STREQ(L"2015-03-14 22:30:06", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
73 EXPECT_STREQ(L"Another dummy with ümlaut", rev.GetCommitterName());
74 EXPECT_STREQ(L"anotherduemmy@example.com", rev.GetCommitterEmail());
75 EXPECT_STREQ(L"2015-03-14 22:30:06", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
76 EXPECT_STREQ(L"Subject line", rev.GetSubject());
77 EXPECT_STREQ(L"\nalso some more lines\n\nhere in body\n\nSigned-off-by: Another dummy with ümlaut <anotherduemmy@example.com>\n", rev.GetBody());
78 EXPECT_STREQ(L"", rev.GetLastErr());
79 rev.Clear();
80 EXPECT_TRUE(rev.m_CommitHash.IsEmpty());
81 EXPECT_EQ(0, rev.GetCommit(L"1fc3c9688e27596d8717b54f2939dc951568f6cb"));
82 EXPECT_STREQ(L"1fc3c9688e27596d8717b54f2939dc951568f6cb", rev.m_CommitHash.ToString());
83 EXPECT_STREQ(L"Some other User", rev.GetAuthorName());
84 EXPECT_STREQ(L"dummy@example.com", rev.GetAuthorEmail());
85 EXPECT_STREQ(L"2015-03-07 18:03:39", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
86 EXPECT_STREQ(L"Sven Strickroth", rev.GetCommitterName());
87 EXPECT_STREQ(L"email@cs-ware.de", rev.GetCommitterEmail());
88 EXPECT_STREQ(L"2015-03-07 18:03:39", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
89 EXPECT_STREQ(L"Added an ascii file", rev.GetSubject());
90 EXPECT_STREQ(L"", rev.GetBody());
91 EXPECT_STREQ(L"", rev.GetLastErr());
92 rev.Clear();
93 EXPECT_EQ(-1, rev.GetCommit(L"does-not-exist"));
94 EXPECT_STRNE(L"", rev.GetLastErr());
95 EXPECT_TRUE(rev.m_CommitHash.IsEmpty());
96 rev.Clear();
97 CGitHash hash(L"aa5b97f89cea6863222823c8289ce392d06d1691");
98 EXPECT_EQ(0, rev.GetCommitFromHash(hash));
99 EXPECT_EQ(hash, rev.m_CommitHash);
100 EXPECT_STREQ(L"Another dummy with ümlaut", rev.GetAuthorName());
101 EXPECT_STREQ(L"anotherduemmy@example.com", rev.GetAuthorEmail());
102 EXPECT_STREQ(L"2015-03-14 22:30:06", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
103 EXPECT_STREQ(L"Another dummy with ümlaut", rev.GetCommitterName());
104 EXPECT_STREQ(L"anotherduemmy@example.com", rev.GetCommitterEmail());
105 EXPECT_STREQ(L"2015-03-14 22:30:06", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
106 EXPECT_STREQ(L"Subject line", rev.GetSubject());
107 EXPECT_STREQ(L"\nalso some more lines\n\nhere in body\n\nSigned-off-by: Another dummy with ümlaut <anotherduemmy@example.com>\n", rev.GetBody());
108 EXPECT_STREQ(L"", rev.GetLastErr());
109 rev.Clear();
110 EXPECT_EQ(0, rev.GetCommit(L"8d1ebbcc7eeb63af10ff8bcf7712afb9fcc90b8a"));
111 EXPECT_STREQ(L"8d1ebbcc7eeb63af10ff8bcf7712afb9fcc90b8a", rev.m_CommitHash.ToString());
112 EXPECT_STREQ(L"Sven Strickroth", rev.GetAuthorName());
113 EXPECT_STREQ(L"email@cs-ware.de", rev.GetAuthorEmail());
114 EXPECT_STREQ(L"2015-03-04 17:50:24", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
115 EXPECT_STREQ(L"Sven Strickroth", rev.GetCommitterName());
116 EXPECT_STREQ(L"email@cs-ware.de", rev.GetCommitterEmail());
117 EXPECT_STREQ(L"2015-03-04 17:50:24", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
118 EXPECT_STREQ(L"Merge branch 'for-merge' into subdir/branch", rev.GetSubject());
119 EXPECT_STREQ(L"", rev.GetBody());
120 EXPECT_EQ(0, rev.ParentsCount());
121 EXPECT_EQ(0, rev.GetParentFromHash(rev.m_CommitHash));
122 ASSERT_EQ(2, rev.ParentsCount());
123 EXPECT_STREQ(L"3686b9cf74f1a4ef96d6bfe736595ef9abf0fb8d", rev.m_ParentHash[0].ToString());
124 EXPECT_STREQ(L"1ce788330fd3a306c8ad37654063ceee13a7f172", rev.m_ParentHash[1].ToString());
125 EXPECT_STREQ(L"", rev.GetLastErr());
126 rev.Clear();
127 EXPECT_TRUE(rev.m_CommitHash.IsEmpty());
128 EXPECT_EQ(0, rev.GetCommit(L"844309789a13614b52d5e7cbfe6350dd73d1dc72")); // root-commit
129 EXPECT_STREQ(L"844309789a13614b52d5e7cbfe6350dd73d1dc72", rev.m_CommitHash.ToString());
130 EXPECT_STREQ(L"Sven Strickroth", rev.GetAuthorName());
131 EXPECT_STREQ(L"email@cs-ware.de", rev.GetAuthorEmail());
132 EXPECT_STREQ(L"2015-03-04 17:35:13", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
133 EXPECT_STREQ(L"Sven Strickroth", rev.GetCommitterName());
134 EXPECT_STREQ(L"email@cs-ware.de", rev.GetCommitterEmail());
135 EXPECT_STREQ(L"2015-03-04 17:35:13", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
136 EXPECT_STREQ(L"added ansi file", rev.GetSubject());
137 EXPECT_STREQ(L"", rev.GetBody());
138 EXPECT_STREQ(L"", rev.GetLastErr());
139 EXPECT_EQ(0, rev.ParentsCount());
140 EXPECT_EQ(0, rev.GetParentFromHash(rev.m_CommitHash));
141 EXPECT_EQ(0, rev.ParentsCount());
142 EXPECT_STREQ(L"", rev.GetLastErr());
143 rev.Clear();
144 // GPG signed commit which was also amended with different dates
145 EXPECT_EQ(0, rev.GetCommit(L"signed-commit"));
146 EXPECT_STREQ(L"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44", rev.m_CommitHash.ToString());
147 EXPECT_STREQ(L"Sven Strickroth", rev.GetAuthorName());
148 EXPECT_STREQ(L"email@cs-ware.de", rev.GetAuthorEmail());
149 EXPECT_STREQ(L"2015-03-16 12:52:29", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
150 EXPECT_STREQ(L"Sven Strickroth", rev.GetCommitterName());
151 EXPECT_STREQ(L"email@cs-ware.de", rev.GetCommitterEmail());
152 EXPECT_STREQ(L"2015-03-16 13:06:08", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
153 EXPECT_STREQ(L"Several actions", rev.GetSubject());
154 EXPECT_STREQ(L"\n* amended with different date\n* make utf16-be-nobom.txt a symlink ti ascii.txt\n* remove utf8-bom.txt\n* Copied ascii.txt\n\nSigned-off-by: Sven Strickroth <email@cs-ware.de>\n", rev.GetBody());
155 EXPECT_STREQ(L"", rev.GetLastErr());
156 EXPECT_EQ(0, rev.ParentsCount());
157 EXPECT_EQ(0, rev.GetParentFromHash(rev.m_CommitHash));
158 ASSERT_EQ(1, rev.ParentsCount());
159 EXPECT_STREQ(L"aa5b97f89cea6863222823c8289ce392d06d1691", rev.m_ParentHash[0].ToString());
160 EXPECT_STREQ(L"", rev.GetLastErr());
161 rev.Clear();
162 // commit with different committer
163 EXPECT_EQ(0, rev.GetCommit(L"subdir/branch"));
164 EXPECT_STREQ(L"31ff87c86e9f6d3853e438cb151043f30f09029a", rev.m_CommitHash.ToString());
165 EXPECT_STREQ(L"Sven Strickroth", rev.GetAuthorName());
166 EXPECT_STREQ(L"email@cs-ware.de", rev.GetAuthorEmail());
167 EXPECT_STREQ(L"2015-03-16 12:52:29", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
168 EXPECT_STREQ(L"a", rev.GetCommitterName());
169 EXPECT_STREQ(L"a@a.com", rev.GetCommitterEmail());
170 EXPECT_STREQ(L"2017-07-29 15:05:49", rev.GetCommitterDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
171 EXPECT_STREQ(L"Several actions", rev.GetSubject());
172 EXPECT_STREQ(L"\n* amended with different date\n* make utf16-be-nobom.txt a symlink ti ascii.txt\n* remove utf8-bom.txt\n* Copied ascii.txt\n\nSigned-off-by: Sven Strickroth <email@cs-ware.de>\n", rev.GetBody());
173 EXPECT_STREQ(L"", rev.GetLastErr());
174 EXPECT_EQ(0, rev.ParentsCount());
175 EXPECT_EQ(0, rev.GetParentFromHash(rev.m_CommitHash));
176 ASSERT_EQ(1, rev.ParentsCount());
177 EXPECT_STREQ(L"aa5b97f89cea6863222823c8289ce392d06d1691", rev.m_ParentHash[0].ToString());
178 EXPECT_STREQ(L"", rev.GetLastErr());
181 TEST_P(GitRevCBasicGitWithTestRepoFixture, GitRevParsing)
183 GetRevParsingTests();
186 TEST_P(GitRevCBasicGitWithTestRepoBareFixture, GitRevParsing)
188 GetRevParsingTests();
191 TEST(GitRev, Constants)
193 EXPECT_STREQ(L"HEAD", GitRev::GetHead());
194 EXPECT_STREQ(L"0000000000000000000000000000000000000000", GitRev::GetWorkingCopy());