core/tests: add nm_utils_get_testing() function
Code that is testable often needs special hooks to work both for unit-tests and production. Add a function nm_utils_get_testing() that returns whether the code is run as part of a unit-test. For non-testing mode, nm_utils_get_testing() will return zero (NM_UTILS_TEST_NONE). For unit tests, the test should call _nm_utils_set_testing() to configure tested functions. By specifing the @flags attribute, the test can enable/disable specific behaviors. https://bugzilla.gnome.org/show_bug.cgi?id=701112
This commit is contained in:
@@ -189,4 +189,21 @@ void nm_utils_array_remove_at_indexes (GArray *array, const guint *indexes_to_de
|
||||
|
||||
void nm_utils_setpgid (gpointer unused);
|
||||
|
||||
typedef enum {
|
||||
NM_UTILS_TEST_NONE = 0,
|
||||
|
||||
/* Internal flag, marking that either nm_utils_get_testing() or _nm_utils_set_testing() was called. */
|
||||
_NM_UTILS_TEST_INITIALIZED = (1LL << 0),
|
||||
|
||||
/* Indicate that test mode is enabled in general. Explicitly calling _nm_utils_set_testing() will always set this flag. */
|
||||
_NM_UTILS_TEST_GENERAL = (1LL << 1),
|
||||
|
||||
_NM_UTILS_TEST_LAST,
|
||||
NM_UTILS_TEST_ALL = (((_NM_UTILS_TEST_LAST - 1) << 1) - 1) & ~(_NM_UTILS_TEST_INITIALIZED),
|
||||
} NMUtilsTestFlags;
|
||||
|
||||
gboolean nm_utils_get_testing_initialized (void);
|
||||
NMUtilsTestFlags nm_utils_get_testing (void);
|
||||
void _nm_utils_set_testing (NMUtilsTestFlags flags);
|
||||
|
||||
#endif /* __NETWORKMANAGER_UTILS_H__ */
|
||||
|
Reference in New Issue
Block a user