static CMPIUint64 dtGetBinaryFormat(const CMPIDateTime* eDt, CMPIStatus* rc) { CIMDateTime* dt=(CIMDateTime*)eDt->hdl; if (!dt) { if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER); return 0; } CMPIUint64 days,hours,mins,secs,usecs,utc,lTime; struct tm tm,tmt; CString tStr=dt->toString().getCString(); char cStr[26]; memset( cStr, 0, 26); memcpy (cStr, (const char*)tStr, 25); if (dt->isInterval()) { cStr[21]=0; usecs=atoi(cStr+15); cStr[15]=0; secs=atoi(cStr+12); cStr[12]=0; mins=atoi(cStr+10); cStr[10]=0; hours=atoi(cStr+8); cStr[8]=0; days=atoi(cStr); lTime=(days*PEGASUS_UINT64_LITERAL(86400000000))+ (hours*PEGASUS_UINT64_LITERAL(3600000000))+ (mins*60000000)+(secs*1000000)+usecs; } else { time_t tt=time(NULL); #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC tmt=*localtime(&tt); #else localtime_r(&tt,&tmt); #endif memset(&tm,0,sizeof(tm)); tm.tm_isdst=tmt.tm_isdst; utc=atoi(cStr+21); cStr[21]=0; usecs=atoi(cStr+15); cStr[15]=0; tm.tm_sec=atoi(cStr+12); cStr[12]=0; tm.tm_min=atoi(cStr+10); cStr[10]=0; tm.tm_hour=atoi(cStr+8); cStr[8]=0; tm.tm_mday=atoi(cStr+6); cStr[6]=0; tm.tm_mon=(atoi(cStr+4)-1); cStr[4]=0; tm.tm_year=(atoi(cStr)-1900); lTime=mktime(&tm); lTime*=1000000; lTime+=usecs; } return lTime; }
void _addSubscription (CIMClient & client, String & filter, String & handler) { CIMObjectPath path; CIMInstance retrievedInstance; // // Create subscriptions // CIMInstance subscription01 = _buildSubscriptionInstance (_buildFilterOrHandlerPath (PEGASUS_CLASSNAME_INDFILTER, filter), PEGASUS_CLASSNAME_INDHANDLER_CIMXML, _buildFilterOrHandlerPath (PEGASUS_CLASSNAME_INDHANDLER_CIMXML, handler)); _addUint16Property (subscription01, "OnFatalErrorPolicy", 2); _addStringProperty (subscription01, "OtherOnFatalErrorPolicy", String::EMPTY, true); _addUint64Property (subscription01, "FailureTriggerTimeInterval", 60); _addUint16Property (subscription01, "SubscriptionState", 2); _addStringProperty (subscription01, "OtherSubscriptionState", String::EMPTY, true); _addUint64Property (subscription01, "SubscriptionDuration", PEGASUS_UINT64_LITERAL (60000000000)); _addUint16Property (subscription01, "RepeatNotificationPolicy", 1); _addStringProperty (subscription01, "OtherRepeatNotificationPolicy", "another policy"); _addUint64Property (subscription01, "RepeatNotificationInterval", 60); _addUint64Property (subscription01, "RepeatNotificationGap", 30); _addUint16Property (subscription01, "RepeatNotificationCount", 5); path = client.createInstance (NAMESPACE, subscription01); _checkSubscriptionPath (path, filter, PEGASUS_CLASSNAME_INDHANDLER_CIMXML, handler); retrievedInstance = client.getInstance (NAMESPACE, path); _checkUint16Property (retrievedInstance, "OnFatalErrorPolicy", 2); _checkStringProperty (retrievedInstance, "OtherOnFatalErrorPolicy", String::EMPTY, true); _checkUint64Property (retrievedInstance, "FailureTriggerTimeInterval", 60); _checkUint16Property (retrievedInstance, "SubscriptionState", 2); _checkStringProperty (retrievedInstance, "OtherSubscriptionState", String::EMPTY, true); _checkUint64Property (retrievedInstance, "SubscriptionDuration", PEGASUS_UINT64_LITERAL (60000000000)); _checkUint16Property (retrievedInstance, "RepeatNotificationPolicy", 1); _checkStringProperty (retrievedInstance, "OtherRepeatNotificationPolicy", "another policy"); _checkUint64Property (retrievedInstance, "RepeatNotificationInterval", 60); _checkUint64Property (retrievedInstance, "RepeatNotificationGap", 30); _checkUint16Property (retrievedInstance, "RepeatNotificationCount", 5); }
int main(int argc, char** argv) { verbose = getenv("PEGASUS_TEST_VERBOSE"); String str = Formatter::format("\\$dollar\\$ X=$0, Y=$1, Z=$2, X=$0", 88, "Hello World", 7.5); if (verbose) cout << "str[" << str << "]" << endl; // test for Uint32 expressions. { Uint32 test = 99; Uint32 big = 32999; String str2 = Formatter::format("test $0 big $1", test, big); if (verbose) cout << "str2[" << str2 << "]" << endl; assert(Formatter::format("[TRUE$0]", test) == "[TRUE99]"); } // Test for booleans. { Boolean flag = true; Boolean flag2 = false; String str = Formatter::format(" TRUE $0 FALSE $1 FALSE $2", flag, !flag, flag2); if (verbose) cout << "str[" << str << "]" << endl; assert(Formatter::format("TRUE$0", flag ) == "TRUEtrue"); assert(Formatter::format("FALSE$0", flag2 ) == "FALSEfalse"); } // Tests for Uint32 and Sint32 { Uint32 test1 = 9999; Sint32 test2 = 9999; String str = Formatter::format("\\$test1 $0 \\$test2 $1", test1, test2); if (verbose) cout << "str[" << str << "]" << endl; assert(Formatter::format("[TRUE$0]", test1 ) == "[TRUE9999]"); assert(Formatter::format("[TRUE$0]", test2 ) == "[TRUE9999]"); } // Test for 64 bit signed integer { Sint64 test1 = PEGASUS_SINT64_LITERAL(0x7fffffffffffffff); Sint64 test2 = PEGASUS_SINT64_LITERAL(0x8000000000000000); Sint64 test3 = PEGASUS_SINT64_LITERAL(0xffffffffffffffff); String str = Formatter::format( "test1 $0 test2 $1 test3 $2", test1, test2, test3); if (verbose) { cout << "str[" << str << "]" << endl; } assert(Formatter::format("[TRUE$0]", test1) == "[TRUE9223372036854775807]"); assert(Formatter::format("[TRUE$0]", test2) == "[TRUE-9223372036854775808]"); assert(Formatter::format("[TRUE$0]", test3) == "[TRUE-1]"); } // Test for 64 bit unsigned integer { Uint64 test1 = PEGASUS_UINT64_LITERAL(0x7fffffffffffffff); Uint64 test2 = PEGASUS_UINT64_LITERAL(0x8000000000000000); Uint64 test3 = PEGASUS_UINT64_LITERAL(0xffffffffffffffff); String str = Formatter::format( "test1 $0 test2 $1 test3 $2", test1, test2, test3); if (verbose) { cout << "str[" << str << "]" << endl; } assert(Formatter::format("[TRUE$0]", test1) == "[TRUE9223372036854775807]"); assert(Formatter::format("[TRUE$0]", test2) == "[TRUE9223372036854775808]"); assert(Formatter::format("[TRUE$0]", test3) == "[TRUE18446744073709551615]"); } // Test for all 10 parameters in the string { Uint32 t0 = 1; Uint32 t1 = 1; Uint32 t2 = 2; Uint32 t3 = 3; Uint32 t4 = 4; Uint32 t5 = 5; Uint32 t6 = 6; Uint32 t7 = 7; Uint32 t8 = 8; Uint32 t9 = 9; String str = Formatter::format("[$0$1$2$3$4$5$6$7$8$9]", t0,t1,t2,t3,t4,t5,t6,t7,t8,t9); if (verbose) cout << "str[" << str << "]" << endl; assert(Formatter::format("[$0$1$2$3$4$5$6$7$8$9]", t0,t1,t2,t3,t4,t5,t6,t7,t8,t9) == "[1123456789]"); } cout << argv[0] << " +++++ passed all tests" << endl; return 0; }
// For Increasing the Coverage of CMPIInstance static int _testInstance () { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIInstance* instance = NULL; CMPIObjectPath* objPath = NULL; CMPIObjectPath* objPathFake = NULL; CMPIValue value; CMPIType type = CMPI_uint64; CMPIData retData; CMPIData returnedData1; const char* property_name = "s"; const char* origin = "origin"; void* handle; int flag = 1; value.uint64 = PEGASUS_UINT64_LITERAL(5000000000); PROV_LOG("++++ _testInstance"); objPath = make_ObjectPath(_broker, _Namespace, "TestCMPI_Instance"); instance = make_Instance(objPath); /* Test cases to increase coverage in instSetPropertyWithOrigin function */ /* Setting n64 property in class TestCMPI_Instance. So origin has been set to TestCMPI_Instance.*/ rc = CMSetPropertyWithOrigin(instance, "n64", &value, type, "TestCMPI_Instance"); if ( rc.rc == CMPI_RC_OK ) { PROV_LOG("++++ SetPropertyWithOrigin for n64 property status : (%s)", strCMPIStatus(rc)); } /* CMGetProperty is called to verify the value of the property just being set. */ retData = CMGetProperty(instance, "n64", &rc); if (retData.type == CMPI_uint64 && retData.value.uint64 == PEGASUS_UINT64_LITERAL(5000000000)) { PROV_LOG("++++ CMGetProperty for n64 property status : (%s)," "value (%"PEGASUS_64BIT_CONVERSION_WIDTH"u)", strCMPIStatus(rc), retData.value.uint64); } /* Setting non-member property of type CMPI_ref*/ type= CMPI_ref; value.ref = objPath; rc = CMSetPropertyWithOrigin(instance, "objPath", &value, type, origin); if ( rc.rc == CMPI_RC_OK ) { PROV_LOG("++++ SetPropertyWithOrigin status : (%s)",strCMPIStatus(rc)); } /* Setting non-memeber property of type other than CMPI_ref*/ value.uint32 = 32; type = CMPI_uint32; rc = CMSetPropertyWithOrigin(instance, "n32", &value, type, NULL); if ( rc.rc == CMPI_RC_OK ) { PROV_LOG("++++ SetPropertyWithOrigin status : (%s)",strCMPIStatus(rc)); } /* Testing error path for instGetProperty with NULL property name*/ returnedData1 = CMGetProperty(instance, NULL, &rc); if (rc.rc == CMPI_RC_ERR_INVALID_PARAMETER ) { PROV_LOG("++++ CMGetProperty with NULL property name status: (%s) ", strCMPIStatus(rc)); } /*-----------------------------------------------------------------------*/ /* Test cases to cover error paths for instSetObjectPath and instSetPropertyFilter*/ /* Testing error path by passing CMPIObjectPath with class name different from the classname for CMPIInstance in CMSetObjectPath*/ objPathFake = CMNewObjectPath(_broker, _Namespace, "TestCMPIInstance_Method", NULL); rc = CMSetObjectPath(instance, objPathFake); if ( rc.rc == CMPI_RC_ERR_FAILED || rc.rc == CMPI_RC_ERR_NOT_SUPPORTED) { PROV_LOG("++++ Test for CMSetObjectPath with wrong input passed"); } /* Testing error path by passing NULL to instSetObjectPath*/ rc = CMSetObjectPath(instance, NULL); if ( rc.rc == CMPI_RC_ERR_INVALID_PARAMETER || rc.rc == CMPI_RC_ERR_NOT_SUPPORTED) { PROV_LOG("++++ Test for CMSetObjectPath with NULL input passed "); } /* Testing error paths by setting handle to CMPIInstance to NULL and using that in calls to instSetObjectPath and instSetPropertyFilter*/ handle = instance->hdl; instance->hdl = NULL ; rc = CMSetObjectPath(instance, NULL); if ( rc.rc == CMPI_RC_ERR_INVALID_HANDLE || rc.rc == CMPI_RC_ERR_NOT_SUPPORTED) { PROV_LOG("++++ CMSetObjectPath with NULL handle for" " CMPIInstance passed"); } PROV_LOG("++++ CMSetObjectPath : (%s) ",strCMPIStatus(rc)); rc = CMSetPropertyFilter(instance,&property_name,NULL); if( rc.rc == CMPI_RC_ERR_INVALID_HANDLE ) { PROV_LOG("++++ CMSetPropertyFilter with NULL handle for CMPIInstance" " status : (%s)", strCMPIStatus (rc)); } instance->hdl = handle; /*-----------------------------------------------------------------------*/ return flag; } // _testInstance end