END_TEST
  
  
START_TEST (test_comp_fileresolver_resolve_3)
{ 
  string filename(TestDataDirectory);
  SBMLFileResolver fr;
  SBMLDocument* doc2 = fr.resolve("enzyme_model.xml", filename);
  fail_unless(doc2 != NULL);
  fail_unless(doc2->getModel() != NULL);
}
END_TEST
  
  
START_TEST (test_comp_fileresolver_resolve_5)
{ 
  SBMLFileResolver fr;
  string name("chrome://anything/enzyme_model.xml");
  string name1("http://anything/enzyme_model.xml");
  SBMLDocument* doc2 = fr.resolve(name, name1);
  // this passes because we have inadvertently used
  // the file nam at the end of the uri
  fail_unless(doc2 == NULL);
}
int 
CompFlatteningConverter::convert()
{  
   // need to keep track so we can delete it later;
  int basePathResolverIndex = -1;

  // need to set the base path if we have the option
  if (getProperties() != NULL && getProperties()->hasOption("basePath"))
  {
    string basePath = getProperties()->getValue("basePath");
    if(basePath != ".")
    {
      // temporarily add a new resolver with the new basePath
      SBMLFileResolver basePathResolver;
      basePathResolver.addAdditionalDir(basePath);
      basePathResolverIndex = 
                   SBMLResolverRegistry::getInstance().getNumResolvers();
      SBMLResolverRegistry::getInstance().addResolver(&basePathResolver);    
    }
  }  

  // remember number of registered callbacks

  int numRegisteredCallbacks = Submodel::getNumProcessingCallbacks();

  int result = performConversion();

  if (basePathResolverIndex != -1)
  {
    // if we added a resolver remove it
    SBMLResolverRegistry::getInstance().removeResolver(basePathResolverIndex);
  }

  // remove all registered callbacks
  for (int index = Submodel::getNumProcessingCallbacks()-1; index >= numRegisteredCallbacks; --index)
  {
    Submodel::removeProcessingCallback(index);
  }
  
  // clean up PkgsToStrip
  if (mPkgsToStrip != NULL)
  {
    mPkgsToStrip->clear();
    delete mPkgsToStrip;
    mPkgsToStrip = NULL;
  }


  return result;

}
END_TEST


  
START_TEST (test_comp_fileresolver_resolve)
{ 
  string filename(TestDataDirectory);
  filename += "complexified.xml";
  SBMLDocument* doc = readSBMLFromFile(filename.c_str());
  fail_unless(doc->getLocationURI() == "file:" + filename);
  SBMLFileResolver fr;
  SBMLDocument* doc2 = fr.resolve("enzyme_model.xml", doc->getLocationURI());
  fail_unless(doc2 != NULL);
  fail_unless(doc2->getModel() != NULL);
}
END_TEST
  
  
START_TEST (test_comp_fileresolver_resolve_6)
{ 
  string filename(TestDataDirectory);
  size_t pos = filename.rfind('/');
  if (pos != filename.npos)
  {
    filename = filename.substr(0, pos);
  }
  SBMLFileResolver fr;
  SBMLDocument* doc2 = fr.resolve("enzyme_model.xml", filename);
  fail_unless(doc2 != NULL);
  fail_unless(doc2->getModel() != NULL);
  delete doc2;
}
END_TEST
  
  
START_TEST (test_comp_fileresolver_resolve_4)
{ 
  string filename(TestDataDirectory);
  filename += "complexified.xml";
  SBMLDocument* doc = readSBMLFromFile(filename.c_str());
  fail_unless(doc->getLocationURI() == "file:" + filename);
  SBMLFileResolver fr;
  string newDir(TestDataDirectory);
  newDir += "/subdir";
  fr.addAdditionalDir(newDir);
  SBMLDocument* doc2 = fr.resolve("new_aggregate.xml", doc->getLocationURI());
  fail_unless(doc2 != NULL);
  fail_unless(doc2->getModel() != NULL);
}
END_TEST
  
  
START_TEST (test_comp_fileresolver_resolve_2)
{ 
  string filename(TestDataDirectory);
  filename += "complexified.xml";
  SBMLDocument* doc = readSBMLFromFile(filename.c_str());
  fail_unless(doc->getLocationURI() == "file:" + filename);
  SBMLFileResolver fr;
  string newFilename("chrome://anything/enzyme_model.xml");
  SBMLDocument* doc2 = fr.resolve(newFilename, doc->getLocationURI());
  // this passes because we have inadvertently used
  // the file name at the end of the uri
  fail_unless(doc2 != NULL);
  fail_unless(doc2->getModel() != NULL);
}