1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/**
* (c) 2021 by Mega Limited, Wellsford, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the rules set forth in the Terms of Service.
*
* The MEGA SDK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/
#include <memory>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "megaapi_impl.h"
#include "mega/sync.h"
#ifdef ENABLE_SYNC
namespace SyncConflictTests {
using namespace mega;
TEST(SyncStallHashTest, MegaSyncStallPrivateGetHash)
{
// Create some SyncStallEntry objects to initialize the MegaSyncStallPrivate after
SyncStallEntry e1{
SyncWaitReason::FileIssue,
true,
false,
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink }
};
SyncStallEntry e1_same{
SyncWaitReason::FileIssue,
true,
false,
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink }
};
SyncStallEntry e2{
SyncWaitReason::FileIssue,
true,
false,
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::NoProblem }
};
std::hash<SyncStallEntry> hashEntryGetter;
ASSERT_EQ(hashEntryGetter(e1), hashEntryGetter(e1));
ASSERT_EQ(hashEntryGetter(e1), hashEntryGetter(e1_same));
ASSERT_NE(hashEntryGetter(e1), hashEntryGetter(e2));
MegaSyncStallPrivate s1(e1);
MegaSyncStallPrivate s1_same(e1_same);
MegaSyncStallPrivate s2(e2);
ASSERT_EQ(hashEntryGetter(e1), s1.getHash());
ASSERT_EQ(hashEntryGetter(e1_same), s1_same.getHash());
ASSERT_EQ(hashEntryGetter(e2), s2.getHash());
ASSERT_EQ(s1.getHash(), s1.getHash());
ASSERT_EQ(s1.getHash(), s1_same.getHash());
ASSERT_NE(s1.getHash(), s2.getHash());
}
TEST(SyncStallHashTest, MegaSyncNameConflictStallPrivateGetHash)
{
// Create some NameConflict objects to initialize the MegaSyncNameConflictStallPrivate after
std::vector<NameConflict::NameHandle> nhVec{};
std::vector<LocalPath> clashingLNames{};
NameConflict nc1{"cloudPath", nhVec, LocalPath(), clashingLNames};
NameConflict nc1_same{"cloudPath", nhVec, LocalPath(), clashingLNames};
nhVec.emplace_back("nameHandle", NodeHandle());
clashingLNames.emplace_back(LocalPath::fromAbsolutePath("./test/local"));
NameConflict nc2{"cloudPath", nhVec, LocalPath(), clashingLNames};
std::hash<NameConflict> hashNCGetter;
ASSERT_EQ(hashNCGetter(nc1), hashNCGetter(nc1));
ASSERT_EQ(hashNCGetter(nc1), hashNCGetter(nc1_same));
ASSERT_NE(hashNCGetter(nc1), hashNCGetter(nc2));
MegaSyncNameConflictStallPrivate s1(nc1);
MegaSyncNameConflictStallPrivate s1_same(nc1_same);
MegaSyncNameConflictStallPrivate s2(nc2);
ASSERT_EQ(hashNCGetter(nc1), s1.getHash());
ASSERT_EQ(hashNCGetter(nc1_same), s1_same.getHash());
ASSERT_EQ(hashNCGetter(nc2), s2.getHash());
ASSERT_EQ(s1.getHash(), s1.getHash());
ASSERT_EQ(s1.getHash(), s1_same.getHash());
ASSERT_NE(s1.getHash(), s2.getHash());
}
/**
* @class MegaSyncStallListTest
* @brief Dummy implementation of the MegaSyncStallList for testing purpose
*
*/
class MegaSyncStallListTest: public MegaSyncStallList
{
public:
std::vector<std::shared_ptr<MegaSyncStall>> mStalls;
MegaSyncStallListTest(std::vector<std::shared_ptr<MegaSyncStall>>&& stalls):
mStalls{stalls}
{}
size_t size() const override
{
return mStalls.size();
}
const MegaSyncStall* get(size_t i) const override
{
return mStalls[i].get();
}
};
class MegaSyncStallMapTest: public MegaSyncStallMapPrivate
{
public:
MegaSyncStallMapTest():
MegaSyncStallMapPrivate()
{}
void add(const MegaHandle backupId, const MegaSyncStallListPrivate& testList)
{
mStallsMap.emplace(backupId, testList);
}
};
TEST(SyncStallHashTest, MegaSyncStallIssuesMapGetHash)
{
std::vector<NameConflict::NameHandle> nhVec{};
std::vector<LocalPath> clashingLNames{};
NameConflict nc1{"cloudPath1", nhVec, LocalPath(), clashingLNames};
std::shared_ptr<MegaSyncNameConflictStallPrivate> s1{new MegaSyncNameConflictStallPrivate(nc1)};
nhVec.emplace_back("nameHandle", NodeHandle());
clashingLNames.emplace_back(LocalPath::fromAbsolutePath("./test/local"));
NameConflict nc2{"cloudPath2", nhVec, LocalPath(), clashingLNames};
std::shared_ptr<MegaSyncNameConflictStallPrivate> s2{new MegaSyncNameConflictStallPrivate(nc2)};
SyncStallEntry e1{
SyncWaitReason::FileIssue,
true,
false,
{NodeHandle{}, "currentPath1", PathProblem::DetectedSymlink},
{NodeHandle{}, "currentPath1", PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink }
};
std::shared_ptr<MegaSyncStallPrivate> s3{new MegaSyncStallPrivate(e1)};
SyncStallEntry e2{
SyncWaitReason::FileIssue,
true,
false,
{NodeHandle{}, "currentPath2", PathProblem::DetectedSymlink},
{NodeHandle{}, "currentPath2", PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::NoProblem }
};
std::shared_ptr<MegaSyncStallPrivate> s4{new MegaSyncStallPrivate(e1)};
MegaSyncStallListPrivate sl1;
sl1.addStall(s1);
sl1.addStall(s3);
MegaSyncStallListPrivate sl2;
sl1.addStall(s2);
sl1.addStall(s4);
MegaSyncStallListPrivate sl3;
sl1.addStall(s2);
sl1.addStall(s3);
MegaSyncStallMapTest m1;
m1.add(111111111111111, sl1);
m1.add(222222222222222, sl2);
MegaSyncStallMapTest m2;
m2.add(111111111111111, sl1);
m2.add(222222222222222, sl2);
MegaSyncStallMapTest m3;
m2.add(222222222222222, sl2);
m2.add(111111111111111, sl1);
MegaSyncStallMapTest m4;
m4.add(222222222222222, sl1);
m4.add(111111111111111, sl3);
ASSERT_EQ(m1.getHash(), m2.getHash());
ASSERT_NE(m1.getHash(), m3.getHash());
ASSERT_NE(m2.getHash(), m4.getHash());
}
TEST(SyncStallHashTest, MegaSyncStallListGetHash)
{
std::vector<NameConflict::NameHandle> nhVec{};
std::vector<LocalPath> clashingLNames{};
NameConflict nc1{"cloudPath", nhVec, LocalPath(), clashingLNames};
std::shared_ptr<MegaSyncNameConflictStallPrivate> s1{new MegaSyncNameConflictStallPrivate(nc1)};
SyncStallEntry e1{
SyncWaitReason::FileIssue,
true,
false,
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{NodeHandle{}, "currentPath", PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink},
{LocalPath{}, PathProblem::DetectedSymlink }
};
std::shared_ptr<MegaSyncStallPrivate> s2{new MegaSyncStallPrivate(e1)};
MegaSyncStallListTest testList1{
std::vector<std::shared_ptr<MegaSyncStall>>{s1, s2}
};
MegaSyncStallListTest testList1_same{
std::vector<std::shared_ptr<MegaSyncStall>>{s1, s2}
};
MegaSyncStallListTest testList2{
std::vector<std::shared_ptr<MegaSyncStall>>{s2, s1}
};
MegaSyncStallListTest testList3{std::vector<std::shared_ptr<MegaSyncStall>>{s2}};
ASSERT_EQ(testList1.getHash(), testList1.getHash());
ASSERT_EQ(testList1.getHash(), testList1_same.getHash());
ASSERT_NE(testList1.getHash(), testList2.getHash());
ASSERT_NE(testList1.getHash(), testList3.getHash());
ASSERT_NE(testList2.getHash(), testList3.getHash());
}
} // namespace
#endif // ENABLE_SYNC
|