MCPcopy Create free account
hub / github.com/comaps/comaps / UNIT_TEST

Function UNIT_TEST

libs/mwm_diff/mwm_diff_tests/diff_tests.cpp:21–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19using std::string, std::vector;
20
21UNIT_TEST(IncrementalUpdates_Smoke)
22{
23 base::ScopedLogAbortLevelChanger ignoreLogError(base::LogLevel::LCRITICAL);
24
25 string const oldMwmPath = base::JoinPath(GetPlatform().WritableDir(), "minsk-pass.mwm");
26 string const newMwmPath1 = base::JoinPath(GetPlatform().WritableDir(), "minsk-pass-new1.mwm");
27 string const newMwmPath2 = base::JoinPath(GetPlatform().WritableDir(), "minsk-pass-new2.mwm");
28 string const diffPath = base::JoinPath(GetPlatform().WritableDir(), "minsk-pass.mwmdiff");
29
30 SCOPE_GUARD(cleanup, [&]
31 {
32 FileWriter::DeleteFileX(newMwmPath1);
33 FileWriter::DeleteFileX(newMwmPath2);
34 FileWriter::DeleteFileX(diffPath);
35 });
36
37 {
38 // Create an empty file.
39 FileWriter writer(newMwmPath1);
40 }
41
42 base::Cancellable cancellable;
43 TEST(MakeDiff(oldMwmPath, newMwmPath1, diffPath), ());
44 TEST_EQUAL(ApplyDiff(oldMwmPath, newMwmPath2, diffPath, cancellable), DiffApplicationResult::Ok, ());
45
46 {
47 // Alter the old mwm slightly.
48 vector<uint8_t> oldMwmContents = base::ReadFile(oldMwmPath);
49 size_t const sz = oldMwmContents.size();
50 for (size_t i = 3 * sz / 10; i < 4 * sz / 10; i++)
51 oldMwmContents[i] += static_cast<uint8_t>(i);
52
53 FileWriter writer(newMwmPath1);
54 writer.Write(oldMwmContents.data(), oldMwmContents.size());
55 }
56
57 TEST(MakeDiff(oldMwmPath, newMwmPath1, diffPath), ());
58 TEST_EQUAL(ApplyDiff(oldMwmPath, newMwmPath2, diffPath, cancellable), DiffApplicationResult::Ok, ());
59
60 TEST(base::IsEqualFiles(newMwmPath1, newMwmPath2), ());
61
62 cancellable.Cancel();
63 TEST_EQUAL(ApplyDiff(oldMwmPath, newMwmPath2, diffPath, cancellable), DiffApplicationResult::Cancelled, ());
64 cancellable.Reset();
65
66 {
67 // Corrupt the diff file contents.
68 vector<uint8_t> diffContents = base::ReadFile(diffPath);
69
70 // Leave the version bits intact.
71 for (size_t i = 4; i < diffContents.size(); i += 2)
72 diffContents[i] ^= 255;
73
74 FileWriter writer(diffPath);
75 writer.Write(diffContents.data(), diffContents.size());
76 }
77
78 TEST_EQUAL(ApplyDiff(oldMwmPath, newMwmPath2, diffPath, cancellable), DiffApplicationResult::Failed, ());

Callers

nothing calls this directly

Calls 12

JoinPathFunction · 0.85
DeleteFileXFunction · 0.85
TESTFunction · 0.85
MakeDiffFunction · 0.85
IsEqualFilesFunction · 0.85
ApplyDiffFunction · 0.50
ReadFileFunction · 0.50
sizeMethod · 0.45
WriteMethod · 0.45
dataMethod · 0.45
CancelMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected