2008年9月21日星期日

configurate dns in solaris

su
vim /etc/nsswitch.conf

change:
hosts file
as
hosts file dns

[by Allen Liu]

2008年7月27日星期日

shell下emacs开启alt

kbdcontrol us.emacs ;use emacs keymap

shell下emacs开启alt

kbdcontrol us.emacs ;use emacs keymap

2008年7月24日星期四

Q: What is a test scenario?

A: The terms "test scenario" and "test case" are often used synonymously. Test scenarios are test cases or test scripts, and the sequence in which they are to be executed. Test scenarios are test cases that ensure that all business process flows are tested from end to end. Test scenarios are independent tests, or a series of tests that follow each other, where each of them dependent upon the output of the previous one. Test scenarios are prepared by reviewing functional requirements, and preparing logical groups of functions that can be further broken into test procedures. Test scenarios are designed to represent both typical and unusual situations that may occur in the application. Test engineers define unit test requirements and unit test scenarios. Test engineers also execute unit test scenarios. It is the test team that, with assistance of developers and clients, develops test scenarios for integration and system testing. Test scenarios are executed through the use of test procedures or scripts. Test procedures or scripts define a series of steps necessary to perform one or more test scenarios. Test procedures or scripts may cover multiple test scenarios.

[Ref]
http://www.robdavispe.com/free2/software-qa-testing-test-tester-2240.html

How complier invoke a member function

There are three steps complier to find function you call
1. Search function name match
2. Get the most approach one
3. Check right of function

class C
{
public:
void F(){}
};

class D : public C
{
void F(){}
};

...
D d;
d.F(); //wrong! why?

First, the complier find a function named F(). (D::F())
Second, check the param list
Third, check the right

Scenario 2:
class C
{
public:
void F(){}
};

class D : public C
{
int f;
};

...
D d;
d.F(); //wrong! why?
First, the compiler find name as f (D::f)
so why should we use m_f as member var name.

2008年7月21日星期一

virtual inherit [Ref:wikipedia]

class Animal
{
public:
virtual void eat();
};

class Mammal : public Animal
{
public:
virtual Color getHairColor();
};

class WingedAnimal : public Animal
{
public:
virtual void flap();
};

// A bat is a winged mammal
class Bat : public Mammal, public WingedAnimal {};
...
Bat bat;

But how does bat eat()? As declared above, a call to bat.eat() is ambiguous. One would have to call either bat.WingedAnimal::Animal::eat() or bat.Mammal::Animal::eat(). The problem is that semantics of conventional multiple inheritance do not model reality. In a sense, an Animal is only an Animal once; a Bat is a Mammal and a WingedAnimal, but the Animalness of a Bat's Mammalness is the same Animalness as that of its WingedAnimalness.

This situation is sometimes referred to as diamond inheritance and is a problem that virtual inheritance works, in part, to solve.


Solution

We can redeclare our classes as follows:

// Two classes virtually inheriting Animal:
class Mammal : public virtual Animal
{
public:
virtual Color getHairColor();
};

class WingedAnimal : public virtual Animal
{
public:
virtual void flap();
};

// A bat is still a winged mammal
class Bat : public Mammal, public WingedAnimal {};

Now the Animal portion of Bat::WingedAnimal is the same Animal as the one used by Bat::Mammal, which is to say that a Bat has only one Animal in its representation and so a call to Bat::eat() is unambiguous.

This is implemented by providing Mammal and WingedAnimal with a vtable pointer since, e.g., the memory offset between the beginning of a Mammal and of its Animal part is unknown until runtime. Thus Bat becomes (vtable*,Mammal,vtable*,WingedAnimal,Bat,Animal). Two vtable pointers per object, so the object size increased by two pointers, but now there is only one Animal and no ambiguity. There are two vtables pointers: one per inheritance hierarchy that virtually inherits Animal: One for Mammal and one for WingedAnimal. All objects of type Bat will have the same vtable *'s, but each Bat object will contain its own unique Animal object. If another class inherits Mammal, such as Squirrel, then the vtable* in the Mammal object in a Squirrel will be different from the vtable* in the Mammal object in a Bat, although they can still be essentially the same in the special case that the squirrel part of the object has the same size as the Bat part, because then the distance from the Mammal to the Animal part is the same. The vtables are not really the same, but all essential information in them (the distance) is.

overidde operator with const modify

A:int operator [](int i) const;
B:inst operator [](int i);

//invoke B
X x;
x[1] = 1;

//invoke A
const X x;
int a = x[1];

mutable keyword

class C1
{
public:
void Modify() const
{
data = 1;
}
private:
mutable int data;
};

Mutable allow a member function who has const keyword end of function name to modify data member (modify as mutable) value.

2008年7月17日星期四

void f( int (&ary)[12] );

The explicit modify

The explicit Keyword

C++A constructor declared with only one argument and without the explicit keyword is a converting constructor. You can construct objects with a converting constructor using the assignment operator. Declaring a constructor of this type with the explicit keyword prevents this behavior. The explicit keyword controls unwanted implicit type conversions. It can only be used in declarations of constructors within a class declaration. For example, except for the default constructor, the constructors in the following class are converting constructors.

class A
{ public:
A();
A(int);
A(const char*, int = 0);
};

The following declarations are legal.

A c = 1;
A d = "Venditti";


The first declaration is equivalent to A c = A(1).

If you declare the constructor of the class with the explicit keyword, the previous declarations would be illegal.

For example, if you declare the class as:

class A
{ public:
explicit A();
explicit A(int);
explicit A(const char*, int = 0);
};

You can only assign values that match the values of the class type.

For example, the following statements will be legal:

A a1;
A a2 = A(1);
A a3(1);
A a4 = A("Venditti");
A* p = new A(1);
A a5 = (A)1;
A a6 = static_cast<a>(1);




Ref:
http://publib.boulder.ibm.com/infocenter/lnxpcomp/v7v91/index.jsp?topic=/com.ibm.vacpp7l.doc/language/ref/clrc06explicit_keyword.htm

2008年7月3日星期四

以_ t结尾的这些数据类型被称为原始系统数据类型

类属指针 void *

类属指针可以隐式的转换成人任意类型的指针
void * malloc(size_t)
char * pch = malloc(10);

2008年7月2日星期三

point to member function 成员函数指针

class CA
{
public:
CA(void (*pfn)(int));
};

class CB
{
public:
CB()
{
CA a(&Fx1);
};
public:
void Fx1(int)
{};
};
/////////////
error C2276: '&' : illegal operation on bound member function expression

solution:

class CA;

class CB
{
public:
CB(void (CA::*)()){};
};


class CA
{
public:
CA()
{
CB b(&CA::Fx);
};
void Fx();
};

2008年6月30日星期一

virtual inherit

class B
{
void Fb(){...};
};
class CA : virtual public B
{
void Fca(){...};
};
class CB : virtual public B
{
void Fcb(){...};
};

class CS: public CA, public CB
{
Fb();
};

B
----
CA
----
CB
----
CS




Err:
class B
{
public:
void Fb()
{
printf("Fbfffffffffffffffffffffffffffffffffffffffffffffffff");
}
};
class CA : public B
{


};
class CB : public B
{

};

class CS: public CA, public CB
{
public:
void Do()
{
Fb();
}
};

int _tmain(int argc, _TCHAR* argv[])
{
CS c;
c.Do();
return 0;
}
//////////////////////////////////////////////////////
1>f:\project\rreg\tt\tt.cpp(28) : error C2385: ambiguous access of 'Fb'
1> could be the 'Fb' in base 'B'
1> or could be the 'Fb' in base 'B'
1>f:\project\rreg\tt\tt.cpp(28) : error C3861: 'Fb': identifier not found

[COM]-ruler of ref count

1. Addref before return. Call Addref if function return interface point.(QueryInterface, CreateInstance)
2. Call "Release" after unuse interface.
3. Call "AddRef" after copy a interface point


HRESULT hr = pIUnknown->QueryInterface(IID_IX, (void **)&pIX)
if (SUCCEEDED(hr))
{
pIX->Fx();
pIX->Release(); //Release if succeeded
}
pIUnknown->Release();


equal:

HRESULT hr = pIUnknown->QueryInterface(IID_IX, (void **)&pIX)
pIUnknown->Release();
if (SUCCEEDED(hr))
{
pIX->Fx();
pIX->Release(); //Release if succeeded
}

for 3:

IX *pIX2 = pIX; //Make a copy of pIX
pIX2->AddRef();
...
pIX2->Release();
pIX->Release();

[转]static_cast、dynamic_cast、reinterpret_cast、和const_cast

static_cast

用法:static_cast <> ( expression )

该运算符把expression转换为type-id类型,但没有运行时类型检查来保证转换的安全性。它主要有如下几种用法:
  • 用于类层次结构中基类和子类之间指针或引用的转换。进行上行转换(把子类的指针或引用转换成基类表示)是安全的;进行下行转换(把基类指针或引用转换成子类表示)时,由于没有动态类型检查,所以是不安全的。
  • 用于基本数据类型之间的转换,如把int转换成char,把int转换成enum。这种转换的安全性也要开发人员来保证。
  • 把空指针转换成目标类型的空指针。
  • 把任何类型的表达式转换成void类型。
注意:static_cast不能转换掉expression的const、volitale、或者__unaligned属性。

dynamic_cast

用法:dynamic_cast <> ( expression )

该 运算符把expression转换成type-id类型的对象。Type-id必须是类的指针、类的引用或者void *;如果type-id是类指针类型,那么expression也必须是一个指针,如果type-id是一个引用,那么expression也必须是一个 引用。

dynamic_cast主要用于类层次间的上行转换和下行转换,还可以用于类之间的交叉转换。

在类层次间进行上行转换时,dynamic_cast和static_cast的效果是一样的;在进行下行转换时,dynamic_cast具有类型检查的功能,比static_cast更安全。
class B{

public:

int m_iNum;

virtual void foo();

};

class D:public B{

public:

char *m_szName[100];

};



void func(B *pb){

D *pd1 = static_cast(pb);

D *pd2 = dynamic_cast(pb);

}

在 上面的代码段中,如果pb指向一个D类型的对象,pd1和pd2是一样的,并且对这两个指针执行D类型的任何操作都是安全的;但是,如果pb指向的是一个 B类型的对象,那么pd1将是一个指向该对象的指针,对它进行D类型的操作将是不安全的(如访问m_szName),而pd2将是一个空指针。另外要注 意:B要有虚函数,否则会编译出错;static_cast则没有这个限制。这是由于运行时类型检查需要运行时类型信息,而这个信息存储在类的虚函数表 (关于虚函数表的概念,详细可见)中,只有定义了虚函数的类才有虚函数表,没有定义虚函数的类是没有虚函数表的。

另外,dynamic_cast还支持交叉转换(cross cast)。如下代码所示。
class A{

public:

int m_iNum;

virtual void f(){}

};



class B:public A{

};



class D:public A{

};



void foo(){

B *pb = new B;

pb->m_iNum = 100;

D *pd1 = static_cast(pb); //copile error

D *pd2 = dynamic_cast(pb); //pd2 is NULL

delete pb;

}

在函数foo中,使用static_cast进行转换是不被允许的,将在编译时出错;而使用 dynamic_cast的转换则是允许的,结果是空指针。

reinpreter_cast

用法:reinpreter_cast (expression)

type-id必须是一个指针、引用、算术类型、函数指针或者成员指针。它可以把一个指针转换成一个整数,也可以把一个整数转换成一个指针(先把一个指针转换成一个整数,在把该整数转换成原类型的指针,还可以得到原先的指针值)。

该运算符的用法比较多。

const_cast

用法:const_cast (expression)

该运算符用来修改类型的const或volatile属性。除了const 或volatile修饰之外, type_id和expression的类型是一样的。

常量指针被转化成非常量指针,并且仍然指向原来的对象;常量引用被转换成非常量引用,并且仍然指向原来的对象;常量对象被转换成非常量对象。

Voiatile和const类试。举如下一例:
class B{

public:

int m_iNum;

}

void foo(){

const B b1;

b1.m_iNum = 100; //comile error

B b2 = const_cast(b1);

b2. m_iNum = 200; //fine
}

上面的代码编译时会报错,因为b1是一个常量对象,不能对它进行改变;使用const_cast把它转换成一个常量对象,就可以对它的数据成员任意改变。注意:b1和b2是两个不同的对象。

2008年5月21日星期三

Ensuring Only One Instance of Your Application Is Running -- 确保只有一个程序实例运行

Many applications must ensure that they have only one instance running. There are several ways to do this in Windows XP. Among them are the following:
许多程序都要确保只能运行一个实例。这个有多个实现方法。总的有以下:

→Use FindWindow or FindWindowEx to search for a known window that your application opens. If that window is already open, you can use that as an indication that the application is already running.
使用FindWindow或者FindWindowEx去查找你的应用程序窗口,如果窗口打开了,就说明程序已经在运行。

→Create a mutex or semaphore object when your application is opened, and close that object when the application terminates. The global object namespace is separated for each desktop, allowing a unique list of mutex and semaphore objects for each.
当你的应用程序打开时创建一个互斥或者信号对象,在程序结束时关闭这个对象。这个全局的对象名字空间在每个桌面是分开的,每个桌面允许有一系统的唯一的互斥和信号对象。

[Reference from MSDN-User Accounts with Fast User Switching and Remote DesktopUser Accounts with Fast User Switching and Remote Desktop]

2008年5月15日星期四

Out-of-band / 带外数据

1. A person is involved in a discussion with a group of people. During the discussion, he decides that some information is best kept between himself and one other member of the group, exclusively -- whether for privacy reasons, or merely the need to avoid saturating the entire group with information they do not need. His communication with that individual may be considered out-of-band, relative to the group discussion.

1. 一个人加入到一个讨论组中。在这个讨论期间,他决定有些信息最好对这个组的其他人保密。无论是私人的原因或者是仅仅是为了避免这些对这个组无用的信息。他的这个与个别人的这种交流就可以看成是out-of-band(相对于这个讨论组)

2. A person is at his place of work, and he is communicating with someone outside of his work place (for example, by Internet or telephone, using his employer's computer or telephone equipment). He decides that key parts of his conversation are best kept private from his employer, such as if he were discussing plans to change jobs. He would use his personal cell phone to transmit sensitive messages to, and receive related messages from, his external contact, in order to avoid use of his employer's phone or computer network. In this situation, his personal cell phone communications are considered out-of-band, relative to the main conversation.

2. 一个人在他的工作场所,他与外面的人交流(如打电话).他觉得有些谈话内容最好不要让老板知道,如想跳槽。他可以用他的手机来发送,接收敏感的信息,而不通过老板电话或计算机网络。这种情况下,手机就可以称做是out-of-band了,相对于这个主要的谈话。

[From wikipedia]

2008年3月9日星期日

apply one job

apply job of SDET(beyonesoft)

2008/3/10 14:47

压力测试-负载测试

负载测试主要关注系统内部的情况,如容量、可扩展性、功能等。例如,能够存储多少个TB的数据?如果同时调用全部的功能会不会出问题? 压力测试主要关心系统外部的表象。例如,能够同时处理多少人的数据操作?能够坚持多少小时不出问题? 负载过关了,但是压力不一定能够过关。你能够挑100斤,但是不一定能够连续挑一个月

2008年3月6日星期四

海尔芙拉

这种睡莲名为“海尔芙拉”,为微型珍稀品种,花朵一般在午间开放,夜晚闭合

2008年3月5日星期三

Pointer of function

void (*pf) (const string &, const string &);
typedef void (*pf) (const string &, const string &);
pf pf1;
void cmp(const string &, const string &);
pf1 = cmp;
pf1("hello", "hell");

void useBigger(const string &, const string &,
bool(const string &, const string &));

the same as:

void useBigger(const string &, const string &,
bool (*) (const string &, const string &));

2008年3月4日星期二

Format of EXE

Windows use PE format to store exe program

Test only

pre