コード例 #1
0
ファイル: stdstrings.cpp プロジェクト: czxxjtu/wxPython-1
void StdStringTestCase::StdConversion()
{
    std::string strStd("std::string value");
    wxStdWideString strStdWide(L"std::wstring value");

    wxString s1(strStd);
    CPPUNIT_ASSERT_EQUAL( "std::string value", s1 );

    wxString s2(strStdWide);
    CPPUNIT_ASSERT_EQUAL( "std::wstring value", s2 );

    wxString s3;
    s3 = strStd;
    CPPUNIT_ASSERT_EQUAL( "std::string value", s3 );
    s3 = strStdWide;
    CPPUNIT_ASSERT_EQUAL( "std::wstring value", s3 );

    wxString s4("hello");

    // wxString -> std::string conversion is only available in wxUSE_STL case,
    // because it conflicts with conversion to const char*/wchar_t*:
#if wxUSE_STL
    std::string s5 = s4;
    CPPUNIT_ASSERT_EQUAL( "hello", s5 );

    wxStdWideString s6 = s4;
    CPPUNIT_ASSERT_EQUAL( "hello", s6 );
#endif

    std::string s7(s4);
    CPPUNIT_ASSERT( s7 == "hello" );

    wxStdWideString s8(s4);
    CPPUNIT_ASSERT( s8 == "hello" );
}
コード例 #2
0
void StdStringTestCase::StdConversion()
{
    std::string strStd("std::string value");
    wxStdWideString strStdWide(L"std::wstring value");

    wxString s1(strStd);
    CPPUNIT_ASSERT_EQUAL( "std::string value", s1 );

    wxString s2(strStdWide);
    CPPUNIT_ASSERT_EQUAL( "std::wstring value", s2 );

    wxString s3;
    s3 = strStd;
    CPPUNIT_ASSERT_EQUAL( "std::string value", s3 );
    s3 = strStdWide;
    CPPUNIT_ASSERT_EQUAL( "std::wstring value", s3 );

    wxString s4("hello");

    // notice that implicit wxString -> std::string conversion is only
    // available in wxUSE_STL case, because it conflicts with conversion to
    // const char*/wchar_t*
#if wxUSE_STL && wxUSE_UNSAFE_WXSTRING_CONV
    std::string s5 = s4;
#else
    std::string s5 = s4.ToStdString();
#endif
    CPPUNIT_ASSERT_EQUAL( "hello", s5 );

#if wxUSE_STL
    wxStdWideString s6 = s4;
#else
    wxStdWideString s6 = s4.ToStdWstring();
#endif
    CPPUNIT_ASSERT_EQUAL( "hello", s6 );

#if wxUSE_UNSAFE_WXSTRING_CONV
    std::string s7(s4);
    CPPUNIT_ASSERT( s7 == "hello" );
#endif

    wxStdWideString s8(s4);
    CPPUNIT_ASSERT( s8 == "hello" );

    std::string s9("\xF0\x9F\x90\xB1\0\xE7\x8C\xAB", 9); /* U+1F431 U+0000 U+732B */
    wxString s10 = wxString::FromUTF8(s9);
    CPPUNIT_ASSERT_EQUAL( s9, s10.ToStdString(wxConvUTF8) );

    std::string s11("xyz\0\xFF", 5); /* an invalid UTF-8 sequence */
    CPPUNIT_ASSERT_EQUAL( wxString::FromUTF8(s11), "" );
}