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 // ----------------------------------------------------------------------------
25 #include "wx/wxcrt.h" // for wxPuts
26 #include "wx/wxcrtvararg.h" // for wxPrintf
28 // ----------------------------------------------------------------------------
29 // conditional compilation
30 // ----------------------------------------------------------------------------
34 #define TEST_INFO_FUNCTIONS
35 #define TEST_STACKWALKER
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class InteractiveOutputTestCase
: public CppUnit::TestCase
46 InteractiveOutputTestCase() { }
49 CPPUNIT_TEST_SUITE( InteractiveOutputTestCase
);
50 CPPUNIT_TEST( TestDllListLoaded
);
51 CPPUNIT_TEST( TestMimeEnum
);
52 CPPUNIT_TEST( TestMimeAssociate
);
53 CPPUNIT_TEST( TestMimeFilename
);
54 CPPUNIT_TEST( TestOsInfo
);
55 CPPUNIT_TEST( TestPlatformInfo
);
56 CPPUNIT_TEST( TestUserInfo
);
57 CPPUNIT_TEST( TestStackWalk
);
58 CPPUNIT_TEST( TestStandardPaths
);
59 CPPUNIT_TEST( TestFSVolume
);
60 CPPUNIT_TEST_SUITE_END();
62 void TestDllListLoaded();
64 void TestMimeAssociate();
65 void TestMimeFilename();
67 void TestPlatformInfo();
70 void TestStandardPaths();
73 wxDECLARE_NO_COPY_CLASS(InteractiveOutputTestCase
);
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 //CPPUNIT_TEST_SUITE_REGISTRATION( InteractiveOutputTestCase );
81 // do not run this test by default!
83 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InteractiveOutputTestCase
, "InteractiveOutputTestCase" );
85 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 #if !defined(__WXMSW__) && !defined(__UNIX__)
97 #include "wx/dynlib.h"
99 void InteractiveOutputTestCase::TestDllListLoaded()
102 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
104 wxPuts("Loaded modules:");
105 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary::ListLoaded();
106 const size_t count
= dlls
.GetCount();
107 for ( size_t n
= 0; n
< count
; ++n
)
109 const wxDynamicLibraryDetails
& details
= dlls
[n
];
110 printf("%-45s", (const char *)details
.GetPath().mb_str());
112 void *addr
wxDUMMY_INITIALIZE(NULL
);
113 size_t len
wxDUMMY_INITIALIZE(0);
114 if ( details
.GetAddress(&addr
, &len
) )
116 printf(" %08lx:%08lx",
117 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
120 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
123 wxPuts(wxEmptyString
);
124 #endif // TEST_DYNLIB
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 #include "wx/mimetype.h"
134 void InteractiveOutputTestCase::TestMimeEnum()
137 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
139 wxArrayString mimetypes
;
141 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
143 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
148 for ( size_t n
= 0; n
< count
; n
++ )
150 wxFileType
*filetype
=
151 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
154 wxPrintf(wxT(" nothing known about the filetype '%s'!\n"),
155 mimetypes
[n
].c_str());
159 filetype
->GetDescription(&desc
);
160 filetype
->GetExtensions(exts
);
162 filetype
->GetIcon(NULL
);
165 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
168 extsAll
<< wxT(", ");
172 wxPrintf(wxT(" %s: %s (%s)\n"),
173 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
176 wxPuts(wxEmptyString
);
180 void InteractiveOutputTestCase::TestMimeFilename()
183 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
185 static const wxChar
*filenames
[] =
193 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
195 const wxString fname
= filenames
[n
];
196 wxString ext
= fname
.AfterLast(wxT('.'));
197 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
200 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
205 if ( !ft
->GetDescription(&desc
) )
206 desc
= wxT("<no description>");
209 if ( !ft
->GetOpenCommand(&cmd
,
210 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
211 cmd
= wxT("<no command available>");
213 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
215 wxPrintf(wxT("To open %s (%s) run:\n %s\n"),
216 fname
.c_str(), desc
.c_str(), cmd
.c_str());
222 wxPuts(wxEmptyString
);
226 void InteractiveOutputTestCase::TestMimeAssociate()
229 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
231 wxFileTypeInfo
ftInfo(
232 wxT("application/x-xyz"),
233 wxT("xyzview '%s'"), // open cmd
234 wxT(""), // print cmd
235 wxT("XYZ File"), // description
236 wxT(".xyz"), // extensions
237 wxNullPtr
// end of extensions
239 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
241 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
244 wxPuts(wxT("ERROR: failed to create association!"));
248 // TODO: read it back
252 wxPuts(wxEmptyString
);
257 // ----------------------------------------------------------------------------
258 // misc information functions
259 // ----------------------------------------------------------------------------
261 #include "wx/utils.h"
263 void InteractiveOutputTestCase::TestOsInfo()
265 #ifdef TEST_INFO_FUNCTIONS
266 wxPuts(wxT("*** Testing OS info functions ***\n"));
269 wxGetOsVersion(&major
, &minor
);
270 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
271 wxGetOsDescription().c_str(), major
, minor
);
273 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
275 wxPrintf(wxT("Host name is %s (%s).\n"),
276 wxGetHostName().c_str(), wxGetFullHostName().c_str());
278 wxPuts(wxEmptyString
);
279 #endif // TEST_INFO_FUNCTIONS
282 void InteractiveOutputTestCase::TestPlatformInfo()
284 #ifdef TEST_INFO_FUNCTIONS
285 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
290 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
291 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
292 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
293 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
294 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
295 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
297 wxPuts(wxEmptyString
);
298 #endif // TEST_INFO_FUNCTIONS
301 void InteractiveOutputTestCase::TestUserInfo()
303 #ifdef TEST_INFO_FUNCTIONS
304 wxPuts(wxT("*** Testing user info functions ***\n"));
306 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
307 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
308 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
309 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
311 wxPuts(wxEmptyString
);
312 #endif // TEST_INFO_FUNCTIONS
316 // ----------------------------------------------------------------------------
318 // ----------------------------------------------------------------------------
320 #if wxUSE_STACKWALKER
322 #include "wx/stackwalk.h"
324 class StackDump
: public wxStackWalker
327 StackDump(const char *argv0
)
328 : wxStackWalker(argv0
)
332 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
334 wxPuts(wxT("Stack dump:"));
336 wxStackWalker::Walk(skip
, maxdepth
);
340 virtual void OnStackFrame(const wxStackFrame
& frame
)
342 printf("[%2d] ", (int) frame
.GetLevel());
344 wxString name
= frame
.GetName();
347 printf("%-20.40s", (const char*)name
.mb_str());
351 printf("0x%08lx", (unsigned long)frame
.GetAddress());
354 if ( frame
.HasSourceLocation() )
357 (const char*)frame
.GetFileName().mb_str(),
358 (int)frame
.GetLine());
364 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
366 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
367 (const char*)name
.mb_str(),
368 (const char*)val
.mb_str());
374 void InteractiveOutputTestCase::TestStackWalk()
376 #ifdef TEST_STACKWALKER
377 #if wxUSE_STACKWALKER
378 wxPuts(wxT("*** Testing wxStackWalker ***"));
380 wxString
progname(wxTheApp
->argv
[0]);
381 StackDump
dump(progname
.utf8_str());
386 #endif // TEST_STACKWALKER
390 // ----------------------------------------------------------------------------
392 // ----------------------------------------------------------------------------
394 #include "wx/stdpaths.h"
395 #include "wx/wxchar.h" // wxPrintf
397 void InteractiveOutputTestCase::TestStandardPaths()
400 wxPuts(wxT("*** Testing wxStandardPaths ***"));
402 wxTheApp
->SetAppName(wxT("console"));
404 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
405 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
406 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
407 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
408 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
409 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
410 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
411 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
412 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
413 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
414 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
415 wxPrintf(wxT("Localized res. dir:\t%s\n"),
416 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
417 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
418 stdp
.GetLocalizedResourcesDir
421 wxStandardPaths::ResourceCat_Messages
425 #endif // TEST_STDPATHS
429 // ----------------------------------------------------------------------------
431 // ----------------------------------------------------------------------------
433 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
439 #include "wx/volume.h"
440 static const wxChar
*volumeKinds
[] =
446 wxT("network volume"),
452 void InteractiveOutputTestCase::TestFSVolume()
455 wxPuts(wxT("*** Testing wxFSVolume class ***"));
457 wxArrayString volumes
= wxFSVolume::GetVolumes();
458 size_t count
= volumes
.GetCount();
462 wxPuts(wxT("ERROR: no mounted volumes?"));
466 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
468 for ( size_t n
= 0; n
< count
; n
++ )
470 wxFSVolume
vol(volumes
[n
]);
473 wxPuts(wxT("ERROR: couldn't create volume"));
477 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
479 vol
.GetDisplayName().c_str(),
480 vol
.GetName().c_str(),
481 volumeKinds
[vol
.GetKind()],
482 vol
.IsWritable() ? wxT("rw") : wxT("ro"),
483 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? wxT("removable")
488 #endif // TEST_VOLUME