Skip to content

Commit

Permalink
refactor: use GTest for running tests (#1383)
Browse files Browse the repository at this point in the history
* refactor: use google-test on libtransmission tests
  • Loading branch information
ckerr committed Aug 11, 2020
1 parent 6da4a4d commit 677dc73
Show file tree
Hide file tree
Showing 201 changed files with 7,498 additions and 8,100 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -22,3 +22,6 @@
path = third-party/miniupnpc
url = https://github.com/transmission/miniupnpc
branch = post-2.0.20170509-transmission
[submodule "third-party/googletest"]
path = third-party/googletest
url = https://github.com/google/googletest.git
139 changes: 95 additions & 44 deletions CMakeLists.txt
Expand Up @@ -111,6 +111,7 @@ set(QT5_MINIMUM 5.2)

if(WIN32)
foreach(L C CXX)
set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DWIN32")
# Target version (Vista and up)
set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DWINVER=0x0600 -D_WIN32_WINNT=0x0600")
# Use Unicode API (although we always use W or A names explicitly)
Expand Down Expand Up @@ -375,10 +376,14 @@ if(WIN32)
endforeach()
endif()

## Compiler standard version

if(CMAKE_VERSION VERSION_LESS "3.1")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17")
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
endif()
else()
set(CMAKE_C_STANDARD 99)
Expand All @@ -387,47 +392,91 @@ else()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(NEEDED_COMPILER_FLAGS
-Wall
-W
-Wcast-align
-Wfloat-equal
-Wmissing-format-attribute
-Wpointer-arith
-Wredundant-decls
-Wundef
-Wunused-parameter
-Wwrite-strings)

if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_GREATER "3.3")
list(APPEND NEEDED_COMPILER_FLAGS
-Wextra
-Winit-self)
### Compiler Warnings

set(C_WARNING_FLAGS)
set(CXX_WARNING_FLAGS)

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

set(WARNING_CANDIDATES
-W
-Wall
-Wextra
-Wcast-align
-Wduplicated-cond
-Wextra-semi
-Wextra-semi-stmt
-Wextra-tokens
-Wfloat-equal
-Wgnu
-Winit-self
-Wint-in-bool-context
-Wlogical-op
-Wmissing-format-attribute
-Wnested-externs
-Wnull-dereference
-Wpointer-arith
-Wredundant-decls
-Wredundant-move
-Wreorder-ctor
-Wrestrict
-Wreturn-std-move
-Wself-assign
-Wself-move
-Wsemicolon-before-method-body
-Wsentinel
-Wshadow
-Wsign-compare
-Wsometimes-uninitialized
-Wstrict-prototypes
-Wstring-conversion
-Wsuggest-destructor-override
-Wsuggest-override
-Wuninitialized
-Wunreachable-code
-Wunused
-Wunused-const-variable
-Wunused-parameter
-Wunused-result
-Wwrite-strings
)

if(MINGW)
# Disable excessive warnings since we're using __USE_MINGW_ANSI_STDIO
# Hopefully, any potential issues will be spotted on other platforms
list(APPEND WARNING_CANDIDATES -Wno-format)
else()
list(APPEND WARNING_CANDIDATES -Wformat-security)
endif()

foreach(FLAG ${WARNING_CANDIDATES})
tr_make_id("${FLAG}" FLAG_ID)

# if available, add to C warnings
set(CACHE_ID "${CMAKE_C_COMPILER_ID}_C_HAS${FLAG_ID}")
string(TOLOWER "${CACHE_ID}" CACHE_ID)
check_c_compiler_flag(${FLAG} ${CACHE_ID})
if (${CACHE_ID})
list(APPEND C_WARNING_FLAGS ${FLAG})
endif()

if(MINGW)
# Disable excessive warnings since we're using __USE_MINGW_ANSI_STDIO
# Hopefully, any potential issues will be spotted on other platforms
list(APPEND NEEDED_COMPILER_FLAGS -Wno-format)
else()
list(APPEND NEEDED_COMPILER_FLAGS -Wformat-security)
# if available, add to CXX warnings
set(CACHE_ID "${CMAKE_CXX_COMPILER_ID}_CXX_HAS${FLAG_ID}")
string(TOLOWER "${CACHE_ID}" CACHE_ID)
check_cxx_compiler_flag(${FLAG} ${CACHE_ID})
if (${CACHE_ID})
list(APPEND CXX_WARNING_FLAGS ${FLAG})
endif()

set(NEEDED_C_COMPILER_FLAGS
${NEEDED_COMPILER_FLAGS}
-Winline
-Wmissing-declarations
-Wnested-externs
-Wstrict-prototypes)
string(REPLACE ";" " " NEEDED_C_COMPILER_FLAGS_STRING "${NEEDED_C_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NEEDED_C_COMPILER_FLAGS_STRING}")
unset(CACHE_ID)
unset(FLAG_ID)
endforeach()

set(NEEDED_CXX_COMPILER_FLAGS
${NEEDED_COMPILER_FLAGS})
string(REPLACE ";" " " NEEDED_CXX_COMPILER_FLAGS_STRING "${NEEDED_CXX_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NEEDED_CXX_COMPILER_FLAGS_STRING}")
endif()
unset(WARNING_CANDIDATES)

###

include(LargeFileSupport)

Expand Down Expand Up @@ -524,18 +573,20 @@ else()
endif()

if(NOT CMAKE_VERSION VERSION_LESS "3.7.2")
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY clang-tidy)
if (CLANG_TIDY STREQUAL "CLANG_TIDY-NOTFOUND")
message(STATUS "Looking for clang-tidy - not found")
else()
message(STATUS "Looking for clang-tidy - found")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}")
endif()
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY clang-tidy)
if (CLANG_TIDY STREQUAL "CLANG_TIDY-NOTFOUND")
message(STATUS "Looking for clang-tidy - not found")
else()
message(STATUS "Looking for clang-tidy - found")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}")
endif()
endif()

if(ENABLE_TESTS)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()

function(tr_install_web DST_DIR)
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Expand Up @@ -24,7 +24,8 @@ SUBDIRS = \
$(CLI_DIR) \
$(GTK_DIR) \
$(MAC_DIR) \
web
web \
tests

EXTRA_DIST = \
qt \
Expand Down
1 change: 1 addition & 0 deletions code_style.sh
Expand Up @@ -27,6 +27,7 @@ xargs \

find \
qt \
tests \
\( -name '*.cc' -o -name '*.h' \) \
-print0 |
xargs \
Expand Down
7 changes: 5 additions & 2 deletions configure.ac
Expand Up @@ -16,7 +16,7 @@ AC_CONFIG_MACRO_DIR([m4])

dnl AM_CONFIG_HEADER(config.h)
AC_CONFIG_SRCDIR(libtransmission/transmission.h)
AM_INIT_AUTOMAKE([1.9 tar-pax no-dist-gzip dist-xz foreign])
AM_INIT_AUTOMAKE([1.9 tar-pax no-dist-gzip dist-xz foreign subdir-objects])
LT_INIT
LT_LIB_M

Expand Down Expand Up @@ -83,7 +83,7 @@ AC_PROG_CXX
AC_C_INLINE
if test "x$GCC" = "xyes" ; then

CFLAGS="$CFLAGS -std=gnu99 -ggdb3 -Wall -W -Wpointer-arith -Wformat-security -Wundef -Wcast-align -Wstrict-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Wunused-parameter -Wwrite-strings -Winline -Wfloat-equal"
CFLAGS="$CFLAGS -std=gnu99 -ggdb3 -Wall -W -Wpointer-arith -Wformat-security -Wundef -Wcast-align -Wstrict-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Wunused-parameter -Wwrite-strings -Wfloat-equal"

dnl figure out gcc version
AC_MSG_CHECKING([gcc version])
Expand Down Expand Up @@ -675,6 +675,9 @@ AC_CONFIG_FILES([Makefile
web/style/transmission/images/buttons/Makefile
web/javascript/Makefile
web/javascript/jquery/Makefile
tests/Makefile
tests/gtest/Makefile
tests/libtransmission/Makefile
po/Makefile.in])

AC_OUTPUT
Expand Down
3 changes: 3 additions & 0 deletions daemon/CMakeLists.txt
Expand Up @@ -6,6 +6,9 @@ endif()

include_directories(
${CMAKE_SOURCE_DIR}
)
include_directories(
SYSTEM
${CURL_INCLUDE_DIRS}
${EVENT2_INCLUDE_DIRS}
)
Expand Down
5 changes: 5 additions & 0 deletions gtk/CMakeLists.txt
@@ -1,5 +1,7 @@
project(trgtk)

add_compile_options(${C_WARNING_FLAGS})

if(WITH_LIBAPPINDICATOR)
add_definitions(-DHAVE_LIBAPPINDICATOR)
endif()
Expand Down Expand Up @@ -119,6 +121,9 @@ set(${PROJECT_NAME}_HEADERS
include_directories(
${CMAKE_SOURCE_DIR}
${PROJECT_BINARY_DIR}
)
include_directories(
SYSTEM
${LIBAPPINDICATOR_INCLUDE_DIRS}
${GTK_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
Expand Down
1 change: 0 additions & 1 deletion gtk/conf.c
Expand Up @@ -39,7 +39,6 @@
#include "util.h"

#define MY_CONFIG_NAME "transmission"
#define MY_READABLE_NAME "transmission-gtk"

static char* gl_confdir = NULL;

Expand Down
5 changes: 2 additions & 3 deletions gtk/details.c
Expand Up @@ -656,7 +656,7 @@ static char* get_short_date_string(time_t t)
tr_localtime_r(&t, &tm);
strftime(buf, sizeof(buf), "%d %b %Y", &tm);
return g_locale_to_utf8(buf, -1, NULL, NULL, NULL);
};
}

static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
{
Expand Down Expand Up @@ -1993,7 +1993,7 @@ static void setPeerViewColumns(GtkTreeView* peer_view)
so create a non-visible column and assign it as the
'expander column. */
{
GtkTreeViewColumn* c = gtk_tree_view_column_new();
c = gtk_tree_view_column_new();
gtk_tree_view_column_set_visible(c, FALSE);
gtk_tree_view_append_column(GTK_TREE_VIEW(peer_view), c);
gtk_tree_view_set_expander_column(GTK_TREE_VIEW(peer_view), c);
Expand Down Expand Up @@ -2374,7 +2374,6 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (g_hash_table_lookup(hash, gstr->str) == NULL)
{
GtkTreePath* p;
GtkTreeIter iter;
GtkTreeRowReference* ref;

gtk_list_store_insert_with_values(store, &iter, -1,
Expand Down
2 changes: 0 additions & 2 deletions gtk/file-list.c
Expand Up @@ -22,9 +22,7 @@
#include "tr-prefs.h"
#include "util.h"

#define TR_DOWNLOAD_KEY "tr-download-key"
#define TR_COLUMN_ID_KEY "tr-model-column-id-key"
#define TR_PRIORITY_KEY "tr-priority-key"

enum
{
Expand Down
24 changes: 11 additions & 13 deletions gtk/icons.c
Expand Up @@ -60,19 +60,17 @@ static int get_size_in_pixels(GtkWidget* widget, GtkIconSize icon_size)

static IconCache* icon_cache_new(GtkWidget* for_widget, int icon_size)
{
IconCache* icon_cache;

g_return_val_if_fail(for_widget != NULL, NULL);

icon_cache = g_new0(IconCache, 1);
icon_cache->icon_theme = gtk_icon_theme_get_for_screen(gtk_widget_get_screen(for_widget));
icon_cache->icon_size = get_size_in_pixels(for_widget, icon_size);
icon_cache->cache = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);
IconCache* icons = g_new0(IconCache, 1);
icons->icon_theme = gtk_icon_theme_get_for_screen(gtk_widget_get_screen(for_widget));
icons->icon_size = get_size_in_pixels(for_widget, icon_size);
icons->cache = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_object_unref);

g_hash_table_insert(icon_cache->cache, (void*)VOID_PIXBUF_KEY, create_void_pixbuf(icon_cache->icon_size,
icon_cache->icon_size));
g_hash_table_insert(icons->cache, (void*)VOID_PIXBUF_KEY, create_void_pixbuf(icons->icon_size,
icons->icon_size));

return icon_cache;
return icons;
}

static char const* _icon_cache_get_icon_key(GIcon* icon)
Expand Down Expand Up @@ -183,7 +181,7 @@ static GdkPixbuf* _get_icon_pixbuf(GIcon* icon, int size, GtkIconTheme* theme)
return NULL;
}

static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icon_cache, char const* mime_type)
static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icons, char const* mime_type)
{
GIcon* icon;
char const* key = NULL;
Expand All @@ -197,7 +195,7 @@ static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icon_cache, char cons
key = VOID_PIXBUF_KEY;
}

pixbuf = g_hash_table_lookup(icon_cache->cache, key);
pixbuf = g_hash_table_lookup(icons->cache, key);

if (pixbuf != NULL)
{
Expand All @@ -206,11 +204,11 @@ static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icon_cache, char cons
return pixbuf;
}

pixbuf = _get_icon_pixbuf(icon, icon_cache->icon_size, icon_cache->icon_theme);
pixbuf = _get_icon_pixbuf(icon, icons->icon_size, icons->icon_theme);

if (pixbuf != NULL)
{
g_hash_table_insert(icon_cache->cache, (gpointer)key, g_object_ref(pixbuf));
g_hash_table_insert(icons->cache, (gpointer)key, g_object_ref(pixbuf));
}

g_object_unref(G_OBJECT(icon));
Expand Down
2 changes: 1 addition & 1 deletion gtk/notify.c
Expand Up @@ -74,7 +74,7 @@ static void get_capabilities_callback(GObject* source, GAsyncResult* res, gpoint
g_variant_unref(result);
}

static void g_signal_callback(GDBusProxy* proxy UNUSED, char* sender_name UNUSED, char* signal_name, GVariant* params,
static void g_signal_callback(GDBusProxy* dbus_proxy UNUSED, char* sender_name UNUSED, char* signal_name, GVariant* params,
gpointer user_data UNUSED)
{
guint id;
Expand Down
2 changes: 1 addition & 1 deletion gtk/tr-core.c
Expand Up @@ -87,7 +87,7 @@ static int core_is_disposed(TrCore const* core)
return core == NULL || core->priv->sorted_model == NULL;
}

G_DEFINE_TYPE_WITH_CODE(TrCore, tr_core, G_TYPE_OBJECT, G_ADD_PRIVATE(TrCore));
G_DEFINE_TYPE_WITH_CODE(TrCore, tr_core, G_TYPE_OBJECT, G_ADD_PRIVATE(TrCore))

static void core_dispose(GObject* o)
{
Expand Down
4 changes: 1 addition & 3 deletions gtk/tr-prefs.c
Expand Up @@ -98,7 +98,7 @@ static gboolean spun_cb_idle(gpointer spin)
struct spin_idle_data* data = g_object_get_data(o, IDLE_DATA);

/* has the user stopped making changes? */
if (g_timer_elapsed(data->last_change, NULL) > 0.33F)
if (g_timer_elapsed(data->last_change, NULL) > 0.33)
{
/* update the core */
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(o, PREF_KEY));
Expand Down Expand Up @@ -804,8 +804,6 @@ static GtkWidget* remotePage(GObject* core)
GtkCellRenderer* r;
GtkTreeSelection* sel;
GtkTreeView* v;
GtkWidget* w;
GtkWidget* h;

page->store = GTK_LIST_STORE(m);
w = gtk_tree_view_new_with_model(m);
Expand Down

0 comments on commit 677dc73

Please sign in to comment.