1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #include <MI.h>
26 #include <assert.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30
31
32 extern "C" {
33 MI_Module* MI_Main(MI_Context* context);
34 }
35
36 const char* arg0;
37
38
39 /*
40
41 #pragma include("qualifiers.mof")
42
43 mike 1.1 // test file for qualifiers
44 // this mof file declares dirretne types of qualifiers and test
45 // progam verifies if they are actually in schema.c
46
47 // test checks that (based on options):
48 // standard qualifiers are generated
49 // boolean qualifiers are generated (TestQ_B, counter)
50 // Description is generated
51 // custom string qualifier is generated (TestQ_S)
52
53 Qualifier TestQ_B : boolean = true,
54 Scope(class, association, indication, method, property),
55 Flavor(EnableOverride, Restricted);
56
57 Qualifier TestQ_S : string = "SSS",
58 Scope(class, association, indication, method, property),
59 Flavor(EnableOverride, Restricted);
60
61 [Description ( "DDD" )]
62 class Test
63 {
64 mike 1.1 [Key, TestQ_B(false), TestQ_S("123")] uint32 kv;
65
66 [static] uint64 Foo([out, emBeddedInstance("X")] string embeddedProperty, [counter]uint32 c);
67 };
68
69
70 */
71 static void usage()
72 {
73 printf("usgae: %s <test-case>\n", arg0);
74 printf("\tsupported test cases:\n"
75 "\tdescription - expecting to find TestClass description 'DDD'\n"
76 "\tignore_all - insures no qualifiers are generated.\n"
77 );
78 exit(0);
79 }
80
81 static void* _FindFeatureDecl(
82 MI_FeatureDecl** features,
83 MI_Uint32 numFeatures,
84 const MI_Char* name)
85 mike 1.1 {
86 for( unsigned int i = 0; i < numFeatures; i++ )
87 {
88 if(strcmp(features[i]->name, name) == 0)
89 return features[i];
90 }
91
92 return 0;
93 }
94
95 static const MI_Qualifier* _FindQualifier(
96 const MI_ClassDecl* cd,
97 const char* qn
98 )
99 {
100 for( unsigned int i = 0; i < cd->numQualifiers; i++ )
101 {
102 if(strcmp(cd->qualifiers[i]->name, qn) == 0)
103 return cd->qualifiers[i];
104 }
105
106 mike 1.1 return 0;
107 }
108
109 static void testDescription(MI_Module* module)
110 {
111 // find 'Test' class
112 const MI_ClassDecl* cd =
113 (const MI_ClassDecl*) _FindFeatureDecl(
114 (MI_FeatureDecl**)module->schemaDecl->classDecls,
115 module->schemaDecl->numClassDecls,
116 "Test");
117
118 assert(cd != 0);
119
120 const MI_Qualifier* q= _FindQualifier(cd, "Description");
121
122 assert(q != 0);
123
124 assert(strcmp(*(char**)q->value, "DDD") == 0);
125 }
126
127 mike 1.1 static void testBoolean(MI_Module* module)
128 {
129 // find 'Test' class
130 const MI_ClassDecl* cd =
131 (const MI_ClassDecl*) _FindFeatureDecl(
132 (MI_FeatureDecl**)module->schemaDecl->classDecls,
133 module->schemaDecl->numClassDecls,
134 "Test");
135
136 assert(cd != 0);
137
138 const MI_PropertyDecl* prop =
139 (const MI_PropertyDecl*) _FindFeatureDecl(
140 (MI_FeatureDecl**)cd->properties,
141 cd->numProperties,
142 "kv");
143
144 assert(prop != 0);
145
146 const MI_Qualifier* q= _FindQualifier((const MI_ClassDecl*)prop, "TestQ_B");
147
148 mike 1.1 assert(q != 0);
149
150 assert( *(MI_Boolean*)q->value == MI_FALSE);
151
152 // find method Foo, parameter c and check qualifier counter
153 const MI_MethodDecl* m =
154 (const MI_MethodDecl*) _FindFeatureDecl(
155 (MI_FeatureDecl**)cd->methods,
156 cd->numMethods,
157 "Foo");
158
159 assert(m != 0);
160
161 prop =
162 (const MI_PropertyDecl*) _FindFeatureDecl(
163 (MI_FeatureDecl**)m->parameters,
164 m->numParameters,
165 "c");
166
167
168 assert(prop != 0);
169 mike 1.1
170 q = _FindQualifier((const MI_ClassDecl*)prop, "Counter");
171
172 assert(q != 0);
173
174 assert( *(MI_Boolean*)q->value == MI_TRUE);
175
176 }
177
178 static void testIgnoreAll(MI_Module* module)
179 {
180 assert(module->schemaDecl->qualifierDecls == 0);
181
182 // find 'Test' class
183 const MI_ClassDecl* cd = //_FindClass(module, "Test");
184 (const MI_ClassDecl*) _FindFeatureDecl(
185 (MI_FeatureDecl**)module->schemaDecl->classDecls,
186 module->schemaDecl->numClassDecls,
187 "Test");
188
189 assert(cd != 0);
190 mike 1.1
191 assert(cd->qualifiers == 0);
192 }
193
194 int main(int argc, char* argv[])
195 {
196 MI_Module* module = MI_Main(NULL);
197 assert(module != NULL);
198
199 arg0 = argv[0];
200
201 if (argc < 2)
202 {
203 fprintf(stderr, "Usage: %s test-case\n", arg0);
204 fprintf(stderr, "Try '%s -h' for help\n\n", arg0);
205 exit(1);
206 }
207
208 if (strcmp(argv[1],"description") == 0)
209 {
210 testDescription(module);
211 mike 1.1 }
212 else if (strcmp(argv[1],"ignore_all") == 0)
213 {
214 testIgnoreAll(module);
215 }
216 else if (strcmp(argv[1],"boolean") == 0)
217 {
218 testBoolean(module);
219 }
220 else if (strcmp(argv[1],"-h") == 0)
221 {
222 usage();
223 }
224 else
225 {
226 fprintf(stderr, "unknown parameter: %s \n", argv[1]);
227 fprintf(stderr, "Try '%s -h' for help\n\n", arg0);
228 exit(1);
229 }
230
231 return 0;
232 mike 1.1 }
|