⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryexpression.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        catch(Exception& e){ cout << "-----" << e.getMessage() << endl;}        catch(...){ cout << "Unknown Exception" << endl;}    }                           }	  return true;}Boolean _evaluate(QueryExpression& qe,                  Array<CIMInstance>& _instances,                  String testOption,		  String lang){  if(testOption == String::EMPTY || testOption == "1")  {                              cout << endl << lang << " ========Evaluating QueryExpression=======" << endl;      cout << qe.getQuery() << endl << endl;      for(Uint32 j = 0; j < _instances.size(); j++)      {        try        {          Boolean result = qe.evaluate(_instances[j]);          cout << qe.getQuery() << " = ";          if (result) cout << "TRUE" << endl << endl;          else cout << "FALSE" << endl << endl;        }        catch(Exception e){ cout << e.getMessage() << endl;}        catch(...){ cout << "Unknown Exception" << endl;}      }      }  return true;}void _validate(QueryExpression& qe,String lang,               String testOption){  if(testOption == String::EMPTY || testOption == "4")  {    cout << endl << lang << " ========Validating QueryExpression=======" << endl;    cout << qe.getQuery() << endl;    try    {      qe.validate();      cout << "validate ok" << endl;    }    catch(Exception e){ cout << e.getMessage() << endl;}    catch(...){ cout << "Unknown Exception" << endl;}  }}void help(const char* command){	cout << command << " queryFile [option]" << endl;	cout << " options:" << endl;	cout << " -test: ";	cout << "1 = evaluate" << endl              << "        2 = apply projection" << endl              << "        3 = get property list and get class path list" << endl;	cout << "        4 = validate properties" << endl;	cout << " -className class" << endl;	cout << " -nameSpace namespace (Example: root/SampleProvider)" << endl << endl;}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");    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;	if(nameSpace != String::EMPTY){		_ns = nameSpace;	}else{		cout << "Using root/SampleProvider as default namespace." << endl;      _ns = String("root/SampleProvider");	}    CIMRepository* _rep;    try    {        _rep = new CIMRepository(repositoryDir);    } catch(Exception &e)    {        cout << endl << endl             << "Invalid Repository: Exception: " << e.getMessage()             << endl << endl;        exit(-1);    }    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->enumerateInstancesForSubtree( _ns, _testclass);		}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->enumerateInstancesForSubtree(_ns, _testclass);        _instances.appendArray(_rep->enumerateInstancesForSubtree(_ns, _testclass2));		}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 = "DMTF: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_TEST_ASSERT(returnQuery == query);                 String returnLang = qexpr.getQueryLanguage();                 PEGASUS_TEST_ASSERT(returnLang == lang);                 QueryExpression copy(qexpr);                 PEGASUS_TEST_ASSERT(copy.getQuery() == qexpr.getQuery());                 PEGASUS_TEST_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;                                                                                                              }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -