int main(int argc, char** argv) { providerNamespace = CIMNamespaceName ("test/TestProvider"); CIMClient client; // Connect to server try { client.connectLocal(); } catch (Exception& e) { _errorExit(e.getMessage()); } // Get the instance object paths for the Person and Vehicle class Array<CIMObjectPath> personRefs; try { personRefs = client.enumerateInstanceNames(providerNamespace, CMPI_TEST_PERSON); } catch (Exception& e) { cerr << "enumerateInstanceNames() failed." << endl; _errorExit(e.getMessage()); } Uint32 numPersonInstances = personRefs.size(); // Test associators for (Uint32 i = 0; i < numPersonInstances; i++) { _testAssociators(client, CMPI_TEST_FAIL, personRefs[i]); } // Test references for (Uint32 i = 0; i < numPersonInstances; i++) { _testReferences(client, personRefs[i]); } _testInstanceError(client); _testMethodError(client); cout << argv[0] << " +++++ passed all tests" << endl; return(0); }
void _testNotFound(CIMClient& client) { Uint32 a_count = 0; Uint32 an_count = 0; Uint32 r_count = 0; Uint32 rn_count = 0; cout << "\n+++++ Test for Supported Static and Not Found Dynamic instance" << endl; Array<CIMObjectPath> familyRefs; Array<CIMObjectPath> personRefs; Uint32 numfamilyInstances = 0; Uint32 numpersonInstances; try { familyRefs = client.enumerateInstanceNames(NAMESPACE, TEST_FAMILY); numfamilyInstances = familyRefs.size(); if (verbose) { cout << " TEST_Marriage :: " ; cout << " Number of instances " << numfamilyInstances << endl; } // Checking the RepositoryIsDefaultInstanceProvider and the number // of instances returned. if (My_isDefaultInstanceProvider == 1 && 0 != numfamilyInstances) { throw Exception(" Unexpected number of instances returned with " "Repository Enabled. "); } else if (My_isDefaultInstanceProvider == 0 && 0 != numfamilyInstances) { throw Exception(" Unexpected number of instances returned with " "Repository Disabled. "); } } catch (const CIMException& ex) { CIMStatusCode code = ex.getCode(); if (CIM_ERR_NOT_FOUND != code) { throw Exception(" Test Not Supported Failed. "); } } catch (Exception&) { throw Exception(" Test Not Supported Failed. "); } try { personRefs = client.enumerateInstanceNames(NAMESPACE, TEST_PERSON); numpersonInstances = personRefs.size(); for (Uint32 i = 0; i < numpersonInstances; ++i) { a_count += _testAssociators(client, TEST_FAMILY, personRefs[i]); an_count += _testAssociatorNames(client, TEST_FAMILY, personRefs[i]); r_count += _testReferences(client, personRefs[i],TEST_FAMILY); rn_count += _testReferenceNames(client, personRefs[i], TEST_FAMILY); } if (a_count != numfamilyInstances || an_count != numfamilyInstances || r_count != numfamilyInstances || rn_count != numfamilyInstances) { throw Exception(" The number of instances returned is incorrect."); } } catch (const CIMException& ex) { CIMStatusCode code = ex.getCode(); if (CIM_ERR_NOT_FOUND != code) { throw Exception(" Test Not Supported Failed. "); } } catch (Exception&) { throw Exception(" Test Not Supported Failed. "); } cout << "\n+++++ Test for Supported Static and Not Found Dynamic instance " "Passed" << endl; }
void _testFromRepository(CIMClient& client) { Uint32 a_count = 0; Uint32 an_count = 0; Uint32 r_count = 0; Uint32 rn_count = 0; cout << "\n+++++ Test for Static instance and Not supported Dynamic " "instance" << endl; try { Array<CIMObjectPath> worksRefs; Array<CIMObjectPath> personRefs; Uint32 numworksInstances; Uint32 numpersonInstances; worksRefs = client.enumerateInstanceNames(NAMESPACE, TEST_WORKS); numworksInstances = worksRefs.size(); if (verbose) { cout << " TEST_Works :: " ; cout << " Number of instances " << numworksInstances << endl; } // Checking the RepositoryIsDefaultInstanceProvider and the number // of instances returned. if (My_isDefaultInstanceProvider == 1 && 1 != numworksInstances) { throw Exception(" Unexpected number of instances returned with " "Repository Enabled. "); } else if (My_isDefaultInstanceProvider == 0 && 0 != numworksInstances) { throw Exception(" Unexpected number of instances returned with " "Repository Disabled. "); } personRefs = client.enumerateInstanceNames(NAMESPACE, TEST_PERSON); numpersonInstances = personRefs.size(); for (Uint32 i = 0; i < numpersonInstances; ++i) { a_count += _testAssociators(client, TEST_WORKS, personRefs[i]); an_count += _testAssociatorNames(client, TEST_WORKS, personRefs[i]); r_count += _testReferences(client, personRefs[i],TEST_WORKS); rn_count += _testReferenceNames(client, personRefs[i], TEST_WORKS); } if (a_count != 2*numworksInstances || an_count != 2*numworksInstances || r_count != 2*numworksInstances || rn_count != 2*numworksInstances) { throw Exception(" The number of instances returned is incorrect."); } } catch (const CIMException& ex) { CIMStatusCode code = ex.getCode(); if (CIM_ERR_NOT_SUPPORTED != code && CIM_ERR_NOT_FOUND != code) { throw Exception(" Test From Repository Failed. "); } } catch (Exception&) { throw Exception(" Test From Repository Failed. "); } cout << "\n+++++ Test for Static instance and Not supported Dynamic " "instance passed" << endl; }
void _testaggregation(CIMClient& client) { Uint32 a_count = 0; Uint32 an_count = 0; Uint32 r_count = 0; Uint32 rn_count = 0; cout << "\n+++++ Test aggregation of Static and Dynamic instances" << endl; try { Array<CIMObjectPath> teachesRefs; Array<CIMObjectPath> personRefs; Uint32 numteachesInstances ; Uint32 numpersonInstances ; teachesRefs = client.enumerateInstanceNames(NAMESPACE, TEST_TEACHES); numteachesInstances = teachesRefs.size(); if (verbose) { cout << " TEST_Teaches :: " ; cout << " Number of instances " << numteachesInstances << endl; } // Checking the RepositoryIsDefaultInstanceProvider and the number // of instances returned. if (My_isDefaultInstanceProvider == 1 && 2 != numteachesInstances) { throw Exception(" Unexpected number of instances returned with " "Repository Enabled. "); } else if (My_isDefaultInstanceProvider == 0 && 1 != numteachesInstances) { throw Exception(" Unexpected number of instances returned with " "Repository Disabled. "); } personRefs = client.enumerateInstanceNames(NAMESPACE, TEST_PERSON); numpersonInstances = personRefs.size(); for (Uint32 i = 0; i < numpersonInstances; ++i) { a_count += _testAssociators(client, TEST_TEACHES, personRefs[i]); an_count += _testAssociatorNames(client, TEST_TEACHES, personRefs[i]); r_count += _testReferences(client, personRefs[i],TEST_TEACHES); rn_count += _testReferenceNames(client, personRefs[i], TEST_TEACHES); } if (a_count != 2*numteachesInstances || an_count != 2*numteachesInstances || r_count != 2*numteachesInstances || rn_count != 2*numteachesInstances) { throw Exception(" The number of instances returned is incorrect."); } } catch (Exception& e) { _errorExit(e.getMessage()); } cout << "\n+++++ Test aggregation of Static and Dynamic instances passed" << endl; }
int main(int argc, char** argv) { verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false; // // Check for command line option // if (argc != 2) { cerr << "Usage: TestCMPIAssociation {namespace}" << endl; return(1); } providerNamespace = CIMNamespaceName (argv[1]); CIMClient client; // Connect to server try { client.connectLocal(); } catch (Exception& e) { _errorExit(e.getMessage()); } // ======================================================================= // Test passing Instance object path to the Association Methods // ======================================================================= // Get the instance object paths for the Person and Vehicle class // Array<CIMObjectPath> personRefs; Array<CIMObjectPath> vehicleRefs; try { personRefs = client.enumerateInstanceNames(providerNamespace, CMPI_TEST_PERSON); vehicleRefs = client.enumerateInstanceNames(providerNamespace, CMPI_TEST_VEHICLE); } catch (Exception& e) { cerr << "enumerateInstanceNames() failed." << endl; _errorExit(e.getMessage()); } for(Uint32 i=0;i<personRefs.size();i++) { cout<<"PersonRefs values : "<<personRefs[i].toString()<<endl; } for(Uint32 i=0;i<vehicleRefs.size();i++) { cout<<"VehicleRefs values : "<<vehicleRefs[i].toString()<<endl; } Uint32 numPersonInstances = personRefs.size(); Uint32 numVehicleInstances = vehicleRefs.size(); cout << "Number of PersonInstances: " << numPersonInstances << endl; cout << "Number of VehicleInstances: " << numVehicleInstances << endl; // ======================================================================= // Test associators // // Get the CIM instances that are associated with the specified source CIM // instance via an instance of a specified association class. // ======================================================================= if (verbose) { cout << "+++++ Test associators" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testAssociators( client, CMPI_TEST_RACING, personRefs[i], resultArray_asso_P1[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testAssociators(client, CMPI_TEST_RACING, vehicleRefs[i], resultArray_asso_V1[i]); } // ======================================================================= // Test associatorNames // // Get the names of the CIM instances that are associated with the specified // source CIM instance via an instance of a association class. // ======================================================================= if (verbose) { cout << "+++++ Test associatorNames" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testAssociatorNames(client, CMPI_TEST_RACING, personRefs[i], resultArray_asso_P1[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testAssociatorNames(client, CMPI_TEST_RACING, vehicleRefs[i], resultArray_asso_V1[i]); } // ======================================================================= // Test references // // Get the association instances that refer to the specified target CIM // instance. // ======================================================================= if (verbose) { cout << "+++++ Test references" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testReferences(client, personRefs[i], resultArray_ref_P[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testReferences(client, vehicleRefs[i], resultArray_ref_V[i]); } // ======================================================================= // Test property filter for associators and references // ======================================================================= _testCMPIFilterOfAssociation(client); // ======================================================================= // Test referenceNames // // Get the names of the association instances that refer to the specified // source CIM instance. // ======================================================================= if (verbose) { cout << "+++++ Test referenceNames" << endl; } for (Uint32 i = 0; i < numPersonInstances; i++) { _testReferenceNames(client, personRefs[i], resultArray_ref_P[i]); } for (Uint32 i = 0; i < numVehicleInstances; i++) { _testReferenceNames(client, vehicleRefs[i], resultArray_ref_V[i]); } // ======================================================================= // Test passing Class object path to the Association Methods // ======================================================================= if (verbose) { cout << "+++++ Test association class operations" << endl; } _testCMPIAssociationClassOperations(client, CMPI_TEST_PERSON); _testCMPIAssociationClassOperations(client, CMPI_TEST_VEHICLE); // ======================================================================= // Association tests completed // ======================================================================= cout << argv[0] << " +++++ passed all tests" << endl; return(0); }