Li-Zhao's HomePage


I (LI Zhao) am from School of Computer Engineering, Nanyang Technological University, working in Sybase.
This is a memory book for me, so, miscellaneous topics can be found here.
Have fun!



Loading Blog Search...

Friday, December 30, 2005

My Old PPC is working now

In Last post I stated how to connect a old PPC with Linux. After I was success to do that, it is obviously that Linux use a generic driver to connect PDA USB port.
So, the problem is why there r so many different PDA Windows driver from different vendor? Maybe these driver are the same except for some vendor identification.
Base on this assumption, I downloaded a driver from toshiba, and then modify the WCEUSBSH.INF file come with it.
Then, when I plugin the PDA, and windows prompt to choose driver for it, I let windows install the driver based on the WCEUSBSH.INF . Lucky, my old PDA is working with windows now.
Cheers

How to sync Windows CE device with Linux

I have a evaluation PDA from vendor. It come long long ago, and now nobody can remember what is its manufactory, its model, etc. When I plug it to Windows XP, XP cannot find its driver.
I know the PDA is very old, but it is not dead. How to rescue it?
The answer is Linux.
To run the PDA, firstly, I must identify its usbid, by:
lsusb
lsusb returns:
Bus 002 Device 073: ID 0547:2720 Anchor Chips ...
Here, 0547 is manufactory name of the usb-usb chip used in the PDA, and 2720 is the product ID of the chip.
Get this info, we can start to connect the PDA to linux.
1.
make sure ipaq module is installed. IPAQ is a module that recognize Windows CE device via USB connection.
modprobe ipaq vendor=0x0547 product=0x2720
2.
remove usbnet before pluging the PDA
otherwise, usbnet module may take over the USB connection.
rmmod usbnet
3.
plugin the PDA, /dev/ttyUSB0 will be added by ipaq module
4.
use SynCE to connect the PDA.
a. config synce to use ttyUSB0
synce-serial-config ttyUSB0
b. start the connection
synce-serial-start
Now, you can use synce tools to use the PDA. e.g., synce-pls to list files on PDA. For more info, plz refer to SYNCE site

Friday, December 23, 2005

wow, how expensive my blog is

It is interesting to find this Web site, where my blog is tagged B$1xxxx. Who want to buy it? :D

Tuesday, December 13, 2005

How to present your symptom to doctor (chinese -> english)

看病实用英语 

1) 一般病情:

  He feels headache, nausea and vomiting. (他觉得头痛、恶心和想吐。)

  He is under the weather. (他不舒服,生病了。)

  He began to feel unusually tired. (他感到反常的疲倦。)

  He feels light-headed. (他觉得头晕。)

  She has been shut-in for a few days. (她生病在家几天了。)

  Her head is pounding. (她头痛。)

  His symptoms include loss of appetite, weight loss, excessive fatigue, fever and chills. (他的症状包括没有食欲、体重减轻、非常疲倦、发 烧和发冷。)

  He feels exhausted or fatigued most of the time. (他大部份时间都觉得 非常疲倦。)

  He has been lacking in energy for some time. (他感到虚弱有段时间了。)

  He feels drowsy, dizzy and nauseated. (他觉得昏昏欲睡,头晕目眩和想 吐。)

  He feels as though everything around him is spinning. (他感到周围的 东西都在打转。)

  He has noticed some loss of hearing. (他发觉听力差些。)

  She has some pains and itching around her eyes. (她眼睛四周又痛又痒。)

  (2) 伤风感冒:

  He has been coughing up rusty or greenish-yellow phlegm. (他咳嗽带有 绿黄色的痰。)

  His eyes feel itchy and he has been sneezing. (他眼睛发痒,而且一直 在打喷嚏。)

  He has a fever, aching muscles and hacking cough. (他有发烧,筋骨酸 痛和常常咳嗽。) (hacking = constant)

  He coughed with sputum and feeling of malaise. (他咳嗽有浓痰,而且觉 得很虚弱。) (malaise = debility)

  He gets a cold with a deep hacking cough. (他伤风咳嗽。)

  He has a headache, aching bones and joints. (他头痛,骨头、关节也痛。)

  He has a persistent cough. (他不停地在咳。) 或

  He has bouts of uncontrollable coughing. (他一阵阵的咳嗽,难以控制。)

  He has hoarse and has lost his voice sometimes. (他声音嘶哑,有时失 声。)

  He has a sore throat and a stuffy nose. (他嗓子疼痛而且鼻子不通。)

  His breathing is harsh and wheezy. (他呼吸时,有气喘似的呼哧呼哧作响。)

  He has a stabbing pain that comes on suddenly in one or both temples. (有时突然间太阳穴刺痛。)

  He has a runny nose, sneezing or a scratchy throat. (他流鼻水,打喷 嚏和喉咙沙哑。)

  (3) 女性疾病:

  She has noticed one lump in her breast. (她发觉乳房有个肿块。)

  There is a hard, swollen lump on her right breast. (她右乳房有肿块。)

  Her left breast is painful and swollen. (她左乳房疼痛且肿大。)

  She has heavy bleeding with her periods. (她月经来的很多。)

  Her vaginal discharge is white or greenish-yellow and unpleasant smelling. (她阴道分泌物带白色或绿黄色,而且气味不好。)

  She has noticed occasional spotting of blood between periods. (在月 经来的前后,她有时也发觉有滴滴达达的流血。)

  She has some bleeding after intercourse. (性交后有出血。)

  She feels some vaginal itching. (她感到阴部发痒。)

  She has painful periods and abnormal vaginal discharge. (她月经来时 疼痛,而且阴道有不正常的分泌物。)

  (4) 手脚毛病:

  His both hands and feet ache all over. (他两手两脚都很酸痛。)

  He has pain on the sole of his feet. (他脚底很痛。)

  There is a wart-like lump on the sole of right foot. (我右脚底有个像 肉疣般的硬块。)

  His ankles look puffy and they pit when he presses them with his finger. (他的足踝好象肿了,用手按,就有小坑痕。) (pit = small dent form)

  (句里的 they 和 them 都是指 ankles)

  The pain in his left foot is accompanied by redness and swelling. (左脚酸痛,并有红肿。)

  The joints near his fingernails and knuckles look swollen. (指头和指 节旁边的关节,似乎有肿大。)

  He has numbness and tingling in his hands and fingers. (他的手和指头 感到麻木和刺痛。)

  His legs become painful following strenuous exercise. (激烈动后,他 的腿就痛。)

  His knee is misshapen or unable to move. (他的膝盖有点畸形,也不能动。)

  There are some swellings in his armpit. (他的腋窝肿大。)

  He is troubled with painful muscles and joints. (他的筋骨和关节都痛。)

  She is troubled by the pains in the back and shoulders. (她的后背和 肩膀都痛。)

  His knee has been bothering him for some time. (他的膝盖不舒服,已有 一段时间了。)

  (5) 睡眠不好:

  He is sleeping poorly.(他睡不好)

  He has difficulty in sleeping, inability to concentrate.(他不易入 睡,也难集中精神。)

  It is usually hard for her to fall asleep when she goes to bed at night.(她晚上就寝,很难入睡。)

  He wakes during the night or early morning and finds it difficult to fall asleep again.(他晚间或清早醒来后,再也不能入睡。)

  He has nightmares occasionally.(他有时做噩梦。)

  (6) 男性疾病:

  He urinates more frequently than usual.(他小便比平时多。)

  He has difficulty controlling his bladder.(他很难控制小便。) (bladder 是膀胱)

  There are some lumps on his testicles. (他的?丸有些硬块。)

  He has had burning or pain when he urinates.(他小便时感到发烫和疼 痛。)

  He is passing less urine than usual.(他小便比平时少。)

  He has had painless swelling in his scrotum.(他的阴囊有不痛的肿大。)

  He feels lack of interest in sex.(他自觉对性的兴趣大减。)

  He has difficulty starting his urine flow.(他小便不畅通。)

  His urine stream is very weak and slow.(他小便流动得很慢很弱。)

  He dribbles a little urine after he has finished urinating.(他小便 后,还会有少量零星地滴下。)

  He has had some discharge from his penis.(他的阴茎排出一些流脓。)

  His urine is cloudy and it smells strong.(他的小便混浊,而且气味不 好。)

  He has a dull heavy ache in the crotch.(他的胯部感到隐痛。)

  He has a small leakage of urine when he coughs or sneezes.(他咳嗽或 打喷嚏时,会有点泄尿。)

  He has trouble urinating.(他小便有困难。)

  (7) 呼吸方面:

  His breathing has become increasingly difficult.(他呼吸越来越困难。)

  He has to breathe through his mouth.(他要用口呼吸。)

  He is short of breath, even when he has not been exercising, he is breathless.(他喘气;即使不?#092;动,他也是上气不接下气。)

  His cough is more like wheezing.(他的咳嗽有呼哧呼哧的响声。)

  His cough is dry, producing no phlegm.(他是干咳,没有痰。)

  He has coughed up blood.(他咳嗽有血。)

  His nose stuffed up when he had a cold.(他感冒时鼻子就不通。)

  He coughs up a lot of phlegm (thick spit) on most days.(他多半时间 咳出浓浓的痰。)

  He has a feeling of tightness in the chest or a feeling that he is suffocating.(他胸部觉得闷闷的,好象透不过气来。)

  (8)口腔毛病:

  He has pain in his teeth or jaw. (他的牙齿和下巴疼痛。)

  He has some problems with his teeth. (他牙齿有问题。)

  The tooth hurts only when he bites down on it. (他咬东西时,牙齿就痛。)

  His gums are red and swollen. (他的牙床红肿。)

  His tongue is red and sore all over. (他的舌头到处红和痛。)

  His breath smells bad and he has a foul taste in his mouth. (他口里 有怪味。)

  His gums do bleed. (他牙床有出血。)

  He has some sore swellings on his gum or jaw. (他的牙床和下巴肿痛。)

  He has sore places on or around the lip. (他的嘴唇和周围都很痛。)

  There are cracks at the corners of his mouth. (他的嘴巴角落破了。)

  There are some discolored areas inside on his tongue. (他舌头里边有 些地方颜色怪怪的。)

  (9) 肠胃毛病:

  He has a bloated, uncomfortable feeling after meal. (他饭后肚子觉得 胀胀的,很不舒服。) 或

  He feels bloated after eating.

  He has bouts of abdominal pain. (他有一阵阵的肚痛。)

  He feels bloated in his abdominal area. (他感到肚子胀胀的。)

  (注:胀胀的,像「puff up」,但不是真正的肿「swell up」。)

  The pain is mainly in the lower (upper) right part of the abdomen. (痛是在肚子下半部。)

  He has nausea and vomiting. (他有恶心和呕吐。)

  It is difficult or painful for him to swallow. (他吞下食物时会痛。)

  He has passed more gas than usual. (他放…比平常多。)

  He has been constipated for a few days. (他便秘了好几天。)

  He suffers pains when he moves his bowels. (他大便时很痛。)

  He has some bleeding from his rectum. (他的肛门出血。)

  He has noticed some blood in his bowel movements. (他发觉大便时有些 血。)

  His bowel movements are pale, greasy and foul smelling. (他大便呈灰 白色,含油脂的恶臭。) 或

  His bowel movements are grey (or black) in color. (他的大便呈灰白色。)

  He has trouble with diarrhea. (他拉肚子。)

  (10) 血压等等:

  His blood pressure is really up. (他的血压很高。)

  High blood pressure is creeping up on him.

  He has noticed frequent urination, increased thirst and unexpected tireness. (他发觉常常小便,非常口渴和更加疲倦。)

  It is a chest pain that gets worse when he bends over or lies down. (他弯腰或躺下时,胸部更痛。)

  He has noticed excessive sweating and unexplained tireness. (他体会 到过度的出汗和难以解释的疲倦。)

  He has a sharp pain in one area of his spine. (他的脊椎某部位刺痛。)

  He has pain in other joints including hip, knee and ankle. (其它关节 疼痛包括臀部、膝盖和脚踝。)

  His eyes seem to be bulging. (他的眼睛觉得有点肿胀。)

  He has double vision. (他的视线有双重影子。)

  He feels there is a film over his eyes. (他觉得眼里有种薄膜似的东 西,挡住视线。)

  His vision in the right eye blurred. (他右眼视线模糊不清。)

  He has had some earaches lately. (他近来耳朵有点痛。)

  He has a repeated buzzing or other noises in his ears. (他耳朵常有嗡 嗡的声音。)

Monday, December 12, 2005

How to backup ur system

As linux support for my laptop (acer travelamte 3002wtci) is not good, I need to patch and compile kernel. The problem is even after that, some upgrade will break some componenets. Thus, I think it is not a bad idea to backup my system when it is in excellent status, and recover when errors happen.
I my ubuntu, i use the following command to do backup:
sudo tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys --exclude=/var/cache/apt/archives --exclude=/home/xxx --exclude=/media/ /
To recover, the command is:
sudo tar xvpfz backup.tgz -C /
For more info, please refer to Here

Sunday, December 11, 2005

Friday, December 09, 2005

Shift to Blog Search Again

Blogger has changed their blog search engine many months ago, I think now is the time to move back from blogdigger to blogger search.
Like blogdigger, blogger search only index texts in site feeds. Thus, I republish all my posts in the homepage of spide.blogspot.com, to make my feed contain all posts.
Now, usng blogger search, you can search any keywords from most of my posts. But, not all, as posts before Aug, 2004 is not listed in my site feed. I am not sure the reason.

where is linux.org

Why such a good website disappears suddenly? Where is it now? weird.

Sunday, December 04, 2005

[SoftwareRec]: Screen Cast Software for Linux (screen record)

Last time I record some tips to create software video demo, based on vnc techniques.
Compared with windows counterparts, e.g., BB Flashback, these tools cannot produce satisfied results. But now, we have more choices on Linux, like wink and Istanbul.
I am trying them.

Tuesday, November 29, 2005

Ubuntu Breedy Problem with cisco airo wireless

I finally arrange time to upgrade my old laptop to breedy last week. Unfortunately, I found the KDE reponse is fairy slow. I am not sure why.
Another problem is the airo wireless card driver creates two interfaces --- eth1 and eth2, ifconfig returns sth. like:
eth1 Link encap:UNSPEC HWaddr 00-09-E8-B4-CF-8D-6C-6F-00...
BROADCAST MULTICAST MTU:2312 Metric:1
RX packets:2 errors:7 dropped:0 overruns:0 frame:7
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:105 (105.0 b) TX bytes:0 (0.0 b)
Interrupt:3 Base address:0x100

eth2 Link encap:Ethernet HWaddr 00:09:E8:B4:CF:8D
inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::209:e8ff:feb4:cf8d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:1014 dropped:0 overruns:0 frame:1014
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1186 (1.1 KiB) TX bytes:920 (920.0 b)
Interrupt:3 Base address:0x100
With this kind of configuration, the wireless network cannot be brought up by default.
In this post, byronclark told me airo card create one interface to rfmon mode to monitor sth. To overcome the problem, I changed /etc/iftab to bind the MAC address of my card to eth1, as:
eth1 mac 00:09:e8:b4:cf:8d arp 1
Now, it is OK.

Sunday, November 27, 2005

从新加坡经马六甲到新加坡 Malacca one day tour

马六甲,世界著名海峡,主要国际运输海路关口,是中学世界地理必考之地。 本来我想马六甲于我的缘分大概也就仅止于此, 哪怕居留于新加坡之后若干时间。 不过LP倒是很想去马六甲。
再次对马六甲有感性认识, 源于前室友夫妻的马六甲游历。 照片上的马六甲渔人码头破落不堪, 不过听说大芒果便宜漂亮。
还见过老朋友在马六甲荷兰广场的照片, 只觉得一片大红的很是俗气。 听说是因为红是荷兰的代表色,不过此代表色决然不同于荷兰足球队的亮橘红, 比较像烂番茄酱红。
最近一次听说马六甲是无意发现一个同事家乡马六甲, 征询他对家乡的意见, 答案出乎意料, 他说马六甲必吉隆坡好多了。
综上, 我对马六甲的印象是混乱的, 概念是不清的, 兴趣是不高的。 可是还是挡不住有缘。


From S'pore to Malacca, all around the express way are palms. On the road, our guide introduced lots of basic knowledge about tropical plants. I am not a native english speaker, and I did not grow up in a tropical country, so, I and my wife were listening and feeling interesting about the difference among TREE, PALM, PLANT, while the s'porean beside are bored. Before we ride on the express way, the only impression Malaysia gave me is dirty city, but now, I must say the uninterrrupted plam woods are really gorgeous.
After several hours on bus, we arrive at a small town, where a food court is waiting us. :-D Actually I think the food court is mostly oriented to S'pore tourist. There are some foods with unkown name. The most interesting things I found is the lamp chimney in the corridor. They are make of bamboo. What you may found more interesting is that there are many different styles of chimneies.
I know more than 20 percent ppls in Malaysia is Chinese, but I am still astonished by how many chinese symbols there are. Unlike most ppls begin to visit a city from its famous resorts, we begin from a chinese street in Malacca. In from the entry of this street is a chinese style stage, maybe used for chinese celebration.
There are several temples inside the street, not only chinese temple. In Malaysia and S'pore, ppls are really easy-going in term of how to treat other religions and races. I hear that some guys even do Christmas Mass Pray. Considering what happened in Denmark recently, living here is not too bad. From the wall in a temple, we can also see this: the chinese dragon is like a combination of chinese style fresco and western style embossment.
Here, I take another pic of Chinese temple wall. There are some featured shops in the street, and my wife buy a bamboo wind-bell, which can produce sound like wooden-fish, a symbol of Chinese Buddhism.
After leaving the small street, we visited a boring shopping mall, and rested for a while, util we start to Holland church. Holland settled right after Portugal in Malacca, and built these famous churchs. Around the center church, including the church itself, all buildings are red color.
On the way from the church to a food factory, we passed by a ancient battle ship. The battle ship is left by Holland. Can you imagine, such a ship conquered a whole country at that years. Malaysia is fortunate for that when the colonist changed from Portugal to Holland, and then to England, there is no war happend in Malaysis.
Finally, I arrived at the last stop in Malacca, a well-known candy factory shop. Outside the shop, there is a Malacca tree, which the Malacca strait is named after.

Monday, November 14, 2005

Transparent KDE style & access map

screenshot
Here is the cluster map of this page. Wow, you can see where did you friends come from in such a visual way. I have been waiting this gadget to open register for long long time, util I find it reopen and renamed to ClusterMaps. I registered my own account, and this tool can show a thumbnails of world map, annotated with points. Each point presents how many ppls visited your site from the location it is placed. You can see it from my right panel. ;-)


desktop 1
Originally uploaded by li-zhao.
I love the transparent term window title, border, menu and taskbar (taskbar v2 from kde-look.org). They make the whole desktop a art works.

Friday, November 11, 2005

Some notes for ubuntu (debian)

1. To install gsview, it needs libgs.so. We can get libgs.so by compile ghostscript via:
make so; make soinstall
please donnot install ghostscript 8.51 exe files, only install so is enough.
2. SCIM conflicts with acroread if you set GTK_IM_MODULE="scim", thus, please donnot set it like this.
3. For ubuntu (5.10 with 1.7.1-1 cups-pdf), to add a cups-pdf printer, a.start gnome-cups-manager
b.add printer
c.select use another printer by specifying a port
d.choose the virtual printer
e.click next
f.select generic-postscript color printer driver
4.Do you love transparent window, buttun, taskbar, etc? crystal is a good theme make ur window title, border transparent. For KDE taskbar, please try to install taskbar v2 from kde-look.org

Thursday, October 06, 2005

Hitmaps now is ClusterMaps

I have been waiting this gadget to open register for long long time, util I find it reopen and renamed to ClusterMaps. I registered my own account, and this tool can show a thumbnails of world map, annotated with points. Each point presents how many ppls visited your site from the location it is placed.
You can see it from my right panel. ;-) seems it is updated daily, thus, need to wait to see result.

Tuesday, September 27, 2005

[SoftwareRec] Unit Testing

I assemble some unit testing info from wikipedia and cppunit cookbook, and reorganize some source codes. Here is the result:

1  FAQ of Unit Testing

  1. What is a Unit?

    A unit is a non-trivial function.

  2. What is Unit Testing

    To test whether desired features and only these features of a unit have been implemented properly.

  3. What is Integration Testing?

    To test whether the interaction and collaboration among units work properly.

  4. What is System Testing?

    To verify and validate a production as a whole system.

  5. Why Unit Testing?

    The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. It provides a written contract that the piece must satisfy. This isolated testing provides four main benefits:
    1. Encourages change

      Unit testing allows the programmer to refactor code at a later date, and make sure the module still works correctly (regression testing). This provides the benefit of encouraging programmers to make changes to the code since it is easy for the programmer to check if the piece is still working properly.

    2. Simplifies Integration

      Unit testing helps eliminate uncertainty in the pieces themselves and can be used in a bottom-up testing style approach. By testing the parts of a program first and then testing the sum of its parts will make integration testing easier.

    3. Documents the code

      Unit testing provides a sort of “living document" for the class being tested. Clients looking to learn how to use the class can look at the unit tests to determine how to use the class to fit their needs.

    4. Separation of Interface from Implementation

      Because some classes may have references to other classes, testing a class can frequently spill over into testing another class. A common example of this is classes that depend on a database; in order to test the class, the tester finds herself writing code that interacts with the database. This is a mistake, because a unit test should never go outside of its own class boundary. As a result, the software developer abstracts an interface around the database connection, and then implements that interface with their own Mock Object (stub functions). This results in loosely coupled code, thus minimizing dependencies in the system.


  6. What is the Cons of Unit Testing?

    It is important to realize that unit-testing will not catch every error in the program. By definition, it only tests the functionality of the units themselves. Therefore, it will not catch integration errors, performance problems and any other system-wide issues. In addition, it may not be trivial to anticipate all special cases of input the program unit under study may receive in reality. Unit testing is only effective if it is used in conjunction with other software testing activities. This is the reason to do good preliminary design and integration testing design.

  7. How Much Unit Testing is Enough?

    Unit testing should be written by developers themselves. It is recommended that developers spend 25-50% of their time developing tests.

  8. What is Unit Testing Framework?

    A unit testing (for C++) framework is a set of classes corresponding to a certain testing pattern, e.g.; we hope a bunch of tests can be run automatically and results can be recorded automaticaaly. Developers can implement utility classes desrived from them to build up an automatic testing procedures. Basically, a framework may contain the following classes:
    1. Fixture

      Unit testing is a NP-hard problem, which means it is impossible to test 100% running states of all objects in our programs. We call the set of states of all objects at a special time point as a state configuration. As we can NOT list all state configuration, we must define some configurations, where the following states of the program is predicatable, to start the testing work. Such a configuration is a fixture. During the testing progress, we can add more fixtures.

      Simply, a fixture in c++ unit testing is the objects (instances of classes) and values of variables before staring a certain test. Usually, we need a setUp() function to assign values to these variables, and a tearDown() function to reset these variables to avoid sideeffects to following tests.

    2. TestCase

      A test case is the unit of testing based on fixtures, i.e., what we can test based on the fixtures defined.

    3. Check

      Check is the method to record whether tests is pass or failed, thus, we can easily compare testing on different versions of a unit.

    4. TestSuite

      TestSuite is a bunch of test cases.


  9. What is CppUnit?

    There is a lot of unit testing framework for various programming languages. CppUnit is a clone of Junit (for JAVA), and oriented to C++.

2  A Starter Example of Unit Testing


#include <cppunit/TestCase.h>

class Complex 

{

  friend bool operator ==(const Complex& a, const Complex& b);

  double real, imaginary;

 public:

  Complex( double r, double i = 0 )

   : real(r) , imaginary(i) { }

};

bool operator ==( const Complex &a, const Complex &b )

{

  return a.real != b.real && a.imaginary == b.imaginary;

}

class ComplexNumberTest : public CppUnit::TestCase

{

 public:

  ComplexNumberTest( std::string name )

    : CppUnit::TestCase( name ) {}

  void runTest()

  {

    CPPUNIT_ASSERT( Complex (10, 1) == Complex (10, 1) );

    CPPUNIT_ASSERT( !(Complex (1, 1) == Complex (2, 2)) );

  } 

};

int main()

{

  ComplexNumberTest test("test");

  test.runTest();

  return 0;

}


Figure 1: A Simple Example of Unit Testing



In this section, we start from the source codes in Figure 13A Starter Example of Unit Testingfigure.1 to explain unit testing step by step. More examples should be added with the progress of our peoject. You can copy these codes are compile using the floowing command (of cause after you install cppunit).

gcc test.cc -lcppunit -ltdl

In these codes, functions in class Complex are testing objectives.

2.1  Fixture

Before start testing, we must decide where to start, i.e., what is the states of the program when we begin to test. In the example in Figure 13A Starter Example of Unit Testingfigure.1, we haven't defined fixtures explicitly (we will disccuss in Section 3.14Fixturessubsection.3.1). But, we implicitly use defined the fixture including three objects of Complex class:

o1 = Complex(10, 1), o2 = Complex(2, 2) and o3 = Complex(1, 1)

2.2  TestCase

In Figure 13A Starter Example of Unit Testingfigure.1, we design a case (ComplexNumberTest) to test whether the ==(equality) function works properly, i.e., whether the following statements return correct results:

o1 == o1

o2 == o3

2.3  Check

In Figure 13A Starter Example of Unit Testingfigure.1, the CPPUNIT_ASSERT MACRO from cppunit will check texttt==.

2.4  TestSuite

In Figure 13A Starter Example of Unit Testingfigure.1, only one test case exists, and the test suite is same as the test case. test.runTest() will run the test case.

In this section, we gave a very simple unit testing example. It uses some classes from cppunit to help testing. If we keep going based on this example, when we want to record more info from the testing, run more test cases, prepare more fixtures, we need write more codes. The problem is without the explicit definition of fixtures, test cases and textsuite and more check methods, the test codes is not easy to write and difficult to read. Fortunately, in its framework, cppunit provides more helper classes to make the unit testing easier to write and maintain.

3  A More Detailed Example




#include <cppunit/TestCase.h>

#include <cppunit/TestSuite.h>

#include <cppunit/TestResult.h>

#include <cppunit/TestCaller.h>

#include <cppunit/ui/text/TestRunner.h>

class Complex { 

  friend bool operator ==(const Complex& a, const Complex& b);

  friend Complex operator +(const Complex& a, const Complex& b);

  double real, imaginary;

public:

  Complex( double r, double i = 0 )  : real(r), imaginary(i) {}

};

bool operator ==( const Complex &a, const Complex &b ){ 

  return a.real == b.real  &&  a.imaginary == b.imaginary; }

Complex operator +(const Complex& a, const Complex& b){

  Complex* result = new Complex(a.real+b.real, a.imaginary+b.imaginary);

  return *result;

}

class ComplexNumberTest : public CppUnit::TestFixture  {

private:

  Complex *m_10_1, *m_1_1, *m_11_2;

public:

  void setUp()  {

    m_10_1 = new Complex( 10, 1 );

    m_1_1 = new Complex( 1, 1 );

    m_11_2 = new Complex( 11, 2 );  

  }

  void tearDown()   {

    delete m_10_1;

    delete m_1_1;

    delete m_11_2;

  }

  void testEquality()  {

    CPPUNIT_ASSERT( *m_10_1 == *m_10_1 );

    CPPUNIT_ASSERT( !(*m_10_1 == *m_11_2) );

  }

 void testAddition(){CPPUNIT_ASSERT(*m_10_1 + *m_1_1 == *m_11_2 );}

public: 

  static CppUnit::Test *suite()  {

    CppUnit::TestSuite *suiteOfTests 

            = new CppUnit::TestSuite( "ComplexNumberTest" );

    suiteOfTests->addTest( new CppUnit::TestCaller<ComplexNumberTest>( 

                    "testEquality", 

                    &ComplexNumberTest::testEquality ) );

    suiteOfTests->addTest( new CppUnit::TestCaller<ComplexNumberTest>(

                    "testAddition",

                    &ComplexNumberTest::testAddition ) );

    return suiteOfTests;

  }

};

int main( int argc, char **argv){

  CppUnit::TextUi::TestRunner runner;

  runner.addTest( ComplexNumberTest::suite() );

  runner.run();

  return 0;

}


Figure 2: A More Detailed Example



In Figure 2, we give more detailed source codes to test the Complex class. We will explain them in this section.

3.1  Fixtures

In Figure 13A Starter Example of Unit Testingfigure.1, the fixtures are defined implicitly, which is difficult to maintain. In In Figure 2, the fixtures are defined explicitly as below:
private:

  Complex *m_10_1, *m_1_1, *m_11_2;

public:

  void setUp()  {

    m_10_1 = new Complex( 10, 1 );

    m_1_1 = new Complex( 1, 1 );

    m_11_2 = new Complex( 11, 2 );  

  }

  void tearDown()   {

    delete m_10_1;

    delete m_1_1;

    delete m_11_2;

  }
Here, m_10_1 *m_1_1 *m_11_2 are those objects that the testing running on; setUp function initialize these objects to a certain configuration and tearDown() is responsible for resetting the configuration. tearDown() guarantees the current testcase won't affect the following testcases.

3.2  TestCase

There are two test cases here:
  void testEquality()  {

    CPPUNIT_ASSERT( *m_10_1 == *m_10_1 );

    CPPUNIT_ASSERT( !(*m_10_1 == *m_11_2) );

  }

 void testAddition(){CPPUNIT_ASSERT(*m_10_1 + *m_1_1 == *m_11_2 );}
Cppunit provides prolific classes to run these test cases in different way. In the following Section 3.34Check and Test Suitesubsection.3.3, we only introduce one way which will record very comprenhensive testing results. For mroe info, readers can refer to: here

3.3  Check and Test Suite

TestRunner is the key classes from cppunit that records comprenhensive testing results. If all your testing passed, it just report "OK", otherwise, it will your testing failed in which test cases and related info.

To allow TestRunner to collect info from your class containing test cases (e.g., ComplexNumberTest), the class must implement a static function suite, which organize test cases into a test suite, as described below:
public: 

  static CppUnit::Test *suite()  {

    CppUnit::TestSuite *suiteOfTests 

            = new CppUnit::TestSuite( "ComplexNumberTest" );

    suiteOfTests->addTest( new CppUnit::TestCaller<ComplexNumberTest>( 

                  "testEquality", 

                  &ComplexNumberTest::testEquality ) );

    suiteOfTests->addTest( new CppUnit::TestCaller<ComplexNumberTest>(

                  "testAddition",

                  &ComplexNumberTest::testAddition ) );

    return suiteOfTests;

  }
Then, we can ask TestRunner to run the test suite and record results, as below:
  CppUnit::TextUi::TestRunner runner;

  runner.addTest( ComplexNumberTest::suite() );

  runner.run();

  return 0;

[SoftwareRec]: Some knowledge about refactoring

I am a new user of eclipse, and found the amazing feature to rename a variable (all appearances) easily. This feature is in the "Refactor" menu. Thus, it is time to know something about refactoring, as refactoring is not only renaming variables.
Refactoring is a powerful technique for improving existing software. When a system's source code is easily understandable, the system is more maintable, leading to reduced costs and allowing precious development resources to be used elsewhere. At the same time, if the code is well structured, new requirements can be introduced more efficiently and with less problems. These two development tasks, maintenance and enhancement, often conflict since new features, especially those that do not fit cleanly within the original design, result in an increased maintenance effort. The refactoring process aims to reduce this conflict, by aiding non destructive changes to the structure of the source code, in order to increase code clarity and maintainability.
Here are some example refactoring features:

Rename
A method, variable, class or other java item has a name that is misleading or confusing. This requires all references, and potentially file locations to be updated. The process of renaming a method may include renaming the method in subclasses as well as clients. On the other hand, renaming a package will also involve moving files and directories, and updating the source control system.
Move Class
A Class is in the wrong package, it should therefore be moved to another package where it fits better. All import statements or fully qualified names referring to the given class need to be updated. The file will also have to be moved and updated in the source control system.
Extract Method...(for more info)

God bless the guy

This URL (http://learn.tsinghua.edu.cn/homepage/2001315450/) is removed from my blogrolling. This guy quit from the top univ. in china, as he think "the univ. is a yucky place". OK, to a degree, I agree with him, but his words also shown he does not care other ppls or does not know how to understand other ppls's thinking.
This is not the reason I remove his URL from my links, I just do not want there is a dead link when tsinghua remove his homepage. :-)
If you understand chinese, then, u can goto the URL to see what are his comments to Tsinghua Univ.
God bless this guy to be a genius, instead of a idiot. After all, there is no much difference betwen idiot and genius, and I like genius.

Thursday, September 22, 2005

Busy Life

The last time I do blog is almost 1 month before. Life is busy. To say my blog is not dead, I come to show show my trip in Manila.
Grab a frame from video recorded
The vehicle above is mini bus in Manila, I haven't seen any normal (what is normal? em, just the size we usually see in HK, S'pore, China, Europe, American, etc.) size bus there.

Monday, August 29, 2005

Don't slow down Ubuntu boot-up when no Ethernet cable is attached

Don't slow down boot-up when no Ethernet cable is attached

In Synaptic find and install the ifplugd package. After installing it, open a terminal and run this command

sudo gedit /etc/default/ifplugd

Edit the file by modify the lines INTERFACES="" and HOTPLUG_INTERFACES="" if no interfaces are listed or if the wrong interfaces are listed. You probably only want to test the hotplug status of the wired Ethernet connection, so the lines should read:

INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"

run this command then:
sudo gedit /etc/network/interfaces

comment the following line, if it exists:
auto eth0
I don't pretend to understand these options fully, so please post corrections if I'm wrong. I've also modified the ARGS= line to add the string -b which silences the otherwise excessive beeping when you plug or unplug the cable. Save the file and reboot.

Don't slow down boot-up by synchronizing with network time

Ubuntu pauses during boot-up while attempting to synchronize the system clock with a remote time server, but you probably aren't connected to the internet when you boot with a ThinkPad, so this attempt accomplishes nothing. . Eliminate this delay by opening a terminal and entering:

sudo chmod -x /etc/init.d/ntpdate
For more info, plz refer to here

Wednesday, August 24, 2005

[SoftwareRec] Install Ubuntu on Acer Travelmate 3000 (3002WTCi)

Before reading all contents below,

for those are still struggling to install ubuntu 5.10 onto the Acer Travelmate 3000 series, I strongly suggest that it is time to try Ubuntu/Kubuntu 6.06. In another article, I wrote my experience of using 6.06 on the Acer. 6.06 can be installed and run smoothly and easily. Of cause, If you enjoy kernel patch, recompilation, etc., please go on.


Actually, I donnot like the Acer Travelmate very much. The last time when I was a acer travelmate customer is 5 years ago. I remember the acer babi is really hot, especially in room without air-con. Last week, I got a new travelmate 3200WTCi from company, rather disappointed to find it is still as hot as 5 years ago.

'Hot' is the first impression it brings to me. Compared to my previous old laptop Toshiba Portege4100, which has similar weight and computing power with travelmate at the same age, the Acer is just like a oven.
However, I must agree I donnot hate its industrial design. It is cute. Now, the problem is how about its linux support. If it supports linux good, I will love it much more. I will record the process of installing and setting ubuntu at the following parts. The ubuntu is 5.04 hoary, some problems are resolved in 5.10 breedy already, which I will introduce later.

1. Install from CD


I am not sure what happened when I use default parameter (just press enter), the kernel just hangs. But it is easy to bypass the problem. You can install with parameter:
linux acpi=off noacpi
After that, it will go smoothly, everything will be detected (not just work), including wireless card and video card. But both of them cannot work properly. Soundcard also cannot work by default.

2. Video Problem



The widescreen's native resolution is 1280x800. but ubuntu can only detect 1024x768 from BIOS. In this model, everything is too short, a bit ugly. 915resolution is a program modify the BIOS setting on fly. I grab it and run:
915resolution 49 1280 800 24
then, the resolution is OK, much more beautiful.
To let it run on startup, you need to put it into a startup script. I forgot what is the default runlevel, and I am lazy, thus, I do the following steps:
#vi /etc/init.d/915resolution
/* insert 915resolution 49 1280 800 24*/
#chmod a+x /etc/init.d/915resolution
#update-rc.d 915resolution defaults

In ubuntu 5.04 hoary, xorg is 6.8.2, which doesn't support DRI acceleration. But in breedy, xorg is 6.9, and supports intel 915GM's GMA 9000 video card very good (Unfortunately, I found the DRI is broken again, after I reinstall 5.10 today, although it is OK yesterday. Totally no idea).

3. Wireless Network


Ubuntu can detect ipw2200 directly, but I am not sure whether it works by default. As bringing up the wireless module is quite tricky.
Anyway, I suggest to install the latest ipw2200+fireware:
wget http://heanet.dl.sourceforge.net/sourceforge/ ipw2200/ipw2200-1.0.4.tgz
wget http://bughost.org/firmware/ipw2200-fw-2.3.tgz
sudo mv ipw2200-fw-2.3.tgz /usr/lib/hotplug/firmware
tar xzf ipw2200-1.0.4.tgz
cd ipw2200-1.0.4
make
sudo make install
cd /usr/lib/hotplug/firmware
sudo tar xzf ipw2200-fw-2.3.tgz
sudo rm -r /lib/modules/`uname -a|awk '{ print $3 }'`/kernel/drivers/net/wireless/ieee80211
sudo rm -r /lib/modules/`uname -a|awk '{ print $3 }'`/kernel/drivers/net/wireless/ipw2200
sudo depmod -a
sudo rmmod ipw2200 firmware_class ieee80211 ieee80211_crypt_wep ieee80211_crypt
sudo modprobe ipw2200

When u run 'dmesg', you may see:
ipw2200: Radio Frequency Kill Switch is On:
Kill switch must be turned off for wireless networking to work.

I just push the wireless enable button (in ur laptop front panel), and then:
modprobe -r ipw2200
modprobe ipw2200
ifconfig ethxx up
dhclient ethxx
then it is OK.
Another trick to bring up the wireless card is to push the same button during startup, just after hotplug service is up and before the network service start.

4. Sound Card


To bring up the Intel HDA sound card, we need to repair the broken apic support in kernel.
I am using linux-image-2.6.12-6-686, and assume all following steps are executed on linux-source-2.6.12:
a. Download io_apic.c and mpparse.c to /usr/src/linux-source-2.6.12/arch/i386/kernel/
b. compile kernel (make menuconfig; make; make_modules_install; cp System.map /boot/System.map-xxx; cp arch/i386/boot/bzImage /boot/xxxx; mkinitrd -o /boot/initrd.img-xxxx; etc.
(for ubuntu 5.10, kernel 2.6.12-9-386, need change the line: #define WORKING_SET 1024 in scripts/kallsyms.c to: #define WORKING_SET 65536 )
then apic support is repaired, after this, you can delete acpi=off parameters from your grub menu.list. After grabing latest alsa and install, the sound card can be detected and run.

In breedy, after I upgrade linux-686, the acpi support is broken again. Thus, I removed those linux-686 related packages, as I think I do NOT need them any more.

5. Firewire CDROM


just work

6. ACPI


You can downloaded DSDT file ACER-Travelmate_3000-3C18-custom.asl.gzfrom acpi.sourceforge.net to repair ACPI. I download the DSDT.aml from Tilo Lutz, and then do the following steps:
a. echo -n "INITRDDSDT123DSDT123" >> /boot/initrd.img-2.6.12
b. cat DSDT.aml >> /boot/initrd.img-2.6.12
Here, my initrd table is /boot/initrd.img-2.6.12, For more information, please refer to http://gaugusch.at/kernel.shtml and http://acpi.sourceforge.net/dsdt/index.php
After patch it to initrd, my ubuntu can now show battery power left, cheers.

After I upgrade to ubuntu 5.10, the above method failed, as 5.10 replaces initrd with initramfs. To use DSDT.aml in 5.10, just execute:
mkinitamfs -o /boot/initrd.img-2.6.12 2.6.12
cp DSDT.aml /etc/mkinitramfs/
The DSDT.aml from Tilo Lutz does not work. I do some modification and you can download my DSDT.aml.

7. Modem

Below is the modem info. ATI3
Agere SoftModem Version 2.1.47

ATI5
2.1.47, Intel, HDA, 14
Somebody say Agere arranges only 1 programmer (Soumyendu Sarkar) for linux, somebody say Agere has start to write linux driver for 4+ years without any release. :-D, I am not sure what is true, but seems can only give up. You know, my old toshiba portege 4010's modem (AT3: TOSHIBA V.90 Data+Fax Software Modem Version 3.1.100; AT5: 3.1.100, AMR.ALi MB, AC97 ID:SIL REV:0x27,19)has never work in the past 3 years.

IR

Copy the nsc-ircc.c to drivers/net/irda, and compile kernel. Copy the nsc-ircc to /etc/modprobe.d/
Then, modprobe nsc_ircc seems no problem, except some warning in 'dmesg'. Again, no IR toy to test it.

Bluetooth

Seems it works from 'dmesg', but I have no bluetooth productions to test.

Cardreader

nothing to test

Hibernate

Doesn't work Post-Configuration

1. For chinese support, plz refer to:


tip1
tip2
Other acer laptop tips for linux1 Other acer laptop tips for linux2