source: tester.c @ 6b28e33

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 6b28e33 was 1cf3f8d3, checked in by Nelson Elhage <nelhage@mit.edu>, 17 years ago
Make the built-in regression tests output TAP and add a perl wrapper to call it.
  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2#include <unistd.h>
3#include <stdlib.h>
4
[1aee7d9]5static const char fileIdent[] = "$Id$";
6
[b2b0773]7owl_global g;
8
[094009a]9void screeninit()
10{
[7d4fbcd]11  char buff[1024];
12 
13  sprintf(buff, "TERMINFO=%s", TERMINFO);
14  putenv(buff);
15
16  initscr();
17  start_color();
18  /* cbreak(); */
19  raw();
20  noecho();
21  intrflush(stdscr,FALSE);
22  keypad(stdscr,TRUE);
23  nodelay(stdscr,1);
24  clear();
25  refresh();
26  meta(stdscr, TRUE);
27}
28
[094009a]29void test1()
30{
[7d4fbcd]31  int j;
32  owl_editwin e;
33
34  screeninit();
35
[e1c4636]36  owl_editwin_init(&e, stdscr, LINES, COLS, OWL_EDITWIN_STYLE_MULTILINE, NULL);
[7d4fbcd]37  /* owl_editwin_set_locktext(&e, "Here is some locktext:\n");*/
38  doupdate();
39  while (1) {
40    usleep(50);
41
42    j=getch();
43
44    if (j==ERR) continue;
45
46    if (j==3) break;
47
48    if (j==27) {
49      j=getch();
50      if (j==ERR) continue;
51      owl_editwin_process_char(&e, j);
52      doupdate();
53    } else {
54      owl_editwin_process_char(&e, j);
55      doupdate();
56    }
57  }
58  endwin();
59  printf("Had:\n%s", owl_editwin_get_text(&e));
60}
61
[094009a]62void test2(char *in)
63{
[7d4fbcd]64  owl_fmtext t;
65
66  screeninit();
67
68  owl_fmtext_init_null(&t);
69  owl_fmtext_append_ztext(&t, in);
70  owl_fmtext_curs_waddstr(&t, stdscr);
71  wrefresh(stdscr);
72  sleep(5000);
73  endwin();
74}
75
[094009a]76void test3()
77{
[7d4fbcd]78  ZNotice_t *n;
79
80  printf("%i\n", sizeof(n->z_uid.zuid_addr));
81  /* gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); */
82}
83
[094009a]84void colorinfo()
85{
[7d4fbcd]86  char buff[1024];
87 
88  screeninit();
89  sprintf(buff, "Have %i COLOR_PAIRS\n", COLOR_PAIRS);
90  addstr(buff);
91  refresh();
92  sleep(10);
93  endwin(); 
94}
95
[094009a]96void test4()
97{
[7d4fbcd]98  int j;
99  char buff[1024];
100
101  screeninit();
102 
103  while (1) {
104    usleep(100);
105
106    j=getch();
107
108    if (j==ERR) continue;
109
110    if (j==3) break;
111    sprintf(buff, "%o\n", j);
112    addstr(buff);
113  }
114  endwin();
115}
116
[094009a]117void test_keypress()
118{
[7d4fbcd]119  int j, rev;
120  char buff[1024], buff2[64];
121
122  screeninit();
123 
124  while (1) {
125    usleep(100);
126
127    j=wgetch(stdscr);
128
129    if (j==ERR) continue;
130
131    if (j==3) break;
132    if (0 == owl_keypress_tostring(j, 0, buff2, 1000)) {
133      rev = owl_keypress_fromstring(buff2);
134      sprintf(buff, "%s : 0x%x 0%o %d %d %s\n", buff2, j, j, j, rev,
135              (j==rev?"matches":"*** WARNING: Does Not Reverse"));
136    } else {
137      sprintf(buff, "UNKNOWN : 0x%x 0%o %d\n", j, j, j);
138    }
139      addstr(buff);
140  }
141  endwin();
142}
143
144
[1cf3f8d3]145#define OWL_DICT_NTESTS  20
146#define OWL_UTIL_NTESTS  9
147#define OWL_OBARRAY_NTESTS  5
148#define OWL_VARIABLE_NTESTS  52
149#define OWL_FILTER_NTESTS  23
150
[094009a]151int main(int argc, char **argv, char **env)
152{
[124aebc]153  owl_errqueue_init(owl_global_get_errqueue(&g));
[e7dc035]154  owl_obarray_init(&(g.obarray));
[124aebc]155
[7d4fbcd]156  int numfailures=0;
[1cf3f8d3]157  if (argc==1 || (argc==2 && 0==strcmp(argv[1],"reg"))) {
158    printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS
159           +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS);
[e1c4636]160    numfailures += owl_util_regtest();
[7d4fbcd]161    numfailures += owl_dict_regtest();
162    numfailures += owl_variable_regtest();
[cb769bb]163    numfailures += owl_filter_regtest();
[124aebc]164    numfailures += owl_obarray_regtest();
[7d4fbcd]165    if (numfailures) {
[1cf3f8d3]166      fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
[7d4fbcd]167    }
168    return(numfailures);
169  } else if (argc==2 && 0==strcmp(argv[1],"test1")) {
170    test1();
171  } else if (argc==2 && 0==strcmp(argv[1],"colorinfo")) {
172    colorinfo();
173  } else if (argc==2 && 0==strcmp(argv[1],"test4")) {
174    test4();
175  } else if (argc==2 && 0==strcmp(argv[1],"keypress")) {
176    test_keypress();
177  } else {
178    fprintf(stderr, "No test specified.  Current options are: reg test1\n");
179  }
180  return(0);
181}
Note: See TracBrowser for help on using the repository browser.