1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,150 +0,0 @@ |
1 |
-/* |
|
2 |
- * re_tests_ui.c |
|
3 |
- * |
|
4 |
- * A programmers editor |
|
5 |
- * |
|
6 |
- * Tests (ensure correct functionality of modules) |
|
7 |
- * |
|
8 |
- * Author: Dario Rodriguez dario@softhome.net |
|
9 |
- * This program is licensed under the terms of GNU GPL v2.1+ |
|
10 |
- */ |
|
11 |
- |
|
12 |
-#include <stdio.h> |
|
13 |
-#include <stdlib.h> |
|
14 |
-#include <unistd.h> |
|
15 |
-#include <string.h> |
|
16 |
-#include <limits.h> |
|
17 |
-#include <fcntl.h> |
|
18 |
-#include <errno.h> |
|
19 |
- |
|
20 |
-#include "re_ui.h" |
|
21 |
- |
|
22 |
-#define TEST_OK "OK" |
|
23 |
- |
|
24 |
-typedef struct test_ui_t { |
|
25 |
- int needs_realui; |
|
26 |
- char *name; |
|
27 |
- char *(*fn)(reui_t *,char *,int , int, int, int); |
|
28 |
-} test_ui_t; |
|
29 |
- |
|
30 |
-char *test_utf8len(reui_t *ui, char *teststring, int expectednchars, int dummy1, int dummy2,int dummy3); |
|
31 |
-char *test_utf8col(reui_t *ui, char *teststring, int dummy0, int col, int expectedoffset,int dummy3); |
|
32 |
-char *test_utf8charlen(reui_t *ui, char *teststring, int dummy0, int dummy1, int offset,int charsizeatoffset); |
|
33 |
- |
|
34 |
-int |
|
35 |
-main(int argc, char *argv[]) |
|
36 |
-{ |
|
37 |
- struct reui_t dummyui; |
|
38 |
- struct { |
|
39 |
- char string[1024]; |
|
40 |
- int nchars; |
|
41 |
- int col; |
|
42 |
- int offsetcol; |
|
43 |
- int charsizeatoffsetcol; |
|
44 |
- } teststrings[]={ |
|
45 |
- {{"This is a latin1 string"},51-28,1,1,1}, |
|
46 |
- {{"lowercase acute vowels:\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"},23+5,23+1,23+2,2}, |
|
47 |
- }; |
|
48 |
- test_ui_t tests[]={ |
|
49 |
- {0,"utf8len",test_utf8len}, |
|
50 |
- {0,"utf8col",test_utf8col}, |
|
51 |
- {0,"utf8charlen",test_utf8charlen}, |
|
52 |
- }; |
|
53 |
- int flag_exit=0,flag_all=0; |
|
54 |
- reui_t *ui; |
|
55 |
- int i,s; |
|
56 |
- int nerrors,total; |
|
57 |
- char *res; |
|
58 |
- for(i=1;i<argc;i++) { |
|
59 |
- if(strcmp(argv[i],"--help")==0) { |
|
60 |
- fprintf(stderr,"Syntax: %s [--all] [--exit] [--help]\nExplanation:\n\t--all: do even the slow tests\n\t--exit: exit program at first unsuccessful test\n\t--help: this text\n",argv[0]); |
|
61 |
- return(1); |
|
62 |
- } else if(strcmp(argv[i],"--all")==0) { |
|
63 |
- flag_all=1; |
|
64 |
- } else if(strcmp(argv[i],"--exit")==0) { |
|
65 |
- flag_exit=1; |
|
66 |
- } |
|
67 |
- } |
|
68 |
- nerrors=0; |
|
69 |
- total=0; |
|
70 |
- /* flag_all is not used right now, next line is to silence the compiler */ |
|
71 |
- total+=(flag_all&0); |
|
72 |
- /* end of hack */ |
|
73 |
- memset(&dummyui,0,sizeof(reui_t)); |
|
74 |
- for(s=0;s<(sizeof(teststrings)/sizeof(teststrings[0]));s++) { |
|
75 |
- fprintf(stderr,"\"%s\"\n",teststrings[s].string); |
|
76 |
- for(i=0;i<(sizeof(tests)/sizeof(tests[0]));i++,total++) { |
|
77 |
- ui=&dummyui; |
|
78 |
- if(tests[i].needs_realui && (ui=reui_init(NULL))==NULL) { |
|
79 |
- fprintf(stderr,"ERROR: problem initializing ui module\n"); |
|
80 |
- return(1); |
|
81 |
- } |
|
82 |
- fprintf(stderr,"%i:%s...",total+1,tests[i].name); |
|
83 |
- res=tests[i].fn(ui,teststrings[s].string,teststrings[s].nchars,teststrings[s].col,teststrings[s].offsetcol,teststrings[s].charsizeatoffsetcol); |
|
84 |
- if(strcmp(res,TEST_OK)==0) { |
|
85 |
- fprintf(stderr," ok.\n"); |
|
86 |
- } else { |
|
87 |
- fprintf(stderr," ERROR: %s <= %s(\"%s\",%i,%i,%i,%i)\n",res,tests[i].name,teststrings[s].string,teststrings[s].nchars,teststrings[s].col,teststrings[s].offsetcol,teststrings[s].charsizeatoffsetcol); |
|
88 |
- nerrors++; |
|
89 |
- if(flag_exit) { |
|
90 |
- /* exit on first error */ |
|
91 |
- s=sizeof(teststrings)/sizeof(teststrings[0]); |
|
92 |
- break; |
|
93 |
- } |
|
94 |
- } |
|
95 |
- if(tests[i].needs_realui) |
|
96 |
- reui_free(ui),ui=NULL; |
|
97 |
- } |
|
98 |
- } |
|
99 |
- fprintf(stderr,"\n"); |
|
100 |
- if(nerrors==0) |
|
101 |
- fprintf(stderr,"All %i tests passed OK\n",total); |
|
102 |
- else |
|
103 |
- fprintf(stderr,"%i test(s) failed of %i tests run.\n",nerrors,total); |
|
104 |
- if(ui!=NULL && ui!=&dummyui) |
|
105 |
- reui_free(ui),ui=NULL; |
|
106 |
- return((nerrors==0)?0:1); |
|
107 |
-} |
|
108 |
- |
|
109 |
-char * |
|
110 |
-test_utf8len(reui_t *ui, char *teststring, int expectednchars, int dummy1, int dummy2, int dummy3) |
|
111 |
-{ |
|
112 |
- int res; |
|
113 |
- static char errorstr[1024]; |
|
114 |
- res=reui_utf8len(ui,teststring,strlen(teststring)); |
|
115 |
- if(res!=expectednchars) { |
|
116 |
- snprintf(errorstr,sizeof(errorstr),"expected %i chars, got %i chars",expectednchars,res); |
|
117 |
- errorstr[sizeof(errorstr)-1]='\0'; |
|
118 |
- return(errorstr); |
|
119 |
- } |
|
120 |
- return(TEST_OK); |
|
121 |
-} |
|
122 |
- |
|
123 |
-char *test_utf8col(reui_t *ui, char *teststring, int dummy0, int col, int expectedoffset, int dummy3) |
|
124 |
-{ |
|
125 |
- char *ptr; |
|
126 |
- static char errorstr[1024]; |
|
127 |
- ptr=reui_utf8col(ui,teststring,strlen(teststring),col); |
|
128 |
- if(ptr!=(teststring+expectedoffset)) { |
|
129 |
- snprintf(errorstr,sizeof(errorstr),"expected offset %i, got offset %i (\"%s\")",expectedoffset,(int) ((ptr==NULL)?-1:ptr-teststring),ptr); |
|
130 |
- errorstr[sizeof(errorstr)-1]='\0'; |
|
131 |
- return(errorstr); |
|
132 |
- } |
|
133 |
- return(TEST_OK); |
|
134 |
-} |
|
135 |
- |
|
136 |
-char * |
|
137 |
-test_utf8charlen(reui_t *ui, char *teststring, int dummy0, int dummy1, int offset,int charsizeatoffset) |
|
138 |
-{ |
|
139 |
- int res; |
|
140 |
- static char errorstr[1024]; |
|
141 |
- res=reui_utf8charlen(ui,teststring+offset,strlen(teststring+offset)); |
|
142 |
- if(res!=(charsizeatoffset)) { |
|
143 |
- snprintf(errorstr,sizeof(errorstr),"expected char size %i, got char size %i (\"%s\")",charsizeatoffset,res,teststring+offset); |
|
144 |
- errorstr[sizeof(errorstr)-1]='\0'; |
|
145 |
- return(errorstr); |
|
146 |
- } |
|
147 |
- return(TEST_OK); |
|
148 |
-} |
|
149 |
- |
|
150 |
- |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,150 @@ |
1 |
+/* |
|
2 |
+ * re_tests_ui.c |
|
3 |
+ * |
|
4 |
+ * A programmers editor |
|
5 |
+ * |
|
6 |
+ * Tests (ensure correct functionality of modules) |
|
7 |
+ * |
|
8 |
+ * Author: Dario Rodriguez dario@softhome.net |
|
9 |
+ * This program is licensed under the terms of GNU GPL v2.1+ |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+#include <stdio.h> |
|
13 |
+#include <stdlib.h> |
|
14 |
+#include <unistd.h> |
|
15 |
+#include <string.h> |
|
16 |
+#include <limits.h> |
|
17 |
+#include <fcntl.h> |
|
18 |
+#include <errno.h> |
|
19 |
+ |
|
20 |
+#include "re_ui.h" |
|
21 |
+ |
|
22 |
+#define TEST_OK "OK" |
|
23 |
+ |
|
24 |
+typedef struct test_ui_t { |
|
25 |
+ int needs_realui; |
|
26 |
+ char *name; |
|
27 |
+ char *(*fn)(reui_t *,char *,int , int, int, int); |
|
28 |
+} test_ui_t; |
|
29 |
+ |
|
30 |
+char *test_utf8len(reui_t *ui, char *teststring, int expectednchars, int dummy1, int dummy2,int dummy3); |
|
31 |
+char *test_utf8col(reui_t *ui, char *teststring, int dummy0, int col, int expectedoffset,int dummy3); |
|
32 |
+char *test_utf8charlen(reui_t *ui, char *teststring, int dummy0, int dummy1, int offset,int charsizeatoffset); |
|
33 |
+ |
|
34 |
+int |
|
35 |
+main(int argc, char *argv[]) |
|
36 |
+{ |
|
37 |
+ struct reui_t dummyui; |
|
38 |
+ struct { |
|
39 |
+ char string[1024]; |
|
40 |
+ int nchars; |
|
41 |
+ int col; |
|
42 |
+ int offsetcol; |
|
43 |
+ int charsizeatoffsetcol; |
|
44 |
+ } teststrings[]={ |
|
45 |
+ {{"This is a latin1 string"},51-28,1,1,1}, |
|
46 |
+ {{"lowercase acute vowels:\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"},23+5,23+1,23+2,2}, |
|
47 |
+ }; |
|
48 |
+ test_ui_t tests[]={ |
|
49 |
+ {0,"utf8len",test_utf8len}, |
|
50 |
+ {0,"utf8col",test_utf8col}, |
|
51 |
+ {0,"utf8charlen",test_utf8charlen}, |
|
52 |
+ }; |
|
53 |
+ int flag_exit=0,flag_all=0; |
|
54 |
+ reui_t *ui; |
|
55 |
+ int i,s; |
|
56 |
+ int nerrors,total; |
|
57 |
+ char *res; |
|
58 |
+ for(i=1;i<argc;i++) { |
|
59 |
+ if(strcmp(argv[i],"--help")==0) { |
|
60 |
+ fprintf(stderr,"Syntax: %s [--all] [--exit] [--help]\nExplanation:\n\t--all: do even the slow tests\n\t--exit: exit program at first unsuccessful test\n\t--help: this text\n",argv[0]); |
|
61 |
+ return(1); |
|
62 |
+ } else if(strcmp(argv[i],"--all")==0) { |
|
63 |
+ flag_all=1; |
|
64 |
+ } else if(strcmp(argv[i],"--exit")==0) { |
|
65 |
+ flag_exit=1; |
|
66 |
+ } |
|
67 |
+ } |
|
68 |
+ nerrors=0; |
|
69 |
+ total=0; |
|
70 |
+ /* flag_all is not used right now, next line is to silence the compiler */ |
|
71 |
+ total+=(flag_all&0); |
|
72 |
+ /* end of hack */ |
|
73 |
+ memset(&dummyui,0,sizeof(reui_t)); |
|
74 |
+ for(s=0;s<(sizeof(teststrings)/sizeof(teststrings[0]));s++) { |
|
75 |
+ fprintf(stderr,"\"%s\"\n",teststrings[s].string); |
|
76 |
+ for(i=0;i<(sizeof(tests)/sizeof(tests[0]));i++,total++) { |
|
77 |
+ ui=&dummyui; |
|
78 |
+ if(tests[i].needs_realui && (ui=reui_init(NULL))==NULL) { |
|
79 |
+ fprintf(stderr,"ERROR: problem initializing ui module\n"); |
|
80 |
+ return(1); |
|
81 |
+ } |
|
82 |
+ fprintf(stderr,"%i:%s...",total+1,tests[i].name); |
|
83 |
+ res=tests[i].fn(ui,teststrings[s].string,teststrings[s].nchars,teststrings[s].col,teststrings[s].offsetcol,teststrings[s].charsizeatoffsetcol); |
|
84 |
+ if(strcmp(res,TEST_OK)==0) { |
|
85 |
+ fprintf(stderr," ok.\n"); |
|
86 |
+ } else { |
|
87 |
+ fprintf(stderr," ERROR: %s <= %s(\"%s\",%i,%i,%i,%i)\n",res,tests[i].name,teststrings[s].string,teststrings[s].nchars,teststrings[s].col,teststrings[s].offsetcol,teststrings[s].charsizeatoffsetcol); |
|
88 |
+ nerrors++; |
|
89 |
+ if(flag_exit) { |
|
90 |
+ /* exit on first error */ |
|
91 |
+ s=sizeof(teststrings)/sizeof(teststrings[0]); |
|
92 |
+ break; |
|
93 |
+ } |
|
94 |
+ } |
|
95 |
+ if(tests[i].needs_realui) |
|
96 |
+ reui_free(ui),ui=NULL; |
|
97 |
+ } |
|
98 |
+ } |
|
99 |
+ fprintf(stderr,"\n"); |
|
100 |
+ if(nerrors==0) |
|
101 |
+ fprintf(stderr,"All %i tests passed OK\n",total); |
|
102 |
+ else |
|
103 |
+ fprintf(stderr,"%i test(s) failed of %i tests run.\n",nerrors,total); |
|
104 |
+ if(ui!=NULL && ui!=&dummyui) |
|
105 |
+ reui_free(ui),ui=NULL; |
|
106 |
+ return((nerrors==0)?0:1); |
|
107 |
+} |
|
108 |
+ |
|
109 |
+char * |
|
110 |
+test_utf8len(reui_t *ui, char *teststring, int expectednchars, int dummy1, int dummy2, int dummy3) |
|
111 |
+{ |
|
112 |
+ int res; |
|
113 |
+ static char errorstr[1024]; |
|
114 |
+ res=reui_utf8len(ui,teststring,strlen(teststring)); |
|
115 |
+ if(res!=expectednchars) { |
|
116 |
+ snprintf(errorstr,sizeof(errorstr),"expected %i chars, got %i chars",expectednchars,res); |
|
117 |
+ errorstr[sizeof(errorstr)-1]='\0'; |
|
118 |
+ return(errorstr); |
|
119 |
+ } |
|
120 |
+ return(TEST_OK); |
|
121 |
+} |
|
122 |
+ |
|
123 |
+char *test_utf8col(reui_t *ui, char *teststring, int dummy0, int col, int expectedoffset, int dummy3) |
|
124 |
+{ |
|
125 |
+ char *ptr; |
|
126 |
+ static char errorstr[1024]; |
|
127 |
+ ptr=reui_utf8col(ui,teststring,strlen(teststring),col); |
|
128 |
+ if(ptr!=(teststring+expectedoffset)) { |
|
129 |
+ snprintf(errorstr,sizeof(errorstr),"expected offset %i, got offset %i (\"%s\")",expectedoffset,(int) ((ptr==NULL)?-1:ptr-teststring),ptr); |
|
130 |
+ errorstr[sizeof(errorstr)-1]='\0'; |
|
131 |
+ return(errorstr); |
|
132 |
+ } |
|
133 |
+ return(TEST_OK); |
|
134 |
+} |
|
135 |
+ |
|
136 |
+char * |
|
137 |
+test_utf8charlen(reui_t *ui, char *teststring, int dummy0, int dummy1, int offset,int charsizeatoffset) |
|
138 |
+{ |
|
139 |
+ int res; |
|
140 |
+ static char errorstr[1024]; |
|
141 |
+ res=reui_utf8charlen(ui,teststring+offset,strlen(teststring+offset)); |
|
142 |
+ if(res!=(charsizeatoffset)) { |
|
143 |
+ snprintf(errorstr,sizeof(errorstr),"expected char size %i, got char size %i (\"%s\")",charsizeatoffset,res,teststring+offset); |
|
144 |
+ errorstr[sizeof(errorstr)-1]='\0'; |
|
145 |
+ return(errorstr); |
|
146 |
+ } |
|
147 |
+ return(TEST_OK); |
|
148 |
+} |
|
149 |
+ |
|
150 |
+ |