Commit f91b71a786c5adc6dd424ad96c38d9518cc31f33

Add a way to test the PluginPointer (needs valgrind)
  
3737# benchmarks
3838 testfilters
3939)
40
41add_subdirectory(pluginpointertest)
  
1cmake_minimum_required(VERSION 2.6)
2project(sometest)
3
4find_package(Qt4 REQUIRED)
5include(${QT_USE_FILE})
6
7include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOOURCE_DIR}/grantlee_core )
8
9set(myplugin_headers myobject.h)
10set(myplugin_sources myobject.cpp)
11
12qt4_wrap_cpp(_plugin_moc_srcs ${myplugin_headers})
13
14add_library(myplugin SHARED ${myplugin_sources} ${_plugin_moc_srcs})
15set_target_properties(myplugin
16 PROPERTIES PREFIX ""
17)
18target_link_libraries(myplugin
19 ${QT_QTCORE_LIBRARIES}
20)
21
22add_executable(main_app main.cpp ${myplugin_sources} ${_plugin_moc_srcs})
23target_link_libraries(main_app
24 ${QT_QTCORE_LIBRARIES}
25)
  
1/*
2 This file is part of the Grantlee template system.
3
4 Copyright (c) 2010 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 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 Library 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>
22#include <QObject>
23
24#include "myinterface.h"
25#include "myobject.h"
26#include "pluginpointer_p.h"
27
28using Grantlee::PluginPointer;
29
30// #define DONT_LEAK
31
32int main(int argc, char **argv)
33{
34 QCoreApplication app(argc, argv);
35
36#ifndef DONT_LEAK
37 QPluginLoader loader( app.applicationDirPath() + "/myplugin.so" );
38 QObject *raw_plugin = loader.instance();
39 MyInterface *if1 = qobject_cast<MyInterface*>(raw_plugin);
40
41 qDebug() << if1->double_it( 5 );
42#endif
43
44 PluginPointer<MyInterface> p1( app.applicationDirPath() + "/myplugin.so" );
45 PluginPointer<MyInterface> p2;
46
47 if (true)
48 {
49 PluginPointer<MyInterface> p3( app.applicationDirPath() + "/myplugin.so" );
50 p1 = p3;
51 PluginPointer<MyInterface> p4( p3 );
52 PluginPointer<MyInterface> p5 = p3;
53 }
54
55 qDebug() << p2->double_it( 15 );
56
57 app.exit();
58}
  
1
2#ifndef MYINTERFACE_H
3#define MYINTERFACE_H
4
5class MyInterface
6{
7public:
8 virtual ~MyInterface() {}
9
10 virtual int double_it( int input ) = 0;
11};
12
13Q_DECLARE_INTERFACE( MyInterface, "org.example.MyInterface/1.0" )
14
15#endif
  
1
2#include "myobject.h"
3
4#include <QtPlugin>
5
6
7MyObject::MyObject(int stop, QObject *parent)
8 : QObject(parent)
9{
10 m_data.fill('o', 2000000);
11
12 if (stop > 0)
13 MyObject *o = new MyObject(--stop, this);
14}
15
16int MyObject::double_it( int input )
17{
18 return input * 2;
19}
20
21Q_EXPORT_PLUGIN2( myplugin, MyObject )
  
1
2#ifndef MYOBJECT_H
3#define MYOBJECT_H
4
5#include <QObject>
6#include "myinterface.h"
7
8class MyObject : public QObject, public MyInterface
9{
10 Q_OBJECT
11 Q_INTERFACES( MyInterface )
12public:
13 MyObject( int stop = 4, QObject *parent = 0 );
14
15 int double_it( int input );
16
17private:
18 QByteArray m_data;
19};
20
21#endif