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
|
/**
* @file NodesMatchedByFsid_test.cpp
* @brief Tests for the methods used to search for nodes matched by fsid.
*/
#ifdef ENABLE_SYNC
#include <gtest/gtest.h>
#include <mega/syncinternals/syncinternals.h>
using namespace mega;
namespace
{
/**
* @brief A default value for the user owner handle.
*/
constexpr handle COMMON_USER_OWNER = 1;
/**
* @brief A default value for the isFsidReused flag.
*/
constexpr bool FSID_REUSED = false;
/**
* @brief A default SourceNodeMatchByFSIDContext struct.
*/
constexpr SourceNodeMatchByFSIDContext BASIC_SOURCE_CONTEXT{FSID_REUSED,
ExclusionState::ES_INCLUDED};
/**
* @brief A default mtime.
*/
constexpr m_time_t SIMPLE_MTIME = 1;
/**
* @brief A default size.
*/
constexpr m_off_t SIMPLE_SIZE = 10;
/**
* @brief Generates a light FileFingerprint (mtime and size).
*
* This light FileFingerprint is enough for comparison purposes,
* the CRC needs real data to be calculated, and we are not
* testing FileFingerprint fields here.
*
* @param mtime The modification time of the file.
* @param size The size of the file.
* @return A valid FileFingerprint with the mtime and size. CRC would be empty.
*/
FileFingerprint genLightFingerprint(const m_time_t mtime = SIMPLE_MTIME,
const m_off_t size = SIMPLE_SIZE)
{
FileFingerprint lightFp{};
lightFp.mtime = mtime;
lightFp.size = size;
lightFp.isvalid = true;
return lightFp;
}
/**
* @brief Generates a NodeMatchByFSIDAttributes structure.
*
* @param nodeType The type of the node (FILENODE or FOLDERNODE).
* @param filesystemFingerprint The fingerprint of the filesystem. It needs an int for the
* fingerprint and a string for the UUID.
* @param userHandle The handle of the user owner.
* @param fileFingerprint The fingerprint of the file.
* @return A NodeMatchByFSIDAttributes struct with the assigned fields.
*/
NodeMatchByFSIDAttributes
genMatchAttributes(const nodetype_t nodeType = FILENODE,
const fsfp_t& filesystemFingerprint = {1, "UUID"},
const handle userHandle = COMMON_USER_OWNER,
const FileFingerprint& fileFingerprint = genLightFingerprint(),
const FileFingerprint& realFingerprint = genLightFingerprint())
{
return NodeMatchByFSIDAttributes{nodeType,
filesystemFingerprint,
userHandle,
fileFingerprint,
realFingerprint};
}
} // namespace
/**
* @brief Tests a match: both nodes are equivalent.
*/
TEST(NodesMatchedByFSIDTest, NodesAreEquivalent)
{
const auto sourceNodeAttributes{genMatchAttributes()};
const auto targetNodeAttributes{sourceNodeAttributes};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes,
targetNodeAttributes,
BASIC_SOURCE_CONTEXT),
NodeMatchByFSIDResult::Matched);
}
/**
* @brief Tests mismatch due to FSID reused by the source node.
*/
TEST(NodesMatchedByFSIDTest, SourceNodeFsidReused)
{
const auto sourceNodeAttributes{genMatchAttributes()};
const auto targetNodeAttributes{sourceNodeAttributes};
constexpr bool fsidIsReused = true;
constexpr SourceNodeMatchByFSIDContext context{fsidIsReused, ExclusionState::ES_INCLUDED};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes, targetNodeAttributes, context),
NodeMatchByFSIDResult::SourceFsidReused);
}
/**
* @brief Test mismatch due to different filesystem fingerprints.
*/
TEST(NodesMatchedByFSIDTest, DifferentFilesystemsFingerprints)
{
const fsfp_t fsfp1{1, "UUID"};
const fsfp_t fsfp2{2, "UUID2"};
const auto sourceNodeAttributes{genMatchAttributes(FILENODE, fsfp1)};
const auto targetNodeAttributes{genMatchAttributes(FILENODE, fsfp2)};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes,
targetNodeAttributes,
BASIC_SOURCE_CONTEXT),
NodeMatchByFSIDResult::DifferentFilesystems);
}
/**
* @brief Tests mismatch due to different node types.
*/
TEST(NodesMatchedByFSIDTest, DifferentNodeTypes)
{
const auto sourceNodeAttributes{genMatchAttributes(FILENODE)};
const auto targetNodeAttributes{genMatchAttributes(FOLDERNODE)};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes,
targetNodeAttributes,
BASIC_SOURCE_CONTEXT),
NodeMatchByFSIDResult::DifferentTypes);
}
/**
* @brief Tests mismatch due to different owners.
*/
TEST(NodesMatchedByFSIDTest, DifferentOwners)
{
constexpr handle sourceOwner = 1;
constexpr handle targetOwner = 2;
const fsfp_t fsfp1{1, "UUID"};
const auto sourceNodeAttributes{genMatchAttributes(FILENODE, fsfp1, sourceOwner)};
const auto targetNodeAttributes{genMatchAttributes(FILENODE, fsfp1, targetOwner)};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes,
targetNodeAttributes,
BASIC_SOURCE_CONTEXT),
NodeMatchByFSIDResult::DifferentOwners);
}
/**
* @brief Tests mismatch due to exclusion unknown.
*/
TEST(NodesMatchedByFSIDTest, SourceNodeExclusionStateIsUnknown)
{
const auto sourceNodeAttributes{genMatchAttributes()};
const auto targetNodeAttributes{sourceNodeAttributes};
constexpr SourceNodeMatchByFSIDContext context{false, ExclusionState::ES_UNKNOWN};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes, targetNodeAttributes, context),
NodeMatchByFSIDResult::SourceExclusionUnknown);
}
/**
* @brief Tests mismatch due to node exclusion.
*/
TEST(NodesMatchedByFSIDTest, SourceNodeIsExcluded)
{
const auto sourceNodeAttributes{genMatchAttributes()};
const auto targetNodeAttributes{sourceNodeAttributes};
constexpr SourceNodeMatchByFSIDContext context{false, ExclusionState::ES_EXCLUDED};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes, targetNodeAttributes, context),
NodeMatchByFSIDResult::SourceIsExcluded);
}
/**
* @brief Test mismatch due to different fingerprint due to mtime.
*/
TEST(NodesMatchedByFSIDTest, DifferentFingerprintDueToMtime)
{
const auto sourceFp = genLightFingerprint();
const auto targetFp = genLightFingerprint(SIMPLE_MTIME + 30, SIMPLE_SIZE);
const fsfp_t fsfp1{1, "UUID"};
const auto sourceNodeAttributes{
genMatchAttributes(FILENODE, fsfp1, COMMON_USER_OWNER, sourceFp)};
const auto targetNodeAttributes{
genMatchAttributes(FILENODE, fsfp1, COMMON_USER_OWNER, targetFp)};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes,
targetNodeAttributes,
BASIC_SOURCE_CONTEXT),
NodeMatchByFSIDResult::DifferentFingerprintOnlyMtime);
}
/**
* @brief Test mismatch due to different fingerprint due to size.
*/
TEST(NodesMatchedByFSIDTest, DifferentFingerprintDueToSize)
{
const auto sourceFp = genLightFingerprint();
const auto targetFp = genLightFingerprint(SIMPLE_MTIME, SIMPLE_SIZE + 1);
const fsfp_t fsfp1{1, "UUID"};
const auto sourceNodeAttributes{
genMatchAttributes(FILENODE, fsfp1, COMMON_USER_OWNER, sourceFp)};
const auto targetNodeAttributes{
genMatchAttributes(FILENODE, fsfp1, COMMON_USER_OWNER, targetFp)};
ASSERT_EQ(areNodesMatchedByFsidEquivalent(sourceNodeAttributes,
targetNodeAttributes,
BASIC_SOURCE_CONTEXT),
NodeMatchByFSIDResult::DifferentFingerprint);
}
#endif // ENABLE_SYNC
|