Subscribe by Email


Showing posts with label Declaration. Show all posts
Showing posts with label Declaration. Show all posts

Tuesday, September 4, 2012

What are User Define Functions? What are all the different types of User defined functions? (In WinRunner)


The testing capabilities of the winrunner can be extended further by letting the user create his own TSL functions. The TSL functions thus created can be used in a compiled module as well as in a test. 

Apart from just providing the built in functions, the TSL allows you to do the following:
1. The user defined functions can be defined by the user. After defining the function once in the test script, it can be called from anywhere in the tests.
2. The user defined functions can be defined by the user for compiled modules. Once that particular gets loaded, the functions it holds can be called from anywhere.
3. These user defined functions can be called from anywhere in the Microsoft API and other external DLL functions as well.

- The user defined functions are used when it is required to perform the same operations several number of times. 
- Instead of repeating the same code again and again, a single function can be written that will perform the same operations a number of times. 
- This has the following benefits:
  1. It makes your test scripts more modular.
  2. It makes your test scripts more readable.
  3. It becomes easier to maintain the code and debug it.

What are User Defined Functions?

- A user defined function because of being incorporated in to the compiled module can be accessed from any where. 
- At the same time the time taken for the execution is reduced since the compilation of the function is done in the earlier stages only. 
- Below stated is the typical declaration for a user defined function:
[class] function name ( [mode]  parameter.... )
{
Declarations;
Statements;
}
- The class of the function can either be public or static. 
- Whenever a static function is declared with static class it is made available to the module or the test within which that function lies. 
- Once a function with a public class is executed, it is made available to almost all the tests for the time till the test holding that function remains open. 
- This seems to be the most convenient option when it is required that the function should be accessible from all the tests. 
- However if the case is as such that it is required that many tests should be able to access the function, then the function has to be placed in a compiled module. 
- Whenever a function is placed in the compiled module, it becomes accessible until the duration of the testing session ends. 
- Unlike the class, there is no need of declaring the parameters explicitly. 
Parameters can possess any one of the following modes:
  1. In: in this mode the value is assigned from outside the function.
  2. Out: in this mode the value is assigned from inside the function.
  3. Inout: in this mode the value can assigned either from inside or from outside the function.

Types of User Functions in WinRunner

Now let us state all are the types of user defined functions:
  1. Scalar functions
  2. Multi- statement table valued functions and
  3. Inline table valued functions
- A user defined function may consist of either zero parameter or more then that.
- The function may return either a table or a scalar value.
- However, the input parameters have a limit of 1024. 
- If the function is to be driven with the default values then the key word DEFAULT must be specified while you call the function. 
- This key word is added in order to get a default value for the user defined functions. 
- In some cases if you omit the parameters then the parameters are treated to be default values. 


Wednesday, April 25, 2012

How does a definition clear path play a role in data flow testing?


Definition clear path is a quite less heard term! This article is focussed up on the concept of definition clear path and what role do it plays in the data flow testing. First let us define what is a definition clear path in actual. 

"A definition clear path as it can made out from the term itself that it is a path through which other variables cannot be defined or through which other variable definitions cannot be made."

To make the meaning of definition clear path clearer we shall look up to an example:
- Suppose X be a variable declared or appearing in a software program or procedure. 
- Suppose there is a path which do not contain any nodes with definition of the variable X.
- Such a path not containing any variable definitions has been termed as a definition clear path. 

We can now define this definition clear path as a path between the two nodes namely A and B, with X being defined in A and an use in node B and there exists no other definition of variable X between the two nodes present in the path. 

Let us see another example to explore another type of definition clear path that can exist. 
- Suppose the above same variable X be defined at a node A along with an use defined at the another node B.
- Suppose the path formed by these two nodes A and B does not appears in the sub path, then such a path is also defined as a definition clear path for the X variable defined by the nodes A and B if the variable X is not defined in the sub path. 
- There is another common name for the definition clear path which is “def- clear path”. 

Now let us talk about the role that the definition clear path plays in the data flow testing. Actually in the data flow testing, there are three types of coverage that have to be provided namely:
  1. Statement coverage
  2. Branch coverage and lastly
  3. Path coverage
Basically problems are faced with the path selection process. A definition of the variable X reaches a use if and only if there exists a sub path such that the sub path is a definition clear path with respect to the variable X. The path selection in the data flow testing is based up on the two criteria:

  1. Rapps and Weyuker criteria: Under these criteria the definition clear sub paths from definitions to uses are listed.
  2. Laski and Korel criteria: Under these criteria the various combinations that reach uses at a node via some sub path are listed.

How does Definition Clear Path play a role in Data Flow Testing?



- Definition clear paths have been known to make remarkable improvements in the control flow techniques for data flow testing.
- A rational is obtained for which there is a need to take in to consideration all the combinations of the sub paths. 
- The “all uses” is the most commonly preferred criteria.
- There are some paths in a program that are infeasible and it is these paths that pose a big problem in the data flow testing. 
- The path testing strategies are based up on the data flow anomalies. 
- Enough paths are required to be tested so that it is ensured that every object in the program has been initialized before use and have been used at least once during the program execution. 
- For a complete data flow testing it is required that definition clear paths are executed by the test cases from each node that contains a defined variable.


Wednesday, September 14, 2011

Some details about pointers and strings in C...

There doesn’t exist anything in C like real strings. A string is an array. It can be defined as an array of characters. A string is terminated by a nul character “\0”. A string can be initialized normally as follows:

Char string[10];
String[0] = ‘c’;
String[1] = ‘a’;
String[2] = ‘t’;
String[3] = ‘s’;

Another way of initializing and declaring a string is as follows:
Char string[10] = “cats”;

The following statement asks compiler to allocate 10 bytes of memory for the string entered by the user. The string can store only 9 characters and the tenth one being used for “nul” character.

We can easily access strings and their constituent characters using character pointers. The string arrays are mostly used for storing char data type elements in the memory. The array of string pointers is preferred over two dimensional arrays of characters mainly for two reasons. The first reason is by implementing array of pointers, you can make more efficient use of available memory since it consumes lesser number of bytes for storing arrays of strings. The second main reason is that an array of string pointers makes the manipulation of strings easier. You can easily exchange the positions of strings in the array using pointers without touching their memory locations. This makes managing strings very convenient. Another way of initializing a string is by using pointers like

for example:
Char string[ ] = “cats”;
Char *a;

Here is a pointer pointing to the string “string”. Pointers are another suitable way to access string arrays and modify them as we want. Since strings are composed of characters, we should use pointers to characters. The types of the variable and the pointers must match otherwise an error will be generated. Be careful that you don’t use “&” (address of) operator to assign the address of a variable to the desired pointer. If you used it, the name of the array will be used as the address of that particular array. For this reason only we do not use “&” (address of) while passing a string to the function scanf(). For example see the following code:

Int a;
Char name[10];
Scanf(“%d%s”, &a, name);

The pointer allows us to access the required character in the string because we made it to point to that string. Functions can be passed to print labels and to call the function. Below is an example:

Void printlbl(char lbl[ ])
{
Printf (“the label: %s\n”, lbl);
}
int main()
{
char lbl2[] = "abc";

Printlbl(lbl2);

}

Now if we want to pass a pointer to the string array lbl2, we will use the following code:
Char *lblptr = lbl2;

The above declared pointer can be used in the function also like shown below:
Printlbl (lblptr) ;

After execution you will observe that both the statements give the same output. Now you will ask me why so? The answer for this is that when we pass an array as a parameter or an argument to a function, a pointer is automatically created without we knowing it and the arrays are passed by reference method automatically the way a pointer is passed. So the above written code can also be written the other way as follows:

void Printlbl(char *lbl)
{
printf("the Label: %s\n",lbl);
}
a code for dynamically allocated string is given below:
string = (char *)malloc(sizeof(char) * (len+1));

Some stings can be allocated dynamically. This is done when we don’t know how much long a string will go until the program is executed or when we don’t what size of string the user will enter.


Tuesday, September 6, 2011

What is Assignment and Logical Comparison in C...

An expression as we all know is composed of one or more operations. When the expression is terminated by a semi colon, it becomes a statement which is the small executable unit in any program. The assignment statements are used to assign a value to a variable. The assigned value can be a constant variable or an expression. An assignment statement can be written in general form as:

A=bcd;

Where A is a variable to whom we are assigning a value and bcd is the assigned value. The “=” sign is called assignment operator. Assignments can be chained together. The assigning operator “=” assigns the value to the left hand operand and returns the value of the assignment. Assignment statements are very much needed for variable initialization since variables are initialized using assignment statements. There are 2 ways to do this:
- Un-initialized variable
- Initialized variable
An un-initialized variable has to be initialized in separate statements whereas an initialized variable combines declaration and assignment in to one statement.

Examples are:
Int a;
a=3; ------------------------uninitialized variable
int a= 3; -------------------- initialized variable

Assignment also follows when you use dynamic initialization. Sometimes variables of different types are mixed with each other. It’s a very common and observed phenomenon. In such cases a type conversion takes place. Here also it follows from the principal of assignment statement that “the value of the right side of the expression or of the assignment is converted to the type of the variable on left side i.e., target variable. Both the sides of assignment should be compatible with each other for type conversion. When conversion takes place from smaller data type to a larger data type no data is lost. Precedence of operators while assigning values with an expression should always be kept in mind.
Some programs need the power of decision making or comparison. This is granted through logical expressions which are nothing but the statements resulting into a 0 (true) or 1 (false) value. These are a combination of constants, variables and logical and relational operators. Be careful that two or more variables and operators should not occur in continuation. A logical expression may contain just one signed or unsigned variable or a constant or it may have two or more also joined by varied relational and logical operators. Following are some valid logical operators: the logical OR operator (||), the logical AND operator (&&) and the logical NOT (!) operator. The OR operator combines 2 expressions as its operands. If either of its operand evaluates to true, the OR operator also evaluates to true. This operator is basically used for testing evaluating expressions. The AND operator combines 2 expressions into one and the operator evaluates to one if and only if both the operands evaluate to 1. The NOT operator works on a single operand since it is a unary operator. It is used to negate or reverse the truth value of the operand. It has a higher precedence than of the relational and logical operators. Therefore, this should be enclosed within parentheses. This operator is useful as a test for zero. OR and AND operators have lower precedence than relational operators. Relational operators are used to define relationships between variables. C provides 6 basic relational operators : < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to), == (equal to), and != (not equal to). Do not confuse the = and the == operators. “=” is assignment operator whereas “==” is relational equality operator.


Facebook activity