# Process with autom4te to create an -*- Autotest -*- test suite.

AT_INIT([dds-test])
# AT_COPYRIGHT([])

#AT_TESTED([dds-test])

AT_ARG_OPTION_ARG([baselines],
    [--baselines=yes|no   Build the baseline file for parser test 'arg'],
    [echo "baselines set to $at_arg_baselines";
     baselines=$at_arg_baselines],[baselines=])

# Usage: _AT_TEST_*(<dds source>, <baseline file>, [xfail|xpass])

m4_define([_AT_DDS_TEST],   
[
    # AT_BANNER([Test $1 $2])
    AT_SETUP([DDS $1])
    AT_KEYWORDS([dds])
    
    input=$1
    baseline=$2
    
    AS_IF([test -n "$baselines" -a x$baselines = xyes],
        [
        # The --baselines=yes option works only for tests that write to stdout
        AT_CHECK([$abs_builddir/dds-test -p < $input || true], [0], [stdout], [ignore])
        AT_CHECK([mv stdout $baseline.tmp])
        ],
        [        
        # Added '|| true' to ensure the command returns '0'
        AT_CHECK([$abs_builddir/dds-test -p < $input || true], [0], [stdout], [stderr])
        # Need to compare either stdout or stderr
        AT_CHECK([diff -b -B $baseline stdout || diff -b -B $baseline stderr], [0], [ignore])
        AT_XFAIL_IF([test "$3" = "xfail"])
        ])
        
    AT_CLEANUP
])

m4_define([AT_DDS_RESPONSE_TEST],
[
    # AT_BANNER([DDS response for $1.])
    _AT_DDS_TEST([$abs_srcdir/dds-testsuite/$1], [$abs_srcdir/dds-testsuite/$1.base], $2)
])


AT_DDS_RESPONSE_TEST([3B42.980909.5.hacked.HDF.das.dds])
AT_DDS_RESPONSE_TEST([3B42.980909.5.HDF.das.dds])
AT_DDS_RESPONSE_TEST([3B42.980909.5.HDF.dds])
AT_DDS_RESPONSE_TEST([AsciiOutputTest1.dds])
AT_DDS_RESPONSE_TEST([fnoc1.nc.das.dds])
AT_DDS_RESPONSE_TEST([fnoc1.nc.dds])
AT_DDS_RESPONSE_TEST([S2000415.HDF.das.dds])
AT_DDS_RESPONSE_TEST([S2000415.HDF.dds])
AT_DDS_RESPONSE_TEST([test.1.dds])
AT_DDS_RESPONSE_TEST([test.10.dds])
AT_DDS_RESPONSE_TEST([test.11.dds])
AT_DDS_RESPONSE_TEST([test.12.dds])
AT_DDS_RESPONSE_TEST([test.13.dds])
AT_DDS_RESPONSE_TEST([test.14.dds])
AT_DDS_RESPONSE_TEST([test.15.dds])
AT_DDS_RESPONSE_TEST([test.16.dds])
AT_DDS_RESPONSE_TEST([test.17.dds])
AT_DDS_RESPONSE_TEST([test.18.dds])
AT_DDS_RESPONSE_TEST([test.19.dds])
AT_DDS_RESPONSE_TEST([test.19b.das.dds])
AT_DDS_RESPONSE_TEST([test.19b.dds])
AT_DDS_RESPONSE_TEST([test.2.dds])
AT_DDS_RESPONSE_TEST([test.20.dds])
AT_DDS_RESPONSE_TEST([test.3.dds])
AT_DDS_RESPONSE_TEST([test.4.dds])
AT_DDS_RESPONSE_TEST([test.6.dds])
AT_DDS_RESPONSE_TEST([test.7.dds])
AT_DDS_RESPONSE_TEST([test.8.dds])
AT_DDS_RESPONSE_TEST([test.9.dds])

# Added these to test zero-length arrays

AT_DDS_RESPONSE_TEST([test.21.dds])
AT_DDS_RESPONSE_TEST([test.22.dds])
AT_DDS_RESPONSE_TEST([test.23.dds])
AT_DDS_RESPONSE_TEST([test.24.dds], [xpass])

# Empty Structures
AT_DDS_RESPONSE_TEST([test.25.dds], [xpass])
AT_DDS_RESPONSE_TEST([test.26.dds], [xpass])

