コード例 #1
0
ファイル: RepositoryMix.cpp プロジェクト: ncultra/Pegasus-2.5
void TestInitRepo()
{
  if (verbose) cout << ProgName << "-TestInitRepo()" << endl;

    try
    {
	r->createNameSpace(NS);
    }
    catch (AlreadyExistsException&)
    {
	// Ignore this!
    }

    // -- Declare the key qualifier:

    r->setQualifier(NS, CIMQualifierDecl(CIMName ("key"),true,CIMScope::PROPERTY));
    r->setQualifier(NS, CIMQualifierDecl(CIMName ("description"),String(),(CIMScope::PROPERTY + CIMScope::CLASS)));
    r->setQualifier(NS, CIMQualifierDecl(CIMName ("junk"),String(),(CIMScope::PROPERTY + CIMScope::CLASS)));



}
コード例 #2
0
CIMQualifierDecl compilerDeclContext::lookupQualifierDecl(
    const CIMNamespaceName &nameSpace,
     const CIMName &qualifierName) const
{
    const CIMQualifierDecl *pTheQualifier = 0;
    if (_ot != compilerCommonDefs::USE_REPOSITORY) {
        if ( (pTheQualifier =
                    _findQualifierInMemory(qualifierName)) )
            return *pTheQualifier;
    }
    if (_repository && (_ot != compilerCommonDefs::IGNORE_REPOSITORY)) {
        return _repository->_getQualifier(nameSpace, qualifierName);
    }
    return CIMQualifierDecl();
}
コード例 #3
0
ファイル: QualifierList.cpp プロジェクト: brunolauze/pegasus
int main(int, char** argv)
{
    Boolean verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false;
    try
    {
    const String NAMESPACE = "/zzz";

    // Create and populate a declaration context:

    SimpleDeclContext context;

    context.addQualifierDecl(NAMESPACE, CIMQualifierDecl
            (CIMName ("abstract"),
        false, CIMScope::CLASS, CIMFlavor::OVERRIDABLE));

    context.addQualifierDecl(NAMESPACE, CIMQualifierDecl
            (CIMName ("description"),
        String(), CIMScope::CLASS, CIMFlavor::OVERRIDABLE));

    context.addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName ("q1"),
        false, CIMScope::CLASS, CIMFlavor::OVERRIDABLE +
            CIMFlavor::TOSUBCLASS));

    context.addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName ("q2"),
        false, CIMScope::CLASS, CIMFlavor::TOSUBCLASS));

    // ATTN: KS P1 29 Mar 2002 - Add Tests for Null Value

    // ATTN: KS P1 29 Mar 2002 - Add tests for array values in Qualifier.

    // Create qualifier list 1:

    CIMQualifierList qualifiers0;
    CIMQualifierList qualifiers1;

    qualifiers1
        .add(CIMQualifier(CIMName ("Abstract"), true))
        .add(CIMQualifier(CIMName ("Description"),
                String("CIMQualifier List 1")))
        .add(CIMQualifier(CIMName ("q1"), false))
        .add(CIMQualifier(CIMName ("q2"), false));

    // Run the find, get, etc tests.

    PEGASUS_TEST_ASSERT(qualifiers1.getCount() == 4);
    PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("Abstract")) == 0);
    PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("Abstract")));
    PEGASUS_TEST_ASSERT(qualifiers1.isTrue(CIMName ("Abstract")));
    PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q1")));
    PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q1")));
    PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q2")));
    PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q2")));

    PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("QualifierDoesNotExist")) ==
            PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(!qualifiers1.exists(CIMName("QualifierDoesNotExist")));

    qualifiers1.resolve(
        &context, NAMESPACE, CIMScope::CLASS, false, qualifiers0, true);

    // Qualifiers after the resolve.  Should have resolved against the
    // declarations.
    PEGASUS_TEST_ASSERT(qualifiers1.getCount() == 4);
    PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("Abstract")) == 0);
    PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("Abstract")));
    PEGASUS_TEST_ASSERT(qualifiers1.isTrue(CIMName ("Abstract")));
    PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q1")));
    PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q1")));
    PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q2")));
    PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q2")));

    PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("QualifierDoesNotExist")) ==
            PEG_NOT_FOUND);
    PEGASUS_TEST_ASSERT(!qualifiers1.exists(CIMName("QualifierDoesNotExist")));
    if(verbose)
        qualifiers1.print();


    // Add test for double add of a name
    Boolean exceptionCaught = false;
    try
    {
        qualifiers1.add(CIMQualifier(CIMName ("Abstract"), true));
    }
    catch (Exception&)
    {
        exceptionCaught = true;
    }
    PEGASUS_TEST_ASSERT(exceptionCaught);

    // Test some of the basics again after the double insertion problem
    PEGASUS_TEST_ASSERT(qualifiers1.getCount() == 4);
    PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("Abstract")) == 0);
    PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("Abstract")));
    PEGASUS_TEST_ASSERT(qualifiers1.isTrue(CIMName ("Abstract")));

    // Create qualifier list 2: Will be resolved against qualifiers1

    CIMQualifierList qualifiers2;

    qualifiers2
        .add(CIMQualifier(CIMName ("Description"),
                String("CIMQualifier List 1")))
        .add(CIMQualifier(CIMName ("q1"), Boolean(true),
                CIMFlavor::OVERRIDABLE));

    if(verbose)
        qualifiers2.print();

    PEGASUS_TEST_ASSERT(qualifiers2.getCount() == 2);
    PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("Description")));
    PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("q1")));
    PEGASUS_TEST_ASSERT(qualifiers2.isTrue(CIMName ("q1")));

    // Resolve the qualifiers against the previous list qualifiers1
    qualifiers2.resolve(
        &context, NAMESPACE, CIMScope::CLASS, false, qualifiers1, true);

    if(verbose)
        qualifiers2.print();

    // Post resolution
    PEGASUS_TEST_ASSERT(qualifiers2.getCount() == 4);
    PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("Description")));
    PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("abstract")));
    PEGASUS_TEST_ASSERT(qualifiers2.isTrue(CIMName ("abstract")));


    PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("q1")));
    PEGASUS_TEST_ASSERT(qualifiers2.isTrue(CIMName ("q1")));

    PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("q2")));
    // Should inherit the value from the superclass
    PEGASUS_TEST_ASSERT(!qualifiers2.isTrue(CIMName ("q2")));

    }
    catch (Exception& e)
    {
        cerr << "Exception: " << e.getMessage() << endl;
        exit(1);
    }

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

    return 0;
}
コード例 #4
0
ファイル: Value.cpp プロジェクト: rdobson/openpegasus
int main(int argc, char** argv)
{
#ifdef IO
    verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false;
    if (verbose)
    cout << "Test CIMValue. To turn off display, compile with IO undefined\n";
#endif
    // Test the primitive CIMValue types with test01
    test01(Boolean(true));
    test01(Boolean(false));
    test01(Char16('Z'));
    test01(Uint8(77));
    test01(Sint8(-77));
    test01(Sint16(77));
    test01(Uint16(-77));
    test01(Sint32(77));
    test01(Uint32(-77));
    test01(Sint64(77));
    test01(Uint64(-77));
    test01(Real32(1.5));
    test01(Real64(55.5));
    test01(Uint64(123456789));
    test01(Sint64(-123456789));
    test01(String("Hello world"));
    test01(CIMDateTime("19991224120000.000000+360"));
    test01(CIMObjectPath(
        "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\""));

    // Create and populate a declaration context:

    const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/zzz");

    SimpleDeclContext* context = new SimpleDeclContext;

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("counter"), false,
        CIMScope::PROPERTY));

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("classcounter"), false,
        CIMScope::CLASS));

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("min"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(
    NAMESPACE, CIMQualifierDecl(CIMName ("max"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(NAMESPACE,
    CIMQualifierDecl(CIMName ("Description"), String(),
        CIMScope::PROPERTY));

    CIMClass class1(CIMName ("MyClass"));

    class1
    .addProperty(CIMProperty(CIMName ("count"), Uint32(55))
        .addQualifier(CIMQualifier(CIMName ("counter"), true))
        .addQualifier(CIMQualifier(CIMName ("min"), String("0")))
        .addQualifier(CIMQualifier(CIMName ("max"), String("1"))))
    .addProperty(CIMProperty(CIMName ("message"), String("Hello"))
        .addQualifier(CIMQualifier(CIMName ("description"),
                String("My Message"))))
    .addProperty(CIMProperty(CIMName ("ratio"), Real32(1.5)));

    Resolver::resolveClass (class1, context, NAMESPACE);
    context->addClass(NAMESPACE, class1);

    // Test a CIMObject that is a CIMClass
    test01(CIMObject(class1));

    // Test a CIMObject that is a CIMInstance
    CIMInstance instance1(CIMName ("MyClass"));
    instance1.addQualifier(CIMQualifier(CIMName ("classcounter"), true));
    instance1.addProperty(CIMProperty(CIMName ("message"), String("Goodbye")));

    Resolver::resolveInstance (instance1, context, NAMESPACE, true);

    test01(CIMObject(instance1));

    testEmbeddedValue<CIMObject>(instance1);
    testEmbeddedValue<CIMInstance>(instance1);

    // Test CIMValue arrays

    Array<Uint8> arr1;
    arr1.append(11);
    arr1.append(22);
    arr1.append(23);
    test02(arr1);

    Array<Uint16> arr2;
    arr2.append(333);
    arr2.append(444);
    arr2.append(445);
    test02(arr2);

    Array<Uint32> arr3;
    arr3.append(5555);
    arr3.append(6666);
    arr3.append(6667);
    test02(arr3);

    Array<Uint64> arr4;
    arr4.append(123456789);
    arr4.append(987654321);
    arr4.append(987654322);
    test02(arr4);

    Array<Sint8> arr5;
    arr5.append(-11);
    arr5.append(-22);
    arr5.append(-23);
    test02(arr5);

    Array<Sint16> arr6;
    arr6.append(333);
    arr6.append(444);
    arr6.append(555);
    test02(arr6);

    Array<Sint32> arr7;
    arr7.append(555);
    arr7.append(666);
    arr7.append(777);
    test02(arr7);

    Array<Sint64> arr8;
    arr8.append(-123456789);
    arr8.append(-987654321);
    arr8.append(-987654321);
    test02(arr8);

    Array<Boolean> arr9;
    arr9.append(true);
    arr9.append(false);
    arr9.append(false);
    test02(arr9);

    Array<Real32> arr10;
    arr10.append(1.55F);
    arr10.append(2.66F);
    arr10.append(3.77F);
    test02(arr10);

    Array<Real64> arr11;
    arr11.append(55.55);
    arr11.append(66.66);
    arr11.append(77.77);
    test02(arr11);

    Array<Char16> arr12;
    arr12.append('X');
    arr12.append('Y');
    arr12.append('Z');
    test02(arr12);

    Array<String> arr13;
    arr13.append("One");
    arr13.append("Two");
    arr13.append("Three");
    test02(arr13);

    Array<CIMDateTime> arr14;
    arr14.append(CIMDateTime ("20020130120000.000000+360"));
    arr14.append(CIMDateTime ("20020201120000.000000+360"));
    arr14.append(CIMDateTime ("20020202120000.000000+360"));
    test02(arr14);

    Array<CIMObjectPath> arr15;
    arr15.append(CIMObjectPath(
        "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\""));
    arr15.append(CIMObjectPath(
        "//host2:88/root/static:Class2.keyA=\"keyAValue\",keyB="
                "\"keyBValue\""));
    arr15.append(CIMObjectPath(
        "//host3:99/root/test/static:Class3.keyX=\"keyXValue\","
                "keyY=\"keyYValue\""));
    test02(arr15);

    testEmbeddedValueArray<CIMObject>(instance1, NAMESPACE, context);
    testEmbeddedValueArray<CIMInstance>(instance1, NAMESPACE, context);

    // Calling remaining  Array tests..
    CIMDateTime D1("19991224120000.000000+100");
    Array<CIMDateTime> arrD1(10,D1);
    CIMDateTime *D2 = new CIMDateTime("19991224120000.000000+100");
    Array<CIMDateTime> arrD2(D2,1);
    test03(arrD1, arrD2, D2, CIMDateTime("19991224120000.000000+100"),
                     CIMDateTime("29991224120000.000000+100"));
    delete D2;

    CIMName cimname1("yourName");
    Array<CIMName> arrcimname1(10,cimname1);
    CIMName *cimname2 = new CIMName("yourName");
    Array<CIMName> arrcimname2(cimname2,1);
    test03(arrcimname1, arrcimname2, cimname2, CIMName("yourName"),
            CIMName("myName"));
    delete cimname2;

    CIMKeyBinding cimbind1(cimname1, "myKey", CIMKeyBinding::STRING);
    CIMKeyBinding cimbind2(cimname1, "yourKey", CIMKeyBinding::STRING);
    Array<CIMKeyBinding> arrcimbind1(10,cimbind1);
    CIMKeyBinding *cimbind3 =
        new CIMKeyBinding(cimname1, "myKey", CIMKeyBinding::STRING);
    Array<CIMKeyBinding> arrcimbind2(cimbind3,1);
    test03(arrcimbind1, arrcimbind2, cimbind3, cimbind1, cimbind2 );
    delete cimbind3;

    CIMNamespaceName cimnamespace1("root/SampleProvider");
    Array<CIMNamespaceName> arrcimnamespace1(10,cimnamespace1);
    CIMNamespaceName *cimnamespace2 = new CIMNamespaceName(
            "root/SampleProvider");
    Array<CIMNamespaceName> arrcimnamespace2(cimnamespace2,1);
    test03(arrcimnamespace1, arrcimnamespace2, cimnamespace2,
            CIMNamespaceName("root/SampleProvider"),
            CIMNamespaceName("root/SampleProvider2"));
    delete cimnamespace2;

    Array<Boolean> arrB1(10,true);
    Boolean *b = new Boolean(true);
    Array<Boolean> arrB2(b,1);
    Array<Boolean> arrB3(2);
    Boolean b1 = true, b2=false;
    test03(arrB1, arrB2, b, Boolean(true),Boolean(false));
    delete b;

    Array<Real32> arrreal321(10);
    Real32 creal321(2.5);
    Array<Real32> arrreal322(10, creal321);
    Real32 *creal322 = new Real32(2.5);
    Array<Real32> arrreal323(creal322,1);
    Array<Real32> arrreal324(arrreal321);
    test03(arrreal322, arrreal323, creal322,Real32(2.5),Real32(3.5));
    delete creal322;

    Array<Real64> arrreal641(10);
    Real64 creal641(20000.54321);
    Array<Real64> arrreal642(10, creal641);
    Real64 *creal642 = new Real64(20000.54321);
    Array<Real64> arrreal643(creal642,1);
    Array<Real64> arrreal644(arrreal641);
    test03(arrreal642, arrreal643, creal642,Real64(20000.54321),
            Real64(30000.54321));
    delete creal642;

    Array<Sint16> arrSint161(10);
    Sint16 cSint161(-2000);
    Array<Sint16> arrSint162(10, cSint161);
    Sint16 *cSint162 = new Sint16(-2000);
    Array<Sint16> arrSint163(cSint162,1);
    Array<Sint16> arrSint164(arrSint161);
    test03(arrSint162, arrSint163, cSint162, Sint16(-2000), Sint16(-3000));
    delete cSint162;

    Array<Sint32> arrSint321(10);
    Sint32 cSint321(-200000000);
    Array<Sint32> arrSint322(10, cSint321);
    Sint32 *cSint322 = new Sint32(-200000000);
    Array<Sint32> arrSint323(cSint322,1);
    Array<Sint32> arrSint324(arrSint321);
    test03(arrSint322, arrSint323, cSint322, Sint32(-200000000),
            Sint32(-300000000));
    delete cSint322;

    Array<Sint64> arrSint641(10);
    Sint64 cSint641(Sint64(-2000000)*Sint64(10000000) );
    Array<Sint64> arrSint642(10, cSint641);
    Sint64 *cSint642 = new Sint64(Sint64(-2000000)*Sint64(10000000));
    Array<Sint64> arrSint643(cSint642,1);
    Array<Sint64> arrSint644(arrSint641);
    test03(arrSint642, arrSint643, cSint642,Sint64(-2000000)*Sint64(10000000),
                           Sint64(-3000000)*Sint64(10000000));
    delete cSint642;

    Array<Sint8> arrSint81(10);
    Sint8 cSint81(-20);
    Array<Sint8> arrSint82(10, cSint81);
    Sint8 *cSint82 = new Sint8(-20);
    Array<Sint8> arrSint83(cSint82,1);
    Array<Sint8> arrSint84(arrSint81);
    test03(arrSint82, arrSint83, cSint82, Sint8(-20), Sint8(-22));
    delete cSint82;

    Array<Uint16> arrUint161(10);
    Uint16 cUint161(200);
    Array<Uint16> arrUint162(10, cUint161);
    Uint16 *cUint162 = new Uint16(200);
    Array<Uint16> arrUint163(cUint162,1);
    Array<Uint16> arrUint164(arrUint161);
    test03(arrUint162, arrUint163, cUint162, Uint16(200), Uint16(255));
    delete cUint162;

    Array<Uint32> arrUint321(10);
    Uint32 cUint321(2000);
    Array<Uint32> arrUint322(10, cUint321);
    Uint32 *cUint322 = new Uint32(2000);
    Array<Uint32> arrUint323(cUint322,1);
    Array<Uint32> arrUint324(arrUint321);
    test03(arrUint322, arrUint323, cUint322, Uint32(2000), Uint32(3000));
    delete cUint322;

    Array<Uint64> arrUint641(10);
    Uint64 cUint641(Uint64(2000000)*Uint64(10000000));
    Array<Uint64> arrUint642(10, cUint641);
    Uint64 *cUint642 = new Uint64(Uint64(2000000)*Uint64(10000000));
    Array<Uint64> arrUint643(cUint642,1);
    Array<Uint64> arrUint644(arrUint641);
    test03(arrUint642, arrUint643, cUint642,Uint64(2000000)*Uint64(10000000),
                           Uint64(255000)*Uint64(10000000));
    delete cUint642;

    Array<Uint8> arrUint81(10);
    Uint8 cUint81(200);
    Array<Uint8> arrUint82(10, cUint81);
    Uint8 *cUint82 = new Uint8(200);
    Array<Uint8> arrUint83(cUint82,1);
    Array<Uint8> arrUint84(arrUint81);
    test03(arrUint82, arrUint83, cUint82, Uint8(200), Uint8(255));
    delete cUint82;

    Array<Char16> arrChar161(10);
    Char16 cChar161('Z');
    Array<Char16> arrChar162(10, cChar161);
    Char16 *cChar162 = new Char16('Z');
    Array<Char16> arrChar163(cChar162,1);
    Array<Char16> arrChar164(arrChar161);
    test03(arrChar162, arrChar163, cChar162, Char16('Z'), Char16('z'));
    delete cChar162;
    delete context;

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

    return 0;
}
コード例 #5
0
CIMQualifierDecl CIMConstQualifierDecl::clone() const
{
    return CIMQualifierDecl(_rep->clone());
}
コード例 #6
0
ファイル: InstanceDecl.cpp プロジェクト: ncultra/Pegasus-2.5
void test01()
{
    const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz");

    // Create and populate a declaration context:

    SimpleDeclContext* context = new SimpleDeclContext;

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("counter"), false,
        CIMScope::PROPERTY));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("classcounter"), false,
        CIMScope::CLASS));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("min"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("max"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(NAMESPACE,
        CIMQualifierDecl(CIMName("Description"), String(),
        CIMScope::PROPERTY));

    CIMClass class1(CIMName("MyClass"));

    class1
        .addProperty(CIMProperty(CIMName("count"), Uint32(55))
            .addQualifier(CIMQualifier(CIMName("counter"), true))
            .addQualifier(CIMQualifier(CIMName("min"), String("0")))
            .addQualifier(CIMQualifier(CIMName("max"), String("1"))))
        .addProperty(CIMProperty(CIMName("message"), String("Hello"))
            .addQualifier(CIMQualifier(CIMName("description"),
                String("My Message"))))
        .addProperty(CIMProperty(CIMName("ratio"), Real32(1.5)));

    // Test
    assert(class1.findProperty(CIMName("count")) != PEG_NOT_FOUND);
    assert(class1.findProperty(CIMName("message")) != PEG_NOT_FOUND);
    assert(class1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND);

    Resolver::resolveClass(class1, context, NAMESPACE);
    context->addClass(NAMESPACE, class1);

    if (verbose)
    {
        XmlWriter::printClassElement(class1);
    }

    CIMInstance instance0(CIMName("MyClass"));
    assert(instance0.getClassName().equal(CIMName("MyClass")));
    instance0.setPath(CIMObjectPath("//localhost/root/cimv2:MyClass.Foo=1"));
    assert(instance0.getPath() ==
        CIMObjectPath("//localhost/root/cimv2:MyClass.Foo=1"));

    CIMInstance instance1(CIMName("MyClass"));
    instance1.addQualifier(CIMQualifier(CIMName("classcounter"), true));

    instance1.addProperty(CIMProperty(CIMName("message"), String("Goodbye")));

    assert(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);

    assert(instance1.findProperty(CIMName("count")) == PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("ratio")) == PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND);
    assert(instance1.getPropertyCount() == 1);

    if (verbose)
    {
        XmlWriter::printInstanceElement(instance1);
    }

    Resolver::resolveInstance(instance1, context, NAMESPACE, true);

    if (verbose)
    {
        XmlWriter::printInstanceElement(instance1);
    }

    // Now test for properties after resolution.

    assert(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("count")) != PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND);
    assert(instance1.getPropertyCount() == 3);

    // Now remove a property

    Uint32 posProperty;
    posProperty = instance1.findProperty(CIMName("count"));
    instance1.removeProperty(posProperty);

    assert(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("count")) == PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND);
    assert(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND);

    assert(instance1.getPropertyCount() == 2);

    // Instance qualifier tests

    CIMQualifier cq=instance1.getQualifier(instance1.findQualifier(
        CIMName("classcounter")));

    const CIMInstance instance2 = instance1.clone();
    assert(instance2.identical(instance1));
    assert(instance1.findQualifier(CIMName("nuts")) == PEG_NOT_FOUND);
    assert(instance2.findQualifier(CIMName("nuts")) == PEG_NOT_FOUND);
    assert(instance1.getQualifierCount() != 4);
    assert(instance1.getQualifierCount() == 1);
    assert(instance2.getQualifierCount() == 1);

    if (verbose)
    {
        XmlWriter::printInstanceElement(instance2);
    }

    // Tests for CIMConstInstance
    CIMConstInstance cinstance1(CIMName("MyClass")), cinstance3;
    CIMConstInstance ccopy(cinstance1);

    cinstance1 = instance1;
    assert(cinstance1.identical(instance1));

    assert(cinstance1.getQualifierCount() == 1);
    CIMConstQualifier ccq = cinstance1.getQualifier(cinstance1.findQualifier(
        CIMName("classcounter")));
    assert(cinstance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);
    CIMConstProperty ccp =
        cinstance1.getProperty(cinstance1.findProperty(CIMName("message")));

    cinstance3 = cinstance1;
    assert(cinstance3.identical(cinstance1));

    assert(cinstance1.getClassName() == CIMName("MyClass"));
    assert(cinstance1.getClassName().equal(CIMName("MyClass")));
    assert(cinstance1.getClassName().equal(CIMName("MYCLASS")));
    assert(cinstance1.getClassName().equal(CIMName("myclass")));
    assert(!cinstance1.getClassName().equal(CIMName("blob")));

    assert(cinstance1.getQualifierCount() != 4);
    assert(cinstance1.getPropertyCount() == 2);

    CIMConstInstance cinstance2 = cinstance1.clone();
    assert(cinstance2.identical(cinstance1));

    if (verbose)
    {
        XmlWriter::printInstanceElement(cinstance1);
    }

    cinstance1.buildPath(class1);

    assert( !cinstance1.isUninitialized() );

    delete context;
}
コード例 #7
0
ファイル: InstanceDecl.cpp プロジェクト: ncultra/Pegasus-2.5
//
// Test of the Instance creation and instance filtering
//
void test04()
{
    if (verbose)
    {
        cout << "Test04 - Create instance from Class. " << endl;
    }

    const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz");

    // Create and populate a declaration context:

    SimpleDeclContext* context = new SimpleDeclContext;

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("counter"), false,
        CIMScope::PROPERTY));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("classcounter"), false,
        CIMScope::CLASS));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("min"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("max"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(NAMESPACE,
        CIMQualifierDecl(CIMName("Description"), String(),
        CIMScope::PROPERTY));

    CIMClass class1(CIMName("MyClass"));

    class1
        .addProperty(CIMProperty(CIMName("count"), Uint32(55))
            .addQualifier(CIMQualifier(CIMName("counter"), true))
            .addQualifier(CIMQualifier(CIMName("min"), String("0")))
            .addQualifier(CIMQualifier(CIMName("max"), String("1"))))
        .addProperty(CIMProperty(CIMName("message"), String("Hello"))
            .addQualifier(CIMQualifier(CIMName("description"),
                String("My Message"))))
        .addProperty(CIMProperty(CIMName("ratio"), Real32(1.5)));


    Resolver::resolveClass(class1, context, NAMESPACE);
    context->addClass(NAMESPACE, class1);


    if (verbose)
    {
        XmlWriter::printClassElement(class1);
    }

    //
    // Create instance with qualifiers, classorigin, and Null propertyList
    //
    {
        CIMInstance newInstance;

        newInstance = class1.buildInstance(true, true, CIMPropertyList());

        if (verbose)
        {
            XmlWriter::printInstanceElement(newInstance);
        }

        assert(newInstance.getPropertyCount() == class1.getPropertyCount());
        assert(newInstance.getQualifierCount() == class1.getQualifierCount());
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") != PEG_NOT_FOUND);

    }

    //
    // Test with include qualifiers false. Should be no qualifiers in result
    //
    {
        CIMInstance newInstance =
            class1.buildInstance(false, true, CIMPropertyList());

        assert(newInstance.getQualifierCount() == 0);
        assert(newInstance.getPropertyCount() == class1.getPropertyCount());
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") != PEG_NOT_FOUND);
    }

    //
    // Test with empty property list.  Should have no properties.
    //
    {
        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);

        CIMInstance newInstance = class1.buildInstance(false, true, pl1);

        assert(newInstance.getQualifierCount() == 0);
        assert(newInstance.getPropertyCount() == 0);
    }

    //
    // Test with a property that exists in property list.
    //
    {
        Array<CIMName> pl1Array;
        pl1Array.append("ratio");
        CIMPropertyList pl1(pl1Array);

        CIMInstance newInstance = class1.buildInstance(false, true, pl1);

        if (verbose)
        {
            cout << "Test with one property in new instance" << endl;
            XmlWriter::printInstanceElement(newInstance);
        }

        assert(newInstance.getPropertyCount() == 1);
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") == PEG_NOT_FOUND);
        assert(newInstance.getQualifierCount() == 0);
    }

    //
    // Test with a property that does/does not exist in property list
    //
    {
        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);
        pl1.clear();
        pl1Array.append("blob");
        pl1Array.append("ratio");
        pl1.set(pl1Array);

        CIMInstance newInstance = class1.buildInstance(false, true, pl1);

        assert(newInstance.getPropertyCount() == 1);
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("blob") == PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") == PEG_NOT_FOUND);
        assert(newInstance.getQualifierCount() == 0);
    }

    ///////////////////////////////////////////////////////////////////////
    //
    // Instance Filtering function tests
    //
    ///////////////////////////////////////////////////////////////////////

    // build instance as starting point for tests.
    CIMInstance tstInstance =
        class1.buildInstance(true, true, CIMPropertyList());

    //
    // Test complete copy, no change
    //
    {
        if (verbose)
        {
            cout << "Test1" << endl;
        }

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, CIMPropertyList());

        assert(tstInstance.identical(filterInstance));
        assert(filterInstance.getPropertyCount() == 3);
        assert(filterInstance.getQualifierCount() ==
            tstInstance.getQualifierCount());
    }

    //
    // Filter to one property, ratio
    //
    {
        if (verbose)
        {
            cout << "Test2" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("ratio");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        if (verbose)
        {
            XmlWriter::printInstanceElement(filterInstance);
        }

        assert(filterInstance.getPropertyCount() == 1);
        assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(_propertyIdentical("ratio", filterInstance, tstInstance));
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to one property, message
    //
    {
        if (verbose)
        {
            cout << "Test3" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("message");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        if (verbose)
        {
            XmlWriter::printInstanceElement(filterInstance);
        }

        assert(filterInstance.getPropertyCount() == 1);
        assert(filterInstance.findProperty("message") != PEG_NOT_FOUND);
        assert(_propertyIdentical("message", filterInstance, tstInstance));
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to one property, count
    //
    {
        if (verbose)
        {
            cout << "Test4" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("count");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        if (verbose)
        {
            XmlWriter::printInstanceElement(filterInstance);
        }

        assert(filterInstance.getPropertyCount() == 1);
        assert(filterInstance.findProperty("count") != PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to no properties
    //
    {
        if (verbose)
        {
            cout << "Test5a" << endl;
        }

        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        assert(filterInstance.getPropertyCount() == 0);
        assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() ==
            tstInstance.getQualifierCount());
    }

    //
    // Filter to two properties
    //
    {
        if (verbose)
        {
            cout << "Test5b" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("count");
        pl1Array.append("message");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        assert(filterInstance.getPropertyCount() == 2);
        assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND);
        assert(filterInstance.findProperty("message") != PEG_NOT_FOUND);
        assert(_propertyIdentical("message", filterInstance, tstInstance));
        assert(filterInstance.findProperty("count") != PEG_NOT_FOUND);
        assert(_propertyIdentical("count", filterInstance, tstInstance));
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to no qualifiers and all properties.
    //
    {
        if (verbose)
        {
            cout << "Test6" << endl;
        }

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(false, true, CIMPropertyList());

        assert(filterInstance.getPropertyCount() == 3);
        assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() == 0);
        for (Uint32 i = 0; i < filterInstance.getPropertyCount() ; i++)
        {
            CIMConstProperty p = filterInstance.getProperty(i);
            assert(p.getQualifierCount() == 0);
        }
    }

    //
    // Filter to no qualifiers and no properties.
    //
    {
        if (verbose)
        {
            cout << "Test6a" << endl;
        }

        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(false, true, pl1);

        assert(filterInstance.getPropertyCount() == 0);
        assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() == 0);
    }

    //
    // Test Class Origin Filter
    //
    {
        if (verbose)
        {
            cout << "Test7 Class Origin" << endl;
        }

        // Create a subclass to do classOrigin testing
        CIMClass mySubClass(CIMName("subclass"));
        mySubClass.setSuperClassName(CIMName("MyClass"));

        Resolver::resolveClass(mySubClass, context, NAMESPACE);
        context->addClass(NAMESPACE, mySubClass);

        // build instance
        CIMInstance filterInstance =
            mySubClass.buildInstance(true, true, CIMPropertyList());
        filterInstance.filter(false, true, CIMPropertyList());

        assert(filterInstance.getPropertyCount() == 3);
        assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() == 0);
        for (Uint32 i = 0 ; i < filterInstance.getPropertyCount() ; i++)
        {
            CIMProperty p = filterInstance.getProperty(i);
            assert(!(p.getClassOrigin() == CIMName()));

        }
        filterInstance.filter(false, false, CIMPropertyList());

        for (Uint32 i = 0 ; i < filterInstance.getPropertyCount() ; i++)
        {
            CIMProperty p = filterInstance.getProperty(i);
            assert(p.getClassOrigin() == CIMName());
        }

        CIMInstance filterInstance2 =
            mySubClass.buildInstance(true, false, CIMPropertyList());

        for (Uint32 i = 0 ; i < filterInstance2.getPropertyCount() ; i++)
        {
            CIMProperty p = filterInstance2.getProperty(i);
            assert(p.getClassOrigin() == CIMName());
        }
    }
    delete context;
}