Files
drharness/tests/test_base64_encode.sh
hal9000 da919f9f6e Merge origin/master into work branch (issue #169)
Resolved merge conflicts:
- CMakeLists.txt: Added both rebase_engine/utility and base64_util sources
- src/harness.cpp: Combined Content type with proper error handling
- src/main.cpp: Merged includes, test flags, and CLI parsing
  - Renamed conflicting flags: -B→-Z (build_rebase), -T→-W (edit_prompt), -b→-K (base64_decode)
- tests/CMakeLists.txt: Added all test targets from both branches
- src/rebase_engine.cpp: Fixed to use get_content_string() for Content variant type
- Updated test files to use new flag names (-Z, -W, -K)
2026-06-15 22:52:29 +00:00

112 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# test_base64_encode.sh - Tests for base64 encoding utility
# Test 1: Basic base64 encoding
OUTPUT=$("${DRHARNESS}" -B "Hello, World!")
if [ "${OUTPUT}" != "SGVsbG8sIFdvcmxkIQ==" ]; then
echo "FAIL: base64_encode - expected 'SGVsbG8sIFdvcmxkIQ==', got '${OUTPUT}'"
exit 1
fi
# Test 2: Empty string encoding
OUTPUT=$("${DRHARNESS}" -B "")
if [ "${OUTPUT}" != "" ]; then
echo "FAIL: base64_encode empty - expected empty string, got '${OUTPUT}'"
exit 1
fi
# Test 3: Base64 decoding
OUTPUT=$("${DRHARNESS}" -K "SGVsbG8sIFdvcmxkIQ==")
if [ "${OUTPUT}" != "Hello, World!" ]; then
echo "FAIL: base64_decode - expected 'Hello, World!', got '${OUTPUT}'"
exit 1
fi
# Test 4: Round-trip encoding/decoding
ORIGINAL="Test string with special chars: !@#$%^&*()"
ENCODED=$("${DRHARNESS}" -B "${ORIGINAL}")
DECODED=$("${DRHARNESS}" -K "${ENCODED}")
if [ "${DECODED}" != "${ORIGINAL}" ]; then
echo "FAIL: round-trip - expected '${ORIGINAL}', got '${DECODED}'"
exit 1
fi
# Test 5: MIME type detection - PNG
OUTPUT=$("${DRHARNESS}" -T "png")
if [ "${OUTPUT}" != "png" ]; then
echo "FAIL: mime_type png - expected 'png', got '${OUTPUT}'"
exit 1
fi
# Test 6: MIME type detection - JPG
OUTPUT=$("${DRHARNESS}" -T "jpg")
if [ "${OUTPUT}" != "jpeg" ]; then
echo "FAIL: mime_type jpg - expected 'jpeg', got '${OUTPUT}'"
exit 1
fi
# Test 7: MIME type detection - JPEG
OUTPUT=$("${DRHARNESS}" -T "jpeg")
if [ "${OUTPUT}" != "jpeg" ]; then
echo "FAIL: mime_type jpeg - expected 'jpeg', got '${OUTPUT}'"
exit 1
fi
# Test 8: MIME type detection - GIF
OUTPUT=$("${DRHARNESS}" -T "gif")
if [ "${OUTPUT}" != "gif" ]; then
echo "FAIL: mime_type gif - expected 'gif', got '${OUTPUT}'"
exit 1
fi
# Test 9: MIME type detection - WEBP
OUTPUT=$("${DRHARNESS}" -T "webp")
if [ "${OUTPUT}" != "webp" ]; then
echo "FAIL: mime_type webp - expected 'webp', got '${OUTPUT}'"
exit 1
fi
# Test 10: MIME type detection - case insensitive (uppercase)
OUTPUT=$("${DRHARNESS}" -T "PNG")
if [ "${OUTPUT}" != "png" ]; then
echo "FAIL: mime_type PNG - expected 'png', got '${OUTPUT}'"
exit 1
fi
# Test 11: MIME type detection - with leading dot
OUTPUT=$("${DRHARNESS}" -T ".jpg")
if [ "${OUTPUT}" != "jpeg" ]; then
echo "FAIL: mime_type .jpg - expected 'jpeg', got '${OUTPUT}'"
exit 1
fi
# Test 12: MIME type detection - unknown extension defaults to png
OUTPUT=$("${DRHARNESS}" -T "xyz")
if [ "${OUTPUT}" != "png" ]; then
echo "FAIL: mime_type unknown - expected 'png', got '${OUTPUT}'"
exit 1
fi
# Test 13: Data URI generation - PNG
OUTPUT=$("${DRHARNESS}" -U "png" "SGVsbG8=")
if [ "${OUTPUT}" != "data:image/png;base64,SGVsbG8=" ]; then
echo "FAIL: data_uri png - expected 'data:image/png;base64,SGVsbG8=', got '${OUTPUT}'"
exit 1
fi
# Test 14: Data URI generation - JPG
OUTPUT=$("${DRHARNESS}" -U "jpg" "SGVsbG8=")
if [ "${OUTPUT}" != "data:image/jpeg;base64,SGVsbG8=" ]; then
echo "FAIL: data_uri jpg - expected 'data:image/jpeg;base64,SGVsbG8=', got '${OUTPUT}'"
exit 1
fi
# Test 15: Data URI generation - GIF
OUTPUT=$("${DRHARNESS}" -U "gif" "SGVsbG8=")
if [ "${OUTPUT}" != "data:image/gif;base64,SGVsbG8=" ]; then
echo "FAIL: data_uri gif - expected 'data:image/gif;base64,SGVsbG8=', got '${OUTPUT}'"
exit 1
fi
echo "All base64 encode tests passed"