Fix '==': signed/unsigned mismatch warning
[TortoiseGit.git] / test / UnitTests / GitRevRefBrowseTest.cpp
blob9ae8b6be9189c8481721392a59f994a3a3e9abf3
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2018 - 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 "GitRevRefBrowser.h"
24 class GitRevRefBrowserCBasicGitWithTestRepoFixture : public CBasicGitWithTestRepoFixture
28 class GitRevRefBrowserCBasicGitWithTestRepoBareFixture : public CBasicGitWithTestRepoBareFixture
32 INSTANTIATE_TEST_CASE_P(GitRevRefBrowser, GitRevRefBrowserCBasicGitWithTestRepoFixture, testing::Values(GIT_CLI));
33 INSTANTIATE_TEST_CASE_P(GitRevRefBrowser, GitRevRefBrowserCBasicGitWithTestRepoBareFixture, testing::Values(GIT_CLI));
35 static void GetGitRevRefMap()
37 g_Git.SetConfigValue(L"branch.master.description", L"test");
38 g_Git.SetConfigValue(L"branch.subdir/branch.description", L"multi\nline");
40 MAP_REF_GITREVREFBROWSER refMap;
41 CString err;
42 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 0, err));
43 EXPECT_STREQ(L"", err);
44 EXPECT_EQ(12U, refMap.size());
46 GitRevRefBrowser rev = refMap[L"refs/heads/master"];
47 EXPECT_STREQ(L"7c3cbfe13a929d2291a574dca45e4fd2d2ac1aa6", rev.m_CommitHash.ToString());
48 EXPECT_STREQ(L"Sven Strickroth", rev.GetAuthorName());
49 EXPECT_STREQ(L"2015-03-07 18:03:58", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
50 EXPECT_STREQ(L"Changed ASCII file", rev.GetSubject());
51 EXPECT_STREQ(L"refs/remotes/origin/master", rev.m_UpstreamRef);
52 EXPECT_STREQ(L"test", rev.m_Description);
54 rev = refMap[L"refs/heads/signed-commit"];
55 EXPECT_STREQ(L"4c5c93d2a0b368bc4570d5ec02ab03b9c4334d44", rev.m_CommitHash.ToString());
56 EXPECT_STREQ(L"Sven Strickroth", rev.GetAuthorName());
57 EXPECT_STREQ(L"2015-03-16 12:52:29", rev.GetAuthorDate().FormatGmt(L"%Y-%m-%d %H:%M:%S"));
58 EXPECT_STREQ(L"Several actions", rev.GetSubject());
59 EXPECT_STREQ(L"", rev.m_UpstreamRef);
60 EXPECT_STREQ(L"", rev.m_Description);
62 rev = refMap[L"refs/tags/also-signed"];
63 EXPECT_STREQ(L"e89cb722e0f9b2eb763bb059dc099ee6c502a6d8", rev.m_CommitHash.ToString());
64 EXPECT_STREQ(L"", rev.GetAuthorName());
65 EXPECT_TRUE(rev.GetAuthorDate() == 0);
66 EXPECT_STREQ(L"Also signed", rev.GetSubject());
67 EXPECT_STREQ(L"", rev.m_UpstreamRef);
68 EXPECT_STREQ(L"", rev.m_Description);
70 refMap.clear();
71 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 0, err, [](const CString& refName) { return CStringUtils::StartsWith(refName, L"refs/heads/"); }));
72 EXPECT_STREQ(L"", err);
73 EXPECT_EQ(6U, refMap.size());
74 EXPECT_TRUE(refMap.find(L"refs/heads/master") != refMap.end());
75 for (auto it = refMap.cbegin(); it != refMap.cend(); ++it)
76 EXPECT_TRUE(CStringUtils::StartsWith(it->first, L"refs/heads/"));
78 refMap.clear();
79 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 1, err));
80 EXPECT_STREQ(L"", err);
81 EXPECT_EQ(6U, refMap.size());
82 for (const auto& branch : { L"refs/heads/master", L"refs/heads/master2", L"refs/remotes/origin/master", L"refs/tags/all-files-signed", L"refs/tags/also-signed", L"refs/tags/normal-tag" })
83 EXPECT_TRUE(refMap.find(branch) != refMap.end());
85 refMap.clear();
86 EXPECT_EQ(0, GitRevRefBrowser::GetGitRevRefMap(refMap, 2, err));
87 EXPECT_STREQ(L"", err);
88 EXPECT_EQ(6U, refMap.size());
89 EXPECT_TRUE(refMap.find(L"refs/heads/master") == refMap.end());
90 for (const auto& branch : { L"refs/heads/forconflict", L"refs/heads/signed-commit", L"refs/heads/simple-conflict", L"refs/heads/subdir/branch", L"refs/notes/commits", L"refs/stash" })
91 EXPECT_TRUE(refMap.find(branch) != refMap.end());
94 TEST_P(GitRevRefBrowserCBasicGitWithTestRepoFixture, GetGitRevRefMap)
96 GetGitRevRefMap();
99 TEST_P(GitRevRefBrowserCBasicGitWithTestRepoBareFixture, GetGitRevRefMap)
101 GetGitRevRefMap();