diff --git a/tests/scripts/2.3.2_get_files_v2.sh b/tests/scripts/2.3.2_get_files_v2.sh index 46d68fa..b87480e 100755 --- a/tests/scripts/2.3.2_get_files_v2.sh +++ b/tests/scripts/2.3.2_get_files_v2.sh @@ -11,4 +11,6 @@ files=( '資料夾 2/子資料夾 2/文字檔案 8.txt' ) -. scripts/common/2.3.x_get_files_v2.sh +proto="$PROTO_V2" + +. scripts/common/x.3.x_get_files.sh diff --git a/tests/scripts/2.3.3_get_files_v2.sh b/tests/scripts/2.3.3_get_files_v2.sh index b3955e6..8d8d8fd 100755 --- a/tests/scripts/2.3.3_get_files_v2.sh +++ b/tests/scripts/2.3.3_get_files_v2.sh @@ -12,4 +12,6 @@ files=( 'sub_2/subsub/empty/' ) -. scripts/common/2.3.x_get_files_v2.sh +proto="$PROTO_V2" + +. scripts/common/x.3.x_get_files.sh diff --git a/tests/scripts/2.3_get_files_v2.sh b/tests/scripts/2.3_get_files_v2.sh index 0a55d91..bc76519 100755 --- a/tests/scripts/2.3_get_files_v2.sh +++ b/tests/scripts/2.3_get_files_v2.sh @@ -11,4 +11,6 @@ files=( 'sub 1/subsub_2/file_8.txt' ) -. scripts/common/2.3.x_get_files_v2.sh +proto="$PROTO_V2" + +. scripts/common/x.3.x_get_files.sh diff --git a/tests/scripts/3.3.1_get_files_v3.sh b/tests/scripts/3.3.1_get_files_v3.sh new file mode 100755 index 0000000..625f298 --- /dev/null +++ b/tests/scripts/3.3.1_get_files_v3.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +proto="$PROTO_V3" + +. scripts/common/x.3.1_get_files.sh diff --git a/tests/scripts/3.3.2_get_files_v3.sh b/tests/scripts/3.3.2_get_files_v3.sh new file mode 100755 index 0000000..9613741 --- /dev/null +++ b/tests/scripts/3.3.2_get_files_v3.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +files=( + '文字檔案 1.txt' + '另一個文件_2.txt' + '資料夾_1/文字檔案 3.txt' + '資料夾_1/另一個文件 4.txt' + '資料夾 2/文字檔案 5.txt' + '資料夾 2/子資料夾/文字檔案 6.txt' + '資料夾 2/子資料夾/另一個文件_7.txt' + '資料夾 2/子資料夾 2/文字檔案 8.txt' + '資料夾 2/資料夾 1/' + '資料夾_3/' +) + +proto="$PROTO_V3" + +. scripts/common/x.3.x_get_files.sh diff --git a/tests/scripts/3.3_get_files_v3.sh b/tests/scripts/3.3_get_files_v3.sh new file mode 100755 index 0000000..3572777 --- /dev/null +++ b/tests/scripts/3.3_get_files_v3.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +files=( + 'file 1.txt' + 'file_2.txt' + 'empty/' + 'sub/file 3.txt' + 'sub 1/empty dir/' + 'sub 1/file 4.txt' + 'sub 1/subsub/empty/' + 'sub 1/subsub/file 5.txt' + 'sub_2/subsub/empty/' +) + +proto="$PROTO_V3" + +. scripts/common/x.3.x_get_files.sh diff --git a/tests/scripts/3.7.1_get_screenshot_v3.sh b/tests/scripts/3.7.1_get_screenshot_v3.sh new file mode 100755 index 0000000..f52a970 --- /dev/null +++ b/tests/scripts/3.7.1_get_screenshot_v3.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +proto="$PROTO_V3" +method="$METHOD_GET_SCREENSHOT" +disp_num=30000 # not existing display +disp="$(printf '%016x' $disp_num)" +if [ "$DETECTED_OS" = 'Linux' ]; then + DISPLAY_ACK="$METHOD_OK" +else + DISPLAY_ACK="$METHOD_NO_DATA" +fi + +copy_image "$imgSample" + +. scripts/common/get_screenshot.sh diff --git a/tests/scripts/3.7_get_screenshot_v3.sh b/tests/scripts/3.7_get_screenshot_v3.sh index a40aa45..d046596 100755 --- a/tests/scripts/3.7_get_screenshot_v3.sh +++ b/tests/scripts/3.7_get_screenshot_v3.sh @@ -4,6 +4,7 @@ proto="$PROTO_V3" method="$METHOD_GET_SCREENSHOT" disp_num=1 disp="$(printf '%016x' $disp_num)" +DISPLAY_ACK="$METHOD_OK" copy_image "$imgSample" diff --git a/tests/scripts/common/get_screenshot.sh b/tests/scripts/common/get_screenshot.sh index c47ad26..e3374f0 100755 --- a/tests/scripts/common/get_screenshot.sh +++ b/tests/scripts/common/get_screenshot.sh @@ -20,12 +20,15 @@ fi responseDump="${responseDump:len_expected_header}" if [ ! -z "$disp" ]; then - if [ "${responseDump::2}" != "$METHOD_OK" ]; then + if [ "${responseDump::2}" != "$DISPLAY_ACK" ]; then showStatus info 'Incorrect display ack.' - echo 'Expected:' "$METHOD_OK" + echo 'Expected:' "$DISPLAY_ACK" echo 'Received:' "${responseDump::2}" exit 1 fi + if [ "$DISPLAY_ACK" = "$METHOD_NO_DATA" ]; then + exit 0 + fi responseDump="${responseDump:2}" fi diff --git a/tests/scripts/common/2.3.x_get_files_v2.sh b/tests/scripts/common/x.3.x_get_files.sh similarity index 74% rename from tests/scripts/common/2.3.x_get_files_v2.sh rename to tests/scripts/common/x.3.x_get_files.sh index b2b03ad..96071df 100755 --- a/tests/scripts/common/2.3.x_get_files_v2.sh +++ b/tests/scripts/common/x.3.x_get_files.sh @@ -13,28 +13,13 @@ for f in "${files[@]}"; do fi done -chunks='' -fileCount=0 - -appendToChunks() { - fname="$1" - if [ -d "$fname" ]; then - for f in "$fname"/*; do - appendToChunks "$f" - done - elif [ -f "$fname" ]; then - printf -v _ '%s%n' "$fname" utf8nameLen - nameLength="$(printf '%016x' $utf8nameLen)" - fileSize=$(printf '%016x' $(stat -c '%s' "$fname")) - content=$(cat "$fname" | bin2hex | tr -d '\n') - chunks+="${nameLength}$(echo -n "$fname" | bin2hex)${fileSize}${content}" - fileCount="$((fileCount + 1))" - fi -} - -for f in *; do - appendToChunks "$f" -done +regFileCount="$(find . -type f | wc -l)" +if [ "$proto" -gt "$PROTO_V2" ]; then + emptyDirCount="$(find . -type d -empty | wc -l)" + fileCount="$((regFileCount + emptyDirCount))" +else + fileCount="$regFileCount" +fi cd .. @@ -43,7 +28,6 @@ file_list=(original/*) shopt -u nullglob copy_files "${file_list[@]}" -proto="$PROTO_V2" method="$METHOD_GET_FILES" responseDump=$(echo -n "${proto}${method}" | hex2bin | client_tool) @@ -79,6 +63,11 @@ for _ in $(seq "$fileCount"); do showStatus info "File is too large. size=${fileSize}." exit 1 fi + if [ "$proto" -gt "$PROTO_V2" ] && [ "$fileSize" = '-1' ]; then + mkdir -p "$fileName" + body="${body:16}" + continue + fi if [[ $fileName == */* ]]; then mkdir -p "${fileName%/*}" fi @@ -94,7 +83,7 @@ fi cd .. # Proto v2 does not get empty directories -find original -depth -type d -empty -delete +[ "$proto" -gt "$PROTO_V2" ] || find original -depth -type d -empty -delete diffOutput=$(diff -rq original copies 2>&1 || echo failed) if [ ! -z "$diffOutput" ]; then