So, what do these tests look like then?

After breaking the socket server into more manageable chunks I started writing the tests. CAsyncSocketConnectionManager is pretty easy to test, it only has one public function; Connect(). So, what exactly do these tests look like? I don’t use a unit testing framework at present, I haven’t found a need. Whilst NUnit and JUnit are great I don’t feel that the C++ version adds much as C++ doesn’t support reflection and that’s where these frameworks really seem to win.

How useful it could have been if...

I’m writing tests for some code. I have a function that I’m testing that looks something like this: bool CAsyncSocket::Read(bool throwOnFailure = false); If C++ allowed us to overload a function call based on return type then we wouldn’t need the horrible throwOnFailure wart and the compiler could pick the right version depending on if we try to use the return value or not… So a call like this: bool ok = pSocket->Read(); would return errors and a call like this: pSocket->Read(); would throw exceptions…

Hacking our way to the first test

So I have some time on my hands and I’ve decided that The Server Framework code could do with some tests but before I can do that I need to refactor because the code was written before I became test infected and, well, it’s not as good as it could be… Step one, as always, is to work on decoupling the code to the point that it’s easy to test. This generally involves breaking the code apart into more cohesive chunks and then writing tests for the chunks.

Admitting that your baby's ugly

I have a couple of days to myself. We’ve just shipped some code to a client a couple of days ahead of schedule and we’re waiting to recieve a purchase order from another client so I find myself without any client work to do. I’ve decided to try and refactor The Server Framework code that we’re using a lot right now. Whilst working on the code that we’ve just shipped I realised that the new code I was writing was much easier to test than the socket server library that formed a major part of the project, so now that I have some time I’m going to try and rectify that.

HeadCam2

My new head cam arrangement worked well in Meribel. As you can see from the picture below, the new camera is much smaller than my previous rig. The camcorder lives in my rucksack, the cables for video and remote control come out over my shoulder and the connections all happen in my chest pocket. The remote allows me to turn the camcorder on and off and start and stop recording. The bulletcam’s battery pack sits in my chest pocket and can be disconnected from the camera to save battery when not recording.

Oh good, comment spam

Just removed my first spam comments… It’s almost nice that the spammers think I’m worth spamming, but only almost… If this is anything like my email spam then I expect that this is just the start of a flood… Does anyone have any advice on how to prevent this kind of stuff when using MovableType as your blog software? I’ve added the spammer’s IP addresses to the list of addresses that can’t comment…

Back from Meribel

Just got back from a week’s skiing in and around Meribel. Great snow, great company, a good time was had by all. Just holiday snaps…. We stayed in the Indiana Lodge and travelled with VIP. Thanks to Eli and Al, our chalet hosts, for excellent service, great food and interesting puzzles over dinner. We had a couple of days of snowy weather at the start of the week and then mainly clear days.

Bitten by the one definition rule

I’ve just wasted 20 minutes or so on a nasty bug. I’d added a bit of test code and suddenly some other tests were failing but the reason for the failure seemed to be that a class’s vtable was getting screwed up and a virtual function was jumping off into hyperspace… After some time stepping through the code for a while I could see that a function that should have been incrementing a data member was in fact stomping over part of the vtable.

In C++ why isn't this a reference?

In C++ every object has a “this” pointer. You could think of it as being passed as an implicit argument to every non static member function that the object has. It can never be null so why isn’t it a reference? The reason I started wondering about this is that when using wiring objects together, such as when using parameterise from above, I often find myself wanting to pass a reference to the current class to some related object.