Esempio n. 1
0
static void _BubbleSort(Array<CIMKeyBinding>& x)
{
    Uint32 n = x.size();

    //
    //  If the key is a reference, the keys in the reference must also be
    //  sorted
    //
    for (Uint32 k = 0; k < n ; k++)
        if (x[k].getType () == CIMKeyBinding::REFERENCE)
        {
            CIMObjectPath tmp (x[k].getValue ());
            Array <CIMKeyBinding> keyBindings = tmp.getKeyBindings ();
            _BubbleSort (keyBindings);
            tmp.setKeyBindings (keyBindings);
            x[k].setValue (tmp.toString ());
        }

    if (n < 2)
        return;

    for (Uint32 i = 0; i < n - 1; i++)
    {
        for (Uint32 j = 0; j < n - 1; j++)
        {
            if (String::compareNoCase(x[j].getName().getString(),
                                      x[j+1].getName().getString()) > 0)
            {
                CIMKeyBinding t = x[j];
                x[j] = x[j+1];
                x[j+1] = t;
            }
        }
    }
}
Esempio n. 2
0
void testCreateInstance(CIMClient& client, const char* ns)
{
  CIMObjectPath path;
  Array<CIMInstance> instances;
  CIMName keyName;
  String keyValue;

  instances = client.enumerateInstances(ns, CIM_QUERYCAPCLASS_NAME);

  Array<CIMKeyBinding> keys = instances[0].getPath().getKeyBindings();

  keys[0].setValue("100");

  path = instances[0].getPath();
  path.setKeyBindings(keys);

  try
  {
    path = client.createInstance(ns, instances[0]);
  }
  catch(Exception)
  {
    // Do nothing. This is expected since createInstance is NOT
    // supported.
    return;
  }

  throw Exception("createInstance is supported");
}
CIMObjectPath _buildSubscriptionPath
   (const CIMObjectPath & filterPath,
    const CIMObjectPath & handlerPath)
{
    CIMObjectPath path;

    Array <CIMKeyBinding> keyBindings;
    keyBindings.append (CIMKeyBinding ("Filter",
        filterPath.toString (), CIMKeyBinding::REFERENCE));
    keyBindings.append (CIMKeyBinding ("Handler",
        handlerPath.toString (), CIMKeyBinding::REFERENCE));

    path.setClassName (SUBSCRIPTION_CLASSNAME);
    path.setKeyBindings (keyBindings);

    return path;
}
CIMObjectPath _buildFilterOrHandlerPath
    (const CIMName & className,
     const String & name,
     const CIMNamespaceName & namespaceName = CIMNamespaceName ())
{
    CIMObjectPath path;

    Array <CIMKeyBinding> keyBindings;
    keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
        System::getSystemCreationClassName (), CIMKeyBinding::STRING));
    keyBindings.append (CIMKeyBinding ("SystemName",
        System::getFullyQualifiedHostName (), CIMKeyBinding::STRING));
    keyBindings.append (CIMKeyBinding ("CreationClassName",
        className.getString(), CIMKeyBinding::STRING));
    keyBindings.append (CIMKeyBinding ("Name", name, CIMKeyBinding::STRING));
    path.setClassName (className);
    path.setKeyBindings (keyBindings);
    path.setNameSpace (namespaceName);

    return path;
}
CIMObjectPath ProviderIndicationCountTable::_buildProviderIndDataInstanceName(
    const _ProviderIndicationCountTableEntry& indicationCountEntry)
{
    PEG_METHOD_ENTER(TRC_INDICATION_SERVICE,
        "ProviderIndicationCountTable::_buildProviderIndDataInstanceName");

    CIMObjectPath instanceName;
    Array<CIMKeyBinding> keyBindings;
    keyBindings.append(CIMKeyBinding(
        "ProviderModuleName",
        indicationCountEntry.providerModuleName,
        CIMKeyBinding::STRING));
    keyBindings.append(CIMKeyBinding(
        "ProviderName",
        indicationCountEntry.providerName,
        CIMKeyBinding::STRING));

    instanceName.setClassName(PEGASUS_CLASSNAME_PROVIDERINDDATA);
    instanceName.setKeyBindings(keyBindings);

    PEG_METHOD_EXIT();
    return instanceName;
}
Esempio n. 6
0
void TestCreateInstances(CIMClient& client)
{
    //
    // Test create Provider module instances
    //
    CIMObjectPath returnRef;

    CIMClass cimClass(CLASSNAME);

    CIMInstance cimInstance(CLASSNAME);

    cimInstance.addProperty(CIMProperty(CIMName ("Name"), 
        String("providersModule1")));
    cimInstance.addProperty(CIMProperty(CIMName ("Vendor"), String("HP")));
    cimInstance.addProperty(CIMProperty(CIMName ("Version"), String("2.0")));
    cimInstance.addProperty(CIMProperty(CIMName ("InterfaceType"), 
        String("C++Default")));
    cimInstance.addProperty(CIMProperty(CIMName ("InterfaceVersion"), 
        String("2.1.0")));
    cimInstance.addProperty(CIMProperty(CIMName ("Location"), 
        String("/tmp/module1")));

    CIMObjectPath instanceName = cimInstance.buildPath(cimClass);

    instanceName.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP);
    instanceName.setClassName(CLASSNAME);

    try
    {
        returnRef = client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, cimInstance);
    }
    catch(const CIMException&)
    {
        throw;
    }

    // Test create PG_Provider instances

    CIMObjectPath returnRef2;

    CIMClass cimClass2(CLASSNAME2);

    CIMInstance cimInstance2(CLASSNAME2);

    cimInstance2.addProperty(CIMProperty(CIMName ("ProviderModuleName"), 
        String("providersModule1")));
    cimInstance2.addProperty(CIMProperty(CIMName ("Name"), 
        String("PG_ProviderInstance1")));

    CIMObjectPath instanceName2 = cimInstance2.buildPath(cimClass2);

    instanceName2.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP);
    instanceName2.setClassName(CLASSNAME2);

    try
    {
        returnRef2 = client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, cimInstance2);
    }
    catch(const CIMException&)
    {
        throw;
    }

    //
    // test create provider capability instances
    //

    Array <String> namespaces;
    Array <Uint16> providerType;
    Array <String> supportedMethods;
    Array <String> supportedProperties;

    namespaces.append("root/cimv2");
    namespaces.append("root/cimv3");
    
    providerType.append(4);
    providerType.append(5);

    supportedMethods.append("test_method1");
    supportedMethods.append("test_method2");

    supportedProperties.append("PkgStatus");
    supportedProperties.append("PkgIndex");

    CIMObjectPath returnRef3;

    CIMClass cimClass3(CLASSNAME3);

    CIMInstance cimInstance3(CLASSNAME3);

    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderModuleName"), 
        String("providersModule1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderName"), 
        String("PG_ProviderInstance1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("CapabilityID"), 
        String("capability1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("ClassName"), 
        String("TestSoftwarePkg")));
    cimInstance3.addProperty(CIMProperty(CIMName ("Namespaces"), namespaces));
    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderType"), 
        providerType));
    cimInstance3.addProperty(CIMProperty(CIMName ("SupportedMethods"), 
        supportedMethods));
    cimInstance3.addProperty(CIMProperty(CIMName ("SupportedProperties"), 
        supportedProperties));

    CIMObjectPath instanceName3 = cimInstance3.buildPath(cimClass3);

    instanceName3.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP);
    instanceName3.setClassName(CLASSNAME3);

    try
    {
        returnRef3 = client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, cimInstance3);
    }
    catch(const CIMException&)
    {
        throw;
    }

    CIMKeyBinding kb1(CIMName ("Name"), "providersModule1", 
        CIMKeyBinding::STRING);
    Array<CIMKeyBinding> keys;
    keys.append(kb1);

    instanceName.setKeyBindings(keys);

    // test getInstance
    try
    {
    	client.getInstance(PEGASUS_NAMESPACENAME_INTEROP, instanceName);
    }
    catch(const CIMException&)
    {
        throw;
    }

    // test enumerateInstances
    try
    {
    	client.enumerateInstances(PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PROVIDER);
    }
    catch(const CIMException&)
    {
        throw;
    }

    // test enumerateInstanceNames
    try
    {
    	client.enumerateInstanceNames(PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PROVIDER);
    }
    catch(const CIMException&)
    {
        throw;
    }


    client.deleteInstance(PEGASUS_NAMESPACENAME_INTEROP, instanceName);
}
Esempio n. 7
0
void TestDeleteInstances(ProviderRegistrationManager & prmanager)
{
   CIMKeyBinding kb1(CIMName ("ProviderModuleName"), "providersModule1", 
       CIMKeyBinding::STRING);
   CIMKeyBinding kb2(CIMName ("ProviderName"), "PG_ProviderInstance1", 
       CIMKeyBinding::STRING);
   CIMKeyBinding kb3(CIMName ("CapabilityID"), "capability1", 
       CIMKeyBinding::STRING);
   CIMKeyBinding kbp1(CIMName ("ProviderModuleName"), "providersModule1", 
       CIMKeyBinding::STRING);
   CIMKeyBinding kbp2(CIMName ("Name"), "PG_ProviderInstance1", 
       CIMKeyBinding::STRING);
   CIMKeyBinding kbm1(CIMName ("Name"), "providersModule1", 
       CIMKeyBinding::STRING);

   CIMObjectPath instanceName;

  try
  {
    for (Uint32 i=1; i<=3; i++)
    {
      CIMObjectPath instanceName2;
      Array<CIMKeyBinding> keys2;
      Array<CIMKeyBinding> keysm;
      Array<CIMKeyBinding> keys;

      //
      // create Provider module instances
      //
      if (i <= 1)
      {
        CIMObjectPath returnRef;
        CIMClass cimClass(CLASSNAME);
        CIMInstance cimInstance(CLASSNAME);

    	cimInstance.addProperty(CIMProperty(CIMName ("Name"), String("providersModule1")));
    	cimInstance.addProperty(CIMProperty(CIMName ("Vendor"), String("HP")));
    	cimInstance.addProperty(CIMProperty(CIMName ("Version"), String("2.0")));
    	cimInstance.addProperty(CIMProperty(CIMName ("InterfaceType"), String("PG_DefaultC++")));
    	cimInstance.addProperty(CIMProperty(CIMName ("InterfaceVersion"), String("2.0")));
    	cimInstance.addProperty(CIMProperty(CIMName ("Location"), String("/tmp/module1")));

    	instanceName = cimInstance.buildPath(cimClass);

    	instanceName.setNameSpace(NAMESPACE);
    	instanceName.setClassName(CLASSNAME);

    	returnRef = prmanager.createInstance(instanceName, cimInstance);
    }

    // create PG_Provider instances

    if (i <= 2 )
    {
    	CIMObjectPath returnRef2;

    	CIMClass cimClass2(CLASSNAME2);

    	CIMInstance cimInstance2(CLASSNAME2);

    	cimInstance2.addProperty(CIMProperty(CIMName ("ProviderModuleName"), String("providersModule1")));
    	cimInstance2.addProperty(CIMProperty(CIMName ("Name"), String("PG_ProviderInstance1")));

    	instanceName2 = cimInstance2.buildPath(cimClass2);

    	instanceName2.setNameSpace(NAMESPACE);
    	instanceName2.setClassName(CLASSNAME2);

    	returnRef2 = prmanager.createInstance(instanceName2, cimInstance2);
    }

    //
    // create provider capability instances
    //

    Array <String> namespaces;
    Array <Uint16> providerType;
    Array <String> supportedMethods;

    namespaces.append("test_namespace1");
    namespaces.append("test_namespace2");
    
    providerType.append(2);
    providerType.append(5);

    supportedMethods.append("test_method1");
    supportedMethods.append("test_method2");

    CIMObjectPath returnRef3;

    CIMClass cimClass3(CLASSNAME3);

    CIMInstance cimInstance3(CLASSNAME3);

    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderModuleName"), String("providersModule1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderName"), String("PG_ProviderInstance1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("CapabilityID"), String("capability1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("ClassName"), String("test_class1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("Namespaces"), namespaces));
    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderType"), providerType));
    cimInstance3.addProperty(CIMProperty(CIMName ("SupportedMethods"), supportedMethods));

    CIMObjectPath instanceName3 = cimInstance3.buildPath(cimClass3);

    instanceName3.setNameSpace(NAMESPACE);
    instanceName3.setClassName(CLASSNAME3);

    returnRef3 = prmanager.createInstance(instanceName3, cimInstance3);

    switch (i)
    {
	case 1:
            //
            // delete cimInstance2
            //
            keys2.append(kbp1);
            keys2.append(kbp2);

            instanceName2.setKeyBindings(keys2);

    	    prmanager.deleteInstance(instanceName2);
	    break;

	case 2:
            //
            // delete cimInstance3
            //
            keys.append(kb1);
            keys.append(kb2);
            keys.append(kb3);

            instanceName3.setKeyBindings(keys);

    	    prmanager.deleteInstance(instanceName3);
	    break;

	case 3:
    	    //
    	    // delete cimInstance
            //
            keysm.append(kbm1);

            instanceName.setKeyBindings(keysm);

	    prmanager.deleteInstance(instanceName);
	    break;
        }
    }
  }
  catch(CIMException& e)
  {
      throw (e);
  }
}
Esempio n. 8
0
int testClass(const String& className)
{
  Array<CIMObjectPath> refs;

  cout << endl << "+++++ Testing Class " << className << " +++++" << endl;

  // =======================================================================
  // enumerateInstanceNames
  // =======================================================================

  cout << "+++++ enumerateInstanceNames(" << className << "): ";
  try
  {
    refs = c.enumerateInstanceNames(NAMESPACE,className);
  }
  catch (Exception& e)
  {
    cout << endl;
    errorExit(e);
  }

  cout << refs.size() << " instances" << endl;

  // There must be at least 5 processes or something's wrong
  if (refs.size() < 5)
  {
    cout << "+++++ Error: too few instances returned" << endl;
    return 1;
  }

  // =======================================================================
  // getInstance
  // =======================================================================

  // -------------------- First do normal getInstance() --------------------

  // pick the middle instance of the bunch
  Uint32 i = (refs.size()-1) >> 1;  // This is a shift right, not streamio!
  CIMObjectPath ref = refs[i];
  CIMInstance inst;
  cout << "+++++ getInstance " << i << endl;
  try
  {
    inst = c.getInstance(NAMESPACE,ref);
  }
  catch (Exception& e)
  {
    errorExit(e);
  }

  if (processTestVerbose)
  {
    // Display keys
    Array<CIMKeyBinding> keys = ref.getKeyBindings();
    cout << "  Keys:" << endl;
    for (i=0; i<keys.size(); i++)
      cout << "    " << keys[i].getName() << " = " << keys[i].getValue() << endl;
  }

  // check returned property values

  // first get the PID and load a process object
  String handle;
  inst.getProperty(inst.findProperty("handle")).getValue().get(handle);
  Process p;
  // error if can't get the process
  if (!p.findProcess(handle))
  {
    cout << "+++++ Error: can't find process corresponding to instance" << endl;
    return 1;
  }

  if (processTestVerbose) cout << "  Properties:" << endl;

  String sa, sb;
  Array<String> asa, asb;
  Uint16 i16a, i16b;
  Uint32 i32a, i32b;
  Uint64 i64a, i64b;
  CIMDateTime da, db;
  
  // For each property, get it from the just-loaded process
  // object and compare with what was returned by getInstance()

  // Caption and Description are common to all classes
  if (p.getCaption(sa))
  {
    if (processTestVerbose) cout << "    Caption" << endl;
    inst.getProperty(inst.findProperty("Caption")).getValue().get(sb);
    if (sa != sb)
    {
      cout << "+++++ Error: property mismatch: Caption" << endl;
      return 1;
    }
  }
  
  if (p.getDescription(sa))
  {
    if (processTestVerbose) cout << "    Description" << endl;
    inst.getProperty(inst.findProperty("Description")).getValue().get(sb);
    if (sa != sb)
    {
      cout << "+++++ Error: property mismatch: Description" << endl;
      return 1;
    }
  }
  
  // The rest of the properties to check depend on the
  // class we are testing

  // ===================== UnixProcess instances =========================

  if (String::equalNoCase(className,"CIM_Process") ||
      String::equalNoCase(className,"PG_UnixProcess"))
  {
    if (p.getInstallDate(da))
    {
      if (processTestVerbose) cout << "    InstallDate" << endl;
      inst.getProperty(inst.findProperty("InstallDate")).getValue().get(db);
      if (da != db)
      {
        cout << "+++++ Error: property mismatch: InstallDate" << endl;
        return 1;
      }
    }
  
    if (p.getStatus(sa))
    {
      if (processTestVerbose) cout << "    Status" << endl;
      inst.getProperty(inst.findProperty("Status")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: Status" << endl;
        return 1;
      }
    }
  
    if (p.getName(sa))
    {
      if (processTestVerbose) cout << "    Name" << endl;
      inst.getProperty(inst.findProperty("Name")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: Name" << endl;
        return 1;
      }
    }
  
    if (p.getPriority(i32a))
    {
      if (processTestVerbose) cout << "    Priority" << endl;
      inst.getProperty(inst.findProperty("Priority")).getValue().get(i32b);
      if (i32a != i32b)
      {
        cout << "+++++ Error: property mismatch: Priority" << endl;
        return 1;
      }
    }
  
    if (p.getExecutionState(i16a))
    {
      if (processTestVerbose) cout << "    ExecutionState" << endl;
      inst.getProperty(inst.findProperty("ExecutionState")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: ExecutionState" << endl;
        return 1;
      }
    }
  
    if (p.getOtherExecutionDescription(sa))
    {
      if (processTestVerbose) cout << "    OtherExecutionDescription" << endl;
      CIMValue oedVal = inst.getProperty
          (inst.findProperty("OtherExecutionDescription")).getValue();
      if (!oedVal.isNull())
          oedVal.get(sb);
      else
         sb = String::EMPTY;
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: OtherExecutionDescription" << endl;
        return 1;
      }
    }
  
    if (p.getCreationDate(da))
    {
      if (processTestVerbose) cout << "    CreationDate" << endl;
      inst.getProperty(inst.findProperty("CreationDate")).getValue().get(db);
      if (da != db)
      {
        cout << "+++++ Error: property mismatch: CreationDate" << endl;
        return 1;
      }
    }
  
    if (p.getTerminationDate(da))
    {
      if (processTestVerbose) cout << "    TerminationDate" << endl;
      inst.getProperty(inst.findProperty("TerminationDate")).getValue().get(db);
      if (da != db)
      {
        cout << "+++++ Error: property mismatch: TerminationDate" << endl;
        return 1;
      }
    }
  
    if (p.getKernelModeTime(i64a))
    {
      if (processTestVerbose) cout << "    KernelModeTime" << endl;
      inst.getProperty(inst.findProperty("KernelModeTime")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: KernelModeTime" << endl;
        return 1;
      }
    }
  
    if (p.getUserModeTime(i64a))
    {
      if (processTestVerbose) cout << "    UserModeTime" << endl;
      inst.getProperty(inst.findProperty("UserModeTime")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: UserModeTime" << endl;
        return 1;
      }
    }
  
    if (p.getWorkingSetSize(i64a))
    {
      if (processTestVerbose) cout << "    WorkingSetSize" << endl;
      inst.getProperty(inst.findProperty("WorkingSetSize")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: WorkingSetSize" << endl;
        return 1;
      }
    }
  
    if (p.getParentProcessID(sa))
    {
      if (processTestVerbose) cout << "    ParentProcessID" << endl;
      inst.getProperty(inst.findProperty("ParentProcessID")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: ParentProcessID" << endl;
        return 1;
      }
    }
  
    if (p.getRealUserID(i64a))
    {
      if (processTestVerbose) cout << "    RealUserID" << endl;
      inst.getProperty(inst.findProperty("RealUserID")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: RealUserID" << endl;
        return 1;
      }
    }
  
    if (p.getProcessGroupID(i64a))
    {
      if (processTestVerbose) cout << "    ProcessGroupID" << endl;
      inst.getProperty(inst.findProperty("ProcessGroupID")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: ProcessGroupID" << endl;
        return 1;
      }
    }
  
    if (p.getProcessSessionID(i64a))
    {
      if (processTestVerbose) cout << "    ProcessSessionID" << endl;
      inst.getProperty(inst.findProperty("ProcessSessionID")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: ProcessSessionID" << endl;
        return 1;
      }
    }
  
    if (p.getProcessTTY(sa))
    {
      if (processTestVerbose) cout << "    ProcessTTY" << endl;
      inst.getProperty(inst.findProperty("ProcessTTY")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: ProcessTTY" << endl;
        return 1;
      }
    }
  
    if (p.getModulePath(sa))
    {
      if (processTestVerbose) cout << "    ModulePath" << endl;
      inst.getProperty(inst.findProperty("ModulePath")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: ModulePath" << endl;
        return 1;
      }
    }
  
    if (p.getParameters(asa))
    {
      if (processTestVerbose) cout << "    Parameters" << endl;
      inst.getProperty(inst.findProperty("Parameters")).getValue().get(asb);
      if (asa != asb)
      {
        cout << "+++++ Error: property mismatch: Parameters" << endl;
        return 1;
      }
    }
  
    if (p.getProcessNiceValue(i32a))
    {
      if (processTestVerbose) cout << "    ProcessNiceValue" << endl;
      inst.getProperty(inst.findProperty("ProcessNiceValue")).getValue().get(i32b);
      if (i32a != i32b)
      {
        cout << "+++++ Error: property mismatch: ProcessNiceValue" << endl;
        return 1;
      }
    }
  
    if (p.getProcessWaitingForEvent(sa))
    {
      if (processTestVerbose) cout << "    ProcessWaitingForEvent" << endl;
      inst.getProperty(inst.findProperty("ProcessWaitingForEvent")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: ProcessWaitingForEvent" << endl;
        return 1;
      }
    }
    cout << "+++++ property values ok" << endl;
  }

  // ========== UnixProcessStatisticalInformation instances ===============

  else if (String::equalNoCase(className,"PG_UnixProcessStatisticalInformation"))
  {
    if (p.getCPUTime(i32a))
    {
      if (processTestVerbose) cout << "    CPUTime" << endl;
      inst.getProperty(inst.findProperty("CPUTime")).getValue().get(i32b);
      if (i32a != i32b)
      {
        cout << "+++++ Error: property mismatch: CPUTime" << endl;
        return 1;
      }
    }
  
    if (p.getRealText(i64a))
    {
      if (processTestVerbose) cout << "    RealText" << endl;
      inst.getProperty(inst.findProperty("RealText")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: RealText" << endl;
        return 1;
      }
    }
  
    if (p.getRealData(i64a))
    {
      if (processTestVerbose) cout << "    RealData" << endl;
      inst.getProperty(inst.findProperty("RealData")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: RealData" << endl;
        return 1;
      }
    }
  
    if (p.getRealStack(i64a))
    {
      if (processTestVerbose) cout << "    RealStack" << endl;
      inst.getProperty(inst.findProperty("RealStack")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: RealStack" << endl;
        return 1;
      }
    }
  
    if (p.getVirtualText(i64a))
    {
      if (processTestVerbose) cout << "    VirtualText" << endl;
      inst.getProperty(inst.findProperty("VirtualText")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: VirtualText" << endl;
        return 1;
      }
    }
  
    if (p.getVirtualData(i64a))
    {
      if (processTestVerbose) cout << "    VirtualData" << endl;
      inst.getProperty(inst.findProperty("VirtualData")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: VirtualData" << endl;
        return 1;
      }
    }
  
    if (p.getVirtualStack(i64a))
    {
      if (processTestVerbose) cout << "    VirtualStack" << endl;
      inst.getProperty(inst.findProperty("VirtualStack")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: VirtualStack" << endl;
        return 1;
      }
    }
  
    if (p.getVirtualMemoryMappedFileSize(i64a))
    {
      if (processTestVerbose) cout << "    VirtualMemoryMappedFileSize" << endl;
      inst.getProperty(inst.findProperty("VirtualMemoryMappedFileSize")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: VirtualMemoryMappedFileSize" << endl;
        return 1;
      }
    }
  
    if (p.getVirtualSharedMemory(i64a))
    {
      if (processTestVerbose) cout << "    VirtualSharedMemory" << endl;
      inst.getProperty(inst.findProperty("VirtualSharedMemory")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: VirtualSharedMemory" << endl;
        return 1;
      }
    }
  
    if (p.getCpuTimeDeadChildren(i64a))
    {
      if (processTestVerbose) cout << "    CpuTimeDeadChildren" << endl;
      inst.getProperty(inst.findProperty("CpuTimeDeadChildren")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: CpuTimeDeadChildren" << endl;
        return 1;
      }
    }

    if (p.getSystemTimeDeadChildren(i64a))
    {
      if (processTestVerbose) cout << "    SystemTimeDeadChildren" << endl;
      inst.getProperty(inst.findProperty("SystemTimeDeadChildren")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: SystemTimeDeadChildren" << endl;
        return 1;
      }
    }
  
    if (p.getRealSpace(i64a))
    {
      if (processTestVerbose) cout << "    RealSpace" << endl;
      inst.getProperty(inst.findProperty("RealSpace")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: RealSpace" << endl;
        return 1;
      }
    }
  
    cout << "+++++ property values ok" << endl;
  }
  
  else
  {
    cout << "+++++ Error: class " << className << " not recognized" << endl;
    return 1;
  }

  // ------------------ do getInstance() with bad key ----------------------
  
  Array<CIMKeyBinding> kb = ref.getKeyBindings();
  // mess up first key name
  kb[0].setName("foobar");
  ref.setKeyBindings(kb);
  
  int status = 0;

  cout << "+++++ getInstance with bad key" << endl;
  try
  {
    inst = c.getInstance(NAMESPACE,ref);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_INVALID_PARAMETER) status = 1;
  }
  catch (Exception& e)
  {
    // any other exception is a failure; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: bad instance name not rejected" << endl;
    return 1;
  }

  // =======================================================================
  // createInstance
  // =======================================================================

  CIMObjectPath ref2;
  cout << "+++++ createInstance" << endl;
  status = 0;
  try
  {
    ref2 = c.createInstance(NAMESPACE,inst);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  catch (Exception& e)
  {
    // any other Exception is a problem; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: createInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // deleteInstance
  // =======================================================================

  cout << "+++++ deleteInstance" << endl;
  status = 0;
  try
  {
    c.deleteInstance(NAMESPACE,ref);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  catch (Exception& e)
  {
    // any other Exception is a problem; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: deleteInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // enumerateInstances
  // =======================================================================

  cout << "+++++ enumerateInstances(" << className << ")" << endl;
  
  Array<CIMInstance> ia;
  try
  {
    ia = c.enumerateInstances(NAMESPACE,className);
  }
  catch (Exception& e)
  {
    errorExit(e);
  }

  // There should be several instances
  if (ia.size() < 5)
  {
    cout << "+++++ Error: enumerateInstances on " << className << " returned too few instances" << endl;
    return 1;
  }
  
  // For UnixProcess, we should be able to find this test process
  // and the cimserver
  if (String::equalNoCase(className,"CIM_Process") ||
      String::equalNoCase(className,"PG_UnixProcess"))
  {
    status = 0;
    for (i=0; i<ia.size(); i++)
    {
      Array<String> cmd;
      ia[i].getProperty(ia[i].findProperty("Parameters")).getValue().get(cmd);
      if (cmd[0] == "cimserver")
      {
        status++;
        if (processTestVerbose) cout << "    cimserver" << endl;
      }
      if (cmd[0] == "ProcessProviderTestClient")
      {
        status++;
        if (processTestVerbose) cout << "    ProcessProviderTestClient" << endl;
      }
    }
    if (status < 2)
    {
      cout << "Error: couldn't find cimserver or test client process!" << endl;
      return 1;
    }
  }

  // =======================================================================
  // modifyInstance
  // =======================================================================

  // We do modifyInstance after enumerateInstances, because
  // modifyInstance requires a CIMInstance argument, which
  // is conveniently what was returned by enumerateInstances

  CIMInstance ni = ia[(ia.size()-1) >> 1]; // pick the middle one

  cout << "+++++ modifyInstance" << endl;
  status = 0;
  try
  {
    c.modifyInstance(NAMESPACE,ni);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  catch (Exception& e)
  {
    // any other Exception is a problem; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: modifyInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // Tests completed
  // =======================================================================

  return 0;
}
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;
}
Esempio n. 10
0
int testClass(const String& className)
{
  Array<CIMObjectPath> refs;

  cout << endl << "+++++ Testing Class " << className << " +++++" << endl;

  // =======================================================================
  // enumerateInstanceNames
  // =======================================================================

  cout << "+++++ enumerateInstanceNames(" << className << "): ";
  try
  {
    refs = c.enumerateInstanceNames(NAMESPACE,className);
  }
  catch (Exception& e)
  {
    cout << endl;
    errorExit(e);
  }

  cout << refs.size() << " instances" << endl;

  // There must be at least 1 processor or something's wrong
  if (refs.size() < 1)
  {
    cout << "+++++ Error: too few instances returned" << endl;
    return 1;
  }

  // =======================================================================
  // getInstance
  // =======================================================================

  // -------------------- First do normal getInstance() --------------------

  // pick the middle instance of the bunch
  Uint32 i = (refs.size()-1) >> 1;  // This is a shift right, not streamio!
  CIMObjectPath ref = refs[i];
  CIMInstance inst;
  cout << "+++++ getInstance " << i << endl;
  try
  {
    inst = c.getInstance(NAMESPACE,ref);
  }
  catch (Exception& e)
  {
    errorExit(e);
  }

  if (processorTestVerbose)
  {
    // Display keys
    Array<CIMKeyBinding> keys = ref.getKeyBindings();
    cout << "  Keys:" << endl;
    for (i=0; i<keys.size(); i++)
        cout << "    " << keys[i].getName().getString() << " = "
             << keys[i].getValue() << endl;
  }

  // check returned property values

  // first get the PID and load a processor object
  String devID;
  inst.getProperty(inst.findProperty("DeviceID")).getValue().get(devID);
  Processor p;
  // error if can't get the process
  if (!p.findProcessor(devID))
  {
    cout << "+++++ Error: can't find process corresponding to instance" << endl;
    return 1;
  }

  if (processorTestVerbose) cout << "  Properties:" << endl;

  Boolean ba, bb;
  String sa, sb;
  Array<String> asa, asb;
  Uint16 i16a, i16b;
  Array<Uint16> ai16a, ai16b;
  Uint32 i32a, i32b;
  Uint64 i64a, i64b;
  CIMDateTime da, db;

  // For each property, get it from the just-loaded process
  // object and compare with what was returned by getInstance()

  // ===================== CIM_ManagedElement =========================

  // Caption and Description are common to all classes
  if (p.getCaption(sa))
  {
    if (processorTestVerbose) cout << "    Caption" << endl;
    inst.getProperty(inst.findProperty("Caption")).getValue().get(sb);
    if (sa != sb)
    {
      cout << "+++++ Error: property mismatch: Caption" << endl;
      return 1;
    }
  }

  if (p.getDescription(sa))
  {
    if (processorTestVerbose) cout << "    Description" << endl;
    inst.getProperty(inst.findProperty("Description")).getValue().get(sb);
    if (sa != sb)
    {
      cout << "+++++ Error: property mismatch: Description" << endl;
      return 1;
    }
  }

  // The rest of the properties to check depend on the
  // class we are testing

  // ===================== CIM_ManagedSystemElement =========================

  if (String::equalNoCase(className,"CIM_Processor") ||
      String::equalNoCase(className,"PG_Processor"))
  {
    if (p.getInstallDate(da))
    {
      if (processorTestVerbose) cout << "    InstallDate" << endl;
      inst.getProperty(inst.findProperty("InstallDate")).getValue().get(db);
      if (da != db)
      {
        cout << "+++++ Error: property mismatch: InstallDate" << endl;
        return 1;
      }
    }

    if (p.getStatus(sa))
    {
      if (processorTestVerbose) cout << "    Status" << endl;
      inst.getProperty(inst.findProperty("Status")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: Status" << endl;
        return 1;
      }
    }

  // ===================== CIM_LogicalDevice =========================

    if (p.getPowerManagementSupported(ba))
    {
      if (processorTestVerbose) cout << "    PowerManagementSupported" << endl;
      inst.getProperty(
          inst.findProperty("PowerManagementSupported")).getValue().get(bb);
      if (ba != bb)
      {
        cout << "+++++ Error: property mismatch: PowerManagementSupported" <<
            endl;
        return 1;
      }
    }

    if (p.getPowerManagementCapabilities(ai16a))
    {
      if (processorTestVerbose)
          cout << "    PowerManagementCapabilities" << endl;
      inst.getProperty(inst.findProperty(
          "PowerManagementCapabilities")).getValue().get(ai16b);
      if (ai16a != ai16b)
      {
        cout << "+++++ Error: property mismatch: PowerManagementCapabilities"
             << endl;
        return 1;
      }
    }

    if (p.getAvailability(i16a))
    {
      if (processorTestVerbose) cout << "    Availability" << endl;
      inst.getProperty(inst.findProperty("Availability")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: Availability" << endl;
        return 1;
      }
    }

    if (p.getStatusInfo(i16a))
    {
      if (processorTestVerbose) cout << "    StatusInfo" << endl;
      inst.getProperty(inst.findProperty("StatusInfo")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: StatusInfo" << endl;
        return 1;
      }
    }

    if (p.getLastErrorCode(i32a))
    {
      if (processorTestVerbose) cout << "    LastErrorCode" << endl;
      inst.getProperty(inst.findProperty("LastErrorCode")).getValue().get(i32b);
      if (i32a != i32b)
      {
        cout << "+++++ Error: property mismatch: LastErrorCode" << endl;
        return 1;
      }
    }

    if (p.getErrorDescription(sa))
    {
      if (processorTestVerbose) cout << "    ErrorDescription" << endl;
      inst.getProperty(
          inst.findProperty("ErrorDescription")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: ErrorDescription" << endl;
        return 1;
      }
    }

    if (p.getErrorCleared(ba))
    {
      if (processorTestVerbose) cout << "    ErrorCleared" << endl;
      inst.getProperty(inst.findProperty("ErrorCleared")).getValue().get(bb);
      if (ba != bb)
      {
        cout << "+++++ Error: property mismatch: ErrorCleared" << endl;
        return 1;
      }
    }

    if (p.getOtherIdentifyingInfo(asa))
    {
      if (processorTestVerbose) cout << "    OtherIdentifyingInfo" << endl;
      inst.getProperty(
          inst.findProperty("OtherIdentifyingInfo")).getValue().get(asb);
      if (asa != asb)
      {
        cout << "+++++ Error: property mismatch: OtherIdentifyingInfo" << endl;
        return 1;
      }
    }

    if (p.getPowerOnHours(i64a))
    {
      if (processorTestVerbose) cout << "    PowerOnHours" << endl;
      inst.getProperty(inst.findProperty("PowerOnHours")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: PowerOnHours" << endl;
        return 1;
      }
    }

    if (p.getTotalPowerOnHours(i64a))
    {
      if (processorTestVerbose) cout << "    TotalPowerOnHours" << endl;
      inst.getProperty(
          inst.findProperty("TotalPowerOnHours")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: TotalPowerOnHours" << endl;
        return 1;
      }
    }

    if (p.getIdentifyingDescriptions(asa))
    {
      if (processorTestVerbose) cout << "    IdentifyingDescriptions" << endl;
      inst.getProperty(
          inst.findProperty("IdentifyingDescriptions")).getValue().get(asb);
      if (asa != asb)
      {
        cout << "+++++ Error: property mismatch: IdentifyingDescriptions" <<
            endl;
        return 1;
      }
    }

    if (p.getAdditionalAvailability(ai16a))
    {
      if (processorTestVerbose) cout << "    AdditionalAvailability" << endl;
      inst.getProperty(
          inst.findProperty("AdditionalAvailability")).getValue().get(ai16b);
      if (ai16a != ai16b)
      {
        cout << "+++++ Error: property mismatch: AdditionalAvailability" <<
            endl;
        return 1;
      }
    }

    if (p.getMaxQuiesceTime(i64a))
    {
      if (processorTestVerbose) cout << "    MaxQuiesceTime" << endl;
      inst.getProperty(
          inst.findProperty("MaxQuiesceTime")).getValue().get(i64b);
      if (i64a != i64b)
      {
        cout << "+++++ Error: property mismatch: MaxQuiesceTime" << endl;
        return 1;
      }
    }

  // ===================== CIM_Processor =========================

    if (p.getRole(sa))
    {
      if (processorTestVerbose) cout << "    Role" << endl;
      inst.getProperty(inst.findProperty("Role")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: Role" << endl;
        return 1;
      }
    }

    if (p.getFamily(i16a))
    {
      if (processorTestVerbose) cout << "    Family" << endl;
      inst.getProperty(inst.findProperty("Family")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: Family" << endl;
        return 1;
      }
    }

    if (p.getOtherFamilyDescription(sa))
    {
      if (processorTestVerbose) cout << "    OtherFamilyDescription" << endl;
      inst.getProperty(
          inst.findProperty("OtherFamilyDescription")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: OtherFamilyDescription" <<
            endl;
        return 1;
      }
    }

    if (p.getUpgradeMethod(i16a))
    {
      if (processorTestVerbose) cout << "    UpgradeMethod" << endl;
      inst.getProperty(inst.findProperty("UpgradeMethod")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: UpgradeMethod" << endl;
        return 1;
      }
    }

    if (p.getMaxClockSpeed(i32a))
    {
      if (processorTestVerbose) cout << "    MaxClockSpeed" << endl;
      inst.getProperty(inst.findProperty("MaxClockSpeed")).getValue().get(i32b);
      if (i32a != i32b)
      {
        cout << "+++++ Error: property mismatch: MaxClockSpeed" << endl;
        return 1;
      }
    }

    if (p.getCurrentClockSpeed(i32a))
    {
      if (processorTestVerbose) cout << "    CurrentClockSpeed" << endl;
      inst.getProperty(
          inst.findProperty("CurrentClockSpeed")).getValue().get(i32b);
      if (i32a != i32b)
      {
        cout << "+++++ Error: property mismatch: CurrentClockSpeed" << endl;
        return 1;
      }
    }

    if (p.getDataWidth(i16a))
    {
      if (processorTestVerbose) cout << "    DataWidth" << endl;
      inst.getProperty(inst.findProperty("DataWidth")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: DataWidth" << endl;
        return 1;
      }
    }

    if (p.getAddressWidth(i16a))
    {
      if (processorTestVerbose) cout << "    AddressWidth" << endl;
      inst.getProperty(inst.findProperty("AddressWidth")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: AddressWidth" << endl;
        return 1;
      }
    }

    if (p.getLoadPercentage(i16a))
    {
      if (processorTestVerbose) cout << "    LoadPercentage" << endl;
      inst.getProperty(
          inst.findProperty("LoadPercentage")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: LoadPercentage" << endl;
        cout << "LoadPercentage expected = " << i16a << ", received = " <<
            i16b << endl;
        return 1;
      }
    }

    if (p.getStepping(sa))
    {
      if (processorTestVerbose) cout << "    Stepping" << endl;
      inst.getProperty(inst.findProperty("Stepping")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: Stepping" << endl;
        return 1;
      }
    }

    if (p.getUniqueID(sa))
    {
      if (processorTestVerbose) cout << "    UniqueID" << endl;
      inst.getProperty(inst.findProperty("UniqueID")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: UniqueID" << endl;
        return 1;
      }
    }

    if (p.getCPUStatus(i16a))
    {
      if (processorTestVerbose) cout << "    CPUStatus" << endl;
      inst.getProperty(inst.findProperty("CPUStatus")).getValue().get(i16b);
      if (i16a != i16b)
      {
        cout << "+++++ Error: property mismatch: CPUStatus" << endl;
        return 1;
      }
    }

  // ===================== PG_Processor =========================

    if (p.getBiosID(sa))
    {
      if (processorTestVerbose) cout << "    BiosID" << endl;
      inst.getProperty(inst.findProperty("BiosID")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: BiosID" << endl;
        return 1;
      }
    }

    if (p.getFirmwareID(sa))
    {
      if (processorTestVerbose) cout << "    FirmwareID" << endl;
      inst.getProperty(inst.findProperty("FirmwareID")).getValue().get(sb);
      if (sa != sb)
      {
        cout << "+++++ Error: property mismatch: FirmwareID" << endl;
        return 1;
      }
    }

    cout << "+++++ property values ok" << endl;
  }

  else
  {
    cout << "+++++ Error: class " << className << " not recognized" << endl;
    return 1;
  }

  // ------------------ do getInstance() with bad key ----------------------

  Array<CIMKeyBinding> kb = ref.getKeyBindings();
  // mess up first key name
  kb[0].setName("garbage");
  ref.setKeyBindings(kb);

  int status = 0;

  cout << "+++++ getInstance with bad key" << endl;
  try
  {
    inst = c.getInstance(NAMESPACE,ref);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_INVALID_PARAMETER) status = 1;
  }
  if (status == 0)
  {
    cout << "+++++ Error: bad instance name not rejected" << endl;
    return 1;
  }

  // =======================================================================
  // createInstance
  // =======================================================================

  CIMObjectPath ref2;
  cout << "+++++ createInstance" << endl;
  status = 0;
  try
  {
    ref2 = c.createInstance(NAMESPACE,inst);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  if (status == 0)
  {
    cout << "+++++ Error: createInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // deleteInstance
  // =======================================================================

  cout << "+++++ deleteInstance" << endl;
  status = 0;
  try
  {
    c.deleteInstance(NAMESPACE,ref);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  if (status == 0)
  {
    cout << "+++++ Error: deleteInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // enumerateInstances
  // =======================================================================

  cout << "+++++ enumerateInstances(" << className << ")" << endl;

  Array<CIMInstance> ia;
  try
  {
    ia = c.enumerateInstances(NAMESPACE,className);
  }
  catch (Exception& e)
  {
    errorExit(e);
  }


  // =======================================================================
  // modifyInstance
  // =======================================================================

  // We do modifyInstance after enumerateInstances, because
  // modifyInstance requires a CIMInstance argument, which
  // is conveniently what was returned by enumerateInstances

  CIMInstance ni = ia[(ia.size()-1) >> 1]; // pick the middle one

  cout << "+++++ modifyInstance" << endl;
  status = 0;
  try
  {
    c.modifyInstance(NAMESPACE,ni);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  if (status == 0)
  {
    cout << "+++++ Error: modifyInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // Tests completed
  // =======================================================================

  return 0;
}
static void
_test2 (CIMClient & client)
{
  Uint32 exceptions = 0;
  CIMObjectPath instanceName;
  Array < CIMKeyBinding > keyBindings;

  keyBindings.append (CIMKeyBinding ("ElementNameName",
                                     "TestCMPI_ExecQuery",
                                     CIMKeyBinding::STRING));

  instanceName.setNameSpace (providerNamespace);
  instanceName.setClassName ("TestCMPI_ExecQuery");
  instanceName.setKeyBindings (keyBindings);

  /* Call the unsupported functions of the provider. */
  try
  {
    CIMInstance instance (client.getInstance (providerNamespace,
                                              instanceName));
  } catch (const CIMException &)
  {
     exceptions ++;
  }


  try
  {
    client.deleteInstance (providerNamespace, instanceName);

  } catch (const CIMException & )
  {
     exceptions ++;
  }
  CIMClass thisClass = client.getClass(
                           providerNamespace,
                           "TestCMPI_ExecQuery",
                           false,
                           true,
                           true,
                           CIMPropertyList());
  Array<CIMName> propertyNameList;
  propertyNameList.append(CIMName("ElementName"));
  CIMPropertyList myPropertyList(propertyNameList);
  // create the instance with the defined properties
  CIMInstance newInstance = thisClass.buildInstance(true, true, myPropertyList);
  newInstance.getProperty(0).setValue(CIMValue(String("TestCMPI_execQuery") ));
  try
  {

    CIMObjectPath objectPath (client.createInstance (providerNamespace,
                                                     newInstance));


  } catch (const CIMException &)
  {
     exceptions ++;
  }

  try
  {
    client.modifyInstance (providerNamespace, newInstance);

  } catch (const CIMException &)
  {
     exceptions ++;
  }
  try
  {

    Array < CIMInstance > instances =
      client.enumerateInstances (providerNamespace,
                                 CIMName ("TestCMPI_ExecQuery"));
  } catch (const CIMException &)
  {
     exceptions ++;
  }

  try
  {
    Array < CIMObjectPath > objectPaths =
      client.enumerateInstanceNames (providerNamespace,
                                     CIMName ("TestCMPI_ExecQuery"));
  } catch (const CIMException &)
  {
     exceptions ++;
  }

  PEGASUS_TEST_ASSERT(exceptions ==  6);

}
Esempio n. 12
0
int testClass(const String& className)
{
  Array<CIMObjectPath> refs;

  // =======================================================================
  // enumerateInstanceNames
  // =======================================================================

  cout << "+++++ enumerateInstanceNames(" << className << ") ";
  try
  {
    refs = c.enumerateInstanceNames(NAMESPACE,className);
  }
  catch (Exception& e)
  {
    cout << endl;
    errorExit(e);
  }

  cout << refs.size() << " instances" << endl;
  // if zero instances, not an error, but can't proceed
  if (refs.size() == 0)
  {
    cout << "+++++ test completed early" << endl;
    return 0;
  }

  // =======================================================================
  // getInstance
  // =======================================================================

  // -------------------- First do normal getInstance() --------------------

  // pick the middle instance of the bunch
  int i = (refs.size()-1) >> 1;  // This is a shift right, not streamio!
  CIMObjectPath ref = refs[i];
  CIMInstance inst;
  cout << "+++++ getInstance #" << i << endl;
  try
  {
    inst = c.getInstance(NAMESPACE,ref);
  }
  catch (Exception& e)
  {
    errorExit(e);
  }

  // ATTN-MG-20020501: Can add some property value checks here

  // ------------------ do getInstance() with bad key ----------------------
  
  Array<CIMKeyBinding> kb = ref.getKeyBindings();
  // mess up first key name
  kb[0].setName("foobar");
  ref.setKeyBindings(kb);
  
  int status = 0;

  cout << "+++++ getInstance with bad key" << endl;
  try
  {
    inst = c.getInstance(NAMESPACE,ref);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_INVALID_PARAMETER) status = 1;
  }
  catch (Exception& e)
  {
    // any other exception is a failure; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: bad instance name not rejected" << endl;
    return 1;
  }

  // =======================================================================
  // createInstance
  // =======================================================================

  CIMObjectPath ref2;
  cout << "+++++ createInstance" << endl;
  status = 0;
  try
  {
    ref2 = c.createInstance(NAMESPACE,inst);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  catch (Exception& e)
  {
    // any other Exception is a problem; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: createInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // deleteInstance
  // =======================================================================

  cout << "+++++ deleteInstance" << endl;
  status = 0;
  try
  {
    c.deleteInstance(NAMESPACE,ref);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  catch (Exception& e)
  {
    // any other Exception is a problem; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: deleteInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // enumerateInstances
  // =======================================================================

  cout << "+++++ enumerateInstances(" << className << ")" << endl;
  
  Array<CIMInstance> ia;
  try
  {
    ia = c.enumerateInstances(NAMESPACE,className);
  }
  catch (Exception& e)
  {
    errorExit(e);
  }

  // There should be several instances
  if (ia.size() == 0)
  {
    cout << "+++++ Error: enumerateInstances on " << className << " returned too few instances" << endl;
    cout << "+++++ Test failed" << endl;
    return 1;
  }

  // =======================================================================
  // modifyInstance
  // =======================================================================

  // We do modifyInstance after enumerateInstances, because
  // modifyInstance requires a CIMInstance argument, which
  // is conveniently what was returned by enumerateInstances

  CIMInstance ni = ia[(ia.size()-1) >> 1]; // pick the middle one

  cout << "+++++ modifyInstance" << endl;
  status = 0;
  try
  {
    c.modifyInstance(NAMESPACE,ni);
  }
  catch (CIMException& e)
  {
    if (e.getCode() == CIM_ERR_NOT_SUPPORTED) status = 1;
  }
  catch (Exception& e)
  {
    // any other Exception is a problem; leave status alone
  }
  if (status == 0)
  {
    cout << "+++++ Error: modifyInstance didn't throw exception" << endl;
    return 1;
  }

  // =======================================================================
  // Tests completed
  // =======================================================================

  return 0;
}
void MCCA_TestAssocProvider::associators(
    const OperationContext & context,
    const CIMObjectPath & objectName,
    const CIMName & associationClass,
    const CIMName & resultClass,
    const String & role,
    const String & resultRole,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList & propertyList,
    ObjectResponseHandler & handler)
{
    CDEBUG("MCCA_TestAssocProvider::associators() called.");
    // create a new CIMInstance based on class with name className
    CIMInstance constructedInstance = CIMInstance(testClassName);
    CIMObjectPath   targetObjectPath = CIMObjectPath();
    Array<CIMKeyBinding> keyBindings = Array<CIMKeyBinding>();
    Uint32 sourceKey = 0;

    CDEBUG("Initialisation ended.");
    handler.processing();
    CDEBUG("handler.processing started.");
    // we do ignore role, resultRole, includeQualifiers, includeClassOrigin,
    // propertyList

    CDEBUG("Next building object path.");
    /////////////////////////////////////////////////////////////////////
    //      BUILD OBJECTPATH
    /////////////////////////////////////////////////////////////////////

    // preparing object path first
    targetObjectPath.setHost("localhost:5988");
    targetObjectPath.setClassName(testClassName);
    CDEBUG("Host and classname set, host=" << objectName.getHost());
    // determine if source namespace is namespace A or B
    // and build respective target namespace ...
    if (objectName.getNameSpace().equal(nameSpaceA))
    {
        targetObjectPath.setNameSpace(nameSpaceB);
    }
    if (objectName.getNameSpace().equal(nameSpaceB))
    {
        targetObjectPath.setNameSpace(nameSpaceA);
    }
    CDEBUG("NameSpace set.");
    // determine key of source object so we can create target object
    Array<CIMKeyBinding> sourceKeyBindings = objectName.getKeyBindings();

    CDEBUG("Determining sourceKey.");
    // only one keyvalue, so we take that first one
    String      keyValueString = String(sourceKeyBindings[0].getValue());
    CDEBUG("keyValueString=" << keyValueString);
    sourceKey = strtoul((const char*) keyValueString.getCString(), NULL, 0);
    CDEBUG("sourceKey=" << sourceKey);


    CIMKeyBinding  testClassKey = CIMKeyBinding(CIMName("theKey"),
                                                    CIMValue(sourceKey) );
    CDEBUG("Created new KeyBinding testClassKey.");
    // testClassKey.setValue(keyValueString);

    CDEBUG("sourceKey = string(set keybinding),int(sourceKey)"
            << testClassKey.getValue()
            << "," << sourceKey);
    keyBindings.append(testClassKey);
    CDEBUG("Appended(testClassKey).");

    targetObjectPath.setKeyBindings(keyBindings);
    /////////////////////////////////////////////////////////////////////
    //      ADD PROPERTIES
    /////////////////////////////////////////////////////////////////////

    // add properties to the CIMInstance object
    constructedInstance.addProperty( CIMProperty( CIMName("theKey"),
                sourceKey));
    constructedInstance.addProperty( CIMProperty( CIMName("theData"),
                20+sourceKey));
    char  buffer[100];
    sprintf(buffer,"ABC-%u",20*sourceKey+sourceKey);
    constructedInstance.addProperty(CIMProperty(CIMName ("theString"),
                String(buffer)));

    CDEBUG("Added properties to the CIMInstance object");

    CIMObject cimObject(constructedInstance);
    cimObject.setPath (targetObjectPath);

    // lets deliver all instances of CIMObjectpaths I do think are okay
    handler.deliver(cimObject);
    // complete processing the request
    handler.complete();
    CDEBUG("Association call conmplete.");
}
Esempio n. 14
0
/////////////////////////////////////////////////////////////////////////////
// WMIInstanceProvider::enumerateInstanceNames
//
// ///////////////////////////////////////////////////////////////////////////
Array<CIMObjectPath> WMIInstanceProvider::enumerateInstanceNames(
        const String& nameSpace,
        const String& userName,
        const String& password,
        const String& className)
{
    HRESULT hr;
    long lCount = 0;
    DWORD dwReturned;

    CComPtr<IEnumWbemClassObject>    pInstEnum;
    CComPtr<IWbemClassObject>        pInstance;

    Array<CIMObjectPath> instanceNames;

    PEG_METHOD_ENTER(TRC_WMIPROVIDER,
        "WMIInstanceProvider::enumerateInstanceNames()");

    setup(nameSpace, userName, password);

    if (!m_bInitialized)
    {
        PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1,
            "WMIInstanceProvider::enumerateInstanceNames - m_bInitilized= %x,"
            " throw CIM_ERR_FAILED exception",
            m_bInitialized));

        throw CIMException(CIM_ERR_FAILED);
    }

    // retrieve the instance enumeration object
    if (!(_collector->getInstanceEnum(&pInstEnum, className, TRUE)))
    {
        if (pInstEnum)
            pInstEnum.Release();

        throw CIMException(CIM_ERR_FAILED);
    }

    // set proxy security on pInstEnum
    bool bSecurity = _collector->setProxySecurity(pInstEnum);

    // Get the names of the instances and send to handler
    hr = pInstEnum->Next(WBEM_INFINITE, 1, &pInstance, &dwReturned);

    while (SUCCEEDED(hr) && (1 == dwReturned))
    {
        CIMInstance tempInst(className);

        if (_collector->getCIMInstance(pInstance,
                                       tempInst,
                                       FALSE,
                                       FALSE,
                                       FALSE))
        {
            //new code
            CIMObjectPath tempRef;

            CComVariant vAux;
            char * strAux = NULL;

            //set hostname
            if (pInstance->Get(L"__SERVER", 0, &vAux, NULL, NULL) != S_OK)
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                    "Failed to retrieve WMI Data.");

            strAux = new char[wcslen(vAux.bstrVal)+1];
            if (strAux == NULL)
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Out of Memory.");

            wcstombs(strAux, vAux.bstrVal, wcslen(vAux.bstrVal)+1);
            tempRef.setHost(strAux);
            delete [] strAux;

            strAux = NULL;
            vAux.Clear();

            //set class name
            if (pInstance->Get(L"__CLASS", 0, &vAux, NULL, NULL) != S_OK)
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                    "Failed to retrieve WMI Data.");

            strAux = new char[wcslen(vAux.bstrVal)+1];
            if (strAux == NULL)
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Out of Memory.");

            wcstombs(strAux, vAux.bstrVal, wcslen(vAux.bstrVal)+1);
            tempRef.setClassName(strAux);

            delete [] strAux;
            strAux = NULL;
            vAux.Clear();

            //set namespace
            if (pInstance->Get(L"__NAMESPACE", 0, &vAux, NULL, NULL) != S_OK)
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                    "Failed to retrieve WMI Data.");

            strAux = new char[wcslen(vAux.bstrVal)+1];
            if (strAux == NULL)
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Out of Memory.");

            wcstombs(strAux, vAux.bstrVal, wcslen(vAux.bstrVal)+1);

            //converts '\' to '/'
            _translateBackslashes(strAux);

            tempRef.setNameSpace(strAux);

            delete [] strAux;
            strAux = NULL;
            vAux.Clear();

            //get key bindings

            SAFEARRAY * aNames;
            if (pInstance->GetNames(NULL,
                                    WBEM_FLAG_KEYS_ONLY,
                                    NULL,
                                    &aNames) != S_OK)
                throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                    "Failed to retrieve WMI Data.");

            LONG lLBuond;
            LONG lUBuond;

            SafeArrayGetLBound(aNames, 1, &lLBuond);
            SafeArrayGetUBound(aNames, 1, &lUBuond);

            Array<CIMKeyBinding> keyBindings;

            for(LONG i = lLBuond; i <=lUBuond; i++)
            {
                CComBSTR bstrName;
                SafeArrayGetElement(aNames, &i, &bstrName);

                char * strPropertyName = new char[bstrName.Length()+1];
                if (strPropertyName == NULL)
                    throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                        "Out of Memory.");

                wcstombs(strPropertyName, bstrName, bstrName.Length()+1);

                CIMName keyname(strPropertyName);
                Uint32 Index = tempInst.findProperty(keyname);

                if (Index == PEG_NOT_FOUND)
                    throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
                        "Failed to retrieve WMI Data.");

                CIMValue keyvalue = tempInst.getProperty(Index).getValue();
                CIMKeyBinding key(keyname, keyvalue);
                keyBindings.append(key);

                delete [] strPropertyName;
            }

            SafeArrayDestroy(aNames);
            tempRef.setKeyBindings(keyBindings);
            instanceNames.append(tempRef);
        }

        if (pInstance)
            pInstance.Release();

        hr = pInstEnum->Next(WBEM_INFINITE, 1, &pInstance, &dwReturned);
    }

    if (pInstEnum)
        pInstEnum.Release();

    PEG_TRACE((TRC_WMIPROVIDER,
                  Tracer::LEVEL4,
                  "WMIInstanceProvider::enumerateInstanceNames() -"
                  " Instance count is %d",
                  lCount));

    if (lCount == 0)
    {
        PEG_TRACE((TRC_WMIPROVIDER,
                      Tracer::LEVEL2,
                      "WMIInstanceProvider::enumerateInstanceNames() -"
                      " hResult value is %x",
                      hr));
    }

    PEG_METHOD_EXIT();

    return instanceNames;
}
Esempio n. 15
0
void TestDeleteInstances(ProviderRegistrationManager & prmanager)
{
   CIMKeyBinding kb1(CIMName ("ProviderModuleName"), "providersModule1",
       CIMKeyBinding::STRING);
   CIMKeyBinding kb2(CIMName ("ProviderName"), "PG_ProviderInstance1",
       CIMKeyBinding::STRING);
   CIMKeyBinding kb3(CIMName ("CapabilityID"), "capability1",
       CIMKeyBinding::STRING);
   CIMKeyBinding kbp1(CIMName ("ProviderModuleName"), "providersModule1",
       CIMKeyBinding::STRING);
   CIMKeyBinding kbp2(CIMName ("Name"), "PG_ProviderInstance1",
       CIMKeyBinding::STRING);
   CIMKeyBinding kbm1(CIMName ("Name"), "providersModule1",
       CIMKeyBinding::STRING);

   CIMObjectPath instanceName;

  try
  {
    for (Uint32 i=1; i<=3; i++)
    {
      CIMObjectPath instanceName2;
      Array<CIMKeyBinding> keys2;
      Array<CIMKeyBinding> keysm;
      Array<CIMKeyBinding> keys;

      //
      // create Provider module instances
      //
      if (i <= 1)
      {
        CIMObjectPath returnRef;
        CIMClass cimClass(CLASSNAME);
        CIMInstance cimInstance(CLASSNAME);

        cimInstance.addProperty(CIMProperty(CIMName ("Name"),
            String("providersModule1")));
        cimInstance.addProperty(CIMProperty(CIMName ("Vendor"), String("HP")));
        cimInstance.addProperty(CIMProperty(CIMName ("Version"),
            String("2.0")));
        cimInstance.addProperty(CIMProperty(CIMName ("InterfaceType"),
            String("PG_DefaultC++")));
        cimInstance.addProperty(CIMProperty(CIMName ("InterfaceVersion"),
            String("2.0")));
        cimInstance.addProperty(CIMProperty(CIMName ("Location"),
            String("/tmp/module1")));

        instanceName = cimInstance.buildPath(cimClass);

        instanceName.setNameSpace(NAMESPACE);
        instanceName.setClassName(CLASSNAME);

        returnRef = prmanager.createInstance(instanceName, cimInstance);
    }

    // create PG_Provider instances

    if (i <= 2 )
    {
        CIMObjectPath returnRef2;

        CIMClass cimClass2(CLASSNAME2);

        CIMInstance cimInstance2(CLASSNAME2);

        cimInstance2.addProperty(CIMProperty(CIMName ("ProviderModuleName"),
            String("providersModule1")));
        cimInstance2.addProperty(CIMProperty(CIMName ("Name"),
            String("PG_ProviderInstance1")));

        instanceName2 = cimInstance2.buildPath(cimClass2);

        instanceName2.setNameSpace(NAMESPACE);
        instanceName2.setClassName(CLASSNAME2);

        returnRef2 = prmanager.createInstance(instanceName2, cimInstance2);
    }

    //
    // create provider capability instances
    //

    Array <String> namespaces;
    Array <Uint16> providerType;
    Array <String> supportedMethods;

    namespaces.append("test_namespace1");
    namespaces.append("test_namespace2");

    providerType.append(2);
    providerType.append(5);

    supportedMethods.append("test_method1");
    supportedMethods.append("test_method2");

    CIMObjectPath returnRef3;

    CIMClass cimClass3(CLASSNAME3);

    CIMInstance cimInstance3(CLASSNAME3);

    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderModuleName"),
        String("providersModule1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderName"),
        String("PG_ProviderInstance1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("CapabilityID"),
        String("capability1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("ClassName"),
        String("test_class1")));
    cimInstance3.addProperty(CIMProperty(CIMName ("Namespaces"), namespaces));
    cimInstance3.addProperty(CIMProperty(CIMName ("ProviderType"),
        providerType));
    cimInstance3.addProperty(CIMProperty(CIMName ("SupportedMethods"),
        supportedMethods));

    CIMObjectPath instanceName3 = cimInstance3.buildPath(cimClass3);

    instanceName3.setNameSpace(NAMESPACE);
    instanceName3.setClassName(CLASSNAME3);

    returnRef3 = prmanager.createInstance(instanceName3, cimInstance3);

    Boolean callFailed = false;
    switch (i)
    {
        case 1:
                //
                // delete cimInstance2
                //
                keys2.append(kbp1);
                keys2.append(kbp2);

                instanceName2.setKeyBindings(keys2);

                prmanager.deleteInstance(instanceName2);

                // Test duplicate delete which should fail
                try
                {
                    prmanager.deleteInstance(instanceName2);
                }
                catch(CIMException& e)
                {
                    callFailed = true;
                    VCOUT << "CIMException code " << e.getCode()
                        << "(" << cimStatusCodeToString(e.getCode()) << ")"
                        <<  "\nDescription \"" << e.getMessage() << "\""
                        << endl;
                    PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND);
                }
                PEGASUS_TEST_ASSERT(callFailed);

            break;

        case 2:
                //
                // delete cimInstance3
                //
                keys.append(kb1);
                keys.append(kb2);
                keys.append(kb3);

                instanceName3.setKeyBindings(keys);

                prmanager.deleteInstance(instanceName3);
            break;

        case 3:
                //
                // delete cimInstance
                //
                keysm.append(kbm1);

                instanceName.setKeyBindings(keysm);

            prmanager.deleteInstance(instanceName);
            break;
    }
    }
  }
  catch(CIMException& e)
  {
      throw (e);
  }
}