diff options
author | Добрый Ээх <bukharaev@gmail.com> | 2016-10-14 11:36:10 +0300 |
---|---|---|
committer | Добрый Ээх <bukharaev@gmail.com> | 2016-10-19 15:51:02 +0300 |
commit | 5666583532d208c05d6194d1cb28a5b61ad9d75c (patch) | |
tree | f224f8c27a03b8104b558f7055921fccc95e64ff /tracking/tracking_tests | |
parent | a65d86ebcf216bd0480c7f576d0eff60df44a160 (diff) |
Pull request #4498 review fixes
Diffstat (limited to 'tracking/tracking_tests')
-rw-r--r-- | tracking/tracking_tests/reporter_test.cpp | 57 | ||||
-rw-r--r-- | tracking/tracking_tests/reporter_tests.cpp | 62 | ||||
-rw-r--r-- | tracking/tracking_tests/tracking_tests.pro | 4 |
3 files changed, 59 insertions, 64 deletions
diff --git a/tracking/tracking_tests/reporter_test.cpp b/tracking/tracking_tests/reporter_test.cpp new file mode 100644 index 0000000000..2492f32e9d --- /dev/null +++ b/tracking/tracking_tests/reporter_test.cpp @@ -0,0 +1,57 @@ +#include "tracking/reporter.hpp" + +#include "coding/traffic.hpp" + +#include "platform/location.hpp" +#include "platform/platform_tests_support/test_socket.hpp" +#include "platform/socket.hpp" + +#include "testing/testing.hpp" + +#include "base/math.hpp" +#include "base/thread.hpp" + +#include "std/cmath.hpp" + +using namespace tracking; +using namespace platform::tests_support; + +namespace +{ +void TransferLocation(Reporter & reporter, TestSocket & testSocket, double timestamp, + double latidute, double longtitude) +{ + location::GpsInfo gpsInfo; + gpsInfo.m_timestamp = timestamp; + gpsInfo.m_latitude = latidute; + gpsInfo.m_longitude = longtitude; + reporter.AddLocation(gpsInfo); + + vector<uint8_t> buffer; + size_t const readSize = testSocket.ReadServer(buffer); + TEST_GREATER(readSize, 0, ()); + + vector<coding::TrafficGPSEncoder::DataPoint> points; + MemReader memReader(buffer.data(), buffer.size()); + ReaderSource<MemReader> src(memReader); + coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src, + points); + + TEST_EQUAL(points.size(), 1, ()); + auto const & point = points[0]; + TEST_EQUAL(point.m_timestamp, timestamp, ()); + TEST(my::AlmostEqualAbs(point.m_latLon.lat, latidute, 0.001), ()); + TEST(my::AlmostEqualAbs(point.m_latLon.lon, longtitude, 0.001), ()); +} +} + +UNIT_TEST(Reporter_TransferLocations) +{ + auto socket = make_unique<TestSocket>(); + TestSocket & testSocket = *socket.get(); + + Reporter reporter(move(socket), milliseconds(10) /* pushDelay */); + TransferLocation(reporter, testSocket, 1.0, 2.0, 3.0); + TransferLocation(reporter, testSocket, 4.0, 5.0, 6.0); + TransferLocation(reporter, testSocket, 7.0, 8.0, 9.0); +} diff --git a/tracking/tracking_tests/reporter_tests.cpp b/tracking/tracking_tests/reporter_tests.cpp deleted file mode 100644 index f8dc89d38b..0000000000 --- a/tracking/tracking_tests/reporter_tests.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "base/thread.hpp" -#include "coding/traffic.hpp" - -#include "platform/location.hpp" -#include "platform/socket.hpp" - -#include "std/cmath.hpp" - -#include "testing/testing.hpp" - -#include "tracking/reporter.hpp" - -namespace -{ -template <class Condition> -bool WaitCondition(Condition condition, size_t durationMs = 1000) -{ - size_t sleepMs = 10; - size_t cyclesLimit = durationMs / sleepMs; - for (size_t i = 0; i < cyclesLimit; ++i) - { - threads::Sleep(sleepMs); - if (condition()) - return true; - } - - return false; -} -} // namespace - -using namespace tracking; - -UNIT_TEST(Reporter_TransferLocation) -{ - unique_ptr<platform::TestSocket> socket = platform::createTestSocket(); - platform::TestSocket * testSocket = socket.get(); - - Reporter reporter(move(socket), 10); - - location::GpsInfo gpsInfo; - gpsInfo.m_timestamp = 3.0; - gpsInfo.m_latitude = 4.0; - gpsInfo.m_longitude = 5.0; - reporter.AddLocation(gpsInfo); - - TEST(WaitCondition([testSocket] { return testSocket->HasOutput(); }), ()); - - vector<uint8_t> buffer; - testSocket->ReadServer(buffer); - - vector<coding::TrafficGPSEncoder::DataPoint> points; - MemReader memReader(buffer.data(), buffer.size()); - ReaderSource<MemReader> src(memReader); - coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src, - points); - - TEST_EQUAL(points.size(), 1, ()); - coding::TrafficGPSEncoder::DataPoint const & point = points[0]; - TEST_EQUAL(point.m_timestamp, 3, ()); - TEST(abs(point.m_latLon.lat - 4.0) < 0.001, ()); - TEST(abs(point.m_latLon.lon - 5.0) < 0.001, ()); -} diff --git a/tracking/tracking_tests/tracking_tests.pro b/tracking/tracking_tests/tracking_tests.pro index f37f3fb860..81465b60aa 100644 --- a/tracking/tracking_tests/tracking_tests.pro +++ b/tracking/tracking_tests/tracking_tests.pro @@ -7,7 +7,7 @@ ROOT_DIR = ../.. INCLUDEPATH *= $$ROOT_DIR/3party/jansson/src -DEPENDENCIES = base coding geometry platform routing stats_client tracking +DEPENDENCIES = routing tracking platform_tests_support platform coding geometry base stats_client include($$ROOT_DIR/common.pri) @@ -26,4 +26,4 @@ win*|linux* { SOURCES += \ $$ROOT_DIR/testing/testingmain.cpp \ - reporter_tests.cpp \ + reporter_test.cpp |