Fix handling of array of pointers (Fixes issue #450)

This commit is contained in:
Mark VanderVoord
2026-06-16 18:14:51 -04:00
parent 82ef7e53cf
commit f756eeaf55
3 changed files with 48 additions and 2 deletions
+6 -1
View File
@@ -16,7 +16,12 @@ class CMockUnityHelperParser
def get_helper(ctype)
lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/, '\1\3\5\6').strip.gsub(/\s+/, '_')
return [@c_types[lookup], ''] if @c_types[lookup]
if @c_types[lookup]
# _ARRAY_ARRAY variants don't exist in Unity; use memory fallback instead
return [@fallback, ''] if @c_types[lookup].end_with?('_ARRAY_ARRAY')
return [@c_types[lookup], '']
end
if lookup =~ /\*$/
lookup = lookup.gsub(/\*$/, '')
+1 -1
View File
@@ -12,7 +12,7 @@
#define CMOCK_VERSION_MAJOR 2
#define CMOCK_VERSION_MINOR 6
#define CMOCK_VERSION_BUILD 3
#define CMOCK_VERSION_BUILD 4
#define CMOCK_VERSION ((CMOCK_VERSION_MAJOR << 16) | (CMOCK_VERSION_MINOR << 8) | CMOCK_VERSION_BUILD)
/* should be big enough to index full range of CMOCK_MEM_MAX */
@@ -49,6 +49,7 @@
void transform_grid(int grid[][4], int rows);
void write_buffer(char (*dest)[10]);
void read_buffers(int count, char (*buffers)[8]);
void process_handles(void *const handles[], int count);
:source:
:header: |
@@ -61,6 +62,7 @@
void function_g(void);
void function_h(void);
void function_i(void);
void function_j(void);
:code: |
void function_a(void)
@@ -128,6 +130,12 @@
read_buffers((int)3, bufs);
}
void function_j(void)
{
void *const ptrs[] = {(void*)1, (void*)2, (void*)3};
process_handles(ptrs, 3);
}
:tests:
:common: |
void setUp(void) {}
@@ -598,4 +606,37 @@
function_i();
}
- :pass: TRUE
:should: 'pass when array of const void pointers matches expected'
:code: |
test()
{
void *const expected[] = {(void*)1, (void*)2, (void*)3};
process_handles_Expect(expected, 3);
function_j();
}
- :pass: FALSE
:should: 'detect mismatch in array of const void pointers'
:code: |
test()
{
void *const expected[] = {(void*)1, (void*)2, (void*)9};
process_handles_Expect(expected, 3);
function_j();
}
- :pass: TRUE
:should: 'pass when comparing subset of const void pointer array via ExpectWithArray'
:code: |
test()
{
void *const expected[] = {(void*)1, (void*)2};
process_handles_ExpectWithArray(expected, 2, 3);
function_j();
}
...