return 0;
}
3. Declare transaction name dynamically
#include "as_web.h"
Action1()
{
/*
Purpose: This script shows how to create dynamic transaction names. The transaction will
not show up in the Controller interface but will in the analysis results.
*/
// declaring variables for transaction names
char trans_name[20];
char *name;
name = "tom";
// creating the dynamic transaction names
sprintf(trans_name, "tom_%s", lr_eval_string("{rand_num}"));
// declaring a prototype
char *strtok(char *, char *);
Actions()
{
/* this forces the intepreter to save input_line in read/write memory.
If a character array is used, value would be save in read only memory
and would cause a memory violation when strtok is used. */
char input_line[100] = "Hi, my name is tom.";
// variable to hold a word from the above phrase.
char *word;
// gets the first word in the phrase.
word = strtok(input_line, " ");
// prints out the whole phrase. One word at a time.
while (word != NULL) {
lr_output_message("===>%s<===", word);
word = strtok(NULL, " ");
} // End of While
Actions()
{
/* this forces the intepreter to save input_line in read/write memory.
If a character array is used, value would be save in read only memory
and would cause a memory violation when strtok is used. */
char *input_line = strdup("Hi, my name is tom.");
char *word;
// variable to hold a word from the above phrase.
word = strtok(input_line, " ");
// prints out the whole phrase. One word at a time.
while (word != NULL) {
lr_output_message("===>%s<===", word);
word = strtok(NULL, " ");
} // End of While
return 0;
}
5. For IP Spoofing – To find out name of host machine
#include "as_web.h"
In this case parameter_name will have some value which will be unique for all vusers per iteration
8. Using lr_advance_param function
#include "as_web.h"
// Requirement:
// Total Vusers: 5
// Total iterations: 3
// Total data in parameter file = 15
// Behavior:
// Vuser 1 picks up data 1, 6, 11
// Vuser 2 picks up data 2, 7, 12
// Vuser 3 picks up data 3, 8, 13
// Vuser 4 picks up data 4, 9, 14
// Vuser 5 picks up data 5, 10,15
Action1()
{
int x,y,v,i;
//get the VuserID and store it in v
v=atoi(lr_eval_string("{VuserID}"));
//get the Iteration number and store it in i
i=atoi(lr_eval_string("{Iteration}"));
//For the first iteration, x = VuserID
if(i==1) x=v;
//For the second iterations onward, x = number of Vusers + 1
//You need to modify this number according to the number of Vusers you have in the scenario
else x=6;
for(y=1;y<x;y++)
lr_advance_param("NewParam");
lr_output_message("This is vuser %d , iteration %d, with data %s",v,i ,lr_eval_string("{NewParam}"));
return 0;
9. Parameterize lr_think_time
When the user tries to run a script in which lr_think_time is parameterized, VuGen issues the following errors:
run.c (x): illegal expression
run.c (x): syntax error; found `Param1' expecting `)'
run.c (x): syntax error; found `Param1' expecting `;'
run.c (x): undeclared identifier `Param1'
run.c (x): illegal expression
Solution: Save the string to a int variable
int kmp= atoi(lr_eval_string("{param1}"));
lr_think_time(kmp);
lr_output_message("The parameter value is %s", lr_eval_string("{param1}"));
..
10. Convert Integer in to String
Action()
{
int i = 1001;
int ii = 1002;
char sVar1[4];
char sVar2[4];
// itoa: 1st pass an integer, next is string to contain integer as string, next is 10 for decimal or 16 for hex
itoa(i, sVar1, 10);
lr_save_string(sVar1, "sVar1");
lr_output_message(sVar1);
itoa(ii, sVar2, 10);
lr_save_string(sVar2, "sVar2");
lr_output_message(sVar2);
return 0;
}
11. Generate Unique data thro script
#include "as_web.h"
Action()
{
/* data record for the database */
char sJobTitle[1024];
char *sHolder_JobTitle = "DBA";
int iRand;
char sRand[4];
char xPrefix[4];
srand(time(NULL)); // seed it always
/* Generate some random number */
iRand = (rand() % 1000);
lr_output_message ("RandomNumber %d\n", iRand);
/* convert number to string */
if (!itoa(iRand, xPrefix, 10))
lr_output_message("Cannot convert iRand to ascii char");
else {
lr_output_message("Converted value %s", xPrefix);
}