Esempio n. 1
0
    // test that the conversion between str and wcs (subject to flags) succeeds
    //
    // the first argument is the index in the test array and is used solely for
    // diagnostics
    void Test(size_t n, wxMBConv& conv) const
    {
        if ( str )
        {
            wxWCharBuffer wbuf = conv.cMB2WC(str);

            if ( wcs )
            {
                CPPUNIT_ASSERT_MESSAGE
                (
                    Message(n, "MB2WC failed"),
                    wbuf.data()
                );

                CPPUNIT_ASSERT_MESSAGE
                (
                    Message(n, "MB2WC", wbuf, wcs),
                    wxStrcmp(wbuf, wcs) == 0
                );
            }
            else // conversion is supposed to fail
            {
                CPPUNIT_ASSERT_MESSAGE
                (
                    Message(n, "MB2WC succeeded"),
                    !wbuf.data()
                );
            }
        }

        if ( wcs && !(flags & ONLY_MB2WC) )
        {
            wxCharBuffer buf = conv.cWC2MB(wcs);

            if ( str )
            {
                CPPUNIT_ASSERT_MESSAGE
                (
                    Message(n, "WC2MB failed"),
                    buf.data()
                );

                CPPUNIT_ASSERT_MESSAGE
                (
                    Message(n, "WC2MB", buf, str),
                    strcmp(buf, str) == 0
                );
            }
            else
            {
                CPPUNIT_ASSERT_MESSAGE
                (
                    Message(n, "WC2MB succeeded"),
                    !buf.data()
                );
            }
        }
    }
Esempio n. 2
0
bool CTextFile::WriteLine(const wxString& line, const wxMBConv& conv)
{
	wxCHECK_MSG(m_file.IsOpened(), false, wxT("Trying to read from closed file."));
	wxCHECK_MSG((m_mode == write), false, wxT("Trying to read from non-readable file."));

	// Ensures that use of newlines/carriage-returns matches the OS
	wxString result = wxTextBuffer::Translate(line);
	
	// Only add line-breaks between lines, as otherwise the number of
	// lines would grow as the result of the addition of an empty line,
	// at the end of the file.
	if (m_file.Tell() > 0) {
		result = wxTextBuffer::GetEOL() + result;
	}

	wxCharBuffer strBuffer = conv.cWC2MB(result);
	if (strBuffer) {
		const size_t length = strlen(strBuffer);

		return (m_file.Write(strBuffer, length) == length);
	}
	
	return false;
}