From d5618e30d3ec4cf5fa10599dbd9027031cd8854f Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 14 Oct 2024 11:29:00 +0200 Subject: test directory included --- .gitignore | 1 - test/Makefile | 7 +++++++ test/gentestfiles.sh | 22 ++++++++++++++++++++++ test/test_deletefiles.sh | 6 ++++++ test/test_deletefiles_tmp.sh | 6 ++++++ test/test_dirs_subdirs.sh | 10 ++++++++++ test/test_generate_delete.sh | 7 +++++++ test/test_generate_delete_tmp.sh | 7 +++++++ test/test_replace_timestamp.sh | 24 ++++++++++++++++++++++++ 9 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 test/Makefile create mode 100755 test/gentestfiles.sh create mode 100755 test/test_deletefiles.sh create mode 100755 test/test_deletefiles_tmp.sh create mode 100755 test/test_dirs_subdirs.sh create mode 100755 test/test_generate_delete.sh create mode 100755 test/test_generate_delete_tmp.sh create mode 100755 test/test_replace_timestamp.sh diff --git a/.gitignore b/.gitignore index 20883c9..ec4dd96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ tsr tsr-TESTING -test/ TODO rockyou.txt testdir/ diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..26ea1ab --- /dev/null +++ b/test/Makefile @@ -0,0 +1,7 @@ + +all: release +clean: + cd .. && make clean + +release: + cd .. && make tests diff --git a/test/gentestfiles.sh b/test/gentestfiles.sh new file mode 100755 index 0000000..d469964 --- /dev/null +++ b/test/gentestfiles.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +touch ts_file1.txt +touch ts_file2.txt +touch ts_file3.txt +touch thisfile.txt + +dd if=/dev/zero of=./1gib.img bs=1GiB count=1 # 1024 exactly, should show 1GiB on tsr -l +dd if=/dev/zero of=./1000mb.img bs=1000MB count=1 # 1000Mib should show 1000MiB on tsr -l +dd if=/dev/zero of=./1.1gib.img bs=1100MiB count=1 # 1100MiB should show 1.1 Gib on tsr -l + +dd if=/dev/zero of=./1mb.img bs=1MB count=1 # MB =/= MiB +dd if=/dev/zero of=./1mib.img bs=1MiB count=1 # 1 Mib +dd if=/dev/zero of=./500kib.img bs=500KiB count=1 # 500 Kib +dd if=/dev/zero of=./1023kib.img bs=1023KiB count=1 # 1023 Kib +dd if=/dev/zero of=./1024kib.img bs=1024KiB count=1 # 1 Mib + +dd if=/dev/zero of=./1000b.img bs=1000B count=1 +dd if=/dev/zero of=./1KiB.img bs=1KiB count=1 +dd if=/dev/zero of=./1023b.img bs=1023B count=1 +dd if=/dev/zero of=./1024b.img bs=1024B count=1 +dd if=/dev/zero of=./1KB.img bs=1KB count=1 # KB =/= KiB diff --git a/test/test_deletefiles.sh b/test/test_deletefiles.sh new file mode 100755 index 0000000..9cf917d --- /dev/null +++ b/test/test_deletefiles.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +files="1000b.img 1000mb.img 1023b.img 1023kib.img 1024b.img 1024kib.img 1.1gib.img 1gib.img 1KB.img 1KiB.img 1mb.img 1mib.img 500kib.img thisfile.txt ts_file1.txt ts_file2.txt ts_file3.txt" +options="-v" + +./tsr-TESTING $options $files diff --git a/test/test_deletefiles_tmp.sh b/test/test_deletefiles_tmp.sh new file mode 100755 index 0000000..deb070f --- /dev/null +++ b/test/test_deletefiles_tmp.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +files="1000b.img 1000mb.img 1023b.img 1023kib.img 1024b.img 1024kib.img 1.1gib.img 1gib.img 1KB.img 1KiB.img 1mb.img 1mib.img 500kib.img thisfile.txt ts_file1.txt ts_file2.txt ts_file3.txt" +options="-v -t" + +./tsr-TESTING $options $files diff --git a/test/test_dirs_subdirs.sh b/test/test_dirs_subdirs.sh new file mode 100755 index 0000000..7349272 --- /dev/null +++ b/test/test_dirs_subdirs.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +mkdir -p testdir/testdir2/testdir3/{td1,td2,td3,td4,td5} + +cd testdir +../gentestfiles.sh +cd testdir2/testdir3/td1 +../../../../gentestfiles.sh +cd ../td2 +../../../../gentestfiles.sh diff --git a/test/test_generate_delete.sh b/test/test_generate_delete.sh new file mode 100755 index 0000000..6764682 --- /dev/null +++ b/test/test_generate_delete.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +for i in {1..10} +do + ./gentestfiles.sh + ./test_deletefiles.sh +done diff --git a/test/test_generate_delete_tmp.sh b/test/test_generate_delete_tmp.sh new file mode 100755 index 0000000..0eed94c --- /dev/null +++ b/test/test_generate_delete_tmp.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +for i in {1..10} +do + ./gentestfiles.sh + ./test_deletefiles_tmp.sh +done diff --git a/test/test_replace_timestamp.sh b/test/test_replace_timestamp.sh new file mode 100755 index 0000000..ffad66e --- /dev/null +++ b/test/test_replace_timestamp.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +LOG_DIR="/home/oskar/.trashsys/log" + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +REPLACEMENT="$1" + +if [ ! -d "$LOG_DIR" ]; then + echo "Directory $LOG_DIR does not exist." + exit 1 +fi + +for file in "$LOG_DIR"/*; do + if [ -f "$file" ]; then + echo "replacing trashed time in: $file" + awk -v replacement="$REPLACEMENT" 'NR % 5 == 0 {print replacement} NR % 5 != 0 {print $0}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" + fi +done + +echo "Done." -- cgit v1.2.3