File:  [LON-CAPA] / loncom / cfgedittests / new.t
Revision 1.2: download - view: text, annotated - select for diffs
Tue Nov 25 12:15:35 2003 UTC (20 years, 4 months ago) by foxr
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_X, version_1_2_99_1, version_1_2_99_0, version_1_2_1, version_1_2_0, version_1_1_X, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, GCI_1, BZ5971-printing-apage, BZ5434-fox, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
Bring back into the mainl-line from whatever branching hell import decided
to put them in.

    1: #
    2: # $Id: new.t,v 1.2 2003/11/25 12:15:35 foxr Exp $
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: 
   27: 
   28: #  Test new functionality of ConfigFileEditor::new
   29: #
   30: 
   31: use strict;
   32: use Test;
   33: use ConfigFileEdit;
   34: 
   35: 
   36: #
   37: #   Tests  we plan are:
   38: #     Check open failure
   39: #     Check open success
   40: #     Check read ok for config files.
   41: #     Check parse/index ok for config files.
   42: #
   43: 
   44: BEGIN {plan tests => 4}
   45: 
   46: 
   47: #
   48: #  Test opens that should fail (file not found in this case).
   49: sub TestOpenFail {
   50:     my $editor = ConfigFileEdit->new("nosuchfile.cfg",0);
   51:     ok($editor, undef);
   52: }
   53: #
   54: #  Test opens that should succeed (in this case we have a test configfile
   55: #  in this directory called test.cfg
   56: #
   57: sub TestOpenOk {
   58:     my $editor  = ConfigFileEdit->new("testconfig.cfg",0);
   59:     if($editor) {
   60: 	ok(1);
   61:     } else {
   62: 	ok(0);
   63:     }
   64: 
   65: }
   66: 
   67: #
   68: #  Test that we can read the file as a line array stored in the hash.
   69: #
   70: sub TestReadOk {
   71:     my $editor = ConfigFileEdit->new("testconfig.cfg",0);
   72: 
   73:     # How many lines in the file?
   74: 
   75:     open(WCOUT, "wc -l testconfig.cfg |");
   76:     my $output = <WCOUT>;	# Output of linecount
   77:     chomp($output);
   78:     $output    =~ s/ +/ /g;	# Get rid of multiple spaces so that...
   79:     my ($trash, $linecount, $junk) = split(/ /,$output); # We can extract the count.
   80:     close(WCOUT);
   81: 
   82:     #  How many lines in the editor linecount array?
   83: 
   84:     my $editorlines = ($editor->{LineArray});
   85:     my $editorlinecount = @$editorlines;
   86:     
   87:     ok($linecount, $editorlinecount);
   88: 
   89: 
   90: }
   91: 
   92: sub TestParseOk {
   93:     my $editor = ConfigFileEdit->new("testconfig.cfg",0);
   94: 
   95:     #
   96:     #  There should be a line in the file hash for the key line1
   97:     #  It should index to line 0. which should match the first line
   98:     #  of the file.
   99:     #  There should only be 1 non-comment line in the file.
  100: 
  101:     my $LineIndex = $editor->{KeyToLines}; # Get the key to line hash.
  102:     if (! defined $LineIndex->{line1}) {
  103: 	ok(0);
  104: 	print (" No index for 'line1'\n");
  105: 	my @keynames = keys %$LineIndex;
  106: 	return;
  107:     }
  108: 
  109:     my $linesubscript = $LineIndex->{line1}; 
  110:     if(!defined($linesubscript) || ($linesubscript != 0)) {
  111: 	ok(0,$linesubscript);
  112: 	print("Subscript for 'line1' <> 0\n");
  113: 	return;
  114:     }
  115: 
  116:     my $editorlines   = $editor->{LineArray};
  117:     my $editorline    = $editorlines->[$linesubscript];
  118:     
  119:     open(FILE, "< testconfig.cfg");
  120:     my $firstline = <FILE>;
  121:     chomp($firstline);
  122:     if($firstline ne $editorline) {
  123: 	ok($firstline, $editorline);
  124: 	return;
  125: 
  126:     }
  127: 
  128: 
  129:     ok(1, scalar(keys %$LineIndex));
  130: 
  131: 
  132: }
  133: 
  134: TestOpenFail;
  135: TestOpenOk;
  136: TestReadOk;
  137: TestParseOk;
  138: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>