Beispiel #1
0
static CIMPropertyList getList(const char** l) {
  CIMPropertyList pl;
  if (l) {
    Array<CIMName> n;
    while (*l) {
      n.append(*l++);
    }
    pl.set(n);
  }
  return pl;
}
CIMPropertyList WQLSelectStatementRep::getPropertyList(
        const CIMObjectPath& inClassName)
{
    if(_ctx == NULL){
        MessageLoaderParms parms(
            "WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
            "Trying to process a query with a NULL Query Context.");
      throw QueryRuntimeException(parms);
    }

    if(_allProperties)
     return CIMPropertyList();

    CIMName className = inClassName.getClassName();
    if (className.isNull())
    {
     // If the caller passed in an empty className, then the
     // FROM class is to be used.
     className = _className;
    }

    // check if inClassName is the From class
    if(!(className == _className)){
        // check if inClassName is a subclass of the From class
        if(!_ctx->isSubClass(_className,className)){
            MessageLoaderParms parms(
                "WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",
                "Class $0 does not match the FROM class or any of its"
                    " subclasses.",
                className.getString());
            throw QueryRuntimeException(parms);
        }
    }

    Array<CIMName> names =
            getWherePropertyList(inClassName).getPropertyNameArray();
    Array<CIMName> selectList =
            getSelectPropertyList(inClassName).getPropertyNameArray();

    // check for duplicates and remove them
    for(Uint32 i = 0; i < names.size(); i++){
        for(Uint32 j = 0; j < selectList.size(); j++){
            if(names[i] == selectList[j])
                selectList.remove(j);
            }
    }

    names.appendArray(selectList);
    CIMPropertyList list = CIMPropertyList();
    list.set(names);
    return list;
}
// ===========================================================================
// Main
// Options:
//  Test or show - TBD
// ===========================================================================
int main()
{
    //verbose = getenv("PEGASUS_TEST_VERBOSE");
    verbose = "test";
    cout << "+++++ Testing AssociationTest Provider" << endl;

    // Build array of classes
    Array<CIMName> Classes;
    Classes.append("TST_ClassA");
    Classes.append("TST_ClassB");
    Classes.append("TST_ClassC");
    Classes.append("TST_ClassD");
    Classes.append("TSTDY_ClassA");
    Classes.append("TSTDY_ClassB");
    Classes.append("TSTDY_ClassC");
    Classes.append("TSTDY_ClassD");

    Array<CIMName> AssocClasses;
    AssocClasses.append("TST_AssocI1");
    AssocClasses.append("TST_AssocI2");
    AssocClasses.append("TST_AssocI3");
    AssocClasses.append("TST_AssocI4");
    AssocClasses.append("TST_AssocI5");
    AssocClasses.append("TST_AssocI6");

    AssocClasses.append("TST_AssocNI1");
    AssocClasses.append("TST_AssocNI2");
    AssocClasses.append("TST_AssocNI3");
    AssocClasses.append("TST_AssocNI4");
    AssocClasses.append("TST_AssocNI5");
    AssocClasses.append("TST_AssocNI6");

    // Connect
    try
    {
        c.connect (HOST, PORTNUMBER, String::EMPTY, String::EMPTY);
    }
    catch (Exception& e)
    {
        errorExit(e);
    }

    int rc;
    // Start by confirming the existence of the classes, etc.
    if ((rc = testClassList(Classes)) != 0) return rc;
    if ((rc = testClassList(AssocClasses)) != 0) return rc;
    // Now start the association tests.
    // Reference Names Test

    // Class A Refrence Names Test

    ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"), CIMName(), "", 2));
    ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"), CIMName(), "to", 2));
    ASRT(testReferenceNames(CIMObjectPath("TST_ClassA"), CIMName(), "from", 2));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI1"), "", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI1"), "to", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI1"), "from", 1));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI3"), "", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI3"), "to", 0));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI3"), "from", 1));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI5"), "", 0));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI5"), "to", 0));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA"), CIMName("TST_AssocI5"), "from", 0));

    // Class B Refrence Names Test
    ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"), CIMName(), "", 4));
    ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"), CIMName(), "to", 2));
    ASRT(testReferenceNames(CIMObjectPath("TST_ClassB"), CIMName(), "from", 4));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "to", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "from", 1));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "to", 0));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI2"), "from", 1));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI5"), "", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI5"), "to", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassB"), CIMName("TST_AssocI5"), "from", 1));

    // TODO TestReferences for class c and class d

    // testRefernceName Instances from static store
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName(), "", 2));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName(), "to", 2));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""), CIMName(), "from", 2));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI1"), "", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI1"), "to", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI1"), "from", 1));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI3"), "", 1));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI3"), "to", 0));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI3"), "from", 1));

    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI5"), "", 0));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI5"), "to", 0));
    ASRT(testReferenceNames(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName("TST_AssocI5"), "from", 0));

    // Lets make the previous a common test between ref and ref names.

    // References
    // Limited test since we learned most in the previous test of reference
    // names
    CIMPropertyList NullPL;

    CIMPropertyList emptyPL;

    CIMPropertyList fullPL;
    Array<CIMName> fullPLinput;
    fullPLinput.append("name");
    fullPL.set(fullPLinput);


    CIMPropertyList errorPL;
    Array<CIMName> errorPLinput;
    errorPLinput.append("junk");
    errorPL.set(errorPLinput);

    ASRT(testReferences(CIMObjectPath("TST_ClassA"), CIMName(), "", emptyPL,2));

    ASRT(testReferences(
        CIMObjectPath("TST_ClassA.name=\"InstanceA1\""),
        CIMName(), "", fullPL,2));

    // Testing associators and and associator names functions.

    ASRT(testAssocNames(
        CIMObjectPath("TST_ClassA"), CIMName(), CIMName(), "", "", 3));

    cout << "+++++ passed all tests" << endl;
    return 0;
}