#!/bin/sh
# PCP QA Test No. 632
# Checkout src/timeshift.
#
# Copyright (c) 2018 Ken McDonell.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=1	# failure is the default!
$sudo rm -rf $tmp $tmp.* $seq.full
trap "_cleanup; exit \$status" 0 1 2 3 15

# real QA test starts here

# archives/vldb-disks label -z
#	commencing Tue Jul 22 20:39:50.357184 1997
# Note use -d to src/timeshift because all out test cases are in
# North American daylight saving time.
#

echo "=== +1 year expect +`expr 365 \* 24` ==="
delta=`src/timeshift -dv -z -a archives/vldb-disks "Jul 22 20:39:50 1998"`
echo $delta
echo "--- pmlogrewite check ---"
cat <<End-of-File >$tmp.config
GLOBAL {
    time -> $delta
}
End-of-File
rm -f $tmp.0 $tmp.meta $tmp.index
pmlogrewrite -c $tmp.config archives/vldb-disks $tmp
pmdumplog -l -z $tmp | grep commencing

echo
echo "=== -1 year expect -`expr 365 \* 24` ==="
delta=`src/timeshift -dv -z -a archives/vldb-disks "Jul 22 20:39:50 1996"`
echo $delta
echo "--- pmlogrewite check ---"
cat <<End-of-File >$tmp.config
GLOBAL {
    time -> $delta
}
End-of-File
rm -f $tmp.0 $tmp.meta $tmp.index
pmlogrewrite -c $tmp.config archives/vldb-disks $tmp
pmdumplog -l -z $tmp | grep commencing

echo "=== +1 month expect +`expr 31 \* 24` ==="
delta=`src/timeshift -dv -z -a archives/vldb-disks "Aug 22 20:39:50 1997"`
echo $delta
echo "--- pmlogrewite check ---"
cat <<End-of-File >$tmp.config
GLOBAL {
    time -> $delta
}
End-of-File
rm -f $tmp.0 $tmp.meta $tmp.index
pmlogrewrite -c $tmp.config archives/vldb-disks $tmp
pmdumplog -l -z $tmp | grep commencing

echo
echo "=== -1 month expect -`expr 30 \* 24` ==="
delta=`src/timeshift -dv -z -a archives/vldb-disks "Jun 22 20:39:50 1997"`
echo $delta
echo "--- pmlogrewite check ---"
cat <<End-of-File >$tmp.config
GLOBAL {
    time -> $delta
}
End-of-File
rm -f $tmp.0 $tmp.meta $tmp.index
pmlogrewrite -c $tmp.config archives/vldb-disks $tmp
pmdumplog -l -z $tmp | grep commencing

echo
echo "+++ YYYYDDMM.HH.MM-NN format checks +++"

echo "=== back to start of day expect -20:39: (approx) ==="
delta=`src/timeshift -dv -z -a archives/vldb-disks "19970722"`
echo $delta
echo "--- pmlogrewite check ---"
cat <<End-of-File >$tmp.config
GLOBAL {
    time -> $delta
}
End-of-File
rm -f $tmp.0 $tmp.meta $tmp.index
pmlogrewrite -c $tmp.config archives/vldb-disks $tmp
pmdumplog -l -z $tmp | grep commencing

echo
echo "=== +1 day expect +24 (approx) ==="
delta=`src/timeshift -dv -z -a archives/vldb-disks "19970723.20.39"`
echo $delta
echo "--- pmlogrewite check ---"
cat <<End-of-File >$tmp.config
GLOBAL {
    time -> $delta
}
End-of-File
rm -f $tmp.0 $tmp.meta $tmp.index
pmlogrewrite -c $tmp.config archives/vldb-disks $tmp
pmdumplog -l -z $tmp | grep commencing

echo
echo "=== -1 hour expect -1 (approx) ==="
delta=`src/timeshift -dv -z -a archives/vldb-disks "19970722.19.39-00"`
echo $delta
echo "--- pmlogrewite check ---"
cat <<End-of-File >$tmp.config
GLOBAL {
    time -> $delta
}
End-of-File
rm -f $tmp.0 $tmp.meta $tmp.index
pmlogrewrite -c $tmp.config archives/vldb-disks $tmp
pmdumplog -l -z $tmp | grep commencing

# success, all done
status=0
exit
