Beispiel #1
0
CMPIInstance   *makeInstance(const CMPIBroker *broker, const char * classname,
                 const char * Namespace, CWS_FILE *cwsf)
{
  CMPIInstance   *in = NULL;
  CMPIValue       val;
  CMPIObjectPath *op = CMNewObjectPath(broker,
                       (char*)Namespace,
                       (char*)classname,
                       NULL);  CMSetHostname(op,CSName());

  if (!CMIsNullObject(op)) {
    in = CMNewInstance(broker,op,NULL);
    if (!CMIsNullObject(in)) {
      CMSetProperty(in,"CSCreationClassName",CSCreationClassName(),CMPI_chars);
      CMSetProperty(in,"CSName",CSName(),CMPI_chars);
      CMSetProperty(in,"FSCreationClassName",FSCreationClassName(),CMPI_chars);
      CMSetProperty(in,"FSName",FSName(),CMPI_chars);
      CMSetProperty(in,"CreationClassName",classname,CMPI_chars);
      CMSetProperty(in,"Name",cwsf->cws_name,CMPI_chars);
      CMSetProperty(in,"FileSize",(CMPIValue*)&cwsf->cws_size,CMPI_uint64);
#ifndef SIMULATED
/* We don't want this code in the simulated env - time is dynamic
   (diff timezones) and 
   the testing system might using a diff timezone and report failure */
      val.uint64 = cwsf->cws_ctime;
      val.dateTime = CMNewDateTimeFromBinary(broker,val.uint64*1000000,0,NULL);
      CMSetProperty(in,"CreationDate",&val,CMPI_dateTime);
      val.uint64 = cwsf->cws_mtime;
      val.dateTime = CMNewDateTimeFromBinary(broker,val.uint64*1000000,0,NULL);
      CMSetProperty(in,"LastModified",&val,CMPI_dateTime);
      val.uint64 = cwsf->cws_atime;
      val.dateTime = CMNewDateTimeFromBinary(broker,val.uint64*1000000,0,NULL);
      CMSetProperty(in,"LastAccessed",&val,CMPI_dateTime);
#endif
      val.uint64=0L;
      val.boolean=(cwsf->cws_mode & 0400) != 0;
      CMSetProperty(in,"Readable",&val,CMPI_boolean);
      val.boolean=(cwsf->cws_mode & 0200) != 0;
      CMSetProperty(in,"Writeable",&val,CMPI_boolean);
      val.boolean=(cwsf->cws_mode & 0100) != 0;
      CMSetProperty(in,"Executable",&val,CMPI_boolean);
    }
  }
  return in;
}
static int
_testCMPIDateTime()
{
  CMPIStatus      rc = { CMPI_RC_OK, NULL };

  CMPIBoolean     isInterval = 0;
  CMPIBoolean     interval = 0;
  CMPIBoolean     cloneSuccessful = 0;
  CMPIBoolean     binaryDateTimeEqual = 0;

  CMPIDateTime   *dateTime = NULL;
  CMPIDateTime   *new_dateTime = NULL;
  CMPIDateTime   *clonedDateTime = NULL;
  CMPIDateTime   *dateTimeFromBinary = NULL;

  CMPIUint64      dateTimeInBinary = UINT64_LITERAL(1150892800000000);
  CMPIUint64      returnedDateTimeInBinary = 0;

  CMPIString     *stringDate = NULL;
  CMPIString     *clonedStringDate = NULL;

  const char     *normalString = NULL;
  const char     *clonedString = NULL;
  void           *dtptr;

  dateTime = CMNewDateTime(_broker, &rc);
  if (dateTime == NULL) {
    return 1;
  }

  dateTimeFromBinary =
      CMNewDateTimeFromBinary(_broker, dateTimeInBinary, interval, &rc);
  returnedDateTimeInBinary = CMGetBinaryFormat(dateTimeFromBinary, &rc);
  if (dateTimeInBinary == returnedDateTimeInBinary) {
    binaryDateTimeEqual = 1;
  }
  isInterval = CMIsInterval(dateTime, &rc);
  interval = 1;
  new_dateTime =
      CMNewDateTimeFromBinary(_broker, dateTimeInBinary, interval, &rc);
  isInterval = CMIsInterval(new_dateTime, &rc);
  clonedDateTime = dateTime->ft->clone(dateTime, &rc);
  stringDate = CMGetStringFormat(dateTime, &rc);
  clonedStringDate = CMGetStringFormat(clonedDateTime, &rc);
  rc = clonedDateTime->ft->release(clonedDateTime);
  normalString = CMGetCharsPtr(stringDate, &rc);
  clonedString = CMGetCharsPtr(clonedStringDate, &rc);
  if (strcmp(normalString, clonedString) == 0) {
    cloneSuccessful = 1;
  }
  dtptr = dateTime->hdl;
  dateTime->hdl = NULL;

  CMGetBinaryFormat(dateTime, &rc);
  if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) {
    return 1;
  }

  dateTime->ft->clone(dateTime, &rc);
  if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) {
    return 1;
  }

  CMGetStringFormat(dateTime, &rc);
  if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) {
    return 1;
  }

  rc = dateTime->ft->release(dateTime);
  if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) {
    return 1;
  }

  dateTime->hdl = dtptr;
  rc = dateTime->ft->release(dateTime);
  return 0;
}