2018-02-06 15:33:45 +01:00
|
|
|
|
2018-02-20 23:34:01 +01:00
|
|
|
// Test library configuration for wxwidgets.cfg
|
2018-02-06 15:33:45 +01:00
|
|
|
//
|
|
|
|
// Usage:
|
2018-02-20 23:34:01 +01:00
|
|
|
// $ ./cppcheck --check-library --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr '--template="{file}:{line}:{severity}:{id}:{message}"' --inconclusive --library=wxwidgets -f test/cfg/wxwidgets.cpp
|
2018-02-06 15:33:45 +01:00
|
|
|
// =>
|
|
|
|
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
|
|
|
|
//
|
|
|
|
|
2018-02-09 20:34:15 +01:00
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/log.h>
|
2018-02-06 15:33:45 +01:00
|
|
|
#include <wx/filefn.h>
|
2018-02-09 20:34:15 +01:00
|
|
|
#include <wx/spinctrl.h>
|
|
|
|
#include <wx/artprov.h>
|
|
|
|
#include <wx/calctrl.h>
|
|
|
|
#include <wx/combo.h>
|
|
|
|
#include <wx/icon.h>
|
|
|
|
#include <wx/bitmap.h>
|
2018-02-14 09:53:40 +01:00
|
|
|
#include <wx/dataview.h>
|
2018-02-20 23:34:01 +01:00
|
|
|
#include <wx/memory.h>
|
2018-03-31 13:23:12 +02:00
|
|
|
#include <wx/frame.h>
|
|
|
|
#include <wx/menu.h>
|
2018-11-22 13:47:17 +01:00
|
|
|
#include <wx/stattext.h>
|
2018-11-22 14:04:22 +01:00
|
|
|
#include <wx/sizer.h>
|
2018-02-06 15:33:45 +01:00
|
|
|
|
|
|
|
void validCode()
|
|
|
|
{
|
|
|
|
wxString str = wxGetCwd();
|
|
|
|
|
|
|
|
wxLogGeneric(wxLOG_Message, "test %d", 0);
|
|
|
|
wxLogMessage("test %s", "str");
|
|
|
|
|
|
|
|
wxString translation1 = _("text");
|
|
|
|
wxString translation2 = wxGetTranslation("text");
|
|
|
|
wxString translation3 = wxGetTranslation("string", "domain");
|
|
|
|
}
|
|
|
|
|
2018-02-09 20:34:15 +01:00
|
|
|
#if wxUSE_GUI==1
|
|
|
|
void validGuiCode()
|
|
|
|
{
|
|
|
|
#if wxUSE_SPINCTRL==1
|
|
|
|
extern wxSpinCtrl spinCtrlInstance;
|
|
|
|
spinCtrlInstance.SetBase(10);
|
|
|
|
spinCtrlInstance.SetBase(16);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-07 20:27:02 +02:00
|
|
|
void nullPointer(const wxString &str)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
|
|
|
// cppcheck-suppress nullPointer
|
2018-02-09 20:34:15 +01:00
|
|
|
wxLogGeneric(wxLOG_Message, (char*)NULL);
|
2018-02-06 15:33:45 +01:00
|
|
|
// cppcheck-suppress nullPointer
|
2018-02-09 20:34:15 +01:00
|
|
|
wxLogMessage((char*)NULL);
|
2018-04-07 20:27:02 +02:00
|
|
|
|
|
|
|
double *doublePtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToDouble(doublePtr);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToCDouble(doublePtr);
|
|
|
|
|
|
|
|
long * longPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToLong(longPtr);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToCLong(longPtr);
|
|
|
|
|
|
|
|
unsigned long * ulongPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToULong(ulongPtr);
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToCULong(ulongPtr);
|
|
|
|
|
|
|
|
long long * longLongPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToLongLong(longLongPtr);
|
|
|
|
|
|
|
|
unsigned long long * ulongLongPtr = NULL;
|
|
|
|
// cppcheck-suppress nullPointer
|
|
|
|
(void)str.ToULongLong(ulongLongPtr);
|
2018-11-22 14:04:22 +01:00
|
|
|
}
|
2018-04-07 20:27:02 +02:00
|
|
|
|
2018-11-22 14:04:22 +01:00
|
|
|
void nullPointer_wxSizer_Add(wxSizer &sizer, wxWindow *w)
|
|
|
|
{
|
2018-11-23 06:47:27 +01:00
|
|
|
wxWindow * const ptr = 0;
|
2018-11-23 09:49:08 +01:00
|
|
|
// @todo cppcheck-suppress nullPointer
|
2018-11-23 06:47:27 +01:00
|
|
|
sizer.Add(ptr);
|
|
|
|
// No warning shall be issued for
|
|
|
|
sizer.Add(w);
|
2018-11-22 14:04:22 +01:00
|
|
|
}
|
|
|
|
|
2018-11-23 06:47:27 +01:00
|
|
|
void uninitvar_wxSizer_Add(wxSizer &sizer, wxWindow *w,wxObject* userData)
|
2018-11-22 14:04:22 +01:00
|
|
|
{
|
2018-11-23 06:47:27 +01:00
|
|
|
int uninit;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
sizer.Add(w,uninit);
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
sizer.Add(w,4,uninit);
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
sizer.Add(w,4,2,uninit,userData);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:29:55 +02:00
|
|
|
void ignoredReturnValue(const wxString &s)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxGetCwd();
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxAtoi(s);
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxAtol(s);
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxAtof(s);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
|
|
|
|
2018-04-07 20:27:02 +02:00
|
|
|
void invalidFunctionArg(const wxString &str)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
2018-02-09 20:34:15 +01:00
|
|
|
#if wxUSE_SPINCTRL==1
|
|
|
|
extern wxSpinCtrl spinCtrlInstance;
|
2018-02-06 15:33:45 +01:00
|
|
|
// cppcheck-suppress invalidFunctionArg
|
2018-02-09 20:34:15 +01:00
|
|
|
spinCtrlInstance.SetBase(0);
|
2018-02-06 15:33:45 +01:00
|
|
|
// cppcheck-suppress invalidFunctionArg
|
2018-02-09 20:34:15 +01:00
|
|
|
spinCtrlInstance.SetBase(5);
|
|
|
|
#endif
|
2018-04-07 20:27:02 +02:00
|
|
|
|
|
|
|
long l;
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)str.ToLong(&l, -1);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)str.ToLong(&l, 1);
|
|
|
|
// cppcheck-suppress invalidFunctionArg
|
|
|
|
(void)str.ToLong(&l, 37);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
|
|
|
|
2018-11-22 13:31:09 +01:00
|
|
|
void uninitvar(wxWindow &w)
|
2018-02-06 15:33:45 +01:00
|
|
|
{
|
|
|
|
wxLogLevel logLevelUninit;
|
|
|
|
char cBufUninit[10];
|
|
|
|
char *pcUninit;
|
2018-11-22 13:31:09 +01:00
|
|
|
bool uninitBool;
|
2018-02-06 15:33:45 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
wxLogGeneric(logLevelUninit, "test");
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
wxLogMessage(cBufUninit);
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
wxLogMessage(pcUninit);
|
2018-11-22 13:31:09 +01:00
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
w.Close(uninitBool);
|
2018-04-07 20:27:02 +02:00
|
|
|
}
|
|
|
|
|
2018-11-22 13:47:17 +01:00
|
|
|
void uninitvar_wxStaticText(wxStaticText &s)
|
|
|
|
{
|
|
|
|
// no warning
|
|
|
|
s.Wrap(-1);
|
|
|
|
bool uninitBool;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
s.Wrap(uninitBool);
|
|
|
|
}
|
|
|
|
|
2018-04-07 20:27:02 +02:00
|
|
|
void uninitvar_wxString_NumberConversion(const wxString &str, const int numberBase)
|
|
|
|
{
|
|
|
|
int uninitInteger;
|
|
|
|
long l;
|
|
|
|
long long ll;
|
|
|
|
unsigned long ul;
|
|
|
|
unsigned long long ull;
|
|
|
|
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)str.ToLong(&l, uninitInteger);
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2018-04-07 20:27:02 +02:00
|
|
|
(void)str.ToLongLong(&ll, uninitInteger);
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)str.ToULong(&ul, uninitInteger);
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
(void)str.ToULongLong(&ull, uninitInteger);
|
|
|
|
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2018-04-07 20:27:02 +02:00
|
|
|
(void)str.ToCLong(&l, uninitInteger);
|
2018-04-04 21:29:55 +02:00
|
|
|
// cppcheck-suppress uninitvar
|
2018-04-07 20:27:02 +02:00
|
|
|
(void)str.ToCULong(&ul, uninitInteger);
|
2018-02-06 15:33:45 +01:00
|
|
|
}
|
2018-02-07 11:40:42 +01:00
|
|
|
|
2018-03-31 13:34:40 +02:00
|
|
|
void uninitvar_SetMenuBar(wxFrame * const framePtr, wxMenuBar * const menuBarPtr)
|
2018-03-31 13:23:12 +02:00
|
|
|
{
|
2018-03-31 13:49:47 +02:00
|
|
|
wxMenuBar *menuBar;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
framePtr->SetMenuBar(menuBar);
|
2018-03-31 13:23:12 +02:00
|
|
|
framePtr->SetMenuBar(menuBarPtr);
|
2018-03-31 13:34:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uninitvar_wxMenuBarAppend(wxMenuBar * const menuBarPtr, wxMenu * const menuPtr, const wxString &title)
|
|
|
|
{
|
2018-03-31 13:49:47 +02:00
|
|
|
wxMenu *menu;
|
|
|
|
// cppcheck-suppress uninitvar
|
|
|
|
menuBarPtr->Append(menu, title);
|
2018-03-31 13:34:40 +02:00
|
|
|
menuBarPtr->Append(menuPtr, title);
|
2018-03-31 13:49:47 +02:00
|
|
|
}
|
2018-03-31 13:23:12 +02:00
|
|
|
|
2018-02-14 09:53:40 +01:00
|
|
|
void deprecatedFunctions_wxDataViewCustomRenderer(wxDataViewCustomRenderer &dataViewCustomRenderer, wxPoint cursor, wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col)
|
|
|
|
{
|
|
|
|
// cppcheck-suppress ActivateCalled
|
|
|
|
dataViewCustomRenderer.Activate(cell, model, item, col);
|
|
|
|
// cppcheck-suppress LeftClickCalled
|
|
|
|
dataViewCustomRenderer.LeftClick(cursor, cell, model, item, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deprecatedFunctions(wxApp &a,
|
|
|
|
const wxString &s,
|
|
|
|
wxArtProvider *artProvider,
|
|
|
|
wxCalendarCtrl &calenderCtrl,
|
2018-02-20 23:34:01 +01:00
|
|
|
wxComboCtrl &comboCtrl,
|
|
|
|
wxChar * path)
|
2018-02-07 11:40:42 +01:00
|
|
|
{
|
2018-02-09 20:34:15 +01:00
|
|
|
#ifdef __WXOSX__
|
2018-02-07 11:40:42 +01:00
|
|
|
// cppcheck-suppress MacOpenFileCalled
|
|
|
|
a.MacOpenFile(s);
|
2018-02-09 20:34:15 +01:00
|
|
|
#endif
|
2018-02-11 16:58:39 +01:00
|
|
|
|
|
|
|
#if wxCHECK_VERSION(3, 1, 0) // wxWidets-3.1.0 or higher:
|
|
|
|
// Some functions are not available anymore in newer versions
|
|
|
|
|
|
|
|
// @todo cppcheck-suppress ShowPopupCalled
|
|
|
|
comboCtrl.ShowPopup();
|
|
|
|
#else
|
2018-02-07 11:40:42 +01:00
|
|
|
// cppcheck-suppress InsertCalled
|
|
|
|
wxArtProvider::Insert(artProvider);
|
2018-02-11 16:58:39 +01:00
|
|
|
|
|
|
|
// cppcheck-suppress GetTextIndentCalled
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
comboCtrl.GetTextIndent();
|
|
|
|
|
|
|
|
// cppcheck-suppress HidePopupCalled
|
|
|
|
comboCtrl.HidePopup(true);
|
|
|
|
// cppcheck-suppress HidePopupCalled
|
|
|
|
comboCtrl.HidePopup(false);
|
|
|
|
// cppcheck-suppress HidePopupCalled
|
|
|
|
comboCtrl.HidePopup(/*default=false*/);
|
|
|
|
|
|
|
|
// cppcheck-suppress SetTextIndentCalled
|
|
|
|
comboCtrl.SetTextIndent(0);
|
2018-02-20 23:34:01 +01:00
|
|
|
|
2018-02-21 12:20:56 +01:00
|
|
|
#if wxUSE_DEBUG_CONTEXT==1
|
2018-02-20 23:34:01 +01:00
|
|
|
// cppcheck-suppress GetLevelCalled
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
|
|
|
wxDebugContext::GetLevel();
|
|
|
|
// cppcheck-suppress SetLevelCalled
|
|
|
|
wxDebugContext::SetLevel(42);
|
2018-02-21 12:20:56 +01:00
|
|
|
#endif
|
2018-02-20 23:34:01 +01:00
|
|
|
|
|
|
|
// cppcheck-suppress wxDos2UnixFilenameCalled
|
|
|
|
wxDos2UnixFilename(path);
|
|
|
|
|
|
|
|
// cppcheck-suppress wxFileNameFromPathCalled
|
|
|
|
// cppcheck-suppress ignoredReturnValue
|
2018-02-21 12:20:56 +01:00
|
|
|
wxFileNameFromPath(wxT_2("../test.c"));
|
2018-02-11 16:58:39 +01:00
|
|
|
#endif
|
|
|
|
|
2018-02-09 20:34:15 +01:00
|
|
|
#if defined(__WXMSW__) || defined(__WXGTK__)
|
|
|
|
// EnableYearChange() is not available on these GUI systems
|
|
|
|
#else
|
2018-02-07 13:33:15 +01:00
|
|
|
// cppcheck-suppress EnableYearChangeCalled
|
|
|
|
calenderCtrl.EnableYearChange(false);
|
|
|
|
// cppcheck-suppress EnableYearChangeCalled
|
2018-02-11 16:58:39 +01:00
|
|
|
calenderCtrl.EnableYearChange(true);
|
|
|
|
// cppcheck-suppress EnableYearChangeCalled
|
2018-02-07 13:33:15 +01:00
|
|
|
calenderCtrl.EnableYearChange(/*default=yes*/);
|
2018-02-09 20:34:15 +01:00
|
|
|
#endif
|
2018-02-07 11:40:42 +01:00
|
|
|
}
|