From: Gareth S B. <bes...@us...> - 2005-05-12 00:53:32
|
Update of /cvsroot/sblim/cmpi-tests/cmpi-instancetest/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31456 Modified Files: TST_InstanceTest.c cmpiutil.c Log Message: changes to support multiple classes in internal instance repository Index: TST_InstanceTest.c =================================================================== RCS file: /cvsroot/sblim/cmpi-tests/cmpi-instancetest/src/TST_InstanceTest.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- TST_InstanceTest.c 7 May 2005 00:45:42 -0000 1.1.1.1 +++ TST_InstanceTest.c 12 May 2005 00:53:19 -0000 1.2 @@ -11,7 +11,7 @@ // // Author: Dr. Gareth S. Bestor, <bes...@us...> // Contributors: -// Last Updated: May 3, 2005 +// Last Updated: May 11, 2005 // Description: // ============================================================================= @@ -20,13 +20,16 @@ #include "cmpift.h" #include "cmpimacs.h" -/* Classname for creating internal instances */ -static char _CLASSNAME[] = "TST_InstanceProperties"; +/* NULL terminated list of classnames supported by this provider */ +static char * _CLASSNAMES[] = {"TST_InstanceProperties", "TST_InstanceKeys", "TST_InstanceDefaults", NULL}; /* Namespace for creating internal instances */ static char _NAMESPACE[] = "root/cimv2"; -/* NULL terminated list of key property names for this class */ +/* NULL terminated list of property names for the class(es) */ +static char * _PROPERTYNAMES[] = {"CreationClassName", "Id", "Property_string", "Property_uint8", "Property_uint16", "Property_uint32", "Property_uint64", "Property_sint8", "Property_sint16", "Property_sint32", "Property_sint64", "Property_boolean", "Property_real32", "Property_real64", "Property_dateTime", "Property_char16", NULL}; + +/* NULL terminated list of key names for the class(es) */ static char * _KEYNAMES[] = {"CreationClassName", "Id", NULL}; /* Include useful utility functions */ @@ -134,7 +137,8 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ CMPIString * classname; char * classnamestring; - + char * classnameptr = _CLASSNAMES[0]; + _OSBASE_TRACE(1,("%s:_testclassname() called", _PROVIDERNAME)); /* Check that we have an object path to test */ @@ -168,10 +172,11 @@ goto exit; } - /* Check that the namespace has the correct value */ - if (strcmp(classnamestring, _CLASSNAME) != 0) { - _OSBASE_TRACE(1,("%s:_testclassname() incorrect classname - \"%s\"", _PROVIDERNAME, classnamestring)); - CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "incorrect classname,"); + /* Check that the classname is recognized */ + while ((classnameptr != NULL) && (strcmp(classnamestring, classnameptr) != 0)) classnameptr++; + if (classnameptr == NULL) { + _OSBASE_TRACE(1,("%s:_testclassname() unrecognized classname - \"%s\"", _PROVIDERNAME, classnamestring)); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "unrecognized classname,"); goto exit; } @@ -189,6 +194,7 @@ { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ char * namestring = NULL; + char * propertynameptr = _PROPERTYNAMES[0]; _OSBASE_TRACE(1,("%s:_testpropertyname() called", _PROVIDERNAME)); @@ -208,10 +214,9 @@ goto exit; } - /* Check that the propety name is recognized */ - if ((strcmp(namestring, "CreationClassName") != 0) && - (strcmp(namestring, "Id") != 0) && - (strncmp(namestring, "Property_", strlen("Property_")) != 0)) { + /* Check that the property name is recognized */ + while ((propertynameptr != NULL) && (strcmp(namestring, propertynameptr) != 0)) propertynameptr++; + if (propertynameptr == NULL) { _OSBASE_TRACE(1,("%s:_testpropertyname() unrecognized property - \"%s\"", _PROVIDERNAME, namestring)); CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "unrecognized property"); goto exit; @@ -326,9 +331,9 @@ } /* Check for 'good' property value state */ - if (!(data.state & CMPI_goodValue)) { + if (data.state != CMPI_goodValue) { _OSBASE_TRACE(1,("%s:_testpropertystate() property value state is not 'good'", _PROVIDERNAME)); -// CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "property value is not 'good'"); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "property value is not 'good'"); goto exit; } @@ -407,7 +412,7 @@ else if (strcmp(namestring, "Property_uint64") == 0) { _OSBASE_TRACE(2,("%s:_testpropertyvalue() property value=%u, data value=%u", _PROVIDERNAME, value.uint64, instancedata->Property_uint64)); -// if (value.uint64 != instancedata->Property_uint64) goto error; + if (value.uint64 != instancedata->Property_uint64) goto error; } else if (strcmp(namestring, "Property_sint8") == 0) { @@ -431,7 +436,7 @@ else if (strcmp(namestring, "Property_sint64") == 0) { _OSBASE_TRACE(2,("%s:_testpropertyvalue() property value=%d, data value=%d", _PROVIDERNAME, value.sint64, instancedata->Property_sint64)); -// if (value.sint64 != instancedata->Property_sint64) goto error; + if (value.sint64 != instancedata->Property_sint64) goto error; } else if (strcmp(namestring, "Property_boolean") == 0) { @@ -507,7 +512,7 @@ CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "unrecognized property"); goto exit; -error: +error: /* Note - regular code path can never reach here except via an explicit goto error. */ _OSBASE_TRACE(1,("%s:_testpropertyvalue() incorrect property value", _PROVIDERNAME)); CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED, "incorrect property value"); goto exit; @@ -528,7 +533,8 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ int numproperties, i; CMPIString * name; - CMPIData data; + CMPIData data, data2; + char * namestring; _OSBASE_TRACE(1,("%s:_testproperties() called", _PROVIDERNAME)); @@ -559,6 +565,7 @@ /* Check the property name */ status = _testpropertyname(name); if (status.rc != CMPI_RC_OK) goto exit; + namestring = CMGetCharPtr(name); /* Check that the property value state is correct */ status = _testpropertystate(data); @@ -572,8 +579,30 @@ status = _testpropertyvalue(name, data, instancedata); if (status.rc != CMPI_RC_OK) goto exit; + /* Check that CMGetProperty() also works and returns the same data */ + data2 = CMGetProperty(instance, namestring, &status); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:_testproperties() CMGetProperty(%s) failed", _PROVIDERNAME, namestring)); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "CMGetProperty() failed"); + goto exit; + } + + /* Check that the CMGetProperty() value state is the same */ + if (data2.state != data.state) { + _OSBASE_TRACE(1,("%s:_testproperties() CMGetProperty(%s) has different state", _PROVIDERNAME, namestring)); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "CMGetProperty() has different state"); + goto exit; + } + + /* Check that the CMGetProperty() value is the same */ + if (!_CMSameValue(data, data2)) { + _OSBASE_TRACE(1,("%s:_testproperties() CMGetProperty(%s) has different value", _PROVIDERNAME, namestring)); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "CMGetProperty() has different value"); + goto exit; + } + /* If got here then the property is OK */ - _OSBASE_TRACE(1,("%s:_testproperties() property #%d is OK", _PROVIDERNAME, i)); + _OSBASE_TRACE(1,("%s:_testproperties() property #%d \"%s\" is OK", _PROVIDERNAME, i, namestring)); } /* Finished */ @@ -621,7 +650,8 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ int numkeys, i; CMPIString * name; - CMPIData data; + CMPIData data, data2; + char * namestring; _OSBASE_TRACE(1,("%s:_testkeys() called", _PROVIDERNAME)); @@ -652,6 +682,7 @@ /* Check the property name */ status = _testpropertyname(name); if (status.rc != CMPI_RC_OK) goto exit; + namestring = CMGetCharPtr(name); /* Check that the property value state is correct */ status = _testpropertystate(data); @@ -665,8 +696,30 @@ status = _testpropertyvalue(name, data, instancedata); if (status.rc != CMPI_RC_OK) goto exit; + /* Check that CMGetKey() also works and returns the same data */ + data2 = CMGetKey(objectpath, namestring, &status); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:_testkeys() CMGetKey(%s) failed", _PROVIDERNAME, namestring)); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "CMGetKey() failed"); + goto exit; + } + + /* Check that the CMGetKey() value state is the same */ + if (data2.state != data.state) { + _OSBASE_TRACE(1,("%s:_testkeys() CMGetKey(%s) has different state", _PROVIDERNAME, namestring)); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "CMGetKey() has different state"); + goto exit; + } + + /* Check that the CMGetKey() value is the same */ + if (!_CMSameValue(data, data2)) { + _OSBASE_TRACE(1,("%s:_testkeys() CMGetKey(%s) has different value", _PROVIDERNAME, namestring)); + CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "CMGetKey() has different value"); + goto exit; + } + /* If got here then the key is OK */ - _OSBASE_TRACE(1,("%s:_testkeys() key #%d is OK", _PROVIDERNAME, i)); + _OSBASE_TRACE(1,("%s:_testkeys() key #%d \"%s\" is OK", _PROVIDERNAME, i, namestring)); } /* Finished */ @@ -745,18 +798,22 @@ // --------------------------------------------------------------------------- +/* _testmethodname() - run tests on the InvokeMethod() method name specified by the client */ CMPIStatus _testmethodname( char * methodname ) { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ _OSBASE_TRACE(1,("%s:_testmethodname() called", _PROVIDERNAME)); + /* Check that the method name string is not null or empty */ if (methodname == NULL || *methodname == '\0') { _OSBASE_TRACE(1,("%s:_testmethodname() NULL method name", _PROVIDERNAME)); CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "NULL method name"); goto exit; } + /* TODO - Check that the method name is recognized */ + exit: _OSBASE_TRACE(1,("%s:_testmethodname() %s", _PROVIDERNAME, (status.rc == CMPI_RC_OK)? "succeeded":"failed")); return status; @@ -766,6 +823,7 @@ // --------------------------------------------------------------------------- +/* _testarguments() - run tests on the InvokeMethod() method arguments specified by the client */ CMPIStatus _testarguments( CMPIArgs * args ) { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ @@ -773,6 +831,7 @@ CMPIData data; /* CIM datum to extract argument values */ CMPIString * name; char * valuestring = NULL; + char * namestring; _OSBASE_TRACE(1,("%s:_testarguments() called", _PROVIDERNAME)); @@ -802,13 +861,14 @@ _OSBASE_TRACE(1,("%s:_testarguments() NULL argument name", _PROVIDERNAME)); CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "NULL argument name"); } + namestring = CMGetCharPtr(name); status = _testpropertystate(data); if (status.rc != CMPI_RC_OK) goto exit; // valuestring = _CMPIValueToString(data); _OSBASE_TRACE(2,("%s:_testarguments() arg #%d: name=\"%s\", type=%s(%d) value=%s", _PROVIDERNAME, - i, CMGetCharPtr(name), _CMPITypeName(data.type), data.type, valuestring)); + i, namestring, _CMPITypeName(data.type), data.type, valuestring)); if (valuestring != NULL) free(valuestring); } @@ -824,7 +884,7 @@ /* _makeinstance() - create a new CIM instance from the specified instance data */ -static CMPIStatus _makeinstance( CMPIInstance ** instance, _INSTANCEDATA * instancedata ) +static CMPIStatus _makeinstance( CMPIInstance ** instance, _INSTANCEDATA * instancedata, char * classname ) { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ CMPIObjectPath * objectpath; /* Object path of the new instance */ @@ -832,7 +892,7 @@ _OSBASE_TRACE(1,("%s:_makeinstance() called", _PROVIDERNAME)); /* Create a new CIM object path for the new instance */ - objectpath = CMNewObjectPath(_BROKER, _NAMESPACE, _CLASSNAME, &status); + objectpath = CMNewObjectPath(_BROKER, _NAMESPACE, classname, &status); if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { _OSBASE_TRACE(1,("%s:_makeinstance() CMNewObjectPath() failed - %s", _PROVIDERNAME, CMGetCharPtr(status.msg))); CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR_SYSTEM, "CMNewObjectPath() failed"); @@ -977,6 +1037,7 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ CMPIObjectPath * objectpath; /* CIM object path of each new instance of this class */ char * namespace; /* Our current CIM namespace */ + char * classname; /* Classname to look for */ int found = 0; /* Found any instances? */ int i; @@ -990,13 +1051,19 @@ /* Check that the reference classname is correct */ status = _testclassname(reference); if (status.rc != CMPI_RC_OK) goto exit; - + classname = CMGetCharPtr(CMGetClassName(reference, NULL)); + /* Go through the internal list of instances and return the object path of each */ for (i=0; i<sizeinstances; i++) { if (instances[i] == NULL) continue; - /* Return the object path of the instance */ + /* Get the instance's object path */ objectpath = CMGetObjectPath(instances[i], NULL); + + /* Check that the instance's class is the same as the reference class */ + if (strcmp(CMGetCharPtr(CMGetClassName(objectpath,NULL)), classname) != 0) continue; + + /* Return the object path of the instance */ CMSetNameSpace(objectpath, namespace); CMReturnObjectPath(results, objectpath); found++; @@ -1024,6 +1091,8 @@ char ** properties) /* [in] List of desired properties (NULL=all) */ { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ + CMPIObjectPath * objectpath; /* CIM object path of each new instance of this class */ + char * classname; /* Classname to look for */ int found = 0; /* Found any instances? */ int i; @@ -1036,18 +1105,17 @@ /* Check that the reference classname is correct */ status = _testclassname(reference); if (status.rc != CMPI_RC_OK) goto exit; - - /* Test the reference object path */ - status = _testobjectpath(reference, NULL); - if (status.rc != CMPI_RC_OK) { - _OSBASE_TRACE(1,("%s:EnumInstances() _testobjectpath() failed", self->ft->miName)); - goto exit; - } + classname = CMGetCharPtr(CMGetClassName(reference, NULL)); /* Go through the internal list of instances and return each */ for (i=0; i<sizeinstances; i++) { if (instances[i] == NULL) continue; + /* Get the instance's object path */ + objectpath = CMGetObjectPath(instances[i], NULL); + + /* Check that the instance's class is the same as the reference class */ + if (strcmp(CMGetCharPtr(CMGetClassName(objectpath,NULL)), classname) != 0) continue; /* Return this instance */ CMReturnInstance(results, instances[i]); found++; @@ -1351,7 +1419,6 @@ status = _testselectexpr(selectexpr); if (status.rc != CMPI_RC_OK) goto exit; - /* Go through the internal list of instances and evaluate each against the query */ for (i=0; i<sizeinstances; i++) { if (instances[i] == NULL) continue; @@ -1416,7 +1483,6 @@ CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations */ CMPIInstance * newinstance = NULL; /* New instance to add to the internal list */ CMPIObjectPath * newobjectpath = NULL; /* New object path for each new instance */ - _INSTANCEDATA newinstancedata; /* Store raw instance data */ int instancenum = 2; /* Number of instances to populate the internal list */ _OSBASE_TRACE(1,("%s:Initialize() called", self->ft->miName)); @@ -1430,11 +1496,51 @@ /* Create sample instance(s) and add to the list of instances */ while (instancenum > 0) { - _OSBASE_TRACE(1,("%s:Initialize() creating new instance", self->ft->miName)); + _INSTANCEDATA newinstancedata; /* Store raw instance data */ - /* Generate raw instance data */ - strncpy(newinstancedata.CreationClassName, _CLASSNAME, _MAXSTRINGLENGTH); + /* Initialize the minimum raw instance data for instances with default property values */ snprintf(newinstancedata.Id, _MAXSTRINGLENGTH, "Instance #%d", instancenum); + + _OSBASE_TRACE(1,("%s:Initialize() creating new instance", self->ft->miName)); + + /* Create a new TST_InstanceDefaults instance from the raw data */ + strncpy(newinstancedata.CreationClassName, "TST_InstanceDefaults", _MAXSTRINGLENGTH); + status = _makeinstance(&newinstance, &newinstancedata, newinstancedata.CreationClassName); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() _makeinstance() failed", self->ft->miName)); + goto exit; + } + + /* Run tests on the newly created instance */ + status = _testinstance(newinstance, NULL); + if (status.rc != CMPI_RC_OK) goto exit; + + /* Get the object path of the newly created instance */ + newobjectpath = CMGetObjectPath(newinstance, &status); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() CMGetObjectPath() failed", self->ft->miName)); + goto exit; + } + + /* Set the namespace of the new object path */ + status = CMSetNameSpace(newobjectpath, _NAMESPACE); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() CMSetNameSpace() failed", self->ft->miName)); + goto exit; + } + + /* Run tests on the new object path */ + status = _testobjectpath(newobjectpath, NULL); + if (status.rc != CMPI_RC_OK) goto exit; + + /* Add the new CIM instance to the list of instances */ + status = _addinstance(newinstance); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() _addinstance() failed", self->ft->miName)); + goto exit; + } + + /* Initialize the rest of the raw instance data */ snprintf(newinstancedata.Property_string, _MAXSTRINGLENGTH, "This is instance #%d", instancenum); newinstancedata.Property_uint8 = (CMPIUint8)255; newinstancedata.Property_uint16 = (CMPIUint16)65535; @@ -1449,10 +1555,12 @@ newinstancedata.Property_real64 = (CMPIReal64)0.123456789012345e38; newinstancedata.Property_dateTime = CMNewDateTimeFromChars(_BROKER,"20050503104354.000000:000",NULL); newinstancedata.Property_char16 = (CMPIChar16)'a'; - instancenum--; - /* Create a new CIM instance from the raw data */ - status = _makeinstance(&newinstance, &newinstancedata); + _OSBASE_TRACE(1,("%s:Initialize() creating new instance", self->ft->miName)); + + /* Create a new TST_InstanceProperties instance from the raw data */ + strncpy(newinstancedata.CreationClassName, "TST_InstanceProperties", _MAXSTRINGLENGTH); + status = _makeinstance(&newinstance, &newinstancedata, newinstancedata.CreationClassName); if (status.rc != CMPI_RC_OK) { _OSBASE_TRACE(1,("%s:Initialize() _makeinstance() failed", self->ft->miName)); goto exit; @@ -1486,6 +1594,43 @@ _OSBASE_TRACE(1,("%s:Initialize() _addinstance() failed", self->ft->miName)); goto exit; } + + _OSBASE_TRACE(1,("%s:Initialize() creating new instance", self->ft->miName)); + + /* Create a new TST_InstanceKeys instance from the same raw data */ + strncpy(newinstancedata.CreationClassName, "TST_InstanceKeys", _MAXSTRINGLENGTH); + status = _makeinstance(&newinstance, &newinstancedata, newinstancedata.CreationClassName); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() _makeinstance() failed", self->ft->miName)); + goto exit; + } + + /* Get the object path of the newly created instance */ + newobjectpath = CMGetObjectPath(newinstance, &status); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() CMGetObjectPath() failed", self->ft->miName)); + goto exit; + } + + /* Set the namespace of the new object path */ + status = CMSetNameSpace(newobjectpath, _NAMESPACE); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() CMSetNameSpace() failed", self->ft->miName)); + goto exit; + } + + /* Run tests on the new object path */ + status = _testobjectpath(newobjectpath, &newinstancedata); + if (status.rc != CMPI_RC_OK) goto exit; + + /* Add the new CIM instance to the list of instances */ + status = _addinstance(newinstance); + if (status.rc != CMPI_RC_OK) { + _OSBASE_TRACE(1,("%s:Initialize() _addinstance() failed", self->ft->miName)); + goto exit; + } + + instancenum--; } /* Finished */ Index: cmpiutil.c =================================================================== RCS file: /cvsroot/sblim/cmpi-tests/cmpi-instancetest/src/cmpiutil.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- cmpiutil.c 6 May 2005 22:56:19 -0000 1.1.1.1 +++ cmpiutil.c 12 May 2005 00:53:19 -0000 1.2 @@ -325,9 +325,7 @@ if (CMIsNullObject(data.value.string)) return NULL; char * str = CMGetCharPtr(data.value.string); if (str == NULL) return NULL; -_OSBASE_TRACE(1,("DEBUG: before strdup")); valuestring = strdup(str); -_OSBASE_TRACE(1,("DEBUG: after strdup")); return valuestring; } case CMPI_boolean: |