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

📄 g11ntest.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
              frInstance.addProperty(CIMProperty(CIMName(IDPROP), Uint8(3)));              CIMObjectPath frInstanceName = frInstance.buildPath(sampleClass);              frInstance.setPath(frInstanceName);              client.setRequestContentLanguages(CL_FR);              if (verboseTest)                  cout << "Creating the instance" << endl;              client.createInstance(NAMESPACE, frInstance);              AcceptLanguageList acceptLangs6;              acceptLangs6.insert(LanguageTag("x-martian"), Real32(0.8));              acceptLangs6.insert(LanguageTag("fr"), Real32(0.1));              acceptLangs6.insert(LanguageTag("x-men"), Real32(0.4));              client.setRequestAcceptLanguages(acceptLangs6);              if (verboseTest)                  cout << "Getting the instance just created, using AcceptLanguageList = "                      << LanguageParser::buildAcceptLanguageHeader(acceptLangs6)                      << endl;              CIMInstance instance6 = client.getInstance(                  NAMESPACE,                  frInstanceName,                  localOnly,                  includeQualifiers,                  includeClassOrigin);              instance6.getProperty (instance6.findProperty(ROUNDTRIPSTRINGPROP)).                  getValue().                  get(returnedString);              instance6.getProperty (instance6.findProperty(ROUNDTRIPCHARPROP)).                  getValue().                  get(returnedChar16);              if (verboseTest)                      cout << "Checking the UTF-16 chars were preserved" << endl;              MYASSERT(expectedUTF16String == returnedString);              MYASSERT(utf16Chars[0] == returnedChar16);              instance6.getProperty (instance6.findProperty(CLPROP)).                  getValue().                  get(returnedString);              if (verboseTest)                  cout << "Checking for fr returned" << endl;              MYASSERT(oui == returnedString);              MYASSERT(CL_FR == client.getResponseContentLanguages());              // Delete the instance for the next pass              if (verboseTest)                   cout << "Deleting the instance" << endl;              client.deleteInstance(                NAMESPACE,                frInstanceName);          } // end else active tests          //          //  TEST 7 - Round trip Test.          //  Modify Instance followed by Get Instance.          //          //  Modify an instance of the base class with an x-homer language          //  string and expect that the x-homer string is preserved on get          //  instance.          //  (x-homer is not one of the supported languages of the provider          //   but still should be returned when asked for)          //          //  Modify baseInstance with a UTF-16 string and char16 and expect that          //  they are preserved on get instance          //          cout << endl << "INSTANCE TEST 7: Modify Instance with ContentLanguageList = " <<                 LanguageParser::buildContentLanguageHeader(CL_HOMER) <<                 " and UTF-16 string." << endl;          if (!activeTest)          {              cout << "Active tests are disabled. Nothing to do for this test." << endl;          }          else          {              String doh = "doh!";              baseInstance.removeProperty (baseInstance.findProperty(CLPROP));              baseInstance.addProperty(CIMProperty(CIMName(CLPROP), doh));              baseInstance.removeProperty (baseInstance.findProperty(ROUNDTRIPSTRINGPROP));              baseInstance.addProperty(CIMProperty(CIMName(ROUNDTRIPSTRINGPROP), String(utf16Chars)));              baseInstance.removeProperty (baseInstance.findProperty(ROUNDTRIPCHARPROP));              baseInstance.addProperty(CIMProperty(CIMName(ROUNDTRIPCHARPROP),utf16Chars[0]));              client.setRequestContentLanguages(CL_HOMER);              if (verboseTest)                 cout << "Modifying the instance" << endl;              client.modifyInstance(NAMESPACE,                                  baseInstance,                                  includeQualifiers);              AcceptLanguageList acceptLangs7;              acceptLangs7.insert(LanguageTag("x-homer"), Real32(0.8));              client.setRequestAcceptLanguages(acceptLangs7);              if (verboseTest)                  cout << "Getting the instance just modified, using AcceptLanguageList = "                      << LanguageParser::buildAcceptLanguageHeader(acceptLangs7)                      << endl;              CIMInstance instance7 = client.getInstance(                                                       NAMESPACE,                                                       baseInstance.buildPath(sampleClass),                                                       localOnly,                                                       includeQualifiers,                                                       includeClassOrigin);              instance7.getProperty (                    instance7.findProperty(ROUNDTRIPSTRINGPROP)).                    getValue().                    get(returnedString);              instance7.getProperty (                    instance7.findProperty(ROUNDTRIPCHARPROP)).                    getValue().                    get(returnedChar16);              if (verboseTest)                    cout << "Checking the UTF-16 chars were preserved" << endl;              MYASSERT(expectedUTF16String == returnedString);              MYASSERT(utf16Chars[0] == returnedChar16);              instance7.getProperty (                    instance7.findProperty(CLPROP)).                    getValue().                    get(returnedString);              if (verboseTest)                    cout << "Checking for x-homer returned" << endl;              MYASSERT(returnedString == doh);              MYASSERT(CL_HOMER == client.getResponseContentLanguages());          } // end else active tests          //          //  TEST 8 - Exception test.          //  Expect an exception to be returned from the server          //  with a localized message in es locale.          //          //  Note: the provider will throw a not-supported exception          //  on delete instance requests.          //          AcceptLanguageList acceptLangs8;          if (skipICU)          {             // Not requesting translated messages from the provider             acceptLangs8.clear();          }          else          {             acceptLangs8.insert(LanguageTag("es"), Real32(1.0));             acceptLangs8.insert(LanguageTag("fr"), Real32(0.9));          }          client.setRequestAcceptLanguages(acceptLangs8);          cout << endl << "INSTANCE TEST 8: Delete Instance with AcceptLanguageList = " <<              LanguageParser::buildAcceptLanguageHeader(acceptLangs8) << endl;          // Try to delete baseInstance, expect an exception          if (verboseTest)                cout << "Deleting the instance, expecting to get a CIMException" << endl;          Boolean gotException = false;          try          {              client.deleteInstance(                                    NAMESPACE,                                    baseInstance.buildPath(sampleClass));          } catch (CIMException & ce)          {              if (verboseTest)                  cout << "Got the CIMException" << endl;              String message = ce.getMessage();              if(skipICU)              {                if (verboseTest)                  cout << "Checking for default language returned in the exception" << endl;                MYASSERT(CL_Dft == client.getResponseContentLanguages());                Uint32 n = message.find("default");                MYASSERT(n != PEG_NOT_FOUND);              }              else              {                if (verboseTest)                  cout << "Checking for es returned in the exception" << endl;                MYASSERT(CL_ES == client.getResponseContentLanguages());                MYASSERT(CL_ES == ce.getContentLanguages());                Uint32 n = message.find("ES");                MYASSERT(n != PEG_NOT_FOUND);              }              gotException = true;          }          MYASSERT(gotException == true);        }  // end for    }    catch(Exception& e)    {        PEGASUS_STD(cerr) << "Error in TestLocalizedInstances: "            << e.getMessage() << PEGASUS_STD(endl);        throw;    }}/*   Tests the globalization support of the Pegasus server by sending requests   that cause error messages to be returned.*/static void TestServerMessages( CIMClient& client,                                String reqLang,                                String rspLang,                                Boolean activeTest,                                Boolean verboseTest ){    try    {        //        // Vars for the getClass test        //        // Build the Accept-Languages for the getClass request using the lang        // specified by the user        AcceptLanguageList acceptLangs1;        if (reqLang.size() > 0)        {            acceptLangs1 = LanguageParser::parseAcceptLanguageHeader(reqLang);        }        // This is the "class not found" message expected back from the server.        // Since we don't know what the message text will be for a given langauge,        // we will use the message returned on the first request as the expected        // message for subsequent requests.        String expectedMsg;        // This is the language of the "class not found" message back from the server,        // as specified by the user        ContentLanguageList expectedCL;        if (rspLang.size() > 0)        {            expectedCL = LanguageParser::parseContentLanguageHeader(rspLang);        }        // Parms for the getClass API call        const CIMNamespaceName NAMESPACE = CIMNamespaceName ("root/SampleProvider");        const CIMName CLASSNAME = CIMName ("CIM_ANonExistentClassName");        Boolean localOnly = false;        Boolean includeQualifiers = true;        Boolean includeClassOrigin = false;        CIMClass rtnClass;        //        // Vars for enumerate sample instances test        //        // Build the Accept-Languages for the enumerate sample instances test        AcceptLanguageList acceptLangsDE;        if (skipICU)        {           // Not requesting translated messages from the provider           acceptLangsDE.clear();        }        else        {           acceptLangsDE.insert(LanguageTag("de"), Real32(0.1));           acceptLangsDE.insert(LanguageTag("x-aa"), Real32(0.2));           acceptLangsDE.insert(LanguageTag("x-bb"), Real32(0.3));        }        AcceptLanguageList acceptLangsFR;        if (skipICU)        {           // Not requesting translated messages from the provider           acceptLangsFR.clear();        }        else        {           acceptLangsFR.insert(LanguageTag("fr"), Real32(0.1));           acceptLangsFR.insert(LanguageTag("x-aa"), Real32(0.2));           acceptLangsFR.insert(LanguageTag("x-bb"), Real32(0.3));        }        AcceptLanguageList acceptLangsES;        if (skipICU)        {           // Not requesting translated messages from the provider           acceptLangsES.clear();        }        else        {           acceptLangsES.insert(LanguageTag("es"), Real32(0.1));           acceptLangsES.insert(LanguageTag("x-aa"), Real32(0.2));           acceptLangsES.insert(LanguageTag("x-bb"), Real32(0.3));        }        // The expected results from the enumerate        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_ES;        CL_ES.append(LanguageTag("es"));        String expectedESString = "ResourceBundleString ES";        cout << endl << "SERVER MESSAGE TESTS: Send requests that test server language support"                        << endl;        // Do a loop of requests.  This is useful when several instances of this        // program are run simultaneously, each with a different language.        for (int i = 0; i < 100; i ++)        {            //            // TEST 1 - Cause "class not found" server message            //            // Send a getClass request with a bad class name to cause an error message.            // Expect the error message to be returned in the language specified            // by the user.            //            try            {              //if (verboseTest)          //  cout << "Sending the getClass request " << i << endl;                client.setRequestAcceptLanguages(acceptLangs1);                rtnClass = client.getClass(            NAMESPACE,            CLASSNAME,            localOnly,            includeQualifiers,            includeClassOrigin);                // should not get here                throw Exception("did not get expected getClass exception");            }            catch (CIMException& ce)            {                if (ce.getCode() == CIM_ERR_NOT_FOUND)                {                   // Sanity check to make sure the bad class name is in the error                   // message                   Uint32 n = ce.getMessage().find(CLASSNAME.getString());

⌨️ 快捷键说明

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