From: Michael Stefaniuc Subject: [PATCH 2/2] ntdll/tests: Avoid ARRAY_SIZE-like macros Message-Id: <20180621210612.6849-3-mstefani@winehq.org> Date: Thu, 21 Jun 2018 23:06:12 +0200 Signed-off-by: Michael Stefaniuc --- dlls/ntdll/tests/large_int.c | 8 +++----- dlls/ntdll/tests/rtl.c | 6 ++---- dlls/ntdll/tests/rtlstr.c | 31 +++++++++++-------------------- dlls/ntdll/tests/string.c | 24 ++++++++++-------------- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/dlls/ntdll/tests/large_int.c b/dlls/ntdll/tests/large_int.c index da7afa4f25..c980aebe5d 100644 --- a/dlls/ntdll/tests/large_int.c +++ b/dlls/ntdll/tests/large_int.c @@ -102,7 +102,6 @@ static const magic_divide_t magic_divide[] = { { ULL(0x74ae3b5f,0x1558c800), ULL(0x2f1e28fd,0x1b5cca00), 41, 0xabcde}, }; -#define NB_MAGIC_DIVIDE (sizeof(magic_divide)/sizeof(*magic_divide)) static void test_RtlExtendedMagicDivide(void) @@ -110,7 +109,7 @@ static void test_RtlExtendedMagicDivide(void) int i; LONGLONG result; - for (i = 0; i < NB_MAGIC_DIVIDE; i++) { + for (i = 0; i < ARRAY_SIZE(magic_divide); i++) { result = pRtlExtendedMagicDivide(magic_divide[i].a, magic_divide[i].b, magic_divide[i].shift); ok(result == magic_divide[i].result, "call failed: RtlExtendedMagicDivide(0x%s, 0x%s, %d) has result 0x%s, expected 0x%s\n", @@ -271,7 +270,6 @@ static const largeint2str_t largeint2str[] = { {20, 0xdeadbeef, 0, 9, "-------------------------------------------------------------------", STATUS_INVALID_PARAMETER}, {-8, 07654321, 0, 12, "-------------------------------------------------------------------", STATUS_INVALID_PARAMETER}, }; -#define NB_LARGEINT2STR (sizeof(largeint2str)/sizeof(*largeint2str)) static void one_RtlInt64ToUnicodeString_test(int test_num, const largeint2str_t *largeint2str) @@ -360,7 +358,7 @@ static void test_RtlInt64ToUnicodeString(void) { int test_num; - for (test_num = 0; test_num < NB_LARGEINT2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(largeint2str); test_num++) { one_RtlInt64ToUnicodeString_test(test_num, &largeint2str[test_num]); } /* for */ } @@ -405,7 +403,7 @@ static void test_RtlLargeIntegerToChar(void) int test_num; ULONGLONG value; - for (test_num = 0; test_num < NB_LARGEINT2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(largeint2str); test_num++) { one_RtlLargeIntegerToChar_test(test_num, &largeint2str[test_num]); } /* for */ diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c index db3dc9ff4e..e202408caa 100644 --- a/dlls/ntdll/tests/rtl.c +++ b/dlls/ntdll/tests/rtl.c @@ -708,7 +708,6 @@ static const all_accesses_t all_accesses[] = { {0xFEDCBA76, 0xC8C4B242, 1}, {0xC8C4B242, 0xFEDCBA76, 0}, }; -#define NB_ALL_ACCESSES (sizeof(all_accesses)/sizeof(*all_accesses)) static void test_RtlAreAllAccessesGranted(void) @@ -722,7 +721,7 @@ static void test_RtlAreAllAccessesGranted(void) return; } - for (test_num = 0; test_num < NB_ALL_ACCESSES; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(all_accesses); test_num++) { result = pRtlAreAllAccessesGranted(all_accesses[test_num].GrantedAccess, all_accesses[test_num].DesiredAccess); ok(all_accesses[test_num].result == result, @@ -751,7 +750,6 @@ static const any_accesses_t any_accesses[] = { {0xFEDCBA76, 0x00040000, 1}, {0xFED8BA76, 0x00040000, 0}, }; -#define NB_ANY_ACCESSES (sizeof(any_accesses)/sizeof(*any_accesses)) static void test_RtlAreAnyAccessesGranted(void) @@ -765,7 +763,7 @@ static void test_RtlAreAnyAccessesGranted(void) return; } - for (test_num = 0; test_num < NB_ANY_ACCESSES; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(any_accesses); test_num++) { result = pRtlAreAnyAccessesGranted(any_accesses[test_num].GrantedAccess, any_accesses[test_num].DesiredAccess); ok(any_accesses[test_num].result == result, diff --git a/dlls/ntdll/tests/rtlstr.c b/dlls/ntdll/tests/rtlstr.c index 53cc185939..8b948fa82a 100644 --- a/dlls/ntdll/tests/rtlstr.c +++ b/dlls/ntdll/tests/rtlstr.c @@ -406,7 +406,6 @@ static const dupl_ustr_t dupl_ustr[] = { { 3, 0, 2, 2, NULL, 40, 42, 42, NULL, 40, 42, 0, NULL, STATUS_INVALID_PARAMETER}, { 3, 0, 0, 0, NULL, 40, 42, 42, NULL, 0, 2, 2, "", STATUS_SUCCESS}, }; -#define NB_DUPL_USTR (sizeof(dupl_ustr)/sizeof(*dupl_ustr)) static void test_RtlDuplicateUnicodeString(void) @@ -429,7 +428,7 @@ static void test_RtlDuplicateUnicodeString(void) return; } - for (test_num = 0; test_num < NB_DUPL_USTR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(dupl_ustr); test_num++) { source_str.Length = dupl_ustr[test_num].source_Length; source_str.MaximumLength = dupl_ustr[test_num].source_MaximumLength; if (dupl_ustr[test_num].source_buf != NULL) { @@ -776,7 +775,6 @@ static const ustr2astr_t ustr2astr[] = { { 0, 0, 12, NULL, 10, 10, 12, NULL, FALSE, 5, 0, 0, NULL, STATUS_BUFFER_OVERFLOW}, #endif }; -#define NB_USTR2ASTR (sizeof(ustr2astr)/sizeof(*ustr2astr)) static void test_RtlUnicodeStringToAnsiString(void) @@ -789,7 +787,7 @@ static void test_RtlUnicodeStringToAnsiString(void) NTSTATUS result; unsigned int test_num; - for (test_num = 0; test_num < NB_USTR2ASTR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(ustr2astr); test_num++) { ansi_str.Length = ustr2astr[test_num].ansi_Length; ansi_str.MaximumLength = ustr2astr[test_num].ansi_MaximumLength; if (ustr2astr[test_num].ansi_buf != NULL) { @@ -852,7 +850,6 @@ static const app_asc2str_t app_asc2str[] = { { 5, 14, 15, NULL, NULL, 5, 14, 15, NULL, STATUS_SUCCESS}, { 5, 12, 15, "Tst\0S01234abcde", "tr\0i", 7, 12, 15, "Tst\0Str234abcde", STATUS_SUCCESS}, }; -#define NB_APP_ASC2STR (sizeof(app_asc2str)/sizeof(*app_asc2str)) static void test_RtlAppendAsciizToString(void) @@ -862,7 +859,7 @@ static void test_RtlAppendAsciizToString(void) NTSTATUS result; unsigned int test_num; - for (test_num = 0; test_num < NB_APP_ASC2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(app_asc2str); test_num++) { dest_str.Length = app_asc2str[test_num].dest_Length; dest_str.MaximumLength = app_asc2str[test_num].dest_MaximumLength; if (app_asc2str[test_num].dest_buf != NULL) { @@ -922,7 +919,6 @@ static const app_str2str_t app_str2str[] = { { 5, 14, 15, NULL, 0, 0, 7, NULL, 5, 14, 15, NULL, STATUS_SUCCESS}, { 5, 12, 15, "Tst\0S01234abcde", 4, 4, 7, "tr\0iZY", 9, 12, 15, "Tst\0Str\0i4abcde", STATUS_SUCCESS}, }; -#define NB_APP_STR2STR (sizeof(app_str2str)/sizeof(*app_str2str)) static void test_RtlAppendStringToString(void) @@ -934,7 +930,7 @@ static void test_RtlAppendStringToString(void) NTSTATUS result; unsigned int test_num; - for (test_num = 0; test_num < NB_APP_STR2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(app_str2str); test_num++) { dest_str.Length = app_str2str[test_num].dest_Length; dest_str.MaximumLength = app_str2str[test_num].dest_MaximumLength; if (app_str2str[test_num].dest_buf != NULL) { @@ -1005,7 +1001,6 @@ static const app_uni2str_t app_uni2str[] = { { 4, 14, 14, "Fake0123abcdef", "U\0stri\0", 10, 14, 14, "FakeU\0stri\0\0ef", STATUS_SUCCESS}, { 6, 14, 16, "Te\0\0stabcdefghij", "St\0\0ri", 8, 14, 16, "Te\0\0stSt\0\0efghij", STATUS_SUCCESS}, }; -#define NB_APP_UNI2STR (sizeof(app_uni2str)/sizeof(*app_uni2str)) static void test_RtlAppendUnicodeToString(void) @@ -1015,7 +1010,7 @@ static void test_RtlAppendUnicodeToString(void) NTSTATUS result; unsigned int test_num; - for (test_num = 0; test_num < NB_APP_UNI2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(app_uni2str); test_num++) { dest_str.Length = app_uni2str[test_num].dest_Length; dest_str.MaximumLength = app_uni2str[test_num].dest_MaximumLength; if (app_uni2str[test_num].dest_buf != NULL) { @@ -1079,7 +1074,6 @@ static const app_ustr2str_t app_ustr2str[] = { { 4, 14, 14, NULL, 0, 0, 8, NULL, 4, 14, 14, NULL, STATUS_SUCCESS}, { 6, 14, 16, "Te\0\0stabcdefghij", 6, 8, 8, "St\0\0riZY", 12, 14, 16, "Te\0\0stSt\0\0ri\0\0ij", STATUS_SUCCESS}, }; -#define NB_APP_USTR2STR (sizeof(app_ustr2str)/sizeof(*app_ustr2str)) static void test_RtlAppendUnicodeStringToString(void) @@ -1091,7 +1085,7 @@ static void test_RtlAppendUnicodeStringToString(void) NTSTATUS result; unsigned int test_num; - for (test_num = 0; test_num < NB_APP_USTR2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(app_ustr2str); test_num++) { dest_str.Length = app_ustr2str[test_num].dest_Length; dest_str.MaximumLength = app_ustr2str[test_num].dest_MaximumLength; if (app_ustr2str[test_num].dest_buf != NULL) { @@ -1189,7 +1183,6 @@ static const find_ch_in_ustr_t find_ch_in_ustr[] = { { 2, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND}, { 3, "abcdabcdabcdabcdabcdabcd", "abcd", 0, STATUS_NOT_FOUND}, }; -#define NB_FIND_CH_IN_USTR (sizeof(find_ch_in_ustr)/sizeof(*find_ch_in_ustr)) static void test_RtlFindCharInUnicodeString(void) @@ -1209,7 +1202,7 @@ static void test_RtlFindCharInUnicodeString(void) return; } - for (test_num = 0; test_num < NB_FIND_CH_IN_USTR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(find_ch_in_ustr); test_num++) { if (find_ch_in_ustr[test_num].main_str != NULL) { main_str.Length = strlen(find_ch_in_ustr[test_num].main_str) * sizeof(WCHAR); main_str.MaximumLength = main_str.Length + sizeof(WCHAR); @@ -1371,7 +1364,6 @@ static const str2int_t str2int[] = { {-8, "0", 0, STATUS_INVALID_PARAMETER}, /* Negative base */ /* { 0, NULL, 0, STATUS_SUCCESS}, */ /* NULL as string */ }; -#define NB_STR2INT (sizeof(str2int)/sizeof(*str2int)) static void test_RtlUnicodeStringToInteger(void) @@ -1382,7 +1374,7 @@ static void test_RtlUnicodeStringToInteger(void) WCHAR *wstr; UNICODE_STRING uni; - for (test_num = 0; test_num < NB_STR2INT; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2int); test_num++) { wstr = AtoW(str2int[test_num].str); value = 0xdeadbeef; pRtlInitUnicodeString(&uni, wstr); @@ -1451,7 +1443,7 @@ static void test_RtlCharToInteger(void) int value; NTSTATUS result; - for (test_num = 0; test_num < NB_STR2INT; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2int); test_num++) { /* w2k skips a leading '\0' and processes the string after */ if (str2int[test_num].str[0] != '\0') { value = 0xdeadbeef; @@ -1600,7 +1592,6 @@ static const int2str_t int2str[] = { {20, 0xdeadbeef, 0, 9, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* ill. base */ {-8, 07654321, 0, 12, "-----------------------------------", STATUS_INVALID_PARAMETER}, /* neg. base */ }; -#define NB_INT2STR (sizeof(int2str)/sizeof(*int2str)) static void one_RtlIntegerToUnicodeString_test(int test_num, const int2str_t *int2str) @@ -1673,7 +1664,7 @@ static void test_RtlIntegerToUnicodeString(void) { size_t test_num; - for (test_num = 0; test_num < NB_INT2STR; test_num++) + for (test_num = 0; test_num < ARRAY_SIZE(int2str); test_num++) one_RtlIntegerToUnicodeString_test(test_num, &int2str[test_num]); } @@ -1700,7 +1691,7 @@ static void test_RtlIntegerToChar(void) NTSTATUS result; size_t test_num; - for (test_num = 0; test_num < NB_INT2STR; test_num++) + for (test_num = 0; test_num < ARRAY_SIZE(int2str); test_num++) one_RtlIntegerToChar_test(test_num, &int2str[test_num]); result = pRtlIntegerToChar(int2str[0].value, 20, int2str[0].MaximumLength, NULL); diff --git a/dlls/ntdll/tests/string.c b/dlls/ntdll/tests/string.c index 407bc0ffec..708d6e7b65 100644 --- a/dlls/ntdll/tests/string.c +++ b/dlls/ntdll/tests/string.c @@ -212,7 +212,6 @@ static const ulong2str_t ulong2str[] = { {36, 62193781, "111111\0------------------------------------------------------------", 0x77}, {37, 71270178, "111111\0------------------------------------------------------------", 0x77}, }; -#define NB_ULONG2STR (sizeof(ulong2str)/sizeof(*ulong2str)) static void one_itoa_test(int test_num, const ulong2str_t *ulong2str) @@ -276,7 +275,7 @@ static void test_ulongtoa(void) { int test_num; - for (test_num = 0; test_num < NB_ULONG2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(ulong2str); test_num++) { if (ulong2str[test_num].mask & 0x01) { one_itoa_test(test_num, &ulong2str[test_num]); } /* if */ @@ -402,7 +401,7 @@ static void test_ulongtow(void) int test_num; LPWSTR result; - for (test_num = 0; test_num < NB_ULONG2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(ulong2str); test_num++) { if (ulong2str[test_num].mask & 0x10) { one_itow_test(test_num, &ulong2str[test_num]); } /* if */ @@ -588,7 +587,6 @@ static const ulonglong2str_t ulonglong2str[] = { {37, 71270178, "111111\0------------------------------------------------------------", 0x33}, {99, ULL(0x2,0x3c9e468c), "111111\0------------------------------------------------------------", 0x33}, }; -#define NB_ULONGLONG2STR (sizeof(ulonglong2str)/sizeof(*ulonglong2str)) static void one_i64toa_test(int test_num, const ulonglong2str_t *ulonglong2str) @@ -642,7 +640,7 @@ static void test_ulonglongtoa(void) { int test_num; - for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(ulonglong2str); test_num++) { if (ulonglong2str[test_num].mask & 0x01) { one_i64toa_test(test_num, &ulonglong2str[test_num]); } /* if */ @@ -746,7 +744,7 @@ static void test_ulonglongtow(void) int test_num; LPWSTR result; - for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(ulonglong2str); test_num++) { if (ulonglong2str[test_num].mask & 0x10) { one_i64tow_test(test_num, &ulonglong2str[test_num]); } /* if */ @@ -885,7 +883,6 @@ static const str2long_t str2long[] = { { "", 0 }, /* empty string */ /* { NULL, 0 }, */ /* NULL as string */ }; -#define NB_STR2LONG (sizeof(str2long)/sizeof(*str2long)) static void test_wtoi(void) @@ -894,7 +891,7 @@ static void test_wtoi(void) UNICODE_STRING uni; int result; - for (test_num = 0; test_num < NB_STR2LONG; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2long); test_num++) { pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str); result = p_wtoi(uni.Buffer); ok(result == str2long[test_num].value, @@ -909,7 +906,7 @@ static void test_atoi(void) int test_num; int result; - for (test_num = 0; test_num < NB_STR2LONG; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2long); test_num++) { result = patoi(str2long[test_num].str); ok(result == str2long[test_num].value, "(test %d): call failed: _atoi(\"%s\") has result %d, expected: %d\n", @@ -922,7 +919,7 @@ static void test_atol(void) int test_num; int result; - for (test_num = 0; test_num < NB_STR2LONG; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2long); test_num++) { result = patol(str2long[test_num].str); ok(result == str2long[test_num].value, "(test %d): call failed: _atol(\"%s\") has result %d, expected: %d\n", @@ -936,7 +933,7 @@ static void test_wtol(void) UNICODE_STRING uni; LONG result; - for (test_num = 0; test_num < NB_STR2LONG; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2long); test_num++) { pRtlCreateUnicodeStringFromAsciiz(&uni, str2long[test_num].str); result = p_wtol(uni.Buffer); ok(result == str2long[test_num].value, @@ -1068,7 +1065,6 @@ static const str2longlong_t str2longlong[] = { { "", 0 }, /* empty string */ /* { NULL, 0 }, */ /* NULL as string */ }; -#define NB_STR2LONGLONG (sizeof(str2longlong)/sizeof(*str2longlong)) static void test_atoi64(void) @@ -1076,7 +1072,7 @@ static void test_atoi64(void) int test_num; LONGLONG result; - for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2longlong); test_num++) { result = p_atoi64(str2longlong[test_num].str); if (str2longlong[test_num].overflow) ok(result == str2longlong[test_num].value || @@ -1100,7 +1096,7 @@ static void test_wtoi64(void) UNICODE_STRING uni; LONGLONG result; - for (test_num = 0; test_num < NB_STR2LONGLONG; test_num++) { + for (test_num = 0; test_num < ARRAY_SIZE(str2longlong); test_num++) { pRtlCreateUnicodeStringFromAsciiz(&uni, str2longlong[test_num].str); result = p_wtoi64(uni.Buffer); if (str2longlong[test_num].overflow) -- 2.14.4