Boolean OperatingSystem::getLastBootUpTime(CIMDateTime& lastBootUpTime)
{
    Uint64 sysUpTime = 0;

    if(getSystemUpTime(sysUpTime))
    {
        // convert sysUpTime to microseconds
        sysUpTime *= (1000 * 1000);

        CIMDateTime currentTime = CIMDateTime::getCurrentDateTime();
        CIMDateTime bootTime =
            CIMDateTime(currentTime.toMicroSeconds() - sysUpTime, false);

        // adjust UTC offset
        String s1 = currentTime.toString();
        String s2 = bootTime.toString();

        s2[20] = s1[20];
        s2[21] = s1[21];
        s2[22] = s1[22];
        s2[23] = s1[23];

        lastBootUpTime = CIMDateTime(s2);

        return true;
    }

    return false;
}
Boolean OperatingSystem::getLocalDateTime(CIMDateTime& localDateTime)
{
    SYSTEMTIME time;
    Sint16 currentTimeZone;

    ::memset(&time, 0, sizeof(time));

    ::GetLocalTime(&time);

    std::stringstream ss;

    ss << std::setfill('0');
    ss << std::setw(4) << time.wYear;
    ss << std::setw(2) << time.wMonth;
    ss << std::setw(2) << time.wDay;
    ss << std::setw(2) << time.wHour;
    ss << std::setw(2) << time.wMinute;
    ss << std::setw(2) << time.wSecond;
    ss << ".";
    ss << std::setw(6) << time.wMilliseconds * 1000;
    if (getCurrentTimeZone(currentTimeZone))
    {
        ss << (currentTimeZone < 0 ? "-" : "+");
    }
    ss << std::setw(3) << ::abs(currentTimeZone);

    localDateTime = CIMDateTime (String (ss.str().c_str()));

    return true;
}
Beispiel #3
0
void drive_get_misc_functions()
{

    try {
        // Get function tests
        CQLValue a1(Uint64(123));
        CQLValue a2(Sint64(-123));
        CQLValue a3(Real64(25.24));
        CQLValue a4(String("Hellow"));
        CQLValue a5(Boolean(true));

        String _date("20040811105625.000000-360");
        CIMDateTime date(_date);
        CQLValue a6(date);
        String _date1("20040811105626.000000-360");
        CIMDateTime date1(_date1);
        CQLValue a61(date1);

        String opStr("MyClass.z=true,y=1234,x=\"Hello World\"");
        CIMObjectPath op(opStr);
        CQLValue a7(op);

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

        CQLValue a8(_i1);

        PEGASUS_TEST_ASSERT(a1.getUint() == Uint64(123));
        PEGASUS_TEST_ASSERT(a2.getSint() == Sint64(-123));
        PEGASUS_TEST_ASSERT(a3.getReal() == Real64(25.24));
        PEGASUS_TEST_ASSERT(a4.getString() == String("Hellow"));
        PEGASUS_TEST_ASSERT(a5.getBool() == Boolean(true));
        PEGASUS_TEST_ASSERT(a6.getDateTime() == CIMDateTime(_date));
        PEGASUS_TEST_ASSERT(a6 != a61);
        PEGASUS_TEST_ASSERT(a6 < a61);
        PEGASUS_TEST_ASSERT(a7.getReference() ==
                            CIMObjectPath(opStr));

        try
        {
            a1.getSint();
            PEGASUS_TEST_ASSERT(0);
        }
        catch(...)
        {
            PEGASUS_TEST_ASSERT(1);
        }
    }
    catch(Exception & e)
    {
        cout << e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }

    return;
}
Beispiel #4
0
IndicationDispatchEvent::IndicationDispatchEvent(OperationContext context,
                                                 String url,
                                                 CIMInstance instance) :
_context(context),
_url(url),
_instance(instance),
_retries(0),
_lastAttemptTime(CIMDateTime())
{
}
Beispiel #5
0
Boolean CIMKeyBinding::equal(CIMValue value)
{
    if (value.isArray())
    {
        return false;
    }

    CIMValue kbValue;

    try
    {
        switch (value.getType())
        {
        case CIMTYPE_CHAR16:
            if (getType() != STRING) return false;
            kbValue.set(getValue()[0]);
            break;
        case CIMTYPE_DATETIME:
            if (getType() != STRING) return false;
            kbValue.set(CIMDateTime(getValue()));
            break;
        case CIMTYPE_STRING:
            if (getType() != STRING) return false;
            kbValue.set(getValue());
            break;
        case CIMTYPE_REFERENCE:
            if (getType() != REFERENCE) return false;
            kbValue.set(CIMObjectPath(getValue()));
            break;
        case CIMTYPE_BOOLEAN:
            if (getType() != BOOLEAN) return false;
            kbValue = XmlReader::stringToValue(0, getValue().getCString(),
                                               value.getType());
            break;
//      case CIMTYPE_REAL32:
//      case CIMTYPE_REAL64:
        case CIMTYPE_OBJECT:
        case CIMTYPE_INSTANCE:
            // From PEP 194: EmbeddedObjects cannot be keys.
            return false;
        default:  // Numerics
            if (getType() != NUMERIC) return false;
            kbValue = XmlReader::stringToValue(0, getValue().getCString(),
                                               value.getType());
            break;
        }
    }
    catch (Exception&)
    {
        return false;
    }

    return value.equal(kbValue);
}
PEGASUS_NAMESPACE_BEGIN

CIMDateTime CIMDateTime::getCurrentDateTime()
{
    char dateTimeBuffer[26];
    time_t systemTime;
    struct tm* tmval;
    struct tm tmvalBuffer;
    int tzMinutesEast;

    // Get the system date and time
    systemTime = time(NULL);

    // Get the localtime
    tmval = localtime_r(&systemTime, &tmvalBuffer);
    PEGASUS_ASSERT(tmval != 0);

    // Get the UTC offset
#if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
    tzMinutesEast =
        - (int)((tmval->tm_isdst > 0 && daylight) ? altzone : timezone) / 60;
#elif defined(PEGASUS_OS_HPUX)
    tzMinutesEast = - (int) timezone / 60;
    if ((tmval->tm_isdst > 0) && daylight)
    {
        // ATTN: It is unclear how to determine the DST offset.  Assume 1 hour.
        tzMinutesEast += 60;
    }
#elif defined(PEGASUS_OS_LINUX)
    tzMinutesEast = (int) tmval->tm_gmtoff/60;
#else
    struct timeval tv;
    struct timezone tz;
    gettimeofday(&tv, &tz);
    tzMinutesEast = -tz.tz_minuteswest;
#endif

    // Format the date
    sprintf(
        dateTimeBuffer,
        "%04d%02d%02d%02d%02d%02d.%06ld%+04d",
        1900 + tmval->tm_year,
        tmval->tm_mon + 1,
        tmval->tm_mday,
        tmval->tm_hour,
        tmval->tm_min,
        tmval->tm_sec,
        0L,    // localtime_r does not return sub-second data
        tzMinutesEast);

    return CIMDateTime(dateTimeBuffer);
}
CIMDateTime CIMHelper::extractDateTimeParameter(const Array<CIMParamValue>& inParameters, String name)
{
    for(Uint32 i = 0; i < inParameters.size(); i++)
    {
    	CIMParamValue paramValue = inParameters[i];
    	CIMName paramName = paramValue.getParameterName();
    	if (paramName.equal(name))
    	{
    		CIMDateTime value;
    		paramValue.getValue().get(value);
    		return value;
    	}
    }
    return CIMDateTime();
}
CIMDateTime UNIX_ApplicationSystem::getLastServingStatusUpdate() const
{
	struct tm* clock;			// create a time structure
	time_t val = time(NULL);
	clock = gmtime(&(val));	// Get the last modified time and put it into the time structure
	return CIMDateTime(
		clock->tm_year + 1900,
		clock->tm_mon + 1,
		clock->tm_mday,
		clock->tm_hour,
		clock->tm_min,
		clock->tm_sec,
		0,0,
		clock->tm_gmtoff);
}
CIMDateTime UNIX_ComputerSystem::getTimeOfLastStateChange() const
{
	struct tm* clock;			// create a time structure
	time_t val = time(NULL);
	clock = gmtime(&(val));	// Get the last modified time and put it into the time structure
	return CIMDateTime(
		clock->tm_year + 1900,
		clock->tm_mon + 1,
		clock->tm_mday,
		clock->tm_hour,
		clock->tm_min,
		clock->tm_sec,
		0,0,
		clock->tm_gmtoff);
}
CIMDateTime UNIX_ClusteringService::getInstallDate() const
{
	struct tm* clock;			// create a time structure
	time_t val = time(NULL);
	clock = gmtime(&(val));	// Get the last modified time and put it into the time structure
	return CIMDateTime(
		clock->tm_year + 1900,
		clock->tm_mon + 1,
		clock->tm_mday,
		clock->tm_hour,
		clock->tm_min,
		clock->tm_sec,
		0,0,
		clock->tm_gmtoff);
}
CIMDateTime SambaService::getTimeOfLastStateChange() const
{
	struct tm* clock;			// create a time structure
	struct stat attrib;			// create a file attribute structure
	stat("/etc/passwd", &attrib);		// get the attributes /etc/passwd
	clock = gmtime(&(attrib.st_mtime));	// Get the last modified time and put it into the time structure
	return CIMDateTime(
		clock->tm_year + 1900,
		clock->tm_mon + 1,
		clock->tm_mday,
		clock->tm_hour,
		clock->tm_min,
		clock->tm_sec,
		0,0,
		clock->tm_gmtoff);
}
CIMDateTime CIMHelper::getCurrentTime()
{
  time_t t = time(0);
  struct tm* clock;			// create a time structure
  clock = gmtime(&(t));	// Get the last modified time and put it into the time structure
  return CIMDateTime(
  	clock->tm_year + 1900, 
	clock->tm_mon + 1, 
	clock->tm_mday,
	clock->tm_hour,
	clock->tm_min,
	clock->tm_sec,
	0,0,
	clock->tm_gmtoff	
  );
}
CIMDateTime CIMHelper::getInstallDate(String path)
{
	struct tm* clock;			// create a time structure
	struct stat attrib;			// create a file attribute structure
	stat(path.getCString(), &attrib);		// get the attributes mnt
	clock = gmtime(&(attrib.st_birthtime));	// Get the last modified time and put it into the time structure
	return CIMDateTime(
		clock->tm_year + 1900,
		clock->tm_mon + 1,
		clock->tm_mday,
		clock->tm_hour,
		clock->tm_min,
		clock->tm_sec,
		0,0,
		clock->tm_gmtoff);
}
int createErrorInstance(CIMClient& client)
{
    // Build the embedded instance
    Array<CIMKeyBinding> embeddedPathKeys;
    CIMName key1Name("key1");
    CIMValue key1Value(String("fake-key1"));
    CIMName key2Name("key2");
    CIMValue key2Value(String("fake-key2"));

    embeddedPathKeys.append(CIMKeyBinding(key1Name, key1Value));
    embeddedPathKeys.append(CIMKeyBinding(key2Name, key2Value));

    CIMObjectPath embeddedPath(
        "localhost",
        TEST_NAMESPACE,
        CIMName("PG_EmbeddedClass"),
        embeddedPathKeys);

    embeddedInstance.reset(new CIMInstance(CIMName("PG_EmbeddedClass")));
    //embeddedInstance->setPath(embeddedPath);
    embeddedInstance->addProperty(CIMProperty(key1Name,
        key1Value));
    embeddedInstance->addProperty(CIMProperty(key2Name,
        key2Value));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop01"),
        Uint8(234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop02"),
        Uint16(16234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop03"),
        Uint32(32234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop04"),
        Uint64(64234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop05"),
        Sint8(-234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop06"),
        Sint16(-16234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop07"),
        Sint32(-32234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop08"),
        Sint64(-64234)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop09"),
        Real32(-64234.46)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop10"),
        Real64(-23464234.78)));
    embeddedInstance->addProperty(CIMProperty(CIMName("prop11"),
        CIMDateTime(60, true)));

    // Build the embedded instance
    Array<CIMKeyBinding> errorPathKeys;
    CIMName errorKeyName("errorKey");
    CIMValue errorKeyValue(String("error key 1"));
    errorPathKeys.append(CIMKeyBinding(errorKeyName, errorKeyValue));
    CIMObjectPath localErrorPath(
        "localhost",
        TEST_NAMESPACE,
        CIMName("PG_EmbeddedError"),
        errorPathKeys);
    errorInstance.reset(new CIMInstance(CIMName("PG_EmbeddedError")));
    errorInstance->setPath(localErrorPath);
    errorInstance->addProperty(CIMProperty(errorKeyName,
        errorKeyValue));
    errorInstance->addProperty(CIMProperty(CIMName("EmbeddedInst"),
        CIMValue(*embeddedInstance)));
    try
    {
        errorPath = client.createInstance(TEST_NAMESPACE, *errorInstance);
        PEGASUS_STD(cout) << "Created EmbeddedError: " << errorPath.toString()
            << PEGASUS_STD(endl);
        errorInstance->setPath(errorPath);
    }
    catch (Exception& e)
    {
        PEGASUS_STD(cout) << "Exception while creating Error Instance: "
            << e.getMessage() << PEGASUS_STD(endl);
        return -1;
    }

    return 0;
}
Beispiel #15
0
int main(int argc, char** argv)
{
#ifdef IO
    verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false;
    if (verbose)
    cout << "Test CIMValue. To turn off display, compile with IO undefined\n";
#endif
    // Test the primitive CIMValue types with test01
    test01(Boolean(true));
    test01(Boolean(false));
    test01(Char16('Z'));
    test01(Uint8(77));
    test01(Sint8(-77));
    test01(Sint16(77));
    test01(Uint16(-77));
    test01(Sint32(77));
    test01(Uint32(-77));
    test01(Sint64(77));
    test01(Uint64(-77));
    test01(Real32(1.5));
    test01(Real64(55.5));
    test01(Uint64(123456789));
    test01(Sint64(-123456789));
    test01(String("Hello world"));
    test01(CIMDateTime("19991224120000.000000+360"));
    test01(CIMObjectPath(
        "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\""));

    // Create and populate a declaration context:

    const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/zzz");

    SimpleDeclContext* context = new SimpleDeclContext;

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("counter"), false,
        CIMScope::PROPERTY));

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("classcounter"), false,
        CIMScope::CLASS));

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("min"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("max"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(NAMESPACE,
    CIMQualifierDecl(CIMName ("Description"), String(),
        CIMScope::PROPERTY));

    CIMClass class1(CIMName ("MyClass"));

    class1
    .addProperty(CIMProperty(CIMName ("count"), Uint32(55))
        .addQualifier(CIMQualifier(CIMName ("counter"), true))
        .addQualifier(CIMQualifier(CIMName ("min"), String("0")))
        .addQualifier(CIMQualifier(CIMName ("max"), String("1"))))
    .addProperty(CIMProperty(CIMName ("message"), String("Hello"))
        .addQualifier(CIMQualifier(CIMName ("description"),
                String("My Message"))))
    .addProperty(CIMProperty(CIMName ("ratio"), Real32(1.5)));

    Resolver::resolveClass (class1, context, NAMESPACE);
    context->addClass(NAMESPACE, class1);

    // Test a CIMObject that is a CIMClass
    test01(CIMObject(class1));

    // Test a CIMObject that is a CIMInstance
    CIMInstance instance1(CIMName ("MyClass"));
    instance1.addQualifier(CIMQualifier(CIMName ("classcounter"), true));
    instance1.addProperty(CIMProperty(CIMName ("message"), String("Goodbye")));

    Resolver::resolveInstance (instance1, context, NAMESPACE, true);

    test01(CIMObject(instance1));

    testEmbeddedValue<CIMObject>(instance1);
    testEmbeddedValue<CIMInstance>(instance1);

    // Test CIMValue arrays

    Array<Uint8> arr1;
    arr1.append(11);
    arr1.append(22);
    arr1.append(23);
    test02(arr1);

    Array<Uint16> arr2;
    arr2.append(333);
    arr2.append(444);
    arr2.append(445);
    test02(arr2);

    Array<Uint32> arr3;
    arr3.append(5555);
    arr3.append(6666);
    arr3.append(6667);
    test02(arr3);

    Array<Uint64> arr4;
    arr4.append(123456789);
    arr4.append(987654321);
    arr4.append(987654322);
    test02(arr4);

    Array<Sint8> arr5;
    arr5.append(-11);
    arr5.append(-22);
    arr5.append(-23);
    test02(arr5);

    Array<Sint16> arr6;
    arr6.append(333);
    arr6.append(444);
    arr6.append(555);
    test02(arr6);

    Array<Sint32> arr7;
    arr7.append(555);
    arr7.append(666);
    arr7.append(777);
    test02(arr7);

    Array<Sint64> arr8;
    arr8.append(-123456789);
    arr8.append(-987654321);
    arr8.append(-987654321);
    test02(arr8);

    Array<Boolean> arr9;
    arr9.append(true);
    arr9.append(false);
    arr9.append(false);
    test02(arr9);

    Array<Real32> arr10;
    arr10.append(1.55F);
    arr10.append(2.66F);
    arr10.append(3.77F);
    test02(arr10);

    Array<Real64> arr11;
    arr11.append(55.55);
    arr11.append(66.66);
    arr11.append(77.77);
    test02(arr11);

    Array<Char16> arr12;
    arr12.append('X');
    arr12.append('Y');
    arr12.append('Z');
    test02(arr12);

    Array<String> arr13;
    arr13.append("One");
    arr13.append("Two");
    arr13.append("Three");
    test02(arr13);

    Array<CIMDateTime> arr14;
    arr14.append(CIMDateTime ("20020130120000.000000+360"));
    arr14.append(CIMDateTime ("20020201120000.000000+360"));
    arr14.append(CIMDateTime ("20020202120000.000000+360"));
    test02(arr14);

    Array<CIMObjectPath> arr15;
    arr15.append(CIMObjectPath(
        "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\""));
    arr15.append(CIMObjectPath(
        "//host2:88/root/static:Class2.keyA=\"keyAValue\",keyB="
                "\"keyBValue\""));
    arr15.append(CIMObjectPath(
        "//host3:99/root/test/static:Class3.keyX=\"keyXValue\","
                "keyY=\"keyYValue\""));
    test02(arr15);

    testEmbeddedValueArray<CIMObject>(instance1, NAMESPACE, context);
    testEmbeddedValueArray<CIMInstance>(instance1, NAMESPACE, context);

    // Calling remaining  Array tests..
    CIMDateTime D1("19991224120000.000000+100");
    Array<CIMDateTime> arrD1(10,D1);
    CIMDateTime *D2 = new CIMDateTime("19991224120000.000000+100");
    Array<CIMDateTime> arrD2(D2,1);
    test03(arrD1, arrD2, D2, CIMDateTime("19991224120000.000000+100"),
                     CIMDateTime("29991224120000.000000+100"));
    delete D2;

    CIMName cimname1("yourName");
    Array<CIMName> arrcimname1(10,cimname1);
    CIMName *cimname2 = new CIMName("yourName");
    Array<CIMName> arrcimname2(cimname2,1);
    test03(arrcimname1, arrcimname2, cimname2, CIMName("yourName"),
            CIMName("myName"));
    delete cimname2;

    CIMKeyBinding cimbind1(cimname1, "myKey", CIMKeyBinding::STRING);
    CIMKeyBinding cimbind2(cimname1, "yourKey", CIMKeyBinding::STRING);
    Array<CIMKeyBinding> arrcimbind1(10,cimbind1);
    CIMKeyBinding *cimbind3 =
        new CIMKeyBinding(cimname1, "myKey", CIMKeyBinding::STRING);
    Array<CIMKeyBinding> arrcimbind2(cimbind3,1);
    test03(arrcimbind1, arrcimbind2, cimbind3, cimbind1, cimbind2 );
    delete cimbind3;

    CIMNamespaceName cimnamespace1("root/SampleProvider");
    Array<CIMNamespaceName> arrcimnamespace1(10,cimnamespace1);
    CIMNamespaceName *cimnamespace2 = new CIMNamespaceName(
            "root/SampleProvider");
    Array<CIMNamespaceName> arrcimnamespace2(cimnamespace2,1);
    test03(arrcimnamespace1, arrcimnamespace2, cimnamespace2,
            CIMNamespaceName("root/SampleProvider"),
            CIMNamespaceName("root/SampleProvider2"));
    delete cimnamespace2;

    Array<Boolean> arrB1(10,true);
    Boolean *b = new Boolean(true);
    Array<Boolean> arrB2(b,1);
    Array<Boolean> arrB3(2);
    Boolean b1 = true, b2=false;
    test03(arrB1, arrB2, b, Boolean(true),Boolean(false));
    delete b;

    Array<Real32> arrreal321(10);
    Real32 creal321(2.5);
    Array<Real32> arrreal322(10, creal321);
    Real32 *creal322 = new Real32(2.5);
    Array<Real32> arrreal323(creal322,1);
    Array<Real32> arrreal324(arrreal321);
    test03(arrreal322, arrreal323, creal322,Real32(2.5),Real32(3.5));
    delete creal322;

    Array<Real64> arrreal641(10);
    Real64 creal641(20000.54321);
    Array<Real64> arrreal642(10, creal641);
    Real64 *creal642 = new Real64(20000.54321);
    Array<Real64> arrreal643(creal642,1);
    Array<Real64> arrreal644(arrreal641);
    test03(arrreal642, arrreal643, creal642,Real64(20000.54321),
            Real64(30000.54321));
    delete creal642;

    Array<Sint16> arrSint161(10);
    Sint16 cSint161(-2000);
    Array<Sint16> arrSint162(10, cSint161);
    Sint16 *cSint162 = new Sint16(-2000);
    Array<Sint16> arrSint163(cSint162,1);
    Array<Sint16> arrSint164(arrSint161);
    test03(arrSint162, arrSint163, cSint162, Sint16(-2000), Sint16(-3000));
    delete cSint162;

    Array<Sint32> arrSint321(10);
    Sint32 cSint321(-200000000);
    Array<Sint32> arrSint322(10, cSint321);
    Sint32 *cSint322 = new Sint32(-200000000);
    Array<Sint32> arrSint323(cSint322,1);
    Array<Sint32> arrSint324(arrSint321);
    test03(arrSint322, arrSint323, cSint322, Sint32(-200000000),
            Sint32(-300000000));
    delete cSint322;

    Array<Sint64> arrSint641(10);
    Sint64 cSint641(Sint64(-2000000)*Sint64(10000000) );
    Array<Sint64> arrSint642(10, cSint641);
    Sint64 *cSint642 = new Sint64(Sint64(-2000000)*Sint64(10000000));
    Array<Sint64> arrSint643(cSint642,1);
    Array<Sint64> arrSint644(arrSint641);
    test03(arrSint642, arrSint643, cSint642,Sint64(-2000000)*Sint64(10000000),
                           Sint64(-3000000)*Sint64(10000000));
    delete cSint642;

    Array<Sint8> arrSint81(10);
    Sint8 cSint81(-20);
    Array<Sint8> arrSint82(10, cSint81);
    Sint8 *cSint82 = new Sint8(-20);
    Array<Sint8> arrSint83(cSint82,1);
    Array<Sint8> arrSint84(arrSint81);
    test03(arrSint82, arrSint83, cSint82, Sint8(-20), Sint8(-22));
    delete cSint82;

    Array<Uint16> arrUint161(10);
    Uint16 cUint161(200);
    Array<Uint16> arrUint162(10, cUint161);
    Uint16 *cUint162 = new Uint16(200);
    Array<Uint16> arrUint163(cUint162,1);
    Array<Uint16> arrUint164(arrUint161);
    test03(arrUint162, arrUint163, cUint162, Uint16(200), Uint16(255));
    delete cUint162;

    Array<Uint32> arrUint321(10);
    Uint32 cUint321(2000);
    Array<Uint32> arrUint322(10, cUint321);
    Uint32 *cUint322 = new Uint32(2000);
    Array<Uint32> arrUint323(cUint322,1);
    Array<Uint32> arrUint324(arrUint321);
    test03(arrUint322, arrUint323, cUint322, Uint32(2000), Uint32(3000));
    delete cUint322;

    Array<Uint64> arrUint641(10);
    Uint64 cUint641(Uint64(2000000)*Uint64(10000000));
    Array<Uint64> arrUint642(10, cUint641);
    Uint64 *cUint642 = new Uint64(Uint64(2000000)*Uint64(10000000));
    Array<Uint64> arrUint643(cUint642,1);
    Array<Uint64> arrUint644(arrUint641);
    test03(arrUint642, arrUint643, cUint642,Uint64(2000000)*Uint64(10000000),
                           Uint64(255000)*Uint64(10000000));
    delete cUint642;

    Array<Uint8> arrUint81(10);
    Uint8 cUint81(200);
    Array<Uint8> arrUint82(10, cUint81);
    Uint8 *cUint82 = new Uint8(200);
    Array<Uint8> arrUint83(cUint82,1);
    Array<Uint8> arrUint84(arrUint81);
    test03(arrUint82, arrUint83, cUint82, Uint8(200), Uint8(255));
    delete cUint82;

    Array<Char16> arrChar161(10);
    Char16 cChar161('Z');
    Array<Char16> arrChar162(10, cChar161);
    Char16 *cChar162 = new Char16('Z');
    Array<Char16> arrChar163(cChar162,1);
    Array<Char16> arrChar164(arrChar161);
    test03(arrChar162, arrChar163, cChar162, Char16('Z'), Char16('z'));
    delete cChar162;
    delete context;

    cout << argv[0] << " +++++ passed all tests" << endl;

    return 0;
}
Beispiel #16
0
void drive_operation()
{

    // Uint64 tests

    CQLValue a1(Uint64(10));
    CQLValue a2(Uint64(15));
    CQLValue a3(Uint64(25));
    CQLValue a4(Uint64(30));
    CQLValue a5(Uint64(150));

    PEGASUS_TEST_ASSERT(a1 != a2);
    PEGASUS_TEST_ASSERT(a5 == a5);
    PEGASUS_TEST_ASSERT(a1 < a2);
    PEGASUS_TEST_ASSERT(a2 >= a1);
    PEGASUS_TEST_ASSERT(a1 <= a2);
    PEGASUS_TEST_ASSERT(a2 > a1);

    // Sint64 tests

    CQLValue b1(Sint64(10));
    CQLValue b2(Sint64(15));
    CQLValue b3(Sint64(25));
    CQLValue b4(Sint64(30));
    CQLValue b5(Sint64(150));

    PEGASUS_TEST_ASSERT(b1 != b2);
    PEGASUS_TEST_ASSERT(b5 == b5);
    PEGASUS_TEST_ASSERT(b1 < b2);
    PEGASUS_TEST_ASSERT(b2 >= b1);
    PEGASUS_TEST_ASSERT(b1 <= b2);
    PEGASUS_TEST_ASSERT(b2 > b1);

    // Real64 tests

    CQLValue c1(Real64(10.00));
    CQLValue c2(Real64(15.00));
    CQLValue c3(Real64(25.00));
    CQLValue c4(Real64(30.00));
    CQLValue c5(Real64(150.00));

    PEGASUS_TEST_ASSERT(c1 != c2);
    PEGASUS_TEST_ASSERT(c5 == c5);
    PEGASUS_TEST_ASSERT(c1 < c2);
    PEGASUS_TEST_ASSERT(c2 >= c1);
    PEGASUS_TEST_ASSERT(c1 <= c2);
    PEGASUS_TEST_ASSERT(c2 > c1);

    // Misc
    PEGASUS_TEST_ASSERT(a1 == b1);
    PEGASUS_TEST_ASSERT(a1 == c1);
    PEGASUS_TEST_ASSERT(b1 == a1);
    PEGASUS_TEST_ASSERT(b1 == c1);
    PEGASUS_TEST_ASSERT(c1 == a1);
    PEGASUS_TEST_ASSERT(c1 == b1);

    PEGASUS_TEST_ASSERT(a2 != b1);
    PEGASUS_TEST_ASSERT(a2 != c1);
    PEGASUS_TEST_ASSERT(b2 != a1);
    PEGASUS_TEST_ASSERT(b2 != c1);
    PEGASUS_TEST_ASSERT(c2 != a1);
    PEGASUS_TEST_ASSERT(c2 != b1);

    PEGASUS_TEST_ASSERT(a2 >= b1);
    PEGASUS_TEST_ASSERT(a2 >= c1);
    PEGASUS_TEST_ASSERT(b2 >= a1);
    PEGASUS_TEST_ASSERT(b2 >= c1);
    PEGASUS_TEST_ASSERT(c2 >= a1);
    PEGASUS_TEST_ASSERT(c2 >= b1);

    PEGASUS_TEST_ASSERT(a2 <= b3);
    PEGASUS_TEST_ASSERT(a2 <= c3);
    PEGASUS_TEST_ASSERT(b2 <= a3);
    PEGASUS_TEST_ASSERT(b2 <= c3);
    PEGASUS_TEST_ASSERT(c2 <= a3);
    PEGASUS_TEST_ASSERT(c2 <= b3);

    PEGASUS_TEST_ASSERT(a2 > b1);
    PEGASUS_TEST_ASSERT(a2 > c1);
    PEGASUS_TEST_ASSERT(b2 > a1);
    PEGASUS_TEST_ASSERT(b2 > c1);
    PEGASUS_TEST_ASSERT(c2 > a1);
    PEGASUS_TEST_ASSERT(c2 > b1);

    PEGASUS_TEST_ASSERT(a2 < b3);
    PEGASUS_TEST_ASSERT(a2 < c3);
    PEGASUS_TEST_ASSERT(b2 < a3);
    PEGASUS_TEST_ASSERT(b2 < c3);
    PEGASUS_TEST_ASSERT(c2 < a3);
    PEGASUS_TEST_ASSERT(c2 < b3);

    //Overflow testing
    CQLValue real1(Real64(0.00000001));
    CQLValue sint1(Sint64(-1));
    CQLValue uint1(Sint64(1));
    CQLValue uint2(Uint64(0));

    PEGASUS_TEST_ASSERT(uint1 > sint1);
    PEGASUS_TEST_ASSERT(real1 > sint1);
    PEGASUS_TEST_ASSERT(uint2 > sint1);
    PEGASUS_TEST_ASSERT(real1 > uint2);

    CQLValue real2(Real64(25.00000000000001));
    CQLValue real3(Real64(24.99999999999999));
    CQLValue sint2(Sint64(25));
    CQLValue uint3(Uint64(25));

    PEGASUS_TEST_ASSERT(real2 > real3);
    PEGASUS_TEST_ASSERT(real2 > sint2);
    PEGASUS_TEST_ASSERT(real2 > uint3);
    PEGASUS_TEST_ASSERT(real3 < sint2);
    PEGASUS_TEST_ASSERT(real3 < uint3);

    // String tests

    CQLValue d1(String("HELLO"));
    CQLValue d2(String("HEL"));
    CQLValue d3(String("LO"));
    CQLValue d4(String("AHELLO"));
    CQLValue d5(String("ZHELLO"));

    PEGASUS_TEST_ASSERT(d1 == d2 + d3);
    PEGASUS_TEST_ASSERT(d1 != d2 + d4);

    PEGASUS_TEST_ASSERT(d1 <= d5);
    PEGASUS_TEST_ASSERT(d1 <  d5);

    PEGASUS_TEST_ASSERT(d1 >= d4);
    PEGASUS_TEST_ASSERT(d1 >  d4);

    String str1("0x10");
    String str2("10");
    String str3("10B");
    String str4("10.10");


    CQLValue e1( str1, CQLValue::Hex);
    CQLValue e2( str2, CQLValue::Decimal);
    CQLValue e3( str3, CQLValue::Binary);
    CQLValue e4( str4, CQLValue::Real);

    CQLValue e5(Uint64(16));
    CQLValue e6(Uint64(10));
    CQLValue e7(Uint64(2));
    CQLValue e8(Real64(10.10));

    PEGASUS_TEST_ASSERT(e1 == e5);
    PEGASUS_TEST_ASSERT(e2 == e6);
    PEGASUS_TEST_ASSERT(e3 == e7);
    PEGASUS_TEST_ASSERT(e4 == e8);

    Array<Uint64> array1;

    array1.append(1);
    array1.append(2);
    array1.append(3);
    array1.append(4);
    array1.append(5);
    array1.append(6);
    array1.append(7);
    array1.append(8);
    array1.append(9);
    array1.append(10);

    Array<Sint64> array2;

    array2.append(1);
    array2.append(2);
    array2.append(3);
    array2.append(4);
    array2.append(5);
    array2.append(6);
    array2.append(7);
    array2.append(8);
    array2.append(9);
    array2.append(10);
    array2.append(3);

    Array<Real64> array3;

    array3.append(1.00);
    array3.append(2.00);
    array3.append(3.00);
    array3.append(9.00);
    array3.append(10.00);
    array3.append(3.00);
    array3.append(4.00);
    array3.append(5.00);
    array3.append(6.00);
    array3.append(7.00);
    array3.append(8.00);

    Array<Uint64> array4;

    array4.append(1);
    array4.append(23);
    array4.append(3);
    array4.append(4);
    array4.append(5);
    array4.append(6);
    array4.append(7);
    array4.append(88);
    array4.append(9);
    array4.append(10);

    Array<Sint64> array5;

    array5.append(-1);
    array5.append(2);
    array5.append(3);
    array5.append(4);
    array5.append(5);
    array5.append(-6);
    array5.append(7);
    array5.append(8);
    array5.append(9);
    array5.append(10);
    array5.append(-3);

    Array<Real64> array6;

    array6.append(1.23);
    array6.append(2.00);
    array6.append(3.00);
    array6.append(9.00);
    array6.append(10.00);
    array6.append(3.00);
    array6.append(4.14);
    array6.append(5.00);
    array6.append(6.00);
    array6.append(7.00);
    array6.append(8.00);

    CIMValue cv1(array1);
    CIMValue cv2(array2);
    CIMValue cv3(array3);
    CIMValue cv4(array4);
    CIMValue cv5(array5);
    CIMValue cv6(array6);

    CQLValue vr1(cv1);
    CQLValue vr2(cv1);
    CQLValue vr3(cv2);
    CQLValue vr4(cv3);
    CQLValue vr5(cv4);
    CQLValue vr6(cv5);
    CQLValue vr7(cv6);

    PEGASUS_TEST_ASSERT(vr1 == vr2);
    PEGASUS_TEST_ASSERT(vr1 == vr3);
    PEGASUS_TEST_ASSERT(vr1 == vr4);
    PEGASUS_TEST_ASSERT(vr4 == vr3);

    PEGASUS_TEST_ASSERT(vr1 != vr5);
    PEGASUS_TEST_ASSERT(vr3 != vr6);
    PEGASUS_TEST_ASSERT(vr4 != vr7);

    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);

    CIMInstance _i2(_cimName);
    CIMProperty _p5(CIMName("Description"),
                    CIMValue(String("Dave Rules Everything")));
    CIMProperty _p6(CIMName("EnabledState"),CIMValue(Uint16(2)));
    CIMProperty _p7(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
    CIMProperty _p8(CIMName("TimeOfLastStateChange"),
                    CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

    _i2.addProperty(_p5);
    _i2.addProperty(_p6);
    _i2.addProperty(_p7);
    _i2.addProperty(_p8);

    CQLValue cql1(_i1);
    CQLValue cql2(_i1);
    CQLValue cql3(_i2);
    CQLValue cql4(_i2);

    //PEGASUS_TEST_ASSERT(cql1 == cql1);

    return;
}
Beispiel #17
0
Boolean Process::getCreationDate (CIMDateTime & d)
  const
  {
    long status,
      dst_desc[2];
    char cimtime[80] = "";
    char log_string[] = "SYS$TIMEZONE_DAYLIGHT_SAVING";
    char libdst;
    unsigned __int64 bintime = 0;
    unsigned short int timbuf[7];
    unsigned long libop,
      libdayweek,
      libdayear;
    unsigned int retlen;
    struct tm timetm;
    struct tm *ptimetm = &timetm;
    static $DESCRIPTOR (lnm_tbl, "LNM$SYSTEM");
    struct
    {
      unsigned short wLength;
      unsigned short wCode;
      void *pBuffer;
      unsigned int *pRetLen;
      int term;
    }
    item_list;

      bintime = pInfo->p_stime;

      libop = LIB$K_DAY_OF_WEEK;
      status = lib$cvt_from_internal_time (&libop, &libdayweek, &bintime);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return false;
    }

    libop = LIB$K_DAY_OF_YEAR;
    status = lib$cvt_from_internal_time (&libop, &libdayear, &bintime);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return false;
    }

    dst_desc[0] = strlen (log_string);
    dst_desc[1] = (long) log_string;
    item_list.wLength = 1;
    item_list.wCode = LNM$_STRING;
    item_list.pBuffer = &libdst;
    item_list.pRetLen = &retlen;
    item_list.term = 0;

    status = sys$trnlnm (0, &lnm_tbl, &dst_desc, 0, &item_list);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return false;
    }

    status = sys$numtim (timbuf, &bintime);
    if (!$VMS_STATUS_SUCCESS (status))
    {
      return false;
    }

    timetm.tm_sec = timbuf[5];
    timetm.tm_min = timbuf[4];
    timetm.tm_hour = timbuf[3];
    timetm.tm_mday = timbuf[2];
    timetm.tm_mon = timbuf[1] - 1;
    timetm.tm_year = timbuf[0] - 1900;
    timetm.tm_wday = libdayweek - 1;
    timetm.tm_yday = libdayear - 1;
    timetm.tm_isdst = 0;
    if (libdst != 48)
    {
      timetm.tm_isdst = 1;
    }
    timetm.tm_gmtoff = -18000;
    timetm.tm_zone = "EST";

    if (convertToCIMDateString (ptimetm, cimtime) != -1)
    {
      d = CIMDateTime (cimtime);
      return true;
    }
    return false;
  }
Beispiel #18
0
// Test CIMKeyBinding constructor (CIMValue variety) and equal(CIMValue) method
void test03()
{
    CIMKeyBinding kb0("test0", Real32(3.14159));
    PEGASUS_TEST_ASSERT(kb0.equal(Real32(3.14159)));
    PEGASUS_TEST_ASSERT(!kb0.equal(Real32(3.141593)));

    CIMKeyBinding kb1("test1", String("3.14159"), CIMKeyBinding::NUMERIC);
    PEGASUS_TEST_ASSERT(kb1.equal(Real32(3.14159)));
    PEGASUS_TEST_ASSERT(!kb1.equal(String("3.14159")));

    CIMKeyBinding kb2("test2", Uint32(1000));
    PEGASUS_TEST_ASSERT(kb2.equal(Uint32(1000)));
    PEGASUS_TEST_ASSERT(!kb2.equal(Uint32(1001)));
    PEGASUS_TEST_ASSERT(kb2.getValue() == "1000");

    CIMKeyBinding kb3("test3", Char16('X'));
    PEGASUS_TEST_ASSERT(kb3.equal(Char16('X')));
    PEGASUS_TEST_ASSERT(!kb3.equal(Char16('Y')));
    PEGASUS_TEST_ASSERT(kb3.getValue() == "X");

    CIMKeyBinding kb4("test4", CIMDateTime("19991224120000.000000+360"));
    PEGASUS_TEST_ASSERT(kb4.equal(CIMDateTime("19991224120000.000000+360")));
    PEGASUS_TEST_ASSERT(!kb4.equal(CIMDateTime("19991225120000.000000+360")));
    PEGASUS_TEST_ASSERT(kb4.getValue() == "19991224120000.000000+360");
    kb4.setValue("0");
    PEGASUS_TEST_ASSERT(!kb4.equal(CIMDateTime("19991224120000.000000+360")));

    CIMKeyBinding kb5("test5", String("StringTest"));
    PEGASUS_TEST_ASSERT(kb5.equal(String("StringTest")));
    PEGASUS_TEST_ASSERT(!kb5.equal(String("StringTest1")));
    PEGASUS_TEST_ASSERT(kb5.getValue() == "StringTest");

    CIMKeyBinding kb6("test6", Boolean(true));
    PEGASUS_TEST_ASSERT(kb6.equal(Boolean(true)));
    PEGASUS_TEST_ASSERT(!kb6.equal(Boolean(false)));
    PEGASUS_TEST_ASSERT(kb6.getValue() == "TRUE");
    kb6.setValue("true1");
    PEGASUS_TEST_ASSERT(!kb6.equal(Boolean(true)));

    CIMKeyBinding kb7("test7",
        CIMObjectPath("//atp:77/root/cimv25:TennisPlayer."
            "last=\"Rafter\",first=\"Patrick\""));

    String path = "//atp:77/root/cimv25:TennisPlayer."
                  "last=\"Rafter\",first=\"Patrick\"";
    PEGASUS_TEST_ASSERT(kb7.equal(CIMObjectPath(path)));

    path = "//atp:77/root/cimv25:TennisPlayer."
           "FIRST=\"Patrick\",LAST=\"Rafter\"";
    PEGASUS_TEST_ASSERT(kb7.equal(CIMObjectPath(path)));

    path = "//atp:77/root/cimv25:TennisPlayer.last=\"Rafter\"";
    PEGASUS_TEST_ASSERT(!kb7.equal(CIMObjectPath(path)));

    Boolean exceptionFlag = false;
    try
    {
        CIMKeyBinding kb8("test8", Array<Uint32>());
    }
    catch (TypeMismatchException&)
    {
        exceptionFlag = true;
    }
    PEGASUS_TEST_ASSERT(exceptionFlag);

    CIMKeyBinding kb9("test9", String("1000"), CIMKeyBinding::STRING);
    PEGASUS_TEST_ASSERT(!kb9.equal(Uint32(1000)));

    CIMKeyBinding kb10("test10", String("100"), CIMKeyBinding::NUMERIC);
    PEGASUS_TEST_ASSERT(kb10.equal(Uint64(100)));
    PEGASUS_TEST_ASSERT(kb10.equal(Uint32(100)));
    PEGASUS_TEST_ASSERT(kb10.equal(Uint16(100)));
    PEGASUS_TEST_ASSERT(kb10.equal(Uint8(100)));
    PEGASUS_TEST_ASSERT(kb10.equal(Sint64(100)));
    PEGASUS_TEST_ASSERT(kb10.equal(Sint32(100)));
    PEGASUS_TEST_ASSERT(kb10.equal(Sint16(100)));
    PEGASUS_TEST_ASSERT(kb10.equal(Sint8(100)));
    PEGASUS_TEST_ASSERT(!kb10.equal(String("100")));

    CIMKeyBinding kb11("test11", String("+100"), CIMKeyBinding::NUMERIC);
    // Unsigned ints may not start with "+"
    PEGASUS_TEST_ASSERT(!kb11.equal(Uint64(100)));
    PEGASUS_TEST_ASSERT(!kb11.equal(Uint32(100)));
    PEGASUS_TEST_ASSERT(!kb11.equal(Uint16(100)));
    PEGASUS_TEST_ASSERT(!kb11.equal(Uint8(100)));
    PEGASUS_TEST_ASSERT(kb11.equal(Sint64(100)));
    PEGASUS_TEST_ASSERT(kb11.equal(Sint32(100)));
    PEGASUS_TEST_ASSERT(kb11.equal(Sint16(100)));
    PEGASUS_TEST_ASSERT(kb11.equal(Sint8(100)));
    PEGASUS_TEST_ASSERT(!kb11.equal(String("100")));
}
Beispiel #19
0
static void _testValues(void)
{
    WsmToCimRequestMapper mapper((CIMRepository*) 0);

    // Test simple data types
    testSimpleType(Boolean(true));
    testSimpleType(Boolean(false));
    testSimpleType((Sint8)-4);
    testSimpleType((Sint16)-44);
    testSimpleType((Sint32)-444);
    testSimpleType((Sint64)-4444);
    testSimpleType((Uint8)4);
    testSimpleType((Uint16)44);
    testSimpleType((Uint32)444);
    testSimpleType((Uint64)4444);
    testSimpleType(Char16('Z'));
    testSimpleType(Real32(1.5));
    testSimpleType(Real64(55.5));
    testSimpleType(Uint64(123456789));
    testSimpleType(Sint64(-123456789));
    testSimpleType(String("Hello world"));

    // Test special floating point values: NaN, INF, -INF
    WsmValue wsmf1("NaN");
    CIMValue cimf1((Real32)0.0);
    mapper.convertWsmToCimValue(wsmf1, CIMNamespaceName(), cimf1);
    PEGASUS_TEST_ASSERT(cimf1.toString() == PEGASUS_NAN);

    WsmValue wsmf2("INF");
    CIMValue cimf2((Real32)0.0);
    mapper.convertWsmToCimValue(wsmf2, CIMNamespaceName(), cimf2);
    PEGASUS_TEST_ASSERT(cimf2.toString() == PEGASUS_INF);

    WsmValue wsmf3("-INF");
    CIMValue cimf3((Real32)0.0);
    mapper.convertWsmToCimValue(wsmf3, CIMNamespaceName(), cimf3);
    PEGASUS_TEST_ASSERT(cimf3.toString() == PEGASUS_NEG_INF);

    WsmValue wsmd1("NaN");
    CIMValue cimd1((Real64)0.0);
    mapper.convertWsmToCimValue(wsmd1, CIMNamespaceName(), cimd1);
    PEGASUS_TEST_ASSERT(cimd1.toString() == PEGASUS_NAN);

    WsmValue wsmd2("INF");
    CIMValue cimd2((Real64)0.0);
    mapper.convertWsmToCimValue(wsmd2, CIMNamespaceName(), cimd2);
    PEGASUS_TEST_ASSERT(cimd2.toString() == PEGASUS_INF);

    WsmValue wsmd3("-INF");
    CIMValue cimd3((Real64)0.0);
    mapper.convertWsmToCimValue(wsmd3, CIMNamespaceName(), cimd3);
    PEGASUS_TEST_ASSERT(cimd3.toString() == PEGASUS_NEG_INF);

    // Test datetime
    CIMDateTime cimDT;

    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0012345678901234S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.001234:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.12345678901234S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.123456:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0055555555S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005555:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.00500000S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005000:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.9999999S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.999999:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.000000:000"));
    mapper.convertWsmToCimDatetime("P1Y1M1DT10H5M44.0055S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000396100544.005500:000"));
    mapper.convertWsmToCimDatetime("PT10H5M44.0055S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000100544.005500:000"));
    mapper.convertWsmToCimDatetime("P10Y", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00003652000000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004201000000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40D", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004241000000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40DT34H", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242100000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40DT34H70M", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242111000.000000:000"));
    mapper.convertWsmToCimDatetime("P10Y18M40DT34H70M140S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00004242111220.000000:000"));
    mapper.convertWsmToCimDatetime("PT70M140S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000011220.000000:000"));
    mapper.convertWsmToCimDatetime("PT140S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000000220.000000:000"));
    mapper.convertWsmToCimDatetime("PT5M44.0055S", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("00000000000544.005500:000"));

    mapper.convertWsmToCimDatetime("2004-12-01", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+000"));
    mapper.convertWsmToCimDatetime("2004-12-01Z", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+000"));
    mapper.convertWsmToCimDatetime("2004-12-01+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******+120"));
    mapper.convertWsmToCimDatetime("2004-12-01-11:30", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201******.******-690"));

    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012-04:15", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200-255"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34Z", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+000"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0012Z", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+000"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.00+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0000000+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.0000009+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000000+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.000001+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.000001+120"));
    mapper.convertWsmToCimDatetime("2004-12-01T12:23:34.1+02:00", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.100000+120"));

    mapper.convertWsmToCimDatetime("20041201122334.001200+360", cimDT);
    PEGASUS_TEST_ASSERT(cimDT == CIMDateTime("20041201122334.001200+360"));


    // Test arrays of simple types
    Array<Sint8> s8_arr;
    s8_arr.append(-11);
    s8_arr.append(-22);
    testArrayType(s8_arr);

    Array<Sint16> s16_arr;
    s16_arr.append(-111);
    s16_arr.append(-222);
    testArrayType(s16_arr);

    Array<Sint32> s32_arr;
    s32_arr.append(-1111);
    s32_arr.append(-2222);
    testArrayType(s32_arr);

    Array<Sint64> s64_arr;
    s64_arr.append(-11111);
    s64_arr.append(-22222);
    testArrayType(s64_arr);

    Array<Uint8> u8_arr;
    u8_arr.append(11);
    u8_arr.append(22);
    testArrayType(u8_arr);

    Array<Uint16> u16_arr;
    u16_arr.append(111);
    u16_arr.append(222);
    testArrayType(u16_arr);

    Array<Uint32> u32_arr;
    u32_arr.append(1111);
    u32_arr.append(2222);
    testArrayType(u32_arr);

    Array<Uint64> u64_arr;
    u64_arr.append(11111);
    u64_arr.append(22222);
    testArrayType(u64_arr);

    Array<Boolean> b_arr;
    b_arr.append(true);
    b_arr.append(false);
    testArrayType(b_arr);

    Array<Real32> r32_arr;
    r32_arr.append(Real32(1.5));
    r32_arr.append(Real32(2.5));
    testArrayType(r32_arr);

    Array<Real64> r64_arr;
    r64_arr.append(Real64(11.5));
    r64_arr.append(Real64(12.5));
    testArrayType(r64_arr);

    Array<Char16> c16_arr;
    c16_arr.append(Char16('Z'));
    c16_arr.append(Char16('X'));
    testArrayType(c16_arr);

    Array<CIMDateTime> dt_arr;
    dt_arr.append(CIMDateTime("19991224120000.000000+360"));
    dt_arr.append(CIMDateTime("20001224120000.000000+360"));
    testArrayType(dt_arr);

    Array<String> str_arr;
    str_arr.append("Test string 1");
    str_arr.append("Test string 2");
    testArrayType(str_arr);

    // Test class URI to class name conversion
    String classURI = String(WSM_RESOURCEURI_CIMSCHEMAV2) + "/MyClass";
    CIMName cimName = mapper.convertResourceUriToClassName(classURI);
    PEGASUS_TEST_ASSERT(cimName.getString() == "MyClass");
}
void ComputerSystem::initialize(void)
{
  // fills in the values of all properties that are not
  // hardcoded (i.e., are obtained from the system) but not
  // going to change dynamically (which is most, for this
  // provider)
  
  // _hostName
  struct hostent *he;
  char hn[PEGASUS_MAXHOSTNAMELEN];
  // fill hn with what this system thinks is name
  gethostname(hn,PEGASUS_MAXHOSTNAMELEN);
  // find out what nameservices think is full name
  if (he=gethostbyname(hn)) _hostName = he->h_name;
  else _hostName = hn;

  size_t bufSize;

  // get serial number using confstr  
  bufSize = confstr(_CS_MACHINE_SERIAL, NULL, 0);
  if (bufSize != 0)
  {
      char* serialNumber = new char[bufSize];
      try
      {
          if (confstr(_CS_MACHINE_SERIAL, serialNumber, bufSize) != 0)
          {
              _serialNumber.set(String(serialNumber));
          }
      }
      catch(...)
      {
          delete [] serialNumber;
          throw;
      }
      delete [] serialNumber;
  }

  // get model using command
  FILE *s = popen("/usr/bin/model","r");
  if (s == 0) throw CIMOperationFailedException("/usr/bin/model: command not found");
  char buf[100];
  if (fgets(buf,100,s) == 0)
    throw CIMOperationFailedException("/usr/bin/model: no output");
  pclose(s);
  _model = String(buf);

  // get system UUID using confstr.  
  bufSize = confstr(_CS_MACHINE_IDENT, NULL, 0);
  if (bufSize != 0)
  {
      char* uuid = new char[bufSize];
      try
      {
          if (confstr(_CS_MACHINE_IDENT, uuid, bufSize) != 0)
          {
              _uuid.set(String(uuid));
          }
      }
      catch(...)
      {
          delete [] uuid;
          throw;
      }
      delete [] uuid;
  }

  // InstallDate
  /*
    A CIM date has the following form:
	yyyymmddhhmmss.mmmmmmsutc

    Where

	yyyy = year (0-1999)
	mm = month (1-12)
	dd = day (1-31)
	hh = hour (0-23)
	mm = minute (0-59)
	ss = second (0-59)
	mmmmmm = microseconds.
	s = '+' or '-' to represent the UTC sign.
	utc = UTC offset (same as GMT offset).
  */
  // creation date of /stand/vmunix
  struct stat st;
  // get get modification time of file
  if (0 != stat("/stand/vmunix", &st))
    throw CIMOperationFailedException("/stand/vmunix: can't access");
  // convert to a usable format
  struct tm tmBuffer;
  struct tm *t = localtime_r(&st.st_mtime, &tmBuffer);
  // convert to CIMDateTime format
  char timstr[26];
  sprintf(timstr,"%04d%02d%02d%02d%02d%02d.000000%c%03d",t->tm_year+1900,
                       t->tm_mon+1,
                       t->tm_mday,
                       t->tm_hour,
                       t->tm_min,
                       t->tm_sec,
                       (timezone>0)?'-':'+',
                       labs (timezone/60 - (t->tm_isdst? 60:0)));
  _installDate = CIMDateTime (timstr);

  // ----------------------------------------------------------
  // Now set properties obtained from DMI
  // ----------------------------------------------------------

  typedef enum
  {
    GenInfoSysName_E       =  1,
    GenInfoSysLoc_E        =  2,
    GenInfoSysPUser_E      =  3,
    GenInfoSysPPhone_E     =  4,
    GenInfoSysUpTime_E     =  5,
    GenInfoSysDate_E       =  6,
    GenInfoSysSUser_E      =  7,
    GenInfoSysSPhone_E     =  8,
    GenInfoSysPPager_E     =  9,
    GenInfoSysSPager_E     = 10,
    GenInfoSecurity_E      = 11,
    GenInfoModel_E         = 12,
    GenInfoSerialNumber_E  = 13,
    GenInfoSoftwareID_E    = 14
  } GenInfoEnumList;

  char                  inLine[1024];
  char                 *tmpGroupId = NULL;
  char                 *tmpAttrId = NULL;
  char                 *value = NULL;
  int                   groupId;
  int                   attrId;
  char                 *tokp = NULL;

  // open file
  ifstream mParmStream(DMI_FILE);
  // Values will be left blank if can't access file
  if (mParmStream == 0) return;

  while (mParmStream.getline(inLine, sizeof(inLine)))
  {
    /* Parse out the line to get the DMI group Id, attribute Id */
    /* and value.                                               */
    tmpGroupId = strtok_r(inLine, "|", &tokp);
    tmpAttrId = strtok_r(NULL, "|", &tokp);
    value = strtok_r(NULL, "\n", &tokp);

    if (NULL != tmpGroupId)
    {
      groupId = atoi(tmpGroupId);
    }
    else
    {
      continue;
    }

    if (NULL != tmpAttrId)
    {
      attrId = atoi(tmpAttrId);
    }
    else
    {
      continue;
    }

    /* Make sure information read in is the right DMI group. */
    if ((groupId != GEN_INFO_GROUP_ID) || (NULL == value))
    {
      continue;
    }
    
    if (attrId == GenInfoSysPUser_E)
    {
      _primaryOwnerName = value;
    }
    else if (attrId == GenInfoSysPPhone_E)
    {
      _primaryOwnerContact = value;
    }
    else if (attrId == GenInfoSysSUser_E)
    {
      _secondaryOwnerName = value;
    }
    else if (attrId == GenInfoSysSPhone_E)
    {
      _secondaryOwnerContact = value;
    }
    else if (attrId == GenInfoSysPPager_E)
    {
      _primaryOwnerPager = value;
    }
    else if (attrId == GenInfoSysSPager_E)
    {
      _secondaryOwnerPager = value;
    }
  }  /* while */

  return;
}
Beispiel #21
0
Boolean Process::getCreationDate (CIMDateTime & d)
const
{
    long status;
    long dst_desc[2];
    char cimtime[80] = "";
    char log_string[] = "SYS$TIMEZONE_DAYLIGHT_SAVING";
    char libdst;
    unsigned __int64 bintime = 0;
    unsigned short int timbuf[7];
    unsigned long libop;
    unsigned long libdayweek;
    unsigned long libdayear;
    unsigned int retlen;
    struct tm timetm;
    struct tm *ptimetm = &timetm;

    // Added to get system uptime for SWAPPER process - PTR 73-51-29
    long item = SYI$_BOOTTIME;
    char t_string[24] = "";
    unsigned __int64  val = 0;
    struct dsc$descriptor_s sysinfo;

    sysinfo.dsc$b_dtype = DSC$K_DTYPE_T;
    sysinfo.dsc$b_class = DSC$K_CLASS_S;
    sysinfo.dsc$w_length = sizeof (t_string);
    sysinfo.dsc$a_pointer = t_string;

    static $DESCRIPTOR (lnm_tbl, "LNM$SYSTEM");
    struct
    {
        unsigned short wLength;
        unsigned short wCode;
        void *pBuffer;
        unsigned int *pRetLen;
        int term;
    } dst_item_list;

    bintime = pInfo.p_stime;

    libop = LIB$K_DAY_OF_WEEK;
    status = lib$cvt_from_internal_time (&libop, &libdayweek, &bintime);
    if (!$VMS_STATUS_SUCCESS (status))
    {
        return false;
    }

    libop = LIB$K_DAY_OF_YEAR;
    status = lib$cvt_from_internal_time (&libop, &libdayear, &bintime);
    if (!$VMS_STATUS_SUCCESS (status))
    {
        return false;
    }

    dst_desc[0] = strlen (log_string);
    dst_desc[1] = (long) log_string;
    dst_item_list.wLength = 1;
    dst_item_list.wCode = LNM$_STRING;
    dst_item_list.pBuffer = &libdst;
    dst_item_list.pRetLen = &retlen;
    dst_item_list.term = 0;

    status = sys$trnlnm (0, &lnm_tbl, &dst_desc, 0, &dst_item_list);
    if (!$VMS_STATUS_SUCCESS (status))
    {
        return false;
    }

    //  Added to get sysuptime for SWAPPER process --- PTR 73-51-29
    if (bintime == 0)
    {
        status = lib$getsyi(&item, 0, &sysinfo, &val, 0, 0);
        status = sys$bintim(&sysinfo, &bintime);
    }

    status = sys$numtim (timbuf, &bintime);
    if (!$VMS_STATUS_SUCCESS (status))
    {
        return false;
    }

    timetm.tm_sec = timbuf[5];
    timetm.tm_min = timbuf[4];
    timetm.tm_hour = timbuf[3];
    timetm.tm_mday = timbuf[2];
    timetm.tm_mon = timbuf[1] - 1;
    timetm.tm_year = timbuf[0] - 1900;
    timetm.tm_wday = libdayweek - 1;
    timetm.tm_yday = libdayear - 1;
    timetm.tm_isdst = 0;
    if (libdst != 48)
    {
        timetm.tm_isdst = 1;
    }
    timetm.tm_gmtoff = -18000;
    timetm.tm_zone = "EST";

    if (convertToCIMDateString (ptimetm, cimtime) != -1)
    {
        d = CIMDateTime (cimtime);
        return true;
    }
    return false;
}
void DefaultPropertyOwner::_requestIndicationServiceStateChange(
    const String& userName,
    Boolean enable,
    Uint32 timeoutSeconds)
{
    MessageQueue *queue = MessageQueue::lookup(
        PEGASUS_QUEUENAME_INDICATIONSERVICE);
    // Return if indication service can not be found
    if (!queue)
    {
        return;
    }

    Uint32 queueId = queue->getQueueId();

    const String METHOD_NAME = "RequestStateChange";
    const String PARAMNAME_REQUESTEDSTATE = "RequestedState";
    const String PARAMNAME_TIMEOUTPERIOD = "TimeoutPeriod";
    const Uint16 STATE_ENABLED = 2;
    const Uint16 STATE_DISABLED = 3;

    String referenceStr("//", 2);
    referenceStr.append(System::getHostName());
    referenceStr.append("/");
    referenceStr.append(PEGASUS_NAMESPACENAME_INTEROP.getString());
    referenceStr.append(":");
    referenceStr.append(
        PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE.getString());
    CIMObjectPath reference(referenceStr);

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

    inParams.append(CIMParamValue(PARAMNAME_REQUESTEDSTATE,
        CIMValue(enable ? STATE_ENABLED : STATE_DISABLED)));

    inParams.append(CIMParamValue(PARAMNAME_TIMEOUTPERIOD,
        CIMValue(CIMDateTime(timeoutSeconds * 1000000, true))));

    MessageQueueService *controller = ModuleController::getModuleController();

    try
    {
        CIMInvokeMethodRequestMessage* request =
            new CIMInvokeMethodRequestMessage(
                XmlWriter::getNextMessageId(),
                PEGASUS_NAMESPACENAME_INTEROP,
                referenceStr,
                CIMNameCast(METHOD_NAME),
                inParams,
                QueueIdStack(queueId));

        request->operationContext.insert(
            IdentityContainer(userName));

        AsyncLegacyOperationStart *asyncRequest =
            new AsyncLegacyOperationStart(
                0,
                queueId,
                request);

        AsyncReply * asyncReply = controller->SendWait(asyncRequest);

        CIMInvokeMethodResponseMessage * response =
            reinterpret_cast<CIMInvokeMethodResponseMessage *>(
                (static_cast<AsyncLegacyOperationResult *>(
                    asyncReply))->get_result());

        CIMException e = response->cimException;

        delete response;
        delete asyncRequest;
        delete asyncReply;

        if (e.getCode() != CIM_ERR_SUCCESS)
        {
            throw e;
        }
    }
    catch(const Exception &e)
    {
        PEG_TRACE((TRC_CONFIG,Tracer::LEVEL1,
            "Exception caught while invoking CIM_IndicationService."
                "RequestStateChange()  method: %s",
        (const char*)e.getMessage().getCString()));
        throw;
    }
    catch(...)
    {
        PEG_TRACE_CSTRING(TRC_CONFIG,Tracer::LEVEL1,
            "Unknown exception caught while invoking CIM_IndicationService."
                "RequestStateChange()  method");
        throw;
    }
}
// Tests PROPERTY.ARRAY as an embedded object with array type.
static void testGetInstanceElement2(const char* testDataFile)
{
    CIMInstance cimInstance;
    Buffer text;
    FileSystem::loadFileToMemory(text, testDataFile);

    XmlParser parser((char*)text.getData());

    XmlReader::getInstanceElement(parser, cimInstance);
    PEGASUS_TEST_ASSERT(cimInstance.getClassName() == 
                        CIMName("CIM_InstCreation"));

    Uint32 idx;
    CIMProperty cimProperty;
    CIMValue cimValue;
    CIMType cimType;
    PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3);

    idx = cimInstance.findProperty(CIMName("IndicationIdentifier"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0);
    String myString;
    cimValue.get(myString);
    PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "0") == 0);

    idx = cimInstance.findProperty(CIMName("IndicationTime"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "datetime") == 0);
    CIMDateTime myDateTime;
    cimValue.get(myDateTime);
    PEGASUS_TEST_ASSERT(myDateTime.equal(
        CIMDateTime("20050227225624.524000-300")));

    idx = cimInstance.findProperty(CIMName("SourceInstance"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "object") == 0);
    Array<CIMObject> cimObject;
    cimValue.get(cimObject);
    PEGASUS_TEST_ASSERT(cimObject.size() == 2);
    for (idx = 0; idx < cimObject.size(); idx++)
    {
        CIMInstance cimInstanceElement(cimObject[idx]);
        PEGASUS_TEST_ASSERT(cimInstanceElement.getPropertyCount() == 2);
        Uint32 propIdx = cimInstanceElement.findProperty(CIMName("uniqueId"));
        if (propIdx != PEG_NOT_FOUND)
        {
            CIMProperty nestedProperty = 
                cimInstanceElement.getProperty(propIdx);
            cimValue = nestedProperty.getValue();
            Uint32 uniqueId;
            cimValue.get(uniqueId);
            propIdx = cimInstanceElement.findProperty(CIMName("lastOp"));
            nestedProperty = cimInstanceElement.getProperty(propIdx);
            cimValue = nestedProperty.getValue();
            String checkStringValue;
            cimValue.get(checkStringValue);
            if (uniqueId == 1)
            {
                PEGASUS_TEST_ASSERT(strcmp(
                    checkStringValue.getCString(), "createInstance") == 0);
            }
            else if (uniqueId == 2)
            {
                PEGASUS_TEST_ASSERT(strcmp(
                    checkStringValue.getCString(), "deleteInstance") == 0);
            }
            else
            {
                PEGASUS_TEST_ASSERT(false);
            }
        }
    }
}
// Tests PROPERTY as an embedded object.
static void testGetInstanceElement(const char* testDataFile)
{
    //--------------------------------------------------------------------------
    // Read in instance
    //--------------------------------------------------------------------------

    CIMInstance cimInstance;
    Buffer text;
    FileSystem::loadFileToMemory(text, testDataFile);

    XmlParser parser((char*)text.getData());

    XmlReader::getInstanceElement(parser, cimInstance);
    PEGASUS_TEST_ASSERT(
        cimInstance.getClassName() == CIMName("CIM_InstCreation"));

    Uint32 idx;
    CIMProperty cimProperty;
    CIMValue cimValue;
    CIMType cimType;
    PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3);

    idx = cimInstance.findProperty(CIMName("IndicationIdentifier"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0);
    String myString;
    cimValue.get(myString);
    PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "0") == 0);

    idx = cimInstance.findProperty(CIMName("IndicationTime"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "datetime") == 0);
    CIMDateTime myDateTime;
    cimValue.get(myDateTime);
    PEGASUS_TEST_ASSERT(myDateTime.equal(
        CIMDateTime("20050227225624.524000-300")));

    idx = cimInstance.findProperty(CIMName("SourceInstance"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "object") == 0);
    CIMObject cimObject;
    cimValue.get(cimObject);
    PEGASUS_TEST_ASSERT(
        cimObject.getClassName() == 
            CIMName("Sample_LifecycleIndicationProviderClass"));
    PEGASUS_TEST_ASSERT(cimObject.getPropertyCount() == 2);

    idx = cimObject.findProperty(CIMName("uniqueId"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimObject.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "uint32") == 0);
    Uint32 myUint32;
    cimValue.get(myUint32);
    PEGASUS_TEST_ASSERT(myUint32 == 1);

    idx = cimObject.findProperty(CIMName("lastOp"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimObject.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0);
    cimValue.get(myString);
    PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "createInstance") == 0);
}
Beispiel #25
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;
}
Beispiel #26
0
CIMDateTime
String::toDateTime() const
{
	return CIMDateTime(*this);
}
void PG_TestPropertyTypes::initialize(CIMOMHandle& cimom)
{
    // save cimom handle
    _cimom = cimom;

    // create default instances
    CIMInstance instance1("PG_TestPropertyTypes");

    instance1.addProperty(CIMProperty(
        "CreationClassName", String("PG_TestPropertyTypes")));   // key
    instance1.addProperty(CIMProperty("InstanceId", Uint64(1))); //key
    instance1.addProperty(CIMProperty(
        "PropertyString", String("PG_TestPropertyTypes_Instance1")));
    instance1.addProperty(CIMProperty("PropertyUint8", Uint8(120)));
    instance1.addProperty(CIMProperty("PropertyUint16", Uint16(1600)));
    instance1.addProperty(CIMProperty("PropertyUint32", Uint32(3200)));
    instance1.addProperty(CIMProperty("PropertyUint64", Uint64(6400)));
    instance1.addProperty(CIMProperty("PropertySint8", Sint8(-120)));
    instance1.addProperty(CIMProperty("PropertySint16", Sint16(-1600)));
    instance1.addProperty(CIMProperty("PropertySint32", Sint32(-3200)));
    instance1.addProperty(CIMProperty("PropertySint64", Sint64(-6400)));
    instance1.addProperty(CIMProperty("PropertyBoolean", Boolean(1)));
    instance1.addProperty(CIMProperty("PropertyReal32", Real32(1.12345670123)));
    instance1.addProperty(CIMProperty(
        "PropertyReal64", Real64(1.12345678906543210123)));
    instance1.addProperty(CIMProperty(
        "PropertyDatetime", CIMDateTime("20010515104354.000000:000")));

    // update object path
    {
        CIMObjectPath objectPath = instance1.getPath();

        Array<CIMKeyBinding> keys;

        {
            CIMProperty keyProperty = instance1.getProperty(
                instance1.findProperty("CreationClassName"));

            keys.append(
                CIMKeyBinding(keyProperty.getName(), keyProperty.getValue()));
        }

        {
            CIMProperty keyProperty = instance1.getProperty(
                instance1.findProperty("InstanceId"));

            keys.append(
                CIMKeyBinding(keyProperty.getName(), keyProperty.getValue()));
        }

        objectPath.setKeyBindings(keys);

        instance1.setPath(objectPath);
    }

    _instances.append(instance1);

    CIMInstance instance2("PG_TestPropertyTypes");

    instance2.addProperty(CIMProperty(
        "CreationClassName", String("PG_TestPropertyTypes")));   // key
    instance2.addProperty(CIMProperty("InstanceId", Uint64(2))); //key
    instance2.addProperty(CIMProperty(
        "PropertyString", String("PG_TestPropertyTypes_Instance2")));

    instance2.addProperty(CIMProperty("PropertyUint8", Uint8(122)));
    instance2.addProperty(CIMProperty("PropertyUint16", Uint16(1602)));
    instance2.addProperty(CIMProperty("PropertyUint32", Uint32(3202)));
    instance2.addProperty(CIMProperty("PropertyUint64", Uint64(6402)));
    instance2.addProperty(CIMProperty("PropertySint8", Sint8(-122)));
    instance2.addProperty(CIMProperty("PropertySint16", Sint16(-1602)));
    instance2.addProperty(CIMProperty("PropertySint32", Sint32(-3202)));
    instance2.addProperty(CIMProperty("PropertySint64", Sint64(-6402)));
    instance2.addProperty(CIMProperty("PropertyBoolean", Boolean(0)));
    instance2.addProperty(CIMProperty("PropertyReal32", Real32(2.12345670123)));
    instance2.addProperty(CIMProperty(
        "PropertyReal64", Real64(2.12345678906543210123)));

    instance2.addProperty(CIMProperty(
        "PropertyDatetime", CIMDateTime("20010515104354.000000:000")));

    _instances.append(instance2);

    // update object path
    {
        CIMObjectPath objectPath = instance2.getPath();

        Array<CIMKeyBinding> keys;

        {
            CIMProperty keyProperty = instance2.getProperty(
                instance2.findProperty("CreationClassName"));

            keys.append(
                CIMKeyBinding(keyProperty.getName(), keyProperty.getValue()));
        }

        {
            CIMProperty keyProperty = instance2.getProperty(
                instance2.findProperty("InstanceId"));

            keys.append(
                CIMKeyBinding(keyProperty.getName(), keyProperty.getValue()));
        }

        objectPath.setKeyBindings(keys);

        instance2.setPath(objectPath);
    }

    // instance3 to check for negative floating point and exponents
    CIMInstance instance3("PG_TestPropertyTypes");

    instance3.addProperty(CIMProperty(
        "CreationClassName", String("PG_TestPropertyTypes")));   // key
    instance3.addProperty(CIMProperty("InstanceId", Uint64(3))); //key
    instance3.addProperty(CIMProperty(
        "PropertyString", String("PG_TestPropertyTypes_Instance3")));
    instance3.addProperty(CIMProperty("PropertyUint8", Uint8(120)));
    instance3.addProperty(CIMProperty("PropertyUint16", Uint16(1600)));
    instance3.addProperty(CIMProperty("PropertyUint32", Uint32(3200)));
    instance3.addProperty(CIMProperty("PropertyUint64", Uint64(6400)));
    instance3.addProperty(CIMProperty("PropertySint8", Sint8(-120)));
    instance3.addProperty(CIMProperty("PropertySint16", Sint16(-1600)));
    instance3.addProperty(CIMProperty("PropertySint32", Sint32(-3200)));
    instance3.addProperty(CIMProperty("PropertySint64", Sint64(-6400)));
    instance3.addProperty(CIMProperty("PropertyBoolean", Boolean(0)));
    instance3.addProperty(CIMProperty(
        "PropertyReal32", Real32(-1.12345670123)));
    instance3.addProperty(CIMProperty(
        "PropertyReal64", Real64(0.000000012345)));
    instance3.addProperty(CIMProperty(
        "PropertyDatetime", CIMDateTime("20060301104354.000000:000")));

    // update object path
    {
        CIMObjectPath objectPath = instance3.getPath();

        Array<CIMKeyBinding> keys;

        {
            CIMProperty keyProperty = instance3.getProperty(
                instance3.findProperty("CreationClassName"));

            keys.append(
                CIMKeyBinding(keyProperty.getName(), keyProperty.getValue()));
        }

        {
            CIMProperty keyProperty =
                instance3.getProperty(instance3.findProperty("InstanceId"));

            keys.append(
                CIMKeyBinding(keyProperty.getName(), keyProperty.getValue()));
        }

        objectPath.setKeyBindings(keys);

        instance3.setPath(objectPath);
    }
    realValueTestInstance = instance3;
}