static int _testCMPIResult(const CMPIResult *rslt) { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIValue value; CMPIType type; const CMPIObjectPath *objPath = NULL; CMPIBoolean returnDataSuccessful = 0; value.uint32 = 10; type = CMPI_uint32; rc = CMReturnData(rslt, &value, type); if (rc.rc == CMPI_RC_OK) { returnDataSuccessful = 1; } objPath = make_ObjectPath(_broker, _Namespace, _ClassName); rc = CMReturnObjectPath(rslt, objPath); rc = CMReturnDone(rslt); rc = CMReturnData(rslt, NULL, type); if (rc.rc != CMPI_RC_ERR_INVALID_PARAMETER) { return 1; } return 0; }
static int _testCMPIEnumeration(const CMPIContext *ctx) { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIEnumeration *enum_ptr = NULL; CMPIData data; unsigned int initCount = 0; CMPIObjectPath *objPath = NULL; CMPIArray *arr_ptr = NULL; CMPICount returnedArraySize; void *eptr; objPath = make_ObjectPath(_broker, _Namespace, _PersonClass); enum_ptr = CBEnumInstances(_broker, ctx, objPath, NULL, &rc); if (enum_ptr == NULL) { return 1; } arr_ptr = CMToArray(enum_ptr, &rc); if (arr_ptr == NULL) { return 1; } returnedArraySize = CMGetArrayCount(arr_ptr, &rc); while (CMHasNext(enum_ptr, &rc)) { data = CMGetNext(enum_ptr, &rc); if (data.type != CMPI_instance) { return 1; } initCount++; } eptr = enum_ptr->hdl; enum_ptr->hdl = NULL; CMToArray(enum_ptr, &rc); if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) { return 1; } CMGetNext(enum_ptr, &rc); if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) { return 1; } CMHasNext(enum_ptr, &rc); if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) { return 1; } enum_ptr->hdl = eptr; rc = CMRelease(enum_ptr); if (rc.rc != CMPI_RC_OK) { return 1; } return 0; }
// To increase the coverage in CMPIBrokerEnc.cpp static int _testBrokerEnc (const CMPIContext * ctx, const CMPIResult * rslt) { int flag = 1 ; int count; char* msgId; char* illegal; char path[100]; void* hdl; CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIString *type; CMPIString *cmpiStr; CMPIBoolean bol=0; CMPIBoolean bool=0; CMPIArray* cmpiArray = NULL ; CMPIInstance* instance = NULL; CMPIInstance* instance1 = NULL; CMPIInstance* instanceErr = NULL; CMPIObjectPath* objPath = NULL; CMPIObjectPath* objPath1 = NULL; CMPICount cmpiCnt = 5; CMPIType cmpiType = CMPI_uint64; CMPIDateTime* cmpiDateTime = NULL ; CMPIMsgFileHandle msgFileHandle; CMPIEnumeration* cmpiEnum; CMPISelectExp* selExp; CMPIValue val; CMPIError* err; CMPIStatus* rc1 = NULL; CMPIArgs* args = NULL; void* handle; CMPIInstanceFT* funcTable; PROV_LOG ("++++ _testBrokerEnc "); PROV_LOG ("++++ ObjectPath testing"); objPath1 = CMNewObjectPath (_broker, NULL, _ClassName, &rc); PROV_LOG ("++++ New object path with NULL namespace creation : (%s)", strCMPIStatus (rc)); CMRelease(objPath1); objPath1 = CMNewObjectPath (_broker, _Namespace, "abc", &rc); PROV_LOG ("++++ New object path with wrong classname : (%s)", strCMPIStatus (rc)); instance = CMNewInstance(_broker, NULL, &rc); PROV_LOG ("++++ New Instance with NULL object path : (%s)", strCMPIStatus (rc)); handle = objPath1->hdl; objPath1->hdl=NULL; instance = CMNewInstance(_broker, objPath1, &rc); PROV_LOG ("++++ New Instance with object path handle set to NULL: (%s)", strCMPIStatus (rc)); objPath1->hdl = handle; objPath = make_ObjectPath(_broker, _Namespace, _ClassName); instance = CMNewInstance(_broker, objPath, &rc); PROV_LOG ("++++ New Instance creation status: (%s)", strCMPIStatus (rc)); instance1 = CMClone(instance, &rc); instanceErr = CMClone(instance, &rc); cmpiStr = CMNewString(_broker, NULL, &rc); PROV_LOG ("++++ Status of mbNewString with NULL parameter:(%s)", strCMPIStatus (rc)); err = CMNewCMPIError(_broker, "abc", "abc", "abc", 4, 5, 6, rc1); if (err) { PROV_LOG ("++++ CMNewCMPIError called with null rc"); } cmpiDateTime = CMNewDateTimeFromChars(_broker, "datetime", &rc); PROV_LOG ("++++ Status of CMNewDateTimeFromChars with junk parameter:(%s)", strCMPIStatus (rc)); if (!CMClassPathIsA(_broker, NULL, NULL, &rc)) { PROV_LOG ("++++ Error Status of CMClassPathIsA:(%s)", strCMPIStatus (rc)); } if (!CMClassPathIsA(_broker, objPath, NULL, &rc)) { PROV_LOG ("++++ Error Status of CMClassPathIsA:(%s)", strCMPIStatus (rc)); } illegal = "$"; if (!CMClassPathIsA(_broker, objPath, illegal, &rc)) { PROV_LOG ("++++ Error Status of CMClassPathIsA:(%s)", strCMPIStatus (rc)); } rc = CMLogMessage(_broker, 2, "TestProvider", "Testing Severity 2 in TestCMPIBrokerEnc", NULL); PROV_LOG ("++++ Status of CMLogMessage with Severity 2:(%s)", strCMPIStatus (rc)); rc = CMLogMessage(_broker, 3, "TestProvider", "Testing Severity 3 in TestCMPIBrokerEnc", NULL); PROV_LOG ("++++ Status of CMLogMessage with Severity 3:(%s)", strCMPIStatus (rc)); rc = CMLogMessage(_broker, 4, "TestProvider", "Testing Severity 4 in TestCMPIBrokerEnc", NULL); PROV_LOG ("++++ Status of CMLogMessage with Severity 4:(%s)", strCMPIStatus (rc)); rc = CMTraceMessage(_broker, 2, "CMPIProvider", "Tracing for level 2", NULL); PROV_LOG ("++++ Status of CMTraceMessage with level 2:(%s)", strCMPIStatus (rc)); rc = CMTraceMessage(_broker, 3, "CMPIProvider", "Tracing for level 3", NULL); PROV_LOG ("++++ Status of CMTraceMessage with level 3:(%s)", strCMPIStatus (rc)); rc = CMTraceMessage(_broker, 4, "CMPIProvider", "Tracing for level 4", NULL); PROV_LOG ("++++ Status of CMTraceMessage with level 4:(%s)", strCMPIStatus (rc)); cmpiStr = CMNewString(_broker, "Tracing for level 5", &rc); rc = CMTraceMessage(_broker, 5, "CMPIProvider", NULL, cmpiStr); PROV_LOG ("++++ Status of CMTraceMessage with level 5:(%s)", strCMPIStatus (rc)); CMRelease(cmpiStr); PROV_LOG ("++++ Calling mbEncToString function "); type = CDToString (_broker, _broker, &rc); PROV_LOG ("++++ Error status of mbEncToString with wrong object path:" " (%s)", strCMPIStatus (rc)); type = CDToString (_broker, NULL, &rc); PROV_LOG ("++++ Error status of mbEncToString with NULL parameter:" " (%s)", strCMPIStatus (rc)); type = CDToString (_broker, type, &rc); PROV_LOG ("++++ Passing CMPIString to mbEncToString successes : (%s)", strCMPIStatus (rc)); type = CDToString (_broker, objPath, &rc); PROV_LOG ("++++ Passing CMPIObjectPath to mbEncToString successes : (%s)", strCMPIStatus (rc)); handle = objPath1->hdl; objPath1->hdl = NULL; type = CDToString (_broker, objPath1, &rc); if ( rc.rc == CMPI_RC_ERR_INVALID_PARAMETER) { PROV_LOG ("++++ Error status of mbEncToString with object path with " "NULL handle: (%s)", strCMPIStatus (rc)); } objPath1->hdl = handle; val.boolean = 1; rc = CMSetProperty (instance, "Boolean", &val, CMPI_boolean); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_boolean : (%s)", strCMPIStatus (rc)); val.uint8 = 8; rc = CMSetProperty (instance, "Uint8", &val, CMPI_uint8); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_uint8 : (%s)", strCMPIStatus (rc)); val.uint16 = 16; rc = CMSetProperty (instance, "Uint16", &val, CMPI_uint16); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_uint16 : (%s)", strCMPIStatus (rc)); val.uint32 = 32; rc = CMSetProperty (instance, "Uint32", &val, CMPI_uint32); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_uint32 : (%s)", strCMPIStatus (rc)); val.uint64 = 64; rc = CMSetProperty (instance, "Uint64", &val, CMPI_uint64); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_uint64 : (%s)", strCMPIStatus (rc)); val.sint8 = -8; rc = CMSetProperty (instance, "Sint8", &val, CMPI_sint8); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_sint8 : (%s)", strCMPIStatus (rc)); val.sint16 = -16; rc = CMSetProperty (instance, "Sint16", &val, CMPI_sint16); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_sint16 : (%s)", strCMPIStatus (rc)); val.sint32 = -32; rc = CMSetProperty (instance, "Sint32", &val, CMPI_sint32); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_sint32 : (%s)", strCMPIStatus (rc)); val.sint64 = -64; rc = CMSetProperty (instance, "Sint64", &val, CMPI_sint64); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_sint64 : (%s)", strCMPIStatus (rc)); val.real32 = 32.32; rc = CMSetProperty (instance, "Real32", &val, CMPI_real32); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_real32 : (%s)", strCMPIStatus (rc)); val.real64 = 64.64; rc = CMSetProperty (instance, "Real64", &val, CMPI_real64); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_real64 : (%s)", strCMPIStatus (rc)); val.char16 = 'c'; rc = CMSetProperty (instance, "Char16", &val, CMPI_char16); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_char16 : (%s)", strCMPIStatus (rc)); cmpiDateTime = CMNewDateTime (_broker, &rc); val.dateTime = cmpiDateTime; rc = CMSetProperty (instance, "DateTime", &val, CMPI_dateTime); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_dateTime : (%s)", strCMPIStatus (rc)); val.ref = objPath; rc = CMSetProperty (instance, "Ref", &val, CMPI_ref); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_ref : (%s)", strCMPIStatus (rc)); val.inst = instance1; rc = CMSetProperty (instance, "Instance", &val, CMPI_instance); PROV_LOG ("++++ Status of CMSetProperty of type CMPI_instance : (%s)", strCMPIStatus (rc)); type = CDToString (_broker, instance, &rc); PROV_LOG ("++++ Passing CMPIInstance to mbEncToString successes : (%s)", strCMPIStatus (rc)); args = CMNewArgs(_broker, &rc); PROV_LOG ("++++ Status of CMNewArgs : (%s)", strCMPIStatus (rc)); type = CDToString (_broker, args, &rc); PROV_LOG ("++++ Passing CMPIArgs to mbEncToString successes : (%s)", strCMPIStatus (rc)); PROV_LOG ("++++ Calling mbEncGetType function "); rc1 = NULL; type = CDGetType (_broker, NULL, rc1); if (!type) { PROV_LOG ("++++ Error calling mbEncGetType with NULL rc"); } rc1 = NULL; funcTable = instanceErr->ft; instanceErr->ft = NULL; type = CDGetType (_broker, instanceErr, rc1); if (!type) { PROV_LOG ("++++ Error calling mbEncGetType with wrong parameter and" " NULL rc"); } type = CDGetType (_broker, instanceErr, &rc); PROV_LOG ("++++ Error status of mbEncGetType with wrong input : (%s)", strCMPIStatus (rc)); instanceErr->ft = funcTable; type = CDGetType (_broker, NULL, &rc); PROV_LOG ("++++ Error status of mbEncGetType with NULL input : (%s)", strCMPIStatus (rc)); type = CDGetType (_broker, instance, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIInstance" " : (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CDGetType (_broker, objPath, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIObjectPath:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); cmpiStr = CMNewString(_broker, "Test1", & rc); type = CDGetType (_broker, cmpiStr, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIString:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CDGetType (_broker, _broker, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIBroker:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); cmpiArray = CMNewArray(_broker, cmpiCnt,cmpiType, &rc); type = CDGetType (_broker, cmpiArray, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIArray:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CDGetType (_broker, cmpiDateTime, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIDateTime:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CDGetType (_broker, ctx, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIContext:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CDGetType (_broker, rslt, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIResult:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); rc1 = NULL; selExp = CMNewSelectExp(_broker, "SELECT c,b FROM TestCMPI_Indication WHERE c='c' OR b=1", "WQL", NULL, rc1); PROV_LOG ("++++ CMNewSelectExp with rc set to NULL Called"); selExp = CMNewSelectExp(_broker, "SELECT c,b FROM TestCMPI_Indication", "WQL", NULL, &rc); PROV_LOG ("++++ Status of CMNewSelectExp: (%s) ", strCMPIStatus (rc)); type = CDGetType (_broker, selExp, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPISelectExp:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); handle = objPath1->hdl; objPath1->hdl = NULL; rc = CMRelease(objPath1); PROV_LOG ("++++ Status of CMRelease(objPath1): (%s)", strCMPIStatus (rc)); objPath1->hdl = handle; rc = CMRelease(objPath1); PROV_LOG ("++++ Status of CMRelease(objPath1): (%s)", strCMPIStatus (rc)); objPath1 = CMNewObjectPath(_broker, "test/TestProvider", "TestCMPI_Instance", &rc); PROV_LOG ("++++ Status of CMNewObjectPath for TestCMPI_Instance : (%s)", strCMPIStatus (rc)); PROV_LOG_CLOSE(); cmpiEnum = CBEnumInstances(_broker, ctx, objPath1, NULL, &rc); PROV_LOG_OPEN (_ClassName, _ProviderLocation); PROV_LOG ("++++ Status of CBEnumInstances : (%s)", strCMPIStatus (rc)); type = CDGetType (_broker, cmpiEnum, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIEnumeration:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CDGetType (_broker, args, &rc); PROV_LOG ("++++ Status of mbEncGetType with input of type CMPIArgs:" " (%s) type(%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); PROV_LOG ("++++ Calling mbEncIsOfType function "); bol = CDIsOfType (_broker, NULL, "No object", rc1); if(!bol) { PROV_LOG ("++++Calling mbEncIsOfType with NULL rc and wrong" " parameters"); } bol = CDIsOfType (_broker, instance, "CMPIInstance", rc1); if(!bol) { PROV_LOG ("++++ Calling mbEncIsOfType with NULL rc"); } bol = CDIsOfType (_broker, NULL, "No object", &rc); PROV_LOG ("++++ Error Status of mbEncIsOfType : (%s)", strCMPIStatus (rc)); bol = CDIsOfType (_broker, instance, "CMPIInstance", &rc); if ( bol ) { PROV_LOG ("++++ CDIsOfType for CMPIInstance status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, instance, "CMPI", &rc); if ( !bol ) { PROV_LOG ("++++ CDIsOfType for CMPIInstance status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, objPath, "CMPIObjectPath", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIObjectPath status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, objPath, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIObjectPath status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiDateTime, "CMPIDateTime", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIDateTime status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiDateTime, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIDateTime status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiStr, "CMPIString", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIString status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiStr, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIString status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, _broker, "CMPIBroker", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIBroker status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, _broker, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIBroker status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiArray, "CMPIArray", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIArray status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiArray, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIArray status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, rslt, "CMPIResult", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIResult status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, rslt, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIResult status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, ctx, "CMPIContext", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIContext status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, ctx, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIContext status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiEnum, "CMPIEnumeration", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIEnumeration status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, cmpiEnum, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPIEnumeration status is (%s) : %d", strCMPIStatus (rc), bol); } /* Testcase to increase coverage in CMPI_Enumeration.cpp*/ rc = CMRelease(cmpiEnum); PROV_LOG ("++++ Status of CMRelease on cmpiEnum :(%s)", strCMPIStatus (rc)); /**********************************************************/ bol = CDIsOfType (_broker, selExp, "CMPISelectExp", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPISelectExp status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, selExp, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CDIsOfType for CMPISelectExp status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, args, "CMPIArgs", &rc); if (bol) { PROV_LOG ("++++ CDIsOfType for CMPIArgs status is (%s) : %d", strCMPIStatus (rc), bol); } bol = CDIsOfType (_broker, args, "CMPI", &rc); if (!bol) { PROV_LOG ("++++ CdIsOfType for CMPIArgs status is (%s) : %d", strCMPIStatus (rc), bol); } type = CMGetMessage (_broker, "msgid", "Test 0 arguments", &rc, 0); PROV_LOG ("++++ Status of GetMessage with 0 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0", &rc, CMFmtArgs1(CMFmtChars("one argument"))); PROV_LOG ("++++ Status of GetMessage with 1 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1", &rc, CMFmtArgs2(CMFmtChars("Sint32 ::"), CMFmtSint(-1))); PROV_LOG ("++++ Status of GetMessage with 2 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1, $2", &rc, CMFmtArgs3(CMFmtChars("Sint32, Uint32 ::"), CMFmtSint(-1), CMFmtUint(1))); PROV_LOG ("++++ Status of GetMessage with 3 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1, $2, $3", &rc, CMFmtArgs4(CMFmtChars("Sint32, Uint32, Sint64 ::"), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64))); PROV_LOG ("++++ Status of GetMessage with 4 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1, $2, $3, $4", &rc, CMFmtArgs5(CMFmtChars("Sint32, Uint32, Sint64, Uint64 ::"), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64))); PROV_LOG ("++++ Status of GetMessage with 5 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1, $2, $3, $4, $5", &rc, CMFmtArgs6(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64 ::"), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64))); PROV_LOG ("++++ Status of GetMessage with 6 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1, $2, $3, $4, $5, $6", &rc, CMFmtArgs7(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64," " Boolean:: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64), CMFmtBoolean(1))); PROV_LOG ("++++ Status of GetMessage with 7 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1, $2, $3, $4, $5, $6, $7", &rc, CMFmtArgs8(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64," " Boolean, chars:: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64), CMFmtBoolean(1), CMFmtChars("chars"))); PROV_LOG ("++++ Status of GetMessage with 8 arguments(%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage (_broker, "msgid", "Test $0 $1, $2, $3, $4, $5, $6, $7, $8", &rc, CMFmtArgs9(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64," " Boolean, chars, String :: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64), CMFmtBoolean(1), CMFmtChars("chars"), CMFmtString(cmpiStr))); PROV_LOG ("++++ Status of GetMessage with 9 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); strcpy(path,"path"); rc = CMOpenMessageFile(_broker, path, &msgFileHandle); PROV_LOG ("++++ Status of CMOpenMessageFile (%s) ", strCMPIStatus (rc)); type = CMGetMessage2(_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test zero arguments", &rc, 0); PROV_LOG ("++++ Status of GetMessage2 with 0 argument (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2(_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0", &rc, CMFmtArgs1(CMFmtChars("Single argument"))); PROV_LOG ("++++ Status of GetMessage2 with 1 argument (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2(_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1", &rc, CMFmtArgs2(CMFmtChars("Sint32 ::"),CMFmtSint(1))); PROV_LOG ("++++ Status of GetMessage2 with 2 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2 (_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1, $2", &rc, CMFmtArgs3(CMFmtChars("Sint32, Uint32 :: "), CMFmtSint(-1), CMFmtUint(1))); PROV_LOG ("++++ Status of GetMessage2 with 3 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2 (_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1, $2, $3", &rc, CMFmtArgs4(CMFmtChars("Sint32, Uint32, Sint64 :: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64))); PROV_LOG ("++++ Status of GetMessage2 with 4 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2 (_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1, $2, $3, $4", &rc, CMFmtArgs5(CMFmtChars("Sint32, Uint32, Sint64, Uint64 :: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64))); PROV_LOG ("++++ Status of GetMessage2 with 5 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2 (_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1, $2, $3, $4, $5", &rc, CMFmtArgs6(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64 :: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64))); PROV_LOG ("++++ Status of GetMessage2 with 6 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2 (_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1, $2, $3, $4, $5, $6", &rc, CMFmtArgs7(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64," " Boolean :: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64), CMFmtBoolean(1))); PROV_LOG ("++++ Status of GetMessage2 with 7 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2 (_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1, $2, $3, $4, $5, $6, $7", &rc, CMFmtArgs8(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64," " Boolean, chars :: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64), CMFmtBoolean(1), CMFmtChars("chars"))); PROV_LOG ("++++ Status of GetMessage2 with 8 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); type = CMGetMessage2 (_broker, "Common.CIMStatusCode.CIM_ERR_SUCCESS", msgFileHandle, "Test $0 $1, $2, $3, $4, $5, $6, $7, $8", &rc, CMFmtArgs9(CMFmtChars("Sint32, Uint32, Sint64, Uint64, Real64," " Boolean, chars, String :: "), CMFmtSint(-1), CMFmtUint(1), CMFmtSint64(-64), CMFmtUint64(64), CMFmtReal(64.64), CMFmtBoolean(1), CMFmtChars("chars"), CMFmtString(cmpiStr))); PROV_LOG ("++++ Status of GetMessage2 with 9 arguments (%s) type (%s)", strCMPIStatus (rc), CMGetCharsPtr(type, NULL)); rc = CMCloseMessageFile(_broker, msgFileHandle); PROV_LOG ("++++ Status of CMCloseMessageFile (%s) ", strCMPIStatus (rc)); CMRelease(instance1); CMRelease(instanceErr); return flag ; }
static CMPI_THREAD_RETURN CMPI_THREAD_CDECL thread (void *args) { CMPIString *str = NULL; CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIStatus rc_Eval = { CMPI_RC_OK, NULL }; CMPIStatus rc_Clone = { CMPI_RC_OK, NULL }; CMPIStatus rc_Inst = { CMPI_RC_OK, NULL }; CMPIStatus rc_Pred = { CMPI_RC_OK, NULL }; CMPIStatus rc_Array = { CMPI_RC_OK, NULL }; CMPIStatus rc_CMGetPropertyAt = { CMPI_RC_OK, NULL }; CMPIString *type = NULL; CMPISelectExp *clone = NULL; CMPIBoolean evalRes; CMPIInstance *inst = NULL; CMPIObjectPath *objPath = NULL; CMPIString *name = NULL; CMPIData prop_data = { 0, CMPI_null, {0} }; CMPIData data = { 0, CMPI_null, {0} }; CMPIArray *projection = NULL; /* General purpose counters */ unsigned int idx; CMPICount cnt; /* Select Condition and sub conditions */ CMPISelectCond *cond = NULL; int sub_type; CMPISubCond *subcnd = NULL; /* Predicate operations */ CMPICount pred_cnt; unsigned int pred_idx; CMPIPredicate *pred = NULL; CMPIType pred_type; CMPIPredOp pred_op; CMPIString *left_side = NULL; CMPIString *right_side = NULL; /* Thread specific data, passed in via arguments. This could also be passed via thread specific data.. */ void **arguments = (void **) args; CMPIContext *ctx; CMPISelectExp *se; char *ns; CMPIBroker *broker; // Copy over the CMPISelectExp, CMPIContext, CMPIBroker and the ns from the argument. se = (CMPISelectExp *)arguments[0]; ctx = (CMPIContext *)arguments[1]; broker = (CMPIBroker *)arguments[2]; ns = (char *)arguments[3]; free(arguments); _thread_active = 1; // Get the CMPIContext and attach it to this thread. rc = CBAttachThread (broker, ctx); // Wait until we get the green signal. while (_thread_runs == 0) { broker->xft->threadSleep(1000); } //PROV_LOG_OPEN (_IndClassName, _ProviderLocation); PROV_LOG ("--- CBAttachThread callled."); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc), (rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("--- %s CMPI thread(void *) running",_IndClassName); PROV_LOG ("-- #1 Clone"); clone = CMClone (se, &rc_Clone); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Clone), (rc_Clone.msg == 0) ? "" : CMGetCharPtr(rc_Clone.msg)); if (clone) CMRelease (clone); /* This functionality is not used in indication providers, but instead in ExecQuery provider API (instance providers). But for the sake of completness this functionality is also used here. */ PROV_LOG ("-- #1.1 CMNewSelectExp"); str = CMGetSelExpString (se, &rc); clone = //CMPI_CQL_NewSelectExp (broker, CMGetCharPtr (str), "CIMxCQL", CMNewSelectExp (broker, CMGetCharPtr (str), "CIM:CQL", &projection, &rc_Clone); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Clone), (rc_Clone.msg == 0) ? "" : CMGetCharPtr(rc_Clone.msg)); if (clone) { if (projection) { PROV_LOG ("--- #1.2 Projection list is: "); cnt = CMGetArrayCount (projection, &rc_Array); PROV_LOG ("---- %s, [%s]", strCMPIStatus (rc_Array),(rc_Array.msg == 0) ? "" : CMGetCharPtr(rc_Array.msg)); PROV_LOG ("--- #1.3 CMGetArrayCount, %d", cnt); for (idx = 0; idx < cnt; idx++) { PROV_LOG ("--- #1.4 CMGetArrayElementAt"); data = CMGetArrayElementAt (projection, idx, &rc_Array); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Array), (rc_Array.msg == 0) ? "" : CMGetCharPtr(rc_Array.msg)); PROV_LOG ("---- type is : %d", data.type); if (data.type == CMPI_chars) { PROV_LOG ("---- %s (chars)", data.value.chars); } if (data.type == CMPI_string) { PROV_LOG ("---- %s (string)", CMGetCharPtr (data.value.string)); } } } else { PROV_LOG ("--- #1.2 No projection list, meaning it is SELECT * .... "); } } // This is how an indication provider would work. // Create an objectpath + instance and use CMEvaluateSelExp // OR // use CMEvaluateSelExpUsingAccessor and pass in the function that would // provide the properties values. PROV_LOG ("-- #2 MakeObjectPath"); // Create instance objPath = make_ObjectPath (broker, _Namespace, _IndClassName); type = CDGetType (broker, objPath, &rc_Inst); PROV_LOG ("---- %s (%s) [%s]", CMGetCharPtr (type), strCMPIStatus (rc_Inst),(rc_Inst.msg == 0) ? "" : CMGetCharPtr(rc_Inst.msg)); CMRelease (type); PROV_LOG ("-- #3 Instance"); inst = CMNewInstance (broker, objPath, &rc_Inst); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Inst), (rc_Inst.msg == 0) ? "" : CMGetCharPtr(rc_Inst.msg)); if (rc_Inst.rc == CMPI_RC_ERR_NOT_FOUND) { PROV_LOG (" --- Class %s is not found in the %s namespace!", _IndClassName, _Namespace); PROV_LOG (" --- Aborting!!! "); goto exit; } type = CDGetType (broker, inst, &rc_Inst); if (type) { PROV_LOG ("---- %s (%s) [%s]", CMGetCharPtr (type), strCMPIStatus (rc_Inst),(rc_Inst.msg == 0) ? "" : CMGetCharPtr(rc_Inst.msg)); CMRelease (type); } PROV_LOG ("- CMGetPropertyCount: %d", CMGetPropertyCount (inst, &rc)); // Set each property. for (idx = 0; idx < CMGetPropertyCount (inst, &rc); idx++) { prop_data = CMGetPropertyAt (inst, idx, &name, &rc_CMGetPropertyAt); // Really dumb way of doing it. Just set each property with its own property name. if (prop_data.type == CMPI_string) { CMSetProperty (inst, CMGetCharPtr (name), CMGetCharPtr (name), CMPI_chars); } prop_data = CMGetPropertyAt (inst, idx, &name, &rc_CMGetPropertyAt); PROV_LOG ("-- %d: %s(%s: %s: %s) [%s]", idx, CMGetCharPtr (name), strCMPIType (prop_data.type), strCMPIValueState (prop_data.state), strCMPIValue (prop_data.value), strCMPIStatus (rc_CMGetPropertyAt)); } PROV_LOG ("-- #4 Evaluate using instance"); evalRes = CMEvaluateSelExp (se, inst, &rc_Eval); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Eval), (rc_Eval.msg == 0) ? "" : CMGetCharPtr(rc_Eval.msg)); if (evalRes == CMPI_true) { PROV_LOG ("--- True, sending indication"); rc_Eval = CBDeliverIndication (broker, ctx, _Namespace, inst); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Eval), (rc_Eval.msg == 0) ? "" : CMGetCharPtr(rc_Eval.msg)); } else { PROV_LOG ("--- False"); } PROV_LOG ("-- #4.1 Evalute using accessor"); evalRes = CMEvaluateSelExpUsingAccessor (se, instance_accessor, broker, &rc_Eval); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Eval), (rc_Eval.msg == 0) ? "" : CMGetCharPtr(rc_Eval.msg)); if (evalRes == CMPI_true) { PROV_LOG ("--- True, but not sending indication"); } else { PROV_LOG ("--- False"); } PROV_LOG ("-- #5 CMGetSelExpString"); str = CMGetSelExpString (se, &rc); type = CDGetType (broker, str, &rc_Inst); if (type != NULL) { PROV_LOG ("---- %s (%s) [%s]", CMGetCharPtr (type), strCMPIStatus (rc_Inst), (rc_Inst.msg == 0) ? "" : CMGetCharPtr(rc_Inst.msg)); CMRelease (type); } PROV_LOG ("---- %s [%s]", strCMPIStatus (rc), (rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("-- #5.1 Query is [%s]", CMGetCharPtr (str)); PROV_LOG ("-- #5.2 Query is [%s]", ns); PROV_LOG ("-- #6 Continue evaluating using GetDOC"); { cond = CMGetDoc (se, &rc); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc), (rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); if (cond != NULL) { PROV_LOG ("--- #6.1 CMGetSubCondCountAndType "); cnt = CMGetSubCondCountAndType (cond, &sub_type, &rc); PROV_LOG ("---- %s %s", strCMPIStatus (rc), (rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("---- Number of disjunctives: %d, Type: %X", cnt, sub_type); /* Parsing the disjunctives */ for (idx = 0; idx < cnt; idx++) { PROV_LOG ("--- #6.2 CMGetSubCondAt @ %d ", idx); subcnd = CMGetSubCondAt (cond, idx, &rc); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc),(rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("--- #6.3 CMGetPredicateCount"); pred_cnt = CMGetPredicateCount (subcnd, &rc); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc), (rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("---- Number of predicates in the conjuctives: %d", pred_cnt); /* Parsing throught conjuctives */ for (pred_idx = 0; pred_idx < pred_cnt; pred_idx++) { PROV_LOG ("--- #6.4 CMGetPredicateAt, %d", pred_idx); pred = CMGetPredicateAt (subcnd, pred_idx, &rc); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc),(rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("--- #6.4 CMGetPredicateData"); rc = CMGetPredicateData (pred, &pred_type, &pred_op, &left_side, &right_side); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc),(rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("----- Type: %s , CMPIPredOp: %s, LS: %s, RS: %s", strCMPIType (pred_type), strCMPIPredOp (pred_op), CMGetCharPtr (left_side), CMGetCharPtr (right_side)); PROV_LOG ("--- #6.5 Evaluate using predicate"); #ifdef CMPI_VER_100 // The CMEvaluatePredicate is gone in the CMPI 1.0 standard. evalRes = CMEvaluatePredicateUsingAccessor (pred, instance_accessor, NULL, &rc_Pred); #else // One can also evaluate this specific predicate evalRes = CMEvaluatePredicate (pred, "PredicateEvaluation", CMPI_chars, &rc_Pred); #endif PROV_LOG ("---- %s [%s]", strCMPIStatus (rc_Pred), (rc_Pred.msg == 0) ? "" : CMGetCharPtr(rc_Pred.msg)); if (evalRes == CMPI_true) { PROV_LOG ("--- True"); } else { PROV_LOG ("--- False"); } } } } } PROV_LOG ("-- #7 GetCOD"); { cond = CMGetCod (se, &rc); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc), (rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); /* Currently this is not supported in Pegasus. */ if (cond != NULL) { } } exit: PROV_LOG ("--- CBDetachThread called"); rc = CBDetachThread (broker, ctx); free (ns); PROV_LOG ("---- %s [%s]", strCMPIStatus (rc), (rc.msg == 0) ? "" : CMGetCharPtr(rc.msg)); PROV_LOG ("--- %s CMPI thread(void *) exited", _IndClassName); _thread_active = 0; _thread_runs = 0; return (CMPI_THREAD_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
static int _testCMPIObjectPath() { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIObjectPath *objPath = NULL; CMPIObjectPath *clonedObjPath = NULL; CMPIObjectPath *otherObjPath = NULL; CMPIObjectPath *fakeObjPath = NULL; const char *hostName = "HOSTNAME"; const char *nameSpace = "root/dummy"; const char *className = "classname"; CMPIString *returnedHostname = NULL; CMPIBoolean equalHostname = 0; CMPIString *returnedNamespace = NULL; CMPIBoolean equalNamespace = 0; CMPIString *returnedClassName; CMPIBoolean equalClassName = 0; CMPIString *returnedObjectPath; CMPIBoolean cloneSuccessful = 0; CMPIBoolean getKeySuccessful = 0; CMPIBoolean getKeyCountSuccessful = 0; CMPIBoolean getKeyAtSuccessful = 0; const char *objectPath1 = NULL; const char *objectPath2 = NULL; CMPIData data; CMPIValue value; unsigned int keyCount = 0; objPath = make_ObjectPath(_broker, _Namespace, _ClassName); rc = CMSetHostname(objPath, hostName); returnedHostname = CMGetHostname(objPath, &rc); if (strcmp(hostName, CMGetCharsPtr(returnedHostname, &rc)) == 0) { equalHostname = 1; } rc = CMSetNameSpace(objPath, nameSpace); returnedNamespace = CMGetNameSpace(objPath, &rc); if (strcmp(nameSpace, CMGetCharsPtr(returnedNamespace, &rc)) == 0) { equalNamespace = 1; } rc = CMSetClassName(objPath, className); returnedClassName = CMGetClassName(objPath, &rc); if (strcmp(className, CMGetCharsPtr(returnedClassName, &rc)) == 0) { equalClassName = 1; } otherObjPath = make_ObjectPath(_broker, _Namespace, _ClassName); returnedNamespace = CMGetNameSpace(otherObjPath, &rc); rc = CMSetNameSpaceFromObjectPath(otherObjPath, objPath); returnedNamespace = CMGetNameSpace(otherObjPath, &rc); if (strcmp(nameSpace, CMGetCharsPtr(returnedNamespace, &rc)) == 0) { equalNamespace = 1; } returnedHostname = CMGetHostname(otherObjPath, &rc); rc = CMSetHostAndNameSpaceFromObjectPath(otherObjPath, objPath); returnedHostname = CMGetHostname(otherObjPath, &rc); if (strcmp(hostName, CMGetCharsPtr(returnedHostname, &rc)) == 0) { equalHostname = 1; } returnedObjectPath = CMObjectPathToString(objPath, &rc); objectPath1 = CMGetCharsPtr(returnedObjectPath, &rc); clonedObjPath = objPath->ft->clone(objPath, &rc); returnedObjectPath = CMObjectPathToString(clonedObjPath, &rc); rc = clonedObjPath->ft->release(clonedObjPath); objectPath2 = CMGetCharsPtr(returnedObjectPath, &rc); if (strcmp(objectPath1, objectPath2) == 0) { cloneSuccessful = 1; } else { cloneSuccessful = 0; } fakeObjPath = CMNewObjectPath(_broker, "root#cimv2", "Sample_Instance", &rc); rc = CMAddKey(fakeObjPath, "ElementName", (CMPIValue *) "Fake", CMPI_chars); rc = CMAddKey(otherObjPath, "ElementName1", (CMPIValue *) "otherObjPath", CMPI_chars); data = CMGetKey(fakeObjPath, "ElementName", &rc); if (strcmp(CMGetCharsPtr(data.value.string, &rc), "Fake") == 0) { getKeySuccessful = 1; } keyCount = CMGetKeyCount(fakeObjPath, &rc); if (keyCount == 1) { getKeyCountSuccessful = 1; } data = CMGetKeyAt(fakeObjPath, 0, NULL, &rc); if (rc.rc == 0) { getKeyAtSuccessful = 1; } value.uint16 = 67; rc = CMAddKey(fakeObjPath, "Numeric_key_unsigned", (CMPIValue *) & value, CMPI_uint16); data = CMGetKey(fakeObjPath, "Numeric_key_unsigned", &rc); value.sint16 = -67; rc = CMAddKey(fakeObjPath, "Numeric_key_signed", (CMPIValue *) & value, CMPI_sint16); data = CMGetKey(fakeObjPath, "Numeric_key_signed", &rc); value.boolean = 1; rc = CMAddKey(fakeObjPath, "Boolean_key", (CMPIValue *) & value, CMPI_boolean); data = CMGetKey(fakeObjPath, "Boolean_key", &rc); CMGetKeyAt(objPath, 500, NULL, &rc); if (rc.rc != CMPI_RC_ERR_NO_SUCH_PROPERTY) { return 1; } rc = objPath->ft->release(objPath); rc = fakeObjPath->ft->release(fakeObjPath); return 0; }
static int _testCMPIInstance() { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIInstance *instance = NULL; CMPIInstance *clonedInstance = NULL; CMPIObjectPath *objPath = NULL; CMPIObjectPath *newObjPath = NULL; CMPIObjectPath *returnedObjPath = NULL; CMPIData returnedData1; CMPIData returnedData2; CMPIData clonedData1; CMPIString *returnedName = NULL; unsigned int count = 0; const char *name1 = "firstPropertyName"; CMPIValue value1; const char *name2 = "secondPropertyName"; CMPIValue value2; CMPIType type = CMPI_uint64; CMPIBoolean dataEqual = 0; CMPIBoolean objectPathEqual = 0; CMPIBoolean cloneSuccessful = 0; CMPIString *beforeObjPath = NULL; CMPIString *afterObjPath = NULL; const char *beforeString = NULL; const char *afterString = NULL; objPath = make_ObjectPath(_broker, _Namespace, _ClassName); instance = make_Instance(objPath); value1.uint32 = 10; rc = CMSetProperty(instance, name1, &value1, type); value2.uint32 = 20; rc = CMSetProperty(instance, name2, &value2, type); count = CMGetPropertyCount(instance, &rc); returnedData1 = CMGetProperty(instance, name1, &rc); if (returnedData1.value.uint32 == 10) { dataEqual = 1; } returnedData2 = CMGetPropertyAt(instance, 2, &returnedName, &rc); if (returnedData2.value.uint32 == 20) { dataEqual = 1; } newObjPath = make_ObjectPath(_broker, _Namespace, _ClassName); returnedObjPath = CMGetObjectPath(instance, &rc); beforeObjPath = CMObjectPathToString(returnedObjPath, &rc); beforeString = CMGetCharsPtr(beforeObjPath, &rc); rc = CMSetNameSpace(newObjPath, "newNamespace"); rc = CMSetObjectPath(instance, newObjPath); returnedObjPath = CMGetObjectPath(instance, &rc); afterObjPath = CMObjectPathToString(returnedObjPath, &rc); afterString = CMGetCharsPtr(afterObjPath, &rc); afterString = CMGetCharsPtr(CMGetNameSpace(returnedObjPath, &rc), &rc); if (strcmp("newNamespace", afterString) == 0) { objectPathEqual = 1; } clonedInstance = instance->ft->clone(instance, &rc); clonedData1 = CMGetProperty(clonedInstance, name1, &rc); rc = clonedInstance->ft->release(clonedInstance); if (returnedData1.value.uint32 == clonedData1.value.uint32) { cloneSuccessful = 1; } else { cloneSuccessful = 0; } CMGetProperty(instance, "noProperty", &rc); if (rc.rc != CMPI_RC_ERR_NO_SUCH_PROPERTY) { return 1; } CMGetPropertyAt(instance, 100, &returnedName, &rc); if (rc.rc != CMPI_RC_ERR_NO_SUCH_PROPERTY) { return 1; } rc = instance->ft->release(instance); return 0; }
static int _testSimpleTypes() { CMPIArgs *args_ptr = NULL; CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIStatus rc1 = { CMPI_RC_OK, NULL }; int i, flag, size; CMPIValue value; CMPIValue value1; CMPIData data; CMPIData dataInst; CMPIData retDataInst; CMPIString *retNamespace = NULL; CMPIString *retClassname = NULL; CMPIObjectPath *objPath = make_ObjectPath(_broker, _Namespace, _ClassName); const char *str1; const char *str2; struct array_types { CMPIType element_type; char *typeName; char *args_name; } types_arr[] = { { CMPI_instance, "CMPI_instance", "CMPI_instance"}, { CMPI_ref, "CMPI_ref", "CMPI_ref"}}; size = 2; flag = 1; for (i = 0; i < size; i++) { args_ptr = CMNewArgs(_broker, &rc); switch (types_arr[i].element_type) { case CMPI_ref: value.ref = CMNewObjectPath(_broker, "root/cimv2", "Sample_Instance", &rc); break; case CMPI_instance: value.inst = make_Instance(objPath); value1.uint32 = 20; rc = CMSetProperty(value.inst, "Property1", &value1, CMPI_uint32); break; } rc = CMAddArg(args_ptr, types_arr[i].args_name, (CMPIValue *) & value, types_arr[i].element_type); data = CMGetArg(args_ptr, types_arr[i].args_name, &rc); switch (types_arr[i].element_type) { case CMPI_ref: retNamespace = CMGetNameSpace(data.value.ref, &rc); retClassname = CMGetClassName(data.value.ref, &rc1); if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) { str1 = CMGetCharsPtr(retNamespace, &rc); str2 = CMGetCharsPtr(retClassname, &rc1); if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) { if ((strcmp(str1, "root/cimv2")) || (strcmp(str2, "Sample_Instance"))) { flag = 0; } } else { flag = 0; } } else { flag = 0; } rc = CMRelease(value.ref); break; case CMPI_instance: retDataInst = CMGetProperty(data.value.inst, "Property1", &rc); dataInst = CMGetProperty(value.inst, "Property1", &rc); if (retDataInst.value.uint32 != dataInst.value.uint32) { flag = 0; } rc = CMRelease(value.inst); break; } if (data.type == types_arr[i].element_type && flag) { } rc = CMRelease(args_ptr); } return flag; }
static int _testArrayTypes() { struct array_types { CMPIType element_type; CMPIType typeA; char *typeName; char *typeAName; char *args_name; } types_arr[] = { { CMPI_uint32, CMPI_uint32A, "CMPI_uint32", "CMPI_uint32A", "CMPI_uint32_array"}, { CMPI_uint16, CMPI_uint16A, "CMPI_uint16", "CMPI_uint16A", "CMPI_uint16_array"}, { CMPI_uint8, CMPI_uint8A, "CMPI_uint8", "CMPI_uint8A", "CMPI_uint8_array"}, { CMPI_uint64, CMPI_uint64A, "CMPI_uint64", "CMPI_uint64A", "CMPI_uint64_array"}, { CMPI_sint32, CMPI_sint32A, "CMPI_sint32", "CMPI_sint32A", "CMPI_sint32_array"}, { CMPI_sint16, CMPI_sint16A, "CMPI_sint16", "CMPI_sint16A", "CMPI_sint16_array"}, { CMPI_sint8, CMPI_sint8A, "CMPI_sint8", "CMPI_sint8A", "CMPI_sint8_array"}, { CMPI_sint64, CMPI_sint64A, "CMPI_sint64", "CMPI_sint64A", "CMPI_sint64_array"}, { CMPI_real32, CMPI_real32A, "CMPI_real32", "CMPI_real32A", "CMPI_real32_array"}, { CMPI_real64, CMPI_real64A, "CMPI_real64", "CMPI_real64A", "CMPI_real64_array"}, { CMPI_char16, CMPI_char16A, "CMPI_char16", "CMPI_char16A", "CMPI_char16_array"}, { CMPI_boolean, CMPI_booleanA, "CMPI_boolean", "CMPI_booleanA", "CMPI_boolean_array"}, { CMPI_string, CMPI_stringA, "CMPI_string", "CMPI_stringA", "CMPI_string_array"}, { CMPI_dateTime, CMPI_dateTimeA, "CMPI_dateTime", "CMPI_dateTimeA", "CMPI_dateTime_array"}, { CMPI_ref, CMPI_refA, "CMPI_ref", "CMPI_refA", "CMPI_ref_array"}, { CMPI_instance, CMPI_instanceA, "CMPI_instance", "CMPI_instanceA", "CMPI_instance_array"}, { CMPI_null, CMPI_ARRAY, "Invalid", "InvalidArray", "Invalid_array"}}; int i, flag, size; CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIStatus rc1 = { CMPI_RC_OK, NULL }; CMPIArray *arr = NULL; CMPIString *retNamespace = NULL; CMPIString *retClassname = NULL; CMPIValue value, value1; CMPIData data; CMPIData arr_data; CMPIData dataInst; CMPIData retDataInst; CMPIArgs *args_ptr = NULL; CMPIObjectPath *objPath = make_ObjectPath(_broker, _Namespace, _ClassName); CMPIUint64 datetime1, datetime2; const char *str1; const char *str2; size = 17; for (i = 0; i < size; i++) { args_ptr = CMNewArgs(_broker, &rc); switch (types_arr[i].element_type) { case CMPI_uint32: value.uint32 = 56; break; case CMPI_uint16: value.uint16 = 32; break; case CMPI_uint8: value.uint8 = 56; break; case CMPI_uint64: value.uint64 = 32; break; case CMPI_sint32: value.sint32 = -56; break; case CMPI_sint16: value.sint16 = -32; break; case CMPI_sint8: value.sint8 = -56; break; case CMPI_sint64: value.sint64 = -32; break; case CMPI_real32: value.real32 = (CMPIReal32) -32.78; break; case CMPI_real64: value.real64 = -899.32; break; case CMPI_char16: value.char16 = 'k'; break; case CMPI_string: value.string = CMNewString(_broker, "string", &rc); break; case CMPI_boolean: value.boolean = 1; break; case CMPI_dateTime: value.dateTime = CMNewDateTime(_broker, &rc); break; case CMPI_ref: value.ref = CMNewObjectPath(_broker, "root/cimv2", "Sample_Instance", &rc); break; case CMPI_null: value.args = NULL; break; case CMPI_instance: value.inst = make_Instance(objPath); value1.uint32 = 20; rc = CMSetProperty(value.inst, "Property1", &value1, CMPI_uint32); break; } arr = NULL; rc = CMAddArg(args_ptr, "EmptyArray", (CMPIValue *) & arr, types_arr[i].typeA); arr = CMNewArray(_broker, 1, types_arr[i].element_type, &rc); rc = CMSetArrayElementAt(arr, 0, &value, types_arr[i].element_type); rc = CMAddArg(args_ptr, types_arr[i].args_name, (CMPIValue *) & arr, types_arr[i].typeA); flag = 1; if ((types_arr[i].element_type) != CMPI_null) { data = CMGetArg(args_ptr, types_arr[i].args_name, &rc); arr_data = CMGetArrayElementAt(data.value.array, 0, &rc); switch (types_arr[i].element_type) { case CMPI_uint32: if (arr_data.value.uint32 != value.uint32) { flag = 0; } break; case CMPI_uint16: if (arr_data.value.uint16 != value.uint16) { flag = 0; } break; case CMPI_uint8: if (arr_data.value.uint8 != value.uint8) { flag = 0; } break; case CMPI_uint64: if (arr_data.value.uint64 != value.uint64) { flag = 0; } break; case CMPI_sint32: if (arr_data.value.sint32 != value.sint32) { flag = 0; } break; case CMPI_sint16: if (arr_data.value.sint16 != value.sint16) { flag = 0; } break; case CMPI_sint8: if (arr_data.value.sint8 != value.sint8) { flag = 0; } break; case CMPI_sint64: if (arr_data.value.sint64 != value.sint64) { flag = 0; } break; case CMPI_real32: if (arr_data.value.real32 != value.real32) { flag = 0; } break; case CMPI_real64: if (arr_data.value.real64 != value.real64) { flag = 0; } break; case CMPI_char16: if (arr_data.value.char16 != value.char16) { flag = 0; } break; case CMPI_string: str1 = CMGetCharsPtr(arr_data.value.string, &rc); str2 = CMGetCharsPtr(value.string, &rc1); if ((rc.rc != CMPI_RC_OK) || (rc1.rc != CMPI_RC_OK) || strcmp(str1, str2)) { flag = 0; } break; case CMPI_boolean: if (arr_data.value.boolean != value.boolean) { flag = 0; } break; case CMPI_dateTime: datetime1 = CMGetBinaryFormat(arr_data.value.dateTime, &rc); datetime2 = CMGetBinaryFormat(value.dateTime, &rc1); if ((rc.rc != CMPI_RC_OK) || (rc1.rc != CMPI_RC_OK) || (datetime1 != datetime2)) { flag = 0; } rc = CMRelease(value.dateTime); break; case CMPI_ref: retNamespace = CMGetNameSpace(arr_data.value.ref, &rc); retClassname = CMGetClassName(arr_data.value.ref, &rc1); if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) { str1 = CMGetCharsPtr(retNamespace, &rc); str2 = CMGetCharsPtr(retClassname, &rc1); if ((rc.rc == CMPI_RC_OK) && (rc1.rc == CMPI_RC_OK)) { if ((strcmp(str1, "root/cimv2")) || (strcmp(str2, "TestCMPI_Instance"))) { flag = 0; } } else { flag = 0; } } else { flag = 0; } rc = CMRelease(value.ref); break; case CMPI_instance: retDataInst = CMGetProperty(arr_data.value.inst, "Property1", &rc); dataInst = CMGetProperty(value.inst, "Property1", &rc); if (retDataInst.value.uint32 != dataInst.value.uint32) { flag = 0; } rc = CMRelease(value.inst); break; } if (data.type == types_arr[i].typeA && flag) { } } rc = CMRelease(arr); rc = CMRelease(args_ptr); } return flag; }