Day 18 : 14 July 2022 : Adding a Test Program

 

My 100 Daze of Code

https://github.com/davidjwalling/100-days-of-code

#18 : Adding a Test Program

To now, we've used the Ava program itself for testing. Now, though, we'll be starting to add a lot of code that performs specific algorithms related to message encryption, creation of digital signatures, compression, etc. So it's very helpful to have a dedicated program that will test the implementation of these algorithms before we have the Ava program use them.

We'll start on Windows and create a new Visual Studio project (.vcxproj, .vcxproj.filter, .vcxproj.user) that includes a single C++ source file, testava.cpp. For today, the test program will simply log a couple of startup messages and a completion message. Under the hood, though, I've made some other changes to enable calling the Log class methods from either the Ava or TestAva programs. This required making the "EXPORT" definition accessible independently from the "idriver.h" header where it had been located. A new "iapi.h" header is a public header (along with idriver.h) that will define, for now, only the EXPORT directive and will be included by both the Ava and the TestAva program.

iapi.h

There is nothing new here. I've just moved this code out of idriver.h so that it can be included by the test program. To be clear, this header is for any public definition that may be included by multiple top-level projects.


idriver.h

Since we've moved the EXPORT definition out of idriver.h, that header now needs to include the new iapi.h header.


api.h

Now api.h is a private header that would not be included in an SDK. But, it also may require use of public API definitions. So, we'll include iapi.h in api.h. The new "#include" statement is highlighted here. Note that the entire api.h is not duplicated here. Refer to the source code repository for that.


log.h

The Log class header file, log.h, already includes api.h. Now that api.h includes iapi.h, we can reference the EXPORT definition in log.h to export the LogWrite function. This allows us to call LogWrite, which is implemented in libava, from our top-level applications. We can add EXPORT to any function, class or method now that we want to access within the library.


testava.cpp

The test program simply has a main routine now. We've defined some extensions to the "cond" namespace to define our test program's log codes and message text. Also, the logging format strings have been defined in api.h so we don't have to use literals like "I%04 %s" repeatedly.

For the logging configuration here, we simply set the log file prefix to "testava".


Running the Test Program

Our test program simply logs startup and exit messages for now. Next time, we'll add some parameter handling and some common routines to invoke test routines.


CMakeLists.txt

Now on Linux and macOS, we build using CMake. so we'll create a new project definition in our CMakeLists.txt file.


Build and Run on Linux

Now our build and install steps include our test driver.


Build and Run on macOS





Comments

Popular posts from this blog

Day 12 : 19 June 2022 : Adding Windows Service Logic

Day 5 : 12 June 2022 : CMake on Windows

Day 11: 18 June 2022 : Handling Program Arguments