TEST_F(AddressTranslatorTest, InsertAddressNotPossibleConflictConfigFile) {
    std::shared_ptr<CommonAPI::DBus::DBusAddressTranslator> translator = CommonAPI::DBus::DBusAddressTranslator::get();

    CommonAPI::DBus::DBusAddress dbusAddressInsertRef("my.new.service.config_my.new.instance.config", "/my/new/instance/config", "my.new.service.config");
    std::string commonApiAddressInsertRef = "local:my.new.service.config:my.new.instance.config";

    CommonAPI::DBus::DBusAddress dbusAddressResult;
    CommonAPI::Address commonApiAddressResult;

    // try to overwrite address
    translator->insert(commonApiAddresses[1],
            dbusAddressInsertRef.getService(),
            dbusAddressInsertRef.getObjectPath(),
            dbusAddressInsertRef.getInterface());

    //check that inserting was not possible
    translator->translate(commonApiAddresses[1], dbusAddressResult);
    std::cout << dbusAddressResult.getService() << " " << dbusAddressResult.getObjectPath() << " " << dbusAddressResult.getInterface() << std::endl;
    ASSERT_EQ(dbusAddresses[1].getService(), dbusAddressResult.getService());
    ASSERT_EQ(dbusAddresses[1].getObjectPath(), dbusAddressResult.getObjectPath());
    ASSERT_EQ(dbusAddresses[1].getInterface(), dbusAddressResult.getInterface());

    translator->translate(CommonAPI::DBus::DBusAddress(dbusAddressInsertRef.getService(), dbusAddressInsertRef.getObjectPath(), dbusAddressInsertRef.getInterface()), commonApiAddressResult);
    std::cout << dbusAddressInsertRef.getService() << " " << dbusAddressInsertRef.getObjectPath() << " " << dbusAddressInsertRef.getInterface() << std::endl;
    std::cout << commonApiAddressResult.getDomain() << " " << commonApiAddressResult.getInterface() << " " << commonApiAddressResult.getInstance() << std::endl;
    ASSERT_EQ(commonApiAddressInsertRef, commonApiAddressResult.getAddress());

    translator->translate(CommonAPI::DBus::DBusAddress(dbusAddresses[1].getService(), dbusAddresses[1].getObjectPath(), dbusAddresses[1].getInterface()), commonApiAddressResult);
    std::cout << dbusAddresses[1].getService() << " " << dbusAddresses[1].getObjectPath() << " " << dbusAddresses[1].getInterface() << std::endl;
    std::cout << commonApiAddressResult.getDomain() << " " << commonApiAddressResult.getInterface() << " " << commonApiAddressResult.getInstance() << std::endl;
    ASSERT_EQ(commonApiAddresses[1], commonApiAddressResult.getAddress());
}
void
InstanceAvailabilityStatusChangedEvent::onServiceInstanceStatus(
        std::shared_ptr<Proxy> _proxy,
        service_id_t _serviceId,
        instance_id_t _instanceId,
        bool _isAvailable,
        void* _data) {
    (void)_proxy;
    InstanceAvailabilityStatusChangedEvent* itsSelf =
            static_cast<InstanceAvailabilityStatusChangedEvent*>(_data);
    if(_instanceId != vsomeip::ANY_INSTANCE) {
        Address service(_serviceId, _instanceId);
        CommonAPI::Address capiAddressNewService;
        AddressTranslator::get()->translate(service, capiAddressNewService);

        if(capiAddressNewService.getInterface() == itsSelf->observedInterfaceName_) {
            if(_isAvailable) {
                if (itsSelf->addInstance(capiAddressNewService, _instanceId)) {
                    itsSelf->notifyListeners(capiAddressNewService.getAddress(),
                            CommonAPI::AvailabilityStatus::AVAILABLE);
                }
            } else {
                if (itsSelf->removeInstance(capiAddressNewService, _instanceId)) {
                    itsSelf->notifyListeners(capiAddressNewService.getAddress(),
                            CommonAPI::AvailabilityStatus::NOT_AVAILABLE);
               }
            }
        } else {
            COMMONAPI_ERROR(
                    itsSelf->observedInterfaceName_ + " doesn't match "
                            + capiAddressNewService.getInterface());
        }
    }
}
TEST_F(AddressTranslatorTest, InsertAddressPossible) {
    std::shared_ptr<CommonAPI::DBus::DBusAddressTranslator> translator = CommonAPI::DBus::DBusAddressTranslator::get();

    std::string commonApiAddressRef = "local:my.service:my.instance";

    CommonAPI::DBus::DBusAddress dbusAddressInsertRef("my.new.service_my.new.instance", "/my/new/instance", "my.new.service");
    CommonAPI::DBus::DBusAddress dbusAddressSecondInsertRef("my.new.second.service_my.new.second.instance", "/my/new/second/instance", "my.new.second.service");
    std::string commonApiSecondInsertAddressRef = "local:my.new.second.service:my.new.second.instance";

    CommonAPI::DBus::DBusAddress dbusAddressResult;
    CommonAPI::Address commonApiAddressResult;

    // insert new address
    translator->insert(commonApiAddressRef,
            dbusAddressInsertRef.getService(),
            dbusAddressInsertRef.getObjectPath(),
            dbusAddressInsertRef.getInterface());

    //check inserted address
    translator->translate(commonApiAddressRef, dbusAddressResult);
    std::cout << dbusAddressResult.getService() << " " << dbusAddressResult.getObjectPath() << " " << dbusAddressResult.getInterface() << std::endl;
    ASSERT_EQ(dbusAddressInsertRef.getService(), dbusAddressResult.getService());
    ASSERT_EQ(dbusAddressInsertRef.getObjectPath(), dbusAddressResult.getObjectPath());
    ASSERT_EQ(dbusAddressInsertRef.getInterface(), dbusAddressResult.getInterface());

    translator->translate(CommonAPI::DBus::DBusAddress(dbusAddressInsertRef.getService(), dbusAddressInsertRef.getObjectPath(), dbusAddressInsertRef.getInterface()), commonApiAddressResult);
    std::cout << dbusAddressInsertRef.getService() << " " << dbusAddressInsertRef.getObjectPath() << " " << dbusAddressInsertRef.getInterface() << std::endl;
    std::cout << commonApiAddressResult.getDomain() << " " << commonApiAddressResult.getInterface() << " " << commonApiAddressResult.getInstance() << std::endl;
    ASSERT_EQ(commonApiAddressRef, commonApiAddressResult.getAddress());

    // try overwriting address
    translator->insert(commonApiAddressRef,
            dbusAddressSecondInsertRef.getService(),
            dbusAddressSecondInsertRef.getObjectPath(),
            dbusAddressSecondInsertRef.getInterface());

    //check overwritten not possible
    translator->translate(commonApiAddressRef, dbusAddressResult);
    std::cout << dbusAddressResult.getService() << " " << dbusAddressResult.getObjectPath() << " " << dbusAddressResult.getInterface() << std::endl;
    ASSERT_EQ(dbusAddressInsertRef.getService(), dbusAddressResult.getService());
    ASSERT_EQ(dbusAddressInsertRef.getObjectPath(), dbusAddressResult.getObjectPath());
    ASSERT_EQ(dbusAddressInsertRef.getInterface(), dbusAddressResult.getInterface());

    translator->translate(CommonAPI::DBus::DBusAddress(dbusAddressSecondInsertRef.getService(), dbusAddressSecondInsertRef.getObjectPath(), dbusAddressSecondInsertRef.getInterface()), commonApiAddressResult);
    std::cout << dbusAddressSecondInsertRef.getService() << " " << dbusAddressSecondInsertRef.getObjectPath() << " " << dbusAddressSecondInsertRef.getInterface() << std::endl;
    std::cout << commonApiAddressResult.getDomain() << " " << commonApiAddressResult.getInterface() << " " << commonApiAddressResult.getInstance() << std::endl;
    ASSERT_EQ(commonApiSecondInsertAddressRef, commonApiAddressResult.getAddress());

    translator->translate(CommonAPI::DBus::DBusAddress(dbusAddressInsertRef.getService(), dbusAddressInsertRef.getObjectPath(), dbusAddressInsertRef.getInterface()), commonApiAddressResult);
    std::cout << dbusAddressInsertRef.getService() << " " << dbusAddressInsertRef.getObjectPath() << " " << dbusAddressInsertRef.getInterface() << std::endl;
    std::cout << commonApiAddressResult.getDomain() << " " << commonApiAddressResult.getInterface() << " " << commonApiAddressResult.getInstance() << std::endl;
    ASSERT_EQ(commonApiAddressRef, commonApiAddressResult.getAddress());
}
コード例 #4
0
bool
AddressTranslator::translate(const Address &_key, std::string &_value) {
    CommonAPI::Address address;
    bool result = translate(_key, address);
    _value = address.getAddress();
    return result;
}
TEST_F(AddressTranslatorTest, CheckWellKnownNameInsertWorks) {
    std::shared_ptr<CommonAPI::DBus::DBusAddressTranslator> translator = CommonAPI::DBus::DBusAddressTranslator::get();

    std::string commonApiAddressRef = "local:my.well.insert.other.interface:my.well.insert.other.instance";
    CommonAPI::DBus::DBusAddress dbusAddressInsertRef("my.well.known.name", "/my/well/insert/instance", "my.well.insert.interface");

    CommonAPI::DBus::DBusAddress dbusAddressResult;
    CommonAPI::Address commonApiAddressResult;

    translator->insert(commonApiAddressRef,
                dbusAddressInsertRef.getService(),
                dbusAddressInsertRef.getObjectPath(),
                dbusAddressInsertRef.getInterface());

    translator->translate(CommonAPI::DBus::DBusAddress(dbusAddressInsertRef.getService(), dbusAddressInsertRef.getObjectPath(), dbusAddressInsertRef.getInterface()), commonApiAddressResult);
    std::cout << dbusAddressInsertRef.getService() << " " << dbusAddressInsertRef.getObjectPath() << " " << dbusAddressInsertRef.getInterface() << std::endl;
    std::cout << commonApiAddressResult.getDomain() << " " << commonApiAddressResult.getInterface() << " " << commonApiAddressResult.getInstance() << std::endl;
    ASSERT_EQ(commonApiAddressRef, commonApiAddressResult.getAddress());

    translator->translate(commonApiAddressRef, dbusAddressResult);
    std::cout << dbusAddressResult.getService() << " " << dbusAddressResult.getObjectPath() << " " << dbusAddressResult.getInterface() << std::endl;
    ASSERT_EQ(dbusAddressInsertRef.getService(), dbusAddressResult.getService());
    ASSERT_EQ(dbusAddressInsertRef.getObjectPath(), dbusAddressResult.getObjectPath());
    ASSERT_EQ(dbusAddressInsertRef.getInterface(), dbusAddressResult.getInterface());
}
TEST_F(AddressTranslatorTest, ParsesCommonAPIAddresses) {
    std::shared_ptr<CommonAPI::DBus::DBusAddressTranslator> translator = CommonAPI::DBus::DBusAddressTranslator::get();

    for(unsigned int i = 0; i < commonApiAddresses.size(); i++) {
        CommonAPI::Address commonApiAddress;
        translator->translate(CommonAPI::DBus::DBusAddress(dbusAddresses[i].getService(), dbusAddresses[i].getObjectPath(), dbusAddresses[i].getInterface()), commonApiAddress);
        std::cout << dbusAddresses[i].getService() << " " << dbusAddresses[i].getObjectPath() << " " << dbusAddresses[i].getInterface() << std::endl;
        std::cout << commonApiAddress.getDomain() << " " << commonApiAddress.getInterface() << " " << commonApiAddress.getInstance() << std::endl;
        ASSERT_EQ(commonApiAddresses[i], commonApiAddress.getAddress());
    }
}
TEST_F(AddressTranslatorTest, UniqueAddressHandlingTranslateWorks) {
    std::shared_ptr<CommonAPI::DBus::DBusAddressTranslator> translator = CommonAPI::DBus::DBusAddressTranslator::get();

    std::string commonApiAddressRef = "local:my.unique.translate.interface:my.unique.translate.instance";
    CommonAPI::DBus::DBusAddress dbusAddressInsertRef(":1.6", "/my/unique/translate/instance", "my.unique.translate.interface");

    CommonAPI::DBus::DBusAddress dbusAddressResult;
    CommonAPI::Address commonApiAddressResult;

    translator->translate(CommonAPI::DBus::DBusAddress(dbusAddressInsertRef.getService(), dbusAddressInsertRef.getObjectPath(), dbusAddressInsertRef.getInterface()), commonApiAddressResult);
    std::cout << dbusAddressInsertRef.getService() << " " << dbusAddressInsertRef.getObjectPath() << " " << dbusAddressInsertRef.getInterface() << std::endl;
    std::cout << commonApiAddressResult.getDomain() << " " << commonApiAddressResult.getInterface() << " " << commonApiAddressResult.getInstance() << std::endl;
    ASSERT_EQ(commonApiAddressRef, commonApiAddressResult.getAddress());

    translator->translate(commonApiAddressRef, dbusAddressResult);
    std::cout << dbusAddressResult.getService() << " " << dbusAddressResult.getObjectPath() << " " << dbusAddressResult.getInterface() << std::endl;
    ASSERT_EQ(dbusAddressInsertRef.getService(), dbusAddressResult.getService());
    ASSERT_EQ(dbusAddressInsertRef.getObjectPath(), dbusAddressResult.getObjectPath());
    ASSERT_EQ(dbusAddressInsertRef.getInterface(), dbusAddressResult.getInterface());
}