test-error-new-unary-op-bad-op.c 855 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "libgccjit.h"
  4. #include "harness.h"
  5. void
  6. create_code (gcc_jit_context *ctxt, void *user_data)
  7. {
  8. /* Trigger an API error by passing bad data. */
  9. (void)gcc_jit_context_new_unary_op (
  10. ctxt,
  11. NULL,
  12. /* Non-valid enum value: */
  13. (enum gcc_jit_unary_op) 42,
  14. /* These aren't valid either: */
  15. NULL, /* gcc_jit_type *result_type, */
  16. NULL); /* gcc_jit_rvalue *rvalue */
  17. }
  18. void
  19. verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
  20. {
  21. /* Ensure that the bad API usage prevents the API giving a bogus
  22. result back. */
  23. CHECK_VALUE (result, NULL);
  24. /* Verify that the correct error message was emitted. */
  25. CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
  26. ("gcc_jit_context_new_unary_op:"
  27. " unrecognized value for enum gcc_jit_unary_op: 42"));
  28. }