2018-03-10 11:22:10 +01:00
|
|
|
|
|
|
|
// Test library configuration for gtk.cfg
|
|
|
|
//
|
|
|
|
// Usage:
|
|
|
|
// $ cppcheck --check-library --enable=information --inconclusive --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --library=gtk test/cfg/gtk.cpp
|
|
|
|
// =>
|
|
|
|
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2019-02-18 16:48:46 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2018-03-10 11:22:10 +01:00
|
|
|
|
|
|
|
void validCode(int argInt)
|
|
|
|
{
|
|
|
|
// if G_UNLIKELY is not defined this results in a syntax error
|
|
|
|
if G_UNLIKELY(argInt == 1) {
|
|
|
|
} else if (G_UNLIKELY(argInt == 2)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if G_LIKELY(argInt == 0) {
|
|
|
|
} else if (G_LIKELY(argInt == -1)) {
|
|
|
|
}
|
2019-01-25 13:07:48 +01:00
|
|
|
|
|
|
|
printf("%s", _("test"));
|
|
|
|
printf("%s", Q_("a|test"));
|
|
|
|
printf("%s", N_("test"));
|
2019-01-28 13:47:46 +01:00
|
|
|
|
|
|
|
gpointer gpt = g_malloc(4);
|
|
|
|
printf("%p", gpt);
|
|
|
|
g_free(gpt);
|
2019-02-13 15:35:46 +01:00
|
|
|
g_assert(gpt);
|
|
|
|
if (!gpt) {
|
|
|
|
// cppcheck-suppress checkLibraryNoReturn
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2019-02-15 08:44:21 +01:00
|
|
|
gpointer p = GINT_TO_POINTER(1);
|
|
|
|
int i = GPOINTER_TO_INT(p);
|
|
|
|
// cppcheck-suppress knownConditionTrueFalse
|
|
|
|
if (i == 1) {}
|
2019-02-18 16:48:46 +01:00
|
|
|
|
|
|
|
g_print("test");
|
|
|
|
g_print("%d", 1);
|
|
|
|
g_printerr("err");
|
2019-01-28 13:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void g_malloc_test()
|
|
|
|
{
|
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
g_malloc(8);
|
|
|
|
|
|
|
|
gpointer gpt = g_malloc(1);
|
|
|
|
printf("%p", gpt);
|
|
|
|
|
|
|
|
// cppcheck-suppress memleak
|
2018-03-10 11:22:10 +01:00
|
|
|
}
|
2019-02-13 15:35:46 +01:00
|
|
|
|
|
|
|
void g_assert_test()
|
|
|
|
{
|
|
|
|
int a;
|
|
|
|
// cppcheck-suppress checkLibraryNoReturn
|
|
|
|
// cppcheck-suppress assignmentInAssert
|
|
|
|
g_assert(a = 5);
|
|
|
|
}
|
2019-02-18 16:48:46 +01:00
|
|
|
|
|
|
|
void g_print_test()
|
|
|
|
{
|
|
|
|
// cppcheck-suppress invalidPrintfArgType_uint
|
|
|
|
g_print("%u", -1);
|
|
|
|
// cppcheck-suppress invalidPrintfArgType_uint
|
|
|
|
g_printerr("%x", "a");
|
|
|
|
}
|
2019-02-28 15:29:37 +01:00
|
|
|
|
|
|
|
void g_alloca_test()
|
|
|
|
{
|
|
|
|
// cppcheck-suppress allocaCalled
|
|
|
|
char * pBuf1 = g_alloca(5);
|
|
|
|
pBuf1[0] = '\0';
|
|
|
|
}
|
2019-03-26 10:45:06 +01:00
|
|
|
|
|
|
|
void g_new_test()
|
|
|
|
{
|
|
|
|
struct a {
|
|
|
|
int b;
|
|
|
|
};
|
|
|
|
// valid
|
|
|
|
struct a * pNew1 = g_new(struct a, 5);
|
|
|
|
printf("%p", pNew1);
|
|
|
|
g_free(pNew1);
|
|
|
|
|
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
g_new(struct a, 1);
|
|
|
|
|
|
|
|
struct a * pNew2 = g_new(struct a, 2);
|
|
|
|
printf("%p", pNew2);
|
|
|
|
// cppcheck-suppress memleak
|
|
|
|
}
|
|
|
|
|
|
|
|
void g_try_new0_test()
|
|
|
|
{
|
|
|
|
struct a {
|
|
|
|
int b;
|
|
|
|
};
|
|
|
|
// valid
|
|
|
|
struct a * pNew1 = g_try_new0(struct a, 5);
|
|
|
|
printf("%p", pNew1);
|
|
|
|
g_free(pNew1);
|
|
|
|
|
|
|
|
// cppcheck-suppress leakReturnValNotUsed
|
|
|
|
g_try_new0(struct a, 1);
|
|
|
|
|
|
|
|
struct a * pNew2 = g_try_new0(struct a, 2);
|
|
|
|
printf("%p", pNew2);
|
|
|
|
// cppcheck-suppress memleak
|
|
|
|
}
|