/* * Test of set_config: * - name = test parameter name * - value = test value * - k = expected returned value * - error = expected error code (if k < 0) */ static void test_set_config(ctx_config_t *config, const char *name, const char *value, int32_t k, int32_t error) { int32_t code; error_code_t ecode; printf("Testing set_config %s := %s: ", name, value); fflush(stdout); code = yices_set_config(config, name, value); if (code >= 0) { printf("ok\n"); show_config(config); } else { printf("error\n"); yices_print_error(stdout); } if (code != k) { printf("TEST FAILED\n"); printf("--> Yices function returned %"PRId32"; %"PRId32" was expected\n", code, k); fflush(stdout); exit(1); } else if (k < 0) { ecode = yices_error_code(); if (ecode != error) { printf("TEST FAILED\n"); printf("--> Found error code %"PRId32"; %"PRId32" was expected\n", ecode, error); fflush(stdout); exit(1); } } printf("\n"); fflush(stdout); }
int example2_main(void) { type_t real; term_t t, a; int32_t code; context_t *ctx; model_t *mdl; /* * Global initialization: this must called first. */ yices_init(); /* * Create an uninterpreted term of type real and call it "x" */ real = yices_real_type(); t = yices_new_uninterpreted_term(real); code = yices_set_term_name(t, "x"); /* * If code is negative, something went wrong */ if (code < 0) { printf("Error in yices_set_term\n"); yices_print_error(stdout); fflush(stdout); goto done; } /* * Create the atom (x > 0) */ a = yices_arith_gt0_atom(t); /* * Print the atom: */ printf("Atom: "); yices_pp_term(stdout, a, 120, 2, 6); /* * Check that (x > 0) is satisfiable and get a model * - create a context * - assert atom 'a' in this context * - check that the context is satisfiable */ ctx = yices_new_context(NULL); // NULL means use the default configuration code = yices_assert_formula(ctx, a); if (code < 0) { printf("Assert failed: "); yices_print_error(stdout); fflush(stdout); goto done; } switch (yices_check_context(ctx, NULL)) { // NULL means default heuristics case STATUS_SAT: // build the model and print it printf("Satisfiable\n"); mdl = yices_get_model(ctx, true); code = yices_pp_model(stdout, mdl, 120, 100, 0); if (code < 0) { printf("Print model failed: "); yices_print_error(stdout); fflush(stdout); goto done; } // cleanup: delete the model yices_free_model(mdl); break; case STATUS_UNSAT: printf("Unsatisfiable\n"); break; case STATUS_UNKNOWN: printf("Status is unknown\n"); break; case STATUS_IDLE: case STATUS_SEARCHING: case STATUS_INTERRUPTED: case STATUS_ERROR: // these codes should not be returned printf("Bug: unexpected status returned\n"); break; } /* * Delete the context: this is optional since yices_exit * would do it anyway. */ yices_free_context(ctx); done: /* * Global cleanup: free all memory used by Yices */ yices_exit(); return 0; }