1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015-2016, 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.
23 TEST(CGitByteArray
, Empty
)
25 CGitByteArray byteArray
;
26 EXPECT_TRUE(byteArray
.empty());
27 EXPECT_EQ(0U, byteArray
.size());
30 TEST(CGitByteArray
, AppendByteArray
)
32 BYTE inputByteArray
[] = { "12345789" };
33 CGitByteArray byteArray
;
34 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
35 EXPECT_EQ(sizeof(inputByteArray
), byteArray
.size());
37 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
38 EXPECT_EQ(2 * sizeof(inputByteArray
), byteArray
.size());
41 EXPECT_TRUE(byteArray
.empty());
42 EXPECT_EQ(0U, byteArray
.size());
45 TEST(CGitByteArray
, AppendByteArrayWithNulls
)
47 BYTE inputByteArray
[] = { "1234\0""5789\0" };
48 CGitByteArray byteArray
;
50 byteArray
.append(inputByteArray
, 0);
51 EXPECT_EQ(0U, byteArray
.size());
53 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
54 EXPECT_EQ(sizeof(inputByteArray
), byteArray
.size());
56 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
57 EXPECT_EQ(2 * sizeof(inputByteArray
), byteArray
.size());
60 TEST(CGitByteArray
, AppendByteArrayRange
)
62 BYTE inputByteArray
[] = { "1234\0""5789\0" };
63 CGitByteArray byteArray1
;
64 byteArray1
.append(inputByteArray
, sizeof(inputByteArray
));
65 EXPECT_EQ(sizeof(inputByteArray
), byteArray1
.size());
67 CGitByteArray byteArray2
;
68 EXPECT_EQ(0U, byteArray2
.append(byteArray1
, 0));
69 EXPECT_EQ(byteArray1
.size(), byteArray2
.size());
71 EXPECT_EQ(0U, byteArray2
.append(byteArray1
, 4, 3));
72 EXPECT_EQ(sizeof(inputByteArray
), byteArray1
.size());
73 EXPECT_EQ(byteArray1
.size(), byteArray2
.size());
75 EXPECT_EQ(0U, byteArray2
.append(byteArray1
, 4, 4));
76 EXPECT_EQ(sizeof(inputByteArray
), byteArray1
.size());
77 EXPECT_EQ(byteArray1
.size(), byteArray2
.size());
79 EXPECT_EQ(0U, byteArray2
.append(byteArray1
, 4, 7));
80 EXPECT_EQ(sizeof(inputByteArray
), byteArray1
.size());
81 EXPECT_EQ(byteArray1
.size() + 3, byteArray2
.size());
84 TEST(CGitByteArray
, Find
)
86 BYTE inputByteArray
[] = { "1234\0""5789\0" };
87 CGitByteArray byteArray
;
89 EXPECT_EQ(CGitByteArray::npos
, byteArray
.find(0));
90 EXPECT_EQ(CGitByteArray::npos
, byteArray
.find('3'));
91 EXPECT_EQ(CGitByteArray::npos
, byteArray
.find(0, 15));
93 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
94 EXPECT_EQ(sizeof(inputByteArray
), byteArray
.size());
96 EXPECT_EQ(4U, byteArray
.find(0));
97 EXPECT_EQ(4U, byteArray
.find(0, 4));
98 EXPECT_EQ(9U, byteArray
.find(0, 5));
99 EXPECT_EQ(CGitByteArray::npos
, byteArray
.find(0, 15));
101 EXPECT_EQ(0U, byteArray
.find('1'));
102 EXPECT_EQ(1U, byteArray
.find('2'));
104 EXPECT_EQ(CGitByteArray::npos
, byteArray
.find('F'));
106 byteArray
.append((const BYTE
*)"1", 1);
107 EXPECT_EQ(0U, byteArray
.find('1'));
108 EXPECT_EQ(11U, byteArray
.find('1', 2));
110 EXPECT_EQ(4U, byteArray
.find(0));
111 EXPECT_EQ(4U, byteArray
.find(0, 4));
112 EXPECT_EQ(9U, byteArray
.find(0, 5));
113 EXPECT_EQ(9U, byteArray
.find(0, 9));
114 EXPECT_EQ(10U, byteArray
.find(0, 10));
115 EXPECT_EQ(CGitByteArray::npos
, byteArray
.find(0, 11));
116 EXPECT_EQ(CGitByteArray::npos
, byteArray
.find(0, 15));
119 TEST(CGitByteArray
, RevertFind
)
121 BYTE inputByteArray
[] = { "1234\0""5789\0" };
122 CGitByteArray byteArray
;
124 EXPECT_EQ(CGitByteArray::npos
, byteArray
.RevertFind(0));
125 EXPECT_EQ(CGitByteArray::npos
, byteArray
.RevertFind('3'));
127 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
128 EXPECT_EQ(sizeof(inputByteArray
), byteArray
.size());
130 EXPECT_EQ(10U, byteArray
.RevertFind(0));
131 EXPECT_EQ(10U, byteArray
.RevertFind(0, 10));
132 EXPECT_EQ(9U, byteArray
.RevertFind(0, 9));
133 EXPECT_EQ(4U, byteArray
.RevertFind(0, 4));
134 EXPECT_EQ(4U, byteArray
.RevertFind(0, 5));
135 EXPECT_EQ(CGitByteArray::npos
, byteArray
.RevertFind(0, 2));
137 EXPECT_EQ(0U, byteArray
.RevertFind('1'));
138 EXPECT_EQ(1U, byteArray
.RevertFind('2'));
140 EXPECT_EQ(CGitByteArray::npos
, byteArray
.RevertFind('F'));
142 byteArray
.append((const BYTE
*)"1", 1);
143 EXPECT_EQ(11U, byteArray
.RevertFind('1'));
144 EXPECT_EQ(11U, byteArray
.RevertFind('1', 11));
145 EXPECT_EQ(0U, byteArray
.RevertFind('1', 10));
146 EXPECT_EQ(0U, byteArray
.RevertFind('1', 2));
147 EXPECT_EQ(0U, byteArray
.RevertFind('1', 1));
148 EXPECT_EQ(0U, byteArray
.RevertFind('1', 0));
150 EXPECT_EQ(10U, byteArray
.RevertFind(0));
151 EXPECT_EQ(CGitByteArray::npos
, byteArray
.RevertFind(0, 0));
152 EXPECT_EQ(CGitByteArray::npos
, byteArray
.RevertFind(0, 2));
153 EXPECT_EQ(4U, byteArray
.RevertFind(0, 4));
154 EXPECT_EQ(4U, byteArray
.RevertFind(0, 5));
155 EXPECT_EQ(9U, byteArray
.RevertFind(0, 9));
156 EXPECT_EQ(10U, byteArray
.RevertFind(0, 10));
157 EXPECT_EQ(10U, byteArray
.RevertFind(0, 11));
160 TEST(CGitByteArray
, FindNextString
)
162 BYTE inputByteArray
[] = { "1234\0""5789\0" };
163 CGitByteArray byteArray
;
165 EXPECT_EQ(CGitByteArray::npos
, byteArray
.findNextString(0));
166 EXPECT_EQ(CGitByteArray::npos
, byteArray
.findNextString(5));
168 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
169 EXPECT_EQ(sizeof(inputByteArray
), byteArray
.size());
171 EXPECT_EQ(5U, byteArray
.findNextString(0));
172 EXPECT_EQ(5U, byteArray
.findNextString(2));
173 EXPECT_EQ(5U, byteArray
.findNextString(4));
174 EXPECT_EQ(CGitByteArray::npos
, byteArray
.findNextString(5));
175 EXPECT_EQ(CGitByteArray::npos
, byteArray
.findNextString(9));
176 EXPECT_EQ(CGitByteArray::npos
, byteArray
.findNextString(10));
178 byteArray
.append((const BYTE
*)"0", 1);
179 EXPECT_EQ(5U, byteArray
.findNextString(0));
180 EXPECT_EQ(5U, byteArray
.findNextString(2));
181 EXPECT_EQ(5U, byteArray
.findNextString(4));
182 EXPECT_EQ(11U, byteArray
.findNextString(5));
183 EXPECT_EQ(11U, byteArray
.findNextString(9));
184 EXPECT_EQ(11U, byteArray
.findNextString(10));
185 EXPECT_EQ(CGitByteArray::npos
, byteArray
.findNextString(11));
188 byteArray
.append(inputByteArray
, sizeof(inputByteArray
));
189 EXPECT_EQ(sizeof(inputByteArray
), byteArray
.size());
191 byteArray
.append((const BYTE
*)"1", 1);
192 EXPECT_EQ(5U, byteArray
.findNextString(0));
193 EXPECT_EQ(5U, byteArray
.findNextString(2));
194 EXPECT_EQ(5U, byteArray
.findNextString(4));
195 EXPECT_EQ(11U, byteArray
.findNextString(5));
196 EXPECT_EQ(11U, byteArray
.findNextString(9));
197 EXPECT_EQ(11U, byteArray
.findNextString(10));
198 EXPECT_EQ(CGitByteArray::npos
, byteArray
.findNextString(11));