aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / svc / tests / allen_place_test.c
| 1 | /* allen_place_test.c -- host test of ck_allen_parse_place (native/kernel/svc/allen_reply.c): |
| 2 | * coordinates typed to Allen, in the forms Drake will use, and the lines that must not |
| 3 | * be taken for a place. Prints one line per check and ends with "ALLEN_PLACE: PASS" or |
| 4 | * "ALLEN_PLACE: FAIL <n> checks". */ |
| 5 | #include <stdint.h> |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | #include "allen_reply.h" |
| 9 | |
| 10 | static int fails = 0, checks = 0; |
| 11 | |
| 12 | static void expect(const char *line, int want, int32_t lat, int32_t lon) |
| 13 | { |
| 14 | int32_t la = 7, lo = 7; |
| 15 | int got = ck_allen_parse_place(line, &la, &lo); |
| 16 | int ok = got == want && (!want || (la == lat && lo == lon)); |
| 17 | checks++; |
| 18 | if (!ok) |
| 19 | fails++; |
| 20 | printf("%s \"%s\" -> %d (%d.%06d, %d.%06d) want %d (%d, %d)\n", ok ? "ok " : "FAIL ", line, got, |
| 21 | la / 1000000, la % 1000000 < 0 ? -(la % 1000000) : la % 1000000, lo / 1000000, |
| 22 | lo % 1000000 < 0 ? -(lo % 1000000) : lo % 1000000, want, lat, lon); |
| 23 | } |
| 24 | |
| 25 | int main(void) |
| 26 | { |
| 27 | /* Drake's forms, and the ones that should match too */ |
| 28 | expect("35 north 90 west", 1, 35000000, -90000000); |
| 29 | expect("35 North 90 West", 1, 35000000, -90000000); |
| 30 | expect("35.1 n, 90.0 w", 1, 35100000, -90000000); |
| 31 | expect("35.1, -90.0", 1, 35100000, -90000000); |
| 32 | expect("35.1,-90.0", 1, 35100000, -90000000); |
| 33 | expect("I'm at 35.1, -90.0.", 1, 35100000, -90000000); |
| 34 | expect("location is 35 north, 90 west", 1, 35000000, -90000000); |
| 35 | expect("lat 35.1 lon -90", 1, 35100000, -90000000); |
| 36 | expect("-33.87 151.21", 1, -33870000, 151210000); /* a minus sign is enough */ |
| 37 | expect("-33.87, 151.21", 1, -33870000, 151210000); |
| 38 | expect("33.87 south, 151.21 east", 1, -33870000, 151210000); |
| 39 | expect("north 35 west 90", 1, 35000000, -90000000); |
| 40 | expect("35.123456789, -90.5", 1, 35123456, -90500000); |
| 41 | expect("0 north 0 east", 1, 0, 0); |
| 42 | /* must not be taken for a place */ |
| 43 | expect("35 90", 0, 0, 0); |
| 44 | expect("what is 35 - 90", 0, 0, 0); |
| 45 | expect("what is 35 plus 90", 0, 0, 0); |
| 46 | expect("35", 0, 0, 0); |
| 47 | expect("sky above me", 0, 0, 0); |
| 48 | expect("i'm in memphis", 0, 0, 0); |
| 49 | expect("my name is 35", 0, 0, 0); |
| 50 | expect("91 north 10 east", 0, 0, 0); /* latitude out of range */ |
| 51 | expect("10 north 181 east", 0, 0, 0); /* longitude out of range */ |
| 52 | expect("35 north 90 west 4", 0, 0, 0); /* three numbers */ |
| 53 | expect("-35 north, 90 west", 0, 0, 0); /* a sign and a direction on one number */ |
| 54 | expect("", 0, 0, 0); |
| 55 | printf("ALLEN_PLACE: %s (%d checks, %d failed)\n", fails ? "FAIL" : "PASS", checks, fails); |
| 56 | return fails ? 1 : 0; |
| 57 | } |