zoukankan      html  css  js  c++  java
  • Loadrunner 脚本开发-从文件读取数据并参数化

    脚本开发-从文件读取数据并参数化

     

     

    直接上代码:

     

    char* testfn()

    {

        int count, total = 0;

        //char buffer[1000];

        char * buffer = NULL;

        int filelenth = 0;

        long file_stream;

        char * filename = "d:\test.txt";

     

        if ((file_stream = fopen(filename, "r")) == NULL )

        {

            lr_error_message ("Cannot open %s", filename);

            return NULL;

        }

     

        fseek(file_stream,0,2); //定位到文件末尾

        filelenth = ftell(file_stream); //获取文件总长度

     

    fseek(file_stream,0,0); //定位文件开头

     

        buffer = (char *)malloc(filelenth);  //动态分配内存

     

        count = fread(buffer, sizeof(char), filelenth, file_stream);  //

        lr_output_message ("%d bytes read", count);

     

        lr_output_message ("content read = %s", buffer );

     

        // Close the file stream

        if (fclose(file_stream))

        {

            lr_error_message ("Error closing file %s", filename);

        }

     

        return buffer;

    }

     

     

    Action()

    {

        char *pt = NULL;

    pt = testfn();

        lr_save_string(lr_eval_string(pt), "param");

    lr_output_message("value of param: %s",lr_eval_string("{param}"));

     

    free(pt); //释放内存

    }

     

    运行结果:

    转载出处:https://www.cnblogs.com/shouke/p/10157706.html

  • 相关阅读:
    文件上传跨域解决方案-jQuery-File-Upload
    求数列的的增幅,已知起始列和结束列,中间阶梯数
    mud那些坑 find_object问题
    jquery mCustomScrollbar使用
    JS的Date对象
    JS获取当前日期
    Go数组求和
    Go九九乘法表
    Go语言基础之time包
    Go语言基础之流程控制
  • 原文地址:https://www.cnblogs.com/lipo/p/11307894.html
Copyright © 2011-2022 走看看