File: tst_formattertest.cpp

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (94 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download
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
#include "plugins/codeformatterplugin.h"
#include "parser/lexer.h"
#include "parser/keywords.h"
#include "common/utils_sql.h"
#include "common/global.h"
#include "db/dbsqlite3.h"
#include "mocks.h"
#include <QString>
#include <QtTest>

class FormatterTest : public QObject
{
        Q_OBJECT

    public:
        FormatterTest();

    private:
        QPluginLoader* loader = nullptr;
        CodeFormatterPlugin* plugin = nullptr;
        Db* db = nullptr;

    private Q_SLOTS:
        void initTestCase();
        void cleanupTestCase();

        void test1();
        void test2();
        void test3();
};

FormatterTest::FormatterTest()
{
}

void FormatterTest::test1()
{
    QString sql = "SELECT 1";
    QString formatted = plugin->format(sql, db);
    QCOMPARE(formatted, "SELECT 1;\n");
}

void FormatterTest::test2()
{
    QString sql = "SELECT ';';";
    QString formatted = plugin->format(sql, db);
    QCOMPARE(formatted, "SELECT ';';\n");
}

void FormatterTest::test3()
{
    QString sql = "SELECT * from test;";
    QString formatted = plugin->format(sql, db);
    QCOMPARE(formatted, "SELECT *\n  FROM test;\n");
}

void FormatterTest::initTestCase()
{
    initKeywords();
    Lexer::staticInit();
    initUtilsSql();
    initMocks();

    QStringList nameFilters = {"*SqlEnterpriseFormatter*.so", "*SqlEnterpriseFormatter*.dll", "*SqlEnterpriseFormatter*.dylib"};

    QDir pluginDir("plugins");
    QStringList files = pluginDir.entryList(nameFilters, QDir::Files);
    QCOMPARE(files.size(), 1);

    QString fileName = pluginDir.absoluteFilePath(files.first());
    loader = new QPluginLoader(fileName);
    loader->setLoadHints(QLibrary::ExportExternalSymbolsHint|QLibrary::ResolveAllSymbolsHint);
    QVERIFY(loader->load());

    plugin = dynamic_cast<CodeFormatterPlugin*>(loader->instance());
    QVERIFY(plugin);

    db = new DbSqlite3("test", ":memory:", {{DB_PURE_INIT, true}});
}

void FormatterTest::cleanupTestCase()
{
    if (loader)
    {
        if (loader->isLoaded())
            loader->unload();

        safe_delete(loader);
    }
}

QTEST_APPLESS_MAIN(FormatterTest)

#include "tst_formattertest.moc"