File indexing completed on 2024-04-28 04:48:14

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef SQLSTORAGEMOCK_H
0018 #define SQLSTORAGEMOCK_H
0019 
0020 #include "core/storage/SqlStorage.h"
0021 
0022 #include <QList>
0023 #include <QPair>
0024 #include <QStringList>
0025 #include <QTest>
0026 #include <QVariant>
0027 #include <QVariantMap>
0028 
0029 class OrderedSqlStorageMock
0030 {
0031 public:
0032     OrderedSqlStorageMock( const QList<QPair<QString, QVariant> > queries );
0033     virtual ~OrderesSqlStorageMock();
0034 
0035     virtual int sqlDatabasePriority() const { return 0; }
0036 
0037     virtual QString type() const { return "RandomSqlStorageMock"; }
0038 
0039     virtual QString escape( const QString &text ) const { return text; }
0040 
0041     virtual QStringList query( const QString &query );
0042     virtual int insert( const QString &statement, const QString &table );
0043 
0044     virtual QString boolTrue() const { return "1"; }
0045     virtual QString boolFalse() const { return "0"; }
0046 
0047     /**
0048         use this type for auto incrementing integer primary keys.
0049     */
0050     virtual QString idType() const { QFAIL( "idType not implemented" ); return QString(); }
0051 
0052     virtual QString textColumnType( int length = 255 ) const { QFAIL( "textColumnType not implemented" ); return QString(); }
0053     virtual QString exactTextColumnType( int length = 1000 ) const { QFAIL( "exactTextColumnType not implemented" ); return QString(); }
0054     //the below value may have to be decreased even more for different indexes; only time will tell
0055     virtual QString exactIndexableTextColumnType( int length = 324 ) const { QFAIL( "exactIdexableTextColumnType not implemented" ); return QString(); }
0056     virtual QString longTextColumnType() const { QFAIL( "longTextColumnType not implemented" ); return QString(); }
0057     virtual QString randomFunc() const { QFAIL( "ramdomFunc not implemented" ); return QString(); }
0058 
0059     //Mock specific method
0060     bool allQueriesRun() const;
0061 
0062 private:
0063     QList<QPair<QString, QVariant> > m_queries;
0064 };
0065 
0066 class RandomSqlStorageMock : public SqlStorage
0067 {
0068 public:
0069     RandomSqlStorageMock( const QVariantMap &queries );
0070     virtual ~RandomSqlStorageMock();
0071 
0072     virtual int sqlDatabasePriority() const { return 0; }
0073 
0074     virtual QString type() const { return "RandomSqlStorageMock"; }
0075 
0076     virtual QString escape( const QString &text ) const { return text; }
0077 
0078     virtual QStringList query( const QString &query );
0079     virtual int insert( const QString &statement, const QString &table );
0080 
0081     virtual QString boolTrue() const { return "1"; }
0082     virtual QString boolFalse() const { return "0"; }
0083 
0084     /**
0085         use this type for auto incrementing integer primary keys.
0086     */
0087     virtual QString idType() const { QFAIL( "idType not implemented" ); return QString(); }
0088 
0089     virtual QString textColumnType( int length = 255 ) const { QFAIL( "textColumnType not implemented" ); return QString(); }
0090     virtual QString exactTextColumnType( int length = 1000 ) const { QFAIL( "exactTextColumnType not implemented" ); return QString(); }
0091     //the below value may have to be decreased even more for different indexes; only time will tell
0092     virtual QString exactIndexableTextColumnType( int length = 324 ) const { QFAIL( "exactIdexableTextColumnType not implemented" ); return QString(); }
0093     virtual QString longTextColumnType() const { QFAIL( "longTextColumnType not implemented" ); return QString(); }
0094     virtual QString randomFunc() const { QFAIL( "ramdomFunc not implemented" ); return QString(); }
0095 
0096     //Mock specific method
0097     bool allQueriesRun() const;
0098 
0099 private:
0100     QVariantMap m_queries;
0101 
0102 };
0103 
0104 #endif // SQLSTORAGEMOCK_H