2 * Test program for epp library. It reads file, given as argument
3 * (while not stdin? to simplify running under debugger)
4 * and performs specified operations
5 * After each operation some fields of epp structure are printed
6 * Availiable operations
7 * read file - open epp file for reading
8 * create file width height offsite bits - create file (write-only mode)
9 * load file - opens file for random read-write access
10 * save - saves loaded file
11 * reset - resets write-only file to read-only mode
12 * get col row - return value
13 * put col row value - change value of pixel
14 * line col1 col2 row value - change value of several adjanced pixels
16 * NOTE: space after hash mark is mandantory
21 char filename[1024]; /* name of currently used epp-file */
22 FILE *f; /*file with test command. */
23 char *error_code[]={"OK","ME_POINT_OUTSIDE","ME_INVALID_MODE",
24 "ME_READ_ERROR","ME_WRITE_ERROR","ME_INVALID_PUT","ME_OUT_OF_MEMORY",
25 "ME_ACCESS_DENIED","ME_NO_FILE","ME_INVALID_FILE","ME_CREATE_ERROR",NULL};
26 /* prints value of global map_error varable. If it is
27 related with file-system error, also
28 prints system error description */
31 if (map_error>ME_OUT_OF_MEMORY) {
32 perror(error_code[map_error]);
34 printf("%s\n",error_code[map_error]);
39 * Prints verbosely mode field of EPP structure.
40 * Note: if it prints something hexadecimal, it should be considered
43 char *epp_flags[]={"MAP_INPUT","MAP_OUTPUT","MAP_LOADED","MAP_CACHED",
44 NULL,NULL,NULL,"MAP_MODIFIED",
45 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
46 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
47 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
50 * Prints verbosely mode field of EPP structure.
51 * Note: if it prints something hexadecimal, it should be considered
54 void print_flags(EPP *epp)
58 for(i=0,mask=1;i<32;i++,mask<<=1) {
61 printf("%c 0x%X",separator,mask);
63 printf("%c %s",separator,epp_flags[i]);
70 /*************************************************************************/
71 /* individual test procedures begin here */
72 /************************************************************************/
77 void test_put(EPP *epp)
80 fprintf(stderr,"Invalid test case - put before open");
83 if (fscanf(f,"%d %d %d",&col,&row,&value)!=3) {
84 fprintf(stderr,"Invalid line in input file\n");
87 printf("epp_put(%d,%d,%d):",col,row,value);
88 epp_put(epp, col, row, value);
89 printf("max=%d,min=%d ",epp->max, epp->min);
94 void test_putline(EPP *epp)
95 { int row,col,col2,value;
97 fprintf(stderr,"Invalid test case - putline before open");
100 if (fscanf(f,"%d %d %d %d",&col,&col2,&row,&value)!=4) {
101 fprintf(stderr,"Invalid line in input file\n");
104 printf("epp_putline(%d,%d,%d,%d):",col,col2,row,value);
105 epp_putline(epp,col,col2,row,value);
106 printf("max=%d,min=%d ",epp->max, epp->min);
111 void test_get(EPP *epp)
114 fprintf(stderr,"Invalid test case - get before open");
117 if (fscanf(f,"%d %d",&row,&col)!=2) {
118 fprintf(stderr,"Invalid line in input file\n");
121 printf("epp_get(%d,%d)=%d ",col,row,epp_get(epp,col,row));
127 void test_save(EPP* epp)
130 fprintf(stderr,"Invalid test case - save before load");
133 printf("Saving %s...",filename);
143 EPP *test_read(EPP *epp)
145 if (epp) close_epp(epp);
146 if (fscanf(f,"%s",filename)!=1) {
147 fprintf(stderr,"Missing filename for read command\n");
150 printf("Opening %s in read-only mode..",filename);
151 epp=open_epp(filename);
154 printf("File wasn't opened.\n");
157 printf("%s header information:\n bits per cell:%d\n size:%dx%d\n "
158 "offsite %d\n values from: %d to %d\n ",filename,epp->kind,
159 epp->lc-epp->fc,epp->lr-epp->fr,epp->offsite,epp->min,epp->max);
168 EPP *test_load(EPP *epp)
170 if (epp) close_epp(epp);
171 if (fscanf(f,"%s",filename)!=1) {
172 fprintf(stderr,"Missing filename for load command\n");
175 printf("Loading %s...",filename);
176 epp=load_epp(filename);
179 printf("File wasn't loaded.\n");
182 printf("%s header information:\n bits per cell:%d\n size:%dx%d\n "
183 "offsite %d\n values from: %d to %d\n ",filename,epp->kind,
184 epp->lc-epp->fc,epp->lr-epp->fr,epp->offsite,epp->min,epp->max);
190 * Test reset. Performs reset operation
193 void test_reset(EPP *epp)
196 fprintf(stderr,"Invalid test case - reset before read");
199 printf("Resetting file.\n Current line was %d\n Flags was:",
205 printf("Current line now is:%d\n",epp->currentline);
206 printf("%s header information:\n bits per cell:%d\n size:%dx%d\n "
207 "offsite %d\n values from: %d to %d\n ",filename,epp->kind,
208 epp->lc-epp->fc,epp->lr-epp->fr,epp->offsite,epp->min,epp->max);
215 EPP *test_create(EPP *epp)
216 { int width,height,bits,offsite;
217 if (epp) close_epp(epp);
218 if (fscanf(f,"%s %d %d %d %d",filename,&width,&height,&offsite,&bits)!=5) {
219 fprintf(stderr,"Wrong arguments for create command\n");
222 Create16bit= (bits!=8);
223 printf("Creating %d-bit file %s...",Create16bit?16:8,filename);
224 epp=creat_epp(filename,1,1,width,height,0.5,0.5,width+0.5,height+0.5,
228 fprintf(stderr,"File is not created\n");
231 printf("%s header information:\n bits per cell:%d\n size:%dx%d\n "
232 "offsite %d\n values from: %d to %d\n ",filename,epp->kind,
233 epp->lc-epp->fc,epp->lr-epp->fr,epp->offsite,epp->min,epp->max);
237 int main (int argc, char *argv[])
241 fprintf(stderr,"Usage: test_load test-file");
244 f=fopen(argv[1],"r");
250 /* skip empty lines */
251 if (fscanf(f,"%s",command)!=1) {
254 if (!strcmp(command,"put")) {
256 } else if (!strcmp(command,"get")) {
258 } else if (!strcmp(command,"reset")) {
260 } else if (!strcmp(command,"save")) {
262 } else if (!strcmp(command,"load")) {
264 } else if (!strcmp(command,"read")) {
266 } else if (!strcmp(command,"create")) {
267 epp=test_create(epp);
268 } else if (!strcmp(command,"line")) {
270 } else if (!strcmp(command,"#")) {
272 fgets(command,255,f);
273 newline=strchr(command,'\n');
274 if (newline) *newline=0;
275 printf("*** %s ***\n",command);
278 fprintf(stderr,"Unknown command:%s",command);
284 if (epp) close_epp(epp);