#!/bin/sh
#
# $RCSfile$
#
# Copyright (c) 2001-2002, Martin Blais. All rights reserved.
#
# This script is my regression tests.  Although every single time I run it i
# feel I'm doing it for nothing, almost every single time I'll find something
# that is buggy about xxdiff.  This isn't much as far as testing, but it is much
# better than nothing, and it really does help.
#

function testhdr { 
    clear
    echo "====================================================================="
    echo "TESTING:" $1
    echo "====================================================================="
}

function waitread { 
    #echo "   <press enter>" && read
    read
}

function waitexit { 
    echo "   <exit xxdiff>"
    read
}

XXDIFF=../bin/xxdiff

#-------------------------------------------------------------------------------
testhdr "Print version"

$XXDIFF --version
waitread;

#-------------------------------------------------------------------------------
testhdr "Print help"

$XXDIFF --help
waitread;

#-------------------------------------------------------------------------------
testhdr "Print help for Qt options"

$XXDIFF --help-qt
waitread;

#-------------------------------------------------------------------------------
testhdr "Print help for all options"

$XXDIFF --help-all
waitread;

#-------------------------------------------------------------------------------
testhdr "Print HTML documentation"

$XXDIFF --help-html | tee /tmp/out.html

echo "=============================="
echo "Open and check file:/tmp/out.html in your browser"
waitread;
rm -f /tmp/out.html

#-------------------------------------------------------------------------------
testhdr "Testing cmdline: no files. Should print something."

$XXDIFF
waitread;

#-------------------------------------------------------------------------------
testhdr "Testing cmdline: one file only. Should fail."

$XXDIFF mine
waitread;

#-------------------------------------------------------------------------------
testhdr "Testing cmdline: four files. Should fail."

$XXDIFF mine older yours empty
waitread;

#-------------------------------------------------------------------------------
testhdr "Testing cmdline: one directory. Should fail."

$XXDIFF dir1
waitread;

#-------------------------------------------------------------------------------
testhdr "Testing cmdline: three directories. Should fail."

$XXDIFF dir1 dir2 dir3
waitread;

#-------------------------------------------------------------------------------
testhdr "Testing cmdline: two files and one directory. Should fail."

$XXDIFF mine older dir1
waitread;

#-------------------------------------------------------------------------------
testhdr "Stat test: file that does not exist. Should fail."

$XXDIFF mine filedoesnotexist
waitread;

#-------------------------------------------------------------------------------
testhdr "Stat test: directory that does not exist. Should fail."

$XXDIFF dir1 dirdoesnotexist
waitread;


#-------------------------------------------------------------------------------
testhdr "Listing resources"

$XXDIFF --list-resources | tee /tmp/xxdiffrc
waitread;

#-------------------------------------------------------------------------------
testhdr "Opening xxdiff with output resources. There should be no warnings here."

XXDIFFRC=/tmp/xxdiffrc $XXDIFF mine mine
waitexit;
rm -f /tmp/xxdiffrc

#-------------------------------------------------------------------------------
testhdr "Testing --no-rcfile"

$XXDIFF --no-rcfile mine mine
waitexit;

#-------------------------------------------------------------------------------
testhdr "Testing --orig-xdiff"

$XXDIFF --no-rcfile --orig-xdiff mine older
waitexit;

#-------------------------------------------------------------------------------
testhdr "Normal 2-way diff"

$XXDIFF mine older
waitexit;

#-------------------------------------------------------------------------------
testhdr "Normal 3-way diff"

$XXDIFF mine older yours
waitexit;

#-------------------------------------------------------------------------------
testhdr "Normal 2-way dir. diff"

$XXDIFF dir1 dir3
waitexit;

#-------------------------------------------------------------------------------
testhdr "Normal 2-way recursive dir. diff"

$XXDIFF -r dir1 dir3
waitexit;

#-------------------------------------------------------------------------------
testhdr "3-way with auto merge"

$XXDIFF --merge mine older yours
waitexit;


#-------------------------------------------------------------------------------
testhdr "Empty files: 2-way with one empty file"

$XXDIFF empty yours
waitexit;

#-------------------------------------------------------------------------------
testhdr "Empty files: 2-way with two empty files"

$XXDIFF empty empty
waitexit;


#-------------------------------------------------------------------------------
testhdr "Empty files: 3-way with one empty file"

$XXDIFF mine empty yours
waitexit;

#-------------------------------------------------------------------------------
testhdr "Empty files: 3-way with two empty files"

$XXDIFF mine empty empty
waitexit;

#-------------------------------------------------------------------------------
testhdr "Empty files: 3-way with three empty files"

$XXDIFF empty empty empty
waitexit;

#-------------------------------------------------------------------------------
testhdr "File with incomplete line"

$XXDIFF incomplete mine
waitexit;

#-------------------------------------------------------------------------------
testhdr "Qt options (misc)"

echo "Simple cmap option"
$XXDIFF --cmap mine yours
waitexit;

echo "Simple visual option"
$XXDIFF --visual TrueColor mine yours

echo "Style option"
$XXDIFF --style=platinum mine yours
waitexit;

echo "Qt options (geometry), this should show up 400x400"
$XXDIFF --geometry 400x400 mine yours
waitexit;

#-------------------------------------------------------------------------------
testhdr "Unmerge with two files. Should fail."

$XXDIFF --unmerge unmerge/basic unmerge/contig
waitexit;

#-------------------------------------------------------------------------------
testhdr "Unmerge with one file. Should work."

$XXDIFF --unmerge unmerge/basic
waitexit;

#-------------------------------------------------------------------------------
testhdr "Unmerge3 with one file. Should work."

$XXDIFF --unmerge3 unmerge/diff3merge
waitexit;

#-------------------------------------------------------------------------------
#
# TODO
#

# ^L rendering, accents

# save as conflicts, 2, 3

# save as ifdefs, 2, 3

# test return values

