struct structure_field *field;
int ret = 0;
- if (!type || index < 0 || !field_name || !field_type ||
- (type->declaration->id != CTF_TYPE_VARIANT)) {
+ if (!type || index < 0 || (type->declaration->id != CTF_TYPE_VARIANT)) {
ret = -1;
goto end;
}
}
field = g_ptr_array_index(variant->fields, index);
- *field_type = field->type;
- bt_ctf_field_type_get(field->type);
- *field_name = g_quark_to_string(field->name);
+ if (field_type) {
+ *field_type = field->type;
+ bt_ctf_field_type_get(field->type);
+ }
+ if (field_name) {
+ *field_name = g_quark_to_string(field->name);
+ }
end:
return ret;
}
ok(bt_ctf_field_type_variant_get_field(NULL, &ret_string, &ret_field_type, 0) < 0,
"bt_ctf_field_type_variant_get_field handles a NULL type correctly");
- ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) < 0,
+ ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) == 0,
"bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
- ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) < 0,
+ bt_ctf_field_type_put(ret_field_type);
+ ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) == 0,
"bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 200) < 0,
"bt_ctf_field_type_variant_get_field handles an invalid index correctly");