Skip to content
9 changes: 7 additions & 2 deletions build/helper/codegen_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def _get_ctype_variable_definition_snippet_for_scalar(parameter, parameters, ivi
S120. Input is size of buffer with mechanism is python-code: visatype.ViInt32(<custom python code>)
S130. Input enum: visatype.ViInt32(parameter_name.value)
S150. Input scalar: visatype.ViInt32(parameter_name)
S160. Input is size of input buffer: visatype.ViInt32(0 if list is None else len(list))
S160. Input is size of 1-dimensional input buffer: visatype.ViInt32(0 if list is None else len(list))
S161. Input is total number of elements in multidimensional input buffer: visatype.ViInt32(0 if array is None else array.size)
S170. Input is size of output buffer with mechanism ivi-dance, QUERY_SIZE: visatype.ViInt32()
S180. Input is size of output buffer with mechanism ivi-dance, GET_DATA: visatype.ViInt32(error_code)
S190. Input is size of output buffer with mechanism ivi-dance-with-a-twist, QUERY_SIZE: visatype.ViInt32()
Expand Down Expand Up @@ -371,7 +372,11 @@ def _get_ctype_variable_definition_snippet_for_scalar(parameter, parameters, ivi
if corresponding_buffer_parameters[0].get('complex_array_representation') == 'interleaved_real_number_array':
definitions.append(parameter['ctypes_variable_name'] + ' = {0}.{1}(0 if {2} is None else len({2}) // 2) # case S160'.format(module_name, parameter['ctypes_type'], corresponding_buffer_parameters[0]['python_name']))
else:
definitions.append(parameter['ctypes_variable_name'] + ' = {0}.{1}(0 if {2} is None else len({2})) # case S160'.format(module_name, parameter['ctypes_type'], corresponding_buffer_parameters[0]['python_name']))
array_dimensions = corresponding_buffer_parameters[0].get('array_dimensions')
if isinstance(array_dimensions, int) and array_dimensions > 1:
definitions.append(parameter['ctypes_variable_name'] + ' = {0}.{1}(0 if {2} is None else {2}.size) # case S161'.format(module_name, parameter['ctypes_type'], corresponding_buffer_parameters[0]['python_name']))
else:
definitions.append(parameter['ctypes_variable_name'] + ' = {0}.{1}(0 if {2} is None else len({2})) # case S160'.format(module_name, parameter['ctypes_type'], corresponding_buffer_parameters[0]['python_name']))
else:
if corresponding_buffer_parameters[0]['size']['mechanism'] == 'ivi-dance': # We are only looking at the first one. Assumes all are the same here, assert below if not
# Verify all corresponding_buffer_parameters are 'out' and 'ivi-dance'
Expand Down
9 changes: 9 additions & 0 deletions build/unit_tests/test_codegen_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,15 @@ def test_get_ctype_variable_declaration_snippet_case_s160():
assert actual == ["input_array_size_ctype = _visatype.ViInt32(0 if input_array is None else len(input_array)) # case S160"]


def test_get_ctype_variable_declaration_snippet_case_s161():
size_parameter = parameters_for_testing[11]
buffer_parameter = dict(parameters_for_testing[10])
buffer_parameter['array_dimensions'] = 3
parameters_for_testing[10] = buffer_parameter
snippet = get_ctype_variable_declaration_snippet(size_parameter, parameters_for_testing, IviDanceStep.NOT_APPLICABLE, config_for_testing, use_numpy_array=False)
assert snippet == ["input_array_size_ctype = _visatype.ViInt32(0 if input_array is None else input_array.size) # case S161"]


def test_get_ctype_variable_declaration_snippet_case_s170():
snippet = get_ctype_variable_declaration_snippet(parameters_for_testing[12], parameters_for_testing, IviDanceStep.QUERY_SIZE, config_for_testing, use_numpy_array=False)
assert snippet == ["string_size_ctype = _visatype.ViInt32() # case S170"]
Expand Down