Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/comapplication/test/src/services/fu/CUpdateControllerTest.cpp b/comapplication/test/src/services/fu/CUpdateControllerTest.cpp
- index 29c2692..5be0662 100644
- --- a/comapplication/test/src/services/fu/CUpdateControllerTest.cpp
- +++ b/comapplication/test/src/services/fu/CUpdateControllerTest.cpp
- @@ -30,6 +30,7 @@
- #include <services/fu/CConfigProviderFake.hpp>
- #include <mock/CMockConfigProvider.hpp>
- +
- using namespace com::ext::fis;
- using namespace com::fu;
- using namespace com::network::homeconnect;
- @@ -39,6 +40,212 @@ using namespace std;
- using namespace ::testing;
- +#include <boost/sml.hpp>
- +#include <boost/di.hpp>
- +#include <cassert>
- +#include <typeinfo>
- +#include <iostream>
- +#include <boost/di/extension/injector.hpp>
- +#include <boost/di/extension/policies/uml_dumper.hpp>
- +
- +namespace {
- +struct someotherdata {};
- +
- +struct datastruct
- +{
- + datastruct(int a, float b, SPackageInfo& r):
- + a(a),
- + b(b),
- + reference(r)
- + {}
- +
- + int a;
- + float b;
- + SPackageInfo& reference;
- +};
- +struct e1 {
- + //explicit e1(struct datastruct& x) : somedata(x) {}
- + datastruct& somedata;
- +};
- +
- +struct e2 {};
- +struct e3 {};
- +
- +auto guard = [](int, double ) {
- + // assert(87.0 == d);
- + std::cout << "guard" << std::endl;
- + return true;
- +};
- +
- +auto action = [](int, auto e) {
- + std::cout << "action: " << typeid(e).name() << std::endl;
- +};
- +auto event1_action = [](const auto& event) {
- + COM_LOG_INFO <<"event1_action" << event.somedata.a << std::endl;
- +};
- +
- +struct example {
- + example(int& a): m_a(a)
- + {
- + std::cout << "CONSTRUCTOR of example()" << std::endl;
- + }
- + auto operator()() const noexcept {
- +
- + using namespace boost::sml;
- + if (m_a == 1)
- + {
- + }
- + return make_transition_table(
- + *"idle"_s + event<e1> / event1_action = "s1"_s
- + , "s1"_s + event<e2> [ guard ] / action = "s2"_s
- + , "s2"_s + event<e3> / [] { std::cout << "in place action" << std::endl; } = X
- + );
- + }
- + void function1()
- + {
- +
- + }
- +private:
- + int m_a;
- +};
- +
- +enum class CustomType : uint8_t
- +{
- + TYPE1 = 0,
- + TYPE2 = 1
- +};
- +
- +class controller {
- + public:
- + explicit controller(boost::sml::sm<example>& sm , double y, float x, CustomType aType) : sm(sm) { COM_LOG_INFO << "y" << y << " x: " << x << " customtype: " << static_cast<int>(aType) << std::endl;}
- +
- + void start() {
- + SPackageInfo testPackage;
- + datastruct someting(3, 4.9, testPackage);
- +
- + sm.process_event(e1{someting});
- + sm.process_event(e2{});
- + sm.process_event(e3{});
- + assert(sm.is(boost::sml::X));
- + }
- +
- + private:
- + boost::sml::sm<example>& sm;
- +};
- +} // namespace
- +
- +
- +
- +struct i1 {
- + virtual ~i1() noexcept = default;
- + virtual int foo() const = 0;
- +};
- +
- +struct i2 {
- + virtual ~i2() noexcept = default;
- + virtual int bar() const = 0;
- +};
- +
- +struct impl2 : i2 {
- + int bar() const override { return 99; }
- +};
- +
- +struct impl1 : i1 {
- + explicit impl1(std::unique_ptr<i2> sp2)
- + {
- + COM_LOG_INFO << "Constructor of impl1 called" << std::endl;
- + assert(sp2->bar() == 99);
- + }
- + int foo() const override { return 42; }
- +};
- +
- +struct another_impl1 : i1 {
- + explicit another_impl1(std::unique_ptr<i2> sp2)
- + {
- + COM_LOG_INFO << "Constructor of another_impl1 called" << std::endl;
- + assert(sp2->bar() == 99);
- + }
- + int foo() const override { return 42; }
- +};
- +
- +struct app {
- + explicit app(std::shared_ptr<i1> sp1)
- + {
- + COM_LOG_INFO << "Constructor of app called" << std::endl;
- + assert(sp1->foo() == 42);
- + }
- +};
- +
- +
- +class CBoostSMLTestFixture : public ::testing::Test
- +{
- +
- +};
- +
- +/*
- +TEST_F(CBoostSMLTestFixture, Test1)
- +{
- +
- + using namespace boost;
- + const auto injector = di::make_injector(
- + di::bind<int>.to(886).in(di::deduce)
- + , di::bind<double>.to(87.0)
- + );
- + injector.create<controller>().start();
- +}
- +*/
- +
- +TEST_F(CBoostSMLTestFixture, CheckData)
- +{
- + int someint = 4;
- + example object(someint);
- + boost::sml::sm<example> sml(object);
- + example& something = static_cast<example&>(sml);
- + something.function1();
- +}
- +
- +/*
- +TEST_F(CBoostSMLTestFixture, Test2)
- +{
- +
- + using namespace boost;
- + //<<creates generic injector>>
- + {
- + auto injector = di::make_injector(
- + di::bind<i1>().to<impl1>(), /// missing binding -> compile error
- + di::bind<i2>().to<impl2>()
- + );
- + // All the singleton instances are created here by the [Boost].DI system.
- + di::create<app>(injector);
- +
- + // We can also create indirect dependencies isolated.
- + di::create<std::shared_ptr<i1>>(injector);
- + di::create<std::shared_ptr<i2>>(injector);
- + injector.create<impl2&>();
- +
- + // Please note we can glue injectors together or expose only specific types from the injector.
- + di::injector<impl2&> impl2injector = di::make_injector(di::bind<i2>().to<impl2>());
- + impl2injector.create<impl2&>();
- +
- + // Boost DI uses singleton instance for shared_ptr types and hence
- + // we can see that the constructor of impl1 is not called for any of the below invocations.
- +
- + di::create<std::shared_ptr<i1>>(injector);
- + di::create<std::shared_ptr<i1>>(injector);
- + di::create<std::shared_ptr<i1>>(injector);
- + di::create<std::shared_ptr<i1>>(injector);
- +
- + auto uml_dump = di::make_injector<di::extension::uml_dumper>(
- + di::bind<i1>().to<impl1>(), /// missing binding -> compile error
- + di::bind<i2>().to<impl2>()
- + );
- + uml_dump.create<app>();
- + }
- +
- + //<<creates exposed injector>>
- +}
- +*/
- +
- namespace com
- {
- namespace services
- @@ -112,6 +319,7 @@ class CFuUpdateControllerTest_Fixture : public ::testing::Test
- static const std::string PACKAGESINFO_FU_CONTENT;
- };
- +
- auto configProviderFake{CConfigProviderFake()};
- const std::string CFuUpdateControllerTest_Fixture::PACKAGESINFO_FU_CONTENT
- {R"({
- @@ -147,6 +355,8 @@ const std::string CFuUpdateControllerTest_Fixture::PACKAGESINFO_FU_CONTENT
- // Method to test the downloading of packages with packageInfo being empty.
- TEST_F(CFuUpdateControllerTest_Fixture, CUpdateController_DownloadPackage_DownloadPackages_EmptyPackageInfo)
- {
- +
- +
- std::vector<SPackageInfo> packageInfo;
- EXPECT_EQ(EUpdateControllerResponseType::ERROR, updateController.DownloadPackages(transactionID, packageInfo));
- @@ -638,6 +848,9 @@ TEST(fu, CUpdateController_AbortPackageDownload)
- updateController.SetDesktopBusMessageHandler(&messageHandler);
- updateController.SetUpdateControllerState(EUpdateControllerState::ABORT_IN_PROGRESS);
- EXPECT_EQ(EUpdateControllerResponseType::NOT_ALLOWED, updateController.AbortPackageDownload());
- +
- + updateController.SetUpdateControllerState(EUpdateControllerState::PAUSE_IN_PROGRESS);
- + EXPECT_EQ(EUpdateControllerResponseType::OK, updateController.AbortPackageDownload());
- EXPECT_EQ(updateController.GetUpdateControllerState(), EUpdateControllerState::ABORT_IN_PROGRESS);
- }
- @@ -665,7 +878,7 @@ TEST(fu, CUpdateController_PausePackageDownload)
- updateController.SetUpdateControllerState(EUpdateControllerState::PACKAGE_DOWNLOADING);
- EXPECT_EQ(EUpdateControllerResponseType::OK, updateController.PausePackageDownload());
- - EXPECT_EQ(updateController.GetUpdateControllerState(), EUpdateControllerState::PACKAGE_DOWNLOADING_PAUSED);
- + EXPECT_EQ(updateController.GetUpdateControllerState(), EUpdateControllerState::PAUSE_IN_PROGRESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement