C++11 library providing functionality common to all adapters.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5 KiB

  1. #include "../src/PityTest.hh"
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5. using namespace pEp;
  6. using namespace pEp::PityTest11;
  7. // eeks-test
  8. // The test framework for geeks without the g
  9. class Car {
  10. private:
  11. int gear_nr = 0;
  12. public:
  13. void setGear(int nr)
  14. {
  15. gear_nr = nr;
  16. }
  17. void drive()
  18. {
  19. if (gear_nr > 0 && gear_nr <= 6) {
  20. cout << "cruising" << endl;
  21. } else {
  22. throw runtime_error{ "invalid gear" };
  23. }
  24. }
  25. };
  26. class CarTestModel {
  27. public:
  28. CarTestModel(const string& name) : name{ name }, car{} {}
  29. string name{};
  30. Car car;
  31. };
  32. int test_setGear(PityUnit<CarTestModel>& node, CarTestModel* ctx)
  33. {
  34. int gear = 1;
  35. node.log("Setting gear to: " + to_string(gear));
  36. ctx->car.setGear(gear);
  37. return 0;
  38. }
  39. int test_drive(PityUnit<CarTestModel>& node, CarTestModel* ctx)
  40. {
  41. ctx->car.drive();
  42. return 0;
  43. }
  44. int main(int argc, char* argv[])
  45. {
  46. // Linear Test
  47. CarTestModel model{ "CarTestModel" };
  48. PityUnit<CarTestModel> testnode_car{ "test car", nullptr, &model };
  49. PityUnit<CarTestModel> testnode_setGear{ testnode_car, "test car setGear()", test_setGear };
  50. PityUnit<CarTestModel> testnode_driv{ testnode_setGear, "test car drive()", &test_drive };
  51. PityUnit<CarTestModel> testnode_driv_before_gear{ testnode_car,
  52. "testnode_driv_before_gear",
  53. &test_drive };
  54. testnode_car.run();
  55. }