Commit Graph

74 Commits

Author SHA1 Message Date
Thomas Haller
a2c843499c all/tests: split core part out of "nm-test-utils.h"
A large part of "nm-test-utils.h" is only relevant for tests inside "src/"
directory, as they are helpers related to NetworkManager core part.

Split this part out of "nm-test-utils.h" header.
2016-05-17 16:48:52 +02:00
Thomas Haller
5847e70fd6 shared: add _nm_pure/_nm_const define for __attribute__ ((pure))/((const)) 2016-05-16 13:09:02 +02:00
Thomas Haller
b871106e25 macros: define NM_MORE_ASSERTS is not defined
In NetworkManager's configure script we have --with-more-asserts
option which always defines NM_MORE_ASSERTS in config.h.

When reusing the header file outside of NetworkManager, the
NM_MORE_ASSERTS define might be unset. Define it in that case
to avoid compiler warnings about undefined preprocessor define.
2016-05-14 23:11:59 +02:00
Thomas Haller
ba90c9601c all: replace nm_unauto() by g_steal_pointer()
They do essentially the same.
2016-05-12 14:28:44 +02:00
Thomas Haller
5d1c4ca6c4 nm-glib: backport g_steal_pointer() from glib-2.44 2016-05-12 14:25:36 +02:00
Thomas Haller
ee29228277 shared: add define _nm_unused for __attribute__((unused))
This is both supported by clang and gcc. Using it is nicer then
casting the (void), which requires an additional line of code.
2016-05-12 09:59:09 +02:00
Thomas Haller
fbf4904ae0 nmtst: allow non-boolean argument to nmtst_assert_success()
Reimplement nmtst_assert_success() as a macro which allows non-boolean @success
arguments.
2016-05-09 11:04:51 +02:00
Thomas Haller
05478e4f4c utils: refactor _nm_utils_ascii_str_to_int64()
To allow for trailing whitespace, we don't need to copy and trunacate
the input string. g_ascii_strtoll() conveniently returns the location via
the endptr argument.
2016-05-03 11:52:39 +02:00
Thomas Haller
6bf022359f core/trivial: rename "source" field of addresses and routes
The "source" field of NMPlatformIPRoute (now "rt_source") maps to the
protocol field of the route. The source of NMPlatformIPAddress (now
"addr_source") has no direct equivalent in the kernel.

As their use is different, they should have different names. Also,
the name "source" is used all over the place. Hence give the fields
a more distinct name.
2016-04-28 12:53:21 +02:00
Thomas Haller
186787744c shared: move nm_utils_ascii_str_to_bool() to shared/nm-shared-utils.h 2016-04-19 13:47:41 +02:00
Thomas Haller
9a1e0b97da shared: add _nm_packed macro for __attribute__((packed)) 2016-04-11 11:26:36 +02:00
Thomas Haller
2e6ec6d8ac nmtst: add nmtst_platform_ip4_address() util 2016-04-11 11:26:32 +02:00
Thomas Haller
0e78ce5ed6 nmtst: add nmtst_rand_buf() util 2016-04-11 11:22:50 +02:00
Lubomir Rintel
350d96a9ee release: bump version to 1.3.0 (development) 2016-04-05 22:22:58 +02:00
Lubomir Rintel
f4b4e35c79 release: add version 1.4 macros 2016-04-05 22:22:58 +02:00
Thomas Haller
9152dec99f build: disable deprecation checks for internal compilation
For internal compilation we want to be able to use deprecated
API without warnings.

Define the version min/max macros to effectively disable deprecation
warnings.

However, don't do it via CFLAGS option in the makefiles, instead hack it
to "nm-default.h". After all, *every* source file that is for internal
compilation needs to include this header as first.
2016-04-05 22:22:58 +02:00
Thomas Haller
88655999df shared: add nm_g_object_set_property() 2016-03-26 12:10:54 +01:00
Thomas Haller
72216f7359 shared: move NM_UTILS_ERROR to shared-utils
NM_UTILS_ERROR is our way to say, that we don't care about
the GError domain and code. nmcli sometimes passes domain "1"
and code "0" to g_set_error(), which could be considered
a bug.

We usually don't care about the error but only about the error
message, so let's have a universally available error quark around.
2016-03-26 12:10:53 +01:00
Thomas Haller
fafc90526b shared: move _nm_utils_ascii_str_to_int64() to "shared/nm-shared-utils.h"
_nm_utils_ascii_str_to_int64() was declared in libnm-core's internal
header "nm-core-internal.h" and thus available for libnm-core, libnm,
NetworkManager and related.

It also means, the function was not available in libnm-util, libnm-glib,
clients or dispatcher. So, we either reimplemented it (nmc_string_to_int_base)
or struggle with the awkward strtol* API.
2016-03-26 12:10:53 +01:00
Thomas Haller
5de30dd029 shared: include "nm-shared-utils.h"
Include it via "nm-default.h" to all projects.
2016-03-26 12:10:53 +01:00
Thomas Haller
330026db90 shared: add "nm-shared-utils" 2016-03-26 12:10:53 +01:00
Thomas Haller
3025bfc8b2 shared: add nm_auto_unset_gvalue macro 2016-03-26 12:10:53 +01:00
Thomas Haller
2c8ef153a1 nmtst: add nmtst_variant_new_vardict() function 2016-03-26 12:10:53 +01:00
Thomas Haller
d45107c1de nmtst: fix memleak when using NMTST_VARIANT_DROP_SETTING() 2016-03-26 12:10:53 +01:00
Thomas Haller
2c11e23c34 shared: include <stdlib.h> in "nm-macros-internal.h"
"nm-macros-internal.h" uses free() for the "nm_auto_free"
macro. Thus, as long as that code is there, we anyway must
include <stdlib.h> along the line.

Do it in "nm-macros-internal.h" to make the header self-contained.
2016-03-24 10:10:53 +01:00
Thomas Haller
0330a55851 shared: add nm_unauto() helper macro 2016-03-17 15:00:48 +01:00
Thomas Haller
a50d28d4dd shared: add nm_assert_not_reached() 2016-03-17 15:00:48 +01:00
Thomas Haller
b5c8d496c2 nmtst: add NMTST_DEBUG option "D" 2016-03-15 12:56:57 +01:00
Thomas Haller
4a00bcf5a6 shared: add nm_g_object_ref() and nm_g_object_unref() function 2016-03-13 12:31:04 +01:00
Thomas Haller
0cee9ef7b5 nmtst: add nmtst_main_loop_quit_on_notify function 2016-03-10 16:46:50 +01:00
Thomas Haller
3a09a7e991 nmtst: add nmtst_assert_variant_*() helper macros 2016-03-10 14:49:55 +01:00
Thomas Haller
2ff11525c6 nmtst: convert nmtst_assert_error() to a macro to preserve func:line information
Within the macro, the assertion print the proper location of where
the failure happens, instead of pointing to "nm-test-utils.h".
2016-03-04 17:01:41 +01:00
Thomas Haller
01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
7871d850f5 shared: add NM_G_ERROR_MSG() 2016-03-03 18:54:20 +01:00
Thomas Haller
7f43e0a7b3 platform/trivial: rename NMPlatformIP6Address's "flags" field to "n_ifa_flags"
There are far too many "flags". Rename the "flags" to "n_ifa_flags"
which reminds to "ifa_flags" in 'struct ifaddrmsg', but with a
distinctive "n_" prefix.
2016-02-29 16:27:08 +01:00
Thomas Haller
e18cdc10d3 platform: adjust type of IPv6 address flags to guint
Address flags inside 'struct ifaddrmsg' are uint8_t and they are
extended to uint32_t via IFA_FLAGS.

Change it to be guint32.
2016-02-29 16:27:08 +01:00
Thomas Haller
3a81c0f301 macros: add nm_auto() macro to cleanup functions 2016-02-29 14:08:00 +01:00
Thomas Haller
17779975c8 nm-glib: backport g_info() macro 2016-02-24 20:04:29 +01:00
Thomas Haller
4eb5ba8b02 macros: split macro NM_GOBJECT_PROPERTIES_DEFINE() in two
Sometimes we don't need the _notify() helper which results in a
unused-function warning.
2016-02-19 19:59:05 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
6d5e55870a shared: fix nm_sprintf_buf() macro to allow plain string
Use non-portable gcc extension to allow for zero variadic
arguments so that you can pass a plain string as argument.
2016-02-19 01:42:29 +01:00
Thomas Haller
6dc431b0c9 shared: move definition of "bool" to nm-macros-internal.h
"nm-default.h" should only include all the relevant header files based
on NETWORKMANAGER_COMPILATION. It should not contain definitions on
it's own.

Move the definition of "bool" to "nm-macros-internal.h".
2016-02-16 20:18:25 +01:00
Thomas Haller
c66ee23f73 macros: add nm_auto_free macro
Similar to gs_free to cleanup pointers with free(). Note that
g_free() and free() cannot be used interchangably.
2016-02-16 14:13:25 +01:00
Thomas Haller
dec3a7e58d shared: add nm_streq() and nm_streq0() macro
Using strcmp() to test for string equality is a well known pattern.
However the inverse logic still is still hard to grasp especially in
more complex expressions.

nm_streq() should is an alternative to use strcmp(). And there is a counterpart
nm_streq0() which is based on g_strcmp0().

Kernel and systemd have also similar streq() macros.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00047.html
2016-02-15 23:47:14 +01:00
Thomas Haller
3d734b30a2 nmtst: drop deprecated test helper macro ASSERT()
It's no longer used.
2016-02-15 14:27:45 +01:00
Thomas Haller
b4cced2cea nmtst: add nmtst_assert_connection_verify() and don't normalize connection in assert
It is ugly that nmtst_assert_connection_verifies_after_normalization() would
normalize the argument and modify it. An assertion should not have side-effects.
2016-02-15 14:26:26 +01:00
Thomas Haller
78f558c706 nmtst: add nmtst_assert_no_success() macro 2016-02-14 23:48:00 +01:00
Thomas Haller
e663b88c59 all/trivial: rename STRLEN() macro to NM_STRLEN()
We should not have defines/macros in header files without a nm/NM
prefix. STRLEN() was one of the few offenders.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00048.html
2016-02-14 11:34:42 +01:00
Thomas Haller
2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Lubomir Rintel
4c3e69f9e9 test: use g_assert_not_reached () instead of asserting FALSE
It's declared as never returning, making do a better at understanding control
flow. Otherwise it makes a poor guess:

  In file included from test-crypto.c:37:
  ../../shared/nm-test-utils.h:1344:3: error: variable 'family' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                  g_assert (FALSE);
                  ^~~~~~~~~~~~~~~~
2016-02-12 09:05:27 +01:00