Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a new internal header file for definitions of handy macros providing convenient assertion testing functionality. * libpam/include/test_assert.h: New file. * libpam/Makefile.am (noinst_HEADERS): Add include/test_assert.h.
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Assert definitions for tests. | ||
* | ||
* Copyright (c) 2020 Dmitry V. Levin <ldv@altlinux.org> | ||
*/ | ||
|
||
#ifndef TEST_ASSERT_H | ||
# define TEST_ASSERT_H | ||
|
||
# ifdef HAVE_CONFIG_H | ||
# include <config.h> | ||
# endif | ||
|
||
# include <stdio.h> | ||
# include <stdlib.h> | ||
|
||
# define ASSERT_(expected_, expected_str_, op_, seen_, seen_str_) \ | ||
do { \ | ||
__typeof__(expected_) e_ = (expected_); \ | ||
__typeof__(seen_) s_ = (seen_); \ | ||
if (e_ op_ s_) break; \ | ||
fprintf(stderr, \ | ||
"%s:%d: Assertion failed: %s (%#lx) %s %s (%#lx)\n", \ | ||
__FILE__, __LINE__, \ | ||
(expected_str_), (unsigned long) e_, #op_, \ | ||
(seen_str_), (unsigned long) s_); \ | ||
abort(); \ | ||
} while (0) \ | ||
/* End of ASSERT_ definition. */ | ||
|
||
# define ASSERT_EQ(expected_, seen_) \ | ||
ASSERT_((expected_), #expected_, ==, (seen_), #seen_) \ | ||
/* End of ASSERT_EQ definition. */ | ||
|
||
# define ASSERT_NE(expected_, seen_) \ | ||
ASSERT_((expected_), #expected_, !=, (seen_), #seen_) \ | ||
/* End of ASSERT_NE definition. */ | ||
|
||
# define ASSERT_LT(expected_, seen_) \ | ||
ASSERT_((expected_), #expected_, <, (seen_), #seen_) \ | ||
/* End of ASSERT_LT definition. */ | ||
|
||
# define ASSERT_LE(expected_, seen_) \ | ||
ASSERT_((expected_), #expected_, <=, (seen_), #seen_) \ | ||
/* End of ASSERT_LT definition. */ | ||
|
||
# define ASSERT_GT(expected_, seen_) \ | ||
ASSERT_((expected_), #expected_, >, (seen_), #seen_) \ | ||
/* End of ASSERT_LT definition. */ | ||
|
||
# define ASSERT_GE(expected_, seen_) \ | ||
ASSERT_((expected_), #expected_, >=, (seen_), #seen_) \ | ||
/* End of ASSERT_LT definition. */ | ||
|
||
#endif /* TEST_ASSERT_H */ |