Fix action icons in the log dialog being clipped on High-DPI displays
[TortoiseGit.git] / test / UnitTests / libgitTest.cpp
blob6731216fae3ff0fc8895a3b5e07eadb05a4637c9
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-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 "Git.h"
22 #include "StringUtils.h"
24 TEST(libgit, BrokenConfig)
26 CAutoTempDir tempdir;
27 g_Git.m_CurrentDir = tempdir.GetTempDir();
28 g_Git.m_IsGitDllInited = false;
29 g_Git.m_CurrentDir = g_Git.m_CurrentDir;
30 g_Git.m_IsUseGitDLL = true;
31 g_Git.m_IsUseLibGit2 = false;
32 g_Git.m_IsUseLibGit2_mask = 0;
33 // libgit relies on CWD being set to working tree
34 SetCurrentDirectory(g_Git.m_CurrentDir);
36 CString output;
37 EXPECT_EQ(0, g_Git.Run(L"git.exe init", &output, CP_UTF8));
38 EXPECT_STRNE(L"", output);
39 CString testFile = tempdir.GetTempDir() + L"\\.git\\config";
40 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(testFile, L"[push]\ndefault=something-that-is-invalid\n"));
42 EXPECT_THROW(g_Git.CheckAndInitDll(), const char*);
45 TEST(libgit, Mailmap)
47 CAutoTempDir tempdir;
48 g_Git.m_CurrentDir = tempdir.GetTempDir();
49 // libgit relies on CWD being set to working tree
50 SetCurrentDirectory(g_Git.m_CurrentDir);
52 GIT_MAILMAP mailmap = (void*)0x12345678;
53 git_read_mailmap(&mailmap);
54 EXPECT_EQ(nullptr, mailmap);
56 CString mailmapFile = tempdir.GetTempDir() + L"\\.mailmap";
57 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(mailmapFile, L""));
59 mailmap = (void*)0x12345678;
60 git_read_mailmap(&mailmap);
61 EXPECT_EQ(nullptr, mailmap);
63 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(mailmapFile, L"Sven Strickroth <sven@tortoisegit.org>"));
64 git_read_mailmap(&mailmap);
65 EXPECT_NE(nullptr, mailmap);
66 const char* email1 = nullptr;
67 const char* author1 = nullptr;
68 EXPECT_EQ(-1, git_lookup_mailmap(mailmap, &email1, &author1, "email@cs-ware.de", nullptr, [](void*) { return "Sven S."; }));
69 EXPECT_EQ(0, git_lookup_mailmap(mailmap, &email1, &author1, "sven@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
70 EXPECT_EQ(nullptr, email1);
71 EXPECT_STREQ("Sven Strickroth", author1);
73 email1 = nullptr;
74 author1 = nullptr;
75 EXPECT_EQ(0, git_lookup_mailmap(mailmap, &email1, &author1, "Sven@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
76 EXPECT_EQ(nullptr, email1);
77 EXPECT_STREQ("Sven Strickroth", author1);
79 git_free_mailmap(mailmap);
80 CString content;
81 for (auto& entry : { L"", L"1", L"2", L"A", L"4", L"5", L"b", L"7" })
82 content.AppendFormat(L"Sven%s Strickroth <sven%s@tortoisegit.org> <email%s@cs-ware.de>\n", entry, entry, entry);
83 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(mailmapFile, content));
84 git_read_mailmap(&mailmap);
85 EXPECT_NE(nullptr, mailmap);
86 email1 = nullptr;
87 author1 = nullptr;
88 EXPECT_EQ(-1, git_lookup_mailmap(mailmap, &email1, &author1, "sven@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
89 EXPECT_EQ(-1, git_lookup_mailmap(mailmap, &email1, &author1, "aaa@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
90 EXPECT_EQ(-1, git_lookup_mailmap(mailmap, &email1, &author1, "zzz@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
91 for (auto& entry : { "", "1", "2", "A", "4", "5", "b", "7" })
93 CStringA maillookup, mail, name;
94 maillookup.Format("email%s@cs-ware.de", entry);
95 mail.Format("sven%s@tortoisegit.org", entry);
96 name.Format("Sven%s Strickroth", entry);
97 email1 = nullptr;
98 author1 = nullptr;
99 EXPECT_EQ(0, git_lookup_mailmap(mailmap, &email1, &author1, maillookup, nullptr, [](void*) { return "Sven S."; }));
100 EXPECT_STREQ(mail, email1);
101 EXPECT_STREQ(name, author1);
104 email1 = nullptr;
105 author1 = nullptr;
106 EXPECT_EQ(0, git_lookup_mailmap(mailmap, &email1, &author1, "email@cs-ware.de", nullptr, [](void*) { return "Sven Strickroth"; }));
107 EXPECT_STREQ("sven@tortoisegit.org", email1);
108 EXPECT_STREQ("Sven Strickroth", author1);
110 git_free_mailmap(mailmap);
111 EXPECT_TRUE(CStringUtils::WriteStringToTextFile(mailmapFile, L"<sven@tortoisegit.org> <email@cs-ware.de>\nSven S. <sven@tortoisegit.org> Sven Strickroth <email@cs-ware.de>"));
112 git_read_mailmap(&mailmap);
113 EXPECT_NE(nullptr, mailmap);
114 email1 = nullptr;
115 author1 = nullptr;
116 EXPECT_EQ(-1, git_lookup_mailmap(mailmap, &email1, &author1, "sven@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
117 EXPECT_EQ(-1, git_lookup_mailmap(mailmap, &email1, &author1, "aaa@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
118 EXPECT_EQ(-1, git_lookup_mailmap(mailmap, &email1, &author1, "zzz@tortoisegit.org", nullptr, [](void*) { return "Sven S."; }));
119 EXPECT_EQ(0, git_lookup_mailmap(mailmap, &email1, &author1, "email@cs-ware.de", nullptr, [](void*) { return "Sven S."; }));
120 EXPECT_STREQ("sven@tortoisegit.org", email1);
121 EXPECT_STREQ(nullptr, author1);
122 email1 = nullptr;
123 author1 = nullptr;
124 EXPECT_EQ(0, git_lookup_mailmap(mailmap, &email1, &author1, "email@cs-ware.de", nullptr, [](void*) { return "Sven Strickroth"; }));
125 EXPECT_STREQ("sven@tortoisegit.org", email1);
126 EXPECT_STREQ("Sven S.", author1);