static int childprocess_unittest(void) { resourceusage_t usage = resourceusage_FREE; display_t disp = display_FREE; window_t win = window_FREE; window_evh_t evhandler = window_evh_INIT_NULL; EGLContext eglcontext = EGL_NO_CONTEXT; // prepare TEST(0 == initdefault_display(&disp)) TEST(0 == init_test_window(&win, &eglcontext, &disp, &evhandler)); if (test_transparentalpha(&disp)) goto ONERR; TEST(0 == init_resourceusage(&usage)); if (test_initfree(&disp)) goto ONERR; acceptleak_helper(&usage); TEST(0 == same_resourceusage(&usage)); TEST(0 == free_resourceusage(&usage)); WAITFOR(&disp, false); size_t logsize; uint8_t * logbuffer; GETBUFFER_ERRLOG(&logbuffer, &logsize); for (unsigned i = 0; i <= 2; ++i) { TEST(0 == init_resourceusage(&usage)); if (test_showhide(&win, &disp)) goto ONERR; if (test_position(&win, &disp)) goto ONERR; if (test_resize(&win, &disp)) goto ONERR; WAITFOR(&disp, false); if (0 == same_resourceusage(&usage)) break; TEST(0 == free_resourceusage(&usage)); TRUNCATEBUFFER_ERRLOG(logsize); } TEST(0 == same_resourceusage(&usage)); TEST(0 == free_resourceusage(&usage)); // unprepare TEST(0 == free_window(&win)); TEST(0 == free_display(&disp)); return 0; ONERR: (void) free_resourceusage(&usage); (void) free_window(&win); (void) free_display(&disp); return EINVAL; }
bool_t free_lessui(lessui_t *ui) { if( ui ) { free_display(&ui->display); free_cursorrep(&ui->cr); free_cursormanager(&ui->cmg); free_cursor(&ui->cursor); return TRUE; } return FALSE; }
int wdt_stop(struct debuggee* dbg) { int ret; wtcl_send_cmd(&dbg->cl, "quit"); ret = wtcl_recv_up_to_prompt(&dbg->cl); TRACE("Got for quit cmd: '%s'\n", dbg->cl.buf_ptr); wtcl_stop(&dbg->cl); dbg->status = ss_none; wdt_free_location(&dbg->loc); free_display(dbg); return 0; }
int main(int argc, char *argv[]) { struct display *d; int xd = 79; int yd = 23; d = create_display(xd + 1, yd + 1); draw_rectangle(d, 0, 0, xd, yd); draw_line(d, 0, 0, xd, yd); draw_line(d, 0, yd, xd, 0); draw_circle(d, xd / 2, yd / 2, yd / 3); show_display(d); free_display(d); return 0; }
static char * test_cursor_up_top_first_page() { struct display_t *display; struct search_t *search; int terminal_line_nb; char text[] = "this is the first line\nthis the second line\n"; const char *pattern = "line"; display = create_display(); search = create_search(); terminal_line_nb = 10; parse_text(search, "fake_file", strlen(text), text, pattern); move_cursor_up(display, search, terminal_line_nb); mu_assert("test_cursor_up_top_first_page failed", display->cursor == 1); free_search(search); free_display(display); return 0; }
int wdt_execute(struct debuggee* dbg, const char* cmd, ...) { int ret; va_list valist; va_start(valist, cmd); wtcl_send_vcmd(&dbg->cl, cmd, valist); va_end(valist); ret = wtcl_recv_up_to_prompt(&dbg->cl); TRACE("Got for exec-cmd='%s': '%s'\n", cmd, dbg->cl.buf_ptr); dump_data(dbg->cl.buf_ptr, "exec> "); if (ret == -1) { snprintf(dbg->err_msg, sizeof(dbg->err_msg), "Couldn't execute command '%s' -> %s", cmd, dbg->cl.buf_ptr); return -1; } if (dbg->num_display) free_display(dbg); while (compare(re_display, dbg->cl.buf_ptr)) { char* end; TRACE("Got display #%.*s: '%.*s' = '%.*s'\n", (int)(rm[1].rm_eo - rm[1].rm_so), &dbg->cl.buf_ptr[rm[1].rm_so], (int)(rm[2].rm_eo - rm[2].rm_so), &dbg->cl.buf_ptr[rm[2].rm_so], (int)(rm[3].rm_eo - rm[3].rm_so), &dbg->cl.buf_ptr[rm[3].rm_so]); dbg->display = realloc(dbg->display, ++dbg->num_display * sizeof(dbg->display[0])); if (dbg->num_display != to_num(dbg, 1)) { free_display(dbg); strcpy(dbg->err_msg, "Suspicious display index"); return -1; } dbg->display[dbg->num_display - 1].expr = to_string(dbg, 2); end = dbg->cl.buf_ptr + rm[3].rm_eo; end[0] = '\0'; dbg->cl.buf_ptr += rm[3].rm_so; /* start of expression */ wdt_fetch_value(dbg, &dbg->display[dbg->num_display - 1].mval); dbg->cl.buf_ptr = end + 1; } /* different possible outputs: * Breakpoint (bpnum) at 0x(addr) (name) [(srcfile):(lineno)] in (module) (refcount=2) */ if (compare(re_stopped_bp_m, dbg->cl.buf_ptr) || compare(re_stopped_wp_m, dbg->cl.buf_ptr)) { TRACE("Stopped at xp='%.*s' addr='%.*s' name='%.*s' src='%.*s'/line=%.*s module='%.*s'\n", (int)(rm[1].rm_eo - rm[1].rm_so), &dbg->cl.buf_ptr[rm[1].rm_so], (int)(rm[2].rm_eo - rm[2].rm_so), &dbg->cl.buf_ptr[rm[2].rm_so], (int)(rm[3].rm_eo - rm[3].rm_so), &dbg->cl.buf_ptr[rm[3].rm_so], (int)(rm[4].rm_eo - rm[4].rm_so), &dbg->cl.buf_ptr[rm[4].rm_so], (int)(rm[5].rm_eo - rm[5].rm_so), &dbg->cl.buf_ptr[rm[5].rm_so], (int)(rm[6].rm_eo - rm[6].rm_so), &dbg->cl.buf_ptr[rm[6].rm_so]); dbg->status = ss_xpoint; dbg->info = to_num(dbg, 1); wdt_free_location(&dbg->loc); grab_location(dbg, &dbg->loc, 2, 3, 4, 5, 6); } else if (compare(re_stopped_bp_b, dbg->cl.buf_ptr) || compare(re_stopped_wp_b, dbg->cl.buf_ptr)) { TRACE("Stopped at xp='%.*s' addr='%.*s' name='%.*s' src='%.*s'/line=%.*s\n", (int)(rm[1].rm_eo - rm[1].rm_so), &dbg->cl.buf_ptr[rm[1].rm_so], (int)(rm[2].rm_eo - rm[2].rm_so), &dbg->cl.buf_ptr[rm[2].rm_so], (int)(rm[3].rm_eo - rm[3].rm_so), &dbg->cl.buf_ptr[rm[3].rm_so], (int)(rm[4].rm_eo - rm[4].rm_so), &dbg->cl.buf_ptr[rm[4].rm_so], (int)(rm[5].rm_eo - rm[5].rm_so), &dbg->cl.buf_ptr[rm[5].rm_so]); dbg->status = ss_xpoint; dbg->info = to_num(dbg, 1); wdt_free_location(&dbg->loc); grab_location(dbg, &dbg->loc, 2, 3, 4, 5, -1); } else if (compare(re_funcchange, dbg->cl.buf_ptr)) { TRACE("Entering function %.*s src='%.*s'/line=%.*s\n", (int)(rm[1].rm_eo - rm[1].rm_so), &dbg->cl.buf_ptr[rm[1].rm_so], (int)(rm[2].rm_eo - rm[2].rm_so), &dbg->cl.buf_ptr[rm[2].rm_so], (int)(rm[3].rm_eo - rm[3].rm_so), &dbg->cl.buf_ptr[rm[3].rm_so]); dbg->status = ss_step; wdt_free_location(&dbg->loc); grab_location(dbg, &dbg->loc, -1, 1, 2, 3, -1); } else if (compare(re_srcline, dbg->cl.buf_ptr)) { /* FIXME: * - this is wrong if we change to another function in the same file * - what happens if we move to a new function or file ?? */ dbg->status = ss_step; dbg->loc.lineno = to_num(dbg, 1); } else if (compare(re_asmline, dbg->cl.buf_ptr)) { dbg->status = ss_step; wdt_free_location(&dbg->loc); grab_location(dbg, &dbg->loc, 1, 2, -1, -1, 3); } else if (compare(re_terminated, dbg->cl.buf_ptr)) { TRACE("Terminated on pid %.*s\n", (int)(rm[1].rm_eo - rm[1].rm_so), &dbg->cl.buf_ptr[rm[1].rm_so]); if (to_num(dbg, 1) != dbg->cl.info.dwProcessId) { snprintf(dbg->err_msg, sizeof(dbg->err_msg), "Wrong pid termination (%lx/%x)\n", to_num(dbg, 1), dbg->cl.info.dwProcessId); ret = -1; } } else TRACE("No RE-exec on '%s' for cmd=%s\n", dbg->cl.buf_ptr, cmd); return ret; }