📄 g11ntest.cpp
字号:
for (Uint32 k = 0; k < cimNInstances.size(); k++) { String enumString; cimNInstances[k].getProperty (cimNInstances[k].findProperty(RBPROP)). getValue(). get(enumString); if (skipICU) { MYASSERT(expectedDftString == enumString); } else { MYASSERT(expectedStr == enumString); } } return cimNInstances;}/* Tests the globalization support of the LocalizedProvider for the instance operations*/static void TestLocalizedInstances( CIMClient& client, Boolean activeTest, Boolean verboseTest ){ const CIMNamespaceName NAMESPACE = CIMNamespaceName ("root/SampleProvider"); const CIMName CLASSNAME = CIMName ("Sample_LocalizedProviderClass"); const CIMName SUBCLASSNAME = CIMName ("Sample_LocalizedProviderSubClass"); const String INSTANCE0 = "instance 0Sample_LocalizedProviderClass"; const String INSTANCE1 = "instance 1Sample_LocalizedProviderClass"; const String RBPROP = "ResourceBundleString"; const String ROUNDTRIPSTRINGPROP = "RoundTripString"; const String ROUNDTRIPCHARPROP = "RoundTripChar"; const String CLPROP = "ContentLanguageString"; const String TESTSTRINGPROP = "TestString"; const String IDPROP = "Identifier"; ContentLanguageList CL_DE; CL_DE.append(LanguageTag("de")); String expectedDEString = "ResourceBundleString DE"; ContentLanguageList CL_FR; CL_FR.append(LanguageTag("fr")); String expectedFRString = "ResourceBundleString FR"; ContentLanguageList CL_Dft; ContentLanguageList CL_EN; CL_EN.append(LanguageTag("en")); String expectedDftString = "ResourceBundleString DEFAULT"; ContentLanguageList CL_HOMER; CL_HOMER.append(LanguageTag("x-homer")); ContentLanguageList CL_ES; CL_ES.append(LanguageTag("es")); String expectedUTF16String(utf16Chars); try { const CIMName className = CLASSNAME; Boolean deepInheritance = false; Boolean localOnly = false; Boolean includeQualifiers = true; Boolean includeClassOrigin = false; Uint32 testRepeat = 1; if (verboseTest) cout << "Getting class: " << CLASSNAME << endl; CIMClass sampleClass = client.getClass( NAMESPACE, CLASSNAME, localOnly, includeQualifiers, includeClassOrigin); CIMClass sampleSubClass = client.getClass( NAMESPACE, SUBCLASSNAME, localOnly, includeQualifiers, includeClassOrigin); // Note: When Pegasus has external message files enabled, // then the provider has message files for fr, de, // and es, but no root message file. The missing root // message file will cause us to test the default message // strings compiled into the code. for (Uint32 q = 0; q < testRepeat; q++) // repeat the test x time { // // TEST 1 - Enumerate Instances of the base class, deepInheritance == false. // de is supported by the provider, and is the most preferred by us. // AcceptLanguageList acceptLangs1; if (skipICU) { // Not requesting translated messages from the provider acceptLangs1.clear(); } else { acceptLangs1.insert(LanguageTag("fr"), Real32(0.5)); acceptLangs1.insert(LanguageTag("de"), Real32(0.8)); acceptLangs1.insert(LanguageTag("es"), Real32(0.4)); } cout << endl << "INSTANCE TEST 1: Enumerate Instances with AcceptLanguageList = " << LanguageParser::buildAcceptLanguageHeader(acceptLangs1) << endl; Array<CIMInstance> cimNInstances = EnumerateSampleInstances( client, acceptLangs1, CL_DE, expectedDEString, verboseTest); // // TEST 2 - Aggregation Test - Enumerate Instances starting at the base class, // with deep inheritance, where each instance has the same language. // This will test that the languages of the instances are aggregated // into the Content-Language of the whole response. // // (tests ContentLanguage aggregation in CIMOperationRequestDispatcher) cout << endl << "INSTANCE TEST 2: Enumerate Instances with Content-Language match" << endl; AcceptLanguageList acceptLangs2; if (skipICU) { // Not requesting translated messages from the provider acceptLangs2.clear(); } else { acceptLangs2.insert(LanguageTag("de"), Real32(0.8)); } client.setRequestAcceptLanguages(acceptLangs2); Array<CIMInstance> cimNInstances2 = client.enumerateInstances(NAMESPACE, className, true, false, includeQualifiers, includeClassOrigin); if (verboseTest) cout << "Found " << cimNInstances2.size() << " Instances of " << className << endl; MYASSERT(cimNInstances2.size() == 3); if (skipICU) { if (verboseTest) cout << "Checking expected response ContentLanguageList: " << LanguageParser::buildContentLanguageHeader(CL_EN) << endl; MYASSERT(CL_EN == client.getResponseContentLanguages()); } else { if (verboseTest) cout << "Checking expected response ContentLanguageList: " << LanguageParser::buildContentLanguageHeader(CL_DE) << endl; MYASSERT(CL_DE == client.getResponseContentLanguages()); } // // TEST 3 - Aggregation Test - Enumerate Instances with deep inheritance, where // the instances do not have the same language. Since the languages of the instances // do not match, we expect the ContentLanguage of the whole response to be empty. // This will test that the languages of the instances are aggregated // into the Content-Language of the whole response. // // We will modify the language of the sub-class instance, and then do the enumerate. // // (tests ContentLanguage aggregation in CIMOperationRequestDispatcher) // cout << endl << "INSTANCE TEST 3: Enumerate Instances with Content-Language mismatch" << endl; if (!activeTest) { cout << "Active tests are disabled. Nothing to do for this test." << endl; } else { // First, find the instance of the sub-class Uint32 i = 0; for (; i < cimNInstances2.size(); i++) { if (cimNInstances2[i].getClassName() == SUBCLASSNAME) { break; } } MYASSERT(i != cimNInstances2.size()); if (verboseTest) cout << "Modifying the language of an instance of the subclass to " << LanguageParser::buildContentLanguageHeader(CL_HOMER) << endl; client.setRequestContentLanguages(CL_HOMER); client.modifyInstance(NAMESPACE, cimNInstances2[i], includeQualifiers); // Enumerate the instances starting at the base class, with deep inheritance. AcceptLanguageList acceptLangs3; acceptLangs3.insert(LanguageTag("x-homer"), Real32(0.8)); client.setRequestAcceptLanguages(acceptLangs3); Array<CIMInstance> cimNInstances3 = client.enumerateInstances(NAMESPACE, className, true, false, includeQualifiers, includeClassOrigin ); if (verboseTest) cout << "Found " << cimNInstances3.size() << " Instances of " << className << endl; MYASSERT(cimNInstances3.size() == 3); if (verboseTest) cout << "Checking expected empty response ContentLanguageList" << endl; MYASSERT(client.getResponseContentLanguages().size() == 0); } // else active tests // // TEST 4 - Get Instance, check default language returned. // None of our preferred languages is supported by the // provider, and the root message file is empty. Expect // the compiled-in default strings from the provider. // AcceptLanguageList acceptLangs4; acceptLangs4.insert(LanguageTag("x-martian"), Real32(0.8)); acceptLangs4.insert(LanguageTag("x-pig-latin"), Real32(0.1)); acceptLangs4.insert(LanguageTag("x-men"), Real32(0.4)); client.setRequestAcceptLanguages(acceptLangs4); cout << endl << "INSTANCE TEST 4: Get Instance with AcceptLanguageList = " << LanguageParser::buildAcceptLanguageHeader(acceptLangs4) << endl; // Find an instance of the base-class from the first enumerate Uint32 j = 0; for (; j < cimNInstances.size(); j++) { if (cimNInstances[j].getClassName() == CLASSNAME) { break; } } MYASSERT(j != cimNInstances.size()); // Get the instance. Note, baseInstance is used later CIMObjectPath baseObjectPath = cimNInstances[j].buildPath(sampleClass); CIMInstance baseInstance = client.getInstance( NAMESPACE, baseObjectPath, localOnly, includeQualifiers, includeClassOrigin); // update base instance object path (it's not set by the cimom or client) baseInstance.setPath(baseObjectPath); String returnedString; Char16 returnedChar16; baseInstance.getProperty (baseInstance.findProperty(RBPROP)). getValue(). get(returnedString); if (verboseTest) cout << "Checking for default language returned" << endl; MYASSERT(expectedDftString == returnedString); // // TEST 5 - Get Instance, check fr language returned. // fr is the lowest preferred language from us, but // is the only one in the list supported by the provider. // AcceptLanguageList acceptLangs5; if (skipICU) { // Not requesting translated messages from the provider acceptLangs5.clear(); } else { acceptLangs5.insert(LanguageTag("x-martian"), Real32(0.8)); acceptLangs5.insert(LanguageTag("fr"), Real32(0.1)); acceptLangs5.insert(LanguageTag("x-men"), Real32(0.4)); } client.setRequestAcceptLanguages(acceptLangs5); cout << endl << "INSTANCE TEST 5: Get Instance with AcceptLanguageList = " << LanguageParser::buildAcceptLanguageHeader(acceptLangs5) << endl; CIMInstance instance5 = client.getInstance( NAMESPACE, cimNInstances[1].buildPath(sampleClass), localOnly, includeQualifiers, includeClassOrigin); instance5.getProperty (instance5.findProperty(RBPROP)). getValue(). get(returnedString); if (skipICU) { if (verboseTest) cout << "Checking for default language returned" << endl; MYASSERT(CL_EN == client.getResponseContentLanguages()); MYASSERT(expectedDftString == returnedString); } else { if (verboseTest) cout << "Checking for fr returned" << endl; MYASSERT(CL_FR == client.getResponseContentLanguages()); MYASSERT(expectedFRString == returnedString); } // // TEST 6 - Round trip Test. // Create Instance followed by Get Instance. // // Create with an fr string and expect that // the fr string is preserved on get instance. // (fr is one of the supported languages of the provider) // // Create with a UTF-16 string and char16 and expect that they // are preserved on get instance // cout << endl << "INSTANCE TEST 6: Create Instance with ContentLanguageList = " << LanguageParser::buildContentLanguageHeader(CL_FR) << " and UTF-16 string." << endl; if (!activeTest) { cout << "Active tests are disabled. Nothing to do for this test." << endl; } else { String oui = "Oui"; CIMInstance frInstance(CLASSNAME); frInstance.addProperty(CIMProperty(CIMName(CLPROP), oui)); frInstance.addProperty(CIMProperty(CIMName(ROUNDTRIPSTRINGPROP), String(utf16Chars))); frInstance.addProperty(CIMProperty(CIMName(ROUNDTRIPCHARPROP), utf16Chars[0]));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -