loadrunner Lr_类函数之 lr_eval_string_ext()

lr_eval_string_ext()

创建缓冲区并在评估嵌入参数后为其分配输入字符串。

int lr_eval_string_ext(const char *in_string,unsigned long const in_len,char ** constout_str,unsigned long * const out_len,unsigned long constoptions,const char * file,long const line);

 

参数说明:

in_str:要计算的字符串。

in_len:参数in_str +2的名称的长度,以考虑括号。

out_str:指向输出缓冲区的指针。

out_len:输出缓冲区的长度。

Options:保留供将来使用。当前设置为“0”。

File:将来使用。当前设置为“0”。

Line:留以备将来使用。当前设置为“-1”。

 

lr_eval_string_ext函数通过用其字符串值替换参数来计算in_str。它创建一个包含扩展字符串的缓冲区,并设置out_str指向该缓冲区。它还将缓冲区的长度分配给out_len。

请注意,in_len是您传递的参数的长度,而不是参数值的长度。例如,如果参数ABC包含字符串“1234567890”,则调用是:

lr_eval_string_ext(“{ABC}”,5

使用lr_eval_string_ext后,使用lr_eval_string_ext_free释放为输出缓冲区分配的内存。

当关联使用二进制数据的语句(例如,具有嵌入的NULL字符的数据)时,此函数非常有用。

在评估循环中的字符串时,优先于lr_eval_string使用此函数与lr_eval_string_ext_free结合使用。在循环中使用lr_eval_string会使用更多的内存。

 

示例:lr_eval_string_ext

在示例1中,lr_eval_string_ext获取包含空字符的参数的内容和长度。

在示例2中,lr_eval_string_ext检索当前URL以替换记录的URL。

 

示例1

unsigned long prmLen;

char *newParam, *strStart;

// Create a parameter 39 characters longcontaining null characters.

lr_save_var("\0A A string\0 containingembedded Nulls\0",

   39, 0, "Param1");

/*Since there are embedded NULL characters,

you cannot use strlen to get the string'slength.

Use the prmLen argument instead.

Note that the second argument is the numberof

characters in the parameter name"Param1", plus 2

for the parenthesis. */

 

lr_eval_string_ext ("{Param1}",8, &newParam,

   &prmLen, 0, 0,-1);

/* Output the length.*/

lr_output_message("The length is%d", prmLen);

// Action.c(24): The length is 39

// Point to the character after the firstNull

strStart = newParam + 2;

// Output between the first and second Null

lr_output_message("The text is\"%s\"",strStart );

// Action.c(31): The text is " Astring"

 

示例2

在以下示例中,lr_eval_string_ext函数创建一个包含参数数据的缓冲区。在脚本录制过程中生成的原始URL如果按原样重播,将会失败。我们使用lr_eval_string_ext检索当前URL以替换记录的URL。

 

/* Original URL/

 

web_url("Response_1.dat",

 

"URL=http://209.88.184.66/SmWeb/Data/S_DFFA13B8DFB711D3AA6D009027

E00675/Response_1.dat",

 

"RecContentType=application/octet-stream",

 

"SupportFrames=0",

 

LAST );

 

web_save_header(RESPONSE,"headerVar")

 

web_create_html_param("returnedBuffer","", "" ) ;

 

web_submit_data("SmartWeb.asp",

 

   "Action=http:/207.86.104.1/SmWeb/Asp/SmartWeb.asp?App=Web&SmStream@,

"Method=POST",

"TargetFrame=",

"RecContentType=application/octet-stream",

"SupportFrames=0",

ITEMDATA,

"name=?App",

"value=Web",

ENDITEM,

"name=SmStream@Request",

"value=ClassDescription",

ENDITEM,

LAST );

 

/* Compute the length of the header */

len = strlen(lr_eval_string("{headerVar}")) ;

/* Get a pointer to the buffer */

lr_eval_string_ext ("{Param1}",8, &newParam, &prmLen, 0, 0,-1);

// Save the address

newParamAdr = newParam;

/* Retrieve the data from the buffer */

newParam += (len + 9) ; /* move the lengthof the header + 9 bytes */

fileLocationLength[0] = newParam[0] ; /*read the length of the buffer

fileLocationLength[1] = newParam[1] ; /*the first two bytes are relevant to us.. */

fileLocationLength[2] = 0 ;

fileLocationLength[3] = 0 ;

fileLocationLengthASCII =(short*)(&fileLocationLength[0]) ; /* cast this to a short* to be sure weonly read two bytes */

newParam += 2 ; /* Move the pointer in thestream to the beginning of the actual string */

for(i=0, j=0 ; i <=*fileLocationLengthASCII; ++i)

   if ( !memcmp( newParam, "\r\n", 1 ) ) {

       /* Copy the new string into a char* called info */

       memcpy(info[j], newParam[i], 1) ;

       /* copy only ASCII characters and no Nulls */

++j ;

}

 

/* We now have a string, URL, which is thevalue we need for the next call. */

char* URL =strcat("URL=http://207.86.104.1", info) ;

web_url("Response_1.dat",

URL, /* this string now holds thecorrelated value */

"RecContentType=application/octet-stream",

"SupportFrames=0",

LAST );

lr_eval_string_ext_free(newParamAdr); /*free the pointer */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值