| 1 |
/* |
| 2 |
* Copyright (C) 2010-2015 Jeremy Lainé |
| 3 |
* Contact: https://github.com/jlaine/qdjango |
| 4 |
* |
| 5 |
* This file is part of the QDjango Library. |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include <QDate> |
| 19 |
|
| 20 |
#include "QDjangoModel.h" |
| 21 |
|
| 22 |
#include "auth-models.h" |
| 23 |
|
| 24 |
class tst_QDjangoMetaModel : public QObject |
| 25 |
{ |
| 26 |
Q_OBJECT |
| 27 |
|
| 28 |
private slots: |
| 29 |
void initTestCase(); |
| 30 |
void testBool(); |
| 31 |
void testByteArray(); |
| 32 |
void testDate(); |
| 33 |
void testDateTime(); |
| 34 |
void testDouble(); |
| 35 |
void testInteger(); |
| 36 |
void testLongLong(); |
| 37 |
void testString(); |
| 38 |
void testTime(); |
| 39 |
void testOptions(); |
| 40 |
void testConstraints(); |
| 41 |
void testIsValid(); |
| 42 |
}; |
| 43 |
|
| 44 |
class tst_Bool : public QDjangoModel |
| 45 |
{ |
| 46 |
Q_OBJECT |
| 47 |
Q_PROPERTY(bool value READ value WRITE setValue) |
| 48 |
|
| 49 |
public: |
| 50 |
bool value() const { return m_value; } |
| 51 |
void setValue(bool value) { m_value = value; } |
| 52 |
|
| 53 |
private: |
| 54 |
bool m_value; |
| 55 |
}; |
| 56 |
|
| 57 |
class tst_ByteArray : public QDjangoModel |
| 58 |
{ |
| 59 |
Q_OBJECT |
| 60 |
Q_PROPERTY(QByteArray value READ value WRITE setValue) |
| 61 |
|
| 62 |
public: |
| 63 |
QByteArray value() const { return m_value; } |
| 64 |
void setValue(const QByteArray &value) { m_value = value; } |
| 65 |
|
| 66 |
private: |
| 67 |
QByteArray m_value; |
| 68 |
}; |
| 69 |
|
| 70 |
class tst_Date : public QDjangoModel |
| 71 |
{ |
| 72 |
Q_OBJECT |
| 73 |
Q_PROPERTY(QDate value READ value WRITE setValue) |
| 74 |
|
| 75 |
public: |
| 76 |
QDate value() const { return m_value; } |
| 77 |
void setValue(const QDate &value) { m_value = value; } |
| 78 |
|
| 79 |
private: |
| 80 |
QDate m_value; |
| 81 |
}; |
| 82 |
|
| 83 |
class tst_DateTime : public QDjangoModel |
| 84 |
{ |
| 85 |
Q_OBJECT |
| 86 |
Q_PROPERTY(QDateTime value READ value WRITE setValue) |
| 87 |
|
| 88 |
public: |
| 89 |
QDateTime value() const { return m_value; } |
| 90 |
void setValue(const QDateTime &value) { m_value = value; } |
| 91 |
|
| 92 |
private: |
| 93 |
QDateTime m_value; |
| 94 |
}; |
| 95 |
|
| 96 |
class tst_Double : public QDjangoModel |
| 97 |
{ |
| 98 |
Q_OBJECT |
| 99 |
Q_PROPERTY(double value READ value WRITE setValue) |
| 100 |
|
| 101 |
public: |
| 102 |
double value() const { return m_value; } |
| 103 |
void setValue(double value) { m_value = value; } |
| 104 |
|
| 105 |
private: |
| 106 |
double m_value; |
| 107 |
}; |
| 108 |
|
| 109 |
class tst_Integer : public QDjangoModel |
| 110 |
{ |
| 111 |
Q_OBJECT |
| 112 |
Q_PROPERTY(int value READ value WRITE setValue) |
| 113 |
|
| 114 |
public: |
| 115 |
int value() const { return m_value; } |
| 116 |
void setValue(int value) { m_value = value; } |
| 117 |
|
| 118 |
private: |
| 119 |
int m_value; |
| 120 |
}; |
| 121 |
|
| 122 |
class tst_LongLong : public QDjangoModel |
| 123 |
{ |
| 124 |
Q_OBJECT |
| 125 |
Q_PROPERTY(qlonglong value READ value WRITE setValue) |
| 126 |
|
| 127 |
public: |
| 128 |
qlonglong value() const { return m_value; } |
| 129 |
void setValue(qlonglong value) { m_value = value; } |
| 130 |
|
| 131 |
private: |
| 132 |
qlonglong m_value; |
| 133 |
}; |
| 134 |
|
| 135 |
class tst_String : public QDjangoModel |
| 136 |
{ |
| 137 |
Q_OBJECT |
| 138 |
Q_PROPERTY(QString value READ value WRITE setValue) |
| 139 |
Q_CLASSINFO("value", "max_length=255") |
| 140 |
|
| 141 |
public: |
| 142 |
QString value() const { return m_value; } |
| 143 |
void setValue(const QString &value) { m_value = value; } |
| 144 |
|
| 145 |
private: |
| 146 |
QString m_value; |
| 147 |
}; |
| 148 |
|
| 149 |
class tst_Time : public QDjangoModel |
| 150 |
{ |
| 151 |
Q_OBJECT |
| 152 |
Q_PROPERTY(QTime value READ value WRITE setValue) |
| 153 |
|
| 154 |
public: |
| 155 |
QTime value() const { return m_value; } |
| 156 |
void setValue(const QTime &value) { m_value = value; } |
| 157 |
|
| 158 |
private: |
| 159 |
QTime m_value; |
| 160 |
}; |
| 161 |
|
| 162 |
class tst_Options : public QDjangoModel |
| 163 |
{ |
| 164 |
Q_OBJECT |
| 165 |
Q_PROPERTY(int aField READ aField WRITE setAField) |
| 166 |
Q_PROPERTY(int bField READ bField WRITE setBField) |
| 167 |
Q_PROPERTY(int blankField READ blankField WRITE setBlankField) |
| 168 |
Q_PROPERTY(int ignoredField READ ignoredField WRITE setIgnoredField) |
| 169 |
Q_PROPERTY(int indexField READ indexField WRITE setIndexField) |
| 170 |
Q_PROPERTY(int nullField READ nullField WRITE setNullField) |
| 171 |
Q_PROPERTY(int uniqueField READ uniqueField WRITE setUniqueField) |
| 172 |
|
| 173 |
Q_CLASSINFO("__meta__", "db_table=some_table unique_together=aField,bField") |
| 174 |
Q_CLASSINFO("bField", "db_column=b_field") |
| 175 |
Q_CLASSINFO("blankField", "blank=true") |
| 176 |
Q_CLASSINFO("ignoredField", "ignore_field=true") |
| 177 |
Q_CLASSINFO("indexField", "db_index=true") |
| 178 |
Q_CLASSINFO("nullField", "null=true") |
| 179 |
Q_CLASSINFO("uniqueField", "unique=true") |
| 180 |
|
| 181 |
public: |
| 182 |
int aField() const { return m_aField; } |
| 183 |
void setAField(int value) { m_aField = value; } |
| 184 |
|
| 185 |
int bField() const { return m_bField; } |
| 186 |
void setBField(int value) { m_bField = value; } |
| 187 |
|
| 188 |
int blankField() const { return m_blankField; } |
| 189 |
void setBlankField(int value) { m_blankField = value; } |
| 190 |
|
| 191 |
int ignoredField() const { return m_ignoredField; } |
| 192 |
void setIgnoredField(int value) { m_ignoredField = value; } |
| 193 |
|
| 194 |
int indexField() const { return m_indexField; } |
| 195 |
void setIndexField(int value) { m_indexField = value; } |
| 196 |
|
| 197 |
int nullField() const { return m_nullField; } |
| 198 |
void setNullField(int value) { m_nullField = value; } |
| 199 |
|
| 200 |
int uniqueField() const { return m_uniqueField; } |
| 201 |
void setUniqueField(int value) { m_uniqueField = value; } |
| 202 |
|
| 203 |
private: |
| 204 |
int m_aField; |
| 205 |
int m_bField; |
| 206 |
int m_blankField; |
| 207 |
int m_ignoredField; |
| 208 |
int m_indexField; |
| 209 |
int m_nullField; |
| 210 |
int m_uniqueField; |
| 211 |
}; |
| 212 |
|
| 213 |
class tst_FkConstraint : public QDjangoModel |
| 214 |
{ |
| 215 |
Q_OBJECT |
| 216 |
Q_PROPERTY(User *noConstraint READ noConstraint WRITE setNoConstraint) |
| 217 |
Q_PROPERTY(User *cascadeConstraint READ cascadeConstraint WRITE setCascadeConstraint) |
| 218 |
Q_PROPERTY(Group *nullConstraint READ nullConstraint WRITE setNullConstraint) |
| 219 |
|
| 220 |
Q_CLASSINFO("cascadeConstraint", "on_delete=cascade") |
| 221 |
Q_CLASSINFO("restrictConstraint", "on_delete=restrict") |
| 222 |
Q_CLASSINFO("nullConstraint", "null=true on_delete=set_null") |
| 223 |
|
| 224 |
public: |
| 225 |
tst_FkConstraint(QObject *parent = 0); |
| 226 |
|
| 227 |
User *noConstraint() const; |
| 228 |
void setNoConstraint(User *user); |
| 229 |
|
| 230 |
User *cascadeConstraint() const; |
| 231 |
void setCascadeConstraint(User *user); |
| 232 |
|
| 233 |
Group *nullConstraint() const; |
| 234 |
void setNullConstraint(Group *group); |
| 235 |
}; |
| 236 |
|
| 237 |
class tst_FkConstraintWithRestrict : public tst_FkConstraint |
| 238 |
{ |
| 239 |
Q_OBJECT |
| 240 |
Q_PROPERTY(User *restrictConstraint READ restrictConstraint WRITE setRestrictConstraint) |
| 241 |
|
| 242 |
Q_CLASSINFO("__meta__", "db_table=tst_fkconstraint") |
| 243 |
Q_CLASSINFO("restrictConstraint", "on_delete=restrict") |
| 244 |
public: |
| 245 |
tst_FkConstraintWithRestrict(QObject *parent = 0); |
| 246 |
|
| 247 |
User *restrictConstraint() const; |
| 248 |
void setRestrictConstraint(User *user); |
| 249 |
}; |