|
1 | 1 | #include <gtest/gtest.h>
|
2 | 2 |
|
3 | 3 | #include <memory>
|
| 4 | +#include <random> |
4 | 5 |
|
5 | 6 | #include "ElasticFrameProtocol.h"
|
6 |
| -#include "ElasticInternal.h" |
7 | 7 | #include "UnitTestHelpers.h"
|
8 | 8 |
|
9 | 9 | // UnitTest24
|
10 |
| -// Test unpack type1 packet |
11 |
| -TEST(UnitTest24, UnpackType1) { |
12 |
| - const size_t FRAME_SIZE = ((MTU - ElasticFrameProtocolSender::getType1Size()) * 5) + 12; |
| 10 | +// Test receiving corrupted packages |
| 11 | +TEST(UnitTest24, SendPacketFrameType1AndFrameType2) { |
| 12 | + std::random_device rd; |
| 13 | + std::mt19937 gen(rd()); |
| 14 | + std::uniform_int_distribution<uint8_t> dis(0, 255); |
| 15 | + |
| 16 | + const size_t FRAME_SIZE = |
| 17 | + (MTU - ElasticFrameProtocolSender::getType1Size()) + 1; |
13 | 18 | std::unique_ptr<ElasticFrameProtocolReceiver> myEFPReceiver =
|
14 | 19 | std::make_unique<ElasticFrameProtocolReceiver>(50, 20);
|
15 |
| - ElasticFrameType1 lType1Frame; |
| 20 | + std::unique_ptr<ElasticFrameProtocolSender> myEFPPacker = |
| 21 | + std::make_unique<ElasticFrameProtocolSender>(MTU); |
| 22 | + |
| 23 | + for (int i = 0; i < 10000; i++) { |
| 24 | + myEFPPacker->sendCallback = [&](const std::vector<uint8_t> &subPacket, |
| 25 | + uint8_t lStreamID, |
| 26 | + ElasticFrameProtocolContext *pCTX) { |
| 27 | + std::vector<uint8_t> garbage = subPacket; |
| 28 | + for (size_t b = 0; b < garbage.size(); b++) { |
| 29 | + garbage[b] = dis(gen); |
| 30 | + } |
| 31 | + ElasticFrameMessages info = myEFPReceiver->receiveFragment(garbage, 0); |
| 32 | + }; |
16 | 33 |
|
17 |
| - // test with nice type1 packet |
18 |
| - lType1Frame.hSuperFrameNo = 0; |
19 |
| - lType1Frame.hFrameType = Frametype::type1; |
20 |
| - ElasticFrameMessages result = myEFPReceiver->receiveFragmentFromPtr(reinterpret_cast<uint8_t*>(&lType1Frame), FRAME_SIZE, 0); |
21 |
| - EXPECT_EQ(result, ElasticFrameMessages::noError); |
| 34 | + std::vector<uint8_t> mydata; |
| 35 | + mydata.resize(FRAME_SIZE); |
22 | 36 |
|
23 |
| - // test with corrupt type1 packet |
24 |
| - lType1Frame.hSuperFrameNo = 1; |
25 |
| - lType1Frame.hFragmentNo = 12345; |
26 |
| - result = myEFPReceiver->receiveFragmentFromPtr(reinterpret_cast<uint8_t*>(&lType1Frame), FRAME_SIZE, 0); |
27 |
| - EXPECT_EQ(result, ElasticFrameMessages::bufferOutOfBounds); |
| 37 | + uint8_t streamID = 4; |
| 38 | + ElasticFrameMessages result = myEFPPacker->packAndSend( |
| 39 | + mydata, ElasticFrameContent::adts, 1001, 1, 2, streamID, NO_FLAGS); |
| 40 | + EXPECT_EQ(result, ElasticFrameMessages::noError); |
| 41 | + } |
28 | 42 | }
|
0 commit comments