📄 testclient.cpp
字号:
if (assocResult.size() != assocResultObjects.size()) { cout << "ERROR, Associator and AssociatorName count returned different counts " << assocResult.size() << " associator name responses and " << assocResultObjects.size() << " associator objects " << endl; //#define LOCAL_MAX (a , b) (a > b) ? a : b ) // Uint32 maxCount = LOCAL_MAX(assocResult.size() ,assocResultObjects.size()); Uint32 maxCount = (assocResult.size() ,assocResultObjects.size() ) ? assocResult.size() : assocResultObjects.size(); cout << "Max " << maxCount << endl; for (Uint32 i = 0 ; i < maxCount ; i ++) { cout << i << " " << ((i < assocResult.size())? assocResult[i].toString() : "") << endl; cout << i << " " << ((i < assocResultObjects.size())? assocResultObjects[i].getPath().toString() : "") << endl; } errorCount++; return; } for (Uint32 i = 0; i < assocResultObjects.size(); i++) { Uint32 matched=0; for (Uint32 j = 0; j < assocResult.size(); j++) { if (assocResultObjects[i].getPath().toString() == assocResult[j].toString()) { matched=1; assocResult.remove(j); j--; break; } } if(matched) { assocResultObjects.remove(i); i--; } } for (Uint32 i = 0; i <assocResult.size(); i++) { cout << "Association Name response Error" << assocResultObjects[i].getPath().toString() << " != " << assocResult[i].toString() << endl; } if (assocResult.size()) { errorCount++; return; }}static void TestAssociationOperations(CIMClient* client, Boolean activeTest, Boolean verboseTest, String uniqueID){ CIMNamespaceName nameSpace = "test/TestProvider"; // If the sample provider class is loaded, this function tests the // association functions against the FamilyProvider Boolean runTest = true; // First test against known name in cim namespace. { CIMObjectPath o1("CIM_ManagedElement"); CIMObjectPath o2("CIM_ManagedElement.name=\"karl\""); testRefandAssoc(client, globalNamespace, verboseTest, o1, CIMName(), CIMName()); try { testRefandAssoc(client, globalNamespace, verboseTest, o2, CIMName(), CIMName()); } catch(CIMException& e) { // This test will get a not supported exception in the case where // the repository is not the default instance provider. We should not // flag this as a test error. if (e.getCode() == CIM_ERR_NOT_SUPPORTED) { cerr << "CIMException : " << e.getMessage() << endl; } } } // Now Test to see if the namespace and class exist before // continueing the test. { CIMName className = "TST_Person"; try { client->getClass(nameSpace, className); } catch(CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_NAMESPACE || e.getCode() == CIM_ERR_INVALID_CLASS) { runTest = false; } else { cerr << "CIMException : " << className << endl; cerr << e.getMessage() << endl; errorCount++; return; } } } if (runTest) { CIMObjectPath TST_PersonClass= CIMObjectPath("TST_Person"); CIMObjectPath TST_PersonInstance = CIMObjectPath( "TST_Person.name=\"Mike\""); CIMObjectPath TST_PersonDynamicClass = CIMObjectPath("TST_PersonDynamic"); CIMObjectPath TST_PersonDynamicInstance = CIMObjectPath( "TST_PersonDynamic.name=\"Father\""); testRefandAssoc(client, nameSpace, verboseTest, TST_PersonClass , CIMName(), CIMName()); testRefandAssoc(client, nameSpace, verboseTest, TST_PersonInstance , CIMName(), CIMName()); testRefandAssoc(client, nameSpace, verboseTest, TST_PersonDynamicClass , CIMName(), CIMName()); testRefandAssoc(client, nameSpace, verboseTest, TST_PersonDynamicInstance , CIMName(), CIMName()); } return;}/* Creates an instance with a method, executes the method and then deletesthe instanceWarning: This test works only as long as there is a provider, in this case, it goesto the repository and gets dropped on the floor.*/static void TestMethodOperations( CIMClient* client, Boolean activeTest, Boolean verboseTest, String uniqueID){ // Since the test modifies the repository, don't do it unless active set. if (!activeTest) return; String name = uniqueID.append("_").append("TestSoftwarePkg"); CIMName cimName(name); //Indication to be created CIMClass cimClass = client->getClass(globalNamespace, cimName, false); CIMInstance cimInstance(cimName); cimInstance.addProperty(CIMProperty(CIMName ("PkgName"), String("WBEM"))); cimInstance.addProperty(CIMProperty(CIMName ("PkgIndex"), Uint32(101))); cimInstance.addProperty(CIMProperty(CIMName ("trapOid"), String("1.3.6.1.4.1.11.2.3.1.7.0.4"))); cimInstance.addProperty(CIMProperty(CIMName ("computerName"), String("NU744781"))); CIMObjectPath instanceName = cimInstance.buildPath(cimClass); instanceName.setNameSpace(globalNamespace); client->createInstance(globalNamespace, cimInstance); try { Array<CIMParamValue> inParams; Array<CIMParamValue> outParams; inParams.append(CIMParamValue("param1", CIMValue(String("Hewlett-Packard")))); inParams.append(CIMParamValue("param2", CIMValue(String("California")))); Uint32 testRepeat = 100; for (Uint32 i = 0; i < testRepeat; i++) // repeat the test x time { CIMValue retValue = client->invokeMethod( globalNamespace, instanceName, CIMName ("ChangeName"), inParams, outParams); if (verboseTest) { cout << "Output : " << retValue.toString() << endl; for (Uint8 i = 0; i < outParams.size(); i++) cout << outParams[i].getParameterName() << " : " << outParams[i].getValue().toString() << endl; } } cout << "Executed " << testRepeat << " methods" << endl; } catch(ConnectionTimeoutException& e) { PEGASUS_STD(cerr) << "Warning: " << e.getMessage() << PEGASUS_STD(endl); exit(2); } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); } client->deleteInstance(globalNamespace, instanceName);}/* Tests the invoke method request via the sample method provider.*/static void TestInvokeMethod( CIMClient * client, Boolean activeTest, Boolean verboseTest, const String& uniqueID){ const CIMNamespaceName NAMESPACE = CIMNamespaceName("root/SampleProvider"); const CIMName classname = CIMName("Sample_MethodProviderClass"); const CIMName methodName = CIMName("SayHello"); const CIMObjectPath instanceName = CIMObjectPath( "Sample_MethodProviderClass.Identifier=1"); try { for (Uint32 testCases = 0; testCases < 3; testCases++) { Array<CIMParamValue> inParams; Array<CIMParamValue> outParams; CIMParamValue inParam; String goodReply; String goodOutParam; if (testCases == 0) { // Test case for a parameter with a non-empty value inParams.append( CIMParamValue("Name", CIMValue(String("Yoda")))); goodReply = "Hello, Yoda!"; goodOutParam = "From Neverland"; } else if (testCases == 1) { // Test case for a parameter with an empty value inParams.append(CIMParamValue("Name", CIMValue(String("")))); goodReply = "Hello"; goodOutParam = "From Neverland"; } else { // Test case for a parameter with a null value inParams.append( CIMParamValue("Name", CIMValue(CIMTYPE_STRING, false, 0))); goodReply = "Hello"; goodOutParam = "From Neverland"; } Uint32 testRepeat = 10; for (Uint32 i = 0; i < testRepeat; i++) // repeat the test x time { CIMValue retValue = client->invokeMethod( NAMESPACE, instanceName, methodName, inParams, outParams); if (verboseTest) { cout << "Output: " << retValue.toString() << endl; for (Uint32 i = 0; i < outParams.size(); i++) { cout << outParams[i].getParameterName() << ": " << outParams[i].getValue().toString() << endl; } } PEGASUS_TEST_ASSERT(retValue.toString() == goodReply); PEGASUS_TEST_ASSERT(outParams.size() == 1); String outParam = String::EMPTY; outParams[0].getValue().get(outParam); PEGASUS_TEST_ASSERT(outParam == goodOutParam); } cout << "Executed " << testRepeat << " methods" << endl; } } catch(ConnectionTimeoutException& e) { PEGASUS_STD(cerr) << "Warning: " << e.getMessage() << PEGASUS_STD(endl); exit(2); } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); }}/* Tests the enumerate instances from the sample instance provider.*/static void TestEnumerateInstances( CIMClient * client, Boolean activeTest, Boolean verboseTest, String uniqueID ){ const CIMNamespaceName NAMESPACE("root/SampleProvider"); const CIMName CLASSNAME("Sample_InstanceProviderClass"); const CIMObjectPath INSTANCE0("Sample_InstanceProviderClass.Identifier=1"); const CIMObjectPath INSTANCE1("Sample_InstanceProviderClass.Identifier=2"); const CIMObjectPath INSTANCE2("Sample_InstanceProviderClass.Identifier=3"); try { const CIMName className = CLASSNAME; Boolean deepInheritance = true; Boolean localOnly = true; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; Uint32 testRepeat = 10; Uint32 numberInstances; for (Uint32 i = 0; i < testRepeat; i++) // repeat the test x time { Array<CIMInstance> cimNInstances = client->enumerateInstances(NAMESPACE, className, deepInheritance, localOnly, includeQualifiers, includeClassOrigin ); cout << "Found " << cimNInstances.size() << " Instances of " << className << endl; //ASSERTTEMP(cimNInstances.size() == 3); numberInstances = cimNInstances.size(); for (Uint32 i = 0; i < cimNInstances.size(); i++) { CIMObjectPath instanceRef = cimNInstances[i].getPath(); if((instanceRef != INSTANCE0) && (instanceRef != INSTANCE1) && (instanceRef != INSTANCE2)) { PEGASUS_STD(cerr) << "Error: EnumInstances failed. Instance Name Error" << " Expected instance name = " << INSTANCE0.toString() << " or " << INSTANCE1.toString() << " or " << INSTANCE2.toString() << "received = " << instanceRef.toString() << PEGASUS_STD(endl); errorCount++; return; } } } cout << "Enumerate " << numberInstances << " instances " << testRepeat << " times" << endl; } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); errorCount++; return; }}static Boolean verifyCertificate(SSLCertificateInfo &certInfo){ //ATTN-NB-03-05132002: Add code to handle server certificate verification. return true;}///////////////////////////////////////////////////////////////// OPTION MANAGEMENT////////////////////////////////////////////////////////////////** GetOptions function - This function defines the Options Table and sets up the options from that table using the option manager. const char* optionName; const char* defaultValue; int required; Option::Type type; char** domain; Uint32 domainSize; const char* commandLineOptionName; const char* optionHelpMessage;*/void GetOptions( OptionManager& om, int& argc, char** argv, const String& pegasusHome){ static struct OptionRow optionsTable[] = // optionname defaultvalue rqd type domain domainsize clname hlpmsg { {"active", "false", false, Option::BOOLEAN, 0, 0, "a", "If set allows test that modify the repository" }, {"repeat", "1", false, Option::WHOLE_NUMBER, 0, 0, "r", "Specifies a Repeat Count Entire test repeated this many times" }, {"namespace", "root/cimv2", false, Option::STRING, 0, 0, "-n", "specifies namespace to use for test" }, {"version", "false", false, Option::BOOLEAN, 0, 0, "version", "Displays TestClient Version "}, {"verbose", "false", false, Option::BOOLEAN, 0, 0, "verbose", "If set, outputs extra information "}, {"help", "false", false, Option::BOOLEAN, 0, 0, "h", "Prints help message with command line options "}, {"debug", "false", false, Option::BOOLEAN, 0, 0, "d", "Not Used "},// remove slp {"slp", "false", false, Option::BOOLEAN, 0, 0, "slp",// "use SLP to find cim servers to test"}, {"ssl", "false", false, Option::BOOLEAN, 0, 0, "ssl", "use SSL"}, {"local", "false", false, Option::BOOLEAN, 0, 0, "local", "Use local connection mechanism"}, {"user", "", false, Option::STRING, 0, 0, "user", "Specifies user name" }, {"password", "", false, Option::STRING, 0, 0, "password", "Specifies password" },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -