Skip to content

Commit

Permalink
Add tests for v3 get files
Browse files Browse the repository at this point in the history
  • Loading branch information
thevindu-w committed May 17, 2024
1 parent 38737c3 commit a071d63
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 29 deletions.
4 changes: 3 additions & 1 deletion tests/scripts/2.3.2_get_files_v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion tests/scripts/2.3.3_get_files_v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion tests/scripts/2.3_get_files_v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions tests/scripts/3.3.1_get_files_v3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

proto="$PROTO_V3"

. scripts/common/x.3.1_get_files.sh
18 changes: 18 additions & 0 deletions tests/scripts/3.3.2_get_files_v3.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tests/scripts/3.3_get_files_v3.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/scripts/3.7.1_get_screenshot_v3.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/scripts/3.7_get_screenshot_v3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 5 additions & 2 deletions tests/scripts/common/get_screenshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a071d63

Please sign in to comment.