[转]C programming examples for Loadrunner test tool
上一篇 / 下一篇 2011-09-13 12:58:59 / 个人分类:LoadRunner性能测试
{
int a,b;
char c;
a=1;
b=2;
c='A';
lr_output_message("值分别是:a=%d ,b=%d,c=%c ",a,b,c);
return 0;
}
------------关于数组的例子----------
Action()
{
int i;
char cp[]={'a','b','c'};
for (i=0;i<3;i++)
}
--------------------------------------------------------------
Action()
{
int a=80;
if(a<75)
else if ((a>=75) && (a<=80))
else if(a>80)
else
return 0;
}
---------------------------------------------------------------
Action()
{
int vuser,commodity;
lr_whoami(&vuser,NULL,NULL);
commodity=vuser%5+1;
switch(commodity)
{
}
return 0;
}
--------------------------------------------------------------------
Action()
{
int i;
for(i=0;i<100;i++)
lr_output_message("%d=%c",i,i);
return 0;
}
---------------------------------------------------------------------
Action()
{
int i,j;
for(i=1;i<=3;i++)
{
}
lr_output_message("end of i loop");
return 0;
}
-----------------------------------------------------------------------
Action()
{
int i=0;
while (i<=50)
lr_output_message("Current value of i=%d",i++);
-----------------------------------------------------------------------
Action()
{
int i;
int sum,avg,multiple,substract;
int array[]={99,1,47,53,19,81};
for(i=0;i<6;i++)
lr_message("%d",sum);
lr_message("%d",avg);
lr_message("%d",multiple);
lr_message("%d",substract);
}
------------------------------------------------------------------------
Action()
{
int i;
char array[]={'M','e','r','c','u','r','y'};
for(i=0;i<7;i++)
lr_output_message(">>>>>>>>>>>>>>>>%c",array[i]);
lr_output_message(">>>>>>>>>>>>>>>>%s",array);
}
-------------------------------------------------------------------------
Action()
{
char mystring1[20]="";
char mystring2[20]="";
char mystring3[20]="mercury2";
char cstring[10]="12345";
int
lr_output_message("mystring1 is %s",mystring1);
// copy "Mercury1" into MyString1
strcpy(mystring1,"mercury1");
lr_output_message("mystring1 is %s",mystring1);
strcpy(mystring2,mystring3);
lr_output_message("mysrting2 is %s",mystring2);
// Catenate MyString2 to MyString1
strcat(mystring1,mystring2);
lr_output_message("mystring1 is %s",mystring1);
lr_output_message("cstring=%s",cstring);
cint=atoi(cstring);
lr_output_message("cint=%d",cint);
cint=100;
itoa(cint,cstring,10);
lr_output_message("cstring=%s",cstring);
}
------------------------------------------------------------------------------
Action()
{
// Each row is a string in itself;
}
-----------------------------------------------------------------------------
Action()
{
int myfile,i,loadnumber;
char filename[30]="D:\\temp\\loans.txt";
myfile=(int)fopen(filename,"r");
for(i=1;i<=5;i++)
{
fscanf(myfile,"%d",&loadnumber);
lr_output_message("load number %d:%d",i,loadnumber);
}
fclose(myfile);
}
备注:
loans.txt文件的内容如下:
11111
22222
33333
44444
55555
运行结果如下:
Virtual User Script. started
Starting action vuser_init.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(10): load number 0:11111
Action.c(10): load number 1:22222
Action.c(10): load number 2:33333
Action.c(10): load number 3:44444
Action.c(10): load number 4:55555
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
-----------------------------------------------------------------------------
Action()
{
int myfile;
char name[]="lihuichang";
myfile=fopen("D:\\temp\\names.txt","w");
fprintf(myfile,"%s",name);
fclose(myfile);
}
----------------------------------------------------------------------------
float average_function(int a,int b,int c)
{
float averagevalue=0.0;
averagevalue=(a+b+c)/3;
return (averagevalue);
}
Action()
{
float x;
x=average_function(4,6,2);
lr_output_message("x=%.2f",x);
x=average_function(10,5,6);
lr_output_message("x=%.2f",x);
}
---------------------------------------------------------------------------
{
// your code goes here
return;
}
Action()
{
split_function("lihuichang");
split_function("goodbye");
split_function("hello word");
}
----------------------------------------------------------------------------
{
system("del D:\\temp\\temp.txt");
}
------------------------------------------------------------------
Action()
{
int i;
// srand(time(NULL));
for (i=0;i<=10;i++)
lr_output_message("Random nummber: %d",rand());
}
-------------------------------------------------------------------
{
return((int)((float)(upperbound-lowerbound+1)*rand()/32770.0)+lowerbound);
}
Action()
{
int i;
srand(time(NULL));
for(i=0;i<100;i++)
lr_output_message("Random nummber,%d,",random_function(1,10));
}
--------------------------------------------------------------------
{
int Year=1;
float Interest=0.00;
float InterestRate = 8.0;
float InitialAmount = 10000.00;
float BeginningBalance;
float EndingBalance;
BeginningBalance = InitialAmount;
do
{
Interest = BeginningBalance * InterestRate/100;
EndingBalance = BeginningBalance + Interest;
lr_output_message("Year = %d, Beginning Balance = %.2f,"
BeginningBalance = EndingBalance;
}
while(EndingBalance <= 20000.00);
}
----------------------------------------------------------------------------
{
int Year=1;
float Interest=0.00;
float InterestRate = 8.0;
float InitialAmount = 10000.00;
float BeginningBalance;
float EndingBalance;
BeginningBalance = InitialAmount;
for(Year=1; Year<=5; Year++)
{
Interest = BeginningBalance * InterestRate/100;
EndingBalance = BeginningBalance + Interest;
lr_output_message("Year = %d, Beginning Balance = %.2f,"
BeginningBalance = EndingBalance;
}
}
---------------------------------------------------------------------------
{
char MyName[] = "Jim Morrison";
}
-------------------------------------------------------------------------
{
int MyFile;
}
----------------------------------------------------------------------
vuser_init()
{
}
Action()
{
char Name[80]="";
}
vuser_end()
{
fclose(MyFile1);
}
----------------------------------------------------------------------------------
{
return;
}
Action()
{
}
----------------------------------------------------------------------------------
TAG:
我的栏目
标题搜索
日历
|
|||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
1 | 2 | 3 | 4 | 5 | 6 | ||||
7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
28 | 29 | 30 |
我的存档
数据统计
- 访问量: 30326
- 日志数: 46
- 文件数: 2
- 书签数: 1
- 建立时间: 2008-10-13
- 更新时间: 2011-12-13