Exemple #1
0
TEST_F(BCLFixture, GetComponentByUID)
{
  std::string uid = "c2c40a00-5ea5-0130-aa1d-14109fdf0b37";
  std::string versionId = "0c316887-63ef-45a3-a132-3b0a1c566b77";

  /// delete this component if we already have it
  boost::optional<BCLComponent> testComponent = LocalBCL::instance().getComponent(uid, versionId);
  if(testComponent){
    bool test = LocalBCL::instance().removeComponent(*testComponent);
    EXPECT_TRUE(test);
  }
  testComponent = LocalBCL::instance().getComponent(uid, versionId);
  EXPECT_FALSE(testComponent);

  RemoteBCL remoteBCL;

  bool success = remoteBCL.downloadComponent(uid);
  ASSERT_TRUE(success);

  boost::optional<BCLComponent> component = remoteBCL.waitForComponentDownload();
  ASSERT_TRUE(component);
  EXPECT_EQ(uid, component->uid());

  /// Returns the last downloaded component if there is one
  boost::optional<BCLComponent> lastDownload = remoteBCL.lastComponentDownload();
  ASSERT_TRUE(lastDownload);
  EXPECT_EQ(uid, lastDownload->uid());

  testComponent = LocalBCL::instance().getComponent(uid, versionId);
  EXPECT_TRUE(testComponent);
  EXPECT_EQ(uid, testComponent->uid());
}
Exemple #2
0
TEST_F(BCLFixture, RemoteBCLTest2)
{
  time_t startTime;
  time(&startTime);

  RemoteBCL remoteBCL;

  // get all constructions, via empty first arg and tid
  std::vector<BCLSearchResult> responses = remoteBCL.searchComponentLibrary("",127);
  ASSERT_GT(responses.size(),0u);

  bool success = remoteBCL.downloadComponent(responses[0].uid());
  ASSERT_TRUE(success);

  boost::optional<BCLComponent> component = remoteBCL.waitForComponentDownload();
  ASSERT_TRUE(component);

  /// delete this component if we already have it
  boost::optional<BCLComponent> testComponent = LocalBCL::instance().getComponent(responses[0].uid(), responses[0].versionId());
  if(testComponent){
    bool test = LocalBCL::instance().removeComponent(*testComponent);
    EXPECT_TRUE(test);
  }
  testComponent = LocalBCL::instance().getComponent(responses[0].uid(), responses[0].versionId());
  EXPECT_FALSE(testComponent);

  /// Download an individual component by uid and extract
  /// returns true if a download is started
  success = remoteBCL.downloadComponent(responses[0].uid());
  ASSERT_TRUE(success);

  component = remoteBCL.waitForComponentDownload();
  ASSERT_TRUE(component);

  /// Returns the last downloaded component if there is one
  boost::optional<BCLComponent> lastDownload = remoteBCL.lastComponentDownload();
  ASSERT_TRUE(lastDownload);

  EXPECT_FALSE(lastDownload->files().empty());
  for (const std::string& file : lastDownload->files()) {
    openstudio::path path = toPath(lastDownload->directory() + "/files/" + file);
    EXPECT_TRUE(QDir().exists(toQString(path)));
    time_t time = QFileInfo(toQString(path)).lastModified().toTime_t();
    EXPECT_GT(time, startTime);
  }

  // Find in local library
  component = LocalBCL::instance().getComponent(responses[0].uid(), responses[0].versionId());
  ASSERT_TRUE(component);

  // check that actually was downloaded
  EXPECT_FALSE(component->files().empty());
  for (const std::string& file : component->files()) {
    openstudio::path path = toPath(component->directory() + "/files/" + file);
    EXPECT_TRUE(QDir().exists(toQString(path)));
    time_t time = QFileInfo(toQString(path)).lastModified().toTime_t();
    EXPECT_GT(time, startTime);
  }

  // read all attributes, look for "OpenStudio Type"
  std::string openstudioType;
  for (const Attribute& attribute : component->attributes()) {
    if (istringEqual("OpenStudio Type", attribute.name())){
      openstudioType = attribute.valueAsString();
      break;
    }
  }
  ASSERT_FALSE(openstudioType.empty());

  // load the component
  std::vector<std::string> oscFiles = component->files("osc");
  ASSERT_FALSE(oscFiles.empty());
  EXPECT_EQ(1u, oscFiles.size());
  openstudio::path oscPath = toPath(oscFiles[0]);
  EXPECT_TRUE(QDir().exists(toQString(oscPath)));
  // DLM: the real loading procedure would be to run this through the version translator first 
  boost::optional<Workspace> workspace = Workspace::load(oscPath, IddFile::catchallIddFile()); 
  // This will fail on Windows if the path is greater than MAX_PATH
  EXPECT_TRUE(workspace);

  // search for components by type
  std::vector<std::pair<std::string, std::string> > searchTerms;
  searchTerms.push_back(std::make_pair("OpenStudio Type", openstudioType));

  std::vector<BCLComponent> components = LocalBCL::instance().componentAttributeSearch(searchTerms);
  EXPECT_FALSE(components.empty());

  // check that search returns newly downloaded component
  bool found = false;
  for (const BCLComponent& testComponent : components) {
    if (component->uid() == testComponent.uid()){
      found = true;
      break;
    }
  }
  EXPECT_TRUE(found);
  
}