Imported Robodoc.
[robodoc.git] / Source / unittest.c
1 /*
2 Copyright (C) 1994-2007  Frans Slothouber, Jacco van Weert, Petteri Kettunen,
3 Bernd Koesling, Thomas Aglassinger, Anthon Pang, Stefan Kost, David Druffner,
4 Sasha Vasko, Kai Hofmann, Thierry Pierron, Friedrich Haase, and Gergely Budai.
5
6 This file is part of ROBODoc
7
8 ROBODoc 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 3 of the License, or
11 (at your option) any later version.
12
13 This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 */
22
23 #include <stdlib.h>
24 #include <assert.h>
25 #include <stdio.h>
26 #include "document.h"
27 #include "file.h"
28 #include "path.h"
29 #include "part.h"
30 #include "directory.h"
31 #include "globals.h"
32 #include "robodoc.h"
33 #include "generator.h"
34 #include "analyser.h"
35
36 int                 test_document(  );
37 int                 test_directory(  );
38 int                 test_file(  );
39
40 /*
41  The output of this programmed if diffed with a reference
42  file to see if robodoc still does what is supposed to do.
43 */
44
45 int
46 main( int argc, char **argv )
47 {
48     course_of_action = course_of_action | DO_TELL;
49     whoami = argv[0];
50     printf( "robodoc unittest\n" );
51     test_file(  );
52     test_directory(  );
53     test_document(  );
54     return EXIT_SUCCESS;
55 }
56
57
58 /*
59  Test struct RB_Document and it's functions.
60 */
61 int
62 test_document(  )
63 {
64     struct RB_Document *document = NULL;
65     struct RB_Filename *rbfilename = NULL;
66     struct RB_Path     *rbpath = NULL;
67     struct RB_Part     *rbpart = NULL;
68
69     /* Try creating and deleting and empty document */ .
70         document = RB_Get_RB_Document(  );
71     assert( document );
72     RB_Free_RB_Document( document );
73
74
75     /* Now we fill it with some stuff. */
76     document = RB_Get_RB_Document(  );
77     assert( document );
78     rbpath = RB_Get_RB_Path( "/home/robodoc/test2/" );
79     rbfilename = RB_Get_RB_Filename( "robodoc.c", rbpath );
80
81     printf( "Fullname  [ %s ]\n", RB_Get_Fullname( rbfilename ) );
82     printf( "Path      [ %s ]\n", RB_Get_Path( rbfilename ) );
83     printf( "Extension [ %s ]\n", RB_Get_Extension( rbfilename ) );
84
85     rbpart = RB_Get_RB_Part(  );
86     RB_Part_Add_Source( rbpart, rbfilename );
87
88     rbfilename = RB_Get_RB_Filename( "analyser.c", rbpath );
89     RB_Part_Add_Source( rbpart, rbfilename );
90
91     RB_Part_Dump( rbpart );
92
93     RB_Document_Add_Part( document, rbpart );
94
95     RB_Analyse_Document_NG( document );
96
97     RB_Generate_Documentation_NG( document );
98
99     RB_Free_RB_Document( document );
100
101     return 0;
102 }
103
104 int
105 test_directory(  )
106 {
107     struct RB_Directory *rb_directory = NULL;
108
109     printf( "test_directory\n" );
110
111     rb_directory = RB_Get_RB_Directory( "/home/robodoc/test2/" );
112     assert( rb_directory );
113     RB_Dump_RB_Directory( rb_directory );
114     RB_Free_RB_Directory( rb_directory );
115     return 0;
116 }
117
118
119 /* Test path and file functions. */
120
121 int
122 test_file(  )
123 {
124     struct RB_Path     *rb_path1 = NULL;
125     struct RB_Filename *rb_filename1 = NULL;
126
127     printf( "test_file\n" );
128     rb_path1 = RB_Get_RB_Path( "/home/robodoc/test2/" );
129     rb_filename1 = RB_Get_RB_Filename( "test.c", rb_path1 );
130     assert( rb_filename1 );
131     printf( "Fullname  [ %s ]\n", RB_Get_Fullname( rb_filename1 ) );
132     printf( "Path      [ %s ]\n", RB_Get_Path( rb_filename1 ) );
133     printf( "Extension [ %s ]\n", RB_Get_Extension( rb_filename1 ) );
134
135     RB_Free_RB_Filename( rb_filename1 );
136
137     rb_path1 = RB_Get_RB_Path( "/home/robodoc/test2/" );
138     assert( rb_path1 );
139     rb_filename1 = RB_Get_RB_Filename( "Makefile", rb_path1 );
140     assert( rb_filename1 );
141     printf( "Fullname  [ %s ]\n", RB_Get_Fullname( rb_filename1 ) );
142     printf( "Path      [ %s ]\n", RB_Get_Path( rb_filename1 ) );
143     printf( "Extension [ %s ]\n", RB_Get_Extension( rb_filename1 ) );
144
145     RB_Free_RB_Filename( rb_filename1 );
146
147     rb_path1 = RB_Get_RB_Path( "./" );
148     assert( rb_path1 );
149     rb_filename1 = RB_Get_RB_Filename( "test.cpp", rb_path1 );
150     assert( rb_filename1 );
151     printf( "Fullname  [ %s ]\n", RB_Get_Fullname( rb_filename1 ) );
152     printf( "Path      [ %s ]\n", RB_Get_Path( rb_filename1 ) );
153     printf( "Extension [ %s ]\n", RB_Get_Extension( rb_filename1 ) );
154
155     RB_Free_RB_Filename( rb_filename1 );
156
157     rb_path1 = RB_Get_RB_Path( "./" );
158     assert( rb_path1 );
159     rb_filename1 = RB_Get_RB_Filename( ".testrc", rb_path1 );
160     assert( rb_filename1 );
161     printf( "Fullname  [ %s ]\n", RB_Get_Fullname( rb_filename1 ) );
162     printf( "Path      [ %s ]\n", RB_Get_Path( rb_filename1 ) );
163     printf( "Extension [ %s ]\n", RB_Get_Extension( rb_filename1 ) );
164
165     RB_Free_RB_Filename( rb_filename1 );
166
167     /* Try something with a lot of dots */
168     rb_path1 = RB_Get_RB_Path( "./../../" );
169     assert( rb_path1 );
170     rb_filename1 = RB_Get_RB_Filename( "file.c.doc", rb_path1 );
171     assert( rb_filename1 );
172     printf( "Fullname  [ %s ]\n", RB_Get_Fullname( rb_filename1 ) );
173     printf( "Path      [ %s ]\n", RB_Get_Path( rb_filename1 ) );
174     printf( "Extension [ %s ]\n", RB_Get_Extension( rb_filename1 ) );
175
176     RB_Free_RB_Filename( rb_filename1 );
177
178     /* Lets see if a slash gets added if we don't
179        specify the end slash in a path name. */
180     rb_path1 = RB_Get_RB_Path( "/home/robodoc/test2" );
181     assert( rb_path1 );
182     rb_filename1 = RB_Get_RB_Filename( "Makefile", rb_path1 );
183     assert( rb_filename1 );
184     printf( "Fullname  [ %s ]\n", RB_Get_Fullname( rb_filename1 ) );
185     printf( "Path      [ %s ]\n", RB_Get_Path( rb_filename1 ) );
186     printf( "Extension [ %s ]\n", RB_Get_Extension( rb_filename1 ) );
187
188     RB_Free_RB_Filename( rb_filename1 );
189
190     return 0;
191 }