-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: unittest: added test for MemoryOutputStream
- Loading branch information
1 parent
0fa2f05
commit d757df1
Showing
1 changed file
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
%description: | ||
Test MemoryOutputStream | ||
|
||
%includes: | ||
#include "inet/common/MemoryOutputStream.h" | ||
#include <iomanip> | ||
|
||
static std::ostream& operator<<(std::ostream& os, const ::inet::MemoryOutputStream& stream) | ||
{ | ||
const const std::vector<uint8_t>& data = stream.getData(); | ||
for (auto b: data) { | ||
os << " " << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)b; | ||
} | ||
os << std::dec; | ||
return os; | ||
} | ||
|
||
%global: | ||
|
||
#define P(X) EV << X << "-->" << ::inet::MacAddress(X).formInterfaceIdentifier() << "\n" | ||
|
||
%activity: | ||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBit(1); | ||
s.writeBit(0); | ||
s.writeBit(0); | ||
s.writeBit(0); | ||
s.writeBit(0); | ||
s.writeBit(0); | ||
s.writeBit(1); | ||
s.writeBit(0); | ||
|
||
EV << "b10000010:" << s << "\n"; | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBit(0); | ||
s.writeByte(0xff); | ||
s.writeBitRepeatedly(0, 7); | ||
|
||
EV << "b0.xff.b0*7:" << s << "\n"; // 0 1111 1111 0000000: 0111 1111 1000 0000 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBit(1); | ||
s.writeByte(0xff); | ||
s.writeBitRepeatedly(1, 7); | ||
|
||
EV << "b1.xff.b1*7:" << s << "\n"; // 1 1111 1111 1111111: 1111 1111 1111 1111 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBit(0); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(0, 7); | ||
|
||
EV << "b0.x82.b0*7:" << s << "\n"; // 0 1000 0010 0000000: 0100 0001 0000 0000 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBit(1); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(1, 7); | ||
|
||
EV << "b1.x82.b1*7:" << s << "\n"; // 1 1000 0010 1111111: 1100 0001 0111 1111 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(0, 5); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(0, 3); | ||
|
||
EV << "b0*5.x82.b0*3:" << s << "\n"; // 00000 1000 0010 000: 0000 0100 0001 0000 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(1, 5); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(1, 3); | ||
|
||
EV << "b1*5.x82.b1*3:" << s << "\n"; // 11111 1000 0010 111: 1111 1100 0001 0111 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(0, 3); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(0, 5); | ||
|
||
EV << "b0*3.x82.b0*5:" << s << "\n"; // 000 1000 0010 00000: 0001 0000 0100 0000 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(1, 3); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(1, 5); | ||
|
||
EV << "b1*3.x82.b1*5:" << s << "\n"; // 111 1000 0010 11111: 1111 0000 0101 1111 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(0, 5); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(0, 3); | ||
|
||
EV << "b0*5.x82.b0*3:" << s << "\n"; // 00000 1000 0010 000: 0000 0100 0001 0000 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(1, 5); | ||
s.writeByte(0x82); | ||
s.writeBitRepeatedly(1, 3); | ||
|
||
EV << "b1*5.x82.b1*3:" << s << "\n"; // 11111 1000 0010 111: 1111 1100 0001 0111 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(0, 7); | ||
s.writeByte(0x82); | ||
s.writeBit(0); | ||
|
||
EV << "b0*7.x82.b0:" << s << "\n"; // 0000000 1000 0010 0: 0000 0001 0000 0100 | ||
} | ||
|
||
{ | ||
inet::MemoryOutputStream s; | ||
s.writeBitRepeatedly(1, 7); | ||
s.writeByte(0x82); | ||
s.writeBit(1); | ||
|
||
EV << "b1*7.x82.b1:" << s << "\n"; // 1111111 1000 0010 1: 1111 1111 0000 0101 | ||
} | ||
|
||
EV << ".\n"; | ||
|
||
%contains: stdout | ||
1000.0010: 82 | ||
b0.xff.b0*7: 7f 80 | ||
b1.xff.b1*7: ff ff | ||
b0.x82.b0*7: 41 00 | ||
b1.x82.b1*7: c1 7f | ||
b0*5.x82.b0*3: 04 10 | ||
b1*5.x82.b1*3: fc 17 | ||
b0*3.x82.b0*5: 10 40 | ||
b1*3.x82.b1*5: f0 5f | ||
b0*5.x82.b0*3: 04 10 | ||
b1*5.x82.b1*3: fc 17 | ||
b0*7.x82.b0: 01 04 | ||
b1*7.x82.b1: ff 05 | ||
. |