示例#1
0
void TestCellInfo::TestWhitespaceWeightingIncreasedInMatchingSizeTables()
{
    ComparisonContext cContext;
    {
        CCellInfo ci1(1,3,5,7,L"", true,0);
        CCellInfo ci2(2,4,6,8,L"", true,0);
        assertMessage(ci1.GetWeightingWith(&cContext, ci2) == CTWS_WHITESPACE_SCORE, _T("Tables are different size, expect normal whitespace weighting"));
    }

    {
        CCellInfo ci1(1,3,6,8,L"", true,0);
        CCellInfo ci2(2,4,6,8,L"", true,0);
        assertMessage(ci1.GetWeightingWith(&cContext, ci2) == CTWS_WHITESPACE_SCORE, _T("tables same size, but rows/cols different - normal weigting"));
    }

    {
        CCellInfo ci1(1,3,6,8,L"", true,0);
        CCellInfo ci2(1,3,6,8,L"", true,0);
        assertMessage(abs(ci1.GetWeightingWith(&cContext, ci2) - (CTWS_COLUMN_THRESHOLD + 0.10))<0.0001, _T("same size, same indicies, enhanced score"));
    }

    {
        CCellInfo ci1(1,3,6,8,L"", true,0);
        CCellInfo ci2(1,3,6,9,L"", true,1);
        assertMessage(abs(ci1.GetWeightingWith(&cContext, ci2) - CTWS_WHITESPACE_SCORE)<0.0001, _T("same indicies, different size, normal score"));
    }
    {
        CCellInfo ci1(1,3,6,8,L"", true,99);
        CCellInfo ci2(1,3,6,9,L"", true,99);
        assertMessage(abs(ci1.GetWeightingWith(&cContext, ci2) - (CTWS_COLUMN_THRESHOLD + 0.1))<0.0001, _T("same indicies, same width, enhanced score"));
    }
}
/* ****************************************************************************
*
* error - 
*/
TEST(exitTreat, error)
{
  ConnectionInfo ci1("/exit",  "GET", "1.1");
  ConnectionInfo ci2("/exit/nadadenada",  "GET", "1.1");
  ConnectionInfo ci3("/exit/harakiri",  "GET", "1.1");
  const char*    outfile1 = "orion.exit.error1.valid.xml";
  const char*    outfile2 = "orion.exit.error2.valid.xml";
  const char*    outfile3 = "orion.exit.error3.valid.xml";
  std::string    out;

  utInit();

  harakiri = true;

  out = restService(&ci1, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  out = restService(&ci2, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  harakiri = false;
  out = restService(&ci3, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  harakiri = true;
  out = restService(&ci3, rs);
  EXPECT_STREQ("DIE", out.c_str());
  harakiri = false;

  utExit();
}
/* ****************************************************************************
*
* error -
*/
TEST(badVerbAllFour, error)
{
  ConnectionInfo ci1("/ngsi10/contextEntities/123",  "PUST", "1.1");
  ConnectionInfo ci2("/ngsi10/contextEntities",      "PUST", "1.1");
  std::string    out;
  RestService    restService1 = { VersionRequest, 3, { "ngsi10", "contextEntities", "123" }, NULL };
  RestService    restService2 = { VersionRequest, 2, { "ngsi10", "contextEntities" },        NULL };

  utInit();

  ci1.apiVersion   = V1;
  ci1.restServiceP = &restService1;

  serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV);
  out = orion::requestServe(&ci1);

  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci1.httpHeader[0]);
  EXPECT_EQ("POST, GET, PUT, DELETE", ci1.httpHeaderValue[0]);

  ci2.apiVersion = V1;
  ci2.restServiceP = &restService2;

  out = orion::requestServe(&ci2);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci2.httpHeader[0]);
  EXPECT_EQ("POST, GET, PUT, DELETE", ci2.httpHeaderValue[0]);

  utExit();
}
/* ****************************************************************************
*
* shortPath - 
*/
TEST(Convenience, shortPath)
{
  ConnectionInfo  ci1("ngsi9", "GET", "1.1");
  ConnectionInfo  ci2("ngsi10", "GET", "1.1");
  ConnectionInfo  ci3("ngsi8", "GET", "1.1");
  ConnectionInfo  ci4("ngsi10/nada", "GET", "1.1");
  std::string     out;
  const char*     outfile1 = "ngsi.convenience.shortPath.postponed.xml";
  const char*     outfile2 = "ngsi.convenience.shortPath2.postponed.xml";
  const char*     outfile3 = "ngsi.convenience.shortPath3.postponed.xml";
  const char*     outfile4 = "ngsi.convenience.shortPath4.postponed.xml";

  utInit();

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  out = restService(&ci1, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  out = restService(&ci2, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  out = restService(&ci3, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'";
  out = restService(&ci4, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* put -
*/
TEST(putSubscriptionConvOp, put)
{
  ConnectionInfo  ci1("/ngsi10/contextSubscriptions/012345678901234567890123",  "XVERB",  "1.1");
  std::string     out;
  RestService     restService =
    {
      VersionRequest,
      3, { "ngsi10", "contextSubscriptions", "012345678901234567890123" },
      NULL
    };

  utInit();

  ci1.outMimeType    = JSON;
  ci1.inMimeType     = JSON;
  ci1.payload        = NULL;
  ci1.payloadSize    = 0;
  ci1.restServiceP   = &restService;

  serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV);
  out = orion::requestServe(&ci1);

  EXPECT_EQ("Allow",       ci1.httpHeader[0]);
  EXPECT_EQ("PUT, DELETE", ci1.httpHeaderValue[0]);
  EXPECT_EQ("", out);

  utExit();
}
/* ****************************************************************************
*
* found - 
*/
TEST(getAttributeValueInstance, found)
{
  ConnectionInfo ci1("/ngsi10/contextEntities/E1/attributes",          "POST", "1.1");
  ConnectionInfo ci2("/ngsi10/contextEntities/E1/attributes/A1/left",  "GET", "1.1");
  const char*    outfile1  = "ngsi10.appendContextElementResponse.ok1.valid.xml";
  const char*    outfile2  = "ngsi10.appendContextElementResponse.ok2.valid.xml";
  const char*    infile    = "ngsi10.IndividualContextEntityAttributes.A1-left.postponed.xml";
  std::string    out;

  utInit();

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";

  ci1.outFormat    = XML;
  ci1.inFormat     = XML;
  ci1.payload      = testBuf;
  ci1.payloadSize  = strlen(testBuf);
  out              = restService(&ci1, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci2.outFormat    = XML;
  out              = restService(&ci2, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* put - 
*/
TEST(logTraceTreat, put)
{
  ConnectionInfo  ci1("/log/traceLevel/0-19,21-200",  "PUT", "1.1");
  ConnectionInfo  ci2("/log/traceLevel/aaa",  "PUT", "1.1");
  ConnectionInfo  ci3("/log/traceLevel",  "GET", "1.1");
  const char*     outfile1 = "orion.logTrace.spanOfLevels.valid.xml";
  const char*     outfile2 = "orion.logTrace.invalidLevels.valid.xml";
  const char*     outfile3 = "orion.logTrace.get.valid.xml";
  std::string     out;

  utInit();

  ci1.outFormat = XML;
  out          = restService(&ci1, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  ci2.outFormat = XML;
  out          = restService(&ci2, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  ci3.outFormat = XML;
  out          = restService(&ci3, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* put - 
*/
TEST(putSubscriptionConvOp, put)
{
  ConnectionInfo ci1("/ngsi10/contextSubscriptions/012345678901234567890123",  "DELETE", "1.1");
  ConnectionInfo ci2("/ngsi10/contextSubscriptions/111222333444555666777888",  "PUT",    "1.1");
  ConnectionInfo ci3("/ngsi10/contextSubscriptions/111222333444555666777881",  "PUT",    "1.1");
  ConnectionInfo ci4("/ngsi10/contextSubscriptions/012345678901234567890123",  "XVERB",  "1.1");
  const char*    infile       = "ngsi10.updateContextSubscriptionRequest.subscriptionNotFound.valid.xml";
  const char*    outfile1     = "ngsi10.unsubscribeContextResponse.putSubscriptionConvOp.notFound.valid.xml";
  const char*    outfile2     = "ngsi10.updateContextSubscriptionResponse.putSubscriptionConvOp.notFound.valid.xml";
  const char*    outfile3     = "ngsi10.updateContextSubscriptionResponse.putSubscriptionConvOp.unmatchingSubscriptionId.valid.xml";
  std::string    out;

  utInit();

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  ci1.outFormat    = XML;
  ci1.inFormat     = XML;
  ci1.payload      = NULL;
  ci1.payloadSize  = 0;
  out              = restService(&ci1, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());
  

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci2.outFormat    = XML;
  ci2.inFormat     = XML;
  ci2.payload      = testBuf;
  ci2.payloadSize  = strlen(testBuf);
  out              = restService(&ci2, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  ci3.outFormat    = XML;
  ci3.inFormat     = XML;
  ci3.payload      = testBuf;
  ci3.payloadSize  = strlen(testBuf);
  out              = restService(&ci3, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  ci4.outFormat    = XML;
  ci4.inFormat     = XML;
  ci4.payload      = NULL;
  ci4.payloadSize  = 0;
  out              = restService(&ci4, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow",       ci4.httpHeader[0]);
  EXPECT_EQ("PUT, DELETE", ci4.httpHeaderValue[0]);

  utExit();
}
/* ****************************************************************************
*
* somethingFound - 
*/
TEST(getContextEntityTypeAttribute, somethingFound)
{
  ConnectionInfo ci1("/ngsi9/registerContext",                                 "POST", "1.1");
  ConnectionInfo ci2("/ngsi9/contextEntityTypes/Room/attributes/temperature",  "GET",  "1.1");
  const char*    registerXmlFile = "ngsi9.registerContextRequest.ok.valid.xml";
  const char*    outfile1        = "ngsi9.registerContextResponse.ok.middle.xml";
  const char*    outfile2        = "ngsi9.discoverContextAvailabilityResponse.ok.valid.xml";
  std::string    out;

  utInit();
  // Avoid forwarding of messages
  extern int fwdPort;
  int saved = fwdPort;

  //
  // 1. Register entities so we have something to find:
  //    - entityId type="Room" isPattern="false", ConferenceRoom
  //    - entityId type="Room" isPattern="false", OfficeRoom
  //
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), registerXmlFile)) << "Error getting test data from '" << registerXmlFile << "'";

  ci1.outFormat    = XML;
  ci1.inFormat     = XML;
  ci1.payload      = testBuf;
  ci1.payloadSize  = strlen(testBuf);
  out              = restService(&ci1, rs);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";

  char* outStart  = (char*) out.c_str();

  // Remove last char in expectedBuf
  expectedBuf[strlen(expectedBuf) - 1] = 0;

  // Shorten 'out' to be of same length as expectedBuf
  outStart[strlen(expectedBuf)]    = 0;
  EXPECT_STREQ(expectedBuf, out.c_str());


  //
  // Now discover
  //
  ci2.outFormat = XML;
  out           = restService(&ci2, rs);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  // Putting old value back
  fwdPort = saved;

  utExit();
}
示例#10
0
void TestCellInfo::TestGetWeighting()
{
    ComparisonContext cContext;
    CCellInfo ci1(1,3,5,7,L"", true,0);
    CCellInfo ci2(2,4,6,8,L"", true,0);

    assertTest(ci1.GetWeightingWith(&cContext, ci2) == CTWS_WHITESPACE_SCORE);
    assertTest(!ci1.DidFuzzyMatch());

    CCellInfo ci3(1,1,4,4,L"fishes", false,0);
    CCellInfo ci4(1,1,4,4,L"fishes", false,0);
    assertTest(ci3.GetWeightingWith(&cContext, ci4) == 1.0);
    assertTest(ci3.DidFuzzyMatch());

}
/* ****************************************************************************
*
* notFound - 
*/
TEST(putAttributeValueInstance, notFound)
{
  ConnectionInfo ci1("/ngsi10/contextEntities/E1/attributes/A1/left",  "PUT", "1.1");
  ConnectionInfo ci2("/ngsi10/contextEntities/E1/attributes/A1/right",  "PUT", "1.1");
  ConnectionInfo ci3("/ngsi10/contextEntities/E1/attributes/A1/left",  "PUT", "1.1");
  const char*    infile1   = "ngsi10.putAttributeValueInstance.A1-left.ok.postponed.xml";
  const char*    infile2   = "ngsi10.putAttributeValueInstance.noIdMetadata.postponed.xml";
  const char*    outfile1  = "ngsi10.statusCode.putAttributeValueInstance1.ok.valid.xml";
  const char*    outfile2  = "ngsi10.statusCode.putAttributeValueInstance2.ok.valid.xml";
  const char*    outfile3  = "ngsi10.statusCode.putAttributeValueInstance3.ok.valid.xml";
  std::string    out;

  utInit();
  
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile1)) << "Error getting test data from '" << infile1 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  ci1.outFormat    = XML;
  ci1.inFormat     = XML;
  ci1.payload      = testBuf;
  ci1.payloadSize  = strlen(testBuf);
  out              = restService(&ci1, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile1)) << "Error getting test data from '" << infile1 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci2.outFormat    = XML;
  ci2.inFormat     = XML;
  ci2.payload      = testBuf;
  ci2.payloadSize  = strlen(testBuf);
  out              = restService(&ci2, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  ci3.outFormat    = XML;
  ci3.inFormat     = XML;
  ci3.payload      = testBuf;
  ci3.payloadSize  = strlen(testBuf);
  out              = restService(&ci3, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* deleteIndividual - 
*/
TEST(logTraceTreat, deleteIndividual)
{
  ConnectionInfo  ci0("/log/traceLevel/0-255",  "PUT",  "1.1");
  ConnectionInfo  ci1("/log/traceLevel/161",  "DELETE", "1.1");
  ConnectionInfo  ci2("/log/traceLevel/aaa",  "DELETE", "1.1");
  ConnectionInfo  ci3("/log/traceLevel",  "GET", "1.1");
  const char*     outfile0 = "orion.logTrace.allLevelsSet.valid.xml";
  const char*     outfile1 = "orion.logTrace.deleteOk.valid.xml";
  const char*     outfile2 = "orion.logTrace.invalidDelete.valid.xml";
  const char*     outfile3 = "orion.logTrace.deleteIndividual4.valid.xml";
  std::string     out;

  utInit();

  ci0.outFormat  = XML;
  ci0.apiVersion = "v1";
  out            = restService(&ci0, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile0)) << "Error getting test data from '" << outfile0 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  ci1.outFormat  = XML;
  ci1.apiVersion = "v1";
  out            = restService(&ci1, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  ci2.outFormat  = XML;
  ci2.apiVersion = "v1";
  out            = restService(&ci2, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  ci3.outFormat  = XML;
  ci3.apiVersion = "v1";
  out            = restService(&ci3, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* deleteAll - 
*/
TEST(logTraceTreat, deleteAll)
{
  ConnectionInfo ci1("/log/traceLevel",  "DELETE", "1.1");
  ConnectionInfo ci2("/log/traceLevel",  "GET", "1.1");
  const char*    outfile1 = "orion.logTrace.allLevelsOff.valid.xml";
  const char*    outfile2 = "orion.logTrace.empty.valid.xml";
  std::string    out;

  utInit();

  ci1.outFormat = XML;
  out           = restService(&ci1, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  ci2.outFormat = XML;
  out           = restService(&ci2, rs);
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* error - 
*/
TEST(badVerbAllFour, error)
{
  ConnectionInfo ci1("/ngsi10/contextEntities/123",  "PUST", "1.1");
  ConnectionInfo ci2("/ngsi10/contextEntities",      "PUST", "1.1");
  ConnectionInfo ci3("/ngsi10/",                     "PUST", "1.1");
  ConnectionInfo ci4("/ngsi10/1/2/3/4",              "PUST", "1.1");
  const char*    outfile1 = "orion.serviceNotRecognized.valid.xml";
  const char*    outfile2 = "orion.serviceNotRecognized2.valid.xml";
  std::string    out;

  utInit();

  ci1.apiVersion = "v1";
  out = restService(&ci1, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci1.httpHeader[0]);
  EXPECT_EQ("POST, GET, PUT, DELETE", ci1.httpHeaderValue[0]);

  ci2.apiVersion = "v1";
  out = restService(&ci2, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci2.httpHeader[0]);
  EXPECT_EQ("POST, GET, PUT, DELETE", ci2.httpHeaderValue[0]);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  ci3.apiVersion = "v1";
  out = restService(&ci3, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci4.apiVersion = "v1";
  out = restService(&ci4, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
示例#15
0
void drive_resolve_specialChars()
{


    const char* env = getenv("PEGASUS_HOME");
    String repositoryDir(env);
    repositoryDir.append("/repository");
    //String repositoryDir("c:/pegasus-cvs/pegasus/repository");
    CIMNamespaceName _ns("root/cimv2");
    CIMRepository *_rep = new CIMRepository(repositoryDir);
    RepositoryQueryContext _query(_ns, _rep);
    RepositoryQueryContext _query1(_ns, _rep);
    try {
        const CQLIdentifier _Id1(String("CIM_OperatingSystem"));

        _query.insertClassPath(_Id1);

        const CIMName _cimName(String("CIM_OperatingSystem"));

        CIMInstance _i1(_cimName);
        CIMProperty _p1(CIMName("OSType"),CIMValue(Uint16(11)));
        CIMProperty _p2(CIMName("Status"),CIMValue(String("Degraded")));
        Array<Uint16> array16;
        array16.append(Uint16(0));
        array16.append(Uint16(1));
        array16.append(Uint16(2));
        array16.append(Uint16(3));
        CIMProperty _p3(CIMName("OperationalStatus"),CIMValue(array16));

        _i1.addProperty(_p1);
        _i1.addProperty(_p2);
        _i1.addProperty(_p3);

        CQLChainedIdentifier ci1(String("CIM_OperatingSystem.OSType#OS400"));
        CQLChainedIdentifier ci2(String("CIM_OperatingSystem.OSType#LINUX"));
        CQLChainedIdentifier ci3(String("CIM_OperatingSystem.Status#Degraded"));

        CQLChainedIdentifier ci5(String("CIM_OperatingSystem.Status#BOGUS"));

        CQLChainedIdentifier ci6(
            String("CIM_OperatingSystem.CIM_OperatingSystem::"
                   "OperationalStatus[2]"));
        CQLValue a1(ci1);
        CQLValue a2(ci2);
        CQLValue a3(ci3);

        CQLValue a5(ci5);
        CQLValue a6(ci6);


        a1.resolve(_i1, _query);
        a2.resolve(_i1, _query);

        a6.resolve(_i1, _query);

        try
        {
            a3.resolve(_i1, _query);
            PEGASUS_TEST_ASSERT(0);
        }
        catch(...)
        {
            PEGASUS_TEST_ASSERT(1);
        }

        try
        {
            a5.resolve(_i1, _query);
            PEGASUS_TEST_ASSERT(0);
        }
        catch(...)
        {
            PEGASUS_TEST_ASSERT(1);
        }

        PEGASUS_TEST_ASSERT(a1 == CQLValue(Uint64(11)));
        PEGASUS_TEST_ASSERT(a2 == CQLValue(Uint64(36)));


        PEGASUS_TEST_ASSERT(a6 == CQLValue(Uint64(2)));


    }
    catch(Exception & e)
    {
        cout << e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }
    delete _rep;
    return;
}
示例#16
0
void drive_resolve_primitive()
{


    const char* env = getenv("PEGASUS_HOME");
    String repositoryDir(env);
    repositoryDir.append("/repository");
    //String repositoryDir("c:/pegasus-cvs/pegasus/repository");
    CIMNamespaceName _ns("root/cimv2");
    CIMRepository *_rep = new CIMRepository(repositoryDir);
    RepositoryQueryContext _query(_ns, _rep);
    RepositoryQueryContext _query1(_ns, _rep);
    try {
        const CQLIdentifier _Id1(String("CIM_OperatingSystem"));

        _query.insertClassPath(_Id1);

        const CIMName _cimName(String("CIM_OperatingSystem"));

        CIMInstance _i1(_cimName);
        CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules")));
        CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2)));
        CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
        CIMProperty _p4(CIMName("TimeOfLastStateChange"),
                        CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

        _i1.addProperty(_p1);
        _i1.addProperty(_p2);
        _i1.addProperty(_p3);
        _i1.addProperty(_p4);

        CQLChainedIdentifier ci1(
            String("CIM_OperatingSystem.CIM_OperatingSystem::Description"));
        CQLChainedIdentifier
        ci2(String("CIM_OperatingSystem.CIM_OperatingSystem::EnabledState"));
        CQLChainedIdentifier ci3(
            String("CIM_OperatingSystem.CIM_OperatingSystem::CurrentTimeZone"));
        CQLChainedIdentifier ci4(
            String("CIM_OperatingSystem.CIM_OperatingSystem::TimeOfLastStateChange"));

        CQLChainedIdentifier
        ci5(String(
                "CIM_OperatingSystem.CIM_EnabledLogicalElement::TimeOfLastStateChange"));

        CQLChainedIdentifier
        ci7(String("CIM_OperatingSystem"));

        CQLChainedIdentifier
        ci9(String(
                "CIM_EnabledLogicalElement.CIM_OperatingSystem::CSCreationClassName"));

        CQLChainedIdentifier
        ci10(String("CIM_OperatingSystem.CIM_OperatingSystem::Bubba"));

        CQLValue a1(ci1);
        CQLValue a2(ci2);
        CQLValue a3(ci3);
        CQLValue a4(ci4);
        CQLValue a5(ci5);

        CQLValue a7(ci7);

        CQLValue a9(ci9);
        CQLValue a10(ci10);

        CQLValue a11(_query.getClass(CIMName("CIM_OperatingSystem")));

        a1.resolve(_i1, _query);
        a2.resolve(_i1, _query);
        a3.resolve(_i1, _query);
        a4.resolve(_i1, _query);
        a5.resolve(_i1, _query);
        a7.resolve(_i1, _query);
        a10.resolve(_i1, _query1);

        a9.resolve(_i1, _query);

        PEGASUS_TEST_ASSERT(a1 == CQLValue(String("Dave Rules")));
        PEGASUS_TEST_ASSERT(a2 == CQLValue(Uint64(2)));
        PEGASUS_TEST_ASSERT(a3 == CQLValue(Sint64(-600)));
        PEGASUS_TEST_ASSERT(a4 == CQLValue(
                                CIMDateTime(String("20040811105625.000000-360"))));
        PEGASUS_TEST_ASSERT(a5 == CQLValue(
                                CIMDateTime(String("20040811105625.000000-360"))));
        //PEGASUS_TEST_ASSERT(a7 == CQLValue(_i1));
        PEGASUS_TEST_ASSERT(a9.isNull());
        PEGASUS_TEST_ASSERT(a10.isNull());

    }
    catch(Exception & e)
    {
        cout << e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }
    delete _rep;
    return;
}
示例#17
0
void testpluginPlugin::getCatalog(QList<CatItem>* items)
{
    items = items;
    CatItem me(itemPath);
#ifdef TEST
    Q_ASSERT(items);
    CatItem cv("test://catalogTestVerb", testVerbStr, TEST_HASH);
    cv.setItemType(CatItem::VERB);
    items->append(cv);

    CatItem ci("test://catalogTestNounItem", testNounStr , TEST_HASH);
    CatItem c("testCatalogChildItem", "testChild", TEST_HASH);
    ci.addChild(c);
    items->append(ci);

    for(uint i=0; i < str_len;i++){
        QString out_str = str_list[i][1];
        CatItem it(out_str, out_str, TEST_HASH);
        it.setExternalWeight(MAX_EXTERNAL_WEIGHT, me);
        qDebug() << "test item path: " << it.getPath();
        qDebug() << "test item name: " << it.getName();

        items->append(it);
    }
    QFileInfo fileInfo("~/.oneline/custom_actions/Send_Email.oneline");
    Q_ASSERT(fileInfo.exists());
    QSettings s(fileInfo.absoluteFilePath(), QSettings::IniFormat);

    CatItem custI(&s);

//    CatItem custI("vTestCustomVerb", testCustomVerbStr, TEST_HASH);
//    custI.setCustomPluginValue(MIN_ARG_NUM_KEY,2);
//    custI.setCustomPluginInfo(VERB_ARG "1","built-in://long-text | body | %s");
//    custI.setCustomPluginInfo(VERB_ARG "2","tag://email-address | recipient(s) | to %s ");
//    custI.setCustomPluginInfo(VERB_ARG "3","tag://email-address | recipient(s) | to %s ");
//    custI.setCustomPluginInfo(CUSTOM_ACTION_KEY,"test_action.sh");

#endif

#ifdef TEST_GUI
    Q_ASSERT(items);
    CatItem ci("catalogTestItem", "testItem", TEST_HASH);
    ci.setExternalWeight(HIGH_EXTERNAL_WEIGHT,me);
    ci.addChild(CatItem("testCatalogChildItem", "testChild", TEST_HASH));
    items->append(ci);
    for(uint i=0; i < str_len;i++){
        QString out_str = str_list[i][1];
        CatItem it(out_str, out_str, TEST_HASH);
        items->append(it);
    }

    CatItem ci0("AHighttestResultItem", "AHighcustom",TEST_HASH);
    ci0.setExternalWeight(HIGH_EXTERNAL_WEIGHT,me);
    items->append(ci0);

    CatItem ci1("AtestResultSource", "Acustom",TEST_HASH);
    ci1.setItemType(CatItem::TAG);
    CatItem childI1("AtestResultChild", "nps_child",TEST_HASH);
    ci1.addChild(childI1);
    items->append(childI1);
    items->append(ci1);

    CatItem ci2("XtestResultSource", "Xcustom",TEST_HASH);
    ci2.setItemType(CatItem::TAG);
    CatItem childI2("XtestResultChild", "wmv_child",TEST_HASH);

    ci2.addChild(childI2);
    items->append(childI2);
    items->append(ci2);

    CatItem ci3("UtestResultSource", "Ucustom",TEST_HASH);
    ci3.setItemType(CatItem::TAG);
    CatItem childI3("UtestResultChild", "pst_child",TEST_HASH);

    ci3.addChild(childI3);
    items->append(ci3);
    items->append(childI3);

    for(uint i=0; i < fill_len;i++){
        QString out_str = fill_list[i][1];
        CatItem it(out_str, out_str, TEST_HASH);
        items->append(it);
    }

    CatItem it("tag item");
    it.setItemType(CatItem::OPERATION);
    it.setTakesAnykeys(true);

    for(int i=0; i< 20; i++){
        CatItem it(QString::number(i));
        ListItem li(it);
        for(int j=0; j< 30; j++){
            CatItem it2(numAsStr(i));
            ListItem li2(it2);
            li.setTotalWeight(abs(5000 - j*j*10 + i*i*i));
            li.addChild(li2);
            if(j % 3 ==0){
                tl.append(li2);
            }

        }
        if(i%5 ==0){
            tl.append(li);
        }
    }




#endif
}
/* ****************************************************************************
*
* put - 
*/
TEST(putAvailabilitySubscriptionConvOp, put)
{
  ConnectionInfo ci1("/ngsi9/contextAvailabilitySubscriptions",  "POST", "1.1");
  ConnectionInfo ci2("/ngsi9/contextAvailabilitySubscriptions",  "GET",  "1.1");
  ConnectionInfo ci3("/ngsi9/contextAvailabilitySubscriptions/111222333444555666777888",  "PUT",     "1.1");
  ConnectionInfo ci4("/ngsi9/contextAvailabilitySubscriptions/111222333444555666777888",  "DELETE",  "1.1");
  ConnectionInfo ci5("/ngsi9/contextAvailabilitySubscriptions/111222333444555666777881",  "PUT",     "1.1");
  ConnectionInfo ci6("/ngsi9/contextAvailabilitySubscriptions/012345678901234567890123",  "XVERB",   "1.1");
  const char*    infile1      = "ngsi9.subscribeContextAvailabilityRequest.ok.valid.xml";
  const char*    infile2      = "ngsi9.updateContextAvailabilitySubscriptionRequest.withSubId.valid.xml";
  const char*    outfile1     = "ngsi9.subscribeContextAvailabilityResponse.ok.middle.xml";
  const char*    outfile3     = "ngsi9.updateContextAvailabilitySubscriptionResponse.putAvailabilitySubscriptionConvOp.notFound.valid.xml";
  const char*    outfile4     = "ngsi9.unsubscribeContextAvailabilityResponse.putAvailabilitySubscriptionConvOp.notFound2.valid.xml";
  const char*    outfile5     = "ngsi9.updateContextAvailabilitySubscriptionResponse.putAvailabilitySubscriptionConvOp.unmatchingSubscriptionId.valid.xml";
  std::string    out;

  utInit();

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile1)) << "Error getting test data from '" << infile1 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";

  ci1.payload      = testBuf;
  ci1.payloadSize  = strlen(testBuf);
  out              = restService(&ci1, rs);

  char* outStart   = (char*) out.c_str();
  // Remove last char in expectedBuf
  expectedBuf[strlen(expectedBuf) - 1] = 0;

  // Shorten'out' to be of same length as expectedBuf
  outStart[strlen(expectedBuf)]    = 0;
  EXPECT_STREQ(expectedBuf, out.c_str());


  out = restService(&ci2, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci2.httpHeader[0]);
  EXPECT_EQ("POST",  ci2.httpHeaderValue[0]);


  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";

  ci3.payload      = testBuf;
  ci3.payloadSize  = strlen(testBuf);
  out              = restService(&ci3, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'";
  out = restService(&ci4, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile5)) << "Error getting test data from '" << outfile5 << "'";
  ci5.payload      = testBuf;
  ci5.payloadSize  = strlen(testBuf);
  out              = restService(&ci5, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  out = restService(&ci6, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci6.httpHeader[0]);
  EXPECT_EQ("PUT, DELETE", ci6.httpHeaderValue[0]);

  utExit();
}
示例#19
0
void test_constructors() {
  Constructors<int> ci1(17);
  Constructors<int> ci2 = ci1;
}