Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.29 KB | None | 0 0
  1. diff --git a/comapplication/test/src/services/fu/CUpdateControllerTest.cpp b/comapplication/test/src/services/fu/CUpdateControllerTest.cpp
  2. index 29c2692..5be0662 100644
  3. --- a/comapplication/test/src/services/fu/CUpdateControllerTest.cpp
  4. +++ b/comapplication/test/src/services/fu/CUpdateControllerTest.cpp
  5. @@ -30,6 +30,7 @@
  6.  #include <services/fu/CConfigProviderFake.hpp>
  7.  #include <mock/CMockConfigProvider.hpp>
  8.  
  9. +
  10.  using namespace com::ext::fis;
  11.  using namespace com::fu;
  12.  using namespace com::network::homeconnect;
  13. @@ -39,6 +40,212 @@ using namespace std;
  14.  using namespace ::testing;
  15.  
  16.  
  17. +#include <boost/sml.hpp>
  18. +#include <boost/di.hpp>
  19. +#include <cassert>
  20. +#include <typeinfo>
  21. +#include <iostream>
  22. +#include <boost/di/extension/injector.hpp>
  23. +#include <boost/di/extension/policies/uml_dumper.hpp>
  24. +
  25. +namespace {
  26. +struct someotherdata {};
  27. +
  28. +struct datastruct
  29. +{
  30. +   datastruct(int a, float b, SPackageInfo& r):
  31. +       a(a),
  32. +       b(b),
  33. +       reference(r)
  34. +   {}
  35. +
  36. +   int a;
  37. +   float b;
  38. +   SPackageInfo& reference;
  39. +};
  40. +struct e1 {
  41. +   //explicit e1(struct datastruct& x) : somedata(x) {}
  42. +   datastruct& somedata;
  43. +};
  44. +
  45. +struct e2 {};
  46. +struct e3 {};
  47. +
  48. +auto guard = [](int, double ) {
  49. +  // assert(87.0 == d);
  50. +  std::cout << "guard" << std::endl;
  51. +  return true;
  52. +};
  53. +
  54. +auto action = [](int, auto e) {
  55. +  std::cout << "action: " << typeid(e).name() << std::endl;
  56. +};
  57. +auto event1_action  = [](const auto& event) {
  58. +   COM_LOG_INFO <<"event1_action" << event.somedata.a << std::endl;
  59. +};
  60. +
  61. +struct example {
  62. +   example(int& a): m_a(a)
  63. +   {
  64. +       std::cout << "CONSTRUCTOR of example()" << std::endl;
  65. +   }
  66. +  auto operator()() const noexcept {
  67. +
  68. +       using namespace boost::sml;
  69. +       if (m_a == 1)
  70. +       {
  71. +       }
  72. +    return make_transition_table(
  73. +       *"idle"_s + event<e1> / event1_action = "s1"_s
  74. +      , "s1"_s + event<e2> [ guard ] / action = "s2"_s
  75. +      , "s2"_s + event<e3> / [] { std::cout << "in place action" << std::endl; } = X
  76. +    );
  77. +  }
  78. +  void function1()
  79. +  {
  80. +
  81. +  }
  82. +private:
  83. +  int m_a;
  84. +};
  85. +
  86. +enum class CustomType : uint8_t
  87. +{
  88. +   TYPE1 = 0,
  89. +   TYPE2 = 1
  90. +};
  91. +
  92. +class controller {
  93. + public:
  94. +  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;}
  95. +
  96. +  void start() {
  97. +   SPackageInfo testPackage;
  98. +   datastruct someting(3, 4.9, testPackage);
  99. +
  100. +    sm.process_event(e1{someting});
  101. +    sm.process_event(e2{});
  102. +    sm.process_event(e3{});
  103. +    assert(sm.is(boost::sml::X));
  104. +  }
  105. +
  106. + private:
  107. +  boost::sml::sm<example>& sm;
  108. +};
  109. +}  // namespace
  110. +
  111. +
  112. +
  113. +struct i1 {
  114. +  virtual ~i1() noexcept = default;
  115. +  virtual int foo() const = 0;
  116. +};
  117. +
  118. +struct i2 {
  119. +  virtual ~i2() noexcept = default;
  120. +  virtual int bar() const = 0;
  121. +};
  122. +
  123. +struct impl2 : i2 {
  124. +  int bar() const override { return 99; }
  125. +};
  126. +
  127. +struct impl1 : i1 {
  128. +  explicit impl1(std::unique_ptr<i2> sp2)
  129. +  {
  130. +   COM_LOG_INFO << "Constructor of impl1 called" << std::endl;
  131. +    assert(sp2->bar() == 99);
  132. +  }
  133. +  int foo() const override { return 42; }
  134. +};
  135. +
  136. +struct another_impl1 : i1 {
  137. +  explicit another_impl1(std::unique_ptr<i2> sp2)
  138. +  {
  139. +   COM_LOG_INFO << "Constructor of another_impl1 called" << std::endl;
  140. +    assert(sp2->bar() == 99);
  141. +  }
  142. +  int foo() const override { return 42; }
  143. +};
  144. +
  145. +struct app {
  146. +  explicit app(std::shared_ptr<i1> sp1)
  147. +  {
  148. +   COM_LOG_INFO << "Constructor of app called" << std::endl;
  149. +   assert(sp1->foo() == 42);
  150. +  }
  151. +};
  152. +
  153. +
  154. +class CBoostSMLTestFixture : public ::testing::Test
  155. +{
  156. +
  157. +};
  158. +
  159. +/*
  160. +TEST_F(CBoostSMLTestFixture, Test1)
  161. +{
  162. +
  163. +   using namespace boost;
  164. +   const auto injector = di::make_injector(
  165. +           di::bind<int>.to(886).in(di::deduce)
  166. +           , di::bind<double>.to(87.0)
  167. +   );
  168. +   injector.create<controller>().start();
  169. +}
  170. +*/
  171. +
  172. +TEST_F(CBoostSMLTestFixture, CheckData)
  173. +{
  174. + int someint = 4;
  175. +  example object(someint);
  176. +  boost::sml::sm<example> sml(object);
  177. +  example& something = static_cast<example&>(sml);
  178. +  something.function1();
  179. +}
  180. +
  181. +/*
  182. +TEST_F(CBoostSMLTestFixture, Test2)
  183. +{
  184. +
  185. +   using namespace boost;
  186. +   //<<creates generic injector>>
  187. +   {
  188. +     auto injector = di::make_injector(
  189. +       di::bind<i1>().to<impl1>(), /// missing binding -> compile error
  190. +       di::bind<i2>().to<impl2>()
  191. +     );
  192. +     // All the singleton instances are created here by the [Boost].DI system.
  193. +     di::create<app>(injector);
  194. +
  195. +     // We can also create indirect dependencies isolated.
  196. +     di::create<std::shared_ptr<i1>>(injector);
  197. +     di::create<std::shared_ptr<i2>>(injector);
  198. +     injector.create<impl2&>();
  199. +
  200. +     // Please note we can glue injectors together or expose only specific types from the injector.
  201. +     di::injector<impl2&> impl2injector = di::make_injector(di::bind<i2>().to<impl2>());
  202. +     impl2injector.create<impl2&>();
  203. +
  204. +     // Boost DI uses singleton instance for shared_ptr types and hence
  205. +     // we can see that the constructor of impl1 is not called for any of the below invocations.
  206. +
  207. +     di::create<std::shared_ptr<i1>>(injector);
  208. +     di::create<std::shared_ptr<i1>>(injector);
  209. +     di::create<std::shared_ptr<i1>>(injector);
  210. +     di::create<std::shared_ptr<i1>>(injector);
  211. +
  212. +     auto uml_dump = di::make_injector<di::extension::uml_dumper>(
  213. +       di::bind<i1>().to<impl1>(), /// missing binding -> compile error
  214. +       di::bind<i2>().to<impl2>()
  215. +     );
  216. +     uml_dump.create<app>();
  217. +   }
  218. +
  219. +   //<<creates exposed injector>>
  220. +}
  221. +*/
  222. +
  223.  namespace com
  224.  {
  225.  namespace services
  226. @@ -112,6 +319,7 @@ class CFuUpdateControllerTest_Fixture : public ::testing::Test
  227.         static const std::string PACKAGESINFO_FU_CONTENT;
  228.  };
  229.  
  230. +
  231.  auto configProviderFake{CConfigProviderFake()};
  232.  const std::string CFuUpdateControllerTest_Fixture::PACKAGESINFO_FU_CONTENT
  233.             {R"({
  234. @@ -147,6 +355,8 @@ const std::string CFuUpdateControllerTest_Fixture::PACKAGESINFO_FU_CONTENT
  235. // Method to test the downloading of packages with packageInfo being empty.
  236. TEST_F(CFuUpdateControllerTest_Fixture, CUpdateController_DownloadPackage_DownloadPackages_EmptyPackageInfo)
  237. {
  238. +
  239. +
  240.     std::vector<SPackageInfo> packageInfo;
  241.  
  242.     EXPECT_EQ(EUpdateControllerResponseType::ERROR, updateController.DownloadPackages(transactionID, packageInfo));
  243. @@ -638,6 +848,9 @@ TEST(fu, CUpdateController_AbortPackageDownload)
  244.     updateController.SetDesktopBusMessageHandler(&messageHandler);
  245.     updateController.SetUpdateControllerState(EUpdateControllerState::ABORT_IN_PROGRESS);
  246.     EXPECT_EQ(EUpdateControllerResponseType::NOT_ALLOWED, updateController.AbortPackageDownload());
  247. +
  248. +   updateController.SetUpdateControllerState(EUpdateControllerState::PAUSE_IN_PROGRESS);
  249. +   EXPECT_EQ(EUpdateControllerResponseType::OK, updateController.AbortPackageDownload());
  250.     EXPECT_EQ(updateController.GetUpdateControllerState(), EUpdateControllerState::ABORT_IN_PROGRESS);
  251. }
  252.  
  253. @@ -665,7 +878,7 @@ TEST(fu, CUpdateController_PausePackageDownload)
  254.  
  255.     updateController.SetUpdateControllerState(EUpdateControllerState::PACKAGE_DOWNLOADING);
  256.     EXPECT_EQ(EUpdateControllerResponseType::OK, updateController.PausePackageDownload());
  257. -   EXPECT_EQ(updateController.GetUpdateControllerState(), EUpdateControllerState::PACKAGE_DOWNLOADING_PAUSED);
  258. +   EXPECT_EQ(updateController.GetUpdateControllerState(), EUpdateControllerState::PAUSE_IN_PROGRESS);
  259.  
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement