Increase timeout
[TortoiseGit.git] / test / UnitTests / GitHashTest.cpp
bloba19ffa17a1ad65433b14bfc3c1d7bd3c6c8e68ce
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 "GitHash.h"
22 #include "GitStatus.h"
24 TEST(CGitHash, Initial)
26 CGitHash empty;
27 EXPECT_TRUE(empty.IsEmpty());
28 EXPECT_STREQ(_T("0000000000000000000000000000000000000000"), GIT_REV_ZERO);
29 EXPECT_STREQ(GIT_REV_ZERO, empty.ToString());
30 EXPECT_TRUE(empty == empty);
31 EXPECT_FALSE(empty != empty);
33 CGitHash hash;
34 hash.ConvertFromStrA("8d1861316061748cfee7e075dc138287978102ab");
35 EXPECT_FALSE(hash.IsEmpty());
36 EXPECT_STREQ(L"8d1861316061748cfee7e075dc138287978102ab", hash.ToString());
37 EXPECT_TRUE(hash == hash);
38 EXPECT_FALSE(hash != hash);
39 EXPECT_FALSE(hash == empty);
40 EXPECT_TRUE(hash != empty);
42 CGitHash hash2(L"8d1861316061748cfee7e075dc138287978102ab");
43 EXPECT_FALSE(hash2.IsEmpty());
44 EXPECT_STREQ(L"8d1861316061748cfee7e075dc138287978102ab", hash2.ToString());
45 EXPECT_TRUE(hash2 == hash);
46 EXPECT_FALSE(hash2 != hash);
47 EXPECT_FALSE(hash2 == empty);
48 EXPECT_TRUE(hash2 != empty);
49 hash2.Empty();
50 EXPECT_STREQ(GIT_REV_ZERO, hash2.ToString());
51 EXPECT_TRUE(hash2 == empty);
52 EXPECT_FALSE(hash2 != empty);
53 EXPECT_TRUE(hash2.IsEmpty());
55 unsigned char chararray[20] = { 0x8D, 0x18, 0x61, 0x31, 0x60, 0x61, 0x74, 0x8C, 0xFE, 0xE7, 0xE0, 0x75, 0xDC, 0x13, 0x82, 0x87, 0x97, 0x81, 0x02, 0xAB };
56 CGitHash hash3((char*)chararray);
57 EXPECT_FALSE(hash3.IsEmpty());
58 EXPECT_STREQ(L"8d1861316061748cfee7e075dc138287978102ab", hash3.ToString());
59 EXPECT_TRUE(hash3 == hash);
60 EXPECT_FALSE(hash3 != hash);
61 EXPECT_FALSE(hash3 == empty);
62 EXPECT_TRUE(hash3 != empty);
64 CGitHash hash4;
65 hash4 = L"8d1861316061748cfee7e075dc138287978102ab";
66 EXPECT_TRUE(hash4 == hash);
68 CGitHash hash5;
69 hash5 = hash;
70 EXPECT_TRUE(hash5 == hash);
72 CGitHash hash6;
73 hash6 = chararray;
74 EXPECT_TRUE(hash6 == hash);
76 CGitHash hash7(L"invalid");
77 EXPECT_TRUE(hash7.IsEmpty());
79 CGitHash hash8(L"01234567");
80 EXPECT_TRUE(hash8.IsEmpty());
83 TEST(CGitHash, IsSHA1Valid)
85 EXPECT_TRUE(CGitHash::IsValidSHA1(GIT_REV_ZERO));
86 EXPECT_TRUE(CGitHash::IsValidSHA1(L"8d1861316061748cfee7e075dc138287978102ab"));
87 EXPECT_TRUE(CGitHash::IsValidSHA1(L"8d1861316061748cfee7E075dc138287978102ab"));
88 EXPECT_TRUE(CGitHash::IsValidSHA1(L"8D1861316061748CFEE7E075DC138287978102AB"));
89 EXPECT_FALSE(CGitHash::IsValidSHA1(L""));
90 EXPECT_FALSE(CGitHash::IsValidSHA1(L"8d18613"));
91 EXPECT_FALSE(CGitHash::IsValidSHA1(L"master"));
92 EXPECT_FALSE(CGitHash::IsValidSHA1(L"refs/heads/master"));
93 EXPECT_FALSE(CGitHash::IsValidSHA1(L"8d1861316061748cfee7e075dc138287978102az"));