diff options
author | Ilya Zverev <zverik@textual.ru> | 2016-11-24 20:27:51 +0300 |
---|---|---|
committer | Ilya Zverev <zverik@textual.ru> | 2016-11-30 18:55:40 +0300 |
commit | 153e4f2b8c0ea07b90b3f72455f201754577e751 (patch) | |
tree | 9c5809357572f6964dde7a9aa39c66eb8b12e3c4 /indexer/indexer_tests | |
parent | 70871724edcb0a50dde550512310fda1a370566f (diff) |
[banners] Add banners infrastructure
Diffstat (limited to 'indexer/indexer_tests')
-rw-r--r-- | indexer/indexer_tests/banners_test.cpp | 70 | ||||
-rw-r--r-- | indexer/indexer_tests/indexer_tests.pro | 1 |
2 files changed, 71 insertions, 0 deletions
diff --git a/indexer/indexer_tests/banners_test.cpp b/indexer/indexer_tests/banners_test.cpp new file mode 100644 index 0000000000..8fc773eeac --- /dev/null +++ b/indexer/indexer_tests/banners_test.cpp @@ -0,0 +1,70 @@ +#include "testing/testing.hpp" + +#include "indexer/banners.hpp" +#include "indexer/classificator.hpp" +#include "indexer/classificator_loader.hpp" + +#include "std/iostream.hpp" + +using namespace banner; + +UNIT_TEST(Banners_Load) +{ + char const kBanners[] = + "# comment\n" + "[abc]\n" + "icon = test.png\n" + "start=2016-07-14\n" + "type= shop-clothes \n" + "\n" + "[error]\n" + "[re_123]\n" + "type=shop-shoes\n" + "url=http://{aux}.com\n" + " \t aux=\t\ttest \n" + "[future]\n" + "type=shop-wine\n" + "start=2028-01-01\n" + "end=2028-12-31\n" + "[final]\n" + "type=shop-pet\n" + "start=2016-07-13\n" + "end=2016-07-14\n" + "\t"; + + classificator::Load(); + Classificator & c = classif(); + + BannerSet bs; + istringstream is(kBanners); + bs.ReadBanners(is); + + TEST(bs.HasBannerForType(c.GetTypeByPath({"shop", "clothes"})), ()); + Banner const & bannerAbc = bs.GetBannerForType(c.GetTypeByPath({"shop", "clothes"})); + TEST(!bannerAbc.IsEmpty(), ()); + TEST_EQUAL(bannerAbc.GetIconName(), "test.png", ()); + TEST_EQUAL(bannerAbc.GetMessageBase(), "banner_abc", ()); + TEST_EQUAL(bannerAbc.GetDefaultUrl(), "", ()); + TEST_EQUAL(bannerAbc.GetFormattedUrl("http://example.com"), "http://example.com", ()); + TEST_EQUAL(bannerAbc.GetFormattedUrl(), "", ()); + TEST(bannerAbc.IsActive(), ()); + + TEST(bs.HasBannerForType(c.GetTypeByPath({"shop", "shoes"})), ()); + Banner const & bannerRe = bs.GetBannerForType(c.GetTypeByPath({"shop", "shoes"})); + TEST(!bannerRe.IsEmpty(), ()); + TEST(bannerRe.IsActive(), ()); + TEST_EQUAL(bannerRe.GetIconName(), "banner_re_123.png", ()); + TEST_EQUAL(bannerRe.GetFormattedUrl(), "http://test.com", ()); + TEST_EQUAL(bannerRe.GetFormattedUrl("http://ex.ru/{aux}?var={v}"), "http://ex.ru/test?var={v}", ()); + + TEST(bs.HasBannerForType(c.GetTypeByPath({"shop", "wine"})), ()); + Banner const & bannerFuture = bs.GetBannerForType(c.GetTypeByPath({"shop", "wine"})); + TEST(!bannerFuture.IsEmpty(), ()); + TEST(!bannerFuture.IsActive(), ()); + + TEST(bs.HasBannerForType(c.GetTypeByPath({"shop", "pet"})), ()); + Banner const & bannerFinal = bs.GetBannerForType(c.GetTypeByPath({"shop", "pet"})); + TEST(!bannerFinal.IsEmpty(), ()); + TEST(!bannerFinal.IsActive(), ()); + TEST_EQUAL(bannerFinal.GetFormattedUrl("http://{aux}.ru"), "http://{aux}.ru", ()); +} diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index 1ff165f0ac..79b5de4b4a 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -28,6 +28,7 @@ HEADERS += \ SOURCES += \ ../../testing/testingmain.cpp \ + banners_test.cpp \ categories_test.cpp \ cell_coverer_test.cpp \ cell_id_test.cpp \ |