static void runtest(bool is_valid, const char *basefn) { char *fn = test_filename(basefn); json_t *tests = read_json(fn); assert(json_is_array(tests)); unsigned int idx; for (idx = 0; idx < json_array_size(tests); idx++) { json_t *test = json_array_get(tests, idx); assert(json_is_array(test)); const char *scriptSigEnc = json_string_value(json_array_get(test, 0)); const char *scriptPubKeyEnc = json_string_value(json_array_get(test, 1)); assert(scriptSigEnc != NULL); assert(scriptPubKeyEnc != NULL); cstring *scriptSig = parse_script_str(scriptSigEnc); cstring *scriptPubKey = parse_script_str(scriptPubKeyEnc); assert(scriptSig != NULL); assert(scriptPubKey != NULL); test_script(is_valid, scriptSig, scriptPubKey, idx, scriptSigEnc, scriptPubKeyEnc); cstr_free(scriptSig, true); cstr_free(scriptPubKey, true); } json_decref(tests); free(fn); }
static void test_suite (void) { const char *srcdir; char *scripts_dir; snprintf (test, sizeof (test), "toyvm.c"); /* We need to locate the test scripts. Rely on "srcdir" being set in the environment. */ srcdir = getenv ("srcdir"); CHECK_NON_NULL (srcdir); scripts_dir = (char *)malloc (strlen (srcdir) + strlen(PATH_TO_SCRIPTS) + 1); CHECK_NON_NULL (scripts_dir); sprintf (scripts_dir, "%s%s", srcdir, PATH_TO_SCRIPTS); test_script (scripts_dir, "factorial.toy", 10, 3628800); test_script (scripts_dir, "fibonacci.toy", 10, 55); free (scripts_dir); }
void execute_line(char *cmdbuf) { int argc; char *argv[MAXARGS]; argc = parse(cmdbuf, argv); if (argc == 0) return; if (!strcmp(argv[0], "noop")) test_noop(); else if (!strcmp(argv[0], "connect") || !strcmp(argv[0], "c")) test_connect(argc, argv); else if (!strcmp(argv[0], "disconnect") || !strcmp(argv[0], "d")) test_disconnect(); else if (!strcmp(argv[0], "host")) test_host(); else if (!strcmp(argv[0], "motd") || !strcmp(argv[0], "m")) test_motd(); else if (!strcmp(argv[0], "query") || !strcmp(argv[0], "qy")) test_query(argc, argv); else if (!strcmp(argv[0], "auth") || !strcmp(argv[0], "a")) test_krb5_auth(); else if (!strcmp(argv[0], "proxy") || !strcmp(argv[0], "p")) test_proxy(argc, argv); else if (!strcmp(argv[0], "access")) test_access(argc, argv); else if (!strcmp(argv[0], "dcm")) test_dcm(); else if (!strcmp(argv[0], "script") || !strcmp(argv[0], "s")) test_script(argc, argv); else if (!strcmp(argv[0], "list_requests") || !strcmp(argv[0], "lr") || !strcmp(argv[0], "?")) test_list_requests(); else if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "Q")) quit = 1; else if (!strcmp(argv[0], "version") || !strcmp(argv[0], "v")) test_version(argc, argv); else if (!strcmp(argv[0], "krb4_auth") || !strcmp(argv[0], "4")) test_auth(); else { fprintf(stderr, "moira: Unknown request \"%s\". " "Type \"?\" for a request list.\n", argv[0]); } }
void test_all() { test_script(); }