diff options
author | Sergey Yershov <yershov@corp.mail.ru> | 2016-10-21 19:54:02 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-10-25 17:33:35 +0300 |
commit | 1f1d0a58713f4f4817827aa108f75e0657014813 (patch) | |
tree | eff7e58b59addf80982788177617215f4f840622 /tracking/tracking_tests | |
parent | 8314310c0e8a63bed40abf95b7741b10c24521eb (diff) |
[tracking] Made tracking work
Diffstat (limited to 'tracking/tracking_tests')
-rw-r--r-- | tracking/tracking_tests/protocol_test.cpp | 34 | ||||
-rw-r--r-- | tracking/tracking_tests/reporter_test.cpp | 34 | ||||
-rw-r--r-- | tracking/tracking_tests/tracking_tests.pro | 3 |
3 files changed, 65 insertions, 6 deletions
diff --git a/tracking/tracking_tests/protocol_test.cpp b/tracking/tracking_tests/protocol_test.cpp new file mode 100644 index 0000000000..f3b72d6160 --- /dev/null +++ b/tracking/tracking_tests/protocol_test.cpp @@ -0,0 +1,34 @@ +#include "testing/testing.hpp" + +#include "tracking/protocol.hpp" + +using namespace tracking; + +UNIT_TEST(Protocol_CreateAuthPacket) +{ + auto packet = Protocol::CreateAuthPacket("AAA"); + TEST_EQUAL(packet.size(), 7, ()); + TEST_EQUAL(Protocol::PacketType(packet[0]), Protocol::PacketType::CurrentAuth, ()); + TEST_EQUAL(packet[1], 0x00, ()); + TEST_EQUAL(packet[2], 0x00, ()); + TEST_EQUAL(packet[3], 0x03, ()); + TEST_EQUAL(packet[4], 'A', ()); + TEST_EQUAL(packet[5], 'A', ()); + TEST_EQUAL(packet[6], 'A', ()); +} + +UNIT_TEST(Protocol_CreateDataPacket) +{ + Protocol::DataElements buffer(5); + buffer.push_back(Protocol::DataElements::value_type(1, ms::LatLon(10, 10))); + buffer.push_back(Protocol::DataElements::value_type(2, ms::LatLon(15, 15))); + auto packet = Protocol::CreateDataPacket(buffer); + TEST_EQUAL(packet.size(), 26, ()); + TEST_EQUAL(Protocol::PacketType(packet[0]), Protocol::PacketType::CurrentData, ()); + TEST_EQUAL(packet[1], 0x00, ()); + TEST_EQUAL(packet[2], 0x00, ()); + TEST_EQUAL(packet[3], 22, ()); + TEST_EQUAL(packet[4], 1, ()); + TEST_EQUAL(packet[5], 227, ()); + TEST_EQUAL(packet[6], 241, ()); +} diff --git a/tracking/tracking_tests/reporter_test.cpp b/tracking/tracking_tests/reporter_test.cpp index 685b4f19f7..bdd47a60a5 100644 --- a/tracking/tracking_tests/reporter_test.cpp +++ b/tracking/tracking_tests/reporter_test.cpp @@ -1,4 +1,7 @@ +#include "testing/testing.hpp" + #include "tracking/reporter.hpp" +#include "tracking/protocol.hpp" #include "coding/traffic.hpp" @@ -6,8 +9,6 @@ #include "platform/platform_tests_support/test_socket.hpp" #include "platform/socket.hpp" -#include "testing/testing.hpp" - #include "base/math.hpp" #include "base/thread.hpp" @@ -28,13 +29,36 @@ void TransferLocation(Reporter & reporter, TestSocket & testSocket, double times gpsInfo.m_horizontalAccuracy = 1.0; reporter.AddLocation(gpsInfo); + using Packet = tracking::Protocol::PacketType; vector<uint8_t> buffer; - size_t const readSize = testSocket.ReadServer(buffer); - TEST_GREATER(readSize, 0, ()); + size_t readSize = 0; + size_t attempts = 3; + do + { + readSize = testSocket.ReadServer(buffer); + if (attempts-- && readSize == 0) + continue; + switch (Packet(buffer[0])) + { + case Packet::CurrentAuth: + { + buffer.clear(); + testSocket.WriteServer(tracking::Protocol::kOk); + break; + } + case Packet::CurrentData: + { + readSize = 0; + break; + } + } + } while (readSize); + TEST(!buffer.empty(), ()); vector<coding::TrafficGPSEncoder::DataPoint> points; MemReader memReader(buffer.data(), buffer.size()); ReaderSource<MemReader> src(memReader); + src.Skip(sizeof(uint32_t /* header */)); coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src, points); @@ -51,7 +75,7 @@ UNIT_TEST(Reporter_TransferLocations) auto socket = make_unique<TestSocket>(); TestSocket & testSocket = *socket.get(); - Reporter reporter(move(socket), milliseconds(10) /* pushDelay */); + Reporter reporter(move(socket), "localhost", 0, 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/tracking_tests.pro b/tracking/tracking_tests/tracking_tests.pro index 81465b60aa..6009b5ffda 100644 --- a/tracking/tracking_tests/tracking_tests.pro +++ b/tracking/tracking_tests/tracking_tests.pro @@ -26,4 +26,5 @@ win*|linux* { SOURCES += \ $$ROOT_DIR/testing/testingmain.cpp \ - reporter_test.cpp + protocol_test.cpp \ + reporter_test.cpp \ |