END_TEST START_TEST (test_win_handler_move_cursor) { Win *w; int ret; int i; win_properties props = { 0, 0 }; /* Test non cursor window. */ w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); ret = win_load_file (w, CONFDIR "text_test.txt"); fail_unless (ret == 0); ret = win_move_cursor (w, -1); fail_unless (ret < 0); win_free (w); /* Test cursor window */ props.properties = WIN_PROP_CURSOR; w = win_create (0, 0, 20, 80, &props); fail_unless (w != NULL); ret = win_load_file (w, CONFDIR "text_test.txt"); fail_unless (ret == 0); ret = win_go_to_line (w, 60); fail_unless (ret == 0); ret = win_move_cursor (w, 1); fail_unless (ret == 0); ret = win_move_cursor (w, -1); fail_unless (ret == 0); ret = win_move_cursor (w, 25); fail_unless (ret == 0); ret = win_move_cursor (w, -25); fail_unless (ret == 0); for (i = 0; i < 125; i++) { ret = win_move_cursor (w, 1); fail_unless (ret == 0); } for (i = 0; i < 125; i++) { ret = win_move_cursor (w, -1); fail_unless (ret == 0); } win_free (w); }
END_TEST START_TEST (test_win_handler_syntax) { Win *w; int ret; int i; char buf[64]; const char *line; win_attribute attr[] = { {1, 0x01}, {2, 0x02}, {3, 0x03} }; char *scan = strdup ("{id='1',type='1',match='int'},{id='2',match='Line'},{id='1',match='[[:digit:]]*'}"); win_properties props = { 0, WIN_PROP_CURSOR | WIN_PROP_SYNTAX, attr, 3, scan }; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); for (i = 0; i < 45; i++) { sprintf (buf, "Line int %d", i); ret = win_add_line (w, buf, 1, i); fail_unless (ret == 0); } win_go_to_line (w, 5); free (scan); win_free (w); }
END_TEST START_TEST (test_win_handler_get_line) { Win *w; int ret; int i; char buf[64]; const char *line; win_properties props = { 0, WIN_PROP_CURSOR, NULL, 0, NULL }; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); for (i = 0; i < 150; i++) { sprintf (buf, "Line %d", i); ret = win_add_line (w, buf, 0, i); fail_unless (ret == 0); } for (i = 0; i < 150; i++) { sprintf (buf, "Line %d", i); line = win_get_line (w, i); fail_unless (strcmp (line, buf) == 0); } line = win_get_line (w, -1); fail_unless (line == NULL); line = win_get_line (w, 200); fail_unless (line == NULL); win_free (w); }
END_TEST START_TEST (test_win_handler_tag) { Win *w; int ret; int i; char buf[64]; win_properties props = { 0, WIN_PROP_CURSOR }; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); for (i = 0; i < 150; i++) { sprintf (buf, "Line nr %d", i); ret = win_add_line (w, buf, 0, i); fail_unless (ret == 0); } for (i = 0; i < 150; i++) { ret = win_go_to_line (w, i); fail_unless (ret == 0); ret = win_get_tag (w); fail_unless (ret == i, "tag = %d != %d", ret, i); } win_free (w); }
/* * Allocate a window node */ WNODE *win_alloc(WORD obid) { WNODE *pw; WORD wob; GRECT *pt; if (G.g_wcnt == NUM_WNODES) return ((WNODE *) NULL); pt = (GRECT *) &G.g_cnxsave.cs_wnode[G.g_wcnt].x_save; wob = obj_walloc(pt->g_x, pt->g_y, pt->g_w, pt->g_h); if (wob) { G.g_wcnt++; pw = &G.g_wlist[wob-2]; pw->w_flags = 0x0; pw->w_obid = obid; /* DESKTOP v1.2 */ pw->w_root = wob; pw->w_cvrow = 0x0; pw->w_pncol = (pt->g_w - gl_wchar) / G.g_iwspc; pw->w_pnrow = (pt->g_h - gl_hchar) / G.g_ihspc; pw->w_vnrow = 0x0; pw->w_id = wind_create(WINDOW_STYLE, G.g_xdesk, G.g_ydesk, G.g_wdesk, G.g_hdesk); if (pw->w_id != -1) { return pw; } win_free(pw); /* decrement G.g_wcnt & call obj_wfree() */ } return NULL; }
struct win *win_alloc(struct rconf *rconf) { struct win *win=NULL; if(!(win=(struct win *)calloc_w(1, sizeof(struct win), __func__)) || !(win->data=(unsigned char *)calloc_w( 1, sizeof(unsigned char)*rconf->win_size, __func__))) win_free(&win); return win; }
struct win *win_alloc(struct rconf *rconf) { struct win *win=NULL; if((win=(struct win *)calloc_w(1, sizeof(struct win), __func__)) && (win->data=(char *)calloc_w(1, sizeof(char)*rconf->win, __func__))) return win; win_free(win); return NULL; }
gboolean get_key_win(gpointer data) { AConvert *aconv = (AConvert *)data; XEvent xev; WInfo *info; Window w; info = win_find(aconv->keyboard->win,aconv); if(info) { if(aconv->sxkb->cur_group!=info->cur_group) { XkbLockGroup(aconv->keyboard->dpy, XkbUseCoreKbd, info->cur_group); update_flag(aconv->sxkb->group2info[aconv->sxkb->cur_group],aconv); } w=get_active_window(aconv->keyboard->dpy); if(info->win!=w) free_keysym_to_list(aconv); } { if (XPending(aconv->keyboard->dpy)) { XNextEvent (aconv->keyboard->dpy, &xev); switch (xev.type) { case KeyPress: if (xev.xkey.send_event == TRUE) return False; get_key_pres(aconv,&xev); info = win_find(aconv->keyboard->win,aconv); if(info) auto_convert_text(aconv,info); break; case DestroyNotify: if((xev.xdestroywindow.event == aconv->keyboard->root)) break; /* XGetInputFocus (aconv->keyboard->dpy,&w, &(aconv->keyboard->cur_status)); DEBUG_MSG("DestroyNotify ID %#x == ID %#x ++ ID %#x == ID %#x == ID %#x \n",(unsigned int) aconv->keyboard->win,(unsigned int)info->win,(unsigned int)w,(unsigned int)xev.xdestroywindow.window,(unsigned int)xev.xdestroywindow.event);*/ info = win_find(xev.xdestroywindow.event,aconv); if (info) { //printf ("Dest window: ID %#x \n",(unsigned int)info->win); win_free(info,aconv); } break; } } } return TRUE; }
END_TEST START_TEST (test_win_handler_mark) { Win *w; int ret; win_properties props = { 0, 0 }; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); ret = win_load_file (w, CONFDIR "text_test.txt"); fail_unless (ret == 0); ret = win_set_mark (w, 15, 1, '?'); fail_unless (ret < 0); win_free (w); props.indent = 100; props.properties = WIN_PROP_MARKS | WIN_PROP_CURSOR; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); ret = win_load_file (w, CONFDIR "text_test.txt"); fail_unless (ret == 0); ret = win_set_mark (w, 1115, 1, '?'); fail_unless (ret < 0); ret = win_set_mark (w, -1, 1, '?'); fail_unless (ret == 0); /* Last line */ ret = win_set_mark (w, 15, 100, '?'); fail_unless (ret < 0); ret = win_set_mark (w, 15, 9, '?'); fail_unless (ret < 0); ret = win_set_mark (w, 15, -1, '?'); fail_unless (ret < 0); ret = win_set_mark (w, 15, 2, '\001'); fail_unless (ret < 0); ret = win_set_mark (w, 2, 2, '?'); fail_unless (ret == 0); win_free (w); }
void seal_destroy() { lua_close(GAME->lstate); nuk_node_free(GAME->nuk_node); texture_cache_free(GAME->texture_cache); sprite_frame_cache_free(GAME->sprite_frame_cache); win_free(GAME->window); sprite_free(GAME->root); s_free(GAME); }
END_TEST START_TEST (test_win_handler_text) { int ret; Win *w; win_properties props = { 0, 0 }; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); win_set_status (w, "test"); win_set_status (w, ""); win_set_status (w, "test test\ntest"); ret = win_add_line (w, "line 1", 0, 1); fail_unless (ret == 0); ret = win_add_line (w, "line 1", 1, 1); fail_unless (ret == 0); ret = win_add_line (w, "line 1", 0, 1); fail_unless (ret == 0); ret = win_add_line (w, "line 1", 1, 1); fail_unless (ret == 0); ret = win_add_line (w, "line 1", 1, 1); fail_unless (ret == 0); ret = win_add_line (w, "line\001 1", 1, 1); fail_unless (ret < 0); ret = win_load_file (w, CONFDIR "text_test_bad.txt"); fail_unless (ret < 0); ret = win_load_file (w, CONFDIR "text_test_short_file.txt"); fail_unless (ret == 0); ret = win_load_file (w, CONFDIR "text_test.txt"); fail_unless (ret == 0); ret = win_load_file (w, CONFDIR "text_test_long.txt"); fail_unless (ret == 0); win_free (w); }
END_TEST START_TEST (test_win_handler_get_curpos) { Win *w; int ret; int i; char buf[64]; const char *name; int line; win_properties props = { 0, WIN_PROP_CURSOR }; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); /* No name */ name = win_get_filename (w); fail_unless (name == NULL); /* With name. */ ret = win_load_file (w, CONFDIR "text_test.txt"); fail_unless (ret == 0); name = win_get_filename (w); fail_unless (name != NULL); for (i = 0; i < 10; i++) { ret = win_go_to_line (w, i); fail_unless (ret == 0); line = win_get_cursor (w); fail_unless (line == i); } win_free (w); }
END_TEST START_TEST (test_win_handler_scroll) { int ret; Win *w; win_properties props = { 0, 0 }; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); ret = win_load_file (w, CONFDIR "text_test_long.txt"); fail_unless (ret == 0); ret = win_scroll (w, -1); fail_unless (ret < 0); /* at the first line already. */ ret = win_scroll (w, 130); fail_unless (ret < 0); /* scroll to far down. */ ret = win_scroll (w, -15); fail_unless (ret == 0); ret = win_scroll (w, -1); fail_unless (ret == 0); ret = win_scroll (w, 5); fail_unless (ret == 0); ret = win_scroll (w, 1); fail_unless (ret == 0); win_to_top (w); ret = win_go_to_line (w, -2); fail_unless (ret < 0); ret = win_go_to_line (w, 180); fail_unless (ret < 0); ret = win_go_to_line (w, 15); fail_unless (ret == 0); ret = win_move (w, -1); fail_unless (ret == 0); ret = win_move (w, -4); fail_unless (ret == 0); ret = win_move (w, 1); fail_unless (ret == 0); ret = win_move (w, 4); fail_unless (ret == 0); win_clear (w); win_free (w); props.properties = WIN_PROP_CURSOR; w = win_create (0, 0, 40, 80, &props); fail_unless (w != NULL); ret = win_load_file (w, CONFDIR "text_test_long.txt"); ret = win_go_to_line (w, 15); fail_unless (ret == 0); ret = win_move (w, -1); fail_unless (ret == 0); ret = win_move (w, -4); fail_unless (ret == 0); ret = win_move (w, 1); fail_unless (ret == 0); ret = win_move (w, 4); fail_unless (ret == 0); win_clear (w); win_free (w); }
void blks_generate_free(void) { free_w(&gbuf); win_free(&win); }
int backup_phase2_client_burp2(struct asfd *asfd, struct conf *conf, int resume) { int ret=-1; int sigs_end=0; int backup_end=0; int requests_end=0; int blk_requests_end=0; struct win *win=NULL; // Rabin sliding window. struct slist *slist=NULL; struct blist *blist=NULL; struct iobuf *rbuf=NULL; struct iobuf *wbuf=NULL; logp("Phase 2 begin (send backup data)\n"); if(!(slist=slist_alloc()) || !(blist=blist_alloc()) || !(wbuf=iobuf_alloc()) || blks_generate_init(conf) || !(win=win_alloc(&conf->rconf))) goto end; rbuf=asfd->rbuf; if(!resume) { // Only do this bit if the server did not tell us to resume. if(asfd->write_str(asfd, CMD_GEN, "backupphase2") || asfd->read_expect(asfd, CMD_GEN, "ok")) goto end; } else if(conf->send_client_cntr) { // On resume, the server might update the client with the // counters. if(cntr_recv(asfd, conf)) goto end; } while(!backup_end) { if(!wbuf->len) { get_wbuf_from_data(conf, wbuf, slist, blist, blk_requests_end); if(!wbuf->len) { get_wbuf_from_blks(wbuf, slist, requests_end, &sigs_end); } } if(wbuf->len) asfd->append_all_to_write_buffer(asfd, wbuf); if(asfd->as->read_write(asfd->as)) { logp("error in %s\n", __func__); goto end; } if(rbuf->buf && deal_with_read(rbuf, slist, blist, conf, &backup_end, &requests_end, &blk_requests_end)) goto end; if(slist->head // Need to limit how many blocks are allocated at once. && (!blist->head || blist->tail->index - blist->head->index<BLKS_MAX_IN_MEM) ) { if(add_to_blks_list(asfd, conf, slist, blist, win)) goto end; } if(blk_requests_end) { // If got to the end of the file request list // and the last block of the last file, and // the write buffer is empty, we got to the end. if(slist->head==slist->tail) { if(!slist->tail || blist->last_sent==slist->tail->burp2->bend) { if(!wbuf->len) break; } } } } if(asfd->write_str(asfd, CMD_GEN, "backup_end")) goto end; ret=0; end: blk_print_alloc_stats(); //sbuf_print_alloc_stats(); win_free(win); slist_free(&slist); blist_free(&blist); // Write buffer did not allocate 'buf'. wbuf->buf=NULL; iobuf_free(&wbuf); cntr_print_end(conf->cntr); cntr_print(conf->cntr, ACTION_BACKUP); if(ret) logp("Error in backup\n"); logp("End backup\n"); return ret; }