|
| 1 | + |
| 2 | +#include <wsjcpp_core.h> |
| 3 | +#include <wsjcpp_unit_tests.h> |
| 4 | +#include <wsjcpp_hashes.h> |
| 5 | + |
| 6 | +// --------------------------------------------------------------------- |
| 7 | +// UnitTestGetSha1String |
| 8 | + |
| 9 | +class UnitTestGetSha1String : public WsjcppUnitTestBase { |
| 10 | + public: |
| 11 | + UnitTestGetSha1String(); |
| 12 | + virtual bool doBeforeTest() override; |
| 13 | + virtual void executeTest() override; |
| 14 | + virtual bool doAfterTest() override; |
| 15 | +}; |
| 16 | + |
| 17 | +REGISTRY_WSJCPP_UNIT_TEST(UnitTestGetSha1String) |
| 18 | + |
| 19 | +UnitTestGetSha1String::UnitTestGetSha1String() |
| 20 | + : WsjcppUnitTestBase("UnitTestGetSha1String") { |
| 21 | +} |
| 22 | + |
| 23 | +// --------------------------------------------------------------------- |
| 24 | + |
| 25 | +bool UnitTestGetSha1String::doBeforeTest() { |
| 26 | + // do something before test |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +// --------------------------------------------------------------------- |
| 31 | + |
| 32 | +void UnitTestGetSha1String::executeTest() { |
| 33 | + struct Sha1Test { |
| 34 | + Sha1Test(std::string sOrig, std::string sExpectedSha1) : sOrig(sOrig), sExpectedSha1(sExpectedSha1) {} |
| 35 | + std::string sOrig; |
| 36 | + std::string sExpectedSha1; |
| 37 | + }; |
| 38 | + |
| 39 | + std::vector<Sha1Test *> tests; |
| 40 | + tests.push_back(new Sha1Test("test", "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3")); |
| 41 | + tests.push_back(new Sha1Test("admin", "d033e22ae348aeb5660fc2140aec35850c4da997")); |
| 42 | + |
| 43 | + unsigned int nSuccess = 0; |
| 44 | + for (unsigned int i = 0; i < tests.size(); i++) { |
| 45 | + std::string sOriginal = tests[i]->sOrig; |
| 46 | + std::string sExpectedSha1 = tests[i]->sExpectedSha1; |
| 47 | + std::string sGotSha1 = WsjcppHashes::getSha1ByString(sOriginal); |
| 48 | + sExpectedSha1 = WsjcppCore::toLower(sExpectedSha1); |
| 49 | + sGotSha1 = WsjcppCore::toLower(sGotSha1); |
| 50 | + compare("text '" + sOriginal + "'", sGotSha1, sExpectedSha1); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +// --------------------------------------------------------------------- |
| 55 | + |
| 56 | +bool UnitTestGetSha1String::doAfterTest() { |
| 57 | + // do somethig after test |
| 58 | + return true; |
| 59 | +} |
| 60 | + |
| 61 | + |
0 commit comments