Back to index

im-sdk  12.3.91
flowtest.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <EIMIL.h>
00005 
00006 static unsigned char* evtype;
00007 static int evval;
00008 static int evmod;
00009 static int evchar;
00010 static unsigned char* evmtext;
00011 
00012 static int
00013 store_event(
00014     EIMIL_handle eh,
00015     EIMIL_event *pev
00016 )
00017 {
00018     if (evtype) free(evtype);
00019     evtype = strdup(pev->type);
00020     if (pev->pv_val)
00021        evval = pev->pv_val->v.number;
00022     else
00023        evval = -1;
00024 
00025     if (pev->pv_mod)
00026        evmod = pev->pv_mod->v.number;
00027     else
00028        evmod = -1;
00029 
00030     if (pev->pv_char)
00031        evchar = pev->pv_char->v.ch;
00032     else
00033        evchar = -1;
00034 
00035     if (evmtext) free(evmtext);
00036 
00037     if (pev->pv_mtext) {
00038        evmtext = EIMIL_convert_UTF32_to_UTF8(pev->pv_mtext->v.mtext.ustr);
00039     } else {
00040        evmtext = NULL;
00041     }
00042 
00043     return 1;
00044 }
00045 
00046 void
00047 sendev(
00048     EIMIL_handle eh,
00049     unsigned char *type,
00050     int val,
00051     int mod,
00052     unsigned char *text
00053 )
00054 {
00055     EIMIL_value *pev;
00056 
00057     pev = EIMIL_construct_event(type,
00058                             EIMIL_construct_number(val),
00059                             EIMIL_construct_number(mod),
00060                             NULL,
00061                             EIMIL_construct_mtext_from_UTF8(text));
00062 
00063     EIMIL_send_event(eh, pev);
00064 }
00065 
00066 int
00067 main(
00068     int argc,
00069     char **argv
00070 )
00071 {
00072     char buf[1024];
00073     unsigned char *pfn;
00074     EIMIL_handle eh, eh2;
00075     EIMIL_value *pv;
00076 
00077     getcwd(buf, sizeof(buf));
00078 
00079     EIMIL_initialize();
00080 
00081     EIMIL_register_class("org.OpenI18N.test", buf);
00082     pfn = EIMIL_find_file("org.OpenI18N.test", "flowtest.xml");
00083 
00084     if (!EIMIL_parse_file(&eh, pfn)) goto error;
00085     EIMIL_register_handler(eh, store_event, NULL, NULL);
00086 
00087     fprintf(stderr, "1st test");
00088     /* first test */
00089     /* if */
00090     sendev(eh, "test", 1, 0, "test");
00091     ASSERT(evval == 1);
00092     /* select */
00093     sendev(eh, "test", 0, 0, "Test1");
00094     ASSERT(evval == 1);
00095     /* while */
00096     sendev(eh, "test", 0, 1, "test");
00097     ASSERT(evval == 0);
00098     fprintf(stderr, "...done.\n");
00099 
00100     /* reset by sending an event. */
00101     sendev(eh, "test", 0, 0, "");
00102 
00103     fprintf(stderr, "2nd test");
00104     /* second test */
00105     /* if */
00106     sendev(eh, "test", 0, 0, "test");
00107     ASSERT(evval == 0);
00108     /* select */
00109     sendev(eh, "test", 0, 0, "Test2");
00110     ASSERT(evval == 2);
00111     /* while */
00112     sendev(eh, "test", 0, 2, "test");
00113     ASSERT(evval == 0);
00114     sendev(eh, "test", 0, 0, "test");
00115     ASSERT(evval == 1);
00116     fprintf(stderr, "...done.\n");
00117 
00118     /* reset by sending an event. */
00119     sendev(eh, "test", 0, 0, "");
00120 
00121     fprintf(stderr, "3rd test");
00122     /* third test */
00123     /* if */
00124     sendev(eh, "test", 1, 10, "test");
00125     ASSERT(evval == 1);
00126     /* select */
00127     sendev(eh, "test", 0, 0, "Test3");
00128     ASSERT(evval == 3);
00129     /* while */
00130     sendev(eh, "test", 0, 3, "test");
00131     ASSERT(evval == 0);
00132     sendev(eh, "test", 0, 0, "test");
00133     ASSERT(evval == 1);
00134     sendev(eh, "test", 0, 0, "test");
00135     ASSERT(evval == 2);
00136     fprintf(stderr, "...done.\n");
00137 
00138     /* reset by sending an event. */
00139     sendev(eh, "test", 0, 0, "");
00140 
00141     fprintf(stderr, "4th test");
00142     /* forth test */
00143     /* if */
00144     sendev(eh, "test", 0, 10, "XXX");
00145     ASSERT(evval == 0);
00146     /* select */
00147     sendev(eh, "test", 0, 0, "Test4");
00148     ASSERT(evval == 4);
00149     /* while */
00150     sendev(eh, "test", 0, 4, "test");
00151     ASSERT(evval == 0);
00152     sendev(eh, "test", 0, 0, "test");
00153     ASSERT(evval == 1);
00154     sendev(eh, "test", 0, 0, "test");
00155     ASSERT(evval == 2);
00156     sendev(eh, "test", 0, 0, "test");
00157     ASSERT(evval == 3);
00158     fprintf(stderr, "...done.\n");
00159 
00160     /* reset by sending an event. */
00161     sendev(eh, "test", 0, 0, "");
00162 
00163     fprintf(stderr, "5th test");
00164     /* fifth test */
00165     /* if */
00166     sendev(eh, "test", 100, 10, "XXX");
00167     ASSERT(evval == 0);
00168     /* select */
00169     sendev(eh, "test", 0, 0, "XXXX");
00170     ASSERT(evval == 5);
00171     /* while */
00172     sendev(eh, "test", 0, 5, "test");
00173     ASSERT(evval == 0);
00174     sendev(eh, "test", 0, 0, "test");
00175     ASSERT(evval == 1);
00176     sendev(eh, "test", 0, 0, "test");
00177     ASSERT(evval == 2);
00178     sendev(eh, "test", 0, 0, "test");
00179     ASSERT(evval == 3);
00180     sendev(eh, "test", 0, 0, "test");
00181     ASSERT(evval == 4);
00182     fprintf(stderr, "...done.\n");
00183 
00184     if (!EIMIL_send_event(eh, NULL)) goto error;
00185 
00186     return 0;
00187 
00188 error:
00189     EIMIL_get_errormsg(eh, &pfn);
00190     fprintf(stderr, "%s\n", pfn);
00191     return 255;
00192 }
00193