aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2014-07-19 18:51:18 +0100
committerAndreas Schneider <asn@cryptomilk.org>2014-07-23 07:40:01 +0200
commit8642ef21b07e025a9aa117867811a725e2fb597e (patch)
tree3bb65365111a379cb4542e1f636d427e1bf9ae7d
parent61b2b557951a88441a88e37bb0014e158cc8a14d (diff)
downloadcmocka-8642ef21b07e025a9aa117867811a725e2fb597e.tar.gz
cmocka-8642ef21b07e025a9aa117867811a725e2fb597e.tar.xz
cmocka-8642ef21b07e025a9aa117867811a725e2fb597e.zip
cmocka: introduce LargestIntegralTypePrintfUnsignedFormat modifier
The modifier is almost identical to LargestIntegralTypePrintfFormat in terms that it handles 64bit integer values, but unlike the latter it prints them as unsigned value. Behind the scenes it uses %I64u for windows, and %llu otherwise. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/cmocka.h9
-rw-r--r--src/cmocka.c22
2 files changed, 24 insertions, 7 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index a60b2a5..5814805 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -85,6 +85,15 @@ int __stdcall IsDebuggerPresent();
#endif /* _WIN32 */
#endif /* LargestIntegralTypePrintfFormat */
+/* Printf format used to display LargestIntegralType as unsigned. */
+#ifndef LargestIntegralTypePrintfUnsignedFormat
+#ifdef _WIN32
+#define LargestIntegralTypePrintfUnsignedFormat "%I64u"
+#else
+#define LargestIntegralTypePrintfUnsignedFormat "%llu"
+#endif /* _WIN32 */
+#endif /* LargestIntegralTypePrintfFormat */
+
/* Perform an unsigned cast to LargestIntegralType. */
#define cast_to_largest_integral_type(value) \
((LargestIntegralType)((size_t)(value)))
diff --git a/src/cmocka.c b/src/cmocka.c
index 1857277..ef6ee8a 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -819,9 +819,10 @@ static int value_in_set_display_error(
if (succeeded) {
return 1;
}
- print_error("%llu is %sin the set (", value, invert ? "" : "not ");
+ print_error(LargestIntegralTypePrintfUnsignedFormat
+ "is %sin the set (", value, invert ? "" : "not ");
for (i = 0; i < size_of_set; i++) {
- print_error("%llu, ", set[i]);
+ print_error(LargestIntegralTypePrintfUnsignedFormat ", ", set[i]);
}
print_error(")\n");
}
@@ -840,8 +841,11 @@ static int integer_in_range_display_error(
if (value >= range_min && value <= range_max) {
return 1;
}
- print_error("%llu is not within the range %llu-%llu\n", value, range_min,
- range_max);
+ print_error(LargestIntegralTypePrintfUnsignedFormat
+ " is not within the range "
+ LargestIntegralTypePrintfUnsignedFormat "-"
+ LargestIntegralTypePrintfUnsignedFormat "\n",
+ value, range_min, range_max);
return 0;
}
@@ -857,8 +861,11 @@ static int integer_not_in_range_display_error(
if (value < range_min || value > range_max) {
return 1;
}
- print_error("%llu is within the range %llu-%llu\n", value, range_min,
- range_max);
+ print_error(LargestIntegralTypePrintfUnsignedFormat
+ " is within the range "
+ LargestIntegralTypePrintfUnsignedFormat "-"
+ LargestIntegralTypePrintfUnsignedFormat "\n",
+ value, range_min, range_max);
return 0;
}
@@ -1334,7 +1341,8 @@ void _assert_return_code(const LargestIntegralType result,
if (result > valmax - 1) {
if (error > 0) {
- print_error("%s < 0, errno(%llu): %s\n",
+ print_error("%s < 0, errno("
+ LargestIntegralTypePrintfUnsignedFormat "): %s\n",
expression, error, strerror(error));
} else {
print_error("%s < 0\n", expression);