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

📄 l10n.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Modified By: Vijay Eli, IBM (vijayeli@in.ibm.com) for bug#3101.//              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)////%/////////////////////////////////////////////////////////////////////////////#include <cstdlib>#include <iostream>#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/AcceptLanguageList.h>#include <Pegasus/Common/ContentLanguageList.h>#include <Pegasus/Common/LanguageParser.h>#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/Common/String.h>#include <Pegasus/Common/Array.h>#include <Pegasus/Common/InternalException.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;void drive_LanguageParser(){    // Test the LanguageTag parser    {        String tag1("en-US-mn-blah-blah");        String language;        String country;        String variant;        LanguageParser::parseLanguageTag(tag1, language, country, variant);        PEGASUS_TEST_ASSERT(language == "en");        PEGASUS_TEST_ASSERT(country == "US");        PEGASUS_TEST_ASSERT(variant == "mn-blah-blah");    }    // Test handling of Accept-Languages whitespace and comments    {        AcceptLanguageList al = LanguageParser::parseAcceptLanguageHeader(            " 	 en-US-mn (should not appear)  ,"            "(and)en-US-ca   (!!!)  ;(less) q(uality) = (just) 0.5 (half)  ");        PEGASUS_TEST_ASSERT(al.size() == 2);        PEGASUS_TEST_ASSERT(al.getLanguageTag(0).toString() == "en-US-mn");        PEGASUS_TEST_ASSERT(al.getQualityValue(0) == 1.0);        PEGASUS_TEST_ASSERT(al.getLanguageTag(1).toString() == "en-US-ca");        PEGASUS_TEST_ASSERT(al.getQualityValue(1) == 0.5);        PEGASUS_TEST_ASSERT(LanguageParser::buildAcceptLanguageHeader(al) ==            "en-US-mn,en-US-ca;q=0.500");    }    // Test handling of Content-Languages whitespace and comments    {        ContentLanguageList cl = LanguageParser::parseContentLanguageHeader(            " 	 en-US-mn (should not appear)  ,"            "(and)en-US-ca   (if you can imagine) (!!!)  ");        PEGASUS_TEST_ASSERT(cl.size() == 2);        PEGASUS_TEST_ASSERT(cl.getLanguageTag(0).toString() == "en-US-mn");        PEGASUS_TEST_ASSERT(cl.getLanguageTag(1).toString() == "en-US-ca");        PEGASUS_TEST_ASSERT(LanguageParser::buildContentLanguageHeader(cl) ==            "en-US-mn,en-US-ca");    }    // Test handling of non-ASCII characters in Content-Languages comment    {        String headerValue = "en-US (will add non-ASCII character in comment)";        headerValue[14] = 132;        ContentLanguageList cl =            LanguageParser::parseContentLanguageHeader(headerValue);        PEGASUS_TEST_ASSERT(cl.size() == 1);        PEGASUS_TEST_ASSERT(cl.getLanguageTag(0).toString() == "en-US");        PEGASUS_TEST_ASSERT(            LanguageParser::buildContentLanguageHeader(cl) == "en-US");    }    // Test handling of non-ASCII characters in Content-Languages value    {        String headerValue = "en-US-ca (will add non-ASCII character in tag)";        headerValue[4] = 132;        Boolean gotException = false;        try        {            ContentLanguageList cl =                LanguageParser::parseContentLanguageHeader(headerValue);        }        catch (const InvalidContentLanguageHeader&)        {            gotException = true;        }        PEGASUS_TEST_ASSERT(gotException);    }    // Test handling of trailing escape character in Content-Languages value    {        String headerValue = "en-US-ca (trailing escape character) \\";        Boolean gotException = false;        try        {            ContentLanguageList cl =                LanguageParser::parseContentLanguageHeader(headerValue);        }        catch (const InvalidContentLanguageHeader&)        {            gotException = true;        }        PEGASUS_TEST_ASSERT(gotException);    }}void drive_LanguageTag(){    try    {        // Test string value constructor and accessor methods        {            String tag1("en-US-mn");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).toString() == "en-US-mn");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getLanguage() == "en");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getCountry() == "US");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getVariant() == "mn");        }        {            String tag1("en-US-123");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).toString() == "en-US-123");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getLanguage() == "en");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getCountry() == "US");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getVariant() == "123");        }        {            String tag1("eng-1a-C3P0");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).toString() == "eng-1a-C3P0");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getLanguage() == "eng");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getCountry() == "1a");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getVariant() == "C3P0");        }        {            String tag1("en-my-weird-dialect");            PEGASUS_TEST_ASSERT(                LanguageTag(tag1).toString() == "en-my-weird-dialect");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getLanguage() == "en");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getCountry() == "my");            PEGASUS_TEST_ASSERT(                LanguageTag(tag1).getVariant() == "weird-dialect");        }        {            String tag1("en-quite-a-weird-dialect");            PEGASUS_TEST_ASSERT(                LanguageTag(tag1).toString() == "en-quite-a-weird-dialect");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getLanguage() == "en");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getCountry() == "");            PEGASUS_TEST_ASSERT(                LanguageTag(tag1).getVariant() == "quite-a-weird-dialect");        }        {            String tag1("x-pig-latin");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).toString() == "x-pig-latin");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getLanguage() == "");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getCountry() == "");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getVariant() == "");        }        {            String tag1("i-latin-for-pigs");            PEGASUS_TEST_ASSERT(                LanguageTag(tag1).toString() == "i-latin-for-pigs");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getLanguage() == "");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getCountry() == "");            PEGASUS_TEST_ASSERT(LanguageTag(tag1).getVariant() == "");        }        // Test copy constructor, assignment operator, and equality operator        LanguageTag lt1("en-US-ca");        LanguageTag lt2(lt1);        LanguageTag lt3 = lt2;        LanguageTag lt4("EN-us-Ca");        LanguageTag lt5("en-US-mn");        LanguageTag lt6;        LanguageTag lt7 = lt6;        LanguageTag lt8 = lt1;        lt7 = lt1;        lt7 = lt7;        lt8 = lt6;        lt8 = lt1;        PEGASUS_TEST_ASSERT(lt1 == lt2);        PEGASUS_TEST_ASSERT(lt1 == lt3);        PEGASUS_TEST_ASSERT(lt2 == lt3);        PEGASUS_TEST_ASSERT(lt1 == lt4);        PEGASUS_TEST_ASSERT(lt1 != lt5);        PEGASUS_TEST_ASSERT(lt3 != lt5);        PEGASUS_TEST_ASSERT(lt1 == lt8);        PEGASUS_TEST_ASSERT(lt7 == lt8);        // Test invalid language tag:  Empty string        {            Boolean gotException = false;            try            {                LanguageTag lt("");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Digit in primary subtag        {            Boolean gotException = false;            try            {                LanguageTag lt("e4-US-ca");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Primary subtag too short        {            Boolean gotException = false;            try            {                LanguageTag lt("e-US-ca");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Primary subtag too long        {            Boolean gotException = false;            try            {                LanguageTag lt("engl-US-ca");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Primary subtag too long        {            Boolean gotException = false;            try            {                LanguageTag lt("englishman-US-ca");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Single character second subtag        {            Boolean gotException = false;            try            {                LanguageTag lt("en-U-ca");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Second subtag too long        {            Boolean gotException = false;            try            {                LanguageTag lt("en-UnitedStates-ca");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Third subtag too long        {            Boolean gotException = false;            try            {                LanguageTag lt("en-US-california");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Empty subtag        {            Boolean gotException = false;            try            {                LanguageTag lt("en--ca");            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Non-ASCII primary tag        {            Boolean gotException = false;            try            {                String tag = "en-US-ca";                tag[1] = 132;                LanguageTag lt(tag);            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test invalid language tag:  Non-ASCII subtag        {            Boolean gotException = false;            try            {                String tag = "en-US-ca";                tag[4] = 132;                LanguageTag lt(tag);            }            catch (Exception&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test uninitialized object:  getLanguage() method        {            Boolean gotException = false;            LanguageTag lt;            try            {                String language = lt.getLanguage();            }            catch (UninitializedObjectException&)            {                gotException = true;            }            PEGASUS_TEST_ASSERT(gotException);        }        // Test uninitialized object:  getCountry() method        {            Boolean gotException = false;            LanguageTag lt;            try            {                String country = lt.getCountry();            }            catch (UninitializedObjectException&)            {                gotException = true;            }

⌨️ 快捷键说明

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