Loadrunner中常用的C函数

发表于:2010-7-29 14:49

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

分享:
  4)strcpy

  char *strcpy ( char *dest, const char *source );

  功能:复制一个字符串到另一个字符串中。

  例子:

  复制一个字符串到字符数组中,并打印出来。

  脚本如下:

char test[1024];
strcpy(test, "what can we see?");
lr_output_message("%s", test);

  运行后在executon log中看到如下语句:

Starting action Action.
Action.c(10): what can we see?

  5)Strdup& strlwr

  char *strdup ( const char *string );

  复制一个字符串。

  char *strlwr ( char *string );

  转换成小写字母。

  例子:

  在这个例子中,Vuser的组名被转换为小写字母。但是lr_whoami把组名作为静态buffer返回。这样的buffer不能被操作。如果有操作需要,就复制这个静态buffer。

  脚本如下:

int id;
char *groupname_static, *groupname;
lr_whoami(&id, &groupname_static, NULL);
lr_output_message("groupname=%s", groupname_static);
groupname = (char *)strdup(groupname_static);
groupname = (char *)strlwr(groupname);
lr_output_message("lower case groupname=%s", groupname);
free(groupname);

  上述脚本用vugen保存为:CHANGE

  在controller中运行(设置为总是发送消息)

  运行后在log中看到如下语句:

Starting action Action.  [MsgId: MMSG-15919]
Action.c(11): groupname=CHANGE       [MsgId: MMSG-17999]
Action.c(16): lower case groupname=change  [MsgId: MMSG-17999]

  6)Strlen

  size_t strlen ( const char *string );

  功能:返回字符串长度(bytes).

  例子:

  这个例子很简单,就是得到一个字符串中的字符的个数。然后打印出来。

  脚本如下:

Starting action Action.  [MsgId: MMSG-15919]
Action.c(11): groupname=CHANGE       [MsgId: MMSG-17999]
Action.c(16): lower case groupname=change  [MsgId: MMSG-17999]

  运行后在log中看到如下语句:

Action.c(13): The  sentence has 18 letters

32/3<123>
《2023软件测试行业现状调查报告》独家发布~

精彩评论

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号