cppcheck/test/cfg/gtk.c

59 lines
1.3 KiB
C
Raw Normal View History

// 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>
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)) {
}
printf("%s", _("test"));
printf("%s", Q_("a|test"));
printf("%s", N_("test"));
gpointer gpt = g_malloc(4);
printf("%p", gpt);
g_free(gpt);
g_assert(gpt);
if (!gpt) {
// cppcheck-suppress checkLibraryNoReturn
g_assert_not_reached();
}
gpointer p = GINT_TO_POINTER(1);
int i = GPOINTER_TO_INT(p);
// cppcheck-suppress knownConditionTrueFalse
if (i == 1) {}
}
void g_malloc_test()
{
// cppcheck-suppress leakReturnValNotUsed
g_malloc(8);
gpointer gpt = g_malloc(1);
printf("%p", gpt);
// cppcheck-suppress memleak
}
void g_assert_test()
{
int a;
// cppcheck-suppress checkLibraryNoReturn
// cppcheck-suppress assignmentInAssert
g_assert(a = 5);
}