Files
drharness/tests/test_image_url.sh
hal9000 0ca0305ebf feat: Add ImageUrl struct and image_url support to ContentPart (#152)
- Add ImageUrl struct with url and detail fields
- Extend ContentPart with optional text and image_url fields
- Add std::optional serialization/deserialization support
- Custom to_json for ContentPart that only serializes relevant fields
- Custom json_to<ContentPart> for proper deserialization
- Add test_image_url.sh with comprehensive tests
- All 30 tests pass
2026-06-12 07:17:08 -05:00

75 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# test_image_url.sh - Tests for ImageUrl and ContentPart with image_url support
# Test ImageUrl deserialization with url and detail fields
OUTPUT=$("${DRHARNESS}" -R ImageUrl '{"url": "data:image/png;base64,abc123", "detail": "auto"}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ImageUrl with url and detail - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ImageUrl deserialization with only url field (detail should default to "auto")
OUTPUT=$("${DRHARNESS}" -R ImageUrl '{"url": "https://example.com/image.png"}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ImageUrl with only url - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ImageUrl deserialization with empty object (should use defaults)
OUTPUT=$("${DRHARNESS}" -R ImageUrl '{}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ImageUrl empty object - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ContentPart with text type
OUTPUT=$("${DRHARNESS}" -R ContentPart '{"type": "text", "text": "Hello world"}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ContentPart with text type - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ContentPart with text type and only type field (text should be optional)
OUTPUT=$("${DRHARNESS}" -R ContentPart '{"type": "text"}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ContentPart with only type text - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ContentPart with image_url type
OUTPUT=$("${DRHARNESS}" -R ContentPart '{"type": "image_url", "image_url": {"url": "data:image/png;base64,abc123", "detail": "auto"}}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ContentPart with image_url type - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ContentPart with image_url type and minimal image_url (only url)
OUTPUT=$("${DRHARNESS}" -R ContentPart '{"type": "image_url", "image_url": {"url": "https://example.com/image.png"}}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ContentPart with minimal image_url - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ContentPart with empty object (should use defaults)
OUTPUT=$("${DRHARNESS}" -R ContentPart '{}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ContentPart empty object - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ContentPart with image_url type and detail "low"
OUTPUT=$("${DRHARNESS}" -R ContentPart '{"type": "image_url", "image_url": {"url": "data:image/png;base64,abc", "detail": "low"}}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ContentPart with image_url detail low - expected 'success', got '${OUTPUT}'"
exit 1
fi
# Test ContentPart with image_url type and detail "high"
OUTPUT=$("${DRHARNESS}" -R ContentPart '{"type": "image_url", "image_url": {"url": "data:image/png;base64,abc", "detail": "high"}}')
if [ "${OUTPUT}" != "success" ]; then
echo "FAIL: ContentPart with image_url detail high - expected 'success', got '${OUTPUT}'"
exit 1
fi
echo "All ImageUrl and ContentPart tests passed!"