Merge branch 'linux-spec-files'
wxFile and wxTextFile for working with special/non-seekable files.
This commit is contained in:
@@ -139,4 +139,33 @@ void FileTestCase::TempFile()
|
||||
CPPUNIT_ASSERT( wxRemoveFile(wxT("test2")) );
|
||||
}
|
||||
|
||||
#ifdef __LINUX__
|
||||
|
||||
// Check that GetSize() works correctly for special files.
|
||||
TEST_CASE("wxFile::Special", "[file][linux][special-file]")
|
||||
{
|
||||
// We can't test /proc/kcore here, unlike in the similar
|
||||
// wxFileName::GetSize() test, as wxFile must be able to open it (at least
|
||||
// for reading) and usually we don't have the permissions to do it.
|
||||
|
||||
// This file is not seekable and has 0 size, but can still be read.
|
||||
wxFile fileProc("/proc/diskstats");
|
||||
CHECK( fileProc.IsOpened() );
|
||||
|
||||
wxString s;
|
||||
CHECK( fileProc.ReadAll(&s) );
|
||||
CHECK( !s.empty() );
|
||||
|
||||
// All files in /sys seem to have size of 4KiB currently, even if they
|
||||
// don't have that much data in them.
|
||||
wxFile fileSys("/sys/power/state");
|
||||
CHECK( fileSys.Length() == 4096 );
|
||||
CHECK( fileSys.IsOpened() );
|
||||
CHECK( fileSys.ReadAll(&s) );
|
||||
CHECK( !s.empty() );
|
||||
CHECK( s.length() < 4096 );
|
||||
}
|
||||
|
||||
#endif // __LINUX__
|
||||
|
||||
#endif // wxUSE_FILE
|
||||
|
@@ -1049,3 +1049,18 @@ void FileNameTestCase::TestShortcuts()
|
||||
}
|
||||
|
||||
#endif // __WINDOWS__
|
||||
|
||||
#ifdef __LINUX__
|
||||
|
||||
// Check that GetSize() works correctly for special files.
|
||||
TEST_CASE("wxFileName::GetSizeSpecial", "[filename][linux][special-file]")
|
||||
{
|
||||
wxULongLong size = wxFileName::GetSize("/proc/kcore");
|
||||
INFO( "size of /proc/kcore=" << size );
|
||||
CHECK( size > 0 );
|
||||
|
||||
// All files in /sys seem to have size of 4KiB currently.
|
||||
CHECK( wxFileName::GetSize("/sys/power/state") == 4096 );
|
||||
}
|
||||
|
||||
#endif // __LINUX__
|
||||
|
@@ -338,5 +338,29 @@ void TextFileTestCase::ReadBig()
|
||||
f[NUM_LINES - 1] );
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEXTFILE
|
||||
#ifdef __LINUX__
|
||||
|
||||
// Check if using wxTextFile with special files, whose reported size doesn't
|
||||
// correspond to the real amount of data in them, works.
|
||||
TEST_CASE("wxTextFile::Special", "[textfile][linux][special-file]")
|
||||
{
|
||||
SECTION("/proc")
|
||||
{
|
||||
wxTextFile f;
|
||||
CHECK( f.Open("/proc/diskstats") );
|
||||
CHECK( f.GetLineCount() > 1 );
|
||||
}
|
||||
|
||||
SECTION("/sys")
|
||||
{
|
||||
wxTextFile f;
|
||||
CHECK( f.Open("/sys/power/state") );
|
||||
REQUIRE( f.GetLineCount() == 1 );
|
||||
INFO( "/sys/power/state contains \"" << f[0] << "\"" );
|
||||
CHECK( f[0].find("mem") != wxString::npos );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __LINUX__
|
||||
|
||||
#endif // wxUSE_TEXTFILE
|
||||
|
Reference in New Issue
Block a user