Archive for July, 2015

C: Unit test of static functions (module local)

July 10, 2015

When you want to unit test the functions you do not export, i.e., you have defined them with the “static” keyword, there are three ways to accomplish this:

  1. Add the unit tests at the end of the file containing the static functions.
  2. Expose the function declarations in the header (probably guarded by some #ifdef UNIT_IMPL), and instead of writing static, use a preprocessor definition like VISIBILITY, which you redefine to an empty string if you want to build your unit test suite. Include the header in your separate unit test file.
  3. Include the file under test in the unit test file:

    // content of module_test.c:
    #include "module.c"
    // ...
  4. I find the 3rd way to be the most elegant.

    Advertisements

Change the extension of multiple files in Windows with one command

July 6, 2015

With the windows command “ren” (rename), it’s possible to rename multiple files in a specific way, but it’s not possible to remove the extension of multiple files. I wrote myself a script once that modifies text files in-place but first saves a backup copy to “%filename.bak”. If I want to restore the *.bak files, I need to remove the ending .bak only. This is possible with one command by using the “for” batch command like this:

for %x in (*.bak) do ren "%x" "%~nx"