summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/test/fapiRcTest.C
blob: 1877f6a89dec94d0f652db0a95792c74c68423f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/hwpf/test/fapiRcTest.C $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
/**
 *  @file fapiTargetTest.C
 *
 *  @brief Implements Target class unit test functions.
 */

/*
 * Change Log ******************************************************************
 * Flag     Defect/Feature  User        Date        Description
 * ------   --------------  ----------  ----------- ----------------------------
 *                          mjjones     04/13/2011  Created.
 *                          mjjones     07/26/2011  Added more tests
 *
 */

#include <fapi.H>

namespace fapi
{

//******************************************************************************
// rcTest1. Ensures that the ReturnCode default constructor works
//******************************************************************************
uint32_t rcTest1()
{
    uint32_t l_result = 0;

    // Create ReturnCode using default constructor
    ReturnCode l_rc;

    // Ensure that the embedded return code is success
    if (l_rc != FAPI_RC_SUCCESS)
    {
        FAPI_ERR("rcTest1. Code is 0x%x, expected success",
                 static_cast<uint32_t>(l_rc));
        l_result = 1;
    }
    else
    {
        // Ensure that ok function works
        if (l_rc.ok() == false)
        {
            FAPI_ERR("rcTest1. ok returned false");
            l_result = 2;
        }
        else
        {
            // Ensure that testing l_rc works
            if (l_rc)
            {
                FAPI_ERR("rcTest1. testing rc returned true");
                l_result = 3;
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest2. Ensures that the ReturnCode creator reflects the return code
//******************************************************************************
uint32_t rcTest2()
{
    uint32_t l_result = 0;

    // Create ReturnCode using default constructor
    ReturnCode l_rc;

    // Set the return code to a FAPI code
    l_rc = FAPI_RC_FAPI_MASK | 0x05;

    // Ensure that the creator is FAPI
    ReturnCode::returnCodeCreator l_creator = l_rc.getCreator();

    if (l_creator != ReturnCode::CREATOR_FAPI)
    {
        FAPI_ERR("rcTest2. Creator is 0x%x, expected FAPI", l_creator);
        l_result = 1;
    }
    else
    {
        // Set the return code to a PLAT code
        l_rc = FAPI_RC_PLAT_ERR_SEE_DATA;

        // Ensure that the creator is PLAT
        l_creator = l_rc.getCreator();

        if (l_creator != ReturnCode::CREATOR_PLAT)
        {
            FAPI_ERR("rcTest2. Creator is 0x%x, expected PLAT", l_creator);
            l_result = 2;
        }
        else
        {
            // Set the return code to a HWP code
            l_rc = 5;

            // Ensure that the creator is HWP
            l_creator = l_rc.getCreator();

            if (l_creator != ReturnCode::CREATOR_HWP)
            {
                FAPI_ERR("rcTest2. Creator is 0x%x, expected HWP", l_creator);
                l_result = 3;
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest3. Ensures that the ReturnCode constructor works when specifying a
//          return code
//******************************************************************************
uint32_t rcTest3()
{
    uint32_t l_result = 0;

    // Create ReturnCode specifying a return code
    uint32_t l_code = 4;
    ReturnCode l_rc(l_code);

    // Ensure that the embedded return code is as expected
    uint32_t l_codeCheck = l_rc;

    if (l_codeCheck != l_code)
    {
        FAPI_ERR("rcTest3. Code is 0x%x, expected 0x%x", l_codeCheck,
                l_code);
        l_result = 1;
    }
    else
    {
        // Ensure that ok function returns false
        if (l_rc.ok())
        {
            FAPI_ERR("rcTest3. ok returned true");
            l_result = 2;
        }
        else
        {
            // Ensure that testing l_rc works
            if (!l_rc)
            {
                FAPI_ERR("rcTest3. testing rc returned false");
                l_result = 3;
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest4. Ensures that the comparison operators work (comparing with another
//          ReturnCode)
//******************************************************************************
uint32_t rcTest4()
{
    uint32_t l_result = 0;

    // Create similar ReturnCodes
    uint32_t l_code = 6;
    uint32_t l_code2 = 7;
    ReturnCode l_rc(l_code);
    ReturnCode l_rc2(l_code);

    // Ensure that the equality comparison returns true
    if (!(l_rc == l_rc2))
    {
        FAPI_ERR("rcTest5. 1. Equality comparison false");
        l_result = 1;
    }
    else
    {
        // Ensure that the inequality comparison returns false
        if (l_rc != l_rc2)
        {
            FAPI_ERR("rcTest5. 2. Inequality comparison true");
            l_result = 2;
        }
        else
        {
            // Change the code of l_rc2
            l_rc2 = l_code2;

            // Ensure that the equality comparison returns false
            if (l_rc == l_rc2)
            {
                FAPI_ERR("rcTest5. 3. Equality comparison true");
                l_result = 3;
            }
            else
            {
                // Ensure that the inequality comparison returns true
                if (!(l_rc != l_rc2))
                {
                    FAPI_ERR("rcTest5. 4. Inequality comparison false");
                    l_result = 4;
                }
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest5. Ensures that the comparison operators work (comparing with a return
//          code value)
//******************************************************************************
uint32_t rcTest5()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    uint32_t l_code = 6;
    uint32_t l_code2 = 7;
    ReturnCode l_rc(l_code);

    // Ensure that the equality comparison returns true when comparing to the
    // same return code value
    if (!(l_rc == l_code))
    {
        FAPI_ERR("rcTest6. 1. Equality comparison false");
        l_result = 1;
    }
    else
    {
        // Ensure that the inequality comparison returns false when comparing to
        // the same return code value
        if (l_rc != l_code)
        {
            FAPI_ERR("rcTest6. 2. Inequality comparison true");
            l_result = 2;
        }
        else
        {
            // Ensure that the equality comparison returns false when comparing
            // to a different return code value
            if (l_rc == l_code2)
            {
                FAPI_ERR("rcTest6. 3. Equality comparison true");
                l_result = 3;
            }
            else
            {
                // Ensure that the inequality comparison returns true when
                // comparing to a different return code value
                if (!(l_rc != l_code2))
                {
                    FAPI_ERR("rcTest6. 4. Inequality comparison false");
                    l_result = 4;
                }
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest6. Ensures that the getPlatData and releasePlatData functions work when
//          there is no attached data
//******************************************************************************
uint32_t rcTest6()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    uint32_t l_code = 6;
    ReturnCode l_rc(l_code);

    // Ensure that the getPlatData function returns NULL
    void * l_pData = reinterpret_cast<void *> (0x12345678);

    l_pData = l_rc.getPlatData();

    if (l_pData != NULL)
    {
        FAPI_ERR("rcTest7. getPlatData did not return NULL");
        l_result = 1;
    }
    else
    {
        // Ensure that the releasePlatData function returns NULL
        l_pData = reinterpret_cast<void *> (0x12345678);

        l_pData = l_rc.releasePlatData();

        if (l_pData != NULL)
        {
            FAPI_ERR("rcTest7. releasePlatData did not return NULL");
            l_result = 2;
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest7. Ensures that the getPlatData function works when there is attached
//          data
//******************************************************************************
uint32_t rcTest7()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    uint32_t l_code = 10;
    ReturnCode l_rc(l_code);

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the FSP deleteData function will attempt to delete an error log, but this
    // is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatData(l_pMyData);

    // Ensure that getPlatData retrieves the PlatData
    void * l_pMyDataCheck = l_rc.getPlatData();

    if (l_pMyDataCheck != l_pMyData)
    {
        FAPI_ERR("rcTest8. 1. getPlatData returned unexpected data ptr");
        l_result = 1;
    }
    else
    {
        // Ensure that getPlatData retrieves the PlatData again
        l_pMyDataCheck = NULL;
        l_pMyDataCheck = l_rc.getPlatData();

        if (l_pMyDataCheck != l_pMyData)
        {
            FAPI_ERR("rcTest8. 2. getPlatData returned unexpected data ptr");
            l_result = 2;
        }
    }

    // Release the data to avoid ReturnCode from deleting in on destruction
    l_pMyDataCheck = l_rc.releasePlatData();

    return l_result;
}

//******************************************************************************
// rcTest8. Ensures that the releasePlatData function works when there is
//          attached data
//******************************************************************************
uint32_t rcTest8()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    uint32_t l_code = 10;
    ReturnCode l_rc(l_code);

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the FSP deleteData function will attempt to delete an error log, but this
    // is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatData(l_pMyData);

    // Ensure that releasePlatData retrieves the PlatData
    void * l_pMyDataCheck = l_rc.releasePlatData();

    if (l_pMyDataCheck != l_pMyData)
    {
        FAPI_ERR("rcTest9. getPlatData returned unexpected data ptr");
        l_result = 1;
    }
    else
    {
        // Ensure that releasePlatData now returns NULL
        l_pMyDataCheck = NULL;
        l_pMyDataCheck = l_rc.releasePlatData();

        if (l_pMyDataCheck != NULL)
        {
            FAPI_ERR("rcTest9. 2. getPlatData returned non NULL ptr");
            l_result = 2;
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest9. Ensures that the copy constructor works when there is attached
//          PlatData and that the getPlatData function works
//******************************************************************************
uint32_t rcTest9()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    uint32_t l_code = 10;
    ReturnCode l_rc(l_code);

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the FSP deleteData function will attempt to delete an error log, but this
    // is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatData(l_pMyData);

    // Create a ReturnCode using the copy constructor
    ReturnCode l_rc2(l_rc);

    // Ensure that the two ReturnCodes are the same
    if (l_rc != l_rc2)
    {
        FAPI_ERR("rcTest10. ReturnCodes differ");
        l_result = 1;
    }
    else
    {
        // Ensure that getPlatData retrieves the PlatData from l_rc
        void * l_pMyDataCheck = l_rc.getPlatData();

        if (l_pMyDataCheck != l_pMyData)
        {
            FAPI_ERR("rcTest10. 1. getPlatData returned unexpected data ptr");
            l_result = 2;
        }
        else
        {
            // Ensure that getPlatData retrieves the PlatData from l_rc2
            l_pMyDataCheck = NULL;
            l_pMyDataCheck = l_rc2.getPlatData();

            if (l_pMyDataCheck != l_pMyData)
            {
                FAPI_ERR("rcTest10. 2. getPlatData returned unexpected data ptr");
                l_result = 3;
            }
        }
    }

    // Release the data to avoid ReturnCode from deleting in on destruction.
    // This will release the data from both copies of the ReturnCode.
    (void) l_rc.releasePlatData();

    return l_result;
}

//******************************************************************************
// rcTest10. Ensures that the assignment operator works when there is attached
//           PlatData and that the releasePlatData function works
//******************************************************************************
uint32_t rcTest10()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    uint32_t l_code = 10;
    ReturnCode l_rc(l_code);

    // Assign PlatData. Note that this should really be an errlHndl_t, because
    // the PLAT deleteData function will attempt to delete an error log, but
    // this is just for test, the data will be released before the ReturnCode is
    // destructed.
    uint32_t l_myData = 6;
    void * l_pMyData = reinterpret_cast<void *> (&l_myData);
    (void) l_rc.setPlatData(l_pMyData);

    // Create a ReturnCode using the assignment operator
    ReturnCode l_rc2;
    l_rc2 = l_rc;

    // Ensure that the two ReturnCodes are the same
    if (l_rc != l_rc2)
    {
        FAPI_ERR("rcTest11. ReturnCodes differ");
        l_result = 1;
    }
    else
    {
        // Ensure that releasePlatData retrieves the PlatData from l_rc
        void * l_pMyDataCheck = l_rc.releasePlatData();

        if (l_pMyDataCheck != l_pMyData)
        {
            FAPI_ERR("rcTest11. releasePlatData returned unexpected data ptr");
            l_result = 2;
        }
        else
        {
            // Ensure that releasePlatData retrieves NULL from l_rc2
            l_pMyDataCheck = NULL;
            l_pMyDataCheck = l_rc2.releasePlatData();

            if (l_pMyDataCheck != NULL)
            {
                FAPI_ERR("rcTest11. releasePlatData returned non NULL ptr");
                l_result = 3;
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest11. Ensures that the getHwpFfdc functions works when there is no FFDC
//******************************************************************************
uint32_t rcTest11()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    uint32_t l_code = 6;
    ReturnCode l_rc(l_code);

    // Ensure that the getHwpFfdc function returns NULL
    const void * l_pFfdc = reinterpret_cast<const void *> (0x12345678);

    // Get FFDC pointer
    uint32_t l_size = 0;
    l_pFfdc = l_rc.getHwpFfdc(l_size);

    if (l_pFfdc != NULL)
    {
        FAPI_ERR("rcTest11. getHwpFfdc did not return NULL");
        l_result = 1;
    }

    return l_result;
}

//******************************************************************************
// rcTest12. Ensures that the getHwpFfdc function works when there is FFDC
//******************************************************************************
uint32_t rcTest12()
{
    uint32_t l_result = 0;
    uint32_t l_code = 10;

    // Create a ReturnCode
    ReturnCode l_rc(l_code);

    // Add HwpFfdc.
    uint32_t l_myData[2] = {4, 5};
    void * l_pMyData = reinterpret_cast<void *> (l_myData);
    (void) l_rc.setHwpFfdc(l_pMyData, sizeof(l_myData));

    // Ensure that getHwpFfdc returns a pointer to the same data
    uint32_t l_size = 0;
    const uint32_t * l_pMyDataCheck = reinterpret_cast<const uint32_t *>
        (l_rc.getHwpFfdc(l_size));

    if (l_size != sizeof(l_myData))
    {
        FAPI_ERR("rcTest12. getHwpFfdc returned bad size %d", l_size);
        l_result = 1;
    }
    else if ((l_pMyDataCheck[0] != 4) || (l_pMyDataCheck[1] != 5))
    {
        FAPI_ERR("rcTest12. getHwpFfdc returned bad data");
        l_result = 2;
    }

    return l_result;
}

//******************************************************************************
// rcTest13. Ensures that the copy constructor works when there is FFDC and that
//           the getHwpFfdc function works
//******************************************************************************
uint32_t rcTest13()
{
    uint32_t l_result = 0;
    uint32_t l_code = 10;

    // Create a ReturnCode
    ReturnCode l_rc(l_code);

    // Add HwpFfdc.
    uint32_t l_myData[2] = {4, 5};
    void * l_pMyData = reinterpret_cast<void *> (l_myData);
    (void) l_rc.setHwpFfdc(l_pMyData, sizeof(l_myData));

    // Create a ReturnCode using the copy constructor
    ReturnCode l_rc2(l_rc);

    // Ensure that the two ReturnCodes are the same
    if (l_rc != l_rc2)
    {
        FAPI_ERR("rcTest13. ReturnCodes differ");
        l_result = 1;
    }
    else
    {
        // Ensure that getHwpFfdc returns a pointer to the same data from l_rc
        uint32_t l_size = 0;
        const uint32_t * l_pMyDataCheck = reinterpret_cast<const uint32_t *>
            (l_rc.getHwpFfdc(l_size));

        if (l_size != sizeof(l_myData))
        {
            FAPI_ERR("rcTest13. getHwpFfdc returned bad size %d", l_size);
            l_result = 2;
        }
        else if ((l_pMyDataCheck[0] != 4) || (l_pMyDataCheck[1] != 5))
        {
            FAPI_ERR("rcTest13. getHwpFfdc returned bad data");
            l_result = 3;
        }
        else
        {
            // Ensure that getHwpFfdc returns a pointer to the same data from
            // l_rc2
            uint32_t l_size2 = 0;
            const uint32_t * l_pMyDataCheck2 = reinterpret_cast<const uint32_t *>
                (l_rc2.getHwpFfdc(l_size2));

            if (l_size2 != sizeof(l_myData))
            {
                FAPI_ERR("rcTest13. getHwpFfdc(2) returned bad size %d",
                         l_size2);
                l_result = 4;
            }
            else if ((l_pMyDataCheck2[0] != 4) || (l_pMyDataCheck2[1] != 5))
            {
                FAPI_ERR("rcTest13. getHwpFfdc(2) returned bad data");
                l_result = 5;
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest14. Ensures that the assignment operator works when there is FFDC and
//           that the getHwpFfdc function works
//******************************************************************************
uint32_t rcTest14()
{
    uint32_t l_result = 0;
    uint32_t l_code = 10;

    // Create a ReturnCode
    ReturnCode l_rc(l_code);

    // Add HwpFfdc.
    uint32_t l_myData[2] = {4, 5};
    void * l_pMyData = reinterpret_cast<void *> (l_myData);
    (void) l_rc.setHwpFfdc(l_pMyData, sizeof(l_myData));

    // Create a ReturnCode using the assignment operator
    ReturnCode l_rc2;
    l_rc2 = l_rc;

    // Ensure that the two ReturnCodes are the same
    if (l_rc != l_rc2)
    {
        FAPI_ERR("rcTest14. ReturnCodes differ");
        l_result = 1;
    }
    else
    {
        // Ensure that getHwpFfdc returns a pointer to the same data from l_rc
        uint32_t l_size = 0;
        const uint32_t * l_pMyDataCheck = reinterpret_cast<const uint32_t *>
            (l_rc.getHwpFfdc(l_size));

        if (l_size != sizeof(l_myData))
        {
            FAPI_ERR("rcTest14. getHwpFfdc returned bad size %d", l_size);
            l_result = 2;
        }
        else if ((l_pMyDataCheck[0] != 4) || (l_pMyDataCheck[1] != 5))
        {
            FAPI_ERR("rcTest14. getHwpFfdc returned bad data");
            l_result = 3;
        }
        else
        {
            // Ensure that getHwpFfdc returns a pointer to the same data from
            // l_rc2
            uint32_t l_size2 = 0;
            const uint32_t * l_pMyDataCheck2 = reinterpret_cast<const uint32_t *>
                (l_rc2.getHwpFfdc(l_size2));

            if (l_size2 != sizeof(l_myData))
            {
                FAPI_ERR("rcTest14. getHwpFfdc(2) returned bad size %d",
                         l_size2);
                l_result = 4;
            }
            else if ((l_pMyDataCheck2[0] != 4) || (l_pMyDataCheck2[1] != 5))
            {
                FAPI_ERR("rcTest14. getHwpFfdc(2) returned bad data");
                l_result = 5;
            }
        }
    }

    return l_result;
}

//******************************************************************************
// rcTest15. Ensures that the setErrTarget function works when there is no error
//******************************************************************************
uint32_t rcTest15()
{
    uint32_t l_result = 0;

    // Create a ReturnCode
    ReturnCode l_rc;

    // Create a Target
    uint8_t l_handle = 7;
    void * l_pHandle = reinterpret_cast<void *>(&l_handle);
    Target l_target(TARGET_TYPE_DIMM, l_pHandle);

    // Set the error target
    l_rc.setErrTarget(l_target);

    // Retreive the Error target (should be null because no error)
    Target * l_pTarget = l_rc.getErrTarget();

    if (l_pTarget != NULL)
    {
        FAPI_ERR("rcTest15. getErrTarget returned non-null pointer");
        l_result = 1;
    }

    // Set the handle pointer to NULL to prevent any problem on destruction
    l_target.set(NULL);

    return l_result;
}

//******************************************************************************
// rcTest16. Ensures that the setErrTarget function works when there is an error
//******************************************************************************
uint32_t rcTest16()
{
    uint32_t l_result = 0;

    // Create a ReturnCode with an error
    ReturnCode l_rc(8);

    // Create a Target
    uint8_t l_handle = 7;
    void * l_pHandle = reinterpret_cast<void *>(&l_handle);
    Target l_target(TARGET_TYPE_DIMM, l_pHandle);

    // Set the error target
    l_rc.setErrTarget(l_target);

    // Retreive the Error target
    Target * l_pTarget = l_rc.getErrTarget();

    if (*l_pTarget != l_target)
    {
        FAPI_ERR("rcTest16. getErrTarget returned bad target");
        l_result = 1;
    }

    // Set the handle pointer to NULL to prevent any problem on destruction
    l_target.set(NULL);

    return l_result;
}

//******************************************************************************
// rcTest17. Ensures that the setErrTarget function works when there is an error
//           and an existing Target
//******************************************************************************
uint32_t rcTest17()
{
    uint32_t l_result = 0;

    // Create a ReturnCode with an error
    ReturnCode l_rc(8);

    // Create a Target
    uint8_t l_handle = 7;
    void * l_pHandle = reinterpret_cast<void *>(&l_handle);
    Target l_target(TARGET_TYPE_DIMM, l_pHandle);

    // Create another Target
    uint8_t l_handle2 = 8;
    void * l_pHandle2 = reinterpret_cast<void *>(&l_handle2);
    Target l_target2(TARGET_TYPE_DIMM, l_pHandle2);

    // Set the error target
    l_rc.setErrTarget(l_target);

    // Attempt to set the error target again (should not be set because there is
    // already an error target)
    l_rc.setErrTarget(l_target2);

    // Retreive the Error target
    Target * l_pTarget = l_rc.getErrTarget();

    if (*l_pTarget != l_target)
    {
        FAPI_ERR("rcTest17. getErrTarget returned bad target");
        l_result = 1;
    }

    // Set the handle pointer to NULL to prevent any problem on destruction
    l_target.set(NULL);

    return l_result;
}

}
OpenPOWER on IntegriCloud