|
| 1 | + |
| 2 | +#include <wsjcpp_core.h> |
| 3 | +#include <wsjcpp_unit_tests.h> |
| 4 | +#include <wsjcpp_yaml.h> |
| 5 | + |
| 6 | +// --------------------------------------------------------------------- |
| 7 | +// UnitTestCleanup |
| 8 | + |
| 9 | +class UnitTestCleanup : public WsjcppUnitTestBase { |
| 10 | + public: |
| 11 | + UnitTestCleanup(); |
| 12 | + virtual bool doBeforeTest() override; |
| 13 | + virtual void executeTest() override; |
| 14 | + virtual bool doAfterTest() override; |
| 15 | +}; |
| 16 | + |
| 17 | +REGISTRY_WSJCPP_UNIT_TEST(UnitTestCleanup) |
| 18 | + |
| 19 | +UnitTestCleanup::UnitTestCleanup() |
| 20 | + : WsjcppUnitTestBase("UnitTestCleanup") { |
| 21 | +} |
| 22 | + |
| 23 | +// --------------------------------------------------------------------- |
| 24 | + |
| 25 | +bool UnitTestCleanup::doBeforeTest() { |
| 26 | + // do something before test |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +// --------------------------------------------------------------------- |
| 31 | + |
| 32 | +void UnitTestCleanup::executeTest() { |
| 33 | + std::string sTestYaml1 = |
| 34 | + "# Some comment 1\n" |
| 35 | + "test10: one\n" |
| 36 | + "test20: two # some comment 2\n" |
| 37 | + ; |
| 38 | + |
| 39 | + std::string sTestYaml2 = |
| 40 | + "# Some comment 1\n" |
| 41 | + "test11: one\n" |
| 42 | + "test20: two # some comment 2\n" |
| 43 | + "test22: two # some comment 2\n" |
| 44 | + ; |
| 45 | + |
| 46 | + WsjcppYaml yaml; |
| 47 | + std::string sError; |
| 48 | + |
| 49 | + if (!compare("Error parsing 1", yaml.loadFromString("parse1", sTestYaml1, sError), true)) { |
| 50 | + WsjcppLog::err(TAG, sError); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + compare("(1) has test10", yaml.getRoot()->hasElement("test10"), true); |
| 55 | + compare("(1) has test11", yaml.getRoot()->hasElement("test11"), false); |
| 56 | + compare("(1) has test20", yaml.getRoot()->hasElement("test20"), true); |
| 57 | + compare("(1) has test22", yaml.getRoot()->hasElement("test22"), false); |
| 58 | + |
| 59 | + if (!compare("Error parsing 2", yaml.loadFromString("parse2", sTestYaml2, sError), true)) { |
| 60 | + WsjcppLog::err(TAG, sError); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + compare("(2) has test10", yaml.getRoot()->hasElement("test10"), false); |
| 65 | + compare("(2) has test11", yaml.getRoot()->hasElement("test11"), true); |
| 66 | + compare("(2) has test20", yaml.getRoot()->hasElement("test20"), true); |
| 67 | + compare("(2) has test22", yaml.getRoot()->hasElement("test22"), true); |
| 68 | + |
| 69 | + yaml.clear(); |
| 70 | + |
| 71 | + compare("(3) has root", yaml.getRoot() == nullptr, true); |
| 72 | +} |
| 73 | + |
| 74 | +// --------------------------------------------------------------------- |
| 75 | + |
| 76 | +bool UnitTestCleanup::doAfterTest() { |
| 77 | + // do somethig after test |
| 78 | + return true; |
| 79 | +} |
| 80 | + |
| 81 | + |
0 commit comments