Appendix - Advanced Data-Driven Test Case Example

MFUT_TESTFLYER.cbl

       program-id. MFUT_TESTFLYER_FILE.
       working-storage section.
       78 78-OVERRIDE-MFU-DD-VALUE-SIZE value 32763.
       copy "mfunit.cpy".
       copy "GetFlyerLevel.cpy" replacing ==:prefix:== by ==ws==.

       01 ws-expected-award-level td-flyer-status.
       01 ws-earned               td-flyer-status-points.

       01 mfu-dd-InitialStatus    is MFU-DD-VALUE external.
       01 mfu-dd-FinalStatus      is MFU-DD-VALUE external.
       01 mfu-dd-InitialPoints    is MFU-DD-VALUE external.
       01 mfu-dd-EarnedPoints     is MFU-DD-VALUE external.
       01 mfu-dd-Description      is MFU-DD-VALUE external.

       01 ws-filename                 pic x(MFU-GET-FILENAME-SIZE).
       01 ws-pointer                  pointer.
       01 ws-size                     binary-long unsigned.


       linkage section.
       01 link-data                   pic x.
       procedure division.
           if length of MFU-DD-VALUE not equal
                   78-OVERRIDE-MFU-DD-VALUE-SIZE
               display "MFU-DD-VALUE size is invalid"
               display length of MFU-DD-VALUE
               goback returning 1
           end-if

      *  Retrieve initial status from external file data
           if mfu-dd-Description(1:1) equal "@"
               move mfu-dd-Description(2:) to ws-filename
               perform retrieve-long-description
               if ws-size < 80
                   display " Description expected to be > 80 "
                   display " "
                   goback returning 2
               else
                   display link-data(1:ws-size)
               end-if
            else
               display mfu-dd-Description
           end-if

           move mfu-dd-InitialStatus to ws-award-level
           move mfu-dd-FinalStatus   to ws-expected-award-level

		   display "  /" "mfu-dd-InitialStatus" "/"
		   mfu-dd-InitialStatus "/"
		   display "  /" "mfu-dd-FinalStatus " "/"
		   mfu-dd-FinalStatus  "/"
		   display "  /" "mfu-dd-InitialPoints" "/"
		   mfu-dd-InitialPoints  "/"
		   display "  /" "mfu-dd-EarnedPoints " "/"
		   mfu-dd-EarnedPoints  "/"

           initialize ws-flyer-info
           move function numval(mfu-dd-InitialPoints) to ws-award-points
           move function numval(mfu-dd-EarnedPoints) to ws-earned

      $if show-progress defined
           display "   Data data driven test for " MFU-DD-DIAG-MSG
      $end

           display "Calling pgm for final Status " mfu-dd-FinalStatus
           call "GetFlyerLevel" using
               by reference ws-flyer-info
               by reference ws-earned
           end-call
           display " "

      *  Release the memory for the external file data
           if mfu-dd-Description(1:1) equal "@"
               perform free-initial-status
           end-if

           if ws-award-level not equal ws-expected-award-level
               display " Unexpected award level, expected "
                       ws-expected-award-level ", got " ws-award-level
               goback returning MFU-FAIL-RETURN-CODE
           end-if

           goback returning MFU-PASS-RETURN-CODE.

       retrieve-long-description section.
           move 0 to ws-size
           set ws-pointer to null
           call MFU-GET-FILE using
                   by reference ws-filename
                   by reference ws-pointer
                   by reference ws-size
           end-call
           if return-code not equal 0
               display "Unable to locate file"
               goback returning return-code
           end-if

           if ws-pointer equal null
               display "No data has been read"
               goback returning 128
           end-if

           if ws-size equal 0
               display "File has no size"
               goback returning 128
           end-if

           *> make link-data addressable
           set address of link-data to ws-pointer
           .

       free-initial-status section.
           *> finish with the data, so free it
           call "CBL_FREE_MEM" using
               by value ws-pointer
           end-call
           .
       entry "MFUM_TESTFLYER_FILE".
           move "csv:FrequentFlyerFile.csv" to MFU-MD-TESTDATA
           move 78-OVERRIDE-MFU-DD-VALUE-SIZE to MFU-MD-DD-VALUE-SIZE
           goback.


       end program.

GetFlyerLevel.cbl

       program-id. GetFlyerLevel.
       linkage section.
       copy "GetFlyerLevel.cpy" replacing ==:prefix:== by ==lnk==.
       01 lnk-extra-status-points  td-flyer-status-points.
       procedure division using lnk-flyer-info, lnk-extra-status-points.
           add lnk-extra-status-points to lnk-award-points
           
           evaluate lnk-award-points
                when < 300
                   move "Bronze" to lnk-award-level
                when >= 300 and < 700
                   move "Silver" to lnk-award-level
                when >= 700 and < 1500
                   move "Gold" to lnk-award-level
                when >= 1500 and < 10000
                  move "Platinum" to lnk-award-level
               when other
                   move "Diamond" to lnk-award-level
           end-evaluate
       end program.

GetFlyerLevel.cpy

       01 td-flyer-status-points        pic 9(9) typedef.
       01 td-flyer-status               pic x(20) typedef.
       01 :prefix:-flyer-info.
           03 :prefix:-award-level      td-flyer-status.
           03 :prefix:-award-points    td-flyer-status-points.

FrequentFlyer.csv

InitialStatus,InitialPoints,EarnedPoints,Deductions,FinalStatus,Description
Bronze,0,100,0,Bronze,Test Case 1
Bronze,0,300,50,Silver,Test Case 2
Bronze,100,200,66,Silver,Test Case 3
Bronze,0,700,1,Gold,Test Case 4
Bronze,0,1500,800,Platinum,Test Case 5
Platinum,1600,12000,600,Diamond,@gettysburg.txt
Platinum,1600,14000,100,Diamond,@lorem.txt

lorem.txt

Test Case 6
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst.

gettysburg.txt

Test Case 7
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
But, in a larger sense, we can not dedicate—we can not consecrate—we can not hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom—and that government of the people, by the people, for the people, shall not perish from the earth.