views:

387

answers:

4

Hi - I've got a PowerBuilder project that calls my .Net class library exposed to COM. I'm very new to PowerBuilder and just starting to pick it up. Id like to create some simple tests for my COM calls and I've looked for quite a while and can't find anything that is similar to the VS Diagnostics methods.

Does this functionality exist?

Thanks a lot!

+2  A: 

You can use the "/pbdebug" runtime switch, which creates a log file. Other than that you have to roll your own logging, PB (IMO) is notoriously hard to perform unit testing.

Otávio Décio
That's what I was afraid of thanks. For the time being I just created a window and dropped a text input on the form to pretty much do what I need.I was just hoping for a cleaner way.
dtrocchio
Some clarity: Typical legacy PB apps are notoriously hard to put into an automated unit test harness. A differently designed PB app would be far more amenable to such constructs.
Bernard Dy
+3  A: 

You can log a message through the Windows Debugging API and then with a suitable viewer your message will be visible.

See Use Windows Debugging API from Powerbuilder

RealHowTo
That's what I do, use OutputDebugString and display it with DebugView. (Love the PowerBuilder RealHowTo, btw).
Slapout
+3  A: 

I'm assuming you want to write custom data, not just the lines executed (which is sadly all you get from PBDEBUG; I've always wanted a custom data write to a PBDEBUG trace, but I've never been able to convince anyone at Sybase to add this to the product).

PFC

PFC offers a Debug service that does this, but if you haven't built your app with PFC already, it may require a moderate effort to adapt it to your infrastructure. If you've got a PFC-based app, all you have to do is

of_SetDebug (TRUE)

in the pfc_Open event of the Application Manager (or some other appropriate place), then start peppering your code with

IF IsValid (gnv_App.inv_Debug) THEN gnv_App.inv_Debug.of_Message (...)

This way, you can just remove the of_SetDebug() to turn off the messaging, without having to remove all the messages' code. (OK, in theory this will slow down your app a little, checking to see if IsValid () all the time.) I even put in code so that I can turn on the Debug Service with a command line option (that I don't tell the users about). That way, I can do this style of troubleshooting at the end-users' workstations (assuming I've anticipated the data I need to write).

Other

If I'm stuck with a non-PFC app, I'm afraid I'm usually too rushed (read: too lazy) to adapt the PFC debug service, so I just create a global function that does a FileOpen, FileWrite and FileClose on a hard-coded file name, writing the message passed in as a parameter. Then I load my code with calls to this function. In theory you could make this an empty function when it's time to deploy, but I have usually removed all the calls instead.

Terry
A: 

are you compiling for a .NET target?

In that case you should be able to use your .NET function:

#if defined PBDOTNET
   System.Diagnostics.Debug.WriteLine( .. )
#endif
Anders K.