Cutelee
6.1.0
templates
tests
testcachingloader.cpp
1
/*
2
This file is part of the Cutelee template system.
3
4
Copyright (c) 2015 Stephen Kelly <steveire@gmail.com>
5
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either version
9
2.1 of the Licence, or (at your option) any later version.
10
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
15
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
19
*/
20
21
#include <QtCore/QDebug>
22
#include <QtCore/QFileInfo>
23
#include <QtTest/QTest>
24
25
#include "cachingloaderdecorator.h"
26
#include "context.h"
27
#include "coverageobject.h"
28
#include "engine.h"
29
#include "filterexpression.h"
30
#include "cutelee_paths.h"
31
#include "template.h"
32
#include <metaenumvariable_p.h>
33
34
typedef
QHash<QString, QVariant> Dict;
35
36
Q_DECLARE_METATYPE(
Cutelee::Error
)
37
38
using namespace
Cutelee
;
39
40
class
TestCachingLoader
:
public
CoverageObject
41
{
42
Q_OBJECT
43
44
private
Q_SLOTS:
45
void
testRenderAfterError();
46
};
47
48
void
TestCachingLoader::testRenderAfterError()
49
{
50
Engine
engine;
51
engine.
setPluginPaths
({QStringLiteral(CUTELEE_PLUGIN_PATH)});
52
53
std::shared_ptr<InMemoryTemplateLoader> loader(
new
InMemoryTemplateLoader
);
54
loader->setTemplate(QStringLiteral(
"template1"
),
55
QStringLiteral(
"This template has an error {{ va>r }}"
));
56
loader->setTemplate(QStringLiteral(
"template2"
), QStringLiteral(
"Ok"
));
57
loader->setTemplate(QStringLiteral(
"main"
),
58
QStringLiteral(
"{% include template_var %}"
));
59
60
std::shared_ptr<Cutelee::CachingLoaderDecorator> cache(
61
new
Cutelee::CachingLoaderDecorator
(loader));
62
63
engine.
addTemplateLoader
(cache);
64
65
Context
c;
66
Template
t;
67
t = engine.
loadByName
(QStringLiteral(
"main"
));
68
69
c.
insert
(QStringLiteral(
"template_var"
), QLatin1String(
"template1"
));
70
QCOMPARE(t->
render
(&c),
QString
());
71
QCOMPARE(t->
error
(), TagSyntaxError);
72
73
c.
insert
(QStringLiteral(
"template_var"
), QLatin1String(
"template2"
));
74
QCOMPARE(t->
render
(&c), QLatin1String(
"Ok"
));
75
QCOMPARE(t->
error
(), NoError);
76
}
77
78
QTEST_MAIN(
TestCachingLoader
)
79
#include "testcachingloader.moc"
CoverageObject
Definition:
coverageobject.h:5
Cutelee::CachingLoaderDecorator
Implements a loader decorator which caches compiled Template objects.
Definition:
cachingloaderdecorator.h:72
Cutelee::Context
The Context class holds the context to render a Template with.
Definition:
context.h:119
Cutelee::Context::insert
void insert(const QString &name, QObject *object)
Definition:
context.cpp:145
Cutelee::Engine
Cutelee::Engine is the main entry point for creating Cutelee Templates.
Definition:
engine.h:121
Cutelee::Engine::loadByName
Template loadByName(const QString &name) const
Definition:
engine.cpp:370
Cutelee::Engine::setPluginPaths
void setPluginPaths(const QStringList &dirs)
Definition:
engine.cpp:87
Cutelee::Engine::addTemplateLoader
void addTemplateLoader(std::shared_ptr< AbstractTemplateLoader > loader)
Definition:
engine.cpp:68
Cutelee::InMemoryTemplateLoader
The InMemoryTemplateLoader loads Templates set dynamically in memory.
Definition:
templateloader.h:195
Cutelee::Template
The Template class is a tree of nodes which may be rendered.
Definition:
template.h:95
Cutelee::Template::render
QString render(Context *c) const
Definition:
template.cpp:74
Cutelee::Template::error
Error error() const
Definition:
template.cpp:122
QString
Definition:
operatorcasttests.cpp:24
TestCachingLoader
Definition:
testcachingloader.cpp:41
Cutelee
The Cutelee namespace holds all public Cutelee API.
Definition:
Mainpage.dox:8
Cutelee::Error
Error
Definition:
exception.h:36
Generated by
1.9.1