Imported Robodoc.
[robodoc.git] / Source / Test / nosort_test.pl
1 #!/usr/bin/perl -w
2 #
3 #
4 # $Id: nosort_test.pl,v 1.2 2004/06/20 09:24:36 gumpu Exp $
5 #
6
7 use strict;
8 use warnings;
9 use ROBOTest;
10 use IO::File;
11
12 #****x* SystemTest/nosort_test_pl
13 # FUNCTION
14 #   ROBODoc sorts the TOC and the headers so that they appear in
15 #   a particular order in the documentation.
16 #   Here we test if the order is the order we expect.
17 #   This is done by generating the documentation and comparing
18 #   the order with a table.  There are two source files, one
19 #   that is already sorted, and one that is unsorted.
20 #   The documentation for both should end up sorted.
21 # SOURCE
22 #
23
24
25 ROBOTest::start("Sort Test");
26
27 # in the documentation for the sorted file when
28 # it is sorted the TOC should look like this.
29 my @toc_sorted_names = qw(
30     AA_Header/BB_header
31     BB_header/aaa_function
32     BB_header/bbb_function
33     BB_header/ccc_function
34 );
35
36 my @toc_unsorted_names = qw(
37     XX_Header/ZZ_Header
38     XX_Header/AA_Header
39     ZZ_Header/DD_Header
40     AA_Header/CC_header
41     CC_header/ccc_function
42     DD_header/aaa_function
43     CC_header/aaa_function
44     CC_header/fff_function
45     CC_header/eee_function
46 );
47
48
49 sub check_toc_order {
50     my $ok = 1;
51     my $filename = shift;  # filename of the file with the headers
52     my $order    = shift;  # order of the headers
53     my $number   = shift;  # number of headers
54     my $file = IO::File->new("<$filename") or die;
55     my $index = 0;
56     while( my $line = <$file> ) {
57         if ( $line =~ m/robo\d+">([^<]+)</ ) {
58             my $name = $1;
59             if ( $name eq ${$order}[ $index ] ) {
60                 # All is OK.
61             } else {
62                 $ok = 0;
63             }
64             ++$index;
65             last if ( $index == $number );
66         }
67     }
68     $file->close();
69
70     return $ok;
71 }
72
73 ROBOTest::assertFile("Doc1/sorted_c.html");
74 ROBOTest::assert( 
75     check_toc_order( "Doc1/sorted_c.html", \@toc_sorted_names, 4 ),
76     "Is the TOC still sorted"
77 );
78
79 ROBOTest::assertFile("Doc1/unsorted_c.html");
80 ROBOTest::assert( 
81     check_toc_order( "Doc1/unsorted_c.html", \@toc_unsorted_names, 4 ),
82     "Is the TOC now sorted"
83 );
84
85 ROBOTest::finish;
86
87 #****
88