Пример #1
0
void testCreateLocalAuthFile(void)
{
    int testUid;
    int testGid;
    PEGASUS_TEST_ASSERT(
        GetUserInfo(PEGASUS_CIMSERVERMAIN_USER, &testUid, &testGid) == 0);

    /* Test with file path that already exists */
    {
        ssize_t result;
        const char* path = "testlocalauthfile";
        int fd = open(path, O_WRONLY | O_EXCL | O_CREAT | O_TRUNC, S_IRUSR);
        EXECUTOR_RESTART(write(fd, "test", 4), result);
        close(fd);
        PEGASUS_TEST_ASSERT(CreateLocalAuthFile(path, testUid, testGid) == 0);
        unlink(path);
    }

    /* Test with non-existent directory in file path */
    {
        const char* path =
            "/tmp/nonexistentdirectory/anotherone/pegasus/localauthtestfile";
        PEGASUS_TEST_ASSERT(CreateLocalAuthFile(path, testUid, testGid) != 0);
    }
}
Пример #2
0
void testCheckLocalAuthToken(void)
{
    /* Test with file path that does not exist */
    {
        const char* path = "nonexistenttestfile";
        PEGASUS_TEST_ASSERT(CheckLocalAuthToken(path, "secret") != 0);
    }

    /* Test with secret token that is too short */
    {
        ssize_t result;
        const char* path = "testlocalauthfile";
        int fd = open(path, O_WRONLY | O_EXCL | O_CREAT | O_TRUNC, S_IRUSR);
        EXECUTOR_RESTART(write(fd, "secret", 6), result);
        close(fd);
        PEGASUS_TEST_ASSERT(CheckLocalAuthToken(path, "secret") != 0);
        unlink(path);
    }

    /* Test with incorrect secret token */
    {
        ssize_t result;
        const char* path = "testlocalauthfile";
        int fd = open(path, O_WRONLY | O_EXCL | O_CREAT | O_TRUNC, S_IRUSR);
        EXECUTOR_RESTART(
            write(fd, "1234567890123456789012345678901234567890", 40), result);
        close(fd);
        PEGASUS_TEST_ASSERT(CheckLocalAuthToken(
            path, "123456789012345678901234567890123456789X") != 0);
        unlink(path);
    }
}
Пример #3
0
void
test04 (CIMClient & client)
{
  CIMObjectPath instanceName;

  instanceName.setNameSpace (providerNamespace);
  instanceName.setClassName (CLASSNAME);

  Array < CIMParamValue > inParams;
  Array < CIMParamValue > outParams;

  /*     [EmbeddedObject] String returnInstance(); */

  CIMValue retValue = client.invokeMethod (providerNamespace,
                       instanceName,
                       "returnInstance",
                       inParams,
                       outParams);

  PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT);
  PEGASUS_TEST_ASSERT (!retValue.isArray ());
  PEGASUS_TEST_ASSERT (!retValue.isNull ());

  CIMObject result;
  retValue.get (result);

  CIMObjectPath objPath  = result.getPath();
  PEGASUS_TEST_ASSERT (objPath.toString() == "TestCMPI_Instance");

}
Пример #4
0
void
test06 (CIMClient & client)
{
  CIMObjectPath instanceName;
  Uint32 exception  =0;
  instanceName.setNameSpace (providerNamespace);
  instanceName.setClassName (CLASSNAME);

  Array < CIMParamValue > inParams;
  Array < CIMParamValue > outParams;

  /*     String returnDateTime(); */
  try {
  CIMValue retValue = client.invokeMethod (providerNamespace,
                       instanceName,
                       "noSuchFunction",
                       inParams,
                       outParams);
  } catch (const CIMException &e)
  {
      exception ++;
    PEGASUS_TEST_ASSERT (e.getCode() == CIM_ERR_NOT_FOUND);
  }
  PEGASUS_TEST_ASSERT (exception == 1);
}
Пример #5
0
void _sendIndicationShouldBeBlocked 
    (CIMClient & client)
{
    Array <CIMParamValue> inParams;
    Array <CIMParamValue> outParams;
    Array <CIMKeyBinding> keyBindings;
    Sint32 result;

    CIMName methodName ("SendTestIndication");
    CIMObjectPath className (String::EMPTY, CIMNamespaceName (), 
        CIMName("Test_IndicationProviderClass"), keyBindings);

    try
    {
        CIMValue retValue = client.invokeMethod 
            (SOURCENAMESPACE,
            className,
            methodName,
            inParams,
            outParams);
        retValue.get (result);
        PEGASUS_TEST_ASSERT (false);
    }
    catch (CIMException & e)
    {
        PEGASUS_TEST_ASSERT (e.getCode () == CIM_ERR_NOT_SUPPORTED);
    }
}
Пример #6
0
void runCIMNameCastTests()
{
    try
    {
        CIMName name(CIMNameCast("Okay"));
    }
    catch (...)
    {
        PEGASUS_TEST_ASSERT(false);
    }

    Boolean caught = false;

    try
    {
        CIMName name(CIMNameCast("Not Okay"));
    }
    catch (InvalidNameException& e)
    {
        caught = true;
    }
    catch (...)
    {
        PEGASUS_TEST_ASSERT(false);
    }

#if defined(PEGASUS_DEBUG)
    PEGASUS_TEST_ASSERT(caught);
#else
    PEGASUS_TEST_ASSERT(!caught);
#endif
}
Пример #7
0
//Test reference array type properties
void test05()
{
    Array<CIMObjectPath> oa;
    oa.append(CIMObjectPath("/root/cimv2:My_Class.a=1"));
    oa.append(CIMObjectPath("/root/cimv2:My_Class.a=2"));
    CIMProperty p1;

    Boolean gotException = false;
    try
    {
        p1 = CIMProperty(CIMName("property1"), oa, 0, CIMName("refclass"));
    }
    catch (TypeMismatchException&)
    {
        gotException = true;
    }
    PEGASUS_TEST_ASSERT(gotException);

    p1 = CIMProperty(CIMName("property1"), oa[0], 0, CIMName("refclass"));
    gotException = false;
    try
    {
        p1.setValue(oa);
    }
    catch (TypeMismatchException&)
    {
        gotException = true;
    }
    PEGASUS_TEST_ASSERT(gotException);
}
Пример #8
0
// Test Thread and AtomicInt
void test02()
{
    const Uint32 numThreads = 64;
    AtomicInt * atom = new AtomicInt(0);
    Thread* threads[numThreads];

    (*atom)++;
    Boolean zero = atom->decAndTestIfZero();
    PEGASUS_TEST_ASSERT(zero);

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i] = new Thread(atomicIncrement, atom, false);
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->run();
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->join();
        delete threads[i];
    }

    PEGASUS_TEST_ASSERT(atom->get() == numThreads);
    delete atom;
}
Пример #9
0
int main (int argc, char** argv)
{
    String stringVal;
    verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false;

    CIMClient client;
    try
    {
        client.connectLocal ();
    }
    catch (Exception & e)
    {
        PEGASUS_STD (cerr) << e.getMessage () << PEGASUS_STD (endl);
        return -1;
    }

    _enumerateInstanceNames(client);
    _getInstance(client);
    _setProperty(client, 7890);
    _getProperty(client);
    // getProperty() only returns CIMValues of type String.
    value.get(stringVal);
    PEGASUS_TEST_ASSERT(atoi((const char*)stringVal.getCString())==7890);
    _setProperty(client,1234);
    _getProperty(client);
    // getProperty() only returns CIMValues of type String.
    // Verify that setProperty worked as expected.
    value.get(stringVal);
    PEGASUS_TEST_ASSERT(atoi((const char*)stringVal.getCString())==1234);

    return 0;
}
Пример #10
0
void testCleanupIdleThread()
{
    if (verbose)
    {
        cout << "testCleanupIdleThread" << endl;
    }

    try
    {
        struct timeval deallocateWait = { 0, 1 };
        ThreadPool threadPool(0, "test cleanup", 0, 6, deallocateWait);

        threadPool.allocate_and_awaken(
            (void*)1, funcSleepSpecifiedMilliseconds);
        Threads::sleep(1000);

        PEGASUS_TEST_ASSERT(threadPool.idleCount() == 1);
        threadPool.cleanupIdleThreads();
        PEGASUS_TEST_ASSERT(threadPool.idleCount() == 0);
    }
    catch (const Exception& e)
    {
        cout << "Exception in testCleanupIdleThread: " <<
             e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(false);
    }
}
Пример #11
0
PEGASUS_NAMESPACE_END

void CompareQualifiers(
    CIMRepository& r1,
    CIMRepository& r2,
    const CIMNamespaceName& namespaceName)
{
    Array<CIMQualifierDecl> quals1 = r1.enumerateQualifiers(namespaceName);
    Array<CIMQualifierDecl> quals2 = r2.enumerateQualifiers(namespaceName);
    PEGASUS_TEST_ASSERT(quals1.size() == quals2.size());

    BubbleSort(quals1);
    BubbleSort(quals2);

    for (Uint32 i = 0; i < quals2.size(); i++)
    {
        if (verbose)
        {
            cout << "testing qualifier " << namespaceName.getString() << "/";
            cout << quals1[i].getName().getString() << "/ against /";
            cout << quals2[i].getName().getString() << "/" << endl;
        }

        PEGASUS_TEST_ASSERT(quals1[i].identical(quals2[i]));
    }
}
Пример #12
0
void _checkStringValue (CIMValue & theValue,
    const String & value,
    Boolean null = false)
{
    PEGASUS_TEST_ASSERT (theValue.getType () == CIMTYPE_STRING);
    PEGASUS_TEST_ASSERT (!theValue.isArray ());
    if (null)
    {
        PEGASUS_TEST_ASSERT (theValue.isNull ());
    }
    else
    {
        PEGASUS_TEST_ASSERT (!theValue.isNull ());
        String result;
        theValue.get (result);

        if (verbose)
        {
            if (result != value)
            {
                cerr << "Property value comparison failed.  ";
                cerr << "Expected " << value << "; ";
                cerr << "Actual property value was " << result << "." << endl;
            }
        }

        PEGASUS_TEST_ASSERT (result == value);
    }
}
Пример #13
0
void testInstancesTransfer(
    CIMRepository& oldRepository,
    CIMRepository& newRepository,
    const CIMNamespaceName& ns,
    const CIMName& className)
{
    Array<CIMInstance> i1 =
        oldRepository.enumerateInstancesForClass(ns, className);
    Array<CIMInstance> i2 =
        newRepository.enumerateInstancesForClass(ns, className);

    PEGASUS_TEST_ASSERT(i1.size() == i2.size());

    for (Uint32 i = 0; i < i1.size(); i++)
    {
        Boolean found = false;

        for (Uint32 j = 0; j < i2.size(); j++)
        {
            if (i1[i].identical(i2[j]))
            {
                found = true;
                break;
            }
        }

        PEGASUS_TEST_ASSERT(found);
    }
}
Пример #14
0
void
test_async_queue::async_handleEnqueue (AsyncOpNode * op,
                                       MessageQueue * q, void *parm)
{

  // I am static, get a pointer to my object 
  test_async_queue *myself = static_cast < test_async_queue * >(q);

  async_start *rq = static_cast < async_start * >(op->removeRequest());
  PEGASUS_TEST_ASSERT(rq != 0);

  async_complete *rp = static_cast < async_complete * >(op->removeResponse());
  PEGASUS_TEST_ASSERT(rp != 0);

  if ((rq->getType () == ASYNC_ASYNC_OP_START) &&
      (rp->getType () == ASYNC_ASYNC_OP_RESULT))
    {
      Message *cim_rq = rq->get_action ();
      Message *cim_rp = rp->get_result_data ();

      PEGASUS_TEST_ASSERT (cim_rq->getType () ==
                           CIM_GET_INSTANCE_REQUEST_MESSAGE);
      PEGASUS_TEST_ASSERT (cim_rp->getType () ==
                      CIM_GET_INSTANCE_RESPONSE_MESSAGE);
      test_async_queue::msg_count++;

      delete cim_rp;
      delete cim_rq;
      delete rp;
      delete rq;
      delete op;
    }
}
void _checkUint32Property
  (CIMInstance & instance, const String & name, Uint32 value)
{
  Uint32 pos = instance.findProperty (name);
  PEGASUS_TEST_ASSERT (pos != PEG_NOT_FOUND);

  CIMProperty theProperty = instance.getProperty (pos);
  CIMValue theValue = theProperty.getValue ();

  PEGASUS_TEST_ASSERT (theValue.getType () == CIMTYPE_UINT32);
  PEGASUS_TEST_ASSERT (!theValue.isArray ());
  PEGASUS_TEST_ASSERT (!theValue.isNull ());
  Uint32 result;
  theValue.get (result);

  if (verbose)
    {
      if (result != value)
        {
          cerr << "Property value comparison failed.  ";
          cerr << "Expected " << value << "; ";
          cerr << "Actual property value was " << result << "." << endl;
        }
    }

  PEGASUS_TEST_ASSERT (result == value);
}
Пример #16
0
void
test_async_queue::_handle_async_request (AsyncRequest * rq)
{
  if ((rq->getType () == ASYNC_ASYNC_OP_START) ||
      (rq->getType () == ASYNC_ASYNC_LEGACY_OP_START))
    {  
     try {
      PEGASUS_TEST_ASSERT (_role == SERVER);
      Message *response_data =
        new Message (CIM_GET_INSTANCE_RESPONSE_MESSAGE);
      async_complete *response_msg =
        new async_complete (static_cast < async_start & >(*rq),
                            async_results::OK,
                            response_data);
      _complete_op_node (rq->op);
    } catch (const PEGASUS_STD(bad_alloc) &)
    {
        cerr <<" Out of memory!" << endl;
    }
    }
  else if (rq->getType () == ASYNC_CIMSERVICE_STOP)
    {
      PEGASUS_TEST_ASSERT (_role == SERVER);
      _handle_stop ((CimServiceStop *) rq);
    }
  else
    Base::_handle_async_request (rq);
}
Пример #17
0
void TestQualifiers()
{
    // -- Create repository and qualifier test namespace:

    const CIMNamespaceName QNS = CIMNamespaceName ("TestQualifiers");

    try
    {
        r->createNameSpace(QNS);
    }
    catch (AlreadyExistsException&)
    {
        // Ignore this!
    }

    // -- Construct a qualifier declaration:

    CIMQualifierDecl q(CIMName ("abstract"), true, CIMScope::CLASS);
    r->setQualifier(QNS, q);

    CIMQualifierDecl qq = r->getQualifier(QNS, CIMName ("abstract"));

    PEGASUS_TEST_ASSERT(qq.identical(q));
    PEGASUS_TEST_ASSERT(q.identical(qq));

    // -- Delete the qualifier:

    r->deleteQualifier(QNS, CIMName ("abstract"));

    // -- Delete the namespace:

    r->deleteNameSpace(QNS);
}
Пример #18
0
void _testHostedIndicationServiceInstance(CIMClient &client)
{
    cout << "Testing Association Class "
        << (const char *)PEGASUS_CLASSNAME_PG_HOSTEDINDICATIONSERVICE.
             getString().getCString()
        << "...";
    // Get PG_HostedIndicationService Instances
    Array<CIMInstance> hostedInstances = client.enumerateInstances(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_HOSTEDINDICATIONSERVICE);
    PEGASUS_TEST_ASSERT(hostedInstances.size() == 1);

    // Get PG_HostedIndicationService Instance names
    Array<CIMObjectPath> hostedPaths = client.enumerateInstanceNames(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_HOSTEDINDICATIONSERVICE);
    PEGASUS_TEST_ASSERT(hostedPaths.size() == 1);

    // Get CIM_IndicationService instance names
    Array<CIMObjectPath> servicePaths = client.enumerateInstanceNames(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE);
    PEGASUS_TEST_ASSERT(servicePaths.size() == 1);

    // Test the CIM_IndicationService value.
    CIMValue capValue = hostedInstances[0].getProperty(
        hostedInstances[0].findProperty("Dependent")).getValue();
    CIMObjectPath testPath;
    capValue.get(testPath);
    testPath.setNameSpace(CIMNamespaceName());
    PEGASUS_TEST_ASSERT(testPath.identical(servicePaths[0]));

    cout << "Test Complete" << endl;
}
void _checkUint64Property
  (CIMInstance & instance, const String & name, Uint64 value)
{
  Uint32 pos = instance.findProperty (name);
  PEGASUS_TEST_ASSERT (pos != PEG_NOT_FOUND);

  CIMProperty theProperty = instance.getProperty (pos);
  CIMValue theValue = theProperty.getValue ();

  PEGASUS_TEST_ASSERT (theValue.getType () == CIMTYPE_UINT64);
  PEGASUS_TEST_ASSERT (!theValue.isArray ());
  PEGASUS_TEST_ASSERT (!theValue.isNull ());
  Uint64 result;
  theValue.get (result);

  if (verbose)
    {
      if (result != value)
        {
          char buffer[32];      // Should need 21 chars max
          sprintf (buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", value);
          cerr << "Property value comparison failed.  ";
          cerr << "Expected " << buffer << "; ";
          sprintf (buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", result);
          cerr << "Actual property value was " << buffer << "." << endl;
        }
    }

  PEGASUS_TEST_ASSERT (result == value);
}
Пример #20
0
void
test_async_queue::_handle_async_callback (AsyncOpNode * op)
{
  PEGASUS_TEST_ASSERT (_role == CLIENT);

  PEGASUS_TEST_ASSERT (op->getState() & ASYNC_OPSTATE_COMPLETE);

  Base::_handle_async_callback (op);
}
Пример #21
0
void callMethod(const CIMName& methodName)
{
    try
    {
        CIMClient client;
        client.connectLocal();

        Array<CIMParamValue> inParams;
        Array<CIMParamValue> outParams;

        CIMObjectPath instName =
            CIMObjectPath("Test_MethodProviderClass.Id=1");

        inParams.append(CIMParamValue("InParam1", Uint32(1)));
        inParams.append(CIMParamValue("InParam2", Uint32(2)));

        CIMValue returnValue = client.invokeMethod(
            NAMESPACE,
            instName,
            methodName,
            inParams,
            outParams);

        Uint32 rc;
        returnValue.get(rc);
        PEGASUS_TEST_ASSERT(rc == 10);

        PEGASUS_TEST_ASSERT(outParams.size() == 2);

        Uint32 outParam1 = 0;
        Uint32 outParam2 = 0;

        for (Uint32 i = 0; i < 2; i++)
        {
            if (outParams[i].getParameterName() == "OutParam1")
            {
                outParams[i].getValue().get(outParam1);
            }
            else if (outParams[i].getParameterName() == "OutParam2")
            {
                outParams[i].getValue().get(outParam2);
            }
            else
            {
                PEGASUS_TEST_ASSERT(0);
            }
        }
        PEGASUS_TEST_ASSERT(outParam1 == 21);
        PEGASUS_TEST_ASSERT(outParam2 == 32);
    }
    catch (Exception& e)
    {
        cerr << "Error: " << e.getMessage() << endl;
        exit(1);
    }
}
void drive_Schema(QueryContext& _query)
{
    CIMName base("CQL_TestElement");
    CIMClass _class = _query.getClass(base);
    PEGASUS_TEST_ASSERT(_class.getClassName() == base);

    Array<CIMName> names = _query.enumerateClassNames(base);
    PEGASUS_TEST_ASSERT(names.size() == 2);

    CIMName derived("CQL_TestPropertyTypes");

    PEGASUS_TEST_ASSERT(_query.isSubClass(base, derived));
    PEGASUS_TEST_ASSERT(!_query.isSubClass(derived, base));

    PEGASUS_TEST_ASSERT(
        _query.getClassRelation(base, base) == QueryContext::SAMECLASS);
    PEGASUS_TEST_ASSERT(
        _query.getClassRelation(base, derived) == QueryContext::SUBCLASS);
    PEGASUS_TEST_ASSERT(
        _query.getClassRelation(derived, base) == QueryContext::SUPERCLASS);

    CIMName unrelated("CIM_Process");
    PEGASUS_TEST_ASSERT(
        _query.getClassRelation(base, unrelated) == QueryContext::NOTRELATED);
    PEGASUS_TEST_ASSERT(
        _query.getClassRelation(unrelated, base) == QueryContext::NOTRELATED);
}
Пример #23
0
void testSharedArrayPtr()
{
    Monkey::numConstructions = 0;
    Monkey::numDestructions = 0;

    {
        SharedArrayPtr<Monkey> p1(new Monkey[3]);

        PEGASUS_TEST_ASSERT(Monkey::numConstructions == 3);
        PEGASUS_TEST_ASSERT(Monkey::numDestructions == 0);

        SharedArrayPtr<Monkey> p5(new Monkey[2]);
        p1 = p5;

        PEGASUS_TEST_ASSERT(Monkey::numConstructions == 5);
        PEGASUS_TEST_ASSERT(Monkey::numDestructions == 3);

        PEGASUS_TEST_ASSERT(p1[0].index == p5[0].index);
        PEGASUS_TEST_ASSERT(p1[1].index == p5[1].index);
        PEGASUS_TEST_ASSERT(p1[0].index != p1[1].index);
    }

    PEGASUS_TEST_ASSERT(Monkey::numConstructions == 5);
    PEGASUS_TEST_ASSERT(Monkey::numDestructions == 5);
}
Пример #24
0
void testClearMethod()
{
    // Test with a variety of object types in the From ResponseData
    // Build the class
    CIMClass CIMclass1 = buildClass();

    // Build a CIM Instance. NOTE: key is defaulted in class

    CIMInstance CIMInst1 = CIMclass1.buildInstance(true, true,
                                                   CIMPropertyList());

        // Clone the instance and change key
    CIMInstance CIMInst2 = CIMInst1.clone();
    setPropertyValue(CIMInst2, "id", 2);

    CIMInstance CIMInst3 = CIMInst1.clone();
    setPropertyValue(CIMInst3, "id", 3);
    CIMInstance CIMInst4 = CIMInst1.clone();
    setPropertyValue(CIMInst4, "id", 4);

    // build CIMInstance array
    Array<CIMInstance> CIMInstArray;
    CIMInstArray.append(CIMInst1);
    CIMInstArray.append(CIMInst2);
    CIMInstArray.append(CIMInst3);
    CIMInstArray.append(CIMInst4);

    // Create CIMReponseData object
    CIMResponseData crd = CIMResponseData(CIMResponseData::RESP_INSTANCES);

    // Append an array of CIMInstances
    crd.appendInstances(CIMInstArray);
    PEGASUS_TEST_ASSERT(crd.size() == 4);

    // Build SCMO instances
    SCMOClass SCMO_CSClass(CIMclass1);

    VCOUT << "Creating SCMOInstance from CIMInstance" << endl;
    SCMOInstance SCMO_CSInstance3(SCMO_CSClass,CIMInst3);
    SCMOInstance SCMO_CSInstance4(SCMO_CSClass,CIMInst4);

    // Create array of 2 SCMO Instances
    Array<SCMOInstance> SCMOInstArray;
    SCMOInstArray.append(SCMO_CSInstance3);
    SCMOInstArray.append(SCMO_CSInstance4);
    crd.appendSCMO(SCMOInstArray);

    PEGASUS_TEST_ASSERT(crd.size() == 6);

    crd.clear();

    PEGASUS_TEST_ASSERT(crd.size() == 0);
}
Пример #25
0
//Test reference type properties
void test04()
{
    // Create reference type property from string input and reference class name
    String p =  "//localhost/root/SampleProvider:"
                "TST_PersonDynamic.Name=\"Father\"";
    CIMObjectPath path = p;
        
    String referenceClassName = "TST_Person";
    CIMProperty p1(CIMName ("message"), path, 0,
                   CIMName(referenceClassName));
    PEGASUS_TEST_ASSERT(!p1.isArray());
    PEGASUS_TEST_ASSERT(p1.getReferenceClassName()==
                        CIMName(referenceClassName));
    PEGASUS_TEST_ASSERT(p1.getType() == CIMTYPE_REFERENCE);
    
    CIMValue v1;
    v1 = p1.getValue();
    PEGASUS_TEST_ASSERT(v1.getType() ==  CIMTYPE_REFERENCE);
    PEGASUS_TEST_ASSERT(!v1.isNull());
    CIMObjectPath pathout;
    v1.get(pathout);
    PEGASUS_TEST_ASSERT( pathout == path );

    if(verbose)
        XmlWriter::printPropertyElement(p1, cout);

    // Now create an empty property, one used in class declaration
    // for a reference
    CIMProperty p2(CIMName ("parent"), CIMObjectPath(),
                   0, CIMName(referenceClassName));
    PEGASUS_TEST_ASSERT(!p2.isArray());
    PEGASUS_TEST_ASSERT(p2.getReferenceClassName() ==
                         CIMName(referenceClassName));
    PEGASUS_TEST_ASSERT(p2.getType() == CIMTYPE_REFERENCE);

    CIMValue v2;
    v2 = p2.getValue();
    PEGASUS_TEST_ASSERT(v2.getType() ==  CIMTYPE_REFERENCE);

    // ATTN: P3 KS 27 Feb 2003. Why does the following test not work.
    // I assume that the value should
    // be null in this case.
    //PEGASUS_TEST_ASSERT(v2.isNull());

    CIMObjectPath pathout2;
    v1.get(pathout2);
    // Now compare the paths

    
    if(verbose)
        XmlWriter::printPropertyElement(p2, cout);
}
Пример #26
0
void _checkResult(const Array<CIMInstance> & instArr)
{
    // provider returns exactly six instances
    PEGASUS_TEST_ASSERT(6==instArr.size());

    for (int i=0; i<6;i++)
    {
        const CIMObjectPath& objPath = instArr[i].getPath();
        const Array<CIMKeyBinding>& keyBinds = objPath.getKeyBindings();

        // instance should have three key bindings
        PEGASUS_TEST_ASSERT(3==keyBinds.size());
    }
}
Пример #27
0
void testCIMOMHandle()
{
    ProviderStatus status;
    status.setInitialized(true);

    status.setCIMOMHandle((CIMOMHandle*) 10);
    PEGASUS_TEST_ASSERT(status.getCIMOMHandle() == (CIMOMHandle*) 10);

    status.setInitialized(false);
    PEGASUS_TEST_ASSERT(status.getCIMOMHandle() == 0);

    status.setInitialized(true);
    CIMOMHandle cimomHandle;
    status.setCIMOMHandle(&cimomHandle);
    PEGASUS_TEST_ASSERT(status.isIdle());

    cimomHandle.disallowProviderUnload();
    PEGASUS_TEST_ASSERT(!status.isIdle());
    cimomHandle.disallowProviderUnload();
    PEGASUS_TEST_ASSERT(!status.isIdle());
    cimomHandle.allowProviderUnload();
    PEGASUS_TEST_ASSERT(!status.isIdle());
    cimomHandle.allowProviderUnload();
    PEGASUS_TEST_ASSERT(status.isIdle());

    // An extra allowProviderUnload() call should be ignored
    cimomHandle.allowProviderUnload();
    PEGASUS_TEST_ASSERT(status.isIdle());
}
Пример #28
0
// Test handling of escape characters
void test05()
{
    {
        // Test '\' and '"' characters in a key value
        // This represents MyClass.key1="\\\"\"\\",key2="\"\"\"\"\\\\\\\\"
        String s1 = "MyClass.key1=\"\\\\\\\"\\\"\\\\\","
                "key2=\"\\\"\\\"\\\"\\\"\\\\\\\\\\\\\\\\\"";
        CIMObjectPath r1 = s1;
        PEGASUS_TEST_ASSERT(r1.toString() == s1);
    }

    // Catch invalid escape sequences in a key value
    Boolean errorDetected;

    // Invalid trailing backslash
    errorDetected = false;
    try
    {
        CIMObjectPath r1("MyClass.key1=\"\\\"");
    }
    catch (const MalformedObjectNameException&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    // Invalid "\n" sequence
    errorDetected = false;
    try
    {
        CIMObjectPath r1("MyClass.key1=\"\\n\"");
    }
    catch (const MalformedObjectNameException&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    // Invalid hex sequence
    errorDetected = false;
    try
    {
        CIMObjectPath r1("MyClass.key1=\"\\x000A\"");
    }
    catch (const MalformedObjectNameException&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);
}
Пример #29
0
void testUserContextRequestor()
{
    try
    {
        CIMClient client;
        client.connectLocal();

        // Determine whether the CIM Server has authentication enabled

        CIMObjectPath authConfigInstName = CIMObjectPath(
            "PG_ConfigSetting.PropertyName=\"enableAuthentication\""); 
        CIMInstance authConfigInst =
            client.getInstance("root/PG_Internal", authConfigInstName);

        String authConfigValue;
        authConfigInst.getProperty(authConfigInst.findProperty("CurrentValue"))
            .getValue().get(authConfigValue);
        Boolean authenticationEnabled =
            String::equalNoCase(authConfigValue, "true");

        // Test a provider running in Requestor user context

        CIMObjectPath instName =
            CIMObjectPath("TST_UserContextRequestor.Id=1");
        CIMInstance cimInstance = client.getInstance(NAMESPACE, instName);

        String userContext;
        cimInstance.getProperty(cimInstance.findProperty("UserContext"))
            .getValue().get(userContext);

        if (verbose)
        {
            cout << "Requestor test: UserContext = " << userContext << endl;
        }

        if (authenticationEnabled)
        {
            PEGASUS_TEST_ASSERT(userContext == System::getEffectiveUserName());
        }
        else
        {
            PEGASUS_TEST_ASSERT(userContext == serverUserContext);
        }
    }
    catch (Exception& e)
    {
        cerr << "Error: " << e.getMessage() << endl;
        exit(1);
    }
}
Пример #30
0
void _testServiceAffectsElementInstances(CIMClient &client)
{
    cout << "Testing Association Class "
        << (const char *)PEGASUS_CLASSNAME_PG_SERVICEAFFECTSELEMENT.
             getString().getCString()
        << "...";

    // Get PG_ServiceAffectsElement instances.
    Array<CIMInstance> sfInstances = client.enumerateInstances(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_SERVICEAFFECTSELEMENT);

    // Get PG_ServiceAffectsElement instance names
    Array<CIMObjectPath> sfPaths = client.enumerateInstanceNames(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_SERVICEAFFECTSELEMENT);

    PEGASUS_TEST_ASSERT(sfInstances.size() == sfPaths.size());

    // Get CIM_IndicationFilter instance names
    Array<CIMObjectPath> filterPaths = client.enumerateInstanceNames(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_INDFILTER);

    // Get CIM_ListenerDestination instance names
    Array<CIMObjectPath> handlerPaths = client.enumerateInstanceNames(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_LSTNRDST);

    // Count only handlers and filters from interop namespace
    Uint32 elements = 0;
    for (Uint32 i = 0; i < sfInstances.size() ; ++i)
    {
        CIMValue value = sfInstances[i].getProperty(
            sfInstances[i].findProperty("AffectedElement")).getValue();
        CIMObjectPath path;
        value.get(path);
        PEGASUS_TEST_ASSERT(path.getNameSpace() != CIMNamespaceName());
        if (path.getNameSpace() == PEGASUS_NAMESPACENAME_INTEROP)
        {
             elements++;
        }
    }
    PEGASUS_TEST_ASSERT(
        elements == (filterPaths.size() + handlerPaths.size()));

    cout << "Test Complete" << endl;
}