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 <base/paths.h>
29 #include <base/log.h>
30 #include <pal/strings.h>
31 #include <indication/common/indicommon.h>
32 #include <indication/indimgr/mgr.h>
33 #include <omi_error/OMI_Error.h>
34 #include <omi_error/errorutil.h>
35 #include "util.h"
36
37 using namespace std;
38
39 /*
40 **==============================================================================
41 **
42 ** Defines structure to control the behavior of StrandSimAgentMgr
43 krisbash 1.1 ** For test indication manager, we need to simulate the behavior of AgentMgr,
44 ** it could,
45 **
46 ** (1) Fail inside _UT_HandleRequest
47 ** - Simulate Fail in AgentMgr_HandleRequest
48 ** (2) Succeed in _UT_HandleRequest and failed from StrandSimAgentMgr later
49 ** - Simulate succeed in AgentMgr_HandleRequest and failed in provider
50 ** (3) Succeed in StrandSimAgentMgr first and failed later
51 ** - Simulate succeed in provider first and failed later
52 ** (4) Succeed in StrandSimAgentMgr and get unsubscribed or cancelled
53 ** - Simulate succeed in provider and get unsubscribed or cancelled
54 **
55 **==============================================================================
56 */
57 typedef struct _SimAgentMgrResponse
58 {
59 MI_Result mrHandleRequest; /* result from _UT_HandleRequest */
60 MI_Result mrResponseFirst; /* first result from StrandSimAgentMgr */
61 MI_Result mrResponseSecond; /* second result from StrandSimAgentMgr */
62 MI_Uint32 muIndicationMsg; /* number of indications to send before terminate */
63 MI_Uint32 muIndicationMsgSent; /* number of indications already sent before terminate */
64 krisbash 1.1 MI_Uint32 muResponseMsgSent; /* number of response msg already sent before terminate, 0 or 1 */
65 MI_Uint32 muResultMsgSent; /* number of result msg already sent before terminate, has to be 1 */
66
67 MI_Boolean mbMessagesSent; /* whether all message sent*/
68
69 MI_Boolean mbOccupied; /* indicate whether this object was used or not */
70 /* _UT_HandleRequest relies on this field to allocate */
71 /* one object for each StrandSimAgentMgr */
72 }SimAgentMgrResponse;
73
74
75 /*
76 **==============================================================================
77 **
78 ** Release message list
79 **
80 **==============================================================================
81 */
82 void MessageList_Release(_In_opt_ Message*head)
83 {
84 Message* msg = head;
85 krisbash 1.1 while(msg)
86 {
87 Message* msgToRelease = msg;
88 msg = msg->next;
89 Message_Release(msgToRelease);
90 }
91 }
92
93 /*
94 **==============================================================================
95 **
96 ** Strand structure simulates protocols, verify the behavior of IndicationManager
97 **
98 **==============================================================================
99 */
100 typedef struct _StrandProtocol
101 {
102 Strand strand;
103
104 size_t nPost; /* Number of post call */
105 Message* postedMsgList; /* List of posted messages */
106 krisbash 1.1
107 size_t nAck;
108 size_t nCancel;
109 size_t nFinished;
110
111 }StrandProtocol;
112
113 /* Reset StrandProtocol object */
114 void StrandProtocol_Reset(_Inout_ Strand* self)
115 {
116 StrandProtocol* sp = (StrandProtocol*)self;
117 MessageList_Release(sp->postedMsgList);
118 sp->postedMsgList = NULL;
119 sp->nAck = 0;
120 sp->nCancel = 0;
121 sp->nFinished = 0;
122 sp->nPost = 0;
123 }
124
125 /* Finalize StrandProtocol object */
126 void StrandProtocol_Finalize(_Inout_ Strand* self)
127 krisbash 1.1 {
128 StrandProtocol_Reset(self);
129 }
130
131 NITS_EXTERN_C void _StrandProtocol_Post(_In_ Strand* self, _In_ Message* msg)
132 {
133 StrandProtocol* sp = (StrandProtocol*)self;
134 trace_StrandProtocol_Post(self, msg, MessageName(msg->tag));
135
136 ++sp->nPost;
137
138 /* Add reference to Message */
139 Message_AddRef(msg);
140
141 /* Insert message into list */
142 msg->next = sp->postedMsgList;
143 sp->postedMsgList = msg;
144
145 /* Ack to indicaiton manager */
146 Strand_Ack(self);
147
148 krisbash 1.1 if (msg->tag == PostResultMsgTag)
149 {
150 /* Final message, close protocol strand */
151 Strand_Close(self);
152 trace_StrandProtocol_Post_ClosedSelf(self);
153 }
154
155 trace_StrandProtocol_Post_Total(self, msg, MessageName(msg->tag), sp->nPost);
156 }
157
158 NITS_EXTERN_C void _StrandProtocol_PostControl(_In_ Strand* self, _In_ Message* msg)
159 {
160 /* Not used now */
161 NitsAssert(PAL_FALSE, PAL_T("_StrandProtocol_PostControl should not be called"));
162 }
163
164 NITS_EXTERN_C void _StrandProtocol_Ack(_In_ Strand* self)
165 {
166 StrandProtocol* sp = (StrandProtocol*)self;
167 ++sp->nAck;
168
169 krisbash 1.1 trace_StrandProtocol_Ack(self, sp->nAck);
170 }
171
172 NITS_EXTERN_C void _StrandProtocol_Cancel(_In_ Strand* self)
173 {
174 StrandProtocol* sp = (StrandProtocol*)self;
175 ++sp->nCancel;
176
177 trace_StrandProtocol_Cancel(self, sp->nCancel);
178 }
179
180 NITS_EXTERN_C void _StrandProtocol_Finished( _In_ Strand* self)
181 {
182 StrandProtocol* sp = (StrandProtocol*)self;
183 ++sp->nFinished;
184
185 trace_StrandProtocol_Finished(self, sp->nFinished);
186
187 /* Leave the finalize/delete after validation */
188 /* TestMgr_Subscribe_Unsubscribe_Cancel calls StrandProtocol_Finalize */
189 /* to clean up StrandProtocol */
190 krisbash 1.1 }
191
192 StrandFT _StrandProcotolFT1 = {
193 _StrandProtocol_Post,
194 _StrandProtocol_PostControl,
195 _StrandProtocol_Ack,
196 _StrandProtocol_Cancel,
197 NULL,
198 _StrandProtocol_Finished,
199 NULL,
200 NULL,
201 NULL,
202 NULL,
203 NULL,
204 NULL};
205
206 /*
207 **==============================================================================
208 **
209 ** Strand structure simulates AgentMgr, verify the behavior of IndicationManager
210 **
211 krisbash 1.1 **==============================================================================
212 */
213 typedef struct _StrandSimAgentMgr
214 {
215 Strand strand;
216 Message* msg;
217 size_t nAck;
218 size_t nCancel;
219 size_t nFinished;
220
221 /* do not release the object */
222 SimAgentMgrResponse* response;
223
224 }StrandSimAgentMgr;
225
226 /* Reset StrandProtocol object */
227 void StrandStrandSimAgentMgr_Reset(_Inout_ Strand* self)
228 {
229 StrandSimAgentMgr* ssa = (StrandSimAgentMgr*)self;
230 Message_Release(ssa->msg);
231 ssa->msg = NULL;
232 krisbash 1.1 ssa->nAck = 0;
233 ssa->nCancel = 0;
234 ssa->nFinished = 0;
235 }
236
237 /* Finalize StrandProtocol object */
238 void StrandStrandSimAgentMgr_Finalize(_Inout_ Strand* self)
239 {
240 StrandStrandSimAgentMgr_Reset(self);
241 }
242
243 NITS_EXTERN_C void _StrandSimAgentMgr_Post(_In_ Strand* self, _In_ Message* msg)
244 {
245 /* Not used now */
246 NitsAssert(PAL_FALSE, PAL_T("_StrandSimAgentMgr_Post should not be called"));
247 }
248
249 NITS_EXTERN_C void _StrandSimAgentMgr_PostControl(_In_ Strand* self, _In_ Message* msg)
250 {
251 /* Not used now */
252 NitsAssert(PAL_FALSE, PAL_T("_StrandSimAgentMgr_PostControl should not be called"));
253 krisbash 1.1 }
254
255 NITS_EXTERN_C void _StrandSimAgentMgr_Ack(_In_ Strand* self)
256 {
257 StrandSimAgentMgr* ssa = (StrandSimAgentMgr*)self;
258 ++ssa->nAck;
259
260 trace_StrandSimAgentMgr_Ack(self, ssa->nAck);
261
262 NitsAssert(NULL != ssa->response, PAL_T("Response object should NOT be NULL"));
263 if (NULL == ssa->response)
264 {
265 /* Close self */
266 Strand_Close(self);
267 trace_StrandSimAgentMgr_AckCloseSelf(self, ssa->nAck);
268 return;
269 }
270
271 /* Stop posting message if first result is not OK, since first message is the final message */
272 if (ssa->response->mrResponseFirst != MI_RESULT_OK)
273 {
274 krisbash 1.1 trace_StrandSimAgentMgr_AckStopByDesign(self, ssa->nAck);
275
276 /* Last Message Close self */
277 Strand_Close(self);
278 trace_StrandSimAgentMgr_AckCloseSelf(self, ssa->nAck);
279 return;
280 }
281
282 /* Stop posting message if all messages were sent */
283 if (ssa->response->mbMessagesSent == MI_TRUE)
284 {
285 trace_StrandSimAgentMgr_AckStopAllSent(self, ssa->nAck);
286
287 /* Last Message Close self */
288 Strand_Close(self);
289 trace_StrandSimAgentMgr_AckCloseSelf(self, ssa->nAck);
290 return;
291 }
292
293 if (ssa->response->muIndicationMsgSent < ssa->response->muIndicationMsg)
294 {
295 krisbash 1.1 /* Post indication message */
296 PostIndicationMsg * res = PostIndicationMsg_New(0);
297 NitsAssert(NULL != res, PAL_T("Failed to create PostIndicationMsg"));
298 if (res)
299 {
300 /* TODO: to post real instance */
301 res->base.instance = (MI_Instance*)(0x12345678);
302 res->machineID = PAL_T("LOCALHOST");
303 res->bookmark = PAL_T("2013010101:010101:123");
304 trace_StrandSimAgentMgr_AckPostIndication(self, &res->base.base);
305 Strand_Post(self, &res->base.base);
306 Message_Release(&res->base.base);
307 }
308 ssa->response->muIndicationMsgSent++;
309 }
310 else if (ssa->response->mrResponseSecond != MI_RESULT_OK)
311 {
312 /* Post Final Result */
313 PostResultMsg * res = PostResultMsg_New(0);
314 NitsAssert(NULL != res, PAL_T("Failed to create PostResultMsg"));
315 if (res)
316 krisbash 1.1 {
317 res->result = ssa->response->mrResponseSecond;
318 trace_StrandSimAgentMgr_AckPostFinal(self, &res->base);
319 Strand_Post(self, &res->base);
320 Message_Release(&res->base);
321 ssa->response->muResultMsgSent ++;
322 }
323 ssa->response->mbMessagesSent = MI_TRUE;
324 }
325 // else if (ssa->response->mrResponseSecond == MI_RESULT_OK)
326 // post final result in _StrandSimAgentMgr_Cancel
327 }
328
329 NITS_EXTERN_C void _StrandSimAgentMgr_Cancel(_In_ Strand* self)
330 {
331 StrandSimAgentMgr* ssa = (StrandSimAgentMgr*)self;
332 ++ssa->nCancel;
333
334 trace_StrandSimAgentMgr_Cancel(self, ssa->nCancel);
335
336 /* Post Final Result */
337 krisbash 1.1 PostResultMsg * res = PostResultMsg_New(0);
338 NitsAssert(NULL != res, PAL_T("Failed to create PostResultMsg"));
339 if (res)
340 {
341 res->result = ssa->response->mrResponseSecond;
342 trace_StrandSimAgentMgr_CancelFinalMessage(self, &res->base);
343 Strand_Post(self, &res->base);
344 Message_Release(&res->base);
345 ssa->response->muResultMsgSent ++;
346 }
347 ssa->response->mbMessagesSent = MI_TRUE;
348 }
349
350 NITS_EXTERN_C void _StrandSimAgentMgr_Finished( _In_ Strand* self)
351 {
352 StrandSimAgentMgr* ssa = (StrandSimAgentMgr*)self;
353 ++ssa->nFinished;
354
355 trace_StrandSimAgentMgr_Finished(self, ssa->nFinished);
356
357 /* TestMgr_Subscribe_Unsubscribe_Cancel calls StrandSimAgentMgrList_Finalize */
358 krisbash 1.1 /* to clean up all StrandSimAgentMgr(s) */
359 }
360
361 StrandFT _StrandSimAgentMgrFT1 = {
362 _StrandSimAgentMgr_Post,
363 _StrandSimAgentMgr_PostControl,
364 _StrandSimAgentMgr_Ack,
365 _StrandSimAgentMgr_Cancel,
366 NULL,
367 _StrandSimAgentMgr_Finished,
368 NULL,
369 NULL,
370 NULL,
371 NULL,
372 NULL,
373 NULL};
374
375 STRAND_DEBUGNAME(StrandProtocol);
376 STRAND_DEBUGNAME(StrandSimAgentMgr);
377
378 /*
379 krisbash 1.1 **==============================================================================
380 **
381 ** Links all StrandSimAgentMgr object created for one test case,
382 ** verification of each test case needs to iterate through all
383 ** objects
384 **
385 **==============================================================================
386 */
387 typedef struct _StrandSimAgentMgrItem StrandSimAgentMgrItem;
388 struct _StrandSimAgentMgrItem
389 {
390 StrandSimAgentMgr* ssa;
391 StrandSimAgentMgrItem* next;
392 };
393
394 typedef struct _StrandSimAgentMgrList
395 {
396 Batch* batch;
397 StrandSimAgentMgrItem* head;
398 }StrandSimAgentMgrList;
399
400 krisbash 1.1
401 /*
402 **==============================================================================
403 **
404 ** Defines structure to hold response object and expected results
405 **
406 **==============================================================================
407 */
408 typedef struct _ResponseAndExpectedResult
409 {
410 /* Call subscribe or cancel to terminate the subscription */
411 MI_Boolean callUnsubscribe;
412 MI_Boolean protocolFinishedBeforeUnsubscribe;
413
414 /* Responses from agent mgr */
415 _Field_size_(samResponseSize) SimAgentMgrResponse* samResponse;
416 MI_Uint32 samResponseSize;
417
418 /* Expected results */
419 MI_Uint32 muPostResultMsg;
420 MI_Uint32 muPostResponseMsg;
421 krisbash 1.1 MI_Result mrFinalResult;
422 MI_Uint32 muPostIndicationMsg;
423 MI_Uint32 muClassCount; /* number of classes were handled */
424 MI_Boolean hasLastErrordetails; /* Has error details instance */
425 }ResponseAndExpectedResult;
426
427 /*
428 **==============================================================================
429 **
430 ** Test_IndiMgrStruct contains objects required for running all test cases
431 ** within current file
432 **
433 **==============================================================================
434 */
435 struct Test_IndiMgrStruct
436 {
437 /* Properties do NOT need to be cleaned up */
438 MI_ConstString query;
439 MI_ConstString queryDialect;
440 MI_ConstString nameSpace;
441 IndicationHost host;
442 krisbash 1.1 StringTagElement* ste;
443 MI_Uint32 steCount;
444
445 /* Objects requires to be cleaned up */
446 IndicationManager* _indimgr;
447 Filter* _filter;
448 Listener* _listener;
449 Subscription* _subscrip;
450
451 /* Objects may need clean up */
452 MI_Boolean provregInited;
453 ProvReg provreg;
454 MI_Uint32 subid;
455
456 /* StrandSimAgentMgr List */
457 StrandSimAgentMgrList ssalist;
458
459 /* Response and expected result */
460 ResponseAndExpectedResult rar;
461
462 /* Copy of ste */
463 krisbash 1.1 StringTagElement* stecopy;
464 };
465
466 int StrandSimAgentMgrList_Initialize(_Out_ StrandSimAgentMgrList* list)
467 {
468 list->head = NULL;
469 list->batch = Batch_New(64);
470 return (list->batch == NULL) ? -1 : 0;
471 }
472
473 void StrandSimAgentMgrList_Finalize(_Inout_ StrandSimAgentMgrList* list)
474 {
475 StrandSimAgentMgrItem* item = list->head;
476 while (item)
477 {
478 if (item->ssa)
479 {
480 StrandStrandSimAgentMgr_Finalize(&item->ssa->strand);
481 Strand_Delete(&item->ssa->strand);
482 item->ssa = NULL;
483 }
484 krisbash 1.1 item = item->next;
485 }
486 if (list->batch)
487 {
488 Batch_Delete(list->batch);
489 list->batch = NULL;
490 }
491 }
492
493 int StrandSimAgentMgrList_AddItem(_Inout_ StrandSimAgentMgrList* list,
494 _In_ StrandSimAgentMgr* ssa)
495 {
496 if (!list->batch)
497 return -1;
498 StrandSimAgentMgrItem* item = (StrandSimAgentMgrItem*)Batch_Get(
499 list->batch, sizeof(StrandSimAgentMgrItem));
500 if (!item)
501 return -1;
502 item->next = list->head;
503 item->ssa = ssa;
504 list->head = item;
505 krisbash 1.1 return 0;
506 }
507
508 MI_EXTERN_C void _UT_HandleRequest_NOOP(
509 _In_ void* context,
510 _Inout_ InteractionOpenParams* interactionParams,
511 _In_ const ProvRegEntry* proventry)
512 {
513 MI_UNREFERENCED_PARAMETER(context);
514 MI_UNREFERENCED_PARAMETER(interactionParams);
515 MI_UNREFERENCED_PARAMETER(proventry);
516 }
517
518 /*
519 **==============================================================================
520 **
521 ** Setup function, it is called before running each test case
522 ** NOTE: for "nits -fault" run, this function will be called once and only once
523 ** for each test case.
524 **
525 **==============================================================================
526 krisbash 1.1 */
527 NitsSetup0(TestMgr_Setup, Test_IndiMgrStruct)
528
529 Test_IndiMgrStruct* tis = NitsContext()->_Test_IndiMgrStruct;
530 tis->provregInited = MI_FALSE;
531 memset(&tis->provreg, 0, sizeof(ProvReg));
532 tis->subid = 0;
533
534 /* Setup the context pointer */
535 tis->host.context = (void*)tis;
536 IndicationManager* indimgr = IndiMgr_New(&tis->host);
537 NitsAssert(indimgr != NULL, PAL_T("Failed to create indication manager"));
538 if (indimgr == NULL)
539 NitsReturn;
540 tis->_indimgr = indimgr;
541
542 Filter* filter = Filter_New(
543 tis->query,
544 tis->queryDialect,
545 NULL);
546 NitsAssert( NULL != filter, PAL_T("Failed to create filter"));
547 krisbash 1.1 if (NULL == filter)
548 NitsReturn;
549 tis->_filter = filter;
550
551 Listener* listener = Listener_New(LISTENER_TEMP);
552 NitsAssert( NULL != listener, PAL_T("Failed to create listener"));
553 if (NULL == listener)
554 NitsReturn;
555 tis->_listener = listener;
556
557 tis->_subscrip = Subscription_New((FilterBase*)
558 tis->_filter,
559 tis->_listener);
560 NitsAssert( NULL != tis->_subscrip, PAL_T("Failed to create subscription"));
561
562 memset(&tis->rar, 0, sizeof(ResponseAndExpectedResult));
563
564 /* setup stecopy memory */
565 if ((NULL != tis->ste) && (tis->steCount > 0))
566 {
567 tis->stecopy = (StringTagElement*)PAL_Malloc(tis->steCount * sizeof(StringTagElement));
568 krisbash 1.1 NitsAssert( NULL != tis->stecopy, PAL_T("Failed to create stecopy"));
569 }
570 NitsEndSetup
571
572 /*
573 **==============================================================================
574 **
575 ** Cleanup function, it is called after run each test case
576 ** NOTE: for "nits -fault" run, this function will be called once and only once
577 ** for each test case.
578 **
579 **==============================================================================
580 */
581 NitsCleanup(TestMgr_Setup)
582
583 Test_IndiMgrStruct* tis = NitsContext()->_Test_IndiMgrStruct;
584 if (tis->_indimgr)
585 {
586 IndiMgr_Shutdown(tis->_indimgr);
587 tis->_indimgr = NULL;
588 }
589 krisbash 1.1 if (tis->_filter)
590 {
591 Filter_Release(tis->_filter);
592 tis->_filter = NULL;
593 }
594 if (tis->_listener)
595 {
596 Listener_Release(tis->_listener);
597 tis->_listener = NULL;
598 }
599 if (tis->_subscrip)
600 {
601 Subscription_Release(tis->_subscrip);
602 tis->_subscrip = NULL;
603 }
604 if (MI_TRUE == tis->provregInited)
605 {
606 ProvReg_Destroy(&tis->provreg);
607 tis->provregInited = MI_FALSE;
608 memset(&tis->provreg, 0, sizeof(ProvReg));
609 }
610 krisbash 1.1 memset(&tis->rar, 0, sizeof(ResponseAndExpectedResult));
611 if (tis->stecopy)
612 {
613 PAL_Free(tis->stecopy);
614 }
615 NitsEndCleanup
616
617 MI_EXTERN_C ProvReg* _UT_GetProvReg(_In_ void* context)
618 {
619 Test_IndiMgrStruct* ims = (Test_IndiMgrStruct*)context;
620 string root = OMI_GetPath(ID_PREFIX);
621 string omiregdir = root + "/tests/provreg/omiregister";
622 /* This function might be called >1 times during one unit test fault injection run */
623 /* So we need to clean up the provreg object if already initialized */
624 if (MI_TRUE == ims->provregInited)
625 {
626 ProvReg_Destroy(&ims->provreg);
627 ims->provregInited = MI_FALSE;
628 }
629 MI_Result r = ProvReg_Init(&ims->provreg, omiregdir.c_str());
630 NitsAssert(r == MI_RESULT_OK, PAL_T("Failed to initialize ProgReg"));
631 krisbash 1.1 ims->provregInited = (r == MI_RESULT_OK) ? MI_TRUE : MI_FALSE;
632 return (r == MI_RESULT_OK) ? &ims->provreg : NULL;
633 }
634
635 static struct Test_IndiMgrStruct sTestIM1 = {
636 MI_T("select * from CIM_Indication"),
637 QUERY_LANGUAGE_WQL,
638 MI_T("root/indication"),
639 {
640 _UT_GetProvReg,
641 _UT_HandleRequest_NOOP,
642 NULL,
643 },
644 NULL,
645 0,
646 NULL,
647 NULL,
648 NULL,
649 NULL};
650
651 NitsTest1(TestMgr_AddRemoveFilter, TestMgr_Setup, sTestIM1)
652 krisbash 1.1 NitsFaultSimMarkForRerun;
653
654 Filter* filter = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_filter;
655 IndicationManager* indimgr = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_indimgr;
656 int refFilter = Filter_GetRefcount(filter);
657 NitsAssert( NULL == filter->base.base.identifier, PAL_T("filter identifier has to be NULL"));
658
659 int r = IndiMgr_AddFilter(indimgr, (FilterBase*)filter);
660 NitsAssert( r == 0, PAL_T("failed to add filter to indication manager"));
661 if (r == 0)
662 {
663 NitsAssert( Filter_GetRefcount(filter) == (refFilter+1), PAL_T("filter has wrong ref count"));
664
665 int c = Tcsncasecmp(filter->base.base.identifier, TEMP_FILTER_ID_PREFIX, MI_COUNT(TEMP_FILTER_ID_PREFIX)-1);
666 NitsAssert( c == 0 , PAL_T("filter has wrong identifier"));
667
668 r = IndiMgr_RemoveFilter(indimgr, (FilterBase*)filter);
669 NitsAssert( r == 0 , PAL_T("failed to remove filter from indication manager"));
670
671 NitsAssert( Filter_GetRefcount(filter) == refFilter, PAL_T("filter has wrong ref count"));
672 }
673 krisbash 1.1
674 NitsEndTest
675
676 NitsTest1(TestMgr_AddRemoveListener, TestMgr_Setup, sTestIM1)
677
678 NitsFaultSimMarkForRerun;
679 Listener* listener = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_listener;
680 IndicationManager* indimgr = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_indimgr;
681
682 int ref = Listener_GetRefcount(listener);
683
684 NitsAssert( NULL == listener->base.identifier, PAL_T("listener identifier has to be NULL"));
685
686 int r = IndiMgr_AddListener(indimgr, listener);
687 NitsAssert( r == 0, PAL_T("Failed to add listener to indication manager"));
688 if (r == 0)
689 {
690 NitsAssert(Listener_GetRefcount(listener) == (ref+1), PAL_T("listener has wrong ref count"));
691
692 int c = Tcsncasecmp(listener->base.identifier, TEMP_LISTENER_ID_PREFIX, MI_COUNT(TEMP_LISTENER_ID_PREFIX)-1);
693 NitsAssert( c == 0, PAL_T("listener has wrong identifier"));
694 krisbash 1.1
695 r = IndiMgr_RemoveListener(indimgr, listener);
696 NitsAssert( r == 0, PAL_T("Failed to remove listener from indication manager"));
697
698 NitsAssert( Listener_GetRefcount(listener) == ref, PAL_T("listener has wrong ref count"));
699 }
700
701 NitsEndTest
702
703 NitsTest1(TestMgr_AddRemoveSubscription, TestMgr_Setup, sTestIM1)
704 NitsFaultSimMarkForRerun;
705
706 // Disable Nits Fault injection here, beacuse in RegFile_New function (Called internally in ProvReg_Init) will
707 // return NULL in both cases Failure OR failed to allocate. And Nits doesn't like that.
708 NitsDisableFaultSim;
709
710 Filter* filter = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_filter;
711 Listener* listener = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_listener;
712 Subscription* sub = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_subscrip;
713 IndicationManager* indimgr = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->_indimgr;
714 int ref = Subscription_GetRefcount(sub);
715 krisbash 1.1 int refFilter = Filter_GetRefcount(filter);
716 int refListener = Listener_GetRefcount(listener);
717
718 {
719 MI_StringA nsa;
720 MI_Char* ns;
721 nsa.size = 1;
722 ns = (MI_Char*)NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct->nameSpace;
723 nsa.data = &ns;
724 if (Filter_SetNamespace(filter, &nsa) != 0)
725 {
726 NitsAssert(0, PAL_T("Set namespace failed"));
727 NitsReturn;
728 }
729 }
730
731 NitsAssert( NULL == sub->base.identifier, PAL_T("Subscription identifier has to be NULL"));
732 sub->subscriptionID = 1;
733 int r = IndiMgr_AddSubscription(indimgr, sub);
734 NitsAssert( r == 0, PAL_T("Failed to add subscription to indication manager"));
735 if (r == 0)
736 krisbash 1.1 {
737 NitsAssert( Subscription_GetRefcount(sub) == (ref+1), PAL_T("Subscription object has wrong ref count"));
738 NitsAssert( Filter_GetRefcount(filter) == (refFilter+1), PAL_T("filter object has wrong ref count"));
739 NitsAssert( Listener_GetRefcount(listener) == (refListener+1), PAL_T("listener object has wrong ref count"));
740
741 int c = Tcsncasecmp(sub->base.identifier, TEMP_SUBSCRIPTION_ID_PREFIX, MI_COUNT(TEMP_SUBSCRIPTION_ID_PREFIX)-1);
742 NitsAssert( c == 0, PAL_T("subscription object has wrong identifier"));
743
744 r = IndiMgr_RemoveSubscription(indimgr, sub);
745 NitsAssert( r == 0, PAL_T("Failed to remove subscription from indication manager"));
746
747 NitsAssert( Subscription_GetRefcount(sub) == ref, PAL_T("subscription object has wrong ref count"));
748 NitsAssert( Filter_GetRefcount(filter) == refFilter, PAL_T("filter object has wrong ref count"));
749 NitsAssert( Listener_GetRefcount(listener) == refListener, PAL_T("listener object has wrong ref count"));
750 }
751
752 NitsEndTest
753
754
755 MI_EXTERN_C void _UT_HandleRequest(
756 _In_ void* context,
757 krisbash 1.1 _Inout_ InteractionOpenParams* interactionParams,
758 _In_ const ProvRegEntry* proventry)
759 {
760 trace_UT_HandleRequest(context, interactionParams->msg, MessageName(interactionParams->msg->tag), interactionParams->interaction);
761
762 Test_IndiMgrStruct* tts = (Test_IndiMgrStruct*)context;
763 SimAgentMgrResponse* response = NULL;
764
765 /* Find response object */
766 MI_Uint32 i = 0;
767 for (; i < tts->rar.samResponseSize; i ++)
768 {
769 if (tts->rar.samResponse[i].mbOccupied == MI_FALSE)
770 {
771 tts->rar.samResponse[i].mbOccupied = MI_TRUE;
772 response = &tts->rar.samResponse[i];
773 break;
774 }
775 }
776 if ( i == tts->rar.samResponseSize)
777 {
778 krisbash 1.1 NitsAssert(false, PAL_T("Failed to find response object for StrandSimAgentMgr"));
779 Strand_FailOpen(interactionParams);
780 return;
781 }
782
783 /* Return error code if handle request failed */
784 if (response->mrHandleRequest != MI_RESULT_OK)
785 {
786 /* Terminate the operation if failed in HandleRequest */
787 trace_UT_HandleRequestFailed(
788 context, interactionParams->msg, MessageName(interactionParams->msg->tag), interactionParams->interaction, response->mrHandleRequest);
789 Strand_FailOpenWithResult(interactionParams,response->mrHandleRequest, PostResultMsg_NewAndSerialize);
790 return;
791 }
792
793 /* Handle subscribe request */
794 StrandSimAgentMgr* ssa = (StrandSimAgentMgr*)Strand_New(
795 STRAND_DEBUG(StrandSimAgentMgr)
796 &_StrandSimAgentMgrFT1,
797 sizeof(StrandSimAgentMgr),
798 0,
799 krisbash 1.1 interactionParams);
800 NitsAssert( NULL != ssa, PAL_T("Failed to create StrandSimAgentMgr"));
801 if (NULL == ssa)
802 {
803 Strand_FailOpenWithResult(interactionParams,MI_RESULT_SERVER_LIMITS_EXCEEDED, PostResultMsg_NewAndSerialize);
804 return;
805 }
806
807 /* Attach response */
808 ssa->response = response;
809
810 /* Add agentmgr to list */
811 int r = StrandSimAgentMgrList_AddItem(&tts->ssalist, ssa);
812 NitsAssert(r == 0, PAL_T("_UT_HandleRequest: Add StrandSimAgentMgr to list failed"));
813
814 /* Attach message */
815 Message_AddRef(interactionParams->msg);
816 ssa->msg = interactionParams->msg;
817
818 /* Ack to indication that this Strand opened */
819 Strand_ScheduleAck(&ssa->strand);
820 krisbash 1.1
821 switch(interactionParams->msg->tag)
822 {
823 case SubscribeReqTag:
824 /* Post result message based on response object */
825 {
826 if (ssa->response->mrResponseFirst != MI_RESULT_OK)
827 {
828 PostResultMsg * res = PostResultMsg_New(interactionParams->msg->operationId);
829 NitsAssert(NULL != res, PAL_T("Failed to create PostResultMsg message"));
830 if (!res)
831 {
832 Strand_FailOpenWithResult(interactionParams,MI_RESULT_SERVER_LIMITS_EXCEEDED, PostResultMsg_NewAndSerialize);
833 return;
834 }
835
836 res->result = ssa->response->mrResponseFirst;
837 ssa->response->muResultMsgSent ++;
838 Strand_SchedulePost(&ssa->strand, &res->base);
839 Message_Release(&res->base);
840 }
841 krisbash 1.1 else
842 {
843 SubscribeRes * res = SubscribeRes_New(interactionParams->msg->operationId);
844 NitsAssert(NULL != res, PAL_T("Failed to create PostResultMsg message"));
845 if (!res)
846 {
847 Strand_FailOpenWithResult(interactionParams,MI_RESULT_SERVER_LIMITS_EXCEEDED, PostResultMsg_NewAndSerialize);
848 return;
849 }
850 ssa->response->muResponseMsgSent ++;
851 Strand_SchedulePost(&ssa->strand, &res->base);
852 Message_Release(&res->base);
853 }
854 }
855 break;
856 default:
857 NitsAssert(PAL_FALSE, PAL_T("_UT_HandleRequest: Unrecognized message"));
858 Strand_FailOpenWithResult(interactionParams,MI_RESULT_FAILED, PostResultMsg_NewAndSerialize);
859 return;
860 }
861 }
862 krisbash 1.1
863 /*
864 **==============================================================================
865 ** Target indication classes list referred by following test cases
866 **==============================================================================
867 */
868 const MI_Uint32 cClassCount = 5;
869 static StringTagElement _IndicationClassList[cClassCount] =
870 {
871 { MI_T("XYZ_Indication"),0 , (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
872 { MI_T("XYZ_ChildIndication1"),0 , (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
873 { MI_T("XYZ_ChildIndication2"),0 , (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
874 { MI_T("XYZ_ChildIndication3"),0 , (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
875 { MI_T("XYZ_ChildIndication4"),0 , (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
876 };
877
878
879 static struct Test_IndiMgrStruct sTestIM2 = {
880 MI_T("select * from CIM_Indication"),
881 QUERY_LANGUAGE_WQL,
882 MI_T("root/indication"),
883 krisbash 1.1 {
884 _UT_GetProvReg,
885 _UT_HandleRequest,
886 NULL,
887 },
888 _IndicationClassList,
889 cClassCount,
890 NULL,
891 NULL,
892 NULL,
893 NULL};
894
895 /*
896 **==============================================================================
897 **
898 ** Helper functions to validate indication manager can handle subscribe request,
899 ** unsubscribe request and cancel operation correctly;
900 **
901 **==============================================================================
902 */
903 void TestMgr_Subscribe_Unsubscribe_Cancel(_In_ Test_IndiMgrStruct* tts)
904 krisbash 1.1 {
905 /*Log_OpenStdErr();
906 Log_SetLevel(LOG_VERBOSE);*/
907
908 StrandProtocol* sp = (StrandProtocol*)Strand_New(
909 STRAND_DEBUG(StrandProtocol)
910 &_StrandProcotolFT1,
911 sizeof(StrandProtocol),
912 STRAND_FLAG_ENTERSTRAND,
913 NULL);
914
915 NitsAssert( NULL != sp, PAL_T("Failed to create StrandProtocol"));
916 if (NULL == sp)
917 return;
918
919 IndicationManager* indimgr = tts->_indimgr;
920 const MI_Uint64 subscriptionID = ++(tts->subid);
921 MI_ConstString ns = tts->nameSpace;
922 MI_ConstString cn = NULL;
923 MI_ConstString qry = tts->query;
924 MI_ConstString lang = tts->queryDialect;
925 krisbash 1.1
926 /* Copy _IndicationClassList to classlist */
927 memcpy(tts->stecopy, tts->ste, tts->steCount * sizeof(StringTagElement));
928
929 int ssalisInited = StrandSimAgentMgrList_Initialize(&tts->ssalist);
930 NitsAssert(0 == ssalisInited, PAL_T("Failed to StrandSimAgentMgrList_Initialize"));
931 if (0 != ssalisInited)
932 {
933 Strand_Leave( &sp->strand );
934 goto Done;
935 }
936
937 /* Post subscribe message to indication manager*/
938 {
939 SubscribeReq* msg = SubscribeReq_New(0, 0);
940 NitsAssert(NULL != msg, PAL_T("Failed to create SubscribeReq message"));
941 if (!msg)
942 {
943 Strand_Leave( &sp->strand );
944 goto Done;
945 }
946 krisbash 1.1
947 msg->nameSpace = ns;
948 msg->filter = qry;
949 msg->language = lang;
950 msg->className = cn; /* Optional for indication manager */
951 msg->targetType = (MI_Uint32)SUBSCRIP_TARGET_DEFAULT; /* Optional for indication manager */
952 msg->subscriptionID = subscriptionID;
953
954 Strand_Open(&sp->strand,IndiMgr_HandleSubscribeReq,indimgr,&msg->base.base,MI_TRUE);
955 Message_Release(&msg->base.base);
956 }
957
958 if (MI_FALSE == tts->rar.protocolFinishedBeforeUnsubscribe)
959 {
960 /* Post unsubscribe request */
961 if (tts->rar.callUnsubscribe == MI_TRUE)
962 {
963 trace_TestMgr_Subscribe_Unsubscribe_Cancel_Unsubscribe();
964
965 UnsubscribeReq* msg = UnsubscribeReq_New(0, 0);
966 NitsAssert(NULL != msg, PAL_T("Failed to create SubscribeReq message"));
967 krisbash 1.1 if (!msg)
968 goto Done;
969
970 Strand_SchedulePost(&sp->strand, &msg->base.base);
971 Message_Release(&msg->base.base);
972 }
973 /* Cancel the subscription */
974 else
975 {
976 trace_TestMgr_Subscribe_Unsubscribe_Cancel_Cancel();
977
978 Strand_ScheduleCancel(&sp->strand);
979 }
980 }
981
982 /* Verify protocol side has correct state */
983 {
984 /* Verify protocol state */
985 NitsCompare(1, sp->nFinished, PAL_T("Expect protocol was closed/finished"));
986
987 /* Verify messages sent by indication manager */
988 krisbash 1.1 {
989 MI_Uint32 nMsgCount = tts->rar.muPostResultMsg + tts->rar.muPostResponseMsg + tts->rar.muPostIndicationMsg;
990 NitsCompare(nMsgCount, sp->nPost, PAL_T("StrandProtocol received wrong number of messages"));
991 NitsAssert(NULL != sp->postedMsgList, PAL_T("StrandProtocol got no messages"));
992
993 Message* msg = sp->postedMsgList;
994 MI_Uint32 resultMsgCount = 0;
995 MI_Uint32 responseMsgCount = 0;
996 MI_Uint32 indMsgCount = 0;
997 MI_Result finalResult = MI_RESULT_FAILED;
998 while (msg)
999 {
1000 switch (msg->tag)
1001 {
1002 case PostResultMsgTag:
1003 {
1004 NitsAssert(resultMsgCount == 0, PAL_T("StrandProtocol got more than 1 result message"));
1005 resultMsgCount++;
1006 if (resultMsgCount == 1)
1007 {
1008 /* Final result is the first one in the list */
1009 krisbash 1.1 finalResult = ((PostResultMsg*)msg)->result;
1010 }
1011 }
1012 break;
1013
1014 case SubscribeResTag:
1015 {
1016 NitsAssert(responseMsgCount == 0, PAL_T("StrandProtocol got more than 1 response message"));
1017 responseMsgCount++;
1018 }
1019 break;
1020
1021 case PostIndicationMsgTag:
1022 {
1023 indMsgCount++;
1024 }
1025 break;
1026
1027 default:
1028 NitsAssert(0, PAL_T("StrandProtocol got unexpected message"));
1029 break;
1030 krisbash 1.1 }
1031 msg = msg->next;
1032 }
1033 NitsCompare(tts->rar.muPostResultMsg, resultMsgCount, PAL_T("StrandProtocol received unexpected number of PostResultMsg"));
1034 NitsCompare(tts->rar.muPostResponseMsg, responseMsgCount, PAL_T("StrandProtocol received unexpected number of PostResponseMsg"));
1035 NitsCompare(tts->rar.muPostIndicationMsg, indMsgCount, PAL_T("StrandProtocol received unexpected number of indication messages"));
1036 NitsCompare(tts->rar.mrFinalResult, finalResult, PAL_T("StrandProtocol received unexpected final result value"));
1037 }
1038 /* Cleanup protocol */
1039 StrandProtocol_Reset(&sp->strand);
1040 }
1041
1042 /* Verify agentmgr side has correct state */
1043 {
1044 StrandSimAgentMgrItem* item = tts->ssalist.head;
1045 MI_Uint32 itemCount = 0;
1046 while(item)
1047 {
1048 /* Verify subscribeReq message received by agentmgr */
1049 NitsAssert(NULL != item->ssa->msg, PAL_T("AgentMgr should received SubscribeReq message"));
1050 if (NULL != item->ssa->msg)
1051 krisbash 1.1 {
1052 NitsCompare(SubscribeReqTag, item->ssa->msg->tag, PAL_T("AgentMgr should received SubscribeReq message"));
1053 StringTagElement* e = IsInArrayEx(((SubscribeReq*)item->ssa->msg)->className, tts->stecopy, tts->steCount);
1054 NitsCompare(1, e->tag, PAL_T("Unexpected class count found"));
1055 if (SubscribeReqTag == item->ssa->msg->tag)
1056 {
1057 SubscribeReq* req = (SubscribeReq*)item->ssa->msg;
1058 NitsCompare(req->targetType, e->reserved1, PAL_T("Unexpected target type"));
1059 }
1060 }
1061
1062 /* Verify cancel/finish call to agentmgr */
1063 MI_Uint32 nCancelCount = 0;
1064 MI_Uint32 nFinishCount = 1;
1065 if ((item->ssa->response->mrResponseFirst == MI_RESULT_OK) &&
1066 (item->ssa->response->mrResponseSecond == MI_RESULT_OK))
1067 {
1068 /* agent item get cancelled call if and only if still subscribed */
1069 /* agent item will be closed if failed already */
1070 nCancelCount = 1;
1071 }
1072 krisbash 1.1 NitsCompare(nCancelCount, item->ssa->nCancel, PAL_T("expect agentmgrItem get cancel called once"));
1073 NitsCompare(nFinishCount, item->ssa->nFinished, PAL_T("expect each agentmgrItem get finish called once"));
1074
1075 /* Verify message acked correctly by indication mgr */
1076 MI_Uint32 nMsgCount = item->ssa->response->muIndicationMsgSent +
1077 item->ssa->response->muResponseMsgSent +
1078 item->ssa->response->muResultMsgSent;
1079 NitsCompare(nMsgCount, item->ssa->nAck, PAL_T("wrong number of Ack called on agentmgrItem"));
1080 item = item->next;
1081 itemCount ++;
1082 }
1083 NitsCompare(tts->rar.muClassCount, itemCount, PAL_T("AgentMgr received wrong number of request"));
1084 }
1085
1086 Done:
1087 if (sp)
1088 {
1089 trace_TestMgr_Subscribe_Unsubscribe_Cancel_Schedule(sp);
1090 /* Finalize StrandProtocol */
1091 StrandProtocol_Finalize(&sp->strand);
1092 Strand_Delete(&sp->strand);
1093 krisbash 1.1 }
1094 if (0 == ssalisInited)
1095 {
1096 trace_TestMgr_Subscribe_Unsubscribe_Cancel_FinalizeAgentManagers();
1097 StrandSimAgentMgrList_Finalize(&tts->ssalist);
1098 }
1099 }
1100
1101
1102 /*
1103 **==============================================================================
1104 **
1105 ** For following tests, each test case needs to run twice w.r.t. the
1106 ** termination of the subscription; one by calling unsubscribe, another
1107 ** by calling cancel;
1108 **
1109 ** To avoid the duplicate test code, Unsubscribe structure was introduced to
1110 ** indicate the way of terminating the subscribe operation
1111 **
1112 **==============================================================================
1113 */
1114 krisbash 1.1 struct Unsubscribe_Struct
1115 {
1116 MI_Boolean shouldUnsubscribe;
1117 };
1118
1119 NitsSetup1(Subscription_Unsubscibe, Unsubscribe_Struct, TestMgr_Setup, sTestIM2)
1120 NitsContext()->_Unsubscribe_Struct->shouldUnsubscribe = MI_TRUE;
1121 NitsEndSetup
1122
1123 NitsSetup1(Subscription_Cancel, Unsubscribe_Struct, TestMgr_Setup, sTestIM2)
1124 NitsContext()->_Unsubscribe_Struct->shouldUnsubscribe = MI_FALSE;
1125 NitsEndSetup
1126
1127 NitsSplit2(Subscription_UnsubCancel, Unsubscribe_Struct, Subscription_Unsubscibe, Subscription_Cancel)
1128 NitsEndSplit
1129
1130 /*
1131 **==============================================================================
1132 **
1133 ** Validate subscribe request handled successfully with all classes succeeded
1134 ** and Unsubscribe request can be handled correctly afterwards
1135 krisbash 1.1 **
1136 **==============================================================================
1137 */
1138 NitsTest1(TestMgr_SubscribeAllSuccess_Unsubscribe, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1139 NitsFaultSimMarkForRerun;
1140 NitsDisableFaultSim;
1141
1142 SimAgentMgrResponse responses[cClassCount] = {
1143 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1144 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1145 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1146 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1147 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1148 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1149
1150 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1151 tts->rar.samResponseSize = cClassCount;
1152 tts->rar.samResponse = responses;
1153 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1154 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1155 tts->rar.mrFinalResult = MI_RESULT_OK;
1156 krisbash 1.1 tts->rar.muPostIndicationMsg = 5;
1157 tts->rar.muPostResultMsg = 1;
1158 tts->rar.muPostResponseMsg = 1;
1159 tts->rar.muClassCount = cClassCount;
1160 tts->rar.hasLastErrordetails = MI_FALSE;
1161 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1162
1163 NitsEndTest
1164
1165
1166 /*
1167 **==============================================================================
1168 **
1169 ** Following test case is designed to test the handling of subscribe responses
1170 ** from provider; Say subscription is targeted to X classes, following are
1171 ** all of the possible typical scenarios of Subscribe Responses,
1172 **
1173 ** 2. X response success and Y failed later (1<Y<X)
1174 **
1175 **==============================================================================
1176 */
1177 krisbash 1.1 NitsTest1(TestMgr_HandleSubscribe_Response_AllSuccess_SomeFailedLater, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1178 NitsFaultSimMarkForRerun;
1179 NitsDisableFaultSim;
1180 SimAgentMgrResponse responses[cClassCount] = {
1181 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1182 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1183 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_CANCELED, 2, 0, 0, MI_FALSE, MI_FALSE},
1184 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1185 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_CANCELED, 2, 0, 0, MI_FALSE, MI_FALSE},
1186 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1187
1188 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1189 tts->rar.samResponseSize = cClassCount;
1190 tts->rar.samResponse = responses;
1191 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1192 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1193 tts->rar.mrFinalResult = MI_RESULT_OK;
1194 tts->rar.muPostIndicationMsg = 7;
1195 tts->rar.muPostResultMsg = 1;
1196 tts->rar.muPostResponseMsg = 1;
1197 tts->rar.muClassCount = cClassCount;
1198 krisbash 1.1 tts->rar.hasLastErrordetails = MI_FALSE;
1199 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1200
1201 NitsEndTest
1202
1203 /*
1204 **==============================================================================
1205 **
1206 ** Following test case is designed to test the handling of subscribe responses
1207 ** from provider; Say subscription is targeted to X classes, following are
1208 ** all of the possible typical scenarios of Subscribe Responses,
1209 **
1210 ** 3. X response success and X failed later
1211 **
1212 **==============================================================================
1213 */
1214 NitsTest1(TestMgr_HandleSubscribe_Response_AllSuccess_AllFailedLater, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1215 NitsFaultSimMarkForRerun;
1216 NitsDisableFaultSim;
1217 SimAgentMgrResponse responses[cClassCount] = {
1218 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1219 krisbash 1.1 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 1, 0, 0, MI_FALSE, MI_FALSE},
1220 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_CANCELED, 2, 0, 0, MI_FALSE, MI_FALSE},
1221 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 1, 0, 0, MI_FALSE, MI_FALSE},
1222 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_CANCELED, 2, 0, 0, MI_FALSE, MI_FALSE},
1223 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 1, 0, 0, MI_FALSE, MI_FALSE},};
1224
1225 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1226 tts->rar.samResponseSize = cClassCount;
1227 tts->rar.samResponse = responses;
1228 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1229 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1230 tts->rar.mrFinalResult = MI_RESULT_FAILED;
1231 tts->rar.muPostIndicationMsg = 7;
1232 tts->rar.muPostResultMsg = 1;
1233 tts->rar.muPostResponseMsg = 1;
1234 tts->rar.muClassCount = cClassCount;
1235 tts->rar.hasLastErrordetails = MI_FALSE;
1236 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1237
1238 NitsEndTest
1239
1240 krisbash 1.1 /*
1241 **==============================================================================
1242 **
1243 ** Following test case is designed to test the handling of subscribe responses
1244 ** from provider; Say subscription is targeted to X classes, following are
1245 ** all of the possible typical scenarios of Subscribe Responses,
1246 **
1247 ** 4. M response success (2<M<X)
1248 **
1249 **==============================================================================
1250 */
1251 NitsTest1(TestMgr_HandleSubscribe_Response_SomeSuccess, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1252 NitsFaultSimMarkForRerun;
1253 NitsDisableFaultSim;
1254 SimAgentMgrResponse responses[cClassCount] = {
1255 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1256 {MI_RESULT_OK, MI_RESULT_CANCELED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1257 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1258 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1259 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1260 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1261 krisbash 1.1
1262 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1263 tts->rar.samResponseSize = cClassCount;
1264 tts->rar.samResponse = responses;
1265 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1266 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1267 tts->rar.mrFinalResult = MI_RESULT_OK;
1268 tts->rar.muPostIndicationMsg = 5;
1269 tts->rar.muPostResultMsg = 1;
1270 tts->rar.muPostResponseMsg = 1;
1271 tts->rar.muClassCount = cClassCount;
1272 tts->rar.hasLastErrordetails = MI_FALSE;
1273 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1274
1275 NitsEndTest
1276
1277 /*
1278 **==============================================================================
1279 **
1280 ** Following test case is designed to test the handling of subscribe responses
1281 ** from provider; Say subscription is targeted to X classes, following are
1282 krisbash 1.1 ** all of the possible typical scenarios of Subscribe Responses,
1283 **
1284 ** 5. M response success and N failed later (1<N<M<X)
1285 **
1286 **==============================================================================
1287 */
1288 NitsTest1(TestMgr_HandleSubscribe_Response_SomeSuccess_SomeFailedLater, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1289 NitsFaultSimMarkForRerun;
1290 NitsDisableFaultSim;
1291 SimAgentMgrResponse responses[cClassCount] = {
1292 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1293 {MI_RESULT_OK, MI_RESULT_CANCELED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1294 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 2, 0, 0, MI_FALSE, MI_FALSE},
1295 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1296 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 2, 0, 0, MI_FALSE, MI_FALSE},
1297 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1298
1299 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1300 tts->rar.samResponseSize = cClassCount;
1301 tts->rar.samResponse = responses;
1302 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1303 krisbash 1.1 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1304 tts->rar.mrFinalResult = MI_RESULT_OK;
1305 tts->rar.muPostIndicationMsg = 5;
1306 tts->rar.muPostResultMsg = 1;
1307 tts->rar.muPostResponseMsg = 1;
1308 tts->rar.muClassCount = cClassCount;
1309 tts->rar.hasLastErrordetails = MI_FALSE;
1310 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1311
1312 NitsEndTest
1313
1314 /*
1315 **==============================================================================
1316 **
1317 ** Following test case is designed to test the handling of subscribe responses
1318 ** from provider; Say subscription is targeted to X classes, following are
1319 ** all of the possible typical scenarios of Subscribe Responses,
1320 **
1321 ** 6. M response success and M failed later (2<M<X)
1322 **
1323 **==============================================================================
1324 krisbash 1.1 */
1325 NitsTest1(TestMgr_HandleSubscribe_Response_SomeSuccess_AllFailedLater, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1326 NitsFaultSimMarkForRerun;
1327 NitsDisableFaultSim;
1328 SimAgentMgrResponse responses[cClassCount] = {
1329 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1330 {MI_RESULT_OK, MI_RESULT_CANCELED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1331 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 2, 0, 0, MI_FALSE, MI_FALSE},
1332 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_CANCELED, 1, 0, 0, MI_FALSE, MI_FALSE},
1333 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 2, 0, 0, MI_FALSE, MI_FALSE},
1334 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1335
1336 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1337 tts->rar.samResponseSize = cClassCount;
1338 tts->rar.samResponse = responses;
1339 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1340 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1341 tts->rar.mrFinalResult = MI_RESULT_FAILED;
1342 tts->rar.muPostIndicationMsg = 5;
1343 tts->rar.muPostResultMsg = 1;
1344 tts->rar.muPostResponseMsg = 1;
1345 krisbash 1.1 tts->rar.muClassCount = cClassCount;
1346 tts->rar.hasLastErrordetails = MI_FALSE;
1347 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1348
1349 NitsEndTest
1350
1351 /*
1352 **==============================================================================
1353 **
1354 ** Following test case is designed to test the handling of subscribe responses
1355 ** from provider; Say subscription is targeted to X classes, following are
1356 ** all of the possible typical scenarios of Subscribe Responses,
1357 **
1358 ** 7. 1 response success
1359 **
1360 **==============================================================================
1361 */
1362 NitsTest1(TestMgr_HandleSubscribe_Response_OneSuccess, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1363 NitsDisableFaultSim;
1364 NitsFaultSimMarkForRerun;
1365 SimAgentMgrResponse responses[cClassCount] = {
1366 krisbash 1.1 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1367 {MI_RESULT_OK, MI_RESULT_CANCELED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1368 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1369 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1370 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1371 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1372
1373 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1374 tts->rar.samResponseSize = cClassCount;
1375 tts->rar.samResponse = responses;
1376 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1377 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1378 tts->rar.mrFinalResult = MI_RESULT_OK;
1379 tts->rar.muPostIndicationMsg = 2;
1380 tts->rar.muPostResultMsg = 1;
1381 tts->rar.muPostResponseMsg = 1;
1382 tts->rar.muClassCount = cClassCount;
1383 tts->rar.hasLastErrordetails = MI_FALSE;
1384 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1385
1386 NitsEndTest
1387 krisbash 1.1
1388 /*
1389 **==============================================================================
1390 **
1391 ** Following test case is designed to test the handling of subscribe responses
1392 ** from provider; Say subscription is targeted to X classes, following are
1393 ** all of the possible typical scenarios of Subscribe Responses,
1394 **
1395 ** 8. 1 response success and 1 failed later
1396 **
1397 **==============================================================================
1398 */
1399 NitsTest1(TestMgr_HandleSubscribe_Response_OneSuccess_FailedLater, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1400 NitsFaultSimMarkForRerun;
1401 NitsDisableFaultSim;
1402 SimAgentMgrResponse responses[cClassCount] = {
1403 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1404 {MI_RESULT_OK, MI_RESULT_CANCELED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1405 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 2, 0, 0, MI_FALSE, MI_FALSE},
1406 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1407 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1408 krisbash 1.1 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1409
1410 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1411 tts->rar.samResponseSize = cClassCount;
1412 tts->rar.samResponse = responses;
1413 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1414 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1415 tts->rar.mrFinalResult = MI_RESULT_FAILED;
1416 tts->rar.muPostIndicationMsg = 2;
1417 tts->rar.muPostResultMsg = 1;
1418 tts->rar.muPostResponseMsg = 1;
1419 tts->rar.muClassCount = cClassCount;
1420 tts->rar.hasLastErrordetails = MI_FALSE;
1421 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1422
1423 NitsEndTest
1424
1425 /*
1426 **==============================================================================
1427 **
1428 ** Following test case is designed to test the handling of subscribe responses
1429 krisbash 1.1 ** from provider; Say subscription is targeted to X classes, following are
1430 ** all of the possible typical scenarios of Subscribe Responses,
1431 **
1432 ** 9. X response failed
1433 **
1434 **==============================================================================
1435 */
1436 NitsTest1(TestMgr_HandleSubscribe_Response_AllFailed, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1437 NitsFaultSimMarkForRerun;
1438 NitsDisableFaultSim;
1439 SimAgentMgrResponse responses[cClassCount] = {
1440 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1441 {MI_RESULT_OK, MI_RESULT_CANCELED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1442 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1443 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1444 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1445 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1446
1447 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1448 tts->rar.samResponseSize = cClassCount;
1449 tts->rar.samResponse = responses;
1450 krisbash 1.1 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1451 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1452 tts->rar.mrFinalResult = MI_RESULT_FAILED;
1453 tts->rar.muPostIndicationMsg = 0;
1454 tts->rar.muPostResultMsg = 1;
1455 tts->rar.muPostResponseMsg = 0;
1456 tts->rar.muClassCount = cClassCount;
1457 tts->rar.hasLastErrordetails = MI_FALSE;
1458 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1459
1460 NitsEndTest
1461
1462 /*
1463 **==============================================================================
1464 **
1465 ** Following test case is designed to test the handling of subscribe responses
1466 ** from provider; Say subscription is targeted to X classes, following are
1467 ** all of the possible typical scenarios of Subscribe Responses,
1468 **
1469 ** 10. M handled success; M succeeded from provider;
1470 ** 1<M<X
1471 krisbash 1.1 **
1472 **==============================================================================
1473 */
1474 NitsTest1(TestMgr_HandleSubscribe_Handle_SomeSuccess_Response_AllSuccess, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1475 NitsFaultSimMarkForRerun;
1476 NitsDisableFaultSim;
1477 SimAgentMgrResponse responses[cClassCount] = {
1478 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1479 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1480 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1481 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1482 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1483 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1484
1485 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1486 tts->rar.samResponseSize = cClassCount;
1487 tts->rar.samResponse = responses;
1488 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1489 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1490 tts->rar.mrFinalResult = MI_RESULT_OK;
1491 tts->rar.muPostIndicationMsg = 4;
1492 krisbash 1.1 tts->rar.muPostResultMsg = 1;
1493 tts->rar.muPostResponseMsg = 1;
1494 tts->rar.muClassCount = 3;
1495 tts->rar.hasLastErrordetails = MI_FALSE;
1496 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1497
1498 NitsEndTest
1499
1500 /*
1501 **==============================================================================
1502 **
1503 ** Following test case is designed to test the handling of subscribe responses
1504 ** from provider; Say subscription is targeted to X classes, following are
1505 ** all of the possible typical scenarios of Subscribe Responses,
1506 **
1507 ** 11. M handled success; N succeeded from provider;
1508 ** 1<N<M<X
1509 **
1510 **==============================================================================
1511 */
1512 NitsTest1(TestMgr_HandleSubscribe_Handle_SomeSuccess_Response_SomeSuccess, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1513 krisbash 1.1 NitsFaultSimMarkForRerun;
1514 NitsDisableFaultSim;
1515 SimAgentMgrResponse responses[cClassCount] = {
1516 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1517 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1518 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1519 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1520 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1521 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1522
1523 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1524 tts->rar.samResponseSize = cClassCount;
1525 tts->rar.samResponse = responses;
1526 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1527 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1528 tts->rar.mrFinalResult = MI_RESULT_OK;
1529 tts->rar.muPostIndicationMsg = 2;
1530 tts->rar.muPostResultMsg = 1;
1531 tts->rar.muPostResponseMsg = 1;
1532 tts->rar.muClassCount = 3;
1533 tts->rar.hasLastErrordetails = MI_FALSE;
1534 krisbash 1.1 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1535
1536 NitsEndTest
1537
1538 /*
1539 **==============================================================================
1540 **
1541 ** Following test case is designed to test the handling of subscribe responses
1542 ** from provider; Say subscription is targeted to X classes, following are
1543 ** all of the possible typical scenarios of Subscribe Responses,
1544 **
1545 ** 12. M handled success; N succeeded from provider; And P failed later
1546 ** 1<=P<N<M<X
1547 **
1548 **==============================================================================
1549 */
1550 NitsTest1(TestMgr_HandleSubscribe_Handle_SomeSuccess_Response_SomeSuccess_SomeFailedLater, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1551 NitsFaultSimMarkForRerun;
1552 NitsDisableFaultSim;
1553 SimAgentMgrResponse responses[cClassCount] = {
1554 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1555 krisbash 1.1 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 1, 0, 0, MI_FALSE, MI_FALSE},
1556 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1557 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1558 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1559 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1560
1561 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1562 tts->rar.samResponseSize = cClassCount;
1563 tts->rar.samResponse = responses;
1564 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1565 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1566 tts->rar.mrFinalResult = MI_RESULT_OK;
1567 tts->rar.muPostIndicationMsg = 2;
1568 tts->rar.muPostResultMsg = 1;
1569 tts->rar.muPostResponseMsg = 1;
1570 tts->rar.muClassCount = 3;
1571 tts->rar.hasLastErrordetails = MI_FALSE;
1572 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1573
1574 NitsEndTest
1575
1576 krisbash 1.1 /*
1577 **==============================================================================
1578 **
1579 ** Following test case is designed to test the handling of subscribe responses
1580 ** from provider; Say subscription is targeted to X classes, following are
1581 ** all of the possible typical scenarios of Subscribe Responses,
1582 **
1583 ** 13. M handled success; N succeeded from provider; And N failed later
1584 ** 1<<N<M<X
1585 **
1586 **==============================================================================
1587 */
1588 NitsTest1(TestMgr_HandleSubscribe_Handle_SomeSuccess_Response_SomeSuccess_AllFailedLater, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1589 NitsFaultSimMarkForRerun;
1590 NitsDisableFaultSim;
1591 SimAgentMgrResponse responses[cClassCount] = {
1592 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1593 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 1, 0, 0, MI_FALSE, MI_FALSE},
1594 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1595 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_FAILED, 1, 0, 0, MI_FALSE, MI_FALSE},
1596 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1597 krisbash 1.1 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1598
1599 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1600 tts->rar.samResponseSize = cClassCount;
1601 tts->rar.samResponse = responses;
1602 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1603 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1604 tts->rar.mrFinalResult = MI_RESULT_FAILED;
1605 tts->rar.muPostIndicationMsg = 2;
1606 tts->rar.muPostResultMsg = 1;
1607 tts->rar.muPostResponseMsg = 1;
1608 tts->rar.muClassCount = 3;
1609 tts->rar.hasLastErrordetails = MI_FALSE;
1610 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1611
1612 NitsEndTest
1613
1614 /*
1615 **==============================================================================
1616 **
1617 ** Following test case is designed to test the handling of subscribe responses
1618 krisbash 1.1 ** from provider; Say subscription is targeted to X classes, following are
1619 ** all of the possible typical scenarios of Subscribe Responses,
1620 **
1621 ** 14. M handled success; M failed from provider;
1622 **
1623 **==============================================================================
1624 */
1625 NitsTest1(TestMgr_HandleSubscribe_Handle_SomeSuccess_Response_AllFailed, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1626 NitsFaultSimMarkForRerun;
1627 NitsDisableFaultSim;
1628 SimAgentMgrResponse responses[cClassCount] = {
1629 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1630 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1631 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1632 {MI_RESULT_OK, MI_RESULT_FAILED, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1633 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1634 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1635
1636 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1637 tts->rar.samResponseSize = cClassCount;
1638 tts->rar.samResponse = responses;
1639 krisbash 1.1 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1640 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1641 tts->rar.mrFinalResult = MI_RESULT_FAILED;
1642 tts->rar.muPostIndicationMsg = 0;
1643 tts->rar.muPostResultMsg = 1;
1644 tts->rar.muPostResponseMsg = 0;
1645 tts->rar.muClassCount = 3;
1646 tts->rar.hasLastErrordetails = MI_FALSE;
1647 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1648
1649 NitsEndTest
1650
1651 /*
1652 **==============================================================================
1653 **
1654 ** Following test case is designed to test the handling of subscribe responses
1655 ** from provider; Say subscription is targeted to X classes, following are
1656 ** all of the possible typical scenarios of Subscribe Responses,
1657 **
1658 ** 15. X handled failed
1659 **
1660 krisbash 1.1 **==============================================================================
1661 */
1662 NitsTest1(TestMgr_HandleSubscribe_Handle_AllFailed, Subscription_UnsubCancel, Subscription_UnsubCancelDefaults)
1663 NitsFaultSimMarkForRerun;
1664 NitsDisableFaultSim;
1665 SimAgentMgrResponse responses[cClassCount] = {
1666 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1667 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1668 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1669 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1670 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 2, 0, 0, MI_FALSE, MI_FALSE},
1671 {MI_RESULT_FAILED, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1672
1673 Test_IndiMgrStruct* tts = NitsContext()->_Subscription_UnsubCancel->_Subscription_Unsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1674 tts->rar.samResponseSize = cClassCount;
1675 tts->rar.samResponse = responses;
1676 tts->rar.callUnsubscribe = NitsContext()->_Subscription_UnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1677 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1678 tts->rar.mrFinalResult = MI_RESULT_FAILED;
1679 tts->rar.muPostIndicationMsg = 0;
1680 tts->rar.muPostResultMsg = 1;
1681 krisbash 1.1 tts->rar.muPostResponseMsg = 0;
1682 tts->rar.muClassCount = 0;
1683 tts->rar.hasLastErrordetails = MI_FALSE;
1684 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1685
1686 NitsEndTest
1687
1688 /*
1689 **==============================================================================
1690 **
1691 ** Lifecycle Indication Tests
1692 **
1693 **==============================================================================
1694 */
1695 /*
1696 **==============================================================================
1697 ** Target lifecycle indication classes list referred by following test cases
1698 **==============================================================================
1699 */
1700 static StringTagElement _LifecycleIndicationClassList[] =
1701 {
1702 krisbash 1.1 { MI_T("TEST_ProcessCreated"), 0, (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
1703 { MI_T("TEST_ProcessTerminated"),0, (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
1704 { MI_T("MSFT_Person"),0, (MI_Uint32)SUBSCRIP_TARGET_LIFECYCLE_ALL},
1705 { MI_T("MSFT_Person2"),0, (MI_Uint32)SUBSCRIP_TARGET_LIFECYCLE_ALL},
1706 };
1707 const MI_Uint32 cLCIndicationClassCount = MI_COUNT(_LifecycleIndicationClassList);
1708 static struct Test_IndiMgrStruct sTestIM3 = {
1709 MI_T("select * from CIM_InstIndication where SourceInstance isa MSFT_Base"),
1710 QUERY_LANGUAGE_WQL,
1711 MI_T("root/indication2"),
1712 {
1713 _UT_GetProvReg,
1714 _UT_HandleRequest,
1715 NULL,
1716 },
1717 _LifecycleIndicationClassList,
1718 cLCIndicationClassCount,
1719 NULL,
1720 NULL,
1721 NULL,
1722 NULL};
1723 krisbash 1.1
1724 NitsSetup1(LCIndicationUnsubscibe, Unsubscribe_Struct, TestMgr_Setup, sTestIM3)
1725 NitsContext()->_Unsubscribe_Struct->shouldUnsubscribe = MI_TRUE;
1726 NitsEndSetup
1727
1728 NitsSetup1(LCIndicationCancel, Unsubscribe_Struct, TestMgr_Setup, sTestIM3)
1729 NitsContext()->_Unsubscribe_Struct->shouldUnsubscribe = MI_FALSE;
1730 NitsEndSetup
1731
1732 NitsSplit2(LCIndicationUnsubCancel, Unsubscribe_Struct, LCIndicationUnsubscibe, LCIndicationCancel)
1733 NitsEndSplit
1734
1735 /*
1736 **==============================================================================
1737 **
1738 ** Validate subscribe request handled successfully with all classes succeeded
1739 ** and Unsubscribe request can be handled correctly afterwards
1740 **
1741 **==============================================================================
1742 */
1743 NitsTest1(TestMgr_HandleIndicationResult_LifecycleIndication_Success, LCIndicationUnsubCancel, LCIndicationUnsubCancelDefaults)
1744 krisbash 1.1 NitsDisableFaultSim;
1745 NitsFaultSimMarkForRerun;
1746
1747 SimAgentMgrResponse responses[cLCIndicationClassCount] = {
1748 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1749 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1750 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1751 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1752 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1753
1754 Test_IndiMgrStruct* tts = NitsContext()->_LCIndicationUnsubCancel->_LCIndicationUnsubscibe->_TestMgr_Setup->_Test_IndiMgrStruct;
1755 tts->rar.samResponseSize = cLCIndicationClassCount;
1756 tts->rar.samResponse = responses;
1757 tts->rar.callUnsubscribe = NitsContext()->_LCIndicationUnsubCancel->_Unsubscribe_Struct->shouldUnsubscribe;
1758 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1759 tts->rar.mrFinalResult = MI_RESULT_OK;
1760 tts->rar.muPostIndicationMsg = 4;
1761 tts->rar.muPostResultMsg = 1;
1762 tts->rar.muPostResponseMsg = 1;
1763 tts->rar.muClassCount = cLCIndicationClassCount;
1764 tts->rar.hasLastErrordetails = MI_FALSE;
1765 krisbash 1.1 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1766
1767 NitsEndTest
1768
1769
1770 /*
1771 **==============================================================================
1772 **
1773 ** Validate subscribe request handled successfully for InstDeletion class
1774 **
1775 **==============================================================================
1776 */
1777 static StringTagElement _InstDeletionClassList[] =
1778 {
1779 { MI_T("TEST_ProcessTerminated"),0, (MI_Uint32)SUBSCRIP_TARGET_DEFAULT},
1780 { MI_T("MSFT_Person"),0, (MI_Uint32)SUBSCRIP_TARGET_LIFECYCLE_DELETE},
1781 { MI_T("MSFT_Person2"),0, (MI_Uint32)SUBSCRIP_TARGET_LIFECYCLE_DELETE},
1782 };
1783 const MI_Uint32 cInstDeletionClassCount = MI_COUNT(_InstDeletionClassList);
1784 static struct Test_IndiMgrStruct sTestIM4 = {
1785 MI_T("select * from CIM_InstDeletion where (SourceInstance isa MSFT_Animal)"),
1786 krisbash 1.1 QUERY_LANGUAGE_WQL,
1787 MI_T("root/indication2"),
1788 {
1789 _UT_GetProvReg,
1790 _UT_HandleRequest,
1791 NULL,
1792 },
1793 _InstDeletionClassList,
1794 cInstDeletionClassCount,
1795 NULL,
1796 NULL,
1797 NULL,
1798 NULL};
1799 NitsTest1(TestMgr_HandleIndicationResult_LifecycleIndication_Success_InstDeletion, TestMgr_Setup, sTestIM4)
1800 NitsFaultSimMarkForRerun;
1801 NitsDisableFaultSim;
1802 SimAgentMgrResponse responses[cInstDeletionClassCount] = {
1803 /*Hdl Req Res Resp First Resp Second nIndi IndSent ResSent AllSent Occupied*/
1804 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1805 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},
1806 {MI_RESULT_OK, MI_RESULT_OK, MI_RESULT_OK, 1, 0, 0, MI_FALSE, MI_FALSE},};
1807 krisbash 1.1
1808 Test_IndiMgrStruct* tts = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct;
1809 tts->rar.samResponseSize = cInstDeletionClassCount;
1810 tts->rar.samResponse = responses;
1811 tts->rar.callUnsubscribe = MI_TRUE;
1812 tts->rar.protocolFinishedBeforeUnsubscribe = MI_FALSE;
1813 tts->rar.mrFinalResult = MI_RESULT_OK;
1814 tts->rar.muPostIndicationMsg = cInstDeletionClassCount;
1815 tts->rar.muPostResultMsg = 1;
1816 tts->rar.muPostResponseMsg = 1;
1817 tts->rar.muClassCount = cInstDeletionClassCount;
1818 tts->rar.hasLastErrordetails = MI_FALSE;
1819 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1820
1821 NitsEndTest
1822
1823 /*
1824 **==============================================================================
1825 **
1826 ** Validate subscribe request handled successfully for a given NOT-supported query
1827 ** NOTE: Neither indication classe nor normal class will be discovered for this
1828 krisbash 1.1 ** query
1829 **
1830 **==============================================================================
1831 */
1832 static struct Test_IndiMgrStruct sTestIM5 = {
1833 MI_T("select * from CIM_InstRead where (SourceInstance isa MSFT_Base) OR (2 > 1)"),
1834 QUERY_LANGUAGE_WQL,
1835 MI_T("root/indication2"),
1836 {
1837 _UT_GetProvReg,
1838 _UT_HandleRequest,
1839 NULL,
1840 },
1841 _LifecycleIndicationClassList,
1842 cLCIndicationClassCount,
1843 NULL,
1844 NULL,
1845 NULL,
1846 NULL};
1847 NitsTest1(TestMgr_HandleIndicationResult_LifecycleIndication_InvalidQuery, TestMgr_Setup, sTestIM5)
1848 NitsFaultSimMarkForRerun;
1849 krisbash 1.1
1850 // Disable Nits Fault injection here, beacuse in RegFile_New function (Called internally in ProvReg_Init) will
1851 // return NULL in both cases Failure OR failed to allocate. And Nits doesn't like that.
1852 NitsDisableFaultSim;
1853
1854 Test_IndiMgrStruct* tts = NitsContext()->_TestMgr_Setup->_Test_IndiMgrStruct;
1855 tts->rar.samResponseSize = 0;
1856 tts->rar.samResponse = NULL;
1857 tts->rar.callUnsubscribe = MI_TRUE;
1858 tts->rar.protocolFinishedBeforeUnsubscribe = MI_TRUE;
1859 tts->rar.mrFinalResult = MI_RESULT_NOT_SUPPORTED;
1860 tts->rar.muPostIndicationMsg = 0;
1861 tts->rar.muPostResultMsg = 1;
1862 tts->rar.muPostResponseMsg = 0;
1863 tts->rar.muClassCount = 0;
1864 tts->rar.hasLastErrordetails = MI_TRUE;
1865 TestMgr_Subscribe_Unsubscribe_Cancel(tts);
1866
1867 NitsEndTest
|