1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/interactive/output.cpp
3 // Purpose: Miscellaneous tests NOT requiring user input, just user checks
4 // Author: Francesco Montorsi (extracted from console sample)
7 // Copyright: (c) 2010 wxWidgets team
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
25 // conditional compilation
26 // ----------------------------------------------------------------------------
30 #define TEST_INFO_FUNCTIONS
31 #define TEST_STACKWALKER
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 class InteractiveOutputTestCase
: public CppUnit
::TestCase
42 InteractiveOutputTestCase() { }
45 CPPUNIT_TEST_SUITE( InteractiveOutputTestCase
);
46 CPPUNIT_TEST( TestDllListLoaded
);
47 CPPUNIT_TEST( TestMimeEnum
);
48 CPPUNIT_TEST( TestMimeAssociate
);
49 CPPUNIT_TEST( TestMimeFilename
);
50 CPPUNIT_TEST( TestOsInfo
);
51 CPPUNIT_TEST( TestPlatformInfo
);
52 CPPUNIT_TEST( TestUserInfo
);
53 CPPUNIT_TEST( TestStackWalk
);
54 CPPUNIT_TEST( TestStandardPaths
);
55 CPPUNIT_TEST( TestFSVolume
);
56 CPPUNIT_TEST_SUITE_END();
58 void TestDllListLoaded();
60 void TestMimeAssociate();
61 void TestMimeFilename();
63 void TestPlatformInfo();
66 void TestStandardPaths();
69 wxDECLARE_NO_COPY_CLASS(InteractiveOutputTestCase
);
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 //CPPUNIT_TEST_SUITE_REGISTRATION( InteractiveOutputTestCase );
77 // do not run this test by default!
79 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InteractiveOutputTestCase
, "InteractiveOutputTestCase" );
81 // ============================================================================
83 // ============================================================================
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 #if !defined(__WXMSW__) && !defined(__UNIX__)
93 #include "wx/dynlib.h"
95 void InteractiveOutputTestCase
::TestDllListLoaded()
98 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
100 wxPuts("Loaded modules:");
101 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary
::ListLoaded();
102 const size_t count
= dlls
.GetCount();
103 for ( size_t n
= 0; n
< count
; ++n
)
105 const wxDynamicLibraryDetails
& details
= dlls
[n
];
106 printf("%-45s", (const char *)details
.GetPath().mb_str());
108 void *addr
wxDUMMY_INITIALIZE(NULL
);
109 size_t len
wxDUMMY_INITIALIZE(0);
110 if ( details
.GetAddress(&addr
, &len
) )
112 printf(" %08lx:%08lx",
113 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
116 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
119 wxPuts(wxEmptyString
);
120 #endif // TEST_DYNLIB
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 #include "wx/mimetype.h"
130 void InteractiveOutputTestCase
::TestMimeEnum()
133 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
135 wxArrayString mimetypes
;
137 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
139 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
144 for ( size_t n
= 0; n
< count
; n
++ )
146 wxFileType
*filetype
=
147 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
150 wxPrintf(wxT(" nothing known about the filetype '%s'!\n"),
151 mimetypes
[n
].c_str());
155 filetype
->GetDescription(&desc
);
156 filetype
->GetExtensions(exts
);
158 filetype
->GetIcon(NULL
);
161 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
164 extsAll
<< wxT(", ");
168 wxPrintf(wxT(" %s: %s (%s)\n"),
169 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
172 wxPuts(wxEmptyString
);
176 void InteractiveOutputTestCase
::TestMimeFilename()
179 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
181 static const wxChar
*filenames
[] =
189 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
191 const wxString fname
= filenames
[n
];
192 wxString ext
= fname
.AfterLast(wxT('.'));
193 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
196 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
201 if ( !ft
->GetDescription(&desc
) )
202 desc
= wxT("<no description>");
205 if ( !ft
->GetOpenCommand(&cmd
,
206 wxFileType
::MessageParameters(fname
, wxEmptyString
)) )
207 cmd
= wxT("<no command available>");
209 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
211 wxPrintf(wxT("To open %s (%s) run:\n %s\n"),
212 fname
.c_str(), desc
.c_str(), cmd
.c_str());
218 wxPuts(wxEmptyString
);
222 void InteractiveOutputTestCase
::TestMimeAssociate()
225 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
227 wxFileTypeInfo
ftInfo(
228 wxT("application/x-xyz"),
229 wxT("xyzview '%s'"), // open cmd
230 wxT(""), // print cmd
231 wxT("XYZ File"), // description
232 wxT(".xyz"), // extensions
233 wxNullPtr
// end of extensions
235 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
237 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
240 wxPuts(wxT("ERROR: failed to create association!"));
244 // TODO: read it back
248 wxPuts(wxEmptyString
);
253 // ----------------------------------------------------------------------------
254 // misc information functions
255 // ----------------------------------------------------------------------------
257 #include "wx/utils.h"
259 void InteractiveOutputTestCase
::TestOsInfo()
261 #ifdef TEST_INFO_FUNCTIONS
262 wxPuts(wxT("*** Testing OS info functions ***\n"));
265 wxGetOsVersion(&major
, &minor
);
266 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
267 wxGetOsDescription().c_str(), major
, minor
);
269 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
271 wxPrintf(wxT("Host name is %s (%s).\n"),
272 wxGetHostName().c_str(), wxGetFullHostName().c_str());
274 wxPuts(wxEmptyString
);
275 #endif // TEST_INFO_FUNCTIONS
278 void InteractiveOutputTestCase
::TestPlatformInfo()
280 #ifdef TEST_INFO_FUNCTIONS
281 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
286 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
287 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
288 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
289 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
290 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
291 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
293 wxPuts(wxEmptyString
);
294 #endif // TEST_INFO_FUNCTIONS
297 void InteractiveOutputTestCase
::TestUserInfo()
299 #ifdef TEST_INFO_FUNCTIONS
300 wxPuts(wxT("*** Testing user info functions ***\n"));
302 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
303 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
304 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
305 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
307 wxPuts(wxEmptyString
);
308 #endif // TEST_INFO_FUNCTIONS
312 // ----------------------------------------------------------------------------
314 // ----------------------------------------------------------------------------
316 #include "wx/stackwalk.h"
318 class StackDump
: public wxStackWalker
321 StackDump(const char *argv0
)
322 : wxStackWalker(argv0
)
326 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
328 wxPuts(wxT("Stack dump:"));
330 wxStackWalker
::Walk(skip
, maxdepth
);
334 virtual void OnStackFrame(const wxStackFrame
& frame
)
336 printf("[%2d] ", (int) frame
.GetLevel());
338 wxString name
= frame
.GetName();
341 printf("%-20.40s", (const char*)name
.mb_str());
345 printf("0x%08lx", (unsigned long)frame
.GetAddress());
348 if ( frame
.HasSourceLocation() )
351 (const char*)frame
.GetFileName().mb_str(),
352 (int)frame
.GetLine());
358 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
360 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
361 (const char*)name
.mb_str(),
362 (const char*)val
.mb_str());
367 void InteractiveOutputTestCase
::TestStackWalk()
369 #ifdef TEST_STACKWALKER
370 wxPuts(wxT("*** Testing wxStackWalker ***"));
372 StackDump
dump(wxTheApp
->argv
[0]);
376 #endif // TEST_STACKWALKER
380 // ----------------------------------------------------------------------------
382 // ----------------------------------------------------------------------------
385 #include "wx/stdpaths.h"
386 #include "wx/wxchar.h" // wxPrintf
388 void InteractiveOutputTestCase
::TestStandardPaths()
391 wxPuts(wxT("*** Testing wxStandardPaths ***"));
393 wxTheApp
->SetAppName(wxT("console"));
395 wxStandardPathsBase
& stdp
= wxStandardPaths
::Get();
396 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
397 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
398 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
399 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
400 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
401 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
402 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
403 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
404 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
405 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
406 wxPrintf(wxT("Localized res. dir:\t%s\n"),
407 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
408 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
409 stdp
.GetLocalizedResourcesDir
412 wxStandardPaths
::ResourceCat_Messages
416 #endif // TEST_STDPATHS
420 // ----------------------------------------------------------------------------
422 // ----------------------------------------------------------------------------
424 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
428 #include "wx/volume.h"
430 static const wxChar
*volumeKinds
[] =
436 wxT("network volume"),
440 void InteractiveOutputTestCase
::TestFSVolume()
443 wxPuts(wxT("*** Testing wxFSVolume class ***"));
445 wxArrayString volumes
= wxFSVolume
::GetVolumes();
446 size_t count
= volumes
.GetCount();
450 wxPuts(wxT("ERROR: no mounted volumes?"));
454 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
456 for ( size_t n
= 0; n
< count
; n
++ )
458 wxFSVolume
vol(volumes
[n
]);
461 wxPuts(wxT("ERROR: couldn't create volume"));
465 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
467 vol
.GetDisplayName().c_str(),
468 vol
.GetName().c_str(),
469 volumeKinds
[vol
.GetKind()],
470 vol
.IsWritable() ?
wxT("rw") : wxT("ro"),
471 vol
.GetFlags() & wxFS_VOL_REMOVABLE ?
wxT("removable")
476 #endif // TEST_VOLUME