1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ------------------------------------------- */
21 #include "schemaparser.h"
22 #include "schemaparser_impl.h"
24 // Interface to FTA definition lexer and parser ...
27 //double htonf(double f){return f;}
28 //long long int htonll(long long int l){return l;}
34 // ./test_interfacelib test_param1.q_0.sch test_param4.q_1.sch
38 int main(int argc, char **argv){
45 fprintf(stderr,"Usage: %s schema_file [schema_file ... ]\n",argv[0]);
51 for(f=0;f<nfiles;++f){
53 FILE *infl = fopen(argv[f+1],"r");
55 fprintf(stderr,"ERROR can't open schema file %s\n",argv[1]);
61 sch_handle = ftaschema_parse_file(infl);
64 while(fgets(tmpstr, 1000, infl)){
68 sch_handle = ftaschema_parse_string( (char *)(fstr.c_str()) );
72 fprintf(stderr,"ERROR parsing schema file.\n");
76 ftaschema_debugdump(sch_handle);
81 printf("Testing access library.\n");
83 // test_param1.q_0.sch
85 printf("Query %s has %d fields and %d parameters.\n",
86 ftaschema_name(0), ftaschema_tuple_len(0), ftaschema_parameter_len(0));
87 printf("The parameters are named:\n");
88 for(i=0;i<ftaschema_parameter_len(0);++i){
89 printf("%s ",ftaschema_parameter_name(0,i));
92 printf("Setting parameters by name.\n");
93 sprintf(tmpstr,"%d",1111); printf("min_hdr_length : %s\n",tmpstr);
94 ftaschema_setparam_by_name(0,"min_hdr_length",tmpstr,strlen(tmpstr));
95 sprintf(tmpstr,"%d",2222); printf("unused_param : %s\n",tmpstr);
96 ftaschema_setparam_by_name(0,"unused_param",tmpstr,strlen(tmpstr));
97 printf("Creating param block.\n");
98 ftaschema_create_param_block(0,&pblock, &block_size);
99 printf("Block created, size is %d. Accessing by name.\n",block_size);
100 printf("\t%s=%d (type is %d) %s=%lu (type is %d)\n",
102 (ftaschema_get_field_by_name(0,"time",pblock, block_size)).r.i,
103 (ftaschema_get_field_by_name(0,"time",pblock, block_size)).field_data_type,
105 (ftaschema_get_field_by_name(0,"hdr_length",pblock, block_size)).r.ul,
106 (ftaschema_get_field_by_name(0,"hdr_length",pblock, block_size)).field_data_type
109 printf("Query %s has %d fields and %d parameters.\n",
110 ftaschema_name(1), ftaschema_tuple_len(1), ftaschema_parameter_len(1));
111 printf("The parameters are named:\n");
112 for(i=0;i<ftaschema_parameter_len(1);++i){
113 printf("%s ",ftaschema_parameter_name(1,i));
117 printf("Setting parameters by index.\n");
118 sprintf(tmpstr,"%d",3333); printf("an_ullong_parameter : %s\n",tmpstr);
119 ftaschema_setparam_by_index(1,0,tmpstr,strlen(tmpstr));
120 sprintf(tmpstr,"%d",2222); printf("ullong_parameter2 : %s\n",tmpstr);
121 ftaschema_setparam_by_index(1,1,tmpstr,strlen(tmpstr));
122 sprintf(tmpstr,"%f",4444.0); printf("min_prec : %s\n",tmpstr);
123 ftaschema_setparam_by_index(1,2,tmpstr,strlen(tmpstr));
124 sprintf(tmpstr,"%s","Foo"); printf("min_str : %s\n",tmpstr);
125 ftaschema_setparam_by_index(1,3,tmpstr,strlen(tmpstr)+1);
126 sprintf(tmpstr,"%s","Bar"); printf("min_str : %s\n",tmpstr);
127 ftaschema_setparam_by_index(1,3,tmpstr,strlen(tmpstr)+1);
128 ftaschema_create_param_block(1,&pblock, &block_size);
129 printf("Block created, size is %d. Accessing by index.\n",block_size);
130 printf("\t%s=%ld, type is %d\n",
131 ftaschema_tuple_name(1,0),
132 (ftaschema_get_field_by_index(1,0,pblock, block_size)).r.ul,
133 (ftaschema_get_field_by_index(1,0,pblock, block_size)).field_data_type
135 printf("\t%s=%ld, type is %d\n",
136 ftaschema_tuple_name(1,1),
137 (ftaschema_get_field_by_index(1,1,pblock, block_size)).r.ul,
138 (ftaschema_get_field_by_index(1,1,pblock, block_size)).field_data_type
140 printf("\t%s=%lf, type is %d\n",
141 ftaschema_tuple_name(1,2),
142 (ftaschema_get_field_by_index(1,2,pblock, block_size)).r.f,
143 (ftaschema_get_field_by_index(1,2,pblock, block_size)).field_data_type
145 printf("\t%s=%s (length=%d), type is %d\n",
146 ftaschema_tuple_name(1,3),
147 (ftaschema_get_field_by_index(1,3,pblock, block_size)).r.vs.offset,
148 (ftaschema_get_field_by_index(1,3,pblock, block_size)).r.vs.length,
149 (ftaschema_get_field_by_index(1,3,pblock, block_size)).field_data_type