1 #include <stdlib.h>
2 #include <stdio.h>
3 
4 #include "libgccjit.h"
5 
6 #include "harness.h"
7 
8 void
create_code(gcc_jit_context * ctxt,void * user_data)9 create_code (gcc_jit_context *ctxt, void *user_data)
10 {
11   gcc_jit_type *int_type =
12     gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
13 
14   /* Trigger an API error by passing bad data.  */
15   (void)gcc_jit_context_new_function (
16 	  ctxt,
17 	  NULL,
18 
19 	  /* Non-valid enum value: */
20 	  (enum gcc_jit_function_kind)42,
21 
22 	  int_type, /* gcc_jit_type *return_type, */
23 	  "foo", /* const char *name, */
24 	  0, /* int num_params, */
25 	  NULL, /* gcc_jit_param **params, */
26 	  0); /* int is_variadic */
27 }
28 
29 void
verify_code(gcc_jit_context * ctxt,gcc_jit_result * result)30 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
31 {
32   /* Ensure that the bad API usage prevents the API giving a bogus
33      result back.  */
34   CHECK_VALUE (result, NULL);
35 
36   /* Verify that the correct error message was emitted.  */
37   CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
38 		      ("gcc_jit_context_new_function:"
39 		       " unrecognized value for enum gcc_jit_function_kind: 42"));
40 }
41 
42