aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/400-expected_backup_output.binbin0 -> 1560 bytes
-rw-r--r--tests/400-successful-backup-restore.sh56
-rw-r--r--tests/assert.sh15
3 files changed, 71 insertions, 0 deletions
diff --git a/tests/400-expected_backup_output.bin b/tests/400-expected_backup_output.bin
new file mode 100644
index 0000000..10a3993
--- /dev/null
+++ b/tests/400-expected_backup_output.bin
Binary files differ
diff --git a/tests/400-successful-backup-restore.sh b/tests/400-successful-backup-restore.sh
new file mode 100644
index 0000000..ce5949a
--- /dev/null
+++ b/tests/400-successful-backup-restore.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+source ./assert.sh
+
+PROGRAM_EXEC="$1"
+
+function files_are_the_same()
+{
+ [ -z "$(diff "$1" "$2")" ]
+}
+
+rm -f input backedup_input ref out
+
+# Create a four-sector reference file (the original file)
+dd if=/dev/zero of=ref bs=512 count=4 1>/dev/null 2>&1
+
+# Change the orignal file to make it an input file for differential backup
+# There will be four different sectors in the input file
+cp ref input
+
+# The first sector will have the 0th byte chaged
+printf '\xFF' | dd of=input bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1
+
+# The second sector will have no changes
+
+# The third sector will have the last byte changed
+printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 3) - 1 )) conv=notrunc 1>/dev/null 2>&1
+
+# The fourth sector will have the middle byte changed
+printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 4) - (512 / 2) )) conv=notrunc 1>/dev/null 2>&1
+
+assert_success $PROGRAM_EXEC -s 512 input ref out
+
+if ! files_are_the_same out 400-expected_backup_output.bin; then
+ echo "assert: Backup output file differs from the expected one"
+ exit 1
+fi
+
+# Modify the file to backup (the input file used in the backup phase)
+cp input backedup_input
+cp ref input
+if ! files_are_the_same ref input; then
+ echo "assert: The input file must be the same as the reference one before restoring it"
+ exit 1
+fi
+
+assert_success $PROGRAM_EXEC -s 512 out input
+
+if ! files_are_the_same input backedup_input; then
+ echo "assert: Cannot restore the backup"
+ exit 1
+fi
+
+rm -f input backedup_input ref out
+
+exit 0
diff --git a/tests/assert.sh b/tests/assert.sh
index ba73f41..73b5dd4 100644
--- a/tests/assert.sh
+++ b/tests/assert.sh
@@ -17,3 +17,18 @@ function assert_error()
exit 1
fi
}
+
+function assert_success()
+{
+ actual_stderr="$("$@" 2>&1 1>/dev/null)"
+ retval=$?
+
+ if [ $retval -ne 0 ]; then
+ echo "assert_error: Return value is $retval, expected 0"
+ exit 1
+ elif [ -n "$actual_stderr" ]; then
+ echo "assert_error: stderr is not empty"
+ echo " actual: $actual_stderr"
+ exit 1
+ fi
+}