From 364ec046e6da20abac51adc7c04e96ebb5814f5c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 22 Sep 2014 23:26:58 +0300 Subject: [PATCH 1/1] Fixes due to changes in API. --- stglibs/srvconf.lib/parsers/chg_tariff.cpp | 8 +---- stglibs/srvconf.lib/parsers/get_tariff.cpp | 12 +------ tests/test_tariff.cpp | 40 +++++++++++----------- tests/testtariffs.h | 2 +- tests/testusers.h | 1 + 5 files changed, 24 insertions(+), 39 deletions(-) diff --git a/stglibs/srvconf.lib/parsers/chg_tariff.cpp b/stglibs/srvconf.lib/parsers/chg_tariff.cpp index 80bb4cb2..8a1c56a4 100644 --- a/stglibs/srvconf.lib/parsers/chg_tariff.cpp +++ b/stglibs/srvconf.lib/parsers/chg_tariff.cpp @@ -60,13 +60,7 @@ appendResetable(stream, "passiveCost", data.tariffConf.passiveCost); appendResetable(stream, "free", data.tariffConf.free); if (!data.tariffConf.traffType.empty()) - switch (data.tariffConf.traffType.data()) - { - case TRAFF_UP: stream << ""; break; - case TRAFF_DOWN: stream << ""; break; - case TRAFF_UP_DOWN: stream << ""; break; - case TRAFF_MAX: stream << ""; break; - } + stream << ""; if (!data.tariffConf.period.empty()) switch (data.tariffConf.period.data()) diff --git a/stglibs/srvconf.lib/parsers/get_tariff.cpp b/stglibs/srvconf.lib/parsers/get_tariff.cpp index c0736b7b..0804b269 100644 --- a/stglibs/srvconf.lib/parsers/get_tariff.cpp +++ b/stglibs/srvconf.lib/parsers/get_tariff.cpp @@ -78,17 +78,7 @@ bool GetTraffType(const char ** attr, T & value, const std::string & attrName) { if (!CheckValue(attr, attrName)) return false; -std::string type(attr[1]); -if (type == "up") - value = TRAFF_UP; -else if (type == "down") - value = TRAFF_DOWN; -else if (type == "up+down") - value = TRAFF_UP_DOWN; -else if (type == "max") - value = TRAFF_MAX; -else - return false; +value = TARIFF::StringToTraffType(attr[1]); return true; } diff --git a/tests/test_tariff.cpp b/tests/test_tariff.cpp index f999b011..7252a237 100644 --- a/tests/test_tariff.cpp +++ b/tests/test_tariff.cpp @@ -22,7 +22,7 @@ namespace tut TARIFF_DATA td("test"); td.tariffConf.fee = 1; td.tariffConf.free = 2; - td.tariffConf.traffType = TRAFF_UP_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_UP_DOWN; td.tariffConf.passiveCost = 4; td.dirPrice[0].mDay = 30; td.dirPrice[0].hDay = 9; @@ -62,7 +62,7 @@ namespace tut TARIFF_DATA td("test"); td.tariffConf.fee = 1; td.tariffConf.free = 2; - td.tariffConf.traffType = TRAFF_UP; + td.tariffConf.traffType = TARIFF::TRAFF_UP; td.tariffConf.passiveCost = 4; td.dirPrice[0].mDay = 30; td.dirPrice[0].hDay = 9; @@ -77,7 +77,7 @@ namespace tut td.dirPrice[0].noDiscount = 0; TARIFF_IMPL tariff(td); - ensure("traffType = TRAFF_UP", tariff.GetTraffType() == TRAFF_UP); + ensure("traffType = TRAFF_UP", tariff.GetTraffType() == TARIFF::TRAFF_UP); ensure_equals("traffByType(6, 0) = 6 for UP", tariff.GetTraffByType(6, 0), 6); ensure_equals("traffByType(5, 1) = 5 for UP", tariff.GetTraffByType(5, 1), 5); ensure_equals("traffByType(4, 2) = 4 for UP", tariff.GetTraffByType(4, 2), 4); @@ -86,10 +86,10 @@ namespace tut ensure_equals("traffByType(1, 5) = 1 for UP", tariff.GetTraffByType(1, 5), 1); ensure_equals("traffByType(0, 6) = 0 for UP", tariff.GetTraffByType(0, 6), 0); - td.tariffConf.traffType = TRAFF_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_DOWN; tariff = td; - ensure("traffType = TRAFF_DOWN", tariff.GetTraffType() == TRAFF_DOWN); + ensure("traffType = TRAFF_DOWN", tariff.GetTraffType() == TARIFF::TRAFF_DOWN); ensure_equals("traffByType(6, 0) = 0 for DOWN", tariff.GetTraffByType(6, 0), 0); ensure_equals("traffByType(5, 1) = 1 for DOWN", tariff.GetTraffByType(5, 1), 1); ensure_equals("traffByType(4, 2) = 2 for DOWN", tariff.GetTraffByType(4, 2), 2); @@ -98,10 +98,10 @@ namespace tut ensure_equals("traffByType(1, 5) = 5 for DOWN", tariff.GetTraffByType(1, 5), 5); ensure_equals("traffByType(0, 6) = 6 for DOWN", tariff.GetTraffByType(0, 6), 6); - td.tariffConf.traffType = TRAFF_MAX; + td.tariffConf.traffType = TARIFF::TRAFF_MAX; tariff = td; - ensure("traffType = TRAFF_MAX", tariff.GetTraffType() == TRAFF_MAX); + ensure("traffType = TRAFF_MAX", tariff.GetTraffType() == TARIFF::TRAFF_MAX); ensure_equals("traffByType(6, 0) = 6 for MAX", tariff.GetTraffByType(6, 0), 6); ensure_equals("traffByType(5, 1) = 5 for MAX", tariff.GetTraffByType(5, 1), 5); ensure_equals("traffByType(4, 2) = 4 for MAX", tariff.GetTraffByType(4, 2), 4); @@ -110,10 +110,10 @@ namespace tut ensure_equals("traffByType(1, 5) = 5 for MAX", tariff.GetTraffByType(1, 5), 5); ensure_equals("traffByType(0, 6) = 6 for MAX", tariff.GetTraffByType(0, 6), 6); - td.tariffConf.traffType = TRAFF_UP_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_UP_DOWN; tariff = td; - ensure("traffType = TRAFF_UP_DOWN", tariff.GetTraffType() == TRAFF_UP_DOWN); + ensure("traffType = TRAFF_UP_DOWN", tariff.GetTraffType() == TARIFF::TRAFF_UP_DOWN); ensure_equals("traffByType(6, 0) = 6 for UP_DOWN", tariff.GetTraffByType(6, 0), 6); ensure_equals("traffByType(5, 1) = 6 for UP_DOWN", tariff.GetTraffByType(5, 1), 6); ensure_equals("traffByType(4, 2) = 6 for UP_DOWN", tariff.GetTraffByType(4, 2), 6); @@ -132,7 +132,7 @@ namespace tut TARIFF_DATA td("test"); td.tariffConf.fee = 1; td.tariffConf.free = 2; - td.tariffConf.traffType = TRAFF_UP_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_UP_DOWN; td.tariffConf.passiveCost = 4; td.dirPrice[0].mDay = 30; td.dirPrice[0].hDay = 9; @@ -188,7 +188,7 @@ namespace tut TARIFF_DATA td("test"); td.tariffConf.fee = 1; td.tariffConf.free = 2; - td.tariffConf.traffType = TRAFF_UP_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_UP_DOWN; td.tariffConf.passiveCost = 4; td.dirPrice[0].mDay = 30; td.dirPrice[0].hDay = 21; @@ -228,7 +228,7 @@ namespace tut TARIFF_DATA td("test"); td.tariffConf.fee = 1; td.tariffConf.free = 2; - td.tariffConf.traffType = TRAFF_UP; + td.tariffConf.traffType = TARIFF::TRAFF_UP; td.tariffConf.passiveCost = 4; td.dirPrice[0].mDay = 30; td.dirPrice[0].hDay = 21; @@ -243,7 +243,7 @@ namespace tut td.dirPrice[0].noDiscount = 0; TARIFF_IMPL tariff(td); - ensure("traffType = TRAFF_UP", tariff.GetTraffType() == TRAFF_UP); + ensure("traffType = TRAFF_UP", tariff.GetTraffType() == TARIFF::TRAFF_UP); ensure_equals("traffByType(6, 0) = 6 for UP", tariff.GetTraffByType(6, 0), 6); ensure_equals("traffByType(5, 1) = 5 for UP", tariff.GetTraffByType(5, 1), 5); ensure_equals("traffByType(4, 2) = 4 for UP", tariff.GetTraffByType(4, 2), 4); @@ -252,10 +252,10 @@ namespace tut ensure_equals("traffByType(1, 5) = 1 for UP", tariff.GetTraffByType(1, 5), 1); ensure_equals("traffByType(0, 6) = 0 for UP", tariff.GetTraffByType(0, 6), 0); - td.tariffConf.traffType = TRAFF_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_DOWN; tariff = td; - ensure("traffType = TRAFF_DOWN", tariff.GetTraffType() == TRAFF_DOWN); + ensure("traffType = TRAFF_DOWN", tariff.GetTraffType() == TARIFF::TRAFF_DOWN); ensure_equals("traffByType(6, 0) = 0 for DOWN", tariff.GetTraffByType(6, 0), 0); ensure_equals("traffByType(5, 1) = 1 for DOWN", tariff.GetTraffByType(5, 1), 1); ensure_equals("traffByType(4, 2) = 2 for DOWN", tariff.GetTraffByType(4, 2), 2); @@ -264,10 +264,10 @@ namespace tut ensure_equals("traffByType(1, 5) = 5 for DOWN", tariff.GetTraffByType(1, 5), 5); ensure_equals("traffByType(0, 6) = 6 for DOWN", tariff.GetTraffByType(0, 6), 6); - td.tariffConf.traffType = TRAFF_MAX; + td.tariffConf.traffType = TARIFF::TRAFF_MAX; tariff = td; - ensure("traffType = TRAFF_MAX", tariff.GetTraffType() == TRAFF_MAX); + ensure("traffType = TRAFF_MAX", tariff.GetTraffType() == TARIFF::TRAFF_MAX); ensure_equals("traffByType(6, 0) = 6 for MAX", tariff.GetTraffByType(6, 0), 6); ensure_equals("traffByType(5, 1) = 5 for MAX", tariff.GetTraffByType(5, 1), 5); ensure_equals("traffByType(4, 2) = 4 for MAX", tariff.GetTraffByType(4, 2), 4); @@ -276,10 +276,10 @@ namespace tut ensure_equals("traffByType(1, 5) = 5 for MAX", tariff.GetTraffByType(1, 5), 5); ensure_equals("traffByType(0, 6) = 6 for MAX", tariff.GetTraffByType(0, 6), 6); - td.tariffConf.traffType = TRAFF_UP_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_UP_DOWN; tariff = td; - ensure("traffType = TRAFF_UP_DOWN", tariff.GetTraffType() == TRAFF_UP_DOWN); + ensure("traffType = TRAFF_UP_DOWN", tariff.GetTraffType() == TARIFF::TRAFF_UP_DOWN); ensure_equals("traffByType(6, 0) = 6 for UP_DOWN", tariff.GetTraffByType(6, 0), 6); ensure_equals("traffByType(5, 1) = 6 for UP_DOWN", tariff.GetTraffByType(5, 1), 6); ensure_equals("traffByType(4, 2) = 6 for UP_DOWN", tariff.GetTraffByType(4, 2), 6); @@ -298,7 +298,7 @@ namespace tut TARIFF_DATA td("test"); td.tariffConf.fee = 1; td.tariffConf.free = 2; - td.tariffConf.traffType = TRAFF_UP_DOWN; + td.tariffConf.traffType = TARIFF::TRAFF_UP_DOWN; td.tariffConf.passiveCost = 4; td.dirPrice[0].mDay = 30; td.dirPrice[0].hDay = 21; diff --git a/tests/testtariffs.h b/tests/testtariffs.h index fb7b1fe2..a2b14142 100644 --- a/tests/testtariffs.h +++ b/tests/testtariffs.h @@ -22,7 +22,7 @@ class TEST_TARIFFS : public TARIFFS { void AddNotifierDel(NOTIFIER_BASE *) {} void DelNotifierDel(NOTIFIER_BASE *) {} - void GetTariffsData(std::list * /*tdl*/) {} + void GetTariffsData(std::list * /*tdl*/) const {} size_t Count() const { return 0; } diff --git a/tests/testusers.h b/tests/testusers.h index d73c8a79..3d3b7931 100644 --- a/tests/testusers.h +++ b/tests/testusers.h @@ -35,6 +35,7 @@ class TEST_USERS : public USERS { { return -1; } bool IsIPInIndex(uint32_t /*ip*/) const { return false; } bool IsIPInUse(uint32_t, const std::string &, CONST_USER_PTR *) const { return false; } + bool Exists(const std::string &) const { return false; } int OpenSearch() { return 0; } int SearchNext(int /*handle*/, USER_PTR * /*u*/) { return -1; } -- 2.44.2