| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimemagicrule.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | static const char magicRuleTypes_string[] = | - | ||||||||||||||||||||||||
| 9 | "invalid\0" | - | ||||||||||||||||||||||||
| 10 | "string\0" | - | ||||||||||||||||||||||||
| 11 | "host16\0" | - | ||||||||||||||||||||||||
| 12 | "host32\0" | - | ||||||||||||||||||||||||
| 13 | "big16\0" | - | ||||||||||||||||||||||||
| 14 | "big32\0" | - | ||||||||||||||||||||||||
| 15 | "little16\0" | - | ||||||||||||||||||||||||
| 16 | "little32\0" | - | ||||||||||||||||||||||||
| 17 | "byte\0" | - | ||||||||||||||||||||||||
| 18 | "\0"; | - | ||||||||||||||||||||||||
| 19 | - | |||||||||||||||||||||||||
| 20 | static const int magicRuleTypes_indices[] = { | - | ||||||||||||||||||||||||
| 21 | 0, 8, 15, 22, 29, 35, 41, 50, 59, 65, 0 | - | ||||||||||||||||||||||||
| 22 | }; | - | ||||||||||||||||||||||||
| 23 | - | |||||||||||||||||||||||||
| 24 | QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName) | - | ||||||||||||||||||||||||
| 25 | { | - | ||||||||||||||||||||||||
| 26 | for (int i = String; i <= Byte 
 | 0-7377 | ||||||||||||||||||||||||
| 27 | if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i] 
 | 3319-4058 | ||||||||||||||||||||||||
| 28 | return executed 4058 times by 1 test: Type(i); return Type(i);Executed by: 
 executed 4058 times by 1 test:  return Type(i);Executed by: 
 | 4058 | ||||||||||||||||||||||||
| 29 | } executed 3319 times by 1 test:  end of blockExecuted by: 
 | 3319 | ||||||||||||||||||||||||
| 30 | return never executed: Invalid; return Invalid;never executed:  return Invalid; | 0 | ||||||||||||||||||||||||
| 31 | } | - | ||||||||||||||||||||||||
| 32 | - | |||||||||||||||||||||||||
| 33 | QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType) | - | ||||||||||||||||||||||||
| 34 | { | - | ||||||||||||||||||||||||
| 35 | return never executed: magicRuleTypes_string + magicRuleTypes_indices[theType]; return magicRuleTypes_string + magicRuleTypes_indices[theType];never executed:  return magicRuleTypes_string + magicRuleTypes_indices[theType]; | 0 | ||||||||||||||||||||||||
| 36 | } | - | ||||||||||||||||||||||||
| 37 | - | |||||||||||||||||||||||||
| 38 | class QMimeMagicRulePrivate | - | ||||||||||||||||||||||||
| 39 | { | - | ||||||||||||||||||||||||
| 40 | public: | - | ||||||||||||||||||||||||
| 41 | bool operator==(const QMimeMagicRulePrivate &other) const; | - | ||||||||||||||||||||||||
| 42 | - | |||||||||||||||||||||||||
| 43 | QMimeMagicRule::Type type; | - | ||||||||||||||||||||||||
| 44 | QByteArray value; | - | ||||||||||||||||||||||||
| 45 | int startPos; | - | ||||||||||||||||||||||||
| 46 | int endPos; | - | ||||||||||||||||||||||||
| 47 | QByteArray mask; | - | ||||||||||||||||||||||||
| 48 | - | |||||||||||||||||||||||||
| 49 | QByteArray pattern; | - | ||||||||||||||||||||||||
| 50 | quint32 number; | - | ||||||||||||||||||||||||
| 51 | quint32 numberMask; | - | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | typedef bool (*MatchFunction)(const QMimeMagicRulePrivate *d, const QByteArray &data); | - | ||||||||||||||||||||||||
| 54 | MatchFunction matchFunction; | - | ||||||||||||||||||||||||
| 55 | }; | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | bool QMimeMagicRulePrivate::operator==(const QMimeMagicRulePrivate &other) const | - | ||||||||||||||||||||||||
| 58 | { | - | ||||||||||||||||||||||||
| 59 | return never executed: type == other.type return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction;
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 60 | value == other.value 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 61 | startPos == other.startPos 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 62 | endPos == other.endPos 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 63 | mask == other.mask 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 64 | pattern == other.pattern 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 65 | number == other.number 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 66 | numberMask == other.numberMask 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 67 | matchFunction == other.matchFunction 
 never executed:  return type == other.type && value == other.value && startPos == other.startPos && endPos == other.endPos && mask == other.mask && pattern == other.pattern && number == other.number && numberMask == other.numberMask && matchFunction == other.matchFunction; | 0 | ||||||||||||||||||||||||
| 68 | } | - | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | - | |||||||||||||||||||||||||
| 71 | bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, | - | ||||||||||||||||||||||||
| 72 | int valueLength, const char *valueData, const char *mask) | - | ||||||||||||||||||||||||
| 73 | { | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart); | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | if (!mask 
 | 9901-17592 | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | bool found = false; | - | ||||||||||||||||||||||||
| 82 | for (int i = rangeStart; i < rangeStart + rangeLength 
 | 5928-39384 | ||||||||||||||||||||||||
| 83 | if (i + valueLength > dataSize 
 | 3928-35456 | ||||||||||||||||||||||||
| 84 | break; executed 3928 times by 1 test:  break;Executed by: 
 | 3928 | ||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | if (memcmp(valueData, dataPtr + i, valueLength) == 0 
 | 45-35411 | ||||||||||||||||||||||||
| 87 | found = true; | - | ||||||||||||||||||||||||
| 88 | break; executed 45 times by 1 test:  break;Executed by: 
 | 45 | ||||||||||||||||||||||||
| 89 | } | - | ||||||||||||||||||||||||
| 90 | } executed 35411 times by 1 test:  end of blockExecuted by: 
 | 35411 | ||||||||||||||||||||||||
| 91 | if (!found 
 | 45-9856 | ||||||||||||||||||||||||
| 92 | return executed 9856 times by 1 test: false; return false;Executed by: 
 executed 9856 times by 1 test:  return false;Executed by: 
 | 9856 | ||||||||||||||||||||||||
| 93 | } executed 45 times by 1 test: else { end of blockExecuted by: 
 | 45 | ||||||||||||||||||||||||
| 94 | bool found = false; | - | ||||||||||||||||||||||||
| 95 | const char *readDataBase = dataPtr + rangeStart; | - | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | const int maxStartPos = dataNeeded - valueLength + 1; | - | ||||||||||||||||||||||||
| 101 | for (int i = 0; i < maxStartPos 
 | 17592-38620 | ||||||||||||||||||||||||
| 102 | const char *d = readDataBase + i; | - | ||||||||||||||||||||||||
| 103 | bool valid = true; | - | ||||||||||||||||||||||||
| 104 | for (int idx = 0; idx < valueLength 
 | 46-39071 | ||||||||||||||||||||||||
| 105 | if (((* 
 
 | 497-38574 | ||||||||||||||||||||||||
| 106 | valid = false; | - | ||||||||||||||||||||||||
| 107 | break; executed 38574 times by 1 test:  break;Executed by: 
 | 38574 | ||||||||||||||||||||||||
| 108 | } | - | ||||||||||||||||||||||||
| 109 | } executed 497 times by 1 test:  end of blockExecuted by: 
 | 497 | ||||||||||||||||||||||||
| 110 | if (valid 
 | 46-38574 | ||||||||||||||||||||||||
| 111 | found = true; executed 46 times by 1 test:  found = true;Executed by: 
 | 46 | ||||||||||||||||||||||||
| 112 | } executed 38620 times by 1 test:  end of blockExecuted by: 
 | 38620 | ||||||||||||||||||||||||
| 113 | if (!found 
 | 46-17546 | ||||||||||||||||||||||||
| 114 | return executed 17546 times by 1 test: false; return false;Executed by: 
 executed 17546 times by 1 test:  return false;Executed by: 
 | 17546 | ||||||||||||||||||||||||
| 115 | } executed 46 times by 1 test:  end of blockExecuted by: 
 | 46 | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | return executed 91 times by 1 test: true; return true;Executed by: 
 executed 91 times by 1 test:  return true;Executed by: 
 | 91 | ||||||||||||||||||||||||
| 118 | } | - | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | static bool matchString(const QMimeMagicRulePrivate *d, const QByteArray &data) | - | ||||||||||||||||||||||||
| 121 | { | - | ||||||||||||||||||||||||
| 122 | const int rangeLength = d->endPos - d->startPos + 1; | - | ||||||||||||||||||||||||
| 123 | return executed 17377 times by 1 test: QMimeMagicRule::matchSubstring(data.constData(), data.size(), d->startPos, rangeLength, d->pattern.size(), d->pattern.constData(), d->mask.constData()); return QMimeMagicRule::matchSubstring(data.constData(), data.size(), d->startPos, rangeLength, d->pattern.size(), d->pattern.constData(), d->mask.constData());Executed by: 
 executed 17377 times by 1 test:  return QMimeMagicRule::matchSubstring(data.constData(), data.size(), d->startPos, rangeLength, d->pattern.size(), d->pattern.constData(), d->mask.constData());Executed by: 
 | 17377 | ||||||||||||||||||||||||
| 124 | } | - | ||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | template <typename T> | - | ||||||||||||||||||||||||
| 127 | static bool matchNumber(const QMimeMagicRulePrivate *d, const QByteArray &data) | - | ||||||||||||||||||||||||
| 128 | { | - | ||||||||||||||||||||||||
| 129 | const T value(d->number); | - | ||||||||||||||||||||||||
| 130 | const T mask(d->numberMask); | - | ||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | const char *p = data.constData() + d->startPos; | - | ||||||||||||||||||||||||
| 136 | const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), d->endPos + 1); | - | ||||||||||||||||||||||||
| 137 | for ( ; p <= e 
 | 1854-3457 | ||||||||||||||||||||||||
| 138 | if (( 
 
 | 13-3444 | ||||||||||||||||||||||||
| 139 | return executed 13 times by 1 test: true; return true;Executed by: 
 executed 13 times by 1 test:  return true;Executed by: 
 | 13 | ||||||||||||||||||||||||
| 140 | } executed 3444 times by 1 test:  end of blockExecuted by: 
 | 3444 | ||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||
| 142 | return executed 1854 times by 1 test: false; return false;Executed by: 
 executed 1854 times by 1 test:  return false;Executed by: 
 | 1854 | ||||||||||||||||||||||||
| 143 | } | - | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | static inline QByteArray makePattern(const QByteArray &value) | - | ||||||||||||||||||||||||
| 146 | { | - | ||||||||||||||||||||||||
| 147 | QByteArray pattern(value.size(), Qt::Uninitialized); | - | ||||||||||||||||||||||||
| 148 | char *data = pattern.data(); | - | ||||||||||||||||||||||||
| 149 | - | |||||||||||||||||||||||||
| 150 | const char *p = value.constData(); | - | ||||||||||||||||||||||||
| 151 | const char *e = p + value.size(); | - | ||||||||||||||||||||||||
| 152 | for ( ; p < e 
 | 3431-33647 | ||||||||||||||||||||||||
| 153 | if (* 
 
 
 
 | 0-31392 | ||||||||||||||||||||||||
| 154 | if (* 
 
 | 775-1480 | ||||||||||||||||||||||||
| 155 | char c = 0; | - | ||||||||||||||||||||||||
| 156 | for (int i = 0; i < 2 
 
 | 10-1550 | ||||||||||||||||||||||||
| 157 | ++p; | - | ||||||||||||||||||||||||
| 158 | if (* 
 
 
 
 | 0-1540 | ||||||||||||||||||||||||
| 159 | c = (c << 4) + *p - '0'; executed 1260 times by 1 test:  c = (c << 4) + *p - '0';Executed by: 
 | 1260 | ||||||||||||||||||||||||
| 160 | else if (* 
 
 
 
 | 0-220 | ||||||||||||||||||||||||
| 161 | c = (c << 4) + *p - 'a' + 10; executed 220 times by 1 test:  c = (c << 4) + *p - 'a' + 10;Executed by: 
 | 220 | ||||||||||||||||||||||||
| 162 | else if (* 
 
 
 
 | 0-60 | ||||||||||||||||||||||||
| 163 | c = (c << 4) + *p - 'A' + 10; executed 60 times by 1 test:  c = (c << 4) + *p - 'A' + 10;Executed by: 
 | 60 | ||||||||||||||||||||||||
| 164 | else | - | ||||||||||||||||||||||||
| 165 | continue; never executed:  continue; | 0 | ||||||||||||||||||||||||
| 166 | } | - | ||||||||||||||||||||||||
| 167 | *data++ = c; | - | ||||||||||||||||||||||||
| 168 | } executed 775 times by 1 test: else if (* end of blockExecuted by: 
 
 
 
 
 | 45-1435 | ||||||||||||||||||||||||
| 169 | char c = *p - '0'; | - | ||||||||||||||||||||||||
| 170 | if (p + 1 < e 
 
 
 | 0-1195 | ||||||||||||||||||||||||
| 171 | c = (c << 3) + *(++p) - '0'; | - | ||||||||||||||||||||||||
| 172 | if (p + 1 < e 
 
 
 
 | 0-1055 | ||||||||||||||||||||||||
| 173 | c = (c << 3) + *(++p) - '0'; executed 1045 times by 1 test:  c = (c << 3) + *(++p) - '0';Executed by: 
 | 1045 | ||||||||||||||||||||||||
| 174 | } executed 1060 times by 1 test:  end of blockExecuted by: 
 | 1060 | ||||||||||||||||||||||||
| 175 | *data++ = c; | - | ||||||||||||||||||||||||
| 176 | } executed 1280 times by 1 test: else if (* end of blockExecuted by: 
 
 
 | 75-1280 | ||||||||||||||||||||||||
| 177 | *data++ = '\n'; | - | ||||||||||||||||||||||||
| 178 | } executed 75 times by 1 test: else if (* end of blockExecuted by: 
 
 
 | 10-115 | ||||||||||||||||||||||||
| 179 | *data++ = '\r'; | - | ||||||||||||||||||||||||
| 180 | } executed 10 times by 1 test: else if (* end of blockExecuted by: 
 
 
 | 10-100 | ||||||||||||||||||||||||
| 181 | *data++ = '\t'; | - | ||||||||||||||||||||||||
| 182 | } executed 15 times by 1 test: else { end of blockExecuted by: 
 | 15 | ||||||||||||||||||||||||
| 183 | *data++ = *p; | - | ||||||||||||||||||||||||
| 184 | } executed 100 times by 1 test:  end of blockExecuted by: 
 | 100 | ||||||||||||||||||||||||
| 185 | } else { | - | ||||||||||||||||||||||||
| 186 | *data++ = *p; | - | ||||||||||||||||||||||||
| 187 | } executed 31392 times by 1 test:  end of blockExecuted by: 
 | 31392 | ||||||||||||||||||||||||
| 188 | } | - | ||||||||||||||||||||||||
| 189 | pattern.truncate(data - pattern.data()); | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | return executed 3431 times by 1 test: pattern; return pattern;Executed by: 
 executed 3431 times by 1 test:  return pattern;Executed by: 
 | 3431 | ||||||||||||||||||||||||
| 192 | } | - | ||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||
| 196 | - | |||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | QMimeMagicRule::QMimeMagicRule(const QString &typeStr, | - | ||||||||||||||||||||||||
| 199 | const QByteArray &theValue, | - | ||||||||||||||||||||||||
| 200 | const QString &offsets, | - | ||||||||||||||||||||||||
| 201 | const QByteArray &theMask, | - | ||||||||||||||||||||||||
| 202 | QString *errorString) : | - | ||||||||||||||||||||||||
| 203 | d(new QMimeMagicRulePrivate) | - | ||||||||||||||||||||||||
| 204 | { | - | ||||||||||||||||||||||||
| 205 | d->value = theValue; | - | ||||||||||||||||||||||||
| 206 | d->mask = theMask; | - | ||||||||||||||||||||||||
| 207 | d->matchFunction = 0; | - | ||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||
| 209 | d->type = QMimeMagicRule::type(typeStr.toLatin1()); | - | ||||||||||||||||||||||||
| 210 | if (d->type == Invalid 
 | 0-4058 | ||||||||||||||||||||||||
| 211 | *errorString = ([]() -> QString { enum { Size = sizeof(u"" "Type %s is not supported")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Type %s is not supported" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp; return qstring_literal_temp;never executed: }()).arg(typeStr); return qstring_literal_temp; | 0 | ||||||||||||||||||||||||
| 212 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | - | |||||||||||||||||||||||||
| 215 | const int colonIndex = offsets.indexOf(QLatin1Char(':')); | - | ||||||||||||||||||||||||
| 216 | const QString startPosStr = colonIndex == -1 
 | 492-3566 | ||||||||||||||||||||||||
| 217 | const QString endPosStr = colonIndex == -1 
 | 492-3566 | ||||||||||||||||||||||||
| 218 | if (!QMimeTypeParserBase::parseNumber(startPosStr, &d->startPos, errorString) 
 | 0-4058 | ||||||||||||||||||||||||
| 219 | !QMimeTypeParserBase::parseNumber(endPosStr, &d->endPos, errorString) 
 | 0-4058 | ||||||||||||||||||||||||
| 220 | d->type = Invalid; | - | ||||||||||||||||||||||||
| 221 | return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 222 | } | - | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | if (d->value.isEmpty() 
 | 0-4058 | ||||||||||||||||||||||||
| 225 | d->type = Invalid; | - | ||||||||||||||||||||||||
| 226 | if (errorString 
 | 0 | ||||||||||||||||||||||||
| 227 | * never executed: errorString = QLatin1String("Invalid empty magic rule value"); *errorString = QLatin1String("Invalid empty magic rule value");never executed:  *errorString = QLatin1String("Invalid empty magic rule value"); | 0 | ||||||||||||||||||||||||
| 228 | return; never executed:  return; | 0 | ||||||||||||||||||||||||
| 229 | } | - | ||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | if (d->type >= Host16 
 
 | 0-3431 | ||||||||||||||||||||||||
| 232 | bool ok; | - | ||||||||||||||||||||||||
| 233 | d->number = d->value.toUInt(&ok, 0); | - | ||||||||||||||||||||||||
| 234 | if (!ok 
 | 2-625 | ||||||||||||||||||||||||
| 235 | d->type = Invalid; | - | ||||||||||||||||||||||||
| 236 | if (errorString 
 | 0-2 | ||||||||||||||||||||||||
| 237 | * executed 2 times by 1 test: errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg( *errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg( QString::fromLatin1(d->value));Executed by: 
 executed 2 times by 1 test:  *errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg( QString::fromLatin1(d->value));Executed by: 
 | 2 | ||||||||||||||||||||||||
| 238 | QString::fromLatin1(d->value)); executed 2 times by 1 test:  *errorString = QString::fromLatin1("Invalid magic rule value \"%1\"").arg( QString::fromLatin1(d->value));Executed by: 
 | 2 | ||||||||||||||||||||||||
| 239 | return; executed 2 times by 1 test:  return;Executed by: 
 | 2 | ||||||||||||||||||||||||
| 240 | } | - | ||||||||||||||||||||||||
| 241 | d->numberMask = !d->mask.isEmpty() 
 | 50-575 | ||||||||||||||||||||||||
| 242 | } executed 625 times by 1 test:  end of blockExecuted by: 
 | 625 | ||||||||||||||||||||||||
| 243 | - | |||||||||||||||||||||||||
| 244 | switch (d->type) { | - | ||||||||||||||||||||||||
| 245 | case executed 3431 times by 1 test: String: case String:Executed by: 
 executed 3431 times by 1 test:  case String:Executed by: 
 | 3431 | ||||||||||||||||||||||||
| 246 | d->pattern = makePattern(d->value); | - | ||||||||||||||||||||||||
| 247 | d->pattern.squeeze(); | - | ||||||||||||||||||||||||
| 248 | if (!d->mask.isEmpty() 
 | 29-3402 | ||||||||||||||||||||||||
| 249 | if (d->mask.size() < 4 
 
 | 0-29 | ||||||||||||||||||||||||
| 250 | d->type = Invalid; | - | ||||||||||||||||||||||||
| 251 | if (errorString 
 | 0-2 | ||||||||||||||||||||||||
| 252 | * executed 2 times by 1 test: errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg( *errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg( QString::fromLatin1(d->mask));Executed by: 
 executed 2 times by 1 test:  *errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg( QString::fromLatin1(d->mask));Executed by: 
 | 2 | ||||||||||||||||||||||||
| 253 | QString::fromLatin1(d->mask)); executed 2 times by 1 test:  *errorString = QString::fromLatin1("Invalid magic rule mask \"%1\"").arg( QString::fromLatin1(d->mask));Executed by: 
 | 2 | ||||||||||||||||||||||||
| 254 | return; executed 2 times by 1 test:  return;Executed by: 
 | 2 | ||||||||||||||||||||||||
| 255 | } | - | ||||||||||||||||||||||||
| 256 | const QByteArray &tempMask = QByteArray::fromHex(QByteArray::fromRawData( | - | ||||||||||||||||||||||||
| 257 | d->mask.constData() + 2, d->mask.size() - 2)); | - | ||||||||||||||||||||||||
| 258 | if (tempMask.size() != d->pattern.size() 
 | 2-25 | ||||||||||||||||||||||||
| 259 | d->type = Invalid; | - | ||||||||||||||||||||||||
| 260 | if (errorString 
 | 0-2 | ||||||||||||||||||||||||
| 261 | * executed 2 times by 1 test: errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg( *errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg( QString::fromLatin1(d->mask));Executed by: 
 executed 2 times by 1 test:  *errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg( QString::fromLatin1(d->mask));Executed by: 
 | 2 | ||||||||||||||||||||||||
| 262 | QString::fromLatin1(d->mask)); executed 2 times by 1 test:  *errorString = QString::fromLatin1("Invalid magic rule mask size \"%1\"").arg( QString::fromLatin1(d->mask));Executed by: 
 | 2 | ||||||||||||||||||||||||
| 263 | return; executed 2 times by 1 test:  return;Executed by: 
 | 2 | ||||||||||||||||||||||||
| 264 | } | - | ||||||||||||||||||||||||
| 265 | d->mask = tempMask; | - | ||||||||||||||||||||||||
| 266 | } executed 25 times by 1 test: else { end of blockExecuted by: 
 | 25 | ||||||||||||||||||||||||
| 267 | d->mask.fill(char(-1), d->pattern.size()); | - | ||||||||||||||||||||||||
| 268 | } executed 3402 times by 1 test:  end of blockExecuted by: 
 | 3402 | ||||||||||||||||||||||||
| 269 | d->mask.squeeze(); | - | ||||||||||||||||||||||||
| 270 | d->matchFunction = matchString; | - | ||||||||||||||||||||||||
| 271 | break; executed 3427 times by 1 test:  break;Executed by: 
 | 3427 | ||||||||||||||||||||||||
| 272 | case executed 205 times by 1 test: Byte: case Byte:Executed by: 
 executed 205 times by 1 test:  case Byte:Executed by: 
 | 205 | ||||||||||||||||||||||||
| 273 | if (d->number <= quint8(-1) 
 | 0-205 | ||||||||||||||||||||||||
| 274 | if (d->numberMask == 0 
 | 0-205 | ||||||||||||||||||||||||
| 275 | d->numberMask = quint8(-1); executed 205 times by 1 test:  d->numberMask = quint8(-1);Executed by: 
 | 205 | ||||||||||||||||||||||||
| 276 | d->matchFunction = matchNumber<quint8>; | - | ||||||||||||||||||||||||
| 277 | } executed 205 times by 1 test:  end of blockExecuted by: 
 | 205 | ||||||||||||||||||||||||
| 278 | break; executed 205 times by 1 test:  break;Executed by: 
 | 205 | ||||||||||||||||||||||||
| 279 | case executed 65 times by 1 test: Big16: case Big16:Executed by: 
 executed 65 times by 1 test:  case Big16:Executed by: 
 | 65 | ||||||||||||||||||||||||
| 280 | case executed 20 times by 1 test: Host16: case Host16:Executed by: 
 executed 20 times by 1 test:  case Host16:Executed by: 
 | 20 | ||||||||||||||||||||||||
| 281 | case executed 85 times by 1 test: Little16: case Little16:Executed by: 
 executed 85 times by 1 test:  case Little16:Executed by: 
 | 85 | ||||||||||||||||||||||||
| 282 | if (d->number <= quint16(-1) 
 | 0-170 | ||||||||||||||||||||||||
| 283 | d->number = d->type == Little16 
 | 85 | ||||||||||||||||||||||||
| 284 | if (d->numberMask == 0 
 | 5-165 | ||||||||||||||||||||||||
| 285 | d->numberMask = quint16(-1); executed 165 times by 1 test:  d->numberMask = quint16(-1);Executed by: 
 | 165 | ||||||||||||||||||||||||
| 286 | d->matchFunction = matchNumber<quint16>; | - | ||||||||||||||||||||||||
| 287 | } executed 170 times by 1 test:  end of blockExecuted by: 
 | 170 | ||||||||||||||||||||||||
| 288 | break; executed 170 times by 1 test:  break;Executed by: 
 | 170 | ||||||||||||||||||||||||
| 289 | case executed 95 times by 1 test: Big32: case Big32:Executed by: 
 executed 95 times by 1 test:  case Big32:Executed by: 
 | 95 | ||||||||||||||||||||||||
| 290 | case executed 20 times by 1 test: Host32: case Host32:Executed by: 
 executed 20 times by 1 test:  case Host32:Executed by: 
 | 20 | ||||||||||||||||||||||||
| 291 | case executed 135 times by 1 test: Little32: case Little32:Executed by: 
 executed 135 times by 1 test:  case Little32:Executed by: 
 | 135 | ||||||||||||||||||||||||
| 292 | if (d->number <= quint32(-1) 
 | 0-250 | ||||||||||||||||||||||||
| 293 | d->number = d->type == Little32 
 | 115-135 | ||||||||||||||||||||||||
| 294 | if (d->numberMask == 0 
 | 45-205 | ||||||||||||||||||||||||
| 295 | d->numberMask = quint32(-1); executed 205 times by 1 test:  d->numberMask = quint32(-1);Executed by: 
 | 205 | ||||||||||||||||||||||||
| 296 | d->matchFunction = matchNumber<quint32>; | - | ||||||||||||||||||||||||
| 297 | } executed 250 times by 1 test:  end of blockExecuted by: 
 | 250 | ||||||||||||||||||||||||
| 298 | break; executed 250 times by 1 test:  break;Executed by: 
 | 250 | ||||||||||||||||||||||||
| 299 | default never executed: : default:never executed:  default: | 0 | ||||||||||||||||||||||||
| 300 | break; never executed:  break; | 0 | ||||||||||||||||||||||||
| 301 | } | - | ||||||||||||||||||||||||
| 302 | } | - | ||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | QMimeMagicRule::QMimeMagicRule(const QMimeMagicRule &other) : | - | ||||||||||||||||||||||||
| 305 | d(new QMimeMagicRulePrivate(*other.d)) | - | ||||||||||||||||||||||||
| 306 | { | - | ||||||||||||||||||||||||
| 307 | } executed 4058 times by 1 test:  end of blockExecuted by: 
 | 4058 | ||||||||||||||||||||||||
| 308 | - | |||||||||||||||||||||||||
| 309 | QMimeMagicRule::~QMimeMagicRule() | - | ||||||||||||||||||||||||
| 310 | { | - | ||||||||||||||||||||||||
| 311 | } | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | QMimeMagicRule &QMimeMagicRule::operator=(const QMimeMagicRule &other) | - | ||||||||||||||||||||||||
| 314 | { | - | ||||||||||||||||||||||||
| 315 | *d = *other.d; | - | ||||||||||||||||||||||||
| 316 | return never executed: *this; return *this;never executed:  return *this; | 0 | ||||||||||||||||||||||||
| 317 | } | - | ||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||
| 319 | bool QMimeMagicRule::operator==(const QMimeMagicRule &other) const | - | ||||||||||||||||||||||||
| 320 | { | - | ||||||||||||||||||||||||
| 321 | return never executed: d == other.d return d == other.d || *d == *other.d;
 never executed:  return d == other.d || *d == *other.d; | 0 | ||||||||||||||||||||||||
| 322 | * 
 
 never executed:  return d == other.d || *d == *other.d; | 0 | ||||||||||||||||||||||||
| 323 | } | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | QMimeMagicRule::Type QMimeMagicRule::type() const | - | ||||||||||||||||||||||||
| 326 | { | - | ||||||||||||||||||||||||
| 327 | return never executed: d->type; return d->type;never executed:  return d->type; | 0 | ||||||||||||||||||||||||
| 328 | } | - | ||||||||||||||||||||||||
| 329 | - | |||||||||||||||||||||||||
| 330 | QByteArray QMimeMagicRule::value() const | - | ||||||||||||||||||||||||
| 331 | { | - | ||||||||||||||||||||||||
| 332 | return never executed: d->value; return d->value;never executed:  return d->value; | 0 | ||||||||||||||||||||||||
| 333 | } | - | ||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||
| 335 | int QMimeMagicRule::startPos() const | - | ||||||||||||||||||||||||
| 336 | { | - | ||||||||||||||||||||||||
| 337 | return never executed: d->startPos; return d->startPos;never executed:  return d->startPos; | 0 | ||||||||||||||||||||||||
| 338 | } | - | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | int QMimeMagicRule::endPos() const | - | ||||||||||||||||||||||||
| 341 | { | - | ||||||||||||||||||||||||
| 342 | return never executed: d->endPos; return d->endPos;never executed:  return d->endPos; | 0 | ||||||||||||||||||||||||
| 343 | } | - | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | QByteArray QMimeMagicRule::mask() const | - | ||||||||||||||||||||||||
| 346 | { | - | ||||||||||||||||||||||||
| 347 | QByteArray result = d->mask; | - | ||||||||||||||||||||||||
| 348 | if (d->type == String 
 | 0 | ||||||||||||||||||||||||
| 349 | - | |||||||||||||||||||||||||
| 350 | result = "0x" + result.toHex(); | - | ||||||||||||||||||||||||
| 351 | } never executed:  end of block | 0 | ||||||||||||||||||||||||
| 352 | return never executed: result; return result;never executed:  return result; | 0 | ||||||||||||||||||||||||
| 353 | } | - | ||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||
| 355 | bool QMimeMagicRule::isValid() const | - | ||||||||||||||||||||||||
| 356 | { | - | ||||||||||||||||||||||||
| 357 | return executed 4058 times by 1 test: d->matchFunction; return d->matchFunction;Executed by: 
 executed 4058 times by 1 test:  return d->matchFunction;Executed by: 
 | 4058 | ||||||||||||||||||||||||
| 358 | } | - | ||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||
| 360 | bool QMimeMagicRule::matches(const QByteArray &data) const | - | ||||||||||||||||||||||||
| 361 | { | - | ||||||||||||||||||||||||
| 362 | const bool ok = d->matchFunction 
 
 | 0-19244 | ||||||||||||||||||||||||
| 363 | if (!ok 
 | 59-19185 | ||||||||||||||||||||||||
| 364 | return executed 19185 times by 1 test: false; return false;Executed by: 
 executed 19185 times by 1 test:  return false;Executed by: 
 | 19185 | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | if (m_subMatches.isEmpty() 
 | 22-37 | ||||||||||||||||||||||||
| 368 | return executed 37 times by 1 test: true; return true;Executed by: 
 executed 37 times by 1 test:  return true;Executed by: 
 | 37 | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||
| 372 | for ( QList<QMimeMagicRule>::const_iterator it = m_subMatches.begin(), end = m_subMatches.end() ; | - | ||||||||||||||||||||||||
| 373 | it != end 
 | 18-22 | ||||||||||||||||||||||||
| 374 | if ((* 
 
 | 4-18 | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | return executed 4 times by 1 test: true; return true;Executed by: 
 executed 4 times by 1 test:  return true;Executed by: 
 | 4 | ||||||||||||||||||||||||
| 377 | } | - | ||||||||||||||||||||||||
| 378 | } executed 18 times by 1 test:  end of blockExecuted by: 
 | 18 | ||||||||||||||||||||||||
| 379 | return executed 18 times by 1 test: false; return false;Executed by: 
 executed 18 times by 1 test:  return false;Executed by: 
 | 18 | ||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | } | - | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |