Add copyright notices and GPL headers to rbuild
[reactos.git] / reactos / 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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 Project project ( RBUILD_BASE "tests" SSEP "data" SSEP "automaticdependency_include.xml" );
55 AutomaticDependency automaticDependency ( project );
56 automaticDependency.ParseFiles ();
57 ARE_EQUAL( 4, automaticDependency.sourcefile_map.size () );
58 const SourceFile* include = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile_include.h" );
59 IS_NOT_NULL( include );
60 const SourceFile* includenext = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile1" SSEP "sourcefile_includenext.h" );
61 IS_NOT_NULL( includenext );
62 }
63
64 void
65 SourceFileTest::FullParseTest ()
66 {
67 const Project project ( RBUILD_BASE "tests" SSEP "data" SSEP "automaticdependency.xml" );
68 AutomaticDependency automaticDependency ( project );
69 automaticDependency.ParseFiles ();
70 ARE_EQUAL( 5, automaticDependency.sourcefile_map.size () );
71 const SourceFile* header1 = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile1_header1.h" );
72 IS_NOT_NULL( header1 );
73 const SourceFile* recurse = automaticDependency.RetrieveFromCache ( RBUILD_BASE "tests" SSEP "data" SSEP "sourcefile1_recurse.h" );
74 IS_NOT_NULL( recurse );
75 IS_TRUE( IsParentOf ( header1,
76 recurse ) );
77 IS_FALSE( IsParentOf ( recurse,
78 header1 ) );
79
80 }
81
82 void
83 SourceFileTest::Run ()
84 {
85 IncludeTest ();
86 FullParseTest ();
87 }