Merge branch 'MasterPropertyList' of github.com:timkoma/automotive-message-broker...
[profile/ivi/automotive-message-broker.git] / plugins / testplugin / testplugin.cpp
1 /*
2         Copyright (C) 2012  Intel Corporation
3
4         This library is free software; you can redistribute it and/or
5         modify it under the terms of the GNU Lesser General Public
6         License as published by the Free Software Foundation; either
7         version 2.1 of the License, or (at your option) any later version.
8
9         This library is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12         Lesser General Public License for more details.
13
14         You should have received a copy of the GNU Lesser General Public
15         License along with this library; if not, write to the Free Software
16         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19
20 #include <iostream>
21 #include <boost/assert.hpp>
22 #include <boost/lexical_cast.hpp>
23 #include <glib.h>
24 #include <sstream>
25 //#include <json-glib/json-glib.h>
26 #include <listplusplus.h>
27 #include <vehicleproperty.h>
28 #include "debugout.h"
29 #include "timestamp.h"
30 #include "testplugin.h"
31 #define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1)
32 AbstractRoutingEngine *m_re;
33
34 //std::list<ObdPid*> Obd2Amb::supportedPidsList;
35
36 void testBooleanToStringFromString()
37 {
38         BasicPropertyType<bool> boolean(true);
39         std::string isTrue = boolean.toString();
40         boolean.fromString(boolean.toString());
41         std::string isTrue2 = boolean.toString();
42
43         g_assert(isTrue == isTrue2);
44 }
45
46 bool beginsWith(std::string a, std::string b)
47 {
48         return (a.compare(0, b.length(), b) == 0);
49 }
50 void TestPlugin::updateProperty(VehicleProperty::Property property,AbstractPropertyType* value)
51 {
52
53 }
54
55 bool TestPlugin::testCoreUpdateSupported()
56 {
57         bool success = false;
58
59         PropertyList toAdd;
60         toAdd.push_back(VehicleProperty::ClutchStatus);
61
62         routingEngine->updateSupported(toAdd,PropertyList(), this);
63
64         PropertyList supported = routingEngine->supported();
65
66         success = ListPlusPlus<VehicleProperty::Property>(&supported).contains(VehicleProperty::ClutchStatus);
67
68         PropertyList toRemove = toAdd;
69
70         routingEngine->updateSupported(PropertyList(),toRemove, this);
71
72         supported = routingEngine->supported();
73
74         success &= !ListPlusPlus<VehicleProperty::Property>(&supported).contains(VehicleProperty::ClutchStatus);
75
76         return success;
77 }
78
79 void TestPlugin::setSupported(PropertyList list)
80 {
81         m_re->updateSupported(list,PropertyList(), this);
82 }
83 void TestPlugin::setConfiguration(map<string, string> config)
84 {
85 //      //Config has been passed, let's start stuff up.
86 }
87
88 TestPlugin::TestPlugin(AbstractRoutingEngine *re, map<string, string> config)
89         : AbstractSource(re, config)
90 {
91
92   re->setSupported(PropertyList(), this);
93   DebugOut() << "Testing MapPropertyType... " << endl;
94   MapPropertyType<BasicPropertyType<Zone::Type>,BasicPropertyType<Door::Status>> propmap("something");
95   MapPropertyType<BasicPropertyType<Zone::Type>,BasicPropertyType<Door::Status>> propmaptwo("something");
96   propmap.append(Zone::RearLeft,Door::Ajar);
97   GVariant *var = propmap.toVariant();
98   gsize dictsize = g_variant_n_children(var);
99   //DebugOut() << var << endl;
100   propmaptwo.fromVariant(var);
101
102   g_assert(propmaptwo.toString() == propmap.toString());
103
104   DebugOut() << "Testing ListPropertyType... " << endl;
105   VehicleProperty::TripMetersType* tfirst = new VehicleProperty::TripMetersType();
106   VehicleProperty::TripMetersType* tsecond = new VehicleProperty::TripMetersType();
107   BasicPropertyType<uint16_t> v1(0);
108   BasicPropertyType<uint16_t> v2(5);
109   BasicPropertyType<uint16_t> v3(10);
110   tfirst->append(&v1);
111   tfirst->append(&v2);
112   tfirst->append(&v3);
113   tsecond->fromVariant(tfirst->toVariant());
114
115   g_assert (tfirst->toString() == tsecond->toString());
116
117   testBooleanToStringFromString();
118
119   g_assert (testCoreUpdateSupported());
120
121   DebugOut() << "Exiting..." << endl;
122   exit(-1);
123 }
124
125 TestPlugin::~TestPlugin()
126 {
127         DebugOut() << "TestPlugin Destructor called!!!"<<endl;
128 }
129
130 PropertyList TestPlugin::supported()
131 {
132         return PropertyList();
133 }
134
135 int TestPlugin::supportedOperations()
136 {
137         return Get | Set;
138 }
139
140 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
141 {
142         return new TestPlugin(routingengine, config);
143         
144 }
145 const string TestPlugin::uuid()
146 {
147         return "f77af740-f1f8-11e1-aff1-0800200c9a66";
148 }
149 void TestPlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
150 {
151 }
152
153
154 void TestPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
155 {
156 }
157
158
159 void TestPlugin::getPropertyAsync(AsyncPropertyReply *reply)
160 {
161         
162 }
163
164 AsyncPropertyReply *TestPlugin::setProperty(AsyncSetPropertyRequest request )
165 {
166         AsyncPropertyReply* reply = new AsyncPropertyReply (request);
167         return reply;
168 }