2 Copyright (C) 2012 Intel Corporation
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.
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.
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
21 #include <boost/assert.hpp>
22 #include <boost/lexical_cast.hpp>
25 //#include <json-glib/json-glib.h>
26 #include <listplusplus.h>
27 #include <vehicleproperty.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;
34 //std::list<ObdPid*> Obd2Amb::supportedPidsList;
36 void testBooleanToStringFromString()
38 BasicPropertyType<bool> boolean(true);
39 std::string isTrue = boolean.toString();
40 boolean.fromString(boolean.toString());
41 std::string isTrue2 = boolean.toString();
43 g_assert(isTrue == isTrue2);
46 bool beginsWith(std::string a, std::string b)
48 return (a.compare(0, b.length(), b) == 0);
50 void TestPlugin::updateProperty(VehicleProperty::Property property,AbstractPropertyType* value)
55 bool TestPlugin::testCoreUpdateSupported()
60 toAdd.push_back(VehicleProperty::ClutchStatus);
62 routingEngine->updateSupported(toAdd,PropertyList(), this);
64 PropertyList supported = routingEngine->supported();
66 success = ListPlusPlus<VehicleProperty::Property>(&supported).contains(VehicleProperty::ClutchStatus);
68 PropertyList toRemove = toAdd;
70 routingEngine->updateSupported(PropertyList(),toRemove, this);
72 supported = routingEngine->supported();
74 success &= !ListPlusPlus<VehicleProperty::Property>(&supported).contains(VehicleProperty::ClutchStatus);
79 void TestPlugin::setSupported(PropertyList list)
81 m_re->updateSupported(list,PropertyList(), this);
83 void TestPlugin::setConfiguration(map<string, string> config)
85 // //Config has been passed, let's start stuff up.
88 TestPlugin::TestPlugin(AbstractRoutingEngine *re, map<string, string> config)
89 : AbstractSource(re, config)
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);
102 g_assert(propmaptwo.toString() == propmap.toString());
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);
113 tsecond->fromVariant(tfirst->toVariant());
115 g_assert (tfirst->toString() == tsecond->toString());
117 testBooleanToStringFromString();
119 g_assert (testCoreUpdateSupported());
121 DebugOut() << "Exiting..." << endl;
125 TestPlugin::~TestPlugin()
127 DebugOut() << "TestPlugin Destructor called!!!"<<endl;
130 PropertyList TestPlugin::supported()
132 return PropertyList();
135 int TestPlugin::supportedOperations()
140 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
142 return new TestPlugin(routingengine, config);
145 const string TestPlugin::uuid()
147 return "f77af740-f1f8-11e1-aff1-0800200c9a66";
149 void TestPlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
154 void TestPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
159 void TestPlugin::getPropertyAsync(AsyncPropertyReply *reply)
164 AsyncPropertyReply *TestPlugin::setProperty(AsyncSetPropertyRequest request )
166 AsyncPropertyReply* reply = new AsyncPropertyReply (request);