File indexing completed on 2024-05-12 04:38:44

0001 /*
0002     SPDX-FileCopyrightText: 2012 Olivier de Gaalon <olivier.jg@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KDEVPLATFORM_JSONTYPETESTS_H
0008 #define KDEVPLATFORM_JSONTYPETESTS_H
0009 
0010 #include "language/duchain/types/abstracttype.h"
0011 #include "language/duchain/types/constantintegraltype.h"
0012 #include "language/duchain/types/delayedtype.h"
0013 #include "language/duchain/types/functiontype.h"
0014 #include "jsontesthelpers.h"
0015 
0016 /**
0017  * Quick Reference:
0018  *   toString : string
0019  *   isConst : bool
0020  *   plainValue : qint64
0021  */
0022 
0023 namespace KDevelop {
0024 namespace TypeTests {
0025 using namespace JsonTestHelpers;
0026 
0027 ///JSON type: string
0028 ///@returns whether the type toString matches the given value
0029 TypeTest(toString)
0030 {
0031     QString typeStr = type ? type->toString() : QStringLiteral("<no type>");
0032     return compareValues(typeStr, value, QStringLiteral("Type's toString"));
0033 }
0034 ///JSON type: bool
0035 ///@returns whether type's constness matches the given value
0036 TypeTest(isConst)
0037 {
0038     VERIFY_TYPE(bool);
0039     bool typeIsConst = false;
0040     if (auto delayed = type.dynamicCast<DelayedType>())
0041         typeIsConst = delayed->identifier().isConstant();
0042     else
0043         typeIsConst = (type->modifiers() & AbstractType::ConstModifier);
0044 
0045     if (typeIsConst != value.toBool())
0046         return typeIsConst ? QStringLiteral("Type is constant, but test data expects non-const.") :
0047                QStringLiteral("Type is non-const, but test data expects constant.");
0048 
0049     return SUCCESS();
0050 }
0051 
0052 ///JSON type: qint64
0053 ///@returns Whether ConstantIntegralType's plainValue matches the given value
0054 TypeTest(plainValue)
0055 {
0056     VERIFY_TYPE(qint64);
0057     auto constantIntegralType = type.dynamicCast<ConstantIntegralType>();
0058     VERIFY_NOT_NULL(constantIntegralType);
0059     return compareValues(constantIntegralType->plainValue(), value,
0060                          QStringLiteral("ConstantIntegralType's plainValue"));
0061 }
0062 }
0063 }
0064 
0065 #endif //KDEVPLATFORM_JSONTYPETESTS_H