Reads a stag CSV, orders the geotagged rows by their parsed timestamp (ISO and EXIF-colon forms sort together), and draws the trip on an OSM map: blue line with white halo, direction arrowhead per leg, red marker per stop, MM-DD HH:MM label per timestamped stop. Rows without a timestamp go last in CSV order; rows without coordinates are skipped. Reuses sgeo tile/zoom/marker code via shared fetch_tiles/draw_attribution helpers. Tests: 11/11 in tests/run_tests.sh (3 new trip cases + tests/check_trip.py). Docs: docs/trip-path.md.
160 lines
7.0 KiB
Bash
Executable File
160 lines
7.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# stag/sgeo tests. Offline except for the local fake tile server:
|
|
# PATH=tests/bin:$PATH (fake `sfile` with canned GPS values)
|
|
# SGEO_TILE_BASE=http://127.0.0.1:<port> (tests/tile_server.py)
|
|
# Cases: multi-file dir (CSV byte-for-byte + map markers), single
|
|
# point, no-geotag dir, empty dir, the default outfiles, and
|
|
# sgeo --trip (ordered polyline + time labels from a synthetic CSV,
|
|
# single point, and the failure cases).
|
|
# Usage: ./tests/run_tests.sh (run from the repo root)
|
|
set -u
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
TMP="$(mktemp -d /tmp/stag-sgeo-tests.XXXXXX)"
|
|
TILE_PID=""
|
|
cleanup() { rm -rf "$TMP"; [ -n "$TILE_PID" ] && kill "$TILE_PID" 2>/dev/null; }
|
|
trap cleanup EXIT
|
|
FAIL=0
|
|
pass() { echo "PASS: $1"; }
|
|
fail() { echo "FAIL: $1"; FAIL=1; }
|
|
|
|
cd "$ROOT" || exit 1
|
|
make stag sgeo >/dev/null 2>&1 || { echo "FAIL: build stag/sgeo"; exit 1; }
|
|
|
|
python3 tests/tile_server.py --port-file "$TMP/port" >/dev/null 2>&1 &
|
|
TILE_PID=$!
|
|
for _ in $(seq 1 50); do [ -s "$TMP/port" ] && break; sleep 0.1; done
|
|
[ -s "$TMP/port" ] || { echo "FAIL: tile server did not start"; exit 1; }
|
|
export SGEO_TILE_BASE="http://127.0.0.1:$(cat "$TMP/port")"
|
|
export PATH="$ROOT/tests/bin:$PATH"
|
|
|
|
mkdir -p "$TMP/multi/sub" "$TMP/nogeo" "$TMP/empty" "$TMP/single"
|
|
touch "$TMP/multi/PARIS.JPG" "$TMP/multi/nyc.jpg" "$TMP/multi/plain.jpg" \
|
|
"$TMP/multi/sf.jpg" "$TMP/multi/tokyo.jpg" "$TMP/multi/notes.txt" \
|
|
"$TMP/multi/sub/inner.jpg"
|
|
touch "$TMP/nogeo/plain.jpg" "$TMP/nogeo/nogeo.png"
|
|
touch "$TMP/single/sf.jpg"
|
|
|
|
# 1. stag, multi-file dir: CSV must match byte-for-byte.
|
|
./stag "$TMP/multi" "$TMP/out.csv" 2>"$TMP/stag.log"
|
|
if diff -u tests/expected_geotags.csv "$TMP/out.csv" >"$TMP/diff.txt" 2>&1; then
|
|
pass "stag multi-file CSV byte-for-byte"
|
|
else
|
|
fail "stag multi-file CSV byte-for-byte"; cat "$TMP/diff.txt"
|
|
fi
|
|
|
|
# 2. sgeo, multi-file dir: 4 markers (PARIS/nyc/sf/tokyo), plaque on image.
|
|
if ./sgeo "$TMP/multi" "$TMP/map.png" 2>"$TMP/sgeo.log"; then
|
|
python3 tests/check_map.py "$TMP/map.png" 4 >/tmp/check1.txt 2>&1 \
|
|
&& pass "sgeo multi-file map (4 markers + attribution)" \
|
|
|| { fail "sgeo multi-file map (4 markers + attribution)"; cat /tmp/check1.txt; }
|
|
else
|
|
fail "sgeo multi-file exit 0"; cat "$TMP/sgeo.log"
|
|
fi
|
|
|
|
# 3. sgeo, single point: succeeds, exactly 1 marker.
|
|
if ./sgeo "$TMP/single" "$TMP/single.png" 2>"$TMP/sgeo1.log"; then
|
|
python3 tests/check_map.py "$TMP/single.png" 1 >/tmp/check2.txt 2>&1 \
|
|
&& pass "sgeo single-point map (1 marker)" \
|
|
|| { fail "sgeo single-point map (1 marker)"; cat /tmp/check2.txt; }
|
|
else
|
|
fail "sgeo single-point exit 0"; cat "$TMP/sgeo1.log"
|
|
fi
|
|
|
|
# 4. No-geotag dir: stag rows are empty, sgeo fails with no file.
|
|
./stag "$TMP/nogeo" "$TMP/nogeo.csv" 2>/dev/null
|
|
if diff -q tests/expected_nogeo.csv "$TMP/nogeo.csv" >/dev/null 2>&1; then
|
|
pass "stag no-geotag CSV"
|
|
else
|
|
fail "stag no-geotag CSV"; diff -u tests/expected_nogeo.csv "$TMP/nogeo.csv"
|
|
fi
|
|
if ./sgeo "$TMP/nogeo" "$TMP/nogeo.png" 2>"$TMP/nogeo.err"; then
|
|
fail "sgeo no-geotag exits non-zero"
|
|
else
|
|
if [ ! -e "$TMP/nogeo.png" ] && grep -q "no geotagged" "$TMP/nogeo.err"; then
|
|
pass "sgeo no-geotag: non-zero, message, no file"
|
|
else
|
|
fail "sgeo no-geotag: message/no-file"; cat "$TMP/nogeo.err"
|
|
fi
|
|
fi
|
|
|
|
# 5. Empty dir: stag header only, sgeo fails with no file.
|
|
./stag "$TMP/empty" "$TMP/empty.csv" 2>/dev/null
|
|
if diff -q tests/expected_empty.csv "$TMP/empty.csv" >/dev/null 2>&1; then
|
|
pass "stag empty-dir CSV (header only)"
|
|
else
|
|
fail "stag empty-dir CSV (header only)"
|
|
fi
|
|
if ./sgeo "$TMP/empty" "$TMP/empty.png" 2>"$TMP/empty.err"; then
|
|
fail "sgeo empty-dir exits non-zero"
|
|
elif [ ! -e "$TMP/empty.png" ]; then
|
|
pass "sgeo empty-dir: non-zero, no file"
|
|
else
|
|
fail "sgeo empty-dir: no file expected"
|
|
fi
|
|
|
|
# 6. Default outfiles: stag -> geotags.csv, sgeo -> map.png in the cwd.
|
|
mkdir -p "$TMP/cwd" && cp "$TMP/single/sf.jpg" "$TMP/cwd/"
|
|
( cd "$TMP/cwd" && "$ROOT/stag" . 2>/dev/null && "$ROOT/sgeo" . 2>/dev/null )
|
|
if [ -s "$TMP/cwd/geotags.csv" ] && [ -s "$TMP/cwd/map.png" ]; then
|
|
pass "default outfiles geotags.csv / map.png"
|
|
else
|
|
fail "default outfiles geotags.csv / map.png"
|
|
fi
|
|
|
|
# 7. sgeo --trip: synthetic CSV, rows out of timestamp order.
|
|
# b.jpg uses the EXIF-colon timestamp form stag's fallback passes
|
|
# through, so the sort must handle mixed ISO/EXIF formats; e.jpg has
|
|
# no timestamp and goes last; plain.jpg has no coords and is skipped.
|
|
cat > "$TMP/trip.csv" <<'EOF'
|
|
file,format,latitude,longitude,altitude,datum,timestamp,source
|
|
c.jpg,JPEG image,37.784900,-122.379400,,WGS-84,2024-05-01 10:00:00,EXIF GPS
|
|
a.jpg,JPEG image,37.774900,-122.419400,,WGS-84,2024-05-01 08:00:00,EXIF GPS
|
|
d.jpg,JPEG image,37.754900,-122.439400,,WGS-84,2024-05-01 11:00:00,EXIF GPS
|
|
b.jpg,JPEG image,37.804900,-122.409400,,WGS-84,2024:05:01 09:00:00,EXIF GPS
|
|
e.jpg,JPEG image,37.794900,-122.439400,,WGS-84,,EXIF GPS
|
|
plain.jpg,JPEG image,,,,,,
|
|
EOF
|
|
if ./sgeo --trip "$TMP/trip.csv" "$TMP/trip.png" 2>"$TMP/trip.log"; then
|
|
python3 tests/check_map.py "$TMP/trip.png" 5 >/tmp/check-trip-map.txt 2>&1 \
|
|
&& python3 tests/check_trip.py "$TMP/trip.csv" "$TMP/trip.png" >/tmp/check-trip.txt 2>&1 \
|
|
&& pass "sgeo --trip ordered polyline + time labels" \
|
|
|| { fail "sgeo --trip ordered polyline + time labels"; cat /tmp/check-trip-map.txt /tmp/check-trip.txt "$TMP/trip.log"; }
|
|
else
|
|
fail "sgeo --trip exit 0"; cat "$TMP/trip.log"
|
|
fi
|
|
|
|
# 8. sgeo --trip: single point (marker + label, no line).
|
|
cat > "$TMP/trip-one.csv" <<'EOF'
|
|
file,format,latitude,longitude,altitude,datum,timestamp,source
|
|
a.jpg,JPEG image,37.774900,-122.419400,,WGS-84,2024-05-01 08:00:00,EXIF GPS
|
|
EOF
|
|
if ./sgeo --trip "$TMP/trip-one.csv" "$TMP/trip-one.png" 2>/dev/null; then
|
|
python3 tests/check_map.py "$TMP/trip-one.png" 1 >/tmp/check-trip1.txt 2>&1 \
|
|
&& pass "sgeo --trip single point" \
|
|
|| { fail "sgeo --trip single point"; cat /tmp/check-trip1.txt; }
|
|
else
|
|
fail "sgeo --trip single point exit 0"
|
|
fi
|
|
|
|
# 9. sgeo --trip failures: no geotags, bad header, missing file.
|
|
# Each must exit non-zero, print its message, and write no file.
|
|
cat > "$TMP/trip-nogeo.csv" <<'EOF'
|
|
file,format,latitude,longitude,altitude,datum,timestamp,source
|
|
plain.jpg,JPEG image,,,,,,
|
|
EOF
|
|
printf 'not,a,stag,csv\n1,2,3\n' > "$TMP/trip-bad.csv"
|
|
trip_fail=0
|
|
./sgeo --trip "$TMP/trip-nogeo.csv" "$TMP/trip-nogeo.png" 2>"$TMP/trip-nogeo.err" && trip_fail=1
|
|
[ -e "$TMP/trip-nogeo.png" ] && trip_fail=1
|
|
grep -q "no geotagged" "$TMP/trip-nogeo.err" || trip_fail=1
|
|
./sgeo --trip "$TMP/trip-bad.csv" "$TMP/trip-bad.png" 2>"$TMP/trip-bad.err" && trip_fail=1
|
|
[ -e "$TMP/trip-bad.png" ] && trip_fail=1
|
|
grep -q "not a stag CSV" "$TMP/trip-bad.err" || trip_fail=1
|
|
./sgeo --trip "$TMP/trip-missing.csv" "$TMP/trip-missing.png" 2>/dev/null && trip_fail=1
|
|
[ -e "$TMP/trip-missing.png" ] && trip_fail=1
|
|
[ "$trip_fail" = 0 ] && pass "sgeo --trip failures (no geotags, bad header, missing file)" \
|
|
|| { fail "sgeo --trip failures"; cat "$TMP/trip-nogeo.err" "$TMP/trip-bad.err"; }
|
|
|
|
echo "stag/sgeo tests: $([ "$FAIL" = 0 ] && echo ALL PASS || echo FAILURES PRESENT)"
|
|
exit "$FAIL"
|