/home/uherbst/Daten/Projekte/ServDoc/servdoc/lib/testServDocpm


#!/usr/bin/perl
use English;
use Test::Unit;

use constant DEBUG => 0;

use ServDoc;

sub debug { ServDoc_debug( "COMMON", $options, shift, shift ); }

sub output_func {
  # $1: function name with all parameters

  my $func_name=shift;
  return `$EXECUTABLE_NAME -e 'use ServDoc;
                                                              sub debug { ServDoc_debug(
                                                                    "COMMON", $options, shift, shift );
					 					 };
			       			       $func_name' 2>&1`;
}

# Here the tests start

######################################################################
# report_allowed

sub test_report_allowed_1 {
  my %options;
  $options{UID}=$UID;
  assert(report_allowed(%options) eq 1,"report_allowed has a problem");
}
sub test_report_allowed_1 {
  my %options;
  $options{UID}=$UID+1;
  assert(report_allowed(%options) eq 0,"report_allowed has a problem");
}
sub test_report_allowed_3 {
  my %options;
  $options{GID}=$GID;
  assert(report_allowed(%options) eq 1,"report_allowed has a problem");
}
sub test_report_allowed_4 {
  my %options;
  $options{GID}=$GID+1;
  assert(report_allowed(%options) eq 0,"report_allowed has a problem");
}
sub test_report_allowed_5 {
  my %options;
  $options{USER}=getpwuid $UID;
  assert(report_allowed(%options) eq 1,"report_allowed has a problem");
}
sub test_report_allowed_6 {
  my %options;
  $options{USER}=sprintf("%sxxx",getpwuid $UID);
  assert(report_allowed(%options) eq 0,"report_allowed has a problem");
}
sub test_report_allowed_7 {
  my %options;
  $options{GROUP}=getgrgid $GID;
  assert(report_allowed(%options) eq 1,"report_allowed has a problem");
}
sub test_report_allowed_8 {
  my %options;
  $options{GROUP}=sprintf("%sxxx",getgrgid $GID);
  assert(report_allowed(%options) eq 0,"report_allowed has a problem");
}

######################################################################
# report_string

sub test_report_string_1 {
  assert(output_func("report_string('title','short','desc','output')")
	 eq
	 "title\%:short\%:desc\%:output\n",
	 "report_string failed");
}
sub test_report_string_2 {
  assert(output_func('report_string("title\ntitle2","short","desc","output")')
	 eq
	 "title title2\%:short\%:desc\%:output\n",
	 "report_string failed");
}

sub test_report_string_3 {
  assert(output_func
	 ('report_string("title","short","long","out",UID=>'. $UID .')')
	 eq
	 "title\%:short\%:long\%:out\n",
	 "report_string has a problem with UID-options"
	)
}
sub test_report_string_4 {
  assert(output_func
	 (sprintf('report_string("title","short","long","out",UID=>%i)',$UID+1))
	 eq
	 "",
	 "report_string has a problem with UID-options"
	)
}
sub test_report_string_5 {
  assert(output_func
	 ('report_string("title","short%text","long","out",UID=>'. $UID .')')
	 eq
	 "title\%:short\%\%text\%:long\%:out\n",
	 "report_string has a problem with Percent-Signs in text"
	)
}

sub test_find_path {
  assert(find_path("ls") eq "/bin/ls","Find Path findet kein ls");
}

my @testarray;
@{$testarray[0]}=(1,2,3);
@{$testarray[1]}=(4,5,6);
sub test_array2table {
  my $testout="_table__tr__th_1_/th__th_2_/th__th_3_/th__/tr_" .
    "_tr__td_4_/td__td_5_/td__td_6_/td__/tr__/table_\n";
  assert(array2table(@testarray) eq $testout,"array2table error")
}

sub test_byte2hrn {
  assert(byte2hrn(5763616,'K') eq "5.76G","byte2hrn error");
}
create_suite();
run_suite();
print "\n";