Show
Ignore:
Timestamp:
08/09/08 21:44:20 (5 months ago)
Author:
liamstask
Message:

- a few tests for the Builder class: creating a Makefile properly and loading in the requisite libraries
- update the AinToServo? example's project file format

Files:
1 modified

Legend:

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

    r798 r799  
     1/********************************************************************************* 
    12 
     3 Copyright 2008 MakingThings 
     4 
     5 Licensed under the Apache License,  
     6 Version 2.0 (the "License"); you may not use this file except in compliance  
     7 with the License. You may obtain a copy of the License at 
     8 
     9 http://www.apache.org/licenses/LICENSE-2.0  
     10  
     11 Unless required by applicable law or agreed to in writing, software distributed 
     12 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
     13 CONDITIONS OF ANY KIND, either express or implied. See the License for 
     14 the specific language governing permissions and limitations under the License. 
     15 
     16*********************************************************************************/ 
    217 
    318#include "TestBuilder.h" 
     19#include "ProjectInfo.h" 
    420 
     21#define TEST_PROJECT "resources/examples/Input-Output/AinToServo" 
     22 
     23TestBuilder::TestBuilder( MainWindow* window ) 
     24{ 
     25  this->window = window; 
     26} 
     27 
     28/* 
     29 util - get the "current" project...just our test project. 
     30*/ 
     31QString TestBuilder::currentProjectPath() 
     32{ 
     33  QDir proj = QDir::current().filePath(TEST_PROJECT); 
     34  return proj.path(); 
     35} 
     36 
     37/* 
     38  This is run before any other tests. 
     39*/ 
    540void TestBuilder::initTestCase() 
    641{ 
     42  builder = window->builder; 
     43  builder->currentProjectPath = currentProjectPath(); 
     44} 
     45 
     46/* 
     47  Take an example project and load its libraries. 
     48  Make sure the appropriate libraries are loaded, no more, no less. 
     49*/ 
     50void TestBuilder::loadLibs() 
     51{ 
     52  // change the path to libraries if you need to for your setup...not sure how best to automatically do that 
     53  QDir libDir = QDir::current().filePath("build/Debug/cores/makecontroller/libraries"); 
     54  builder->loadDependencies(libDir.path(), currentProjectPath()); 
     55  QList<Builder::Library> libs = builder->libraries; 
     56  // the AinToServo example only pulls in one library, servo 
     57  QVERIFY(libs.size() == 1); 
     58  QVERIFY(libs.at(0).name == QString("servo")); 
     59  // only expect there to be one thumb src file - servo.c 
     60  QVERIFY(libs.at(0).thumb_src.size() == 1); 
     61  QVERIFY(libs.at(0).arm_src.size() == 0); 
     62} 
     63 
     64/* 
     65  Create a Makefile and verify that all the files in the project file are included, 
     66  the appropriate include dirs are there, taking into account any loaded libraries. 
     67*/ 
     68void TestBuilder::testMakefile() 
     69{ 
     70  builder->createMakefile(currentProjectPath()); 
     71  QDir projDir(currentProjectPath()); 
     72  QFile makefile(projDir.filePath("build/Makefile")); 
     73  QVERIFY(makefile.exists()); 
    774   
     75  QStringList projectFiles; // a list of all the files in the project file 
     76  QFile projectFile(projDir.filePath(projDir.dirName() + ".xml")); 
     77  QDomDocument projectDoc; 
     78  if(projectDoc.setContent(&projectFile)) // read the project file and extract all the file paths 
     79  { 
     80    QDomNodeList files = projectDoc.elementsByTagName("files").at(0).childNodes(); 
     81    for(int i = 0; i < files.count(); i++) 
     82      projectFiles.append(builder->filteredPath(files.at(i).toElement().text())); 
     83  } 
     84  QVERIFY(projectFiles.size()); // make sure we got something 
     85   
     86  QStringList makeFiles; // list of files in the Makefile 
     87  QVERIFY(makefile.open(QFile::ReadOnly | QFile::Text)); 
     88  QTextStream in(&makefile); 
     89  QString makeLine = in.readLine(); 
     90  static const int BEGIN = 0; 
     91  static const int FILES = 1; 
     92  int state = BEGIN; 
     93  while(!makeLine.isNull()) 
     94  { 
     95    switch(state) 
     96    { 
     97      case BEGIN: 
     98        if(makeLine.startsWith("THUMB_SRC") ) 
     99          state = FILES; 
     100        break; 
     101      case FILES: 
     102        if(makeLine.startsWith("INCLUDEDIRS")) 
     103          state = BEGIN; 
     104        else 
     105        { 
     106          if(!makeLine.isEmpty() && !makeLine.startsWith("ARM_SRC")) 
     107            makeFiles.append(makeLine.remove("\\").trimmed()); 
     108        } 
     109        break; 
     110    } 
     111    makeLine = in.readLine(); 
     112  } 
     113  QVERIFY(makeFiles.size()); // make sure we got something 
     114   
     115  // now, let's compare our lists 
     116  // it's possible (probable) that the list of files in the makefiles list will be 
     117  // longer since it will have libraries files added as part of the build process 
     118  // that are not included in the project file. 
     119  int matches = 0; 
     120  int libraryFiles = 0; 
     121  foreach(QString file, makeFiles) 
     122  { 
     123    if(projectFiles.contains(file)) 
     124      matches++; 
     125    else if(file.contains("cores/makecontroller/libraries")) 
     126      libraryFiles++; 
     127  } 
     128  //qDebug("makefiles: %d, projectfiles: %d, matches: %d", makeFiles.size(), projectFiles.size(), matches); 
     129  QVERIFY( matches == (makeFiles.size() - libraryFiles)); 
    8130} 
    9131 
    10132 
    11