Big news! The community will be moving to a new platform April 21. Read more.
Big news! The community will be moving to a new platform April 21. Read more.
Commander
Commander
392 views

Dump working storage for use in a Unit Test

I would like to unit test a program that is several layers deep in a large monolithic application.  The program undergoing change and requiring testing has a lengthy list of fields that needs to be supplied via its Linkage Section.  Is there a way I capture the contents of storage during execution, perhaps in debug mode, so I can more easily use these values in my unit test?

Tags (1)
0 Likes
4 Replies
Micro Focus Expert
Micro Focus Expert

One thing I've done in situations like this is create test driver that moves the data to linkage and then does the call. If I want to run multiple test cases I set up the move/call combination multiple times with the different test scenarios. The initial setup may be a bit but the go forward is fairly minor


Commander
Commander

Thanks @SteveW2 ; that's the plan.  I was hoping to, at least initally, grab all the values needed in the driver from a dump of storage, rather than manually discovering and coding them.

0 Likes
Micro Focus Expert
Micro Focus Expert

Hi @StompinBob,

We've come up with a couple of ideas for how you might save and restore data areas from within a COBOL program, which might allow you to do what you wanted. Both approaches make use of special byte-stream-io APIs that are available in Micro Focus COBOL to read and write the data. Each would require some coding on your part; I'm going to attach a couple of examples to give you a clear idea of how this might be done.

Sample 1 in the attached zip file is streamio-memfromarray.cbl, and was conceived and developed by my colleague Chris Glazier. It shows an idea for defining an array containing references to each memory (01 level) item that needs to be saved. These could be 01 levels within Working Storage of a program, or items that were passed into the program via Linkage Section. The example loops through the array, saving memory for these items to a file, and then later reads them back from the file.  You could call this program as a child of an existing program where you needed to save items. 

Sample 2 is  streamio-memrange.cbl. Chris also wrote this one, based on an idea suggested by Development. It takes a slightly different approach, and assumes that you only need to save items that are in working storage (rather than those passed in linkage) and also that the items needing to be saved are all together in one contiguous section of memory. The program uses COBOL constant (78 Level) items that are inserted before and after the items to be saved, and these are used to calculate the size of the memory to save.

Please let me know if you have any questions about the attached examples.

Blair McDonald

Commander
Commander

Thanks @Blair McDonald and @Chris Glazier! An early Christmas present that I will share with the members of the dev team that are still toiling away during the Holidays.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.