1 /**
2 * (c) 2019 by Mega Limited, Wellsford, New Zealand
3 *
4 * This file is part of the MEGA SDK - Client Access Engine.
5 *
6 * Applications using the MEGA API must present a valid application key
7 * and comply with the the rules set forth in the Terms of Service.
8 *
9 * The MEGA SDK is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * @copyright Simplified (2-clause) BSD License.
14 *
15 * You should have received a copy of the license along with this
16 * program.
17 */
18
19 #include <array>
20 #include <memory>
21 #include <numeric>
22 #include <string>
23
24 #include <gtest/gtest.h>
25
26 #include <mega/filefingerprint.h>
27
28 #include "DefaultedFileAccess.h"
29
30 namespace {
31
32 class MockFileAccess : public mt::DefaultedFileAccess
33 {
34 public:
MockFileAccess(const mega::m_time_t mtime,std::vector<mega::byte> content,const bool readFails=false)35 MockFileAccess(const mega::m_time_t mtime, std::vector<mega::byte> content, const bool readFails = false)
36 : mContent{std::move(content)}
37 , mReadFails{readFails}
38 {
39 this->size = mContent.size();
40 this->mtime = mtime;
41 }
42
MEGA_DISABLE_COPY_MOVE(MockFileAccess)43 MEGA_DISABLE_COPY_MOVE(MockFileAccess)
44
45 bool sysstat(mega::m_time_t* curr_mtime, m_off_t* curr_size) override
46 {
47 *curr_mtime = mtime;
48 *curr_size = size;
49 return true;
50 }
51
sysopen(bool async=false)52 bool sysopen(bool async = false) override
53 {
54 return true;
55 }
56
sysread(mega::byte * buffer,const unsigned size,const m_off_t offset)57 bool sysread(mega::byte* buffer, const unsigned size, const m_off_t offset) override
58 {
59 if (mReadFails)
60 {
61 return false;
62 }
63 assert(static_cast<unsigned>(offset) + size <= mContent.size());
64 std::copy(mContent.begin() + static_cast<unsigned>(offset), mContent.begin() + static_cast<unsigned>(offset) + size, buffer);
65 return true;
66 }
67
sysclose()68 void sysclose() override
69 {}
70
getReadFails() const71 bool getReadFails() const
72 {
73 return mReadFails;
74 }
75
76 private:
77 const std::vector<mega::byte> mContent;
78 const bool mReadFails = false;
79 };
80
81 class MockInputStreamAccess : public mega::InputStreamAccess
82 {
83 public:
MockInputStreamAccess(const mega::m_time_t mtime,std::vector<mega::byte> content,const bool readFails=false)84 MockInputStreamAccess(const mega::m_time_t mtime, std::vector<mega::byte> content, const bool readFails = false)
85 : mFa{mtime, std::move(content), readFails}
86 {}
87
getMTime() const88 mega::m_time_t getMTime() const
89 {
90 return mFa.mtime;
91 }
92
setSize(const m_off_t size)93 void setSize(const m_off_t size)
94 {
95 mFa.size = size;
96 }
97
size()98 m_off_t size() override
99 {
100 return mFa.size;
101 }
102
read(mega::byte * buffer,const unsigned size)103 bool read(mega::byte* buffer, const unsigned size) override
104 {
105 if (mFa.getReadFails())
106 {
107 return false;
108 }
109 if (!buffer)
110 {
111 return true;
112 }
113 return mFa.frawread(buffer, size, 0);
114 }
115
116 private:
117 MockFileAccess mFa;
118 };
119
120 } // anonymous
121
TEST(FileFingerprint,FileFingerprintCmp_compareNotSmaller)122 TEST(FileFingerprint, FileFingerprintCmp_compareNotSmaller)
123 {
124 mega::FileFingerprint ffp;
125 ffp.size = 1;
126 ffp.mtime = 2;
127 std::iota(ffp.crc.begin(), ffp.crc.end(), 3);
128 ffp.isvalid = true;
129
130 mega::FileFingerprint copiedFfp;
131 copiedFfp = ffp;
132
133 ASSERT_FALSE(mega::FileFingerprintCmp{}(&ffp, &copiedFfp));
134 }
135
TEST(FileFingerprint,FileFingerprintCmp_compareSmallerBecauseOfSize)136 TEST(FileFingerprint, FileFingerprintCmp_compareSmallerBecauseOfSize)
137 {
138 mega::FileFingerprint ffp;
139 ffp.size = 1;
140
141 mega::FileFingerprint ffp2;
142 ffp2.size = 2;
143
144 ASSERT_TRUE(mega::FileFingerprintCmp{}(&ffp, &ffp2));
145 }
146
TEST(FileFingerprint,FileFingerprintCmp_compareNotSmallerBecauseOfSize)147 TEST(FileFingerprint, FileFingerprintCmp_compareNotSmallerBecauseOfSize)
148 {
149 mega::FileFingerprint ffp;
150 ffp.size = 2;
151
152 mega::FileFingerprint ffp2;
153 ffp2.size = 1;
154
155 ASSERT_FALSE(mega::FileFingerprintCmp{}(&ffp, &ffp2));
156 }
157
TEST(FileFingerprint,FileFingerprintCmp_compareSmallerBecauseOfMTime)158 TEST(FileFingerprint, FileFingerprintCmp_compareSmallerBecauseOfMTime)
159 {
160 mega::FileFingerprint ffp;
161 ffp.mtime = 1;
162
163 mega::FileFingerprint ffp2;
164 ffp2.mtime = 2;
165
166 ASSERT_TRUE(mega::FileFingerprintCmp{}(&ffp, &ffp2));
167 }
168
TEST(FileFingerprint,FileFingerprintCmp_compareNotSmallerBecauseOfMTime)169 TEST(FileFingerprint, FileFingerprintCmp_compareNotSmallerBecauseOfMTime)
170 {
171 mega::FileFingerprint ffp;
172 ffp.mtime = 2;
173
174 mega::FileFingerprint ffp2;
175 ffp2.mtime = 1;
176
177 ASSERT_FALSE(mega::FileFingerprintCmp{}(&ffp, &ffp2));
178 }
179
TEST(FileFingerprint,FileFingerprintCmp_compareSmallerBecauseOfCrc)180 TEST(FileFingerprint, FileFingerprintCmp_compareSmallerBecauseOfCrc)
181 {
182 mega::FileFingerprint ffp;
183 ffp.crc[0] = 1;
184
185 mega::FileFingerprint ffp2;
186 ffp2.crc[0] = 2;
187
188 ASSERT_TRUE(mega::FileFingerprintCmp{}(&ffp, &ffp2));
189 }
190
TEST(FileFingerprint,defaultConstructor)191 TEST(FileFingerprint, defaultConstructor)
192 {
193 const mega::FileFingerprint ffp;
194 ASSERT_EQ(-1, ffp.size);
195 ASSERT_EQ(0, ffp.mtime);
196 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
197 ASSERT_EQ(expected, ffp.crc);
198 ASSERT_EQ(false, ffp.isvalid);
199 }
200
TEST(FileFingerprint,copyAssignment)201 TEST(FileFingerprint, copyAssignment)
202 {
203 mega::FileFingerprint ffp;
204 ffp.size = 1;
205 ffp.mtime = 2;
206 std::iota(ffp.crc.begin(), ffp.crc.end(), 3);
207 ffp.isvalid = true;
208
209 mega::FileFingerprint copiedFfp;
210 copiedFfp = ffp;
211
212 ASSERT_EQ(copiedFfp.size, ffp.size);
213 ASSERT_EQ(copiedFfp.mtime, ffp.mtime);
214 ASSERT_EQ(copiedFfp.crc, ffp.crc);
215 ASSERT_EQ(copiedFfp.isvalid, ffp.isvalid);
216 }
217
TEST(FileFingerprint,copyConstructor)218 TEST(FileFingerprint, copyConstructor)
219 {
220 mega::FileFingerprint ffp;
221 ffp.size = 1;
222 ffp.mtime = 2;
223 std::iota(ffp.crc.begin(), ffp.crc.end(), 3);
224 ffp.isvalid = true;
225
226 const mega::FileFingerprint copiedFfp{ffp};
227
228 ASSERT_EQ(copiedFfp.size, ffp.size);
229 ASSERT_EQ(copiedFfp.mtime, ffp.mtime);
230 ASSERT_EQ(copiedFfp.crc, ffp.crc);
231 ASSERT_EQ(copiedFfp.isvalid, ffp.isvalid);
232 }
233
TEST(FileFingerprint,comparisonOperator_compareEqual)234 TEST(FileFingerprint, comparisonOperator_compareEqual)
235 {
236 mega::FileFingerprint ffp;
237 ffp.size = 1;
238 ffp.mtime = 2;
239 std::iota(ffp.crc.begin(), ffp.crc.end(), 3);
240 ffp.isvalid = true;
241
242 mega::FileFingerprint copiedFfp;
243 copiedFfp = ffp;
244
245 ASSERT_TRUE(ffp == copiedFfp);
246 }
247
TEST(FileFingerprint,comparisonOperator_compareNotEqualBecauseOfSize)248 TEST(FileFingerprint, comparisonOperator_compareNotEqualBecauseOfSize)
249 {
250 mega::FileFingerprint ffp;
251 ffp.isvalid = true;
252 ffp.size = 1;
253
254 mega::FileFingerprint ffp2;
255 ffp2.isvalid = true;
256
257 ASSERT_FALSE(ffp == ffp2);
258 }
259
260 #ifndef __ANDROID__
261 #ifndef WINDOWS_PHONE
TEST(FileFingerprint,comparisonOperator_compareNotEqualBecauseOfMTime)262 TEST(FileFingerprint, comparisonOperator_compareNotEqualBecauseOfMTime)
263 {
264 mega::FileFingerprint ffp;
265 ffp.isvalid = true;
266 ffp.mtime = 3; // difference must be at least 3
267
268 mega::FileFingerprint ffp2;
269 ffp2.isvalid = true;
270
271 ASSERT_FALSE(ffp == ffp2);
272 }
273 #endif
274 #endif
275
TEST(FileFingerprint,comparisonOperator_compareNotEqualBecauseOfValid)276 TEST(FileFingerprint, comparisonOperator_compareNotEqualBecauseOfValid)
277 {
278 mega::FileFingerprint ffp;
279 ffp.isvalid = false;
280
281 mega::FileFingerprint ffp2;
282 ffp2.isvalid = true;
283
284 ASSERT_TRUE(ffp == ffp2);
285 }
286
TEST(FileFingerprint,comparisonOperator_compareNotEqualBecauseOfCrc)287 TEST(FileFingerprint, comparisonOperator_compareNotEqualBecauseOfCrc)
288 {
289 mega::FileFingerprint ffp;
290 ffp.isvalid = true;
291 ffp.crc[0] = 1;
292
293 mega::FileFingerprint ffp2;
294 ffp2.isvalid = true;
295
296 ASSERT_FALSE(ffp == ffp2);
297 }
298
TEST(FileFingerprint,serialize_unserialize)299 TEST(FileFingerprint, serialize_unserialize)
300 {
301 mega::FileFingerprint ffp;
302 ffp.size = 1;
303 ffp.mtime = 2;
304 std::iota(ffp.crc.begin(), ffp.crc.end(), 3);
305 ffp.isvalid = true;
306
307 std::string data;
308 ASSERT_TRUE(ffp.serialize(&data));
309 auto ffp2 = std::unique_ptr<mega::FileFingerprint>{mega::FileFingerprint::unserialize(&data)};
310
311 ASSERT_EQ(ffp2->size, ffp.size);
312 ASSERT_EQ(ffp2->mtime, ffp.mtime);
313 ASSERT_EQ(ffp2->crc, ffp.crc);
314 ASSERT_EQ(ffp2->isvalid, ffp.isvalid);
315 }
316
TEST(FileFingerprint,unserialize_32bit)317 TEST(FileFingerprint, unserialize_32bit)
318 {
319 mega::FileFingerprint ffp;
320 ffp.size = 1;
321 ffp.mtime = 2;
322 std::iota(ffp.crc.begin(), ffp.crc.end(), 3);
323 ffp.isvalid = true;
324
325 // This is the result of serialization on 32bit Windows
326 const std::array<char, 33> rawData = {
327 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
328 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
329 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01
330 };
331 std::string data(rawData.data(), rawData.size());
332
333 auto ffp2 = std::unique_ptr<mega::FileFingerprint>{mega::FileFingerprint::unserialize(&data)};
334
335 ASSERT_EQ(ffp2->size, ffp.size);
336 ASSERT_EQ(ffp2->mtime, ffp.mtime);
337 ASSERT_EQ(ffp2->crc, ffp.crc);
338 ASSERT_EQ(ffp2->isvalid, ffp.isvalid);
339 }
340
TEST(FileFingerprint,unserialize_butStringTooShort)341 TEST(FileFingerprint, unserialize_butStringTooShort)
342 {
343 std::string data = "blah";
344 ASSERT_EQ(nullptr, mega::FileFingerprint::unserialize(&data));
345 }
346
TEST(FileFingerprint,serializefingerprint_unserializefingerprint)347 TEST(FileFingerprint, serializefingerprint_unserializefingerprint)
348 {
349 mega::FileFingerprint ffp;
350 ffp.size = 1;
351 ffp.mtime = 2;
352 std::iota(ffp.crc.begin(), ffp.crc.end(), 3);
353 ffp.isvalid = true;
354
355 std::string data;
356 ffp.serializefingerprint(&data);
357 mega::FileFingerprint ffp2;
358 ASSERT_TRUE(ffp2.unserializefingerprint(&data));
359
360 ASSERT_EQ(ffp2.size, -1); // it is not clear why `size` is dealed with
361 ASSERT_EQ(ffp2.mtime, ffp.mtime);
362 ASSERT_EQ(ffp2.crc, ffp.crc);
363 ASSERT_EQ(ffp2.isvalid, ffp.isvalid);
364 }
365
TEST(FileFingerprint,genfingerprint_FileAccess_forTinyFile)366 TEST(FileFingerprint, genfingerprint_FileAccess_forTinyFile)
367 {
368 mega::FileFingerprint ffp;
369 MockFileAccess fa{1, {3, 4, 5, 6}};
370 ASSERT_TRUE(ffp.genfingerprint(&fa));
371 ASSERT_EQ(4, ffp.size);
372 ASSERT_EQ(1, ffp.mtime);
373 const std::array<int32_t, 4> expected = {100992003, 0, 0, 0};
374 ASSERT_EQ(expected, ffp.crc);
375 ASSERT_EQ(true, ffp.isvalid);
376 }
377
TEST(FileFingerprint,genfingerprint_FileAccess_forTinyFile_butReadFails)378 TEST(FileFingerprint, genfingerprint_FileAccess_forTinyFile_butReadFails)
379 {
380 mega::FileFingerprint ffp;
381 MockFileAccess fa{1, {3, 4, 5, 6}, true};
382 ASSERT_TRUE(ffp.genfingerprint(&fa));
383 ASSERT_EQ(-1, ffp.size);
384 ASSERT_EQ(1, ffp.mtime);
385 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
386 ASSERT_EQ(expected, ffp.crc);
387 ASSERT_EQ(false, ffp.isvalid);
388 }
389
TEST(FileFingerprint,genfingerprint_FileAccess_forSmallFile)390 TEST(FileFingerprint, genfingerprint_FileAccess_forSmallFile)
391 {
392 mega::FileFingerprint ffp;
393 std::vector<mega::byte> content(100);
394 std::iota(content.begin(), content.end(), mega::byte{0});
395 MockFileAccess fa{1, std::move(content)};
396 ASSERT_TRUE(ffp.genfingerprint(&fa));
397 ASSERT_EQ(100, ffp.size);
398 ASSERT_EQ(1, ffp.mtime);
399 const std::array<int32_t, 4> expected = {215253208, 661795201, 937191950, 562141813};
400 ASSERT_EQ(expected, ffp.crc);
401 ASSERT_EQ(true, ffp.isvalid);
402 }
403
TEST(FileFingerprint,genfingerprint_FileAccess_forSmallFile_butReadFails)404 TEST(FileFingerprint, genfingerprint_FileAccess_forSmallFile_butReadFails)
405 {
406 mega::FileFingerprint ffp;
407 std::vector<mega::byte> content(100);
408 std::iota(content.begin(), content.end(), mega::byte{0});
409 MockFileAccess fa{1, std::move(content), true};
410 ASSERT_TRUE(ffp.genfingerprint(&fa));
411 ASSERT_EQ(-1, ffp.size);
412 ASSERT_EQ(1, ffp.mtime);
413 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
414 ASSERT_EQ(expected, ffp.crc);
415 ASSERT_EQ(false, ffp.isvalid);
416 }
417
TEST(FileFingerprint,genfingerprint_FileAccess_forLargeFile)418 TEST(FileFingerprint, genfingerprint_FileAccess_forLargeFile)
419 {
420 mega::FileFingerprint ffp;
421 std::vector<mega::byte> content(20000);
422 std::iota(content.begin(), content.end(), mega::byte{0});
423 MockFileAccess fa{1, std::move(content)};
424 ASSERT_TRUE(ffp.genfingerprint(&fa));
425 ASSERT_EQ(20000, ffp.size);
426 ASSERT_EQ(1, ffp.mtime);
427 const std::array<int32_t, 4> expected = {-1424885571, 1204627086, 1194313128, -177560448};
428 ASSERT_EQ(expected, ffp.crc);
429 ASSERT_EQ(true, ffp.isvalid);
430 }
431
TEST(FileFingerprint,genfingerprint_FileAccess_forLargeFile_butReadFails)432 TEST(FileFingerprint, genfingerprint_FileAccess_forLargeFile_butReadFails)
433 {
434 mega::FileFingerprint ffp;
435 std::vector<mega::byte> content(20000);
436 std::iota(content.begin(), content.end(), mega::byte{0});
437 MockFileAccess fa{1, std::move(content), true};
438 ASSERT_TRUE(ffp.genfingerprint(&fa));
439 ASSERT_EQ(-1, ffp.size);
440 ASSERT_EQ(1, ffp.mtime);
441 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
442 ASSERT_EQ(expected, ffp.crc);
443 ASSERT_EQ(false, ffp.isvalid);
444 }
445
TEST(FileFingerprint,genfingerprint_InputStreamAccess_forTinyFile)446 TEST(FileFingerprint, genfingerprint_InputStreamAccess_forTinyFile)
447 {
448 mega::FileFingerprint ffp;
449 MockInputStreamAccess is{1, {3, 4, 5, 6}};
450 ASSERT_TRUE(ffp.genfingerprint(&is, is.getMTime()));
451 ASSERT_EQ(4, ffp.size);
452 ASSERT_EQ(1, ffp.mtime);
453 const std::array<int32_t, 4> expected = {100992003, 0, 0, 0};
454 ASSERT_EQ(expected, ffp.crc);
455 ASSERT_EQ(true, ffp.isvalid);
456 }
457
TEST(FileFingerprint,genfingerprint_InputStreamAccess_forTinyFile_butReadFails)458 TEST(FileFingerprint, genfingerprint_InputStreamAccess_forTinyFile_butReadFails)
459 {
460 mega::FileFingerprint ffp;
461 MockInputStreamAccess is{1, {3, 4, 5, 6}, true};
462 ASSERT_TRUE(ffp.genfingerprint(&is, is.getMTime()));
463 ASSERT_EQ(-1, ffp.size);
464 ASSERT_EQ(1, ffp.mtime);
465 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
466 ASSERT_EQ(expected, ffp.crc);
467 ASSERT_EQ(false, ffp.isvalid);
468 }
469
TEST(FileFingerprint,genfingerprint_InputStreamAccess_forTinyFile_butSizeNegative)470 TEST(FileFingerprint, genfingerprint_InputStreamAccess_forTinyFile_butSizeNegative)
471 {
472 mega::FileFingerprint ffp;
473 MockInputStreamAccess is{1, {3, 4, 5, 6}};
474 is.setSize(-1);
475 ASSERT_TRUE(ffp.genfingerprint(&is, is.getMTime()));
476 ASSERT_EQ(-1, ffp.size);
477 ASSERT_EQ(1, ffp.mtime);
478 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
479 ASSERT_EQ(expected, ffp.crc);
480 ASSERT_EQ(false, ffp.isvalid);
481 }
482
TEST(FileFingerprint,genfingerprint_InputStreamAccess_forSmallFile)483 TEST(FileFingerprint, genfingerprint_InputStreamAccess_forSmallFile)
484 {
485 mega::FileFingerprint ffp;
486 std::vector<mega::byte> content(100);
487 std::iota(content.begin(), content.end(), mega::byte{0});
488 MockInputStreamAccess is{1, std::move(content)};
489 ASSERT_TRUE(ffp.genfingerprint(&is, is.getMTime()));
490 ASSERT_EQ(100, ffp.size);
491 ASSERT_EQ(1, ffp.mtime);
492 const std::array<int32_t, 4> expected = {215253208, 661795201, 937191950, 562141813};
493 ASSERT_EQ(expected, ffp.crc);
494 ASSERT_EQ(true, ffp.isvalid);
495 }
496
TEST(FileFingerprint,genfingerprint_InputStreamAccess_forSmallFile_butReadFails)497 TEST(FileFingerprint, genfingerprint_InputStreamAccess_forSmallFile_butReadFails)
498 {
499 mega::FileFingerprint ffp;
500 std::vector<mega::byte> content(100);
501 std::iota(content.begin(), content.end(), mega::byte{0});
502 MockInputStreamAccess is{1, std::move(content), true};
503 ASSERT_TRUE(ffp.genfingerprint(&is, is.getMTime()));
504 ASSERT_EQ(-1, ffp.size);
505 ASSERT_EQ(1, ffp.mtime);
506 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
507 ASSERT_EQ(expected, ffp.crc);
508 ASSERT_EQ(false, ffp.isvalid);
509 }
510
TEST(FileFingerprint,genfingerprint_InputStreamAccess_forLargeFile)511 TEST(FileFingerprint, genfingerprint_InputStreamAccess_forLargeFile)
512 {
513 mega::FileFingerprint ffp;
514 std::vector<mega::byte> content(20000);
515 std::iota(content.begin(), content.end(), mega::byte{0});
516 MockInputStreamAccess is{1, std::move(content)};
517 ASSERT_TRUE(ffp.genfingerprint(&is, is.getMTime()));
518 ASSERT_EQ(20000, ffp.size);
519 ASSERT_EQ(1, ffp.mtime);
520 const std::array<int32_t, 4> expected = {-1236811658, -1236811658, -1236811658, -1236811658};
521 ASSERT_EQ(expected, ffp.crc);
522 ASSERT_EQ(true, ffp.isvalid);
523 }
524
TEST(FileFingerprint,genfingerprint_InputStreamAccess_forLargeFile_butReadFails)525 TEST(FileFingerprint, genfingerprint_InputStreamAccess_forLargeFile_butReadFails)
526 {
527 mega::FileFingerprint ffp;
528 std::vector<mega::byte> content(20000);
529 std::iota(content.begin(), content.end(), mega::byte{0});
530 MockInputStreamAccess is{1, std::move(content), true};
531 ASSERT_TRUE(ffp.genfingerprint(&is, is.getMTime()));
532 ASSERT_EQ(-1, ffp.size);
533 ASSERT_EQ(1, ffp.mtime);
534 const std::array<int32_t, 4> expected = {0, 0, 0, 0};
535 ASSERT_EQ(expected, ffp.crc);
536 ASSERT_EQ(false, ffp.isvalid);
537 }
538
TEST(FileFingerprint,light_genfingerprint)539 TEST(FileFingerprint, light_genfingerprint)
540 {
541 mega::LightFileFingerprint ffp;
542 const m_off_t filesize = 42;
543 const mega::m_time_t filemtime = 13;
544 ASSERT_TRUE(ffp.genfingerprint(filesize, filemtime));
545 ASSERT_EQ(filesize, ffp.size);
546 ASSERT_EQ(filemtime, ffp.mtime);
547 }
548
TEST(FileFingerprint,light_genfingerprint_compare_equal)549 TEST(FileFingerprint, light_genfingerprint_compare_equal)
550 {
551 mega::LightFileFingerprint ffp1;
552 ffp1.size = 42;
553 ffp1.mtime = 13;
554 mega::LightFileFingerprint ffp2;
555 ffp2.size = 42;
556 ffp2.mtime = 13;
557 ASSERT_TRUE(ffp1 == ffp2);
558 }
559
TEST(FileFingerprint,light_genfingerprint_compare_not_equal)560 TEST(FileFingerprint, light_genfingerprint_compare_not_equal)
561 {
562 mega::LightFileFingerprint ffp1;
563 ffp1.size = 42;
564 ffp1.mtime = 13;
565 mega::LightFileFingerprint ffp2;
566 ffp2.size = 42;
567 ffp2.mtime = 12;
568 ASSERT_FALSE(ffp1 == ffp2);
569 }
570
TEST(FileFingerprint,light_genfingerprint_firstSmaller_becauseOfSize)571 TEST(FileFingerprint, light_genfingerprint_firstSmaller_becauseOfSize)
572 {
573 mega::LightFileFingerprint ffp1;
574 ffp1.size = 41;
575 ffp1.mtime = 13;
576 mega::LightFileFingerprint ffp2;
577 ffp2.size = 42;
578 ffp2.mtime = 13;
579 ASSERT_TRUE(mega::LightFileFingerprintCmp{}(&ffp1, &ffp2));
580 }
581
TEST(FileFingerprint,light_genfingerprint_firstSmaller_becauseOfMTime)582 TEST(FileFingerprint, light_genfingerprint_firstSmaller_becauseOfMTime)
583 {
584 mega::LightFileFingerprint ffp1;
585 ffp1.size = 42;
586 ffp1.mtime = 12;
587 mega::LightFileFingerprint ffp2;
588 ffp2.size = 42;
589 ffp2.mtime = 13;
590 ASSERT_TRUE(mega::LightFileFingerprintCmp{}(&ffp1, &ffp2));
591 }
592
TEST(FileFingerprint,light_genfingerprint_firstNotSmaller)593 TEST(FileFingerprint, light_genfingerprint_firstNotSmaller)
594 {
595 mega::LightFileFingerprint ffp1;
596 ffp1.size = 42;
597 ffp1.mtime = 13;
598 mega::LightFileFingerprint ffp2;
599 ffp2.size = 42;
600 ffp2.mtime = 13;
601 ASSERT_FALSE(mega::LightFileFingerprintCmp{}(&ffp1, &ffp2));
602 }
603