From 69b4f096f732ce91b9ff7fa85b763ffdab9a818c Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 7 Oct 2014 14:04:31 +0300 Subject: [PATCH] Removed dummy includes, avoid copy-paste. --- base/base.pro | 1 + base/pseudo_random.cpp | 20 +++++++++++++++++ base/pseudo_random.hpp | 9 ++++++++ coding/coding_tests/base64_test.cpp | 3 --- coding/coding_tests/hex_test.cpp | 22 +++++-------------- .../coding_tests/var_serial_vector_test.cpp | 18 +-------------- map/map_tests/mwm_url_tests.cpp | 3 ++- platform/platform_ios.mm | 2 -- 8 files changed, 38 insertions(+), 40 deletions(-) create mode 100644 base/pseudo_random.cpp diff --git a/base/base.pro b/base/base.pro index 2d0599c67e..75696fd8b3 100644 --- a/base/base.pro +++ b/base/base.pro @@ -29,6 +29,7 @@ SOURCES += \ object_tracker.cpp \ scheduled_task.cpp \ thread_pool.cpp \ + pseudo_random.cpp \ HEADERS += \ SRC_FIRST.hpp \ diff --git a/base/pseudo_random.cpp b/base/pseudo_random.cpp new file mode 100644 index 0000000000..bdbf52f2f3 --- /dev/null +++ b/base/pseudo_random.cpp @@ -0,0 +1,20 @@ +#include "pseudo_random.hpp" + + +namespace rnd +{ + +string GenerateString() +{ + static PseudoRNG32 rng; + + size_t const size = rng.Generate() % 20 + 1; + string result; + result.reserve(size); + + for (size_t i = 0; i < size; ++i) + result.append(1, static_cast(rng.Generate() + 1)); + return result; +} + +} diff --git a/base/pseudo_random.hpp b/base/pseudo_random.hpp index 61c5e51033..6ad1b31456 100644 --- a/base/pseudo_random.hpp +++ b/base/pseudo_random.hpp @@ -2,6 +2,9 @@ #include "../base/base.hpp" +#include "../std/string.hpp" + + class LCG32 { public: @@ -19,3 +22,9 @@ private: }; typedef LCG32 PseudoRNG32; + + +namespace rnd +{ +string GenerateString(); +} diff --git a/coding/coding_tests/base64_test.cpp b/coding/coding_tests/base64_test.cpp index 56bf7a9b2e..dfe45fe53f 100644 --- a/coding/coding_tests/base64_test.cpp +++ b/coding/coding_tests/base64_test.cpp @@ -1,8 +1,5 @@ #include "../../testing/testing.hpp" -#include "../../base/logging.hpp" -#include "../../base/pseudo_random.hpp" - #include "../base64.hpp" diff --git a/coding/coding_tests/hex_test.cpp b/coding/coding_tests/hex_test.cpp index 2ba539687e..4bef2c1c34 100644 --- a/coding/coding_tests/hex_test.cpp +++ b/coding/coding_tests/hex_test.cpp @@ -1,10 +1,12 @@ -#include "../../base/SRC_FIRST.hpp" #include "../../testing/testing.hpp" #include "../hex.hpp" + #include "../../base/pseudo_random.hpp" + #include "../../std/string.hpp" + UNIT_TEST(GoldenRecode) { string data("\x01\x23\x45\x67\x89\xAB\xCD\xEF"); @@ -14,26 +16,12 @@ UNIT_TEST(GoldenRecode) TEST_EQUAL(data, FromHex(hexData), ()); } -static string GenString() -{ - static PseudoRNG32 rng; - string result; - // Avoid empty string, since we test it seperately. - size_t size = rng.Generate() % 20 + 1; - for (size_t i = 0; i < size; ++i) - { - result.append(1, static_cast(rng.Generate() + 1)); - } - return result; -} - UNIT_TEST(RandomRecode) { for (size_t i = 0; i < 256; ++i) { - string data = GenString(); - string recoded = FromHex(ToHex(data)); - TEST_EQUAL(data, recoded, ()); + string const data = rnd::GenerateString(); + TEST_EQUAL(data, FromHex(ToHex(data)), ()); } } diff --git a/coding/coding_tests/var_serial_vector_test.cpp b/coding/coding_tests/var_serial_vector_test.cpp index bd0c6d27f1..75157dacae 100644 --- a/coding/coding_tests/var_serial_vector_test.cpp +++ b/coding/coding_tests/var_serial_vector_test.cpp @@ -1,4 +1,3 @@ -#include "../../base/SRC_FIRST.hpp" #include "../var_serial_vector.hpp" #include "../../testing/testing.hpp" @@ -86,27 +85,12 @@ UNIT_TEST(ReadSerial) TEST_EQUAL(reader.Read(2), "ef", ()); } -namespace -{ - string GenString() - { - static PseudoRNG32 rng; - string result; - size_t size = rng.Generate() % 20; - for (size_t i = 0; i < size; ++i) - { - result.append(1, static_cast(rng.Generate() + 1)); - } - return result; - } -} - UNIT_TEST(EncodeDecode) { vector elements; for (size_t i = 0; i < 1024; ++i) - elements.push_back(GenString()); + elements.push_back(rnd::GenerateString()); string serial; PushBackByteSink sink(serial); diff --git a/map/map_tests/mwm_url_tests.cpp b/map/map_tests/mwm_url_tests.cpp index 2eff3989f4..260552328d 100644 --- a/map/map_tests/mwm_url_tests.cpp +++ b/map/map_tests/mwm_url_tests.cpp @@ -2,11 +2,12 @@ #include "../framework.hpp" #include "../mwm_url.hpp" + #include "../../coding/uri.hpp" #include "../../base/string_format.hpp" #include "../../base/pseudo_random.hpp" -#include "../../base/logging.hpp" + using namespace url_scheme; diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm index 0a4dd2943b..386f9e3613 100644 --- a/platform/platform_ios.mm +++ b/platform/platform_ios.mm @@ -3,8 +3,6 @@ #include "constants.hpp" #include "../coding/file_reader.hpp" -#include "../coding/base64.hpp" -#include "../coding/sha2.hpp" #include #include