#! /usr/bin/perl
#
# Copyright (c) 2004-2007 - Consultas, PKG.fr
#
# This file is part of A2P.
#
# A2P is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# A2P is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with A2P; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# $Id: e-adresse.pl 3 2007-10-18 16:20:19Z g $
#

use strict ;
use Test ;

require 'test/A2P/Defaults.pm' ;

use warnings FATAL => qw(void);

BEGIN {
    plan
        tests  => 7,
        onfail => sub { exit(1) }
}

$| = 1 ;

$ENV{JOB} = "TEST-JOB-EADRESSE" ;

my $script = "LANG=C EADRESSE_CONF=test perl e-adresse.pl" ;
# We should start the script in each possible mode with a test file

# A simple call must fail as script is expecting something to do
ok system( $script);
# A call with a bad file must fail, also if more than 2 args are given
ok system( $script . ' test/e-adresse-good.xml' );
ok system( $script . ' test/e-adresse-good.xml test/e-adresse-a2p.xml' );

# A call with a right formatted file must return 0
my $mail = '/tmp/e-adresse.txt' ;
unlink $mail if -s $mail ;
ok ! system( $script . ' test/e-adresse-a2p.xml' );
ok -s $mail ;
unlink $mail if -s $mail ;
ok ! system( 'cat test/e-adresse-a2p.xml | ' . $script );
ok -s $mail ;
