Initialize Tizen 2.3
[external/ragel.git] / test / call1.rl
1 /*
2  * @LANG: c
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7
8 int num = 0;
9
10 struct test
11 {
12         int cs, top, stack[32];
13 };
14
15 %%{ 
16         machine test;
17         access fsm->;
18
19         action check_num {
20                 if ( num & 1 )
21                         fcall *fentry(odd);
22                 else
23                         fcall even;
24         }
25
26         # Test call and return functionality.
27         even := 'even' any @{fhold; fret;};
28         odd := 'odd' any @{fhold; fret;};
29         num = [0-9]+ ${ num = num * 10 + (fc - '0'); };
30         even_odd = num ' ' @check_num "\n";
31
32         # Test calls in out actions.
33         fail := !(any*);
34         out_acts = 'OA ok\n' | 
35                 'OA error1\n' |
36                 'OA error2\n';
37
38         main := even_odd | out_acts;
39 }%%
40
41 %% write data;
42
43 void test_init( struct test *fsm )
44 {
45         num = 0;
46         %% write init;
47 }
48
49 void test_execute( struct test *fsm, const char *data, int len )
50 {
51         const char *p = data;
52         const char *pe = data+len;
53
54         %% write exec;
55 }
56
57 int test_finish( struct test *fsm )
58 {
59         if ( fsm->cs == test_error )
60                 return -1;
61         if ( fsm->cs >= test_first_final )
62                 return 1;
63         return 0;
64 }
65
66 #define BUFSIZE 1024
67
68 void test( char *buf )
69 {   
70         struct test test;
71         test_init( &test );
72         test_execute( &test, buf, strlen(buf) );
73         if ( test_finish( &test ) > 0 )
74                 printf( "ACCEPT\n" );
75         else
76                 printf( "FAIL\n" );
77 }
78
79 int main()
80 {
81         test( "78 even\n" );
82         test( "89 odd\n" );
83         test( "1 even\n" );
84         test( "0 odd\n" );
85         test( "OA ok\n" );
86         test( "OA error1\n" );
87         test( "OA error2\n" );
88         
89         return 0;
90 }
91
92
93 #ifdef _____OUTPUT_____
94 ACCEPT
95 ACCEPT
96 FAIL
97 FAIL
98 ACCEPT
99 ACCEPT
100 ACCEPT
101 #endif