]> git.saurik.com Git - wxWidgets.git/blame - tests/file/filetest.cpp
Disable wxEVT_COMMAND_LIST_ITEM_FOCUSED test for wxMSW.
[wxWidgets.git] / tests / file / filetest.cpp
CommitLineData
227989f3
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/file/filetest.cpp
3// Purpose: wxFile unit test
4// Author: Vadim Zeitlin
5// Created: 2009-09-12
6// RCS-ID: $Id$
7// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8///////////////////////////////////////////////////////////////////////////////
9
10// ----------------------------------------------------------------------------
11// headers
12// ----------------------------------------------------------------------------
13
14#include "testprec.h"
15
16#ifdef __BORLANDC__
17 #pragma hdrstop
18#endif
19
20#if wxUSE_FILE
21
22#include "wx/file.h"
23
24#include "testfile.h"
25
26// ----------------------------------------------------------------------------
27// test class
28// ----------------------------------------------------------------------------
29
30class FileTestCase : public CppUnit::TestCase
31{
32public:
33 FileTestCase() { }
34
35private:
36 CPPUNIT_TEST_SUITE( FileTestCase );
37 CPPUNIT_TEST( RoundTripUTF8 );
38 CPPUNIT_TEST( RoundTripUTF16 );
39 CPPUNIT_TEST( RoundTripUTF32 );
69fc8587 40 CPPUNIT_TEST( TempFile );
227989f3
VZ
41 CPPUNIT_TEST_SUITE_END();
42
43 void RoundTripUTF8() { DoRoundTripTest(wxConvUTF8); }
44 void RoundTripUTF16() { DoRoundTripTest(wxMBConvUTF16()); }
45 void RoundTripUTF32() { DoRoundTripTest(wxMBConvUTF32()); }
46
47 void DoRoundTripTest(const wxMBConv& conv);
69fc8587 48 void TempFile();
227989f3
VZ
49
50 wxDECLARE_NO_COPY_CLASS(FileTestCase);
51};
52
53// ----------------------------------------------------------------------------
54// CppUnit macros
55// ----------------------------------------------------------------------------
56
57CPPUNIT_TEST_SUITE_REGISTRATION( FileTestCase );
58CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileTestCase, "FileTestCase" );
59
60// ----------------------------------------------------------------------------
61// tests implementation
62// ----------------------------------------------------------------------------
63
64void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
65{
66 TestFile tf;
67
68 const wxString data = "Hello\0UTF";
69
70 {
71 wxFile fout(tf.GetName(), wxFile::write);
72 CPPUNIT_ASSERT( fout.IsOpened() );
73
74 CPPUNIT_ASSERT( fout.Write(data, conv) );
75 }
76
77 {
78 wxFile fin(tf.GetName(), wxFile::read);
79 CPPUNIT_ASSERT( fin.IsOpened() );
80
bf24fcdd 81 const ssize_t len = fin.Length();
227989f3
VZ
82 wxCharBuffer buf(len);
83 CPPUNIT_ASSERT_EQUAL( len, fin.Read(buf.data(), len) );
84
85 wxWCharBuffer wbuf(conv.cMB2WC(buf));
86#if wxUSE_UNICODE
87 CPPUNIT_ASSERT_EQUAL( data, wbuf );
88#else // !wxUSE_UNICODE
89 CPPUNIT_ASSERT
90 (
91 memcmp(wbuf, L"Hello\0UTF", data.length()*sizeof(wchar_t)) == 0
92 );
93#endif // wxUSE_UNICODE/!wxUSE_UNICODE
94 }
95}
96
69fc8587
FM
97void FileTestCase::TempFile()
98{
99 wxTempFile tmpFile;
100 CPPUNIT_ASSERT( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) );
101 CPPUNIT_ASSERT( tmpFile.Commit() );
102 CPPUNIT_ASSERT( wxRemoveFile(wxT("test2")) );
103}
104
227989f3 105#endif // wxUSE_FILE