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 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
27 // conditional compilation
28 // ----------------------------------------------------------------------------
32 #define TEST_INFO_FUNCTIONS
33 #define TEST_STACKWALKER
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 class InteractiveOutputTestCase
: public CppUnit::TestCase
44 InteractiveOutputTestCase() { }
47 CPPUNIT_TEST_SUITE( InteractiveOutputTestCase
);
48 CPPUNIT_TEST( TestDllListLoaded
);
49 CPPUNIT_TEST( TestMimeEnum
);
50 CPPUNIT_TEST( TestMimeAssociate
);
51 CPPUNIT_TEST( TestMimeFilename
);
52 CPPUNIT_TEST( TestOsInfo
);
53 CPPUNIT_TEST( TestPlatformInfo
);
54 CPPUNIT_TEST( TestUserInfo
);
55 CPPUNIT_TEST( TestStackWalk
);
56 CPPUNIT_TEST( TestStandardPaths
);
57 CPPUNIT_TEST( TestFSVolume
);
58 CPPUNIT_TEST_SUITE_END();
60 void TestDllListLoaded();
62 void TestMimeAssociate();
63 void TestMimeFilename();
65 void TestPlatformInfo();
68 void TestStandardPaths();
71 wxDECLARE_NO_COPY_CLASS(InteractiveOutputTestCase
);
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 //CPPUNIT_TEST_SUITE_REGISTRATION( InteractiveOutputTestCase );
79 // do not run this test by default!
81 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InteractiveOutputTestCase
, "InteractiveOutputTestCase" );
83 // ============================================================================
85 // ============================================================================
87 // ----------------------------------------------------------------------------
89 // ----------------------------------------------------------------------------
91 #if !defined(__WXMSW__) && !defined(__UNIX__)
95 #include "wx/dynlib.h"
97 void InteractiveOutputTestCase::TestDllListLoaded()
100 wxPuts(wxT("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
102 wxPuts("Loaded modules:");
103 wxDynamicLibraryDetailsArray dlls
= wxDynamicLibrary::ListLoaded();
104 const size_t count
= dlls
.GetCount();
105 for ( size_t n
= 0; n
< count
; ++n
)
107 const wxDynamicLibraryDetails
& details
= dlls
[n
];
108 printf("%-45s", (const char *)details
.GetPath().mb_str());
110 void *addr
wxDUMMY_INITIALIZE(NULL
);
111 size_t len
wxDUMMY_INITIALIZE(0);
112 if ( details
.GetAddress(&addr
, &len
) )
114 printf(" %08lx:%08lx",
115 (unsigned long)addr
, (unsigned long)((char *)addr
+ len
));
118 printf(" %s\n", (const char *)details
.GetVersion().mb_str());
121 wxPuts(wxEmptyString
);
122 #endif // TEST_DYNLIB
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
130 #include "wx/mimetype.h"
132 void InteractiveOutputTestCase::TestMimeEnum()
135 wxPuts(wxT("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
137 wxArrayString mimetypes
;
139 size_t count
= wxTheMimeTypesManager
->EnumAllFileTypes(mimetypes
);
141 wxPrintf(wxT("*** All %u known filetypes: ***\n"), count
);
146 for ( size_t n
= 0; n
< count
; n
++ )
148 wxFileType
*filetype
=
149 wxTheMimeTypesManager
->GetFileTypeFromMimeType(mimetypes
[n
]);
152 wxPrintf(wxT(" nothing known about the filetype '%s'!\n"),
153 mimetypes
[n
].c_str());
157 filetype
->GetDescription(&desc
);
158 filetype
->GetExtensions(exts
);
160 filetype
->GetIcon(NULL
);
163 for ( size_t e
= 0; e
< exts
.GetCount(); e
++ )
166 extsAll
<< wxT(", ");
170 wxPrintf(wxT(" %s: %s (%s)\n"),
171 mimetypes
[n
].c_str(), desc
.c_str(), extsAll
.c_str());
174 wxPuts(wxEmptyString
);
178 void InteractiveOutputTestCase::TestMimeFilename()
181 wxPuts(wxT("*** Testing MIME type from filename query ***\n"));
183 static const wxChar
*filenames
[] =
191 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
193 const wxString fname
= filenames
[n
];
194 wxString ext
= fname
.AfterLast(wxT('.'));
195 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
198 wxPrintf(wxT("WARNING: extension '%s' is unknown.\n"), ext
.c_str());
203 if ( !ft
->GetDescription(&desc
) )
204 desc
= wxT("<no description>");
207 if ( !ft
->GetOpenCommand(&cmd
,
208 wxFileType::MessageParameters(fname
, wxEmptyString
)) )
209 cmd
= wxT("<no command available>");
211 cmd
= wxString(wxT('"')) + cmd
+ wxT('"');
213 wxPrintf(wxT("To open %s (%s) run:\n %s\n"),
214 fname
.c_str(), desc
.c_str(), cmd
.c_str());
220 wxPuts(wxEmptyString
);
224 void InteractiveOutputTestCase::TestMimeAssociate()
227 wxPuts(wxT("*** Testing creation of filetype association ***\n"));
229 wxFileTypeInfo
ftInfo(
230 wxT("application/x-xyz"),
231 wxT("xyzview '%s'"), // open cmd
232 wxT(""), // print cmd
233 wxT("XYZ File"), // description
234 wxT(".xyz"), // extensions
235 wxNullPtr
// end of extensions
237 ftInfo
.SetShortDesc(wxT("XYZFile")); // used under Win32 only
239 wxFileType
*ft
= wxTheMimeTypesManager
->Associate(ftInfo
);
242 wxPuts(wxT("ERROR: failed to create association!"));
246 // TODO: read it back
250 wxPuts(wxEmptyString
);
255 // ----------------------------------------------------------------------------
256 // misc information functions
257 // ----------------------------------------------------------------------------
259 #include "wx/utils.h"
261 void InteractiveOutputTestCase::TestOsInfo()
263 #ifdef TEST_INFO_FUNCTIONS
264 wxPuts(wxT("*** Testing OS info functions ***\n"));
267 wxGetOsVersion(&major
, &minor
);
268 wxPrintf(wxT("Running under: %s, version %d.%d\n"),
269 wxGetOsDescription().c_str(), major
, minor
);
271 wxPrintf(wxT("%ld free bytes of memory left.\n"), wxGetFreeMemory().ToLong());
273 wxPrintf(wxT("Host name is %s (%s).\n"),
274 wxGetHostName().c_str(), wxGetFullHostName().c_str());
276 wxPuts(wxEmptyString
);
277 #endif // TEST_INFO_FUNCTIONS
280 void InteractiveOutputTestCase::TestPlatformInfo()
282 #ifdef TEST_INFO_FUNCTIONS
283 wxPuts(wxT("*** Testing wxPlatformInfo functions ***\n"));
288 wxPrintf(wxT("Operating system family name is: %s\n"), plat
.GetOperatingSystemFamilyName().c_str());
289 wxPrintf(wxT("Operating system name is: %s\n"), plat
.GetOperatingSystemIdName().c_str());
290 wxPrintf(wxT("Port ID name is: %s\n"), plat
.GetPortIdName().c_str());
291 wxPrintf(wxT("Port ID short name is: %s\n"), plat
.GetPortIdShortName().c_str());
292 wxPrintf(wxT("Architecture is: %s\n"), plat
.GetArchName().c_str());
293 wxPrintf(wxT("Endianness is: %s\n"), plat
.GetEndiannessName().c_str());
295 wxPuts(wxEmptyString
);
296 #endif // TEST_INFO_FUNCTIONS
299 void InteractiveOutputTestCase::TestUserInfo()
301 #ifdef TEST_INFO_FUNCTIONS
302 wxPuts(wxT("*** Testing user info functions ***\n"));
304 wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
305 wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
306 wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
307 wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());
309 wxPuts(wxEmptyString
);
310 #endif // TEST_INFO_FUNCTIONS
314 // ----------------------------------------------------------------------------
316 // ----------------------------------------------------------------------------
318 #include "wx/stackwalk.h"
320 class StackDump
: public wxStackWalker
323 StackDump(const char *argv0
)
324 : wxStackWalker(argv0
)
328 virtual void Walk(size_t skip
= 1, size_t maxdepth
= wxSTACKWALKER_MAX_DEPTH
)
330 wxPuts(wxT("Stack dump:"));
332 wxStackWalker::Walk(skip
, maxdepth
);
336 virtual void OnStackFrame(const wxStackFrame
& frame
)
338 printf("[%2d] ", (int) frame
.GetLevel());
340 wxString name
= frame
.GetName();
343 printf("%-20.40s", (const char*)name
.mb_str());
347 printf("0x%08lx", (unsigned long)frame
.GetAddress());
350 if ( frame
.HasSourceLocation() )
353 (const char*)frame
.GetFileName().mb_str(),
354 (int)frame
.GetLine());
360 for ( size_t n
= 0; frame
.GetParam(n
, &type
, &name
, &val
); n
++ )
362 printf("\t%s %s = %s\n", (const char*)type
.mb_str(),
363 (const char*)name
.mb_str(),
364 (const char*)val
.mb_str());
369 void InteractiveOutputTestCase::TestStackWalk()
371 #ifdef TEST_STACKWALKER
372 wxPuts(wxT("*** Testing wxStackWalker ***"));
374 StackDump
dump(wxTheApp
->argv
[0]);
378 #endif // TEST_STACKWALKER
382 // ----------------------------------------------------------------------------
384 // ----------------------------------------------------------------------------
386 #include "wx/stdpaths.h"
387 #include "wx/wxchar.h" // wxPrintf
389 void InteractiveOutputTestCase::TestStandardPaths()
392 wxPuts(wxT("*** Testing wxStandardPaths ***"));
394 wxTheApp
->SetAppName(wxT("console"));
396 wxStandardPathsBase
& stdp
= wxStandardPaths::Get();
397 wxPrintf(wxT("Config dir (sys):\t%s\n"), stdp
.GetConfigDir().c_str());
398 wxPrintf(wxT("Config dir (user):\t%s\n"), stdp
.GetUserConfigDir().c_str());
399 wxPrintf(wxT("Data dir (sys):\t\t%s\n"), stdp
.GetDataDir().c_str());
400 wxPrintf(wxT("Data dir (sys local):\t%s\n"), stdp
.GetLocalDataDir().c_str());
401 wxPrintf(wxT("Data dir (user):\t%s\n"), stdp
.GetUserDataDir().c_str());
402 wxPrintf(wxT("Data dir (user local):\t%s\n"), stdp
.GetUserLocalDataDir().c_str());
403 wxPrintf(wxT("Documents dir:\t\t%s\n"), stdp
.GetDocumentsDir().c_str());
404 wxPrintf(wxT("Executable path:\t%s\n"), stdp
.GetExecutablePath().c_str());
405 wxPrintf(wxT("Plugins dir:\t\t%s\n"), stdp
.GetPluginsDir().c_str());
406 wxPrintf(wxT("Resources dir:\t\t%s\n"), stdp
.GetResourcesDir().c_str());
407 wxPrintf(wxT("Localized res. dir:\t%s\n"),
408 stdp
.GetLocalizedResourcesDir(wxT("fr")).c_str());
409 wxPrintf(wxT("Message catalogs dir:\t%s\n"),
410 stdp
.GetLocalizedResourcesDir
413 wxStandardPaths::ResourceCat_Messages
417 #endif // TEST_STDPATHS
421 // ----------------------------------------------------------------------------
423 // ----------------------------------------------------------------------------
425 #if !defined(__WIN32__) || !wxUSE_FSVOLUME
431 #include "wx/volume.h"
432 static const wxChar
*volumeKinds
[] =
438 wxT("network volume"),
444 void InteractiveOutputTestCase::TestFSVolume()
447 wxPuts(wxT("*** Testing wxFSVolume class ***"));
449 wxArrayString volumes
= wxFSVolume::GetVolumes();
450 size_t count
= volumes
.GetCount();
454 wxPuts(wxT("ERROR: no mounted volumes?"));
458 wxPrintf(wxT("%u mounted volumes found:\n"), count
);
460 for ( size_t n
= 0; n
< count
; n
++ )
462 wxFSVolume
vol(volumes
[n
]);
465 wxPuts(wxT("ERROR: couldn't create volume"));
469 wxPrintf(wxT("%u: %s (%s), %s, %s, %s\n"),
471 vol
.GetDisplayName().c_str(),
472 vol
.GetName().c_str(),
473 volumeKinds
[vol
.GetKind()],
474 vol
.IsWritable() ? wxT("rw") : wxT("ro"),
475 vol
.GetFlags() & wxFS_VOL_REMOVABLE
? wxT("removable")
480 #endif // TEST_VOLUME