コード例 #1
0
ファイル: Method.cpp プロジェクト: brunolauze/pegasus
int main(int, char** argv)
{
    verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false;

    try
    {
        CIMMethod m1(CIMName ("getHostName"), CIMTYPE_STRING);
        m1.addQualifier(CIMQualifier(CIMName ("stuff"), true));
        m1.addQualifier(CIMQualifier(CIMName ("stuff2"), true));
        m1.addParameter(CIMParameter(CIMName ("ipaddress"), CIMTYPE_STRING));


        // Tests for Qualifiers
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 2);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);

        Uint32 posQualifier;
        posQualifier = m1.findQualifier(CIMName ("stuff"));
        PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(posQualifier < m1.getQualifierCount());

        m1.removeQualifier(posQualifier);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 1);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        // Tests for Parameters
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("noparam"))  == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getParameterCount()  == 1);
        CIMParameter cp = m1.getParameter(
            m1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cp.getName() == CIMName ("ipaddress"));

        m1.removeParameter (m1.findParameter (
            CIMName (CIMName ("ipaddress"))));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 0);
        m1.addParameter (CIMParameter (CIMName ("ipaddress"),
                                       CIMTYPE_STRING));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 1);

        // throws OutOfBounds
        try
        {
            m1.removeParameter (1);
        }
        catch (IndexOutOfBoundsException & oob)
        {
            if (verbose)
            {
                PEGASUS_STD (cout) << "Caught expected exception: "
                                   << oob.getMessage () << PEGASUS_STD (endl);
            }
        }

        CIMMethod m2(CIMName ("test"), CIMTYPE_STRING);
        m2.setName(CIMName ("getVersion"));
        PEGASUS_TEST_ASSERT(m2.getName() == CIMName ("getVersion"));

        m2.setType(CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(m2.getType() == CIMTYPE_STRING);

        m2.setClassOrigin(CIMName ("test"));
        PEGASUS_TEST_ASSERT(m2.getClassOrigin() == CIMName ("test"));

        m2.setPropagated(true);
        PEGASUS_TEST_ASSERT(m2.getPropagated() == true);

        const CIMMethod cm1(m1);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT((cm1.getParameterCount() != 3));
        PEGASUS_TEST_ASSERT(cm1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);

        CIMQualifier q = m1.getQualifier(posQualifier);
        CIMConstParameter ccp = cm1.getParameter(
                    cm1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(cm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(cm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!cm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!m1.identical(m2));

        // throws OutOfBounds
        try
        {
            CIMConstParameter p = cm1.getParameter(cm1.findParameter(
                                        CIMName ("ipaddress")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = cm1.getQualifier(cm1.findQualifier(
                                        CIMName ("abstract")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(cm1);
        }
        Buffer out;
        XmlWriter::appendMethodElement(out, cm1);
        MofWriter::appendMethodElement(out, cm1);

        Boolean nullMethod = cm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        CIMMethod m3 = m2.clone();
        m3 = cm1.clone();

        CIMMethod m4;
        CIMMethod m5(m4);

        CIMConstMethod ccm1(CIMName ("getHostName"),CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));

        PEGASUS_TEST_ASSERT(ccm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(ccm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!ccm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));
        PEGASUS_TEST_ASSERT(ccm1.getQualifierCount() == 0);
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("Stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(ccm1);
        }

        XmlWriter::appendMethodElement(out, ccm1);

        CIMConstMethod ccm2(ccm1);
        CIMConstMethod ccm3;

        ccm3 = ccm1.clone();
        ccm1 = ccm3;
        PEGASUS_TEST_ASSERT(ccm1.identical(ccm3));
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        nullMethod = ccm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        // throws OutOfBounds
        try
        {
            //CIMParameter p = m1.getParameter(
            //     m1.findParameter(CIMName ("ipaddress")));
            CIMConstParameter p = ccm1.getParameter(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = ccm1.getQualifier(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }
    }
    catch(Exception& e)
    {
        cerr << "Exception: " << e.getMessage() << endl;
    }

    // Test for add second qualifier with same name.
    // Should do exception

    cout << argv[0] << " +++++ passed all tests" << endl;

    return 0;
}
コード例 #2
0
ファイル: Cimpls.cpp プロジェクト: host1812/scx_plugin_public
int _getClass(const int argc, const char **argv)
{
  CIMClass cldef;
  try
  {
    cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );
  }
  catch (Exception& e)
  {
    cerr << /* "getClass: " << */ e.getMessage() << endl;
    return 1;
  }

  // Display the class definition
  // without qualifiers, for the moment

  // First the class name and superclass
  cout << "class " << cldef.getClassName().getString() << " : "
    << cldef.getSuperClassName().getString() << endl;
  cout << "{" << endl;
  
  // Now the properties
  // No qualifiers except [key], but specify type, array
  for (int i=0; i<cldef.getPropertyCount(); i++)
  {
    CIMProperty p = cldef.getProperty(i);
    cout << "  ";
    // output key, if required
    if (_isKey(p)) cout << "[ Key ] ";
    // prepare to output type, but
    // first, if type is "reference", find target class
    if (p.getType() == CIMTYPE_REFERENCE)
      cout << p.getReferenceClassName().getString() << " REF ";
    // output type
    else cout << cimTypeToString(p.getType()) << " ";
    // output name
    cout << p.getName().getString();
    // output array, if required
    if (p.isArray()) cout << "[]";
    // final eol
    cout << ";" << endl;
  }
  
  // need to do methods
  for (int i=0; i<cldef.getMethodCount(); i++)
  {
    CIMMethod m = cldef.getMethod(i);
    // output type
    cout << "  " << cimTypeToString(m.getType()) << " ";
    // output name
    cout << m.getName().getString() << "(";
    // output parameters
    // new line if there are any parameters
    for (int j=0; j<m.getParameterCount(); j++)
    {
      CIMParameter p = m.getParameter(j);
      // output IN/OUT qualifiers on a fresh line
      cout << endl << "    [ ";
      // loop through qualifiers looking for IN, OUT
      for (int k=0; k<p.getQualifierCount(); k++)
      {
        // when one found, output its value
        CIMQualifier q = p.getQualifier(k);
        if (q.getName().equal("in") ||
            q.getName().equal("out"))
        {
          cout << q.getName().getString() << " ";
        }
      }
      // Now the type
      cout << "] " << cimTypeToString(p.getType()) << " ";
      // finally the name
      cout << p.getName().getString();
      // array brackets
      if (p.isArray()) cout << "[]";
      // closing , on parameter if not last
      if (j != m.getParameterCount()-1) cout << ",";
    }
    // after last param, indent before closing paren

    // close paren
    cout << ")";
    // if (m.isArray()) cout << "[]";
    // finish output
    cout << ";" << endl;
  }
  
  // final brace and done
  cout << "};" << endl;

  return 0; 
}
コード例 #3
0
ファイル: OW_CIMtoXML.cpp プロジェクト: kkaempf/openwbem
void
CIMtoXML(CIMParameter const& cp, ostream& ostr)
{
	if (cp.getName().empty())
	{
		OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
			"parameter must have a name");
	}
	if (!cp.getType())
	{
		OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
			"parameter must have a valid data type");
	}
	bool isArray = cp.getType().isArrayType();
	if (cp.getType().isReferenceType())
	{
		//
		// Data type is a reference
		//
		String classref = cp.getType().getRefClassName();
		if (!classref.empty())
		{
			classref = "REFERENCECLASS=\"" + classref + "\"";
		}
		if (isArray)
		{
			if (cp.getType().getSize() == -1)
			{
				ostr
					<< "<PARAMETER.REFARRAY "
					<< classref
					<< " NAME=\""
					<< cp.getName()
					<< "\">";
				qualifierXML(cp, ostr);
				ostr << "</PARAMETER.REFARRAY>";
			}
			else
			{
				ostr
					<< "<PARAMETER.REFARRAY "
					<< classref
					<< " NAME=\""
					<< cp.getName()
					<< "\""
					<< " ARRAYSIZE=\""
					<< cp.getType().getSize()
					<< "\">";
				qualifierXML(cp, ostr);
				ostr << "</PARAMETER.REFARRAY>";
			}
		}
		else
		{
			ostr
				<< "<PARAMETER.REFERENCE "
				<< classref
				<< " NAME=\""
				<< cp.getName()
				<< "\">";
			qualifierXML(cp, ostr);
			ostr << "</PARAMETER.REFERENCE>";
		}
	}
	else
	{
		// Data type is not a ref
		if (isArray)
		{
			ostr << "<PARAMETER.ARRAY TYPE=\"";
			CIMtoXML(cp.getType(), ostr);
			ostr << "\" NAME=\"" << cp.getName();
			if (cp.getType().getSize() != -1)
			{
				ostr
					<< "\" ARRAYSIZE=\""
					<< cp.getType().getSize();
			}
			ostr << "\">";
			qualifierXML(cp, ostr);
			ostr << "</PARAMETER.ARRAY>";
		}
		else
		{
			ostr << "<PARAMETER TYPE=\"";
			CIMtoXML(cp.getType(), ostr);
			ostr
				<< "\"  NAME=\""
				<< cp.getName()
				<< "\">";
			qualifierXML(cp, ostr);
			ostr << "</PARAMETER>";
		}
	}
}