1{ 2 image, 3 method, 4 invisible-watermark, 5 runCommand, 6 testName, 7 withOnnx, 8}: 9 10# This file runs one test case. 11# There are six test cases in total. method can have three possible values and 12# withOnnx two possible values. 3 * 2 = 6. 13# 14# The case where the method is rivaGan and invisible-watermark is built 15# without onnx is expected to fail and this case is handled accordingly. 16# 17# The test works by first encoding a message into a test image, 18# then decoding the message from the image again and checking 19# if the message was decoded correctly. 20 21let 22 message = 23 if method == "rivaGan" then 24 "asdf" # rivaGan only supports 32 bits 25 else 26 "fnörd1"; 27 length = (builtins.stringLength message) * 8; 28 invisible-watermark' = invisible-watermark.override { inherit withOnnx; }; 29 expected-exit-code = if method == "rivaGan" && !withOnnx then "1" else "0"; 30in 31runCommand "invisible-watermark-test-${testName}" { nativeBuildInputs = [ invisible-watermark' ]; } 32 '' 33 set +e 34 invisible-watermark \ 35 --verbose \ 36 --action encode \ 37 --type bytes \ 38 --method '${method}' \ 39 --watermark '${message}' \ 40 --output output.png \ 41 '${image}' 42 exit_code="$?" 43 set -euf -o pipefail 44 if [ "$exit_code" != '${expected-exit-code}' ]; then 45 echo "Exit code of invisible-watermark was $exit_code while ${expected-exit-code} was expected." 46 exit 1 47 fi 48 if [ '${expected-exit-code}' == '1' ]; then 49 echo 'invisible-watermark failed as expected.' 50 touch "$out" 51 exit 0 52 fi 53 decoded_message="$(invisible-watermark \ 54 --action decode \ 55 --type bytes \ 56 --method '${method}' \ 57 --length '${toString length}' \ 58 output.png \ 59 )" 60 61 if [ '${message}' != "$decoded_message" ]; then 62 echo "invisible-watermark did not decode the watermark correctly." 63 echo "The original message was ${message} but the decoded message was $decoded_message." 64 exit 1 65 fi 66 touch "$out" 67 ''