Show
Ignore:
Timestamp:
08/10/08 13:20:07 (5 months ago)
Author:
liamstask
Message:

- add compareConfigFile() to determine when we need to re-write the config file
- add tests for it

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • mcbuilder/trunk/tests/TestBuilder.cpp

    r799 r800  
    1717 
    1818#include "TestBuilder.h" 
    19 #include "ProjectInfo.h" 
    2019 
    2120#define TEST_PROJECT "resources/examples/Input-Output/AinToServo" 
     
    4039void TestBuilder::initTestCase() 
    4140{ 
     41  window->openProject(currentProjectPath()); 
    4242  builder = window->builder; 
    43   builder->currentProjectPath = currentProjectPath(); 
    4443} 
    4544 
     
    8584   
    8685  QStringList makeFiles; // list of files in the Makefile 
     86  QStringList makeFileDirs; // list of include dirs in the Makefile 
    8787  QVERIFY(makefile.open(QFile::ReadOnly | QFile::Text)); 
    8888  QTextStream in(&makefile); 
     
    9090  static const int BEGIN = 0; 
    9191  static const int FILES = 1; 
     92  static const int DIRS = 2; 
    9293  int state = BEGIN; 
    9394  while(!makeLine.isNull()) 
     
    101102      case FILES: 
    102103        if(makeLine.startsWith("INCLUDEDIRS")) 
     104          state = DIRS; 
     105        else if(!makeLine.isEmpty() && !makeLine.startsWith("ARM_SRC")) 
     106          makeFiles << makeLine.remove("\\").trimmed(); 
     107        break; 
     108      case DIRS: 
     109        if(makeLine.startsWith("CC")) 
    103110          state = BEGIN; 
    104         else 
    105         { 
    106           if(!makeLine.isEmpty() && !makeLine.startsWith("ARM_SRC")) 
    107             makeFiles.append(makeLine.remove("\\").trimmed()); 
    108         } 
    109         break; 
     111        else if(!makeLine.isEmpty()) 
     112          makeFileDirs << makeLine.remove("\\").remove("-I").trimmed(); 
    110113    } 
    111114    makeLine = in.readLine(); 
    112115  } 
    113116  QVERIFY(makeFiles.size()); // make sure we got something 
     117  QVERIFY(makeFileDirs.size()); 
    114118   
    115119  // now, let's compare our lists 
     
    128132  //qDebug("makefiles: %d, projectfiles: %d, matches: %d", makeFiles.size(), projectFiles.size(), matches); 
    129133  QVERIFY( matches == (makeFiles.size() - libraryFiles)); 
     134   
     135  // now check that the appropriate include directories have been added 
     136  QDomNodeList dirs = projectDoc.elementsByTagName("include_dirs").at(0).childNodes(); 
     137  QStringList includeDirs; 
     138  for(int i = 0; i < dirs.count(); i++) 
     139    includeDirs.append(builder->filteredPath(dirs.at(i).toElement().text())); 
     140  QVERIFY(includeDirs.size()); // make sure we got something 
     141   
     142  matches = 0; 
     143  int libraryDirs = 0; 
     144  foreach( QString dir, makeFileDirs ) 
     145  { 
     146    if(includeDirs.contains(dir)) 
     147      matches++; 
     148    else if(dir.contains("cores/makecontroller/libraries")) 
     149      libraryDirs++; 
     150  } 
     151  //qDebug("makefile dirs: %d, project file dirs: %d, matches: %d, library dirs: %d",  
     152  //         makeFileDirs.size(), includeDirs.size(), matches, libraryDirs); 
     153   
     154  // one additional difference is that the Makefile should include the project dir itself as an include dir 
     155  // whereas this is not specificed in the project file 
     156  QVERIFY(matches == (makeFileDirs.size() - libraryDirs - 1)); 
     157} 
     158 
     159/* 
     160  Create a config file. 
     161  Make sure it includes the appropriate elements, based on the  
     162  ProjectInfo. 
     163*/ 
     164void TestBuilder::testConfigFile() 
     165{ 
     166  QDir projDir(currentProjectPath()); 
     167  QFile configFile(projDir.filePath("config.h")); 
     168   
     169  if( configFile.exists() ) 
     170    projDir.remove("config.h"); // get rid of the file, so we can test creating it 
     171 
     172  builder->createConfigFile(currentProjectPath()); 
     173  // we haven't changed anything in the file yet, so this should return false 
     174  QVERIFY( builder->compareConfigFile(currentProjectPath()) == false ); 
     175   
     176  // now let's change a few things in the config file, and confirm that we need to update it 
     177//  QVERIFY(configFile.open(QFile::Text)); 
     178//  QTextStream in(&configFile); 
     179//   
     180//  configFile.close(); 
    130181} 
    131182