X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e01a788ee05125b4fefa01a5b11f4088915cb54e..59d866ad8510b8674e6cc7cdf218c4c0010d3925:/tests/filename/filenametest.cpp diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index c1a9c5e6d4..a9fab6197c 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -125,6 +125,7 @@ private: CPPUNIT_TEST( TestStrip ); CPPUNIT_TEST( TestNormalize ); CPPUNIT_TEST( TestReplace ); + CPPUNIT_TEST( TestGetHumanReadable ); #ifdef __WINDOWS__ CPPUNIT_TEST( TestShortLongPath ); #endif // __WINDOWS__ @@ -139,6 +140,7 @@ private: void TestStrip(); void TestNormalize(); void TestReplace(); + void TestGetHumanReadable(); #ifdef __WINDOWS__ void TestShortLongPath(); #endif // __WINDOWS__ @@ -478,6 +480,39 @@ void FileNameTestCase::TestReplace() fn.GetFullPath(wxPATH_UNIX) ); } +void FileNameTestCase::TestGetHumanReadable() +{ + static const struct TestData + { + const char *result; + int size; + int prec; + wxSizeConvention conv; + } testData[] = + { + { "NA", 0, 1, wxSIZE_CONV_TRADITIONAL }, + { "2.0 KB", 2000, 1, wxSIZE_CONV_TRADITIONAL }, + { "1.953 KiB", 2000, 3, wxSIZE_CONV_IEC }, + { "2.000 KB", 2000, 3, wxSIZE_CONV_SI }, + { "297 KB", 304351, 0, wxSIZE_CONV_TRADITIONAL }, + { "304 KB", 304351, 0, wxSIZE_CONV_SI }, + }; + + for ( unsigned n = 0; n < WXSIZEOF(testData); n++ ) + { + const TestData& td = testData[n]; + + CPPUNIT_ASSERT_EQUAL + ( + td.result, + wxFileName::GetHumanReadableSize(td.size, "NA", td.prec, td.conv) + ); + } + + // also test the default convention value + CPPUNIT_ASSERT_EQUAL( "1.4 MB", wxFileName::GetHumanReadableSize(1512993, "") ); +} + void FileNameTestCase::TestStrip() { CPPUNIT_ASSERT_EQUAL( "", wxFileName::StripExtension("") );