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

📄 g11ntest.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        if (verboseTest)        cout << "Checking that the UTF-16 was preserved in the property name" << endl;    Uint32 idx = rtnClass.findProperty(name2);  // name2 is UTF16        MYASSERT(idx != PEG_NOT_FOUND);        if (verboseTest)        cout << "Checking that the UTF-16 was preserved in the qualifier" << endl;    CIMProperty rtnProp = rtnClass.getProperty(idx);        idx = rtnProp.findQualifier(qualDecl.getName());        MYASSERT(idx != PEG_NOT_FOUND);        CIMQualifier rtnQual = rtnProp.getQualifier(idx);        MYASSERT(rtnQual.getValue() == utf16String);    if (verboseTest)      cout << "Modifying the class" << endl;    CIMName name3("anotherprop");        CIMProperty prop5(name3, fred);        CIMQualifier qual3(qualDecl.getName(),      // UTF16 qualifier                           qualDecl.getValue(),                           qualDecl.getFlavor());        CIMProperty prop6 = prop5.addQualifier(qual3);        cimClass.addProperty(prop6);    client.modifyClass(NAMESPACE,               cimClass);        if (verboseTest)        cout << "Getting the class that was just modified" << endl;        rtnClass = client.getClass(                   NAMESPACE,                   className,                   true,                   true);        if (verboseTest)        cout << "Checking that the UTF-16 was preserved in the property name" << endl;    idx = rtnClass.findProperty(name2);  // name2 is UTF16        MYASSERT(idx != PEG_NOT_FOUND);    idx = rtnClass.findProperty(name3);        MYASSERT(idx != PEG_NOT_FOUND);        if (verboseTest)        cout << "Checking that the UTF-16 was preserved in the qualifier" << endl;    rtnProp = rtnClass.getProperty(idx);        idx = rtnProp.findQualifier(qualDecl.getName());        MYASSERT(idx != PEG_NOT_FOUND);        rtnQual = rtnProp.getQualifier(idx);        MYASSERT(rtnQual.getValue() == utf16String);    //        // Clean up the repository        //        if (verboseTest)        cout << endl << "Cleaning up the repository" << endl;        if (verboseTest)        cout << "Delete the qualifier" << endl;    client.deleteQualifier(NAMESPACE, qualDeclName);        if (verboseTest)        cout << "Deleting the class" << endl;    client.deleteClass(NAMESPACE, className);    //    //  TEST 3 - Create namespace        //    //  Create a namespace with UTF-16 in the namespace name, and    //  add class to the namespace.    //    cout << endl << "REPOSITORY TEST 3: Create Namespace with UTF-16 chars in the name" << endl;    if (!utfRepNames)    {      // Since namespaces are only directory names, no point in doing this      // if the utfrep option wasn't set.      cout << "Note: Skipping this test because the utfrep option was not used"           << endl;    }    else    {      if (verboseTest)        cout << endl << "Deleting the old namespace in case it was there from before."         << endl;      CIMName __nameSpace = "__NameSpace";      Array<CIMObjectPath> enumNamespaces = client.enumerateInstanceNames(                      CIMNamespaceName("root"),                      __nameSpace);      for (Uint32 i = 0; i < enumNamespaces.size(); i++)          {        Array<CIMKeyBinding> kb = enumNamespaces[i].getKeyBindings();        if (kb[0].getValue() == utf16FileName)        {          client.deleteInstance(ROOT_NAMESPACE, enumNamespaces[i]);        }      }      if (verboseTest)        cout << endl << "Creating the namespace" << endl;      CIMInstance nsInstance(__nameSpace);      CIMName nsPropName("Name");      CIMProperty nsProp(nsPropName,                 CIMValue(utf16FileName));      nsInstance.addProperty(nsProp);      CIMObjectPath nsInstanceName = client.createInstance(ROOT_NAMESPACE,                                   nsInstance);      if (verboseTest)        cout << endl << "Getting the namespace just created" << endl;      CIMInstance rtnNSInst = client.getInstance(ROOT_NAMESPACE, nsInstanceName);      idx = rtnNSInst.findProperty(nsPropName);      MYASSERT(idx != PEG_NOT_FOUND);      CIMProperty rtnNSProp = rtnNSInst.getProperty(idx);      String rtnNSName;      rtnNSProp.getValue().get(rtnNSName);      MYASSERT(rtnNSName == utf16FileName);      if (verboseTest)        cout << endl << "Creating classes in that namespace" << endl;      String root("root/");      root.append(utf16FileName);      CIMNamespaceName ns(root);      // Do a little inheriting with UTF-16 class names      CIMName baseClassName(utf16FileName);      CIMClass baseClass(baseClassName);      CIMName basePropName("baseProp1");      CIMValue basePropValue("fred");      CIMProperty baseProp(basePropName, basePropValue);      baseClass.addProperty(baseProp);      CIMName inhClassName(&utf16Chars[1]);      CIMClass inhClass(inhClassName, baseClassName);      CIMName inhPropName("inhProp1");      CIMValue inhPropValue("fred");      CIMProperty inhProp(inhPropName, inhPropValue);      inhClass.addProperty(inhProp);      client.createClass(ns, baseClass);      client.createClass(ns, inhClass);      if (verboseTest)        cout << endl << "Deleting classes in that namespace" << endl;      client.deleteClass(ns, inhClassName);      client.deleteClass(ns, baseClassName);      if (verboseTest)        cout << endl << "Deleting the namespace" << endl;      client.deleteInstance(ROOT_NAMESPACE, nsInstanceName);    }  // endif utfrep    }    catch(Exception& e)    {      PEGASUS_STD(cerr) << "Error in TestLocalizedRepository: "            << e.getMessage() << PEGASUS_STD(endl);      throw;    }}/*   Tests the globalization support of the LocalizedProvider   for the method operations*/static void TestLocalizedMethods( CIMClient& client,                                  Boolean activeTest,                                  Boolean verboseTest ){  const CIMNamespaceName NAMESPACE = CIMNamespaceName ("root/SampleProvider");  const CIMName CLASSNAME = CIMName ("Sample_LocalizedProviderClass");  const String INPARAM1 = "inStr";  const String INPARAM2 = "inChar16";  const CIMName METHOD = CIMName("UTFMethod");  const CIMObjectPath REFERENCE = CIMObjectPath("Sample_LocalizedProviderClass.Identifier=0");  // Array of UTF-16 chars to be sent and received to the server.  // Note: the first 3 chars are taken from section 3.3.2 of the CIM-over-HTTP spec.  // The next 2 chars are a UTF-16 surrogate pair  Char16 hangugo[] = {0xD55C, 0xAD6D, 0xC5B4,            0xdbc0,            0xdc01,                    'g','l','o','b','a','l',            0x00};  try  {     // Before we begin, set the language objects to be sent to the provider     AcceptLanguageList AL_DE;     AL_DE.insert(LanguageTag("de"), Real32(0.8));     ContentLanguageList CL_DE;     CL_DE.append(LanguageTag("de"));     client.setRequestAcceptLanguages(AL_DE);     client.setRequestContentLanguages(CL_DE);     //     //  TEST 1 - Invoke Method with UTF-16 in input parameters, output parameters     //  and return value.     //     //  This will also check that Accept-Language and Content-Language are     //  are sent to and received from a Method Provider.     cout << endl << "METHOD TEST 1: Invoke Method with UTF-16 parameters" << endl;     // Strings sent to the provider     String inString(utf16Chars);     Char16 inChar16 = utf16Chars[1];     // Expected strings from the provider     String outString(utf16Chars);     Char16 outChar16 = utf16Chars[2];     String expectedRtnString(utf16Chars);     // Strings returned by the provider     String rtnString;     String outParam1;     Char16 outParam2;     Array<CIMParamValue> inParams;     Array<CIMParamValue> outParams;     inParams.append( CIMParamValue(  INPARAM1, CIMValue( inString ) ) );     inParams.append( CIMParamValue(  INPARAM2, CIMValue( inChar16 ) ) );     if (verboseTest)        cout << "Invoking the method" << endl;     CIMValue retValue = client.invokeMethod(        NAMESPACE,        REFERENCE,        METHOD,        inParams,        outParams);     if (verboseTest)        cout << "Checking for UTF-16 chars returned" << endl;     retValue.get(rtnString);     MYASSERT (expectedRtnString == rtnString);     CIMValue paramVal = outParams[0].getValue();     paramVal.get( outParam1 );     MYASSERT (outString == outParam1);     paramVal = outParams[1].getValue();     paramVal.get( outParam2 );     MYASSERT (outChar16 == outParam2);     if (verboseTest)        cout << "Checking returned Content-Language = " <<            LanguageParser::buildContentLanguageHeader(CL_DE) << endl;     MYASSERT(CL_DE == client.getResponseContentLanguages());     //     //  TEST 2 - Invoke method with UTF-16 in the method name.     //     //  This will test the URI encoding and decoding of UTF-8 in the CIMMethod     //  HTTP header     cout << endl << "METHOD TEST 2: Invoke Method with UTF-16 method name" << endl;     String methodName(hangugo);     if (verboseTest)        cout << "Invoking the method" << endl;     CIMValue retValue1 = client.invokeMethod(        NAMESPACE,        REFERENCE,        methodName,        inParams,        outParams);     // Check UTF-16 in the return value just to make sure that the method     // was called on the provider.     String expectedRtnString1(hangugo);     String rtnString1;     if (verboseTest)        cout << "Checking for UTF-16 chars returned" << endl;     retValue1.get(rtnString1);     MYASSERT (expectedRtnString1 == rtnString1);  }  catch(Exception& e)  {    PEGASUS_STD(cerr) << "Error in TestLocalizedMethod: " << e.getMessage() << PEGASUS_STD(endl);    throw;  }}/* Enumerates instances of the sample classes using a given AcceptLanguageList,   and checks the language of the response.*/static Array<CIMInstance> EnumerateSampleInstances(CIMClient &client,                                     AcceptLanguageList & acceptLangs,                                     ContentLanguageList & contentLangs,                                     String & expectedStr,                                     Boolean verboseTest){  const CIMNamespaceName NAMESPACE = CIMNamespaceName ("root/SampleProvider");  const CIMName CLASSNAME = CIMName ("Sample_LocalizedProviderClass");  Boolean deepInheritance = false;  Boolean localOnly = false;  Boolean includeQualifiers = true;  Boolean includeClassOrigin = false;  ContentLanguageList CL_EN;  CL_EN.append(LanguageTag("en"));  const String RBPROP = "ResourceBundleString";  String expectedDftString = "ResourceBundleString DEFAULT";  client.setRequestAcceptLanguages(acceptLangs);  Array<CIMInstance> cimNInstances =                     client.enumerateInstances(NAMESPACE,  CLASSNAME, deepInheritance,                                               localOnly,  includeQualifiers,                                               includeClassOrigin );  if (verboseTest)      cout << "Found " << cimNInstances.size() << " Instances of " << CLASSNAME << endl;  MYASSERT(cimNInstances.size() == 3);  if (skipICU)  {      if (verboseTest)          cout << "Checking expected response ContentLanguageList: " <<            LanguageParser::buildContentLanguageHeader(CL_EN) << endl;      // Note - the LocalizedProvider is setting en in Content-Languages to override      // the MessageLoader.      // Otherwise, Content-Languages would be empty since Accept-Languages was empty.      MYASSERT(CL_EN == client.getResponseContentLanguages());  }  else  {      if (verboseTest)          cout << "Checking expected response ContentLanguageList: " <<              LanguageParser::buildContentLanguageHeader(contentLangs) << endl;      MYASSERT(contentLangs == client.getResponseContentLanguages());  }  if (verboseTest)      cout << "Checking the returned string in each instance" << endl;

⌨️ 快捷键说明

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