#include "debugout.h"
#include "timestamp.h"
#include "testplugin.h"
+#include <jsonhelper.h>
+
#define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1)
AbstractRoutingEngine *m_re;
-#define TEST(success) g_assert((success));
+#define TEST(success) DebugOut(0) << "Testing " << ""#success"" << endl; g_assert((success));
const std::string TestProptertyName1 = "TestPropertyName1";
const std::string TestProptertyName2 = "TestPropertyName2";
boolean.fromString(boolean.toString());
std::string isTrue2 = boolean.toString();
- g_assert(isTrue == isTrue2);
+ TEST(isTrue == isTrue2);
}
bool beginsWith(std::string a, std::string b)
{
return (a.compare(0, b.length(), b) == 0);
}
-void TestPlugin::updateProperty(VehicleProperty::Property property,AbstractPropertyType* value)
-{
-
-}
/**
* Tests Core's methods:
bool TestPlugin::testCoreSetSupported()
{
PropertyList supported(routingEngine->supported());
- TEST(ListPlusPlus<VehicleProperty::Property>(&supported).contains(TestProptertyName1) == false);
- std::list<std::string> sources(routingEngine->sourcesForProperty(TestProptertyName1));
- TEST(ListPlusPlus<std::string>(&sources).contains(uuid()) == false);
-
- // if we were registered in Core, it will ask us and we will return it valid, but we haven't registered yet
- TEST(routingEngine->getPropertyInfo(TestProptertyName1, uuid()).isValid() == false);
-
+ TEST(contains(supported, TestProptertyName1) == false);
//
// CALL setSupported
//
- routingEngine->setSupported(m_supportedProperties, nullptr);// invalid input
- TEST(routingEngine->getPropertyInfo(TestProptertyName1, uuid()).isValid() == false);
// valid call
- routingEngine->setSupported(m_supportedProperties, this);// we are register as source from now
+ routingEngine->updateSupported(m_supportedProperties, PropertyList(), this);
TEST(routingEngine->getPropertyInfo(TestProptertyName1, uuid()).isValid() == true);
Zone::ZoneList zones(routingEngine->getPropertyInfo(TestProptertyName1, uuid()).zones());
- TEST(ListPlusPlus<Zone::Type>(&zones).contains(Zone::LeftSide) == true);
+ TEST(contains(zones, Zone::LeftSide) == true);
supported = routingEngine->supported();
- TEST(ListPlusPlus<VehicleProperty::Property>(&supported).contains(TestProptertyName1) == true);
- TEST(ListPlusPlus<VehicleProperty::Property>(&supported).contains(TestProptertyName2) == true);
- TEST(ListPlusPlus<VehicleProperty::Property>(&supported).contains(VehicleProperty::ClutchStatus) == false);
+ TEST(contains(supported, TestProptertyName1) == true);
+ TEST(contains(supported, TestProptertyName2) == true);
+ TEST(contains(supported, VehicleProperty::ClutchStatus) == false);
- sources = routingEngine->sourcesForProperty(TestProptertyName1);
- TEST(ListPlusPlus<std::string>(&sources).contains(uuid()) == true);
+ std::vector<std::string> sources = routingEngine->sourcesForProperty(TestProptertyName1);
+ TEST(contains(sources,uuid()) == true);
TEST(routingEngine->getPropertyInfo(TestProptertyName2, uuid()).isValid() == true);
zones = routingEngine->getPropertyInfo(TestProptertyName2, uuid()).zones();
- TEST(ListPlusPlus<Zone::Type>(&zones).contains(Zone::FrontSide) == true);
-
- // we haven't put VehicleProperty::ClutchStatus to Core as supported,
- // but our impl. returns valid Property for it if we will insert it into m_supportedProperties
- m_supportedProperties.push_back(VehicleProperty::ClutchStatus);
- TEST(routingEngine->getPropertyInfo(VehicleProperty::ClutchStatus, uuid()).isValid() == true);
- zones = routingEngine->getPropertyInfo(VehicleProperty::ClutchStatus, uuid()).zones();
- TEST(ListPlusPlus<Zone::Type>(&zones).contains(Zone::None) == true);
- removeOne(&m_supportedProperties, VehicleProperty::ClutchStatus);
+ TEST(contains(zones, Zone::FrontSide) == true);
return true;
}
int oldPropertyChanges = propertyChanges;
AbstractPropertyType* value = new BasicPropertyType<int>(TestProptertyName1, 22);
+ value->priority = AbstractPropertyType::Instant;
routingEngine->updateProperty(value, "");
TEST(oldSupportedPropertyChanges == supportedPropertyChanges);
TEST(oldPropertyChanges == propertyChanges);
delete value;
value = new BasicPropertyType<short>(TestProptertyName2, 255);
+ value->priority = AbstractPropertyType::Instant;
routingEngine->updateProperty(value, "");
TEST(oldSupportedPropertyChanges == supportedPropertyChanges);
TEST(oldPropertyChanges == propertyChanges);
delete value;
value = new BasicPropertyType<bool>(VehicleProperty::ClutchStatus, true);
+ value->priority = AbstractPropertyType::Instant;
routingEngine->updateSupported({VehicleProperty::ClutchStatus},PropertyList(), this);
class TestSink : public AbstractSink
TestSink(AbstractRoutingEngine* engine, map<string, string> config) : AbstractSink(engine, config) {}
virtual const string uuid() { return "other"; }
virtual void propertyChanged(AbstractPropertyType *value){ ++propertyChanges; }
- virtual void supportedChanged(PropertyList supportedProperties){};
+ virtual void supportedChanged(const PropertyList & supportedProperties){};
int propertyChanges = 0;
};
TEST(oldUnsubscriptionsToSupportedCounter == unsubscriptionsToSupportedCounter);
TEST(++oldUnsubscriptionsToUnsupportedCounter == unsubscriptionsToUnsupportedCounter);
+
+ /// test lamba subscription:
+
+ TEST (routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed,[](AbstractPropertyType* value)
+ {
+ DebugOut(0)<<"lamba subscriptions work!"<<endl;
+ TEST(value);
+ }) > 0);
+
+ /// change vehiclespeed to trigger subscribe above
+
+ PropertyList s;
+ s.push_back(VehicleProperty::VehicleSpeed);
+
+ routingEngine->updateSupported(s, PropertyList(), this);
+ VehicleProperty::VehicleSpeedType speed(10);
+ speed.priority = AbstractPropertyType::Instant;
+
+ routingEngine->updateProperty(&speed,uuid());
+ routingEngine->updateSupported(PropertyList(), s, this);
+
delete value;
// unsubscription
return true;
}
+bool testListPlusPlus()
+{
+ std::map<std::string, int> theMap;
+ theMap["1"] = 1;
+ theMap["2"] = 2;
+
+ TEST(amb::containsKey(theMap, "1"));
+ TEST(!amb::containsKey(theMap, "bar"));
+
+ std::vector<int> list;
+ list.push_back(1);
+ list.push_back(2);
+ list.push_back(3);
+
+ TEST(contains(list, 2));
+ removeOne(&list, 2);
+ TEST(!contains(list, 2));
+
+ class Complex
+ {
+ public:
+ Complex(int a, int b): foo(a), bar(b) {}
+ int foo;
+ int bar;
+ };
+
+ Complex complex1(1, 2);
+
+ Complex complex2(2, 2);
+
+ std::vector<Complex> complexList;
+ complexList.push_back(complex1);
+ complexList.push_back(complex2);
+
+ TEST(contains(complexList, complex1, [](auto a, auto b) { return a.foo == b.foo && a.bar == b.bar; }));
+
+ return true;
+}
+
+void testJsonHelper()
+{
+
+}
+
bool TestPlugin::testSetAndGet()
{
bool replySuccess(false);
PropertyList toAdd;
toAdd.push_back(VehicleProperty::ClutchStatus);
- routingEngine->updateSupported(toAdd,PropertyList(), this);
+ routingEngine->updateSupported(toAdd, PropertyList(), this);
PropertyList supported = routingEngine->supported();
- success = ListPlusPlus<VehicleProperty::Property>(&supported).contains(VehicleProperty::ClutchStatus);
+ success = contains(supported,VehicleProperty::ClutchStatus);
PropertyList toRemove = toAdd;
supported = routingEngine->supported();
- success &= !ListPlusPlus<VehicleProperty::Property>(&supported).contains(VehicleProperty::ClutchStatus);
+ success &= !contains(supported,VehicleProperty::ClutchStatus);
return success;
}
void TestPlugin::setConfiguration(map<string, string> config)
{
-// //Config has been passed, let's start stuff up.
+ // //Config has been passed, let's start stuff up.
}
TestPlugin::TestPlugin(AbstractRoutingEngine *re, map<string, string> config)
: AbstractSource(re, config),
- m_supportedProperties({TestProptertyName1, TestProptertyName2}),
- subscriptionsToSupportedCounter(0),
- subscriptionsToUnsupportedCounter(0),
- unsubscriptionsToSupportedCounter(0),
- unsubscriptionsToUnsupportedCounter(0),
- propertyChanges(0),
- supportedPropertyChanges(0)
+ m_supportedProperties({TestProptertyName1, TestProptertyName2}),
+ subscriptionsToSupportedCounter(0),
+ subscriptionsToUnsupportedCounter(0),
+ unsubscriptionsToSupportedCounter(0),
+ unsubscriptionsToUnsupportedCounter(0),
+ propertyChanges(0),
+ supportedPropertyChanges(0)
{
- DebugOut() << "Testing Core::setSupported... " << endl;
- testCoreSetSupported();
+ DebugOut(0) << "Capabilities: " << endl;
+
+ for(auto prop : VehicleProperty::capabilities())
+ {
+ DebugOut(0) << prop << endl;
+ }
+
+ DebugOut() << "Testing Core::setSupported... " << endl;
+ testCoreSetSupported();
+
+ DebugOut() << "Testing MapPropertyType... " << endl;
+ MapPropertyType<BasicPropertyType<Door::Status>> propmap("Something");
+ MapPropertyType<BasicPropertyType<Door::Status>> propmaptwo("SomethingElse");
+ propmap.append("hi", Door::Ajar);
+ GVariant *var = propmap.toVariant();
+ gsize dictsize = g_variant_n_children(var);
+ //DebugOut() << var << endl;
+ propmaptwo.fromVariant(var);
- DebugOut() << "Testing MapPropertyType... " << endl;
- MapPropertyType<BasicPropertyType<Zone::Type>,BasicPropertyType<Door::Status>> propmap("something");
- MapPropertyType<BasicPropertyType<Zone::Type>,BasicPropertyType<Door::Status>> propmaptwo("something");
- propmap.append(Zone::RearLeft,Door::Ajar);
- GVariant *var = propmap.toVariant();
- gsize dictsize = g_variant_n_children(var);
- //DebugOut() << var << endl;
- propmaptwo.fromVariant(var);
+ g_assert(propmaptwo.toString() == propmap.toString());
- g_assert(propmaptwo.toString() == propmap.toString());
+ ///test fromString:
+ propmap.fromString(propmaptwo.toString());
- DebugOut() << "Testing ListPropertyType... " << endl;
- VehicleProperty::TripMetersType* tfirst = new VehicleProperty::TripMetersType();
- VehicleProperty::TripMetersType* tsecond = new VehicleProperty::TripMetersType();
- BasicPropertyType<uint16_t> v1(0);
- BasicPropertyType<uint16_t> v2(5);
- BasicPropertyType<uint16_t> v3(10);
- tfirst->append(&v1);
- tfirst->append(&v2);
- tfirst->append(&v3);
- tsecond->fromVariant(tfirst->toVariant());
+ DebugOut() << "Testing map string equivalency: " << propmaptwo.toString() << "==" << propmap.toString() << endl;
- g_assert (tfirst->toString() == tsecond->toString());
+ g_assert(propmaptwo.toString() == propmap.toString());
- testBooleanToStringFromString();
+ DebugOut() << "Testing ListPropertyType... " << endl;
+ VehicleProperty::TripMetersType* tfirst = new VehicleProperty::TripMetersType();
+ VehicleProperty::TripMetersType* tsecond = new VehicleProperty::TripMetersType();
+ tfirst->append(0);
+ tfirst->append(5);
+ tfirst->append(10);
+ tsecond->fromVariant(tfirst->toVariant());
- g_assert (testCoreUpdateSupported());
+ GVariant* testGVSVariant = g_variant_new("i", 9);
+ TEST(GVS<int>::value(testGVSVariant) == 9);
- testSubscription();
+ TEST (tfirst->toString() == tsecond->toString());
- testSetAndGet();
+ testBooleanToStringFromString();
- DebugOut() << "Exiting..." << endl;
- exit(-1);
+ TEST (testCoreUpdateSupported());
+
+ testSubscription();
+
+ testSetAndGet();
+
+ TEST(testListPlusPlus());
+
+ testJsonHelper();
}
TestPlugin::~TestPlugin()
return Get | Set;
}
-extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
+extern "C" void create(AbstractRoutingEngine* routingengine, map<string, string> config)
{
- return new TestPlugin(routingengine, config);
-
+ new TestPlugin(routingengine, config);
}
const string TestPlugin::uuid()
{
}
void TestPlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
{
- if(ListPlusPlus<VehicleProperty::Property>(&m_supportedProperties).contains(property))
+ if(contains(m_supportedProperties, property))
++subscriptionsToSupportedCounter;
else
++subscriptionsToUnsupportedCounter;
void TestPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
{
- if(ListPlusPlus<VehicleProperty::Property>(&m_supportedProperties).contains(property))
+ if(contains(m_supportedProperties, property))
++unsubscriptionsToSupportedCounter;
else
++unsubscriptionsToUnsupportedCounter;
void TestPlugin::getPropertyAsync(AsyncPropertyReply *reply)
{
-
+
}
AsyncPropertyReply *TestPlugin::setProperty(AsyncSetPropertyRequest request )
return reply;
}
-PropertyInfo TestPlugin::getPropertyInfo(VehicleProperty::Property property)
+PropertyInfo TestPlugin::getPropertyInfo(const VehicleProperty::Property &property)
{
- if(!ListPlusPlus<VehicleProperty::Property>(&m_supportedProperties).contains(property))
+ if(!contains(m_supportedProperties, property))
return PropertyInfo::invalid();
if(property == TestProptertyName1){
void TestPlugin::propertyChanged(AbstractPropertyType *value)
{
++propertyChanges;
- if(value && ListPlusPlus<VehicleProperty::Property>(&m_supportedProperties).contains(value->name))
+ if(value && contains(m_supportedProperties, value->name))
supportedPropertyChanges++;
}