|
| 1 | +#include "unicore.h" |
| 2 | +#include <cassert> |
| 3 | +#include <cstdio> |
| 4 | + |
| 5 | +void test_empty() |
| 6 | +{ |
| 7 | + const char str[] = " "; |
| 8 | + |
| 9 | + UnicoreParser unicore_parser; |
| 10 | + |
| 11 | + for (unsigned i = 0; i < sizeof(str); ++i) { |
| 12 | + auto result = unicore_parser.parseChar(str[i]); |
| 13 | + assert(result == UnicoreParser::Result::None); |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +void test_garbage() |
| 18 | +{ |
| 19 | + const char str[] = "#GARBAGE,BLA"; |
| 20 | + |
| 21 | + UnicoreParser unicore_parser; |
| 22 | + |
| 23 | + for (unsigned i = 0; i < sizeof(str); ++i) { |
| 24 | + auto result = unicore_parser.parseChar(str[i]); |
| 25 | + assert(result == UnicoreParser::Result::None); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +void test_too_long() |
| 30 | +{ |
| 31 | + const char str[] = |
| 32 | + "#UNIHEADINGA,89,GPS,FINE,2251,168052600,0,0,18,11;SOL_COMPUTED," |
| 33 | + "NARROW_INT,0.3718,67.0255,-0.7974,0.0000,0.8065,3.3818,\"999\"," |
| 34 | + "31,21,21,18,3,01,3,f3,1234567890,1234567890,1234567890,1234567890," |
| 35 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 36 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 37 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 38 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 39 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 40 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 41 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 42 | + "1234567890,1234567890,1234567890,1234567890,1234567890,1234567890," |
| 43 | + "1234567890,ffffffff"; |
| 44 | + |
| 45 | + UnicoreParser unicore_parser; |
| 46 | + |
| 47 | + for (unsigned i = 0; i < sizeof(str); ++i) { |
| 48 | + auto result = unicore_parser.parseChar(str[i]); |
| 49 | + assert(result == UnicoreParser::Result::None); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +void test_uniheadinga_wrong_crc() |
| 54 | +{ |
| 55 | + const char str[] = |
| 56 | + "#UNIHEADINGA,89,GPS,FINE,2251,168052600,0,0,18,11;SOL_COMPUTED,NARROW_INT," |
| 57 | + "0.3718,67.0255,-0.7974,0.0000,0.8065,3.3818,\"999\",31,21,21,18,3,01,3,f3*" |
| 58 | + "ffffffff"; |
| 59 | + |
| 60 | + UnicoreParser unicore_parser; |
| 61 | + |
| 62 | + for (unsigned i = 0; i < sizeof(str); ++i) { |
| 63 | + auto result = unicore_parser.parseChar(str[i]); |
| 64 | + |
| 65 | + if (result == UnicoreParser::Result::WrongCrc) { |
| 66 | + return; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + assert(false); |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +void test_uniheadinga() |
| 75 | +{ |
| 76 | + const char str[] = |
| 77 | + "#UNIHEADINGA,89,GPS,FINE,2251,168052600,0,0,18,11;SOL_COMPUTED,NARROW_INT,0.3718,67.0255,-0.7974,0.0000,0.8065,3.3818,\"999\",31,21,21,18,3,01,3,f3*ece5bb07"; |
| 78 | + |
| 79 | + UnicoreParser unicore_parser; |
| 80 | + |
| 81 | + for (unsigned i = 0; i < sizeof(str); ++i) { |
| 82 | + auto result = unicore_parser.parseChar(str[i]); |
| 83 | + |
| 84 | + if (result == UnicoreParser::Result::GotHeading) { |
| 85 | + assert(unicore_parser.heading().heading_deg == 67.0255f); |
| 86 | + assert(unicore_parser.heading().baseline_m == 0.3718f); |
| 87 | + return; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + assert(false); |
| 92 | +} |
| 93 | + |
| 94 | +void test_unicore() |
| 95 | +{ |
| 96 | + test_empty(); |
| 97 | + test_garbage(); |
| 98 | + test_too_long(); |
| 99 | + test_uniheadinga_wrong_crc(); |
| 100 | + test_uniheadinga(); |
| 101 | +} |
| 102 | + |
| 103 | +int main(int, char **) |
| 104 | +{ |
| 105 | + test_unicore(); |
| 106 | + |
| 107 | + return 0; |
| 108 | +} |
0 commit comments