Category Archives: General

How to unit test C++ private and protected member functions?

In the unit testing world, sometimes we encounter a situation where we need to unit test private or protected member functions. There is a lot of arguments surrounding this topic. Some claim that if a private member function needs testing, it implies that there is a need for refactoring. However, I strongly feel that protected member functions are still APIs and people often are in a situation where they need to unit test some of them. One of the simple ways that I found was to declare the test suite class to be the friend of that is to be tested. It is better to scope the declaration in an #ifdef block.

class Foo {
  public:
#ifdef UNITTEST
    friend class FooTest;
#endif
    ...
 
  protected:
    ...
 
  private:
    ...
};

It would be even better to come up with an helper macro like the following.

#ifdef UNITTEST
#define ASSIST_UNIT_TEST( class__ ) friend class class__##Test
#else
#define ASSIST_UNIT_TEST( class__ )
#endif

And use the above macro in the class to be tested.

class Foo {
  public:
    ASSIST_UNIT_TEST( Foo );
    ...
 
  protected:
    ...
 
  private:
    ...
};

We can have the macro UNITTEST to define only for the unit test code. During this exercise, I found that I dearly missed __CLASS__ macro in C++ badly! I documented this approach in the cppunit FAQ page.

I have also tried to create a wrapper class that derives from the class to be tested and override the protected functions so that they are in the public scope of the derived class. This can help testing only protected member functions. However there is a lot of new code involved in the wrapper class to invoke the base class’ appropriate function. So, I consider this ineffective and error prone.

PS: If someone knows a better approach to do this in C++ please let me know.

Fix one; break two!

I am using Lenovo Thinkpad T60 that has ATI Mobility Radeon X1300 on it. I run Debian GNU/Linux sid on my laptop. Even though I am not extensively using a lot of 3D applications on my laptop, I am forced to use AMD’s proprietary fglrx driver so that I can have my dual screen setup running with AMD’s big desktop. I have used NVIDIA’s proprietary driver on Linux three years ago. It was much better even three years back compared to the crippled fglrx driver that AMD distributes currently.

I am so much annoyed with the driver releases that AMD makes. I was so unhappy that fglrx driver didn’t have AIGLX support. This kept me away from Compiz that I was running on my old laptop in spite of the fact that I just had a mediocre Intel graphics adapter. Finally AMD added the much awaited AIGLX support in fglrx 8.42. However, I was not able to run Compiz using that driver on my box as there was a bug that made it crippled with XOrg 1.4. That is not all of it. Scrolling in most of the applications had become very slow. I can’t do anything but to wait for the next driver release where things would be fixed.

Then came the fglrx 8.43 release. I didn’t see a significant stuff in the driver apart from their change of version number. Now the driver is known as “ATI Catalyst” and the version number uses y.mm format. I got ATI Catalyst 7.11. They didn’t even care to fix the bug that crippled the driver with XOrg 1.4. The scrolling speed issue is not fixed as well. The first application to communicate with the driver would hang eternally till you kill it. Wait, that is not all! It also brings a shiny memory leak issue in the OpenGL applications. What now? Wait for the next ATI Catalyst.

Here comes ATI Catalyst 7.12. They have fixed OpenGL memory leak issue. But the XOrg 1.4, scrolling speed, first application to communicate to the driver still stays. I got an added bonus. This driver breaks the support for wide screen resolutions for certain displays. Well, I was the unfortunate. My Thinkpad can’t run 1400×1050 anymore with this driver. It fell back automatically to 1024×768. It looked horrible! I had no option than to switch back to 7.11 and wait for 8.1, where they will ‘Fix one; break two’ again.

Here are the few thoughts that came to my mind after this whole experience.

  • I would never buy a ATI graphics card given the state of their Linux driver. I am planning to go for NVIDIA GeForce 8800 GT for the gaming PC that I would get assembled shortly. Can’t AMD realize that they are losing at least a bunch of customers because of their awful Linux driver?
  • It is clear that AMD’s driver release follows Iterative approach with an iteration cycle close to 4/5 weeks. If AMD can’t either add significant stuff to the driver or test the driver thoroughly, why don’t they revisit the iteration cycle? It makes no sense to me to release a quick degrading versions. Each incremental release should evolve consistently.
  • How many developers are working on the driver as of now? I guess it is one or maybe two. Does AMD find it difficult to hire developers for their Linux driver? I would expect that AMD should have atleast 4 developers dedicated to their driver development.

Name change – Praveen Ravi Kumar

One of the major headaches that I had after moving to the US was due to the way my name was handled in various places. I am from Tamil Nadu in India. In Tamil Nadu, we don’t have an official concept of last name. Instead, we have a concept known as “Initial” where we use father name’s first letter in front of the name. My name is Praveen Kumar and my father’s name is Ravi Kumar. So, I was called “R Praveen Kumar”. However, when I applied for an Indian passport back in 2003, I was asked to expand my initials as my last name. So, my name has become “Praveen Kumar Ravi Kumar” where “Praveen Kumar” was the first name and “Ravi Kumar” was the last name. Needless to say, we don’t have a middle name concept.

After I moved to the US, when I applied for a Social Security Card in the Social Security Office, the officer made “Praveen/Kumar/Ravi Kumar” as my first, middle and last names respectively. Living in the US with a last name that has two parts clearly caused a lot of confusion for me in the past five months. Also, I didn’t prefer “Kumar” to repeat twice in my name. So, I decided that I would adopt “Praveen/Ravi/Kumar” as my first, middle and last name respectively. It was not a straight forward procedure.

I had to file a petition in one of the Supreme Courts of California for a name change. As a part of this process, I had to advertise “Order to show cause” notice in a local newspaper for four consecutive weeks and attend a court hearing. In the meantime, I also had to publish an advertisement back in the area of my permanent residence in India. The latter procedure is required for getting my Indian passport updated with my new name. All these procedures burnt around USD 500 out of my pocket. Finally, I was granted a “Decree showing Name Change” by Fremont Hall of Justice a couple of weeks back.

Once I received the order, I had to go to the Social Security Office to get a new Social Security Card showing my new name. After a week, I got my Driver’s license updated with my new name in the DMV office. Finally, I had to notify my financial institutions and other places about my name change. I also applied for a new Indian passport. It was really annoying to get all these done. But I love the simplicity in Praveen Ravi Kumar!

My first car

I have bought (a month and a half back) a used Honda Civic LX 2001. The color is Burgundy. This is an automatic transmission vehicle. I was actually looking for a manual transmission vehicle (mostly Mitsubushi Lancer Rally). However, it was not that easy to find a good manual transmission car for low mileage within my budget. I bought this car from one of my colleagues. Initially I was not happy with the acceleration of the car. However, I started loving this car pretty soon. I was a bit scared to buy my first car. But, it has turned out to be really a nice one. It is more than a month and there are no issues so far. A couple of weeks back, I had to give her a jump start as I drained out my battery by leaving my headlights turned on.

Xorg 7.3 and AMD ATI driver fglrx 8.40.4 issue

Xorg 7.3 is now available in Debian sid. I am using fglrx 8.40.4 for my ATI Mobility Radeon X1300. Looks like fglrx 8.40.4 works only with XFree86 4.3 and X.Org 6.7, 6.8, 6.9, 7.0, 7.1, 7.2. When I restarted my X after the upgrade, it failed to start with the following message.

(II) LoadModule: "fglrx"
(II) Loading /usr/lib/xorg/modules/drivers//fglrx_drv.so
(II) Module fglrx: vendor="FireGL - ATI Technologies Inc."
        compiled for 7.1.0, module version = 8.39.4
        Module class: X.Org Video Driver
        ABI class: X.Org Video Driver, version 1.0
(EE) module ABI major version (1) doesn't match the server's version (2)
(II) UnloadModule: "fglrx"
(II) Unloading /usr/lib/xorg/modules/drivers//fglrx_drv.so
(EE) Failed to load module "fglrx" (module requirement mismatch, 0)

I can’t wait till I get updated driver from AMD. I have asked X to ignore ABI versions. If you are using gdm, edit /etc/gdm/gdm.conf to have the following lines at the end.

[server-Standard]
command=/usr/bin/X -audit 0 -ignoreABI

Font issues in shiny Gnome 2.20 under Debian

I have just upgraded to Gnome 2.20 in Debian sid. It just got released last Friday (Sep 21). Debian developers have impressed me this time with the speed they brought it to sid. Some packages are not yet available due to some dependencies and other usual stuff. The control center has gone through a major revamp. Looks like the new control center queries the X driver for DPI settings. Most of the X drivers still doesn’t report the DPI properly. Because of this, I was getting unusually huge fonts after my upgrade. To fix this, choose the DPI manually under “System -> Preferences -> Appearance -> Fonts -> Details”.

இருவது20 உலகக் கோப்பை இறுதிப் போட்டிக்கு இந்தியா storms

சனிக்கிழமை காலைல எழுந்திருச்ச உடனே நம்ம ரூமி (அதுதாங்க room mate), “Cricinfoல India Vs Australia match commentry பாருடா!” அப்பிடின்னாரு. “அமா! இவனுங்க என்னாத ஆடி, என்னாத ஜெயிச்சி!” அப்படின்னு சொலிகிட்டு, மத்த வேலைய பார்த்துகிட்டே scoreஅ track பண்ணேன். ரொம்ப நாளைக்கு அப்புறமா ஒரு நல்ல cricket match பார்த்த (cricinfoல தாங்க) திருப்தி! இது வரைக்கும் பல matchகல TVல live show பார்திருக்கேண். ஆனா பாருங்க, அது எதுலையும் இல்லாத ஒரு thrill இந்த ஒரு matchல இருந்தது. இந்தியா semi-final வரைக்கும் கூட போவாங்கனு யாரும் எதிர்பார்கலை. Tournament ஆரம்பிச்சதிலிருந்து யாருக்கிட்டையும் தோக்காத ஆடிக்கிடிருந்தாங்க South Africa. அவங்களை பாவம் ஒரே matchல கெலிச்சி வெளிய அனுப்பிசிட்டு உள்ள வந்தோமில்ல, அதையே இன்னும் நம்ப முடியல்லை! அதுக்குள்ள Australiaவையும் ஊத்தி மூடி வீட்டுகு அனுபிச்சாசி. Finalsல ஆடப் போறது இந்தியாவும் பாக்கிஸ்தானும். இதுல ஒரு comedy பாருங்க, இந்த ரெண்டு teamமையும் இந்த வருஷம் நடந்த ODI World Cup மொதல் roundலையே ஊட்டுக்கு அனுப்பிச்சி total damage பண்ணிட்டாங்க. பத்தாத குறைக்கு press, fans எல்லாரும் players மேல செம காண்டா ஆயிட்டாங்க. இதெல்லாம் தாண்டி இப்போ இந்த ரெண்டு teamமும் Twenty20 finals வந்தது பாராட்ட வேண்டிய விஷயம். ஆனா இதுல match fixing எதுனா இருக்குமோன்னு light ஒரு doubt வரத தவிர்க்க முடியல.

இதுல note பண்ண வேண்டிய matter என்னன்னா, இந்தியா first roundல வெளிய வந்திருந்தா கூட ஒன்னும் பெருசா feel பண்ணியிருக்க மாட்டோம். இப்போ finalல மட்டும் பாக்கிஸ்தான் கிட்ட தோத்தாங்கன்னா சங்கு தான்டியேய்! ஏலே Dhoni, Yuvaraj பாத்து ஆடுங்க, சொல்லிபுட்டோம்! World cupஅ கெலிக்காம உரப்பாக்க வந்திங்க, ஊட்ட கீட்ட எல்லாம் அடிச்சு காலி பண்ணிடுவோம்!

ஆனா, எனக்கு என்னமோ இந்த final matchஅ பத்தி யோசிச்சா, Chennai 600026 படத்தோட climax நியாபகத்துக்கு வந்து slightடா ஒரு hint தரமாதிரி தோனுது!

Dhoni: டேய் பஜ்ஜி, leg sideல போடாதடா! அவன் (Nazir) தான் அடிக்கிறான்னு தெரியுது இல்ல…
Harbajan: டேய் மச்சி, அவன் எங்க போட்டாலும் அடிகிறான்டா!

பின்குறிப்பு: அப்பாடா! ரொம்ப நாளா தமிழ்ல ஒரு entry போடாத குறைய போக்கியாச்சு!

Domain name change

I am planning to migrate my primary domain from praveen.ws to kumar.in. As a first step my blog is moved from the old place to here. If you have a direct bookmark to my blog, please update it accordingly. If you have subscribed to my RSS feed through Feedburner, you don’t need to do anything. I have taken care of my Feedburner feed to use my new blog instead of my old one. I have mostly migrated most of the stuff from the old domain to the new one. But you might see some visual changes here over the weekend as I tweak it. I have decided to give up using some of the WordPress plugins like IP2Country, user agent, nested comments and subscribe to comments that I used in my previous domain.

Java Microsystems, Inc., JavaOS and JavaFire

I really don’t understand the point how changing the ticker symbol from SUNW to JAVA is going to bring a great difference to Sun’s brandname. I would suggest some more brilliant changes like Java Microsystems, Inc., JavaOS, JavaFire, JavaOffice, JMC (Java Managament Center), Java Java (well, that is a Cafe in MPK campus), The Java newspaper (oops! that is not our brand; you gotta watch out!).

Jokes apart! I personally don’t think that it is a brilliant idea to change the name of the ticker from SUNW to JAVA. I don’t see a positive brand assoicated with Java anywhere. We practically saw the brand name of Java in JDS. Do we want to repeat that mistake again? I feel that Sun brand is more powerful than Java is. When I was a teenager, I knew StarOffice as a product of Sun Microsystems and not Sun Microsystems as a creator of StarOffice. The same is true with Java. Looking at comments on Jonathan’s blog, I am not the only guy who is unhappy about this. I am expecting that there would be a justification post made by Jonathan soon. It is a bad idea to name your ticker after a language or technology that could be easily extinct in a few years from now. SUNW = JAVA makes the same sense as IBM = COBOL, RHT = LNX, NOVL = MONO and APPL = IPOD.

Disclaimer: I am not speaking for my employer in this post. The views expressed herein are mine and should not be attributed to anyone else.

Lenovo Thinkpad T60

Lenovo Thinkpad T60

I got a new Lenovo Thinkpad T60 from my office. I am amazed to see the difference between this one and my previous laptop, Toshiba Satellite A80. Thinkpad is built so professionaly that I love the look and feel of the laptop. I got an ATI graphics card, fingerprint reader, faster RPM hard drive and a wonderful display that supports 1400×1050 resolution. I will soon write a post on getting Debian GNU/Linux on Thinkpad T60.