| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64util/na64/event-id.hh" | ||
| 2 | #include <gtest/gtest.h> | ||
| 3 | |||
| 4 | namespace na64dp { | ||
| 5 | |||
| 6 | // TODO: exception-throw tests | ||
| 7 | |||
| 8 | 8 | TEST( EventID, ToStringConversion ) { | |
| 9 |
1/1✓ Branch 1 taken 1 times.
|
2 | EventID eid( 124, 735, 1094102 ); |
| 10 |
1/1✓ Branch 1 taken 1 times.
|
2 | std::string txt = eid.to_str(); |
| 11 |
1/1✓ Branch 1 taken 1 times.
|
2 | EventID eid2 = EventID::from_str( txt ); |
| 12 |
5/7✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 29 taken 1 times.
✗ Branch 30 not taken.
|
2 | ASSERT_STREQ( eid.to_str().c_str(), eid2.to_str().c_str() ); |
| 13 | 2 | } | |
| 14 | |||
| 15 | 8 | TEST( EventID, ComparisonOperations ) { | |
| 16 | struct EvStub { | ||
| 17 | struct id { int run, spill, event; } a, b; | ||
| 18 | bool expectedResult; | ||
| 19 | 2 | } stubs[] = { | |
| 20 | { { 0, 0, 0}, { 0, 0, 0}, false }, | ||
| 21 | |||
| 22 | { { 1, 0, 0}, { 0, 0, 0}, false }, | ||
| 23 | { { 0, 1, 0}, { 0, 0, 0}, false }, | ||
| 24 | { { 0, 0, 1}, { 0, 0, 0}, false }, | ||
| 25 | |||
| 26 | { { 0, 0, 0}, { 1, 0, 0}, true }, | ||
| 27 | { { 0, 0, 0}, { 0, 1, 0}, true }, | ||
| 28 | { { 0, 0, 0}, { 0, 0, 1}, true }, | ||
| 29 | |||
| 30 | { { 1, 1, 1}, { 1, 1, 1}, false }, | ||
| 31 | |||
| 32 | { { 2, 1, 1}, { 1, 1, 1}, false }, | ||
| 33 | { { 1, 2, 1}, { 1, 1, 1}, false }, | ||
| 34 | { { 1, 1, 2}, { 1, 1, 1}, false }, | ||
| 35 | |||
| 36 | { { 2, 1, 1}, { 3, 1, 1}, true }, | ||
| 37 | { { 1, 2, 1}, { 1, 3, 1}, true }, | ||
| 38 | { { 1, 1, 2}, { 1, 1, 3}, true }, | ||
| 39 | }; | ||
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1 times.
|
30 | for( unsigned int i = 0; i < sizeof(stubs)/sizeof(EvStub); ++i ) { |
| 42 | 28 | const EvStub & stub = stubs[i]; | |
| 43 |
1/1✓ Branch 1 taken 14 times.
|
28 | EventID a( stub.a.run, stub.a.spill, stub.a.event ) |
| 44 |
1/1✓ Branch 1 taken 14 times.
|
28 | , b( stub.b.run, stub.b.spill, stub.b.event ); |
| 45 |
2/3✓ Branch 2 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14 times.
|
28 | EXPECT_EQ( stub.expectedResult, a < b ); |
| 46 | } | ||
| 47 | 2 | } | |
| 48 | |||
| 49 | // Controls basic order, simple stubs | ||
| 50 | 8 | TEST( EventID, MapIndexOrderBasic ) { | |
| 51 | 2 | std::map<EventID, int> map; | |
| 52 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | map.emplace( EventID( 5, 0, 12), 1 ); |
| 53 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | map.emplace( EventID(10, 0, 0), 2 ); |
| 54 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | auto it1 = map.find( EventID( 5, 0, 12) ); |
| 55 |
3/5✓ Branch 2 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
2 | ASSERT_NE( it1, map.end() ); |
| 56 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
2 | auto it2 = map.find( EventID(10, 0, 0) ); |
| 57 |
3/5✓ Branch 2 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
|
2 | ASSERT_NE( it2, map.end() ); |
| 58 |
3/5✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
2 | ASSERT_LT( it1->second, it2->second ); |
| 59 | 2 | } | |
| 60 | |||
| 61 | // Controls ordering, combinatiorial test | ||
| 62 | 8 | TEST( EventID, MapIndexOrderFull ) { | |
| 63 | // Three bits from ctrl byte are used, steering the run, spill and event | ||
| 64 | // numbers | ||
| 65 | 2 | std::map<EventID, int> map; | |
| 66 | 2 | for( uint8_t ctrlByte = 0x0 | |
| 67 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 times.
|
34 | ; ctrlByte < (1 << 4) |
| 68 | ; ++ctrlByte ) { | ||
| 69 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
32 | int runNo = ctrlByte & (1 << 2) ? 10 : 0 |
| 70 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
32 | , spillNo = ctrlByte & (1 << 1) ? 10 : 0 |
| 71 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
32 | , eventNo = ctrlByte & 0x1 ? 10 : 0 |
| 72 | ; | ||
| 73 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
32 | map.emplace( EventID(runNo, spillNo, eventNo) |
| 74 | , ctrlByte ); | ||
| 75 | } | ||
| 76 |
1/1✓ Branch 1 taken 1 times.
|
2 | std::pair<EventID, int> prevPair( EventID(0, 0, 0), -1 ); |
| 77 |
2/2✓ Branch 5 taken 8 times.
✓ Branch 6 taken 1 times.
|
18 | for( auto p : map ) { |
| 78 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
16 | if( prevPair.second > -1 ) { |
| 79 |
2/3✓ Branch 1 taken 7 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
|
14 | EXPECT_GT( p.first, prevPair.first ); |
| 80 | } | ||
| 81 |
2/3✓ Branch 1 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
|
16 | EXPECT_GT( p.second, prevPair.second ) |
| 82 | ✗ | << "current event ID is " << p.first | |
| 83 | ✗ | << " (0x" << std::hex << p.first << std::dec << ") " | |
| 84 | ✗ | << ", index is " << p.second | |
| 85 | ✗ | << "; previous event ID was: " << prevPair.first | |
| 86 | ✗ | << " (0x" << std::hex << prevPair.first << std::dec << ") " | |
| 87 | ✗ | << ", with index " << prevPair.second | |
| 88 | 16 | ; | |
| 89 | 16 | prevPair = p; | |
| 90 | } | ||
| 91 | 2 | } | |
| 92 | |||
| 93 | // 1010(0) [0000 0000 0000 0000] | ||
| 94 | // | ||
| 95 | |||
| 96 | } | ||
| 97 | |||
| 98 |