* Bring back rbuild build to be used until bug 6372 is fixed.
[reactos.git] / tools / rbuild / tests / sourcefiletest.cpp
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 #include "test.h"
19
20 using std::string;
21
22 bool
23 SourceFileTest::IsParentOf ( const SourceFile* parent,
24 const SourceFile* child )
25 {
26 size_t i;
27 for ( i = 0; i < child->parents.size (); i++ )
28 {
29 if ( child->parents[i] != NULL )
30 {
31 if ( child->parents[i] == parent )
32 {
33 return true;
34 }
35 }
36 }
37 for ( i = 0; i < child->parents.size (); i++ )
38 {
39 if ( child->parents[i] != NULL )
40 {
41 if ( IsParentOf ( parent,
42 child->parents[i] ) )
43 {
44 return true;
45 }
46 }
47 }
48 return false;
49 }
50
51 void
52 SourceFileTest::IncludeTest ()
53 {
54 const string projectFilename = RBUILD_BASE "tests" SSEP "data" SSEP "automaticdependency_include.xml";
55 Configuration configuration;
56 Project project ( configuration, projectFilename );
57 AutomaticDependency automaticDependency ( project );
58 automaticDependency.ParseFiles ();
59 ARE_EQUAL( 4, automaticDependency.sourcefile_map.size () );
60 const SourceFile* include = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile_include.h" );
61 IS_NOT_NULL( include );
62 const SourceFile* includenext = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile1" SSEP "sourcefile_includenext.h" );
63 IS_NOT_NULL( includenext );
64 }
65
66 void
67 SourceFileTest::FullParseTest ()
68 {
69 const string projectFilename = RBUILD_BASE "tests" SSEP "data" SSEP "automaticdependency.xml";
70 Configuration configuration;
71 Project project ( configuration, projectFilename );
72 AutomaticDependency automaticDependency ( project );
73 automaticDependency.ParseFiles ();
74 ARE_EQUAL( 5, automaticDependency.sourcefile_map.size () );
75 const SourceFile* header1 = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile1_header1.h" );
76 IS_NOT_NULL( header1 );
77 const SourceFile* recurse = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile1_recurse.h" );
78 IS_NOT_NULL( recurse );
79 IS_TRUE( IsParentOf ( header1,
80 recurse ) );
81 IS_FALSE( IsParentOf ( recurse,
82 header1 ) );
83
84 }
85
86 void
87 SourceFileTest::Run ()
88 {
89 IncludeTest ();
90 FullParseTest ();
91 }