]> git.saurik.com Git - wxWidgets.git/blame - tests/file/filetest.cpp
Fix warnings in the MSW IE backend.
[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 );
a9f3fb07 37#if wxUSE_UNICODE
227989f3
VZ
38 CPPUNIT_TEST( RoundTripUTF8 );
39 CPPUNIT_TEST( RoundTripUTF16 );
40 CPPUNIT_TEST( RoundTripUTF32 );
a9f3fb07 41#endif // wxUSE_UNICODE
69fc8587 42 CPPUNIT_TEST( TempFile );
227989f3
VZ
43 CPPUNIT_TEST_SUITE_END();
44
a9f3fb07 45#if wxUSE_UNICODE
227989f3
VZ
46 void RoundTripUTF8() { DoRoundTripTest(wxConvUTF8); }
47 void RoundTripUTF16() { DoRoundTripTest(wxMBConvUTF16()); }
48 void RoundTripUTF32() { DoRoundTripTest(wxMBConvUTF32()); }
a9f3fb07 49#endif // wxUSE_UNICODE
227989f3
VZ
50
51 void DoRoundTripTest(const wxMBConv& conv);
69fc8587 52 void TempFile();
227989f3
VZ
53
54 wxDECLARE_NO_COPY_CLASS(FileTestCase);
55};
56
57// ----------------------------------------------------------------------------
58// CppUnit macros
59// ----------------------------------------------------------------------------
60
61CPPUNIT_TEST_SUITE_REGISTRATION( FileTestCase );
62CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileTestCase, "FileTestCase" );
63
64// ----------------------------------------------------------------------------
65// tests implementation
66// ----------------------------------------------------------------------------
67
a9f3fb07
VZ
68#if wxUSE_UNICODE
69
227989f3
VZ
70void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
71{
72 TestFile tf;
73
24b4db9b
VZ
74 // Explicit length is needed because of the embedded NUL.
75 const wxString data("Hello\0UTF!", 10);
227989f3
VZ
76
77 {
78 wxFile fout(tf.GetName(), wxFile::write);
79 CPPUNIT_ASSERT( fout.IsOpened() );
80
81 CPPUNIT_ASSERT( fout.Write(data, conv) );
82 }
83
84 {
85 wxFile fin(tf.GetName(), wxFile::read);
86 CPPUNIT_ASSERT( fin.IsOpened() );
87
bf24fcdd 88 const ssize_t len = fin.Length();
227989f3
VZ
89 wxCharBuffer buf(len);
90 CPPUNIT_ASSERT_EQUAL( len, fin.Read(buf.data(), len) );
91
24b4db9b
VZ
92 wxString dataReadBack(buf, conv, len);
93 CPPUNIT_ASSERT_EQUAL( data, dataReadBack );
227989f3
VZ
94 }
95}
96
a9f3fb07
VZ
97#endif // wxUSE_UNICODE
98
69fc8587
FM
99void FileTestCase::TempFile()
100{
101 wxTempFile tmpFile;
102 CPPUNIT_ASSERT( tmpFile.Open(wxT("test2")) && tmpFile.Write(wxT("the answer is 42")) );
103 CPPUNIT_ASSERT( tmpFile.Commit() );
104 CPPUNIT_ASSERT( wxRemoveFile(wxT("test2")) );
105}
106
227989f3 107#endif // wxUSE_FILE