Source
527
527
case ZBX_MOCK_NOT_A_BINARY:
528
528
return "Provided handle is not a binary string.";
529
529
case ZBX_MOCK_NOT_AN_UINT64:
530
530
return "Provided handle is not an unsigned 64 bit integer handle.";
531
531
case ZBX_MOCK_NOT_A_FLOAT:
532
532
return "Provided handle is not a floating point number handle.";
533
533
case ZBX_MOCK_NOT_A_TIMESTAMP:
534
534
return "Invalid timestamp format.";
535
535
case ZBX_MOCK_NOT_ENOUGH_MEMORY:
536
536
return "Not enough space in output buffer.";
537
+
case ZBX_MOCK_NOT_AN_INT:
538
+
return "Provided handle is not a integer handle.";
537
539
default:
538
540
return "Unknown error.";
539
541
}
540
542
}
541
543
542
544
static zbx_mock_error_t zbx_mock_builtin_parameter(zbx_mock_parameter_t type, const char *name, zbx_mock_handle_t *parameter)
543
545
{
544
546
const yaml_node_t *source;
545
547
const yaml_node_pair_t *pair;
546
548
933
935
tmp[handle->node->data.scalar.length] = '\0';
934
936
935
937
if (SUCCEED != is_double(tmp, value))
936
938
res = ZBX_MOCK_NOT_A_FLOAT;
937
939
938
940
zbx_free(tmp);
939
941
940
942
return res;
941
943
}
942
944
945
+
zbx_mock_error_t zbx_mock_int(zbx_mock_handle_t object, int *value)
946
+
{
947
+
const zbx_mock_pool_handle_t *handle;
948
+
char *tmp = NULL, *ptr;
949
+
zbx_mock_error_t res = ZBX_MOCK_SUCCESS;
950
+
951
+
if (0 > object || object >= handle_pool.values_num)
952
+
return ZBX_MOCK_INVALID_HANDLE;
953
+
954
+
handle = handle_pool.values[object];
955
+
956
+
if (YAML_SCALAR_NODE != handle->node->type)
957
+
return ZBX_MOCK_NOT_AN_INT;
958
+
959
+
tmp = zbx_malloc(tmp, handle->node->data.scalar.length + 1);
960
+
memcpy(tmp, handle->node->data.scalar.value, handle->node->data.scalar.length);
961
+
tmp[handle->node->data.scalar.length] = '\0';
962
+
963
+
ptr = tmp;
964
+
if ('-' == *ptr)
965
+
ptr++;
966
+
967
+
if (SUCCEED != is_uint31(ptr, value))
968
+
res = ZBX_MOCK_NOT_AN_INT;
969
+
970
+
if (ptr != tmp)
971
+
*value = -(*value);
972
+
973
+
zbx_free(tmp);
974
+
975
+
return res;
976
+
}
977
+
943
978
/******************************************************************************
944
979
* *
945
980
* Function: zbx_mock_string_ex *
946
981
* *
947
982
* Purpose: return string object contents *
948
983
* *
949
984
* Comments: The object can be either scalar value or a mapping. In the first *
950
985
* case the scalar value is returned. In the other case the string *
951
986
* is assembled from the object properties: *
952
987
* <header> + <page> * <pages> + <footer> *