File: print.c

package info (click to toggle)
xnee 3.19-9.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,432 kB
  • sloc: ansic: 23,555; sh: 13,521; makefile: 600
file content (291 lines) | stat: -rw-r--r-- 7,735 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*****
 *       Xnee's Not an Event Emulator                                
 *                                                                   
 * Xnee enables recording and replaying of X protocol data           
 *                                                                   
 *   Copyright (C) 2006, 2007, 2010, 2011
 *                        Henrik Sandklef 
 *                                                                   
 * This program is free software; you can redistribute it and/or     
 * modify it under the terms of the GNU General Public License       
 * as published by the Free Software Foundation; either version 3    
 * of the License, or any later version.                             
 *                                                                   
 *                                                                   
 * This program is distributed in the hope that it will be useful,   
 * but WITHOUT ANY WARRANTY; without even the implied warranty of    
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     
 * GNU General Public License for more details.                      
 *                                                                   
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software       
 * Foundation, Inc., 51 Franklin Street, Boston,            
 * MA  02110-1301, USA.                                              
 ****/

#include "test_setget.h"
#include "libxnee/xnee.h"
#include "libxnee/xnee_display.h"
#include "libxnee/xnee_range.h"
#include "libxnee/xnee_session.h"



int fails;
int total;
int verbose;


int 
test_distributionfuns(xnee_data *xd)
{
  int ret;
  char disp_buf[256];

  /*
  xnee_add_display_list(xd, ":0");
  total++;
  xnee_add_display_list(xd, ":0"); 
  total++;
  xnee_add_display_list(xd, ":0,:0"); 
  total++;
  */
  xnee_add_display_list(xd, getenv("DISPLAY"));
  total++;
  xnee_add_display_list(xd, getenv("DISPLAY")); 
  total++;
  strcpy(disp_buf, getenv("DISPLAY"));
  strcat(disp_buf, ",");
  strcat(disp_buf, getenv("DISPLAY"));
  strcat(disp_buf, ",");
  strcat(disp_buf, getenv("DISPLAY"));
  xnee_add_display_list(xd, disp_buf); 
  total++;

  ret = xnee_print_distr_list (xd, NULL);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_distr_list");
  
  ret = xnee_print_distr_list (xd, xd->out_file);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_distr_list");
  
  
  return 0;
}

int 
test_rangefuns(xnee_data *xd)
{
  int ret;

  xnee_record_print_record_range (xd, NULL) ;
  total++;

  xnee_add_range(xd, XNEE_DELIVERED_EVENT, 2, 4);
  xnee_add_range(xd, XNEE_DEVICE_EVENT, 7, 14);
  xnee_add_range(xd, XNEE_REQUEST, 2, 4);
  xnee_add_range(xd, XNEE_REPLY, 2, 4);
  xnee_add_range(xd, XNEE_ERROR, 1, 1);

  xnee_prepare(xd);

  xnee_record_print_record_range (xd, NULL) ;
  total++;

  ret = xnee_print_ranges (xd, xd->out_file) ;
  XNEE_TEST_ASSERT(ret, 0, "xnee_record_print_ranges");

  ret = xnee_print_data_range_count (xd);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_data_range_count");

  xnee_replay_printbuffer_impl (xd );
  total++;

  xnee_version(xd);
  total++;

  ret = xnee_print_xnee_data(xd);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_xnee_data");

  ret = xnee_print_xnee_resource_settings (xd, xd->out_file ) ;
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_xnee_resource_settings");
  
  xnee_store_mouse_pos (xd );
  total++;

  ret = xnee_print_xnee_settings(xd, xd->out_file);
  XNEE_TEST_ASSERT(ret, 0, "xnee_rec_print_xnee_settings");

  ret = xnee_print_data_str(xd, "MotionNotify", XNEE_EVENT);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_data_str");

  return 0;
}

int 
test_printfuns(xnee_data *xd)
{
  int ret ;
  XRecordInterceptData xrecintd_impl;
  XRecordDatum         xrec_data_impl;
  xResourceReq         req_impl;
  xEvent               ev_impl;
  xGenericReply        rep_impl;
  xError               err_impl;
  int req_type ;
  int ev_type ;
  int i ;

  XRecordInterceptData *xrecintd  = &xrecintd_impl;
  XRecordDatum         *xrec_data = &xrec_data_impl;
  xResourceReq         *req       = &req_impl;
  xEvent               *ev        = &ev_impl;
  xGenericReply        *rep       = &rep_impl;
  xError               *err       = &err_impl;

  ret = xnee_print_event_info(xd);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_event_info");

  ret = xnee_print_error_info(xd);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_error_info");

  ret = xnee_print_request_info(xd);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_request_info");

  ret = xnee_print_reply_info(xd);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_reply_info");

  ret = xnee_print_data_info(xd);
  XNEE_TEST_ASSERT(ret, 0, "xnee_print_data_info");


  /* just make sure it links :) */
  xnee_verbose_event(xd, 18);
  total++;
  
  /* make sure it accepts NULL without crashing the app */
  xnee_record_print_request(xd, NULL);   
  total++;
  xnee_human_print_request(xd, NULL);   
  total++;
  

  /* NOTE: bogus values */
  #define SET_BOGUES_REQ_VALUES(r)   \
  memset(xrecintd, 0, sizeof(XRecordInterceptData)); \
  memset(xrec_data, 0, sizeof(XRecordDatum)); \
  req_type     = r ; \
  req->reqType = 1 ; \
  req->length  = 1 ; \
  req->id      = 4 ; \
  xrecintd->server_time = 200; \
  xrec_data->req    = *(xReq*)&req;\
  xrec_data->type   = req_type;\
  xrecintd->data    = (unsigned char*)xrec_data;


 for (i=1;i<128;i++)
    {
      printf("  request: %d\n", i);
      
      SET_BOGUES_REQ_VALUES(i);


      xnee_record_print_request(xd, xrecintd);  
      total++;

      SET_BOGUES_REQ_VALUES(i);
      xnee_human_print_request(xd, xrecintd);  
      total++;

      SET_BOGUES_REQ_VALUES(i);
      xnee_human_print_request_verbose(xd, xrecintd);  
      total++;
    }
  
  printf ("==================================================\n");

  #define SET_BOGUES_EV_VALUES(e)   \
  memset(xrecintd, 0, sizeof(XRecordInterceptData));  \
  memset(xrec_data, 0, sizeof(XRecordDatum));  \
  ev_type      = e ;  \
  ev->u.u.type = 0 ;   \
  ev->u.keyButtonPointer.state = 0 ;   \
  xrec_data->event  = *(xEvent*)&ev;  \
  xrec_data->type   = (unsigned char) ev_type ; \
  xrecintd->data    = (unsigned char*) xrec_data;  

  for (i=2;i<35;i++)
    {
      SET_BOGUES_EV_VALUES(i);
      xnee_human_print_event(xd, xrecintd);  
      total++;

      SET_BOGUES_EV_VALUES(i);
      xnee_human_print_event_verbose(xd, xrecintd);  
      total++;
    }


  memset(xrecintd, 0, sizeof(XRecordInterceptData));  
  memset(xrec_data, 0, sizeof(XRecordDatum));  
  rep->type = X_Reply;
  xrec_data->reply = *(xGenericReply*)&req ;
  xrecintd->data = (unsigned char*) xrec_data;

  xnee_human_print_reply (xd, xrecintd );
  total++;

  xnee_record_print_reply (xd, xrecintd );
  total++;

  err->type = X_Error;
  xrec_data->error = *(xError*)&err;
  xrecintd->data   = (unsigned char*) xrec_data;
  xnee_human_print_error (xd, xrecintd );
  total++;

  xnee_record_print_error (xd, xrecintd );
  total++;

  return 0;
}

int main()
{
  xnee_data *xdl;

  fails = 0;
  total = 0;
  

  printf (" print functions tester\n");

  xdl = xnee_new_xnee_data();

  xnee_set_program_name (xdl, "print-tester");

  xnee_set_application_parameters (xdl, NULL);

  test_printfuns(xdl);

  test_rangefuns(xdl);

  test_distributionfuns(xdl);

  xnee_set_verbose(xdl);
  xnee_verbose((xdl, "Just a simple string, printed from test code\n"));
  xnee_verbose((NULL, "Just a simple string, but with xnee_data arg set to NULL\n"));
  xnee_print_error("Simple test string in test code\n");
  xnee_unset_verbose(xdl);

  fprintf (stdout, "\n");
  fprintf (stdout, "\tSucesses:  %d\n", total);
  fprintf (stdout, "\tFailures:  %d\n", fails);

  xnee_close_down(xdl);

  
      
  return 0;
}