February 25, 2013

Renaming files

Lately I tried to order a bunch of my old photos. All imported from CD, with similar names (guess it was from back when the digicams started over once they'd lost their battery?).

Any huh I needed to rename some photos when there was a name clash, and I didn't bother pointing and clicking in this case. Here's a small command line renamer:

for i in *.jpg ; do mv $i new_name${i#01} ; done

Have fun!

February 18, 2013

UnitTest++

Writing unit tests for your C++ code is sometimes painful. But fear no more, with UnitTest++ and it's fixture feature, your shared data between the individual tests becomes so easy to set up it's almost cheating! Sweet!


The code in the tweet is for the svn version of the unittest++ framework, not the one available in google code!!

Just dump the files in your test directory and use them like this:

#include <fstream>
#include <unittest++/UnitTest++.h>
#include <unittest++/TestRunner.h>
#include <test_reporter_junit.h>

using namespace std;
using namespace UnitTest;

int main()
{
    ofstream f("test-report.xml");
    Test_reporter_junit reporter(f);
    TestRunner runner(reporter);
    return runner.RunTestsIf(Test::GetTestList(),NULL,True(),0);
}