/* ****************************************************************************
*
* getAndSize - 
*/
TEST(ScopeVector, getAndSize)
{
  ScopeVector   sV;
  Scope         scope0("Type", "Value0");
  Scope         scope1("Type", "Value1");
  Scope         scope2("Type", "Value2");
  Scope*        scopeP;

  utInit();

  sV.push_back(&scope0);
  sV.push_back(&scope1);
  sV.push_back(&scope2);

  EXPECT_EQ(3, sV.size());

  scopeP = sV[0];
  EXPECT_STREQ("Value0", scopeP->value.c_str());

  scopeP = sV[1];
  EXPECT_STREQ("Value1", scopeP->value.c_str());

  scopeP = sV[2];
  EXPECT_STREQ("Value2", scopeP->value.c_str());

  utExit();
}
/* ****************************************************************************
*
* present - no output expected, just exercising the code
*/
TEST(ScopeVector, present)
{
  ScopeVector   sV;
  Scope         scope("Type", "Value");

  utInit();

  sV.push_back(&scope);
  sV.present("");

  utExit();
}
/* ****************************************************************************
*
* check - 
*/
TEST(ScopeVector, check)
{
  Scope*         s1 = new Scope("Type", "Value");
  Scope*         s2 = new Scope("", "Value");
  ScopeVector    sV;
  std::string    expected1 = "OK";
  std::string    expected2 = "Empty type in restriction scope";
  std::string    rendered;
  
  utInit();

  sV.push_back(s1);
  rendered = sV.check(RegisterContext, "", "", 0);
  EXPECT_STREQ(expected1.c_str(), rendered.c_str());

  sV.push_back(s2);
  rendered = sV.check(RegisterContext, "", "", 0);
  EXPECT_STREQ(expected2.c_str(), rendered.c_str());  

  utExit();
}
/* ****************************************************************************
*
* renderAndRelease -
*
*/
TEST(ScopeVector, renderAndRelease)
{
  Scope*         s = new Scope("Type", "Value");
  ScopeVector    sV;
  std::string    out;

  utInit();

  out = sV.toJsonV1(false);
  EXPECT_STREQ("", out.c_str());

  sV.push_back(s);

  out = sV.toJsonV1(false);

  EXPECT_EQ(sV.size(), 1);
  sV.release();
  EXPECT_EQ(sV.size(), 0);

  utExit();
}
/* ****************************************************************************
*
* renderAndRelease - 
*
* FIXME P5 #1862: _json counterpart?
*/
TEST(ScopeVector, DISABLED_renderAndRelease)
{
  Scope*         s = new Scope("Type", "Value");
  ScopeVector    sV;
  const char*    outfile = "ngsi.scopeVector.render.middle.xml";
  std::string    out;

  utInit();

  out = sV.render("", false);
  EXPECT_STREQ("", out.c_str());

  sV.push_back(s);

  out = sV.render("", false);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ(sV.size(), 1);
  sV.release();
  EXPECT_EQ(sV.size(), 0);

  utExit();
}