void drive_RepositoryQueryContext()
{
    // get the configuration variable PEGASUS_HOME
    const char* peg_home = getenv("PEGASUS_HOME");
    if (peg_home == NULL)
    {
        cout << "PEGASUS_HOME needs to be set to run this test." << endl;
        exit(-1);
    }
    String repositoryDir(peg_home);
    repositoryDir.append("/");

    // get the makefile build config variable REPOSITORY_NAME
    const char* repo_name = getenv("REPOSITORY_NAME");
    if (repo_name == NULL)
        repositoryDir.append("repository");
    else
        repositoryDir.append(repo_name);

    CIMNamespaceName _ns("root/SampleProvider");
    CIMRepository _rep(repositoryDir);
    RepositoryQueryContext _queryOrig(_ns, &_rep);

    RepositoryQueryContext _query = _queryOrig;

    PEGASUS_TEST_ASSERT(_query.getNamespace() == _ns);

    drive_FromList(_query);
    drive_WhereIds(_query);
    drive_Schema(_query);
}
Ejemplo n.º 2
0
void drive_resolve_specialChars()
{


    const char* env = getenv("PEGASUS_HOME");
    String repositoryDir(env);
    repositoryDir.append("/repository");
    //String repositoryDir("c:/pegasus-cvs/pegasus/repository");
    CIMNamespaceName _ns("root/cimv2");
    CIMRepository *_rep = new CIMRepository(repositoryDir);
    RepositoryQueryContext _query(_ns, _rep);
    RepositoryQueryContext _query1(_ns, _rep);
    try {
        const CQLIdentifier _Id1(String("CIM_OperatingSystem"));

        _query.insertClassPath(_Id1);

        const CIMName _cimName(String("CIM_OperatingSystem"));

        CIMInstance _i1(_cimName);
        CIMProperty _p1(CIMName("OSType"),CIMValue(Uint16(11)));
        CIMProperty _p2(CIMName("Status"),CIMValue(String("Degraded")));
        Array<Uint16> array16;
        array16.append(Uint16(0));
        array16.append(Uint16(1));
        array16.append(Uint16(2));
        array16.append(Uint16(3));
        CIMProperty _p3(CIMName("OperationalStatus"),CIMValue(array16));

        _i1.addProperty(_p1);
        _i1.addProperty(_p2);
        _i1.addProperty(_p3);

        CQLChainedIdentifier ci1(String("CIM_OperatingSystem.OSType#OS400"));
        CQLChainedIdentifier ci2(String("CIM_OperatingSystem.OSType#LINUX"));
        CQLChainedIdentifier ci3(String("CIM_OperatingSystem.Status#Degraded"));

        CQLChainedIdentifier ci5(String("CIM_OperatingSystem.Status#BOGUS"));

        CQLChainedIdentifier ci6(
            String("CIM_OperatingSystem.CIM_OperatingSystem::"
                   "OperationalStatus[2]"));
        CQLValue a1(ci1);
        CQLValue a2(ci2);
        CQLValue a3(ci3);

        CQLValue a5(ci5);
        CQLValue a6(ci6);


        a1.resolve(_i1, _query);
        a2.resolve(_i1, _query);

        a6.resolve(_i1, _query);

        try
        {
            a3.resolve(_i1, _query);
            PEGASUS_TEST_ASSERT(0);
        }
        catch(...)
        {
            PEGASUS_TEST_ASSERT(1);
        }

        try
        {
            a5.resolve(_i1, _query);
            PEGASUS_TEST_ASSERT(0);
        }
        catch(...)
        {
            PEGASUS_TEST_ASSERT(1);
        }

        PEGASUS_TEST_ASSERT(a1 == CQLValue(Uint64(11)));
        PEGASUS_TEST_ASSERT(a2 == CQLValue(Uint64(36)));


        PEGASUS_TEST_ASSERT(a6 == CQLValue(Uint64(2)));


    }
    catch(Exception & e)
    {
        cout << e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }
    delete _rep;
    return;
}
Ejemplo n.º 3
0
void drive_resolve_primitive()
{


    const char* env = getenv("PEGASUS_HOME");
    String repositoryDir(env);
    repositoryDir.append("/repository");
    //String repositoryDir("c:/pegasus-cvs/pegasus/repository");
    CIMNamespaceName _ns("root/cimv2");
    CIMRepository *_rep = new CIMRepository(repositoryDir);
    RepositoryQueryContext _query(_ns, _rep);
    RepositoryQueryContext _query1(_ns, _rep);
    try {
        const CQLIdentifier _Id1(String("CIM_OperatingSystem"));

        _query.insertClassPath(_Id1);

        const CIMName _cimName(String("CIM_OperatingSystem"));

        CIMInstance _i1(_cimName);
        CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules")));
        CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2)));
        CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
        CIMProperty _p4(CIMName("TimeOfLastStateChange"),
                        CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

        _i1.addProperty(_p1);
        _i1.addProperty(_p2);
        _i1.addProperty(_p3);
        _i1.addProperty(_p4);

        CQLChainedIdentifier ci1(
            String("CIM_OperatingSystem.CIM_OperatingSystem::Description"));
        CQLChainedIdentifier
        ci2(String("CIM_OperatingSystem.CIM_OperatingSystem::EnabledState"));
        CQLChainedIdentifier ci3(
            String("CIM_OperatingSystem.CIM_OperatingSystem::CurrentTimeZone"));
        CQLChainedIdentifier ci4(
            String("CIM_OperatingSystem.CIM_OperatingSystem::TimeOfLastStateChange"));

        CQLChainedIdentifier
        ci5(String(
                "CIM_OperatingSystem.CIM_EnabledLogicalElement::TimeOfLastStateChange"));

        CQLChainedIdentifier
        ci7(String("CIM_OperatingSystem"));

        CQLChainedIdentifier
        ci9(String(
                "CIM_EnabledLogicalElement.CIM_OperatingSystem::CSCreationClassName"));

        CQLChainedIdentifier
        ci10(String("CIM_OperatingSystem.CIM_OperatingSystem::Bubba"));

        CQLValue a1(ci1);
        CQLValue a2(ci2);
        CQLValue a3(ci3);
        CQLValue a4(ci4);
        CQLValue a5(ci5);

        CQLValue a7(ci7);

        CQLValue a9(ci9);
        CQLValue a10(ci10);

        CQLValue a11(_query.getClass(CIMName("CIM_OperatingSystem")));

        a1.resolve(_i1, _query);
        a2.resolve(_i1, _query);
        a3.resolve(_i1, _query);
        a4.resolve(_i1, _query);
        a5.resolve(_i1, _query);
        a7.resolve(_i1, _query);
        a10.resolve(_i1, _query1);

        a9.resolve(_i1, _query);

        PEGASUS_TEST_ASSERT(a1 == CQLValue(String("Dave Rules")));
        PEGASUS_TEST_ASSERT(a2 == CQLValue(Uint64(2)));
        PEGASUS_TEST_ASSERT(a3 == CQLValue(Sint64(-600)));
        PEGASUS_TEST_ASSERT(a4 == CQLValue(
                                CIMDateTime(String("20040811105625.000000-360"))));
        PEGASUS_TEST_ASSERT(a5 == CQLValue(
                                CIMDateTime(String("20040811105625.000000-360"))));
        //PEGASUS_TEST_ASSERT(a7 == CQLValue(_i1));
        PEGASUS_TEST_ASSERT(a9.isNull());
        PEGASUS_TEST_ASSERT(a10.isNull());

    }
    catch(Exception & e)
    {
        cout << e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }
    delete _rep;
    return;
}
Ejemplo n.º 4
0
int main(int argc, char ** argv)
{
    // process options
    if(argc == 1 || (argc > 1 && strcmp(argv[1],"-h") == 0) ) {
        help(argv[0]);
        exit(0);
    }

    // Since the output of this program will be compared with
    // a master output file, turn off ICU message loading.
    MessageLoader::_useDefaultMsg = true;

    String testOption;
    String className;
    String nameSpace;

    for(int i = 0; i < argc; i++) {
        if((strcmp(argv[i],"-test") == 0) && (i+1 < argc))
            testOption = argv[i+1];
        if((strcmp(argv[i],"-className") == 0) && (i+1 < argc))
            className = argv[i+1];
        if((strcmp(argv[i],"-nameSpace") == 0) && (i+1 < argc))
            nameSpace = argv[i+1];
    }

    String lang("WQL");
    Array<CQLSelectStatement> _statements;

    // setup test environment
    // get the configuration variable PEGASUS_HOME
    const char* peg_home = getenv("PEGASUS_HOME");

    // get the makefile build config variable REPOSITORY_NAME
    const char* repo_name = getenv("REPOSITORY_NAME");


    if (peg_home == NULL)
        exit(-1);

    if (repo_name == NULL)
        repo_name = "repository";


    String repositoryDir(peg_home);
    repositoryDir.append("/");
    repositoryDir.append(repo_name);

    CIMNamespaceName _ns;
    if(nameSpace != String::EMPTY) {
        _ns = nameSpace;
    } else {
        cout << "Using root/SampleProvider as default namespace." << endl;
        _ns = String("root/SampleProvider");
    }

    CIMRepository* _rep = new CIMRepository(repositoryDir);
    RepositoryQueryContext _ctx(_ns, _rep);

    char text[1024];
    char* _text;

    // setup Test Instances
    Array<CIMInstance> _instances;
    if(className != String::EMPTY) {
        try {
            const CIMName _testclass(className);
            _instances = _rep->enumerateInstances( _ns, _testclass, true );  // deep inh true
        } catch(Exception& e) {
            cout << endl << endl
                 << "Exception: Invalid namespace/class: "
                 << e.getMessage() << endl << endl;
        }
    } else { // load default class names
        cout << endl << "Using default class names to test queries. " << endl << endl;
        const CIMName _testclass(String("QExpr_TestPropertyTypes"));
        const CIMName _testclass2(String("QExpr_TestElement"));
        try {
            _instances = _rep->enumerateInstances( _ns, _testclass, true ); // deep inh true
            _instances.appendArray(_rep->enumerateInstances( _ns, _testclass2, true )); // deep inh true
        } catch(Exception& e) {
            cout << endl << endl << "Exception: Invalid namespace/class: " << e.getMessage() << endl << endl;
        }
    }

    // setup input stream
    if(argc >= 2) {
        ifstream queryInputSource(argv[1]);
        if(!queryInputSource) {
            cout << "Cannot open input file.\n" << endl;
            return 1;
        }
        int cnt = 0;
        while(!queryInputSource.eof()) {
            queryInputSource.getline(text, 1024);
            char* _ptr = text;
            _text = strcat(_ptr,"\n");
            // check for comments and ignore
            // a comment starts with a # as the first non whitespace character on the line
            char _comment = '#';
            int i = 0;
            while(text[i] == ' ' || text[i] == '\t') i++; // ignore whitespace
            if(text[i] != _comment)
            {
                if(!(strlen(_text) < 2))
                {
                    String query(text);
                    if(query == "WQL:\n") lang = "WQL";
                    else if(query == "CQL:\n") lang = "CIM:CQL";
                    else
                    {
                        try
                        {
                            QueryExpression qexpr;

                            if(cnt % 2)
                            {
                                qexpr = QueryExpression(lang,query);
                                qexpr.setQueryContext(_ctx);
                            }
                            else
                            {
                                qexpr = QueryExpression(lang,query,_ctx);
                            }

                            cnt++;

                            SelectStatement* ss = qexpr.getSelectStatement();

                            String returnQuery = qexpr.getQuery();
                            PEGASUS_ASSERT(returnQuery == query);

                            String returnLang = qexpr.getQueryLanguage();
                            PEGASUS_ASSERT(returnLang == lang);

                            QueryExpression copy(qexpr);
                            PEGASUS_ASSERT(copy.getQuery() == qexpr.getQuery());
                            PEGASUS_ASSERT(copy.getQueryLanguage() == qexpr.getQueryLanguage());

                            _applyProjection(qexpr,_instances, testOption, lang);
                            _getPropertyList(qexpr,_instances, _ns, testOption,lang);
                            _validate(qexpr,lang, testOption);
                            _evaluate(qexpr,_instances, testOption,lang);
                        }
                        catch(Exception& e) {
                            cout << e.getMessage() << endl;
                        }
                        catch(...) {
                            cout << "CAUGHT ... BADNESS HAPPENED!!!" << endl;
                        }
                    }
                }
            }

            // while (!eof) behaves differently on HP-UX, seems
            // like it takes an extra iteration to hit eof.  This
            // leaves "text" with the previous value from
            // getline(..), which causes a duplicate parse of
            // the last select statement in the query file,
            // FIX: we clear text before doing another getline(..)
            text[0] = 0;
        }
        queryInputSource.close();
    } else {
        cout << "Invalid number of arguments.\n" << endl;
    }
    delete _rep;
    return 0;
}