#!/bin/bash

# Copyright (C) 2010 Karel Zak <kzak@redhat.com>

TS_TOPDIR="${0%/*}/../.."
TS_DESC="tab files"

. $TS_TOPDIR/functions.sh
ts_init "$*"

TESTPROG="$TS_HELPER_LIBMOUNT_TAB"

[ -x $TESTPROG ] || ts_skip "test not compiled"

ts_init_subtest "parse-fstab"
ts_run $TESTPROG --parse "$TS_SELF/files/fstab" &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "parse-fstab-full"
ts_run $TESTPROG --parse "$TS_SELF/files/fstab.comment" --comments &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "parse-mtab"
ts_run $TESTPROG --parse "$TS_SELF/files/mtab" &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "parse-fstab-broken"
ts_run $TESTPROG --parse "$TS_SELF/files/fstab.broken" &> $TS_OUTPUT
sed -i -e 's/.*fstab.broken:[[:digit:]]*: parse error//g; s/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "parse-mountinfo"
ts_run $TESTPROG --parse "$TS_SELF/files/mountinfo" &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "parse-mountinfo-nosrc"
ts_run $TESTPROG --parse "$TS_SELF/files/mountinfo_nosrc" &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "parse-swaps"
ts_run $TESTPROG --parse "$TS_SELF/files/swaps" &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "copy"
ts_run $TESTPROG --copy-fs "$TS_SELF/files/fstab" &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "find-source"
ts_run $TESTPROG --find-forward "$TS_SELF/files/fstab" source UUID=fef7ccb3-821c-4de8-88dc-71472be5946f &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "find-target"
ts_run $TESTPROG --find-forward "$TS_SELF/files/fstab" target /home/foo &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "find-target2"
ts_run $TESTPROG --find-forward "$TS_SELF/files/fstab" target /any/foo &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "find-target3"
ts_run $TESTPROG --find-forward "$TS_SELF/files/fstab" target /any/foo/ &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "find-pair"
ts_run $TESTPROG --find-pair "$TS_SELF/files/mtab" /dev/mapper/kzak-home /home/kzak &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_init_subtest "find-fs"
ts_run $TESTPROG --find-fs "$TS_SELF/files/mountinfo" /home/kzak &> $TS_OUTPUT
sed -i -e 's/fs: 0x.*/fs:/g' $TS_OUTPUT
ts_finalize_subtest

ts_finalize
