(file) Return to test_filter.cpp CVS log (file) (dir) Up to [OMI] / omi / tests / indication

  1 krisbash 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 krisbash 1.1 **==============================================================================
 23              */
 24              
 25              #include <vector>
 26              #include <algorithm>
 27              #include <ut/ut.h>
 28              #include <indication/common/indicommon.h>
 29              #include <indication/indimgr/filter.h>
 30              #include <pal/strings.h>
 31              
 32              using namespace std;
 33              
 34              NitsSetup(TestFilterSetup)
 35              NitsEndSetup
 36              
 37              NitsCleanup(TestFilterSetup)
 38              NitsEndCleanup
 39              
 40              NitsTestWithSetup(TestCreateFilter, TestFilterSetup)
 41              {
 42                  int c;
 43 krisbash 1.1     const MI_Char* query = MI_T("select * from CIM_Indication");
 44                  Filter * filter = Filter_New(query, QUERY_LANGUAGE_WQL, NULL);
 45                  UT_ASSERT( NULL != filter );
 46                  if (filter)
 47                  {
 48                      UT_ASSERT( Filter_GetRefcount(filter) == 1 );
 49              
 50                      // identifier gets generated upon adding to indication manager cache
 51                      UT_ASSERT( NULL == filter->base.base.identifier );
 52              
 53                      c = Tcscasecmp(filter->QueryLanguage, QUERY_LANGUAGE_WQL);
 54                      UT_ASSERT( c == 0 );
 55              
 56                      c = Tcscasecmp(filter->Query, query);
 57                      UT_ASSERT( c == 0 );
 58              
 59                      Filter_Release(filter);
 60                  }
 61              
 62                  query = MI_T("select * from CIM_Indication2");
 63                  filter = Filter_New(query, QUERY_LANGUAGE_CQL, NULL);
 64 krisbash 1.1     UT_ASSERT( NULL != filter );
 65                  if (filter)
 66                  {
 67                      UT_ASSERT( Filter_GetRefcount(filter) == 1 );
 68              
 69                      // identifier gets generated upon adding to indication manager cache
 70                      UT_ASSERT( NULL == filter->base.base.identifier );
 71              
 72                      c = Tcscasecmp(filter->QueryLanguage, QUERY_LANGUAGE_CQL);
 73                      UT_ASSERT( c == 0 );
 74              
 75                      c = Tcscasecmp(filter->Query, query);
 76                      UT_ASSERT( c == 0 );
 77              
 78                      Filter_AddRef(filter);
 79                      UT_ASSERT( Filter_GetRefcount(filter) == 2);
 80                      Filter_AddRef(filter);
 81                      UT_ASSERT( Filter_GetRefcount(filter) == 3);
 82                      Filter_AddRef(filter);
 83                      UT_ASSERT( Filter_GetRefcount(filter) == 4);
 84                      Filter_Release(filter);
 85 krisbash 1.1         Filter_Release(filter);
 86                      Filter_Release(filter);
 87              
 88                      Filter_Release(filter);
 89                  }
 90              }
 91              NitsEndTest
 92              
 93              NitsTestWithSetup(TestCreateFilter_WQL, TestFilterSetup)
 94              {
 95                  const MI_Char* query = MI_T("select * from CIM_TestClass where 2 > 1");
 96                  Filter * filter = Filter_New(query, QUERY_LANGUAGE_WQL, NULL);
 97                  UT_ASSERT( NULL != filter );
 98                  if (filter)
 99                  {
100                      UT_ASSERT(NULL != filter->wql);
101                      UT_ASSERT(FILTER_UNARY_TEMP == filter->base.type);
102                      UT_ASSERT(Tcscasecmp(filter->wql->className, MI_T("CIM_TestClass")) == 0);
103              
104                      /* Test Namespace */
105                      MI_StringA nsa;
106 krisbash 1.1         MI_String data[3];
107                      MI_String nsroot = (MI_Char*)MI_T("root");
108                      nsa.size = 3;
109                      nsa.data = data;
110                      data[0] = nsroot;
111                      data[1] = (MI_Char*)MI_T("interop");
112                      data[2] = (MI_Char*)MI_T("root/cimv2");
113              
114                      /* Fail if namespace size is not 1 */
115                      int r = Filter_SetNamespace(filter, &nsa);
116                      UT_ASSERT( r == -1 );
117                      UT_ASSERT( filter->SourceNamespaces.data == NULL );
118                      nsa.size = 1;
119              
120                      /* Success if namespace size is 1 */
121                      r = Filter_SetNamespace(filter, &nsa);
122                      UT_ASSERT( r == 0 );
123                      UT_ASSERT( filter->SourceNamespaces.data != NULL );
124                      UT_ASSERT( filter->SourceNamespaces.size == 1 );
125                      UT_ASSERT(Tcscasecmp(filter->SourceNamespaces.data[0], nsroot) == 0);
126              
127 krisbash 1.1         /* NO-OP if filter already added to a container */
128                      /* i.e., namespaces property of filter should not change */
129                      filter->base.base._container = (void*)0xF;
130                      nsa.data = &data[1];
131                      r = Filter_SetNamespace(filter, &nsa);
132                      UT_ASSERT( r == 0 );
133                      UT_ASSERT( filter->SourceNamespaces.data != NULL );
134                      UT_ASSERT( filter->SourceNamespaces.size == 1 );
135                      UT_ASSERT(Tcscasecmp(filter->SourceNamespaces.data[0], nsroot) == 0);
136                      filter->base.base._container = NULL;
137              
138                      Filter_Release(filter);
139                  }
140              }
141              NitsEndTest
142              
143              // Following are negative test cases and out of memory or the negative input generates the same error
144              // TODO: one can check if error object has specific errorcode to make sure we return right error for unknown dialect vs OOM
145              
146              NitsTestWithSetup(TestCreateFilter_NotSupportedQueryDialect, TestFilterSetup)
147              {
148 krisbash 1.1     const MI_Char* query = MI_T("select * from CIM_Indication");
149                  MI_Instance* error = NULL;
150                  Filter * filter = Filter_New(query, MI_T("UnknownDialect"), &error);
151                  UT_ASSERT( NULL == filter );
152                  UT_ASSERT( NULL != error );
153                  NitsIgnoringError(); 
154                  if (error)
155                      MI_Instance_Delete(error);
156              }
157              NitsEndTest
158              
159              NitsTestWithSetup(TestCreateFilter_InvalidWQLQuery, TestFilterSetup)
160              {
161                  const MI_Char* query = MI_T("select * from CIM_Indication where");
162                  MI_Instance* error = NULL;
163                  Filter * filter = Filter_New(query, QUERY_LANGUAGE_WQL, &error);
164                  UT_ASSERT( NULL == filter );
165                  UT_ASSERT( NULL != error );
166                  NitsIgnoringError(); 
167                  if (error)
168                      MI_Instance_Delete(error);
169 krisbash 1.1 }
170              NitsEndTest
171              
172              NitsTestWithSetup(TestCreateFilter_NotSupportedCQLQuery, TestFilterSetup)
173              {
174                  const MI_Char* query = MI_T("select * from CIM_Indication, CIM_TestClass where (1=1)");
175                  MI_Instance* error = NULL;
176                  Filter * filter = Filter_New(query, QUERY_LANGUAGE_CQL, &error);
177                  UT_ASSERT( NULL == filter );
178                  UT_ASSERT( NULL != error );
179                  NitsIgnoringError(); 
180                  if (error)
181                      MI_Instance_Delete(error);
182              }
183              NitsEndTest
184              
185              
186              
187              
188              

ViewCVS 0.9.2