| 135 | } |
| 136 | |
| 137 | void testBadFcs() |
| 138 | { |
| 139 | // Corrupt a bit in the middle of the bitstream and verify FCS fails. |
| 140 | lm::packet pkt("N0CALL", "APRS", {}, ">Corruption test"); |
| 141 | auto nrzi = makeNrziBitstream(pkt); |
| 142 | |
| 143 | // Flip a bit roughly in the middle (well away from preamble/postamble flags). |
| 144 | size_t mid = nrzi.size() / 2; |
| 145 | nrzi[mid] ^= 1; |
| 146 | |
| 147 | HdlcCodec codec; |
| 148 | int frames = 0; |
| 149 | int badFcs = 0; |
| 150 | for (uint8_t bit : nrzi) { |
| 151 | if (codec.processBit(bit)) { |
| 152 | ++frames; |
| 153 | if (!codec.fcsValid()) |
| 154 | ++badFcs; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // We expect at least one complete frame (may not decode as valid AX.25) |
| 159 | // but the FCS should be wrong. |
| 160 | report("bad FCS: at least one frame candidate", frames >= 1); |
| 161 | report("bad FCS: no valid FCS", badFcs == frames); |
| 162 | } |
| 163 | |
| 164 | void testTwoConsecutiveFrames() |
| 165 | { |
no test coverage detected