发布新日志

  • String Manipulation Functions

    2012-06-05 17:34:10

    String Manipulation functions allow you to manipulate or compare strings. These functions begin with the str prefix. Expand the category to view a list of the available functions.

    Function Name

    Description

    strcat

    Concatenates two strings.

    strchr

    Returns the pointer to the first occurrence of a character in a string.

    strcmp

    Compares two strings to determine the alphabetic order.

    strcpy

    Copies one string to another.

    strdup

    Duplicates a string.

    stricmp

    Performs a case-insensitive comparison of two strings.

    strlen

    Returns the length of a string.

    strlwr

    Converts a string to lower case.

    strncat

    Concatenates n characters from one string to another.

    strncmp

    Compares the first n characters of two strings.

    strncpy

    Copies the first n characters of one string to another.

    strnicmp

    Performs a case-insensitive comparison of n strings.

    strrchr

    Finds the last occurrence of a character in a string.

    strset

    Fills a string with a specific character.

    strspn

    Returns the length of the leading characters in a string that are contained in a specified string.

    strstr

    Returns the first occurrence of one string in another.

    strtok

    Returns a token from a string delimited by specified characters.

    strupr

    Converts a string to upper case.

     

     

     

    strdup //字符串复制

    strlwr //转换为小写字符

    strupr // 转换为大写字符

    strncat// 连接n个字符到另一字符串

     

    strcat

    //char *strcat(char *to,const char *from);

    char fullpath[1024],*filename="logfile.txt";

    strcpy(fullpath,"c:\\tmp\\");//字符串复制

    strcat(fullpath,filename);//字符串连接

    lr_output_message("Full path of file is %s",fullpath);

     

     

    strchr

    strrchr

    char *string ="His Excellency the Duke of Exeter";

    char *first_x,*last_x;

    //获取搜索字符第一次出现的位置以后的字符串,如:xcellency the Duke of Exeter

    first_x=(char *)strchr(string,'x');

    lr_output_message("The first occurrence of x: %s",first_x);

    //获取搜索字符最后一次出现的位置以后的字符串,如:xeter

    last_x=(char *)strrchr(string,'x');

    lr_output_message("The last occurrence of x: %s",last_x);

     

    strlen

        int is_digit, i = 0;

        char * str = "1234567k89";

        unsigned int len = strlen(str);

     

        do {

            if (i == len) {

                lr_output_message ("No letters found in string");

                return -1;

            }

                       //isdigit函数,返回十进制数非0(true),返回0(false)

            is_digit = isdigit(str[i++]);

        }

              //当为0是循环条件终止

        while (is_digit);

            lr_output_message ("The first letter appears in character %d of string", i);}

    strcmp

    stricmp

    strncmp

    strnicmp

    int result;

    char tmp[20];

    char string1[]="The quick brown dog jumps over the lazy fox";

    char string2[]="The QUICK brown dog jumps over the lazy fox";

     

    //大小写敏感(小写>大写)

    result = strcmp(string1,string2);

    if(result>0)

         strcpy(tmp, "greater than");

        else if(result < 0)

         strcpy(tmp, "less than");

        else

         strcpy(tmp, "equal to");

    lr_output_message("strcmpString1 is %s string2",tmp);

    //大小写不敏感(小写=大写)

    result = stricmp(string1,string2);

    if( result > 0 )

            strcpy( tmp, "greater than" );

        else if( result < 0 )

            strcpy( tmp, "less than" );

        else

            strcpy( tmp, "equal to" );

    lr_output_message( "stricmp: String 1 is %s string 2", tmp);

              // 比较string1string230个字符,大小写敏感

        result = strncmp( string1, string2 , 30);

        if (result > 0 )

            strcpy(tmp, "greater than");

        else if (result < 0)

            strcpy(tmp, "less than");

        else

            strcpy(tmp, "equal to");

    lr_output_message ("strncmp: String 1 is %s string 2", tmp);

              // 比较string1string230个字符,大小写不敏感

              result = strnicmp( string1, string2 , 30); 

        if (result > 0 )

            strcpy( tmp, "greater than");

        else if (result < 0)

            strcpy(tmp, "less than");

        else

            strcpy(tmp, "equal to");

        lr_output_message ("strnicmp: String 1 is %s string 2", tmp);

     

    strset

              char str[16];

        strcpy(str, "Fill me in");

        lr_output_message ("Before strset str=%s", str);

              lr_output_message("%d",strlen(str));//字符串长度为10

              // 用字符'x'填充

        strset(str, 'x');

        lr_output_message ("After strset str=%s", str);

     

    strspn

       char * str = "corroborative";

        int rc;

              //返回字符串'corroborative'首位是否包含'ro'

        if ((rc = strspn(str, "ro")) == 0)

            lr_output_message ("No o's or r's found");

        else

            lr_output_message ("%d of %d characters are an o or an r", rc, strlen(str));

              //返回字符串'corroborative'首位+1是否包含'ro'

        if ((rc = strspn(str + 1, "ro")) == 0)

            lr_output_message ("No o's or r's found");

        else

            lr_output_message ("%d of %d characters are an o or an r", rc, strlen(str));

     

    strstr

      int offset;

        char * position;

        char * str = "The quick brown dog jumps over the lazy fox";

        char * search_str = "dog";

              //返回搜索字符串'dog'str中的第一个位置

        position = (char *)strstr(str, search_str);

        // strstr has returned the address. Now calculate * the offset from the beginning of str

              //按照内存中的相对位置计算offset

        offset = (int)(position - str + 1);

        lr_output_message ("The string \"%s\" was found at position %d", search_str, offset);

     

     

    strtok

    extern char * strtok(char * string, const char * delimiters ); // Explicit declaration

        char path[] = "c:\\mercury\\lrun\\bin\\wlrun.exe";

              \\分隔符号为.\

        char separators[] = ".\\";

        char * token;

        token = (char *)strtok(path, separators); // 获取第一个token

        if (!token) {

            lr_output_message ("No tokens found in string!");

            return( -1 );

        }

        while (token != NULL ) {

                       //打印有效的token

            lr_output_message ("%s", token );

                       // 获取下一个token,后续调用必须传递NULL作为字符串parameter.

            token = (char *)strtok(NULL, separators);

  • Buffer Manipulation Functions

    2012-06-05 15:12:47

    Buffer Manipulation functions allow you to manipulate or compare characters stored in data buffers. These functions begin with the mem prefix. Expand the category to view a list of the available functions.

     

    Function Name

    Description

    memchr

    Searches for a character in a buffer.

    memcmp

    Compares two buffers.

    memcpy

    Copies n characters from one buffer into another.

    memmove

    Moves a number of bytes from one buffer to another.

    memset

    Sets n bytes of a buffer to a given character.

     

    memchr

    void *memchr(const void *s,int c,size_t n);

    s: The name of the buffer.

    c: The character to search for in the buffer.

    n:The number of characters at the beginning of the buffer to search.

     

    //以下的例子是在字符串"Example string"中搜索字符'x'出现的第一个位置

        char * p;

        char str[] = "Example xtring";

             //获取第一个字符在内存中的位置

             lr_output_message("The first character is at buffer %d",str);

             //搜索整个字符串,获取'x'在内存中的位置

        p = (char *)memchr(str, 'x', strlen(str));

        if (p) {

      //打印出获取'x'在内存中的位置

      lr_output_message ("Character x is at buffer %d\n", p);

      //打印出获取'x'在字符串中的位置,'x'的位置是内存中相对位置+1

      lr_output_message ("Character x is at position %d\n", p - str + 1);

      }

        else

            lr_output_message ("Character x was not found");

     

    memcmp

    int memcmp(const viod *s1,const void *s2,size_t n);

    s1: The name of a buffer.

    Se: The name of a buffer.

    n:The number of characters to search at the beginning of the buffer.

     

    //以下的例子是用memcmp来比较两个字符串是否相等。

    char *s1="access to shared transmission";

    char *s2="access to transmission";

    int rc;

    //通过memcmp返回值与0比较大写来确认字符串大小

    rc =memcmp(s1,s2,strlen(s1));

    if(rc>0)

    lr_output_message("'%s' is greater than '%s'",s1,s2);//s1>s2

    else if (rc<0)

    lr_output_message("'%s' is less than '%s'",s1,s2);//s1<s2

    else

    lr_output_message("'%s' is equal to '%s'",s1,s2);//s1=s2

     

     

    memcpy

    Void *memcpy(void *dest,const void *src,size_t n);

    dest: Destination buffer where the data is copied

    src: The name of the source buffer from which from the data is copied.

    n: The number of bytes to copy

     

    char s1[] = "Sample string",s3[]="Just testing";

    char s2[40],s4[40];

    /* +1是为了复制s1的结束符号(NULLterminator) */

    memcpy(s2, s1, strlen(s1)+1);

    lr_output_message("s1=%s s2=%s", s1, s2);

    /* -1使得s4比比s3少一位*/

    memcpy(s4, s3, strlen(s3)-1);

    lr_output_message("s3=%s s4=%s", s3, s4);

     

    memmove

    void *memmove(void *dest,const void *src,size_t n);

    dest:Destination buffer where the data is copied.

    src:The name of the source buffer from which the data is copied.

    n:The number of bytes to copy.

     

    char buffer[80];

    strcpy(buffer,"abcde");

    //'abcde'的前四位'abcd'拼接到自身字符串从第二位开始的位置''

    memmove(buffer+1,buffer,4);

    lr_output_message("New string: %s\n",buffer);

     

     

    memset

    void *memset(void *buffer,int c,size_t n);

    buffer:Pointer to block of data to be filled with c.

    c:The character placed in buffer.

    n:The number of bytes in buffer set as c.

    //在初始化之前memset填充结构about_app中所有元素为0

             //定义结构about_app

             struct about_app {

                       char *version;

                       int field1;

                       int field2;

             }a;

             //赋值

             a.field1=12;

             a.field2=13;

             //使用0填充所有的fields

             memset(&a,0,sizeof(struct about_app));

             //打印出所有的fields查看是否为0

             lr_output_message("After memset field1=%d field2=%d",a.field1,a.field2);

             //初始化结构,并赋初值。

             a.version="app version1.0";

             a.field1=5;

             a.field2=6;

             lr_output_message("Now,field1=%d field2=%d",a.field1,a.field2);

  • Mathematics Functions

    2012-06-05 11:45:02

    Mathematics functions allow you to perform. mathematical operations. Expand the category to view a list of the available functions.

     

    Function Name

    Description

    floor

    Gets the largest integral value that is less than x.

    rand

    Gets a random integer between 0 and RAND_MAX.

    sqrt

    Computes the square root of x.

    srand

    Seeds the pseudo-random number generator.

     

     

       例子:

      double sqrt(double x); //开平方根需要事先声明

        lr_output_message ("Square root of 9 = %f\n", sqrt(9));

        lr_output_message ("Square root of 8 = %f\n", sqrt(8));

        lr_output_message ("Square root of -8 = %f\n", sqrt(-8));

     

        例子:

        //调用rand之前先调用srand

        srand(time(NULL));

        //返回数值范围是0-RAND_MAX伪随机整数

        lr_output_message ("A number between (0,100): %d\n", rand() % 100);

        lr_output_message ("A number between (20,30): %d\n", rand() % 10+20);

        //调用rand之前先调用srand

             //返回数值范围是0-RAND_MAX伪随机整数

        srand(time(NULL));

        //返回数值范围是0-RAND_MAX伪随机整数0100

        lr_output_message

            ("A number between (0,100): %d\n", rand() % 100);

     

       例子:

        double floor(double x); //显示声明

             //整数部分取整,小数部分为零

        lr_output_message ("floor of 2.3 is %.1lf\n", floor(2.3));

        lr_output_message ("floor of 3.8 is %.1lf\n", floor(3.8));

             //负数往小取负整数

        lr_output_message ("floor of -2.3 is %.1lf\n", floor(-2.3));

        lr_output_message ("floor of -3.8 is %.1lf\n", floor(-3.8));

     

     

     

     

  • Data Type Conversion Functions

    2012-06-05 00:07:40

    Data Type Conversion functions allow you to convert strings from one data type to another. These functions contain the to phrase. Expand the category to view a list of the available functions.

    Click one of the following functions for more information:

    Function Name

    Description

    atof

    Converts a string to a floating point value.

    atoi

    Converts a string to an integer value.

    atol

    Converts a string to a long integer value.

    itoa

    Converts an integer to a string. Windows only.

    strtol

    Converts a string to a long integer using a given radix.

     

     

           例子:转换字符串s的初始部分为float数据

           double atof(const char *string);/* Explicit declaration */ //显示声明

           float x;

           char *s = "7.2339 by these hilts or I am a villain else";

           //转换为实型数据并以保留两位小数输出到输出窗口

           x=atof(s);

           lr_output_message("%.2f",x);

     

     

        例子:转换字符串s的初始部分为int数据

        int i;

        char * s = "7 dollars";

        //转换为整型数据

        i = atoi(s);

        lr_output_message ("Price $%d", i);

     

     

       //例子:转换字符串s的初始部分为long数据

        long atol(const char * s); // Explicit declaration  //显示声明

        long i;

        char * s = "2147483647 dollars";

        //转换为长整型

        i = atol(s);

        lr_output_message ("Price $%ld", i);

     

    例子:转换字整型把数据卫字符串数据

    int i=56;

    char filename[64].file_index[32];

    if(!itoa(i,file_index,10)

    lr_output_message("Cannot convert i to ascii char");

    else {

    sprintf(filename,"log_%s.txt",file_index);

    lr_output_message("New file name %s",filename);

    }

     

  • Character Classification and Conversion Functions

    2012-06-04 16:47:04

    Character Classification and Conversion Functions

     

    Character Classification and Conversion functions allow you to convert characters within a string. Expand the category to view a list of the available functions.

    Click one of the following functions for more information:

    Function Name

    Description

    tolower

    Converts a string to lowercase.

    toupper

    Converts a string to uppercase.

    isdigit

    Checks if a string is a decimal digit.

    isalpha

    Checks if a string is a letter.

     

    例子

    char character_set[]={'A','5','$','z','c'};

    int i;

    //将所有字符转换为大写

    for (i=0;i<5;i++) {

             lr_output_message("%c ",toupper(character_set[i]));

    }

    //将所有字符转换为小写

    for (i=0;i<5;i++) {

    lr_output_message("%c ",tolower(character_set[i]));

             }

     

    例子

    //Checks if a string is a decimal digit (characters `0' to `9').

    if(isdigit(55))

             lr_output_message("The value 55 is the digit %c",55);

    else

             lr_output_message("Value 55 is not a digit. It's the character %c",55);

    ////Checks if a string is a decimal digit (characters `0' to `9').

    if(isdigit(109))

             lr_output_message("The value 109 is the digit %c",109);

    else

             lr_output_message("Value 109 is not a digit. It's the character %c.",109);

     

    //The function isalpha checks to see if the value of interger falls within the ranges A - Z or a - z.

    if(isalpha(107))

             lr_output_message("The value 107 is %c",107);

    else

             lr_output_message("Value 107 is not alphabetic.It's the digit %d",107);

    //The function isalpha checks to see if the value of interger falls within the ranges A - Z or a - z.

    if(isalpha(22))

             lr_output_message("The value 22 is %c",22);

    else

             lr_output_message("The value 22 is not alphabetic. It's the digit %d",22);

     

  • LR File Manipulation Functions examples

    2012-06-04 16:01:24

    File Manipulation functions allow you to manipulate directories. Expand the category to view a list of the available functions.

    Click one of the following functions for more information:

    Function Name

    Description

    chdir

    Changes the current directory to the given path.

    chdrive

    Switches to another drive.

    getcwd

    Returns the name of the current working directory.

    getdrive

    Returns the name of the current drive.

    mkdir

    Creates a directory using the given path name.

    remove

    Deletes the specified file.

    rmdir

    Deletes the specified directory.

     

     

     

     

    例子:The following example uses mkdir to create a new directory, xyz. It then moves to the new directory.

    #ifdef unix

    char new_dir[]="/tmp/xyz"

    #else

    char new_dir[]="C:\\xyz";

    #endif

     

    //加载外部函数

    lr_load_dll("D:\Accessdll.dll");

    //动态文件中包含如下函数

    /*int file_exists(char *filename)

    return (access(filename,0)==0);*/

     

    //判断目录是否存在可以用

    if(file_exists(new_dir)) {

    lr_output_message("%s directory exists",new_dir);

    rmdir(new_dir);

    }

    //root目录下创建xyz目录,并设置其为当前目录

    if (mkdir(new_dir)) {

             lr_output_message("Create directory %s failed",new_dir);

             return -1;

    }

     

    else

    lr_output_message("Created new directory %s",new_dir);

     

    //变更目录

    if (chdir(new_dir)) {

             lr_output_message("Unable to change to dir %s",new_dir);

             return -1;

    }

    else

    lr_output_message("Changed to new dir %s",new_dir);*/

     

     

     

    例子:The following example uses chdrive to move to all available drives on the file system.

    It saves the original drive in curdrive, so it can be restored later.

    int drive,curdrive;

    //获取当前的盘符

    curdrive=getdrive();

    lr_output_message("Available drives are:");

    //循环读取本系统中所有的盘符

    for(drive=1;drive<=26;drive++)

             if(!chdrive(drive))

                lr_output_message("%c:",drive + 'A'-1);

             chdrive(curdrive);

     

     

     

    例子:This example uses getcwd to save the current directory, before moving to a new directory.

    It then moves back to the first directory.

    #define DIR_LEN 512

    char original_dir[DIR_LEN];

    #ifdef unix

    char new_dir[]="/tmp";

    #else

    char new_dir[]="C:\\";

    #endif

    //getcwd如果成功返回当前的字符串,否则返回空值

    if (!getcwd(original_dir,DIR_LEN)) {

    lr_output_message("getcwd error");

    return -1;

    }

    else

    lr_output_message("The current dir is: %s",original_dir);

    if (chdir(new_dir)) {

             lr_output_message("Unable to locate directory:%s",new_dir);

             return -1;

    }

    else

    lr_output_message("Changed dir to %s",new_dir);

    if (chdir(original_dir)) {

             lr_output_message("Cannot move back to #s",original_dir);

             return -1;

    }

    else

    lr_output_message("Move back to %s",original_dir);

     

     

     

    例子:/*The system function executes a dir command.

    The output of the command is written (using `>) to the newly created file.

    The content of the file should be a list of the contents of the C drive.

    It then deletes the new file with remove*/

     

    char filename[1024],command[1024];

    char new_dir[]="C:\\xyz";

    extern int errno;

     

    //root下创建xyz目录,并设为当前目录

    if(mkdir(new_dir))

             lr_output_message("Create directory %s failed",new_dir);

    else

    lr_output_message("Created new directory %s",new_dir);

    //filename赋值为C:\xyz\newfile.txt

    sprintf(filename,"%s\\%s",new_dir,"newfile.txt");

    //command赋值为dir C:\ > C:\xyz\newfile.txt /w

    sprintf(command,"dir /b C:\\ > %s /w",filename);

    //运行命令:dir /b C:\ > C:\xyz\newfile.txt /w

    system(command);

    lr_output_message("Create new file %s",filename);

     

    //删除已经建立的文件

    if (remove(filename) == 0)

            lr_output_message ("Removed new file %s", filename);

        else

            lr_output_message ("Unable to remove %s error %d", filename, errno);

     

    例子:/*在windows系统,用LR中的system函数执行系统命令,在LR中利用C函数建立文件,写文件,读文件。
      主要相关函数:sprintf/fopen/fgetc/fread/fclose*/
      int count,total=0,i;
         char buffer[1000];
         long file_stream;
         char filename[1024], command[1024],line[100];
         char new_dir[] = "C:\\test";
         if (mkdir(new_dir))
              lr_output_message("Create directory %s failed", new_dir);
         else
              lr_output_message("Created new directory %s", new_dir);
         sprintf (filename, "%s\\%s", new_dir, "newfile.txt");
         sprintf (command, "dir /b c:\\ > %s /w", filename );
         system(command);//通过DOS管道命令创建TXT文件
         lr_output_message("Created new file %s", filename);
      //以只读方式打开文件
       if((file_stream=fopen(filename,"r"))==NULL)
           {
           lr_error_message("can not open %s",filename);
           return -1;
       }
       //逐行读取TXT文件中的字符串
       for(i=1;i<10;i++)
        {
           if (fgets(line, 100, file_stream) == NULL)
              lr_output_message("fgets error" );
         else 
              lr_output_message( "The line%d is: %s",i,line);
        }
    //如果已经到文件结尾,计算总得字节数
        while(!feof(file_stream))
                  {
          count=fread(buffer,sizeof(char),1000,file_stream);
           lr_output_message("%3d read",count);

     //Checks if any error has occurred during file I/0.
        if(ferror(file_stream))
                  {
        lr_output_message("error reading file %s",filename);
        break;
            }
    //把计算后的Count赋值给total
       total+=count;
            }
          lr_output_message("Total number of bytes read = %d",total);

         if(fclose(file_stream))//关闭文件
          lr_error_message("Error closing file %s",filename);

  • LR文件输入输出函数

    2012-06-03 11:18:36

    Input Output functions allow you to read and write to files. Most of these functions begin with an f prefix. Expand the category to view a list of the available functions.

     

    Function Name

    Description

    fclose

    Closes a file.

    feof

    Checks if the end of file has occurred on a stream.

    ferror

    Checks if any error has occurred during file I/0.

    fgetc

    Gets a character from a stream.

    fgets

    Reads a string from a file.

    fopen

    Opens a file for buffered I/0.

    fprintf

    Writes formatted output to a file.

    fputc

    Writes a character to a stream.

    fread

    Reads unformatted data from a stream into a buffer.

    fscanf

    Reads formatted input from a stream.

    fseek

    Sets the current position in a file to a new location.

    fwrite

    Write unformatted data from a buffer to a stream.

    rewind

    Rewinds a file.

    sprintf

    Writes formatted output to a string.

    sscanf

    Reads formatted input from a string.

     

     

     

     

    例子:The following example opens a log file and writes the string to it using fputc.

        //预处理命令之条件编译,如果已经定义了#define,取#ifdef,现取#else部分

        #ifdef unix

            char * filename = "/tmp/logfile.txt";

        #else

            char * filename = "D:\\logfile.txt"; //运行前现在路径下建立文件

        #endif

     

        long file; //使用long来取代文件指针File *fp来声明变量

        char * p, str[] = "this is the first line of the log file";

        int c;

     

        //创建新文件

        //通过判断file的值与NULL是不是相等来验证文件是否正常打开

        if ((file=fopen(filename,"w+"))==NULL) {

            lr_output_message("Unable to create %s",filename);

            return -1;

        }

        //向文件中写入字符串

        p = str; //p指针指向数组str的第一个字符

        //文本文件结束标记EOF,十进制为-1,十六进制为oxffwhile后跟一空语句

        while ((*p != NULL) && fputc(*(p++), file) != -1);

        fclose(file);

     

     

       例子:The following example, for Windows platforms, opens a file and reads 3 characters into a buffer using fgetc.

       #define NUM_CHARS 3

       int i,total=0;

       char buffer[100],ch;

       long file;

       char *filename="D:\\readme.txt";

       //只读方式打开文件,并且file指向文件,如果为NULL,文件为正常打开

       if((file=fopen(filename,"r"))==NULL) {

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

            return -1;

       }

       //feof未读取到文件末尾返回0,否则返回非零值

       for (i=0; (i<NUM_CHARS) && (feof(file) == 0); i++) {

           ch=fgetc(file);

           buffer[i]=ch;

       }

     

       buffer[i]=NULL;

       lr_output_message("First %d characters of file %s are \"%s\"",NUM_CHARS,filename,buffer);

       if (fclose(file))//文件关闭成功返回0,否则返回EOF

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

     

     

     

       例子:The following example, for Windows platforms, opens a file and reads the first line using fgets.

        int i,total=0;

        char line[100],ch;

        long file;

        char *filename ="D:\\readme.txt";

        ////通过判断   file的值与NULL是不是相等来验证文件是否正常打开

        if((file=fopen(filename,"r"))==NULL) {

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

            return -1;

        }

        //获得文件中第一行字符串

        if((fgets(line,100,file)==NULL))

           lr_output_message("fgets error");

        else

            lr_output_message("The first line is \"%s\"",line);

        if(fclose(file))

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

     

       例子:The following example opens a log file and writes the id number and group name of the Virtual User to it using fprintf.

       //预处理命令之条件编译,如果已经定义了#define,取#ifdef,现取#else部分

        #ifdef unix

            char * filename = "/tmp/logfile.txt";

        #else

            char * filename = "D:\\logfile.txt";

        #endif

     

        long file;

        int id;

        char * groupname;

        // <span style='fon

  • 编译预处理#define

    2012-06-02 12:18:29

    编译预处理在Loadrunner应用的例子:
     
    例一:结果1
    #define SQR(X) X*X
    int a=10,k=2,m=1;
    a/=SQR(k+m)/SQR(k+m);
    //printf("%d",a);
    lr_output_message("%d",a);
     
    例二:结果48
    #define N 3
    #define Y(n) ((N+1)*n)
    lr_output_message("%d",2*(N+Y(5+1)));
     
    例三:结果8
    #define MA(X)  X*(X-1)
    int a=1,b=2;
    lr_output_message("%d",MA(1+a+b));
     
    例四:结果97,c
    #define STR "%d,%c"
    #define A 97
    lr_output_message(STR,A,A+2);
    例五:结果9911
     
    #define PR(ar) lr_output_message("%d",ar)
     int j,a[]={1,3,5,7,9,11,13,15},*p=a+5;
    for (j=3;j;j--) {
     switch (j) {
     case 1:
     case 2: PR(*p++);break;
     case 3: PR(*(--p));
     }
    }
    例六:结果7
    #define MAX(x,y) (x)>(y)?(x):(y)
    int a=5,b=2,c=3,d=3,t;
    t=MAX(a+b,c+d)*10;
    lr_output_message("%d\n",t);
     
    例七:结果9
    #define POWER(x) (x)*(x)
    int a=1,b=2,t;
    t=POWER(a+b);
    lr_output_message("%d\n",t);
     
    例八:结果10
    #define A 2
    #define B 3*A
    #define C B+A
    lr_output_message("%d\n",C*2);
     
     
     
     
     
     
     
     

     
  • LR耗时统计函数例子

    2012-05-30 16:22:23


    /*********************************
    说明:LoadRunner中每一步都是需要消耗时间的。
    所谓耗时(Wasted Time)解释如下:
    Wasted time is time spent on activities whose purpose is to support test analysis, but would never be performed by a browser user, for example, time spent keeping transaction statistics for later reporting. Wasted time is calculated internally by LoadRunner. Your script. can also add wasted time with lr_wasted_time.

    Sometimes, you may enter activities in a script. that your do not want reported as part of the transaction statistics. Generally, these are activities related to record keeping, logging, or custom analysis. If you enhance the script. with steps whose durations should not be included in the test statistics, you can track the time used by these steps with lr_start_timer and lr_end_timer. Then, the function lr_wasted_time is used for adding this user-determined time to the internally generated wasted time.

    You can retrieve the total wasted time (both that generated by LoadRunner automatically and that added with lr_wasted_time) with the function lr_get_transaction_wasted_time, or with lr_get_trans_instance_wasted_time, as appropriate. *///*******************************

    Action()
    {
        int i, baseIter = 1000;
        char dude[1000];
        double wasteTime, actualElapsedTime;
        merc_timer_handle_t MasterT, timer;

        // Examine the total elapsed time of the action
     // MasterT以秒为单位并以此为开始计算时长起点(秒)
        MasterT = lr_start_timer();
     
        lr_start_transaction("Demo"); //Start transaction

        // Create some elapsed time for the transaction
        for (i=0; i< (10 * baseIter); ++i)
                sprintf(dude,
                    "This is the way we create elapsed time artificially = %d", i);       

     // Add some think time
        lr_think_time(0.5);

        // Create some wasted time and record it with timer
        timer = lr_start_timer(); ////timer以秒为单位并以此为计算时长起点(秒)。
        for (i=0; i< (5 * baseIter); ++i)
                sprintf(dude,
                    "This is the way we waste time in a script. = %d", i);

        wasteTime = lr_end_timer(timer); //停止timer计时器,并返回消耗的时长(秒)。
        lr_output_message("User created waste time = %lf", wasteTime);
        lr_output_message("Before lr_waste_time: Duration = %lf - Waste = %lf",        
            lr_get_transaction_duration("Demo"),
            lr_get_transaction_wasted_time("Demo"));

        /* Convert Timer in seconds to wasted time in milliseconds
         and add to internally generated waste time */
        wasteTime *= 1000;
        lr_wasted_time(wasteTime);

        lr_output_message("After lr_waste_time: Duration = %lf - Waste = %lf",
                lr_get_transaction_duration("Demo"),
                lr_get_transaction_wasted_time("Demo"));

        lr_output_message("Think time = %lf",
            lr_get_transaction_think_time("Demo"));

        lr_end_transaction("Demo", LR_AUTO);
        actualElapsedTime = lr_end_timer(MasterT); //统计总耗时(秒)。
        lr_output_message("Total Elapsed time for Action = %lf", actualElapsedTime);

        return 0;

    }


     

  • visual 2008中error PRJ0003 : 生成 cmd.exe 时出错”

    2012-05-24 15:58:20

    visual 2008error PRJ0003 : 生成 cmd.exe 时出错

    刚装完Visual2008,建了个Win32工程,一编译就出现 项目 : error PRJ0003 : 生成“cmd.exe”时出错。

    解决方案:工具—>选项—>项目和解决方案—>VC++目录,在可执行文件栏中加上如下路径:

    $(SystemRoot)/System32
    $(SystemRoot)
    $(SystemRoot)/System32/wbem

    现在运行成功了,Win32工程路径Debug下已经生成DLL文件

    C:\Users\P000800880\Documents\Visual Studio 2008\Projects\mydll\Debug

     

    Debug下文件:

    mydll.dll(新生成)

    mydll.exp(新生成)

    mydll.ilk(新生成)

    mydll.lib(新生成)

    mydll.pdb(新生成)

     

     

     

     

     

  • ruby笔记

    2011-11-02 09:03:36

    #puts "hello world!"
    #::
    =begin
    module
    class
    def,undef
    defined?
    if,then,else,elsif,case,when,unless
    for,in,while,until,next,break,do,redo,
    retry,yield
    not,and,or
    true,false,nil
    rescue,ensure
    super,self
    begin/end
    BENGIN END
    _FILE_,_LINE_
    return
    alias
    require,include

    [] []=
    **
    !~+-
    */%
    +-
    >> <<
    <= < > >=
    <=> == ===
    =~ != !~
    &&
    ||
    .. ...
    defined?
    not
    or and
    if unless while until
    begin/end
    局部变量、方法参数、方法名用一个小写字母开头
    或者用一个下划线开头,全局变量用美元符号作为前缀
    ¥,实例变量用@开头,类变量用@@开头
    类名、模块名、常量用大写字母开头。

    词首字母后面可以是字母、数字和下划线的任意组合
    @后面不可以直接跟数字


    类库

    require include将类库程序名包含在已经定义好的
    类、方法。从父类继承得到的方法可以直接使用

    I/O 输入/输出 Ruby语言Kernel模块的方法,Mix-in在根类的Object中


    puts带换行符号,print不带换行符号
    printf "Number:%4.3f,string:%s",7.8,"hi!" \n

    gets

    =end


    =begin
    数据类型

    浮点型数据小数点后必须跟数字1.1e3
    0表示八进制,0x表示十六进制,0b表示二进制

    字符串是在单引号,双引号之间的代码

    1..5    1,2,3,4,5 [1,5]
    1...5   1,2,3,4   [1,5)


        
    a =1;b=2+3
    a,b=b,a#值互换
    print a ; print b


    x=0
    a,b,c=x,(x+1),(x+2)
    puts a,b,c
    print a,b,c
    print a


    a=1;b=1.0;print a==b

    a=1;b=1.0;
    puts a.eql?(b)

    a=1;b=1.0;
    print a.equal?(b)


    a=1.0;b=a
    print a.equal?(b)


    puts 'aab'<=>'acb'
    puts     [5]<=>[4,9]



    puts (0..9)===3.14
    puts ('a'..'c')==='c'
    =~用来比较是否符合一个正则表达式,返回模式在字符串中被匹配到得位置,否则返回nil
    !~断言不符合一个正则表达式,返回true,false


    if 条件 then 语句 end
    语句 if 条件

    if conditon
        statement
        elsif condition
            statement
            else
                statement
            end
           

    unless= if not
       
        case object
            when condition
            statement
            when condition
            statement
            else
                statement
            end
           



    x=3
    case x
        when 1..2
        print "x=",x,";在1..2中"
        when 4..9,0
        print "x=",x,";在4..9中,或是0"
        else
            print "x=",x,";其它可能"
        end
       


    a =1
    until a>=10
    print a," "
    a=a+1
    end


    a=1
    while  not a>=10
        print a," "
    a=a+1
    end



    until= while not   
     

    for i  in 1..9
        print i, " "
    end

    break
    next
    redo
    retry



    puts "演示break"
    c='a'
    for i in 1..4
        if i==2 and c=='a'
            print "\n"
            break
        end
        print i,c," "
    end
    puts "\n\n"




    puts "演示break"
    c='a'
    for i in 1..4
        if i==2 and c=='a'
            c='b'
            print "\n"
            next
        end
        print i,c," "
    end
    puts "\n\n"



    puts "演示break"
    c='a'
    for i in 1..4
        if i==2 and c=='a'
            c='b'
            print "\n"
            redo
        end
        print i,c," "
    end
    puts "\n\n"



    puts "演示break"
    c='a'
    for i in 1..4
        if i==2 and c=='a'
            c='b'
            print "\n"
            retry
        end
        print i,c," "
    end
    puts "\n\n"


    for i in 2..100
        f=true
        for p in 2..i
            if i%p==0 and i!=p
                f=!f
                break
            end
        end
        print i," " if f
    end




    #3.times {print "Hi!"}
    #9.downto(1) {|i| print i if i <7}
    #1..9).each {|i| print i if i<7}
    #1.upto(9) {|i| print i if i<7}

    #0.step(11,3) {|i| print i}

    try catch finally throw
    begin/end rescue ensure raise



    谁将被影响 ====来编写代码
    以类为模块,以消息来驱动程序的执行


    对象===静态的属性 , 动态的方法
    子类型从父类型得到属性、方法。我们称之为继承

    同一个父类,不同子类有不同的行为和状态,我们称之为多态

    对象的属性、方法只有定义代码的人知道,其它的类不知道,这就是封装

    封装、继承、多态是面向对象编程的三个本质特征



    人们可以决定代码世界中一类事物的属性、方法,当然可以修改代码世界中
    一类事物的属性、方法,而且可以委托其它的类来修改,甚至删除。这就是动态
    动态语言超越静态语言之处,由于代码是一直运行着的,与其他代码一直交互,修改,删除应慎重,避免产生副作用。




    attr_writer:motherland

    def motherland=(value)
        return @motherland=value
    end




    attr_reader:motherland
    def motherland
        return @motherland
    end

    封装完成了 隐藏实现

    class Person
        def initialize(name,age=18)
            @name =name
            @age=age
            @motherland="China"
        end
        def talk
            puts "my name is "+@name+",age is "+@age.to_s
            if @motherland=="China"
                puts "I am a Chinese"
                else               
                puts "I am a foreigner"
            end
        end
        attr_writer:motherland
    end

    #p1=Person.new("kaichun",20)
    #p1.talk
    #p2=Person.new("Ben")
    #p2.motherland ="ABC"
    #p2.talk
               

    puts "****************"

    class Student < Person
        def talk
            puts "I am a student. my name is "+@name+", age is "+@age.to_s
        end
    end
    p3=Student.new("kaichuan",25);p3.talk
    p4=Student.new("Ben"); p4.talk
           
       
       
    继承、重写方法
    子类继承父类可以重写方法、也可以增加一些新的方法,以增强父类的方法

    当你new的时候,一个实例就按照蓝图生成了






    Ruby灵巧、快速,但并不简单!
    冗余,不可预知
    冗余性、缺陷性、动态性


    由编译内核(或解释内核)在运行时刻来判断变量类型的语言,叫动态语言

    一切都是对象,但是变量不是对象,变量是引用某个对象时候的代号而已




    a=5
    b="hh"
    puts "a=#{5}"
    puts "b=#{b}"



    变量类型
    常量


    变量名、变量值、变量类型、变量的作用域



    (1..9).each {|i| print i if i<7}


    def one_block
        yield
        yield
        yield
    end
    one_block{puts "This is a block. "}



    def one_block
        for num in 1..3
            yield(num)
        end
    end
    one_block do |i|
        puts "This is block#{i}."
    end


    def do_something
        yield
    end

    do_something do
        (1..9).each {|i| print i if i<5}
        puts
    end

    do_something do
        3.times {print "Hi!"}
        puts
    end



    class Array
        def one_by_one
            for i in 0..size
                yield(self[i])
            end
            puts
        end
    end

    arr=[1,3,5,7,9]
    arr.one_by_one {|k| print k, ","}
    arr.one_by_one {|h| print h*h, ", "}

    class Array
    def one_by_one
    for i in 0...size
    yield(self[i] )
    end
    puts
    end
    end
    arr = [1,3,5,7,9]
    arr.one_by_one {|k| print k , ", "} # 1, 3, 5, 7, 9,
    arr.one_by_one {|h| print h*h, ", "} # 1, 9, 25, 49, 81,



    class Array
        def one_by_one
            for i in 0...size
                yield(self[i])
            end
            puts
        end
    end
    arr=[1,3,5,7,9]
    arr.one_by_one {|k| print k, ","}
    arr.one_by_one {|h| print h*h,","}


    def method(pr)
        puts pr.call(7)
    end

    oneProc=proc {|k|  k *=3}
    method(oneProc)





    def method(n)
        return proc {|i| n +=i}
    end

    oneProc=method(3)


    puts oneProc.call(9)
    puts oneProc.call(5)




    puts self.private_methods.sort




    rice_on_square =1
    64.times do |square|
        puts "On square #{square+1} are #{raice_on_square} gain(s)"
        rice_on_quare *=2
    end


    rice_on_square = 1
    64.times do |square|
    puts "On square #{square + 1} are #{rice_on_square} grain(s)"
    rice_on_square *= 2
    end



    rice_on_square = 1
    64.times {|square|
    puts "On square #{square } are #{rice_on_square} grain(s)"
    rice_on_square *= 2}

    #do end 替代{}
    #相当是一个循环!


    watir已经搭建好了!
    require "watir" 
    test_site = "http://www.google.com" 

    ie = Watir::IE.new 
    puts "Beginning of test: Google search." 
    #puts " Step 1: go to the test site: " + test_site 
    ie.goto test_site 

    ie.text_field(:name, "q").set "pickaxe"
    ie.button(:name, "btnG").click

    if ie.text.include? "Programming Ruby"  
    puts "  Test Passed. Found the test string: 'Programming Ruby'. Actual Results match Expected Results." 
    else 
    puts "  Test Failed! Could not find: 'Programming Ruby'." 
    end 
    puts "End of test: Google search."
    =end
  • Linux性能评测工具nmon

    2011-04-17 22:27:07

    1. nmon概述
    1.1. 概述

    nmon是收集AIX或Linux主机的性能数据并分析的工具,使用简单易用。主要有两个,一个是nmon采集数据的工具,一般名称为nmon_**,例如 nmon_aix5.3,另一个是分析结果的工具,它是一个excel的文件,名称为:nmon analyser v33A.xls。

    nmon在一个屏幕上显示所有重要的性能优化信息,并动态地对其进行更新。还可以将相同的数据捕获到一个文本文件,便于以后对报告进行分析和绘制图形。

    nmon_analyser 工具以 NMON 性能工具生成的文件作为输入,然后将它们转换为 Microsoft Excel 电子表格,并自动地生成相应的图形。

    nmon 工具可以为 AIX 和 Linux 性能专家提供监视和分析性能数据的功能,其中包括:

    l CPU 使用率

    l 内存使用情况

    l 内核统计信息和运行队列信息

    l 磁盘 I/O 速度、传输和读/写比率

    l 文件系统中的可用空间

    l 磁盘适配器

    l 网络 I/O 速度、传输和读/写比率

    l 页面空间和页面速度

    l 消耗资源最多的进程

    l 计算机详细信息和资源

    IBM 没有提供对该工具的正式支持,并且您在使用它的时候必须自己承担相应的风险,但是您可以从中获得大量有价值的性能统计信息。其中,nmon for linux版本已经在2009年7月27日开放源码。

    1.2. 适用范围

    本文档为使用nmon作为性能测试中监控linux服务器的应用,提供使用规范和帮助。

    1.3. 词汇表

    词汇
       

    解释

    Nmon
       

    性能数据收集分析工具

    Nmon analyser
       

    性能数据分析工具,excel文件

    nmon_x86_sles10
       

    Nmon在x86_sles10下二进制执行文件

    1.4. 参考资料

    Nmon在IBM的官方网站

    http://www.ibm.com/developerworks/wikis/display/WikiPtype/nmon

    nmon for linux的官方网站

    http://nmon.sourceforge.net/pmwiki.php

    文章一:《nmon 性能:分析 AIX 和 Linux 性能的免费工具》

    http://www.ibm.com/developerworks/cn/aix/library/analyze_aix/

    文章二:《nmon analyser——生成 AIX 性能报告的免费工具》

    http://www.ibm.com/developerworks/cn/aix/library/nmon_analyser/index.html:

    1.5. 获取该工具

    下载nmon工具的可执行文件nmon_x86_sles10。

    http://nmon.sourceforge.net/pmwiki.php?n=Site.Download

    也可以下载源码自己编译特定的版本。(推荐这个)

    http://nmon.sourceforge.net/pmwiki.php?n=Site.CompilingNmon

    下载nmon Analyser V3.3

    http://www.ibm.com/developerworks/wikis/display/Wikiptype/nmonanalyser

    下载nmon Consolidator

    http://www.ibm.com/developerworks/wikis/display/WikiPtype/nmonconsolidator

    ibm的其他性能测试工具

    http://www.ibm.com/developerworks/wikis/display/WikiPtype/Performance+Other+Tools

    2. nmon
    2.1. 安装

    该工具是一个独立的二进制文件(不同的 AIX 或 Linux 版本中该文件也有所不同)。安装过程非常简单:

    1. 将 nmon_x86_sles10文件复制到计算机,rz—>在弹出框选择nmon_x86_sles10。

    2. 修改nmon_x86_sles10的文件权限,chmod 777 ./nmon_x86_sles10

    3. 要启动 nmon 工具,输入 ./ nmon_x86_sles10。
    2.2. 运行

    Nmon可以交互式运行

    l 启动该工具 ./ nmon_x86_sles10

    l 使用单键命令来查看您所需要的数据。例如,要获取 CPU、内存和磁盘统计信息,启动 nmon 并输入: c m d

    l 获取相关的帮助信息,按 h 键。

    使用下面这些键来切换显示状态:

    c = CPU l = CPU Long-term  - = Faster screen updates  

    m = Memory j = Filesystems + = Slower screen updates 

    d = Disks n = Network V = Virtual Memory

    r = Resource N = NFS v = Verbose hints

    k = kernel t = Top-processes . = only busy disks/procs

    h = more options q = Quit   
    2.3. 捕获数据到文件

    捕获数据到文件,只要运行带 -f 标志的 nmon 命令。执行nmon –f ***后,nmon 将转为后台运行。要查看该进程是否仍在运行,可以输入: ps -ef | grep nmon。

    示例:

    每1秒捕获数据快照,捕获20次

    nmon –f -s 1 -c 20

    每30秒捕获数据快照,捕获120次,包含进程信息

    nmon –ft -s 30 -c 120

    命令将在当前目录中创建输出文件,其名称为: <hostname>_date_time.nmon。该文件采用逗号分隔值 (CSV) 的格式,并且可以将其直接导入到电子表格中,可进行分析和绘制图形

       3. nmon_analyser

    nmon_analyser 工具以 NMON 性能工具生成的文件作为输入,然后将它们转换为 Microsoft Excel 电子表格,并自动地生成相应的图形。

    使用wps未能正确执行脚本生成*.xls文件。建议Excel?? 2000 或更高版本,必须在打开nmon_analyser选择启用宏。

    nmon_analyser 工具设计用于最新版本的 nmon,但出于向后兼容性的考虑,也使用旧版本对其进行了测试。每当在对 nmon 进行更新时,同时也将对该工具进行更新.

    本文来自:http://blog.csdn.net/stanjiang2010/archive/2010/06/08/5655150.aspx

    安装下载:http://nmon.sourceforge.net/pmwiki.php?n=Site.Download

  • Linux中的目录结构介绍

    2011-04-16 17:49:24

    1、文件系统
    了解Linux文件系统的目录结构,是学好Linux的至关重要的一步。首先需要明白什么是文件系统,以及为何Linux的文件系统结构是树形结构。linux文件系统的最顶端是/,我们称/为Linux的root,也就是 Linux操作系统的文件系统。Linux的文件系统的入口就是/,所有的目录、文件、设备都在/之下,/就是Linux文件系统的组织者,也是最高级的领导者。


    2、文件系统的类型
    LINUX有四种基本文件系统类型:普通文件、目录文件、连接文件和特殊文件,可用file命令来识别。
    普通文件:如文本文件、C语言元代码、SHELL脚本、二进制的可执行文件等,可用cat、less、more、vi、emacs来察看内容,用mv来改名。
    目录文件:包括文件名、子目录名及其指针。它是LINUX储存文件名的唯一地方,可用ls列出目录文件。
    连接文件:是指向同一索引节点的那些目录条目。用ls来查看是,连接文件的标志用l开头,而文件面后以"->"指向所连接的文件。
    特殊文件:LINUX的一些设备如磁盘、终端、打印机等都在文件系统中表示出来,则一类文件就是特殊文件,常放在/dev目录内。例如,软驱A称为/dev/fd0。LINUX无C:的概念,而是用/dev/had来自第一硬盘。


    3、目录结构
    以Red Hat为例对文件系统的组织结构进行分析,每个目录具体的功能用途。
    /  文件系统的入口,也是处于最高一级的目录;
    /bin 系统所需要的那些命令位于此目录,比如 ls、su、pwd等命令;这个目录中的文件都是可执行的、普通用户都可以使用的命令,作为基础系统所需要的最基础的命令就是放在这里;
    /boot Linux的内核及引导系统程序所需要的文件目录,比如 vmlinuz\initrd.img\boot.b\kernel.h等文件都位于这个目录中。在一般情况下,GRUB或LILO系统引导管理器也位于这个目录;
    /dev 设备文件存储目录,比如声卡、磁盘... ... ;
    /etc 系统配置文件的所在地,一些服务器的配置文件也在这里;比如用户帐号及密码配置文件;
    /home 普通用户home目录默认存放目录;
    /lib 库文件存放目录;
    /lost+found 在ext2或ext3文件系统中,当系统意外崩溃或机器意外关机,而产生一些文件碎片放在这里。当系统启动的过程中fsck工具会检查这里,并修复已经损坏的文件系统。有时系统发生问题,有很多的文件被移到这个目录中,可能会用手工的方式来修复,或移到文件到原来的位置上;
    /mnt 这个目录一般是用于存放挂载储存设备的挂载目录的,比如有cdrom\floppy等目录;
    /opt 表示的是可选择的意思,有些软件包也会被安装在这里,也就是自定义软件包;
    /proc 操作系统运行时,进程信息及内核信息(比如cpu、硬盘分区、内存信息等)存放在这里。/proc目录伪装的文件系统proc的挂载目录,proc并不是真正的文件系统,它的定义可以参见 /etc/fstab 。
    /root Linux超级权限用户root的家目录;
    /sbin 大多是涉及系统管理的命令的存放,是超级权限用户root的可执行命令存放地,普通用户无权限执行这个目录下的命令,凡是目录sbin中包含的都是root权限才能执行的。
    /tmp 临时文件目录,有时用户运行程序的时候,会产生临时文件。/tmp就用来存放临时文件的。/var/tmp目录和这个目录相似。
    /usr 这个是系统存放程序的目录,比如命令、帮助文件等。这个目录下有很多的文件和目录。当我们安装一个Linux发行版官方提供的软件包时,大多安装在这里。如果有涉及服务器配置文件的,会把配置文件安装在/etc目录中。
    /var 这个目录的内容是经常变动的,看名字就知道,我们可以理解为vary的缩写,/var下有/var/log
    这是用来存放系统日志的目录。/var/www目录是定义Apache服务器站点存放目录;/var/lib
    用来存放一些库文件,比如MySQL的,以及MySQL数据库的的存放地;


    4、一些重要子目录的解说
    下面飘扬再补充几个比较常见且很重要的目录。
    /etc/init.d      这个目录是用来存放系统或服务器以System V模式启动的脚本,这在以System V模式启动或初始化的系统中常见。比如Fedora/RedHat;
    /etc/xinit.d    如果服务器是通过xinetd模式运行的,它的脚本要放在这个目录下。有些系统没有这个目录, 比如Slackware,有些老的版本也没有。在Rehat/Fedora中比较新的版本中存在。
    /etc/rc.d        这是Slackware发行版有的一个目录,是BSD方式启动脚本的存放地;比如定义网卡,服务器开启脚本等。
    /etc/X11  这是X-Windows相关的配置文件存放地。
    /usr/bin
    这个目录是可执行程序的目录,普通用户就有权限执行;当我们从系统自带的软件包安装一个程序时,他的可执行文件大多会放在这个目录。比如安装gaim软件
    包时。相似的目录是/usr/local/bin;有时/usr/bin中的文件是/usr/local/bin的链接文件;
    /usr/sbin       这个目录也是可执行程序的目录,但大多存放涉及系统管理的命令。只有root权限才能执行;相似目录是/sbin 或/usr/local/sbin或/usr/X11R6/sbin等;
    /usr/local     这个目录一般是用来存放用户自编译安装软件的存放目录;一般是通过源码包安装的软件,如果没有特别指定安装目录的话,一般是安装在这个目录中。这个目录下面有子目录。自己看看吧。
    /usr/share   系统共用的东西存放地,比如 /usr/share/fonts 是字体目录,/usr/share/doc和/usr/share/man帮助文件。
    /usr/src 是内核源码存放的目录,比如下面有内核源码目录,比如
    linux 、linux-2.xxx.xx
    目录等。有的系统也会把源码软件包安装在这里。比如Fedora/Redhat,当我们安装file.src.rpm的时候,这些软件包会安装在
    /usr/src/redhat相应的目录中。
    /var/adm     比如软件包安装信息、日志、管理信息等,在Slackware操作系统中是有这个目录的。在Fedora中好象没有;自己看看吧。
    /var/log       系统日志存放,分析日志要看这个目录的东西;
    /var/spool   打印机、邮件、代理服务器等假脱机目录;


    5、附录:目录结构的简明查阅手册
    (1)“/”根目录部分有以下子目录:
    /usr 目录包含所有的命令、程序库、文档和其它文件。这些文件在正常操作中不会被改变的。这个目录也包含你的Linux发行版本的主要的应用程序,譬如,Netscape。
    /var 目录包含在正常操作中被改变的文件:假脱机文件、记录文件、加锁文件、临时文件和页格式化文件等
    /home 目录包含用户的文件:参数设置文件、个性化文件、文档、数据、EMAIL、缓存数据等。这个目录在系统省级时应该保留。
    /proc 目录整个包含虚幻的文件。它们实际上并不存在磁盘上,也不占用任何空间。(用ls –l 可以显示它们的大小)当查看这些文件时,实际上是在访问存在内存中的信息,这些信息用于访问系统
    /bin 系统启动时需要的执行文件(二进制),这些文件可以被普通用户使用。
    /sbin 系统执行文件(二进制),这些文件不打算被普通用户使用。(普通用户仍然可以使用它们,但要指定目录。)
    /etc 操作系统的配置文件目录。
    /root 系统管理员(也叫超级用户或根用户)的Home目录。
    /dev 设备文件目录。LINUX下设备被当成文件,这样一来硬件被抽象化,便于读写、网络共享以及需要临时装载到文件系统中。正常情况下,设备会有一个独立的子目  录。这些设备的内容会出现在独立的子目录下。LINUX没有所谓的驱动符。
    /lib 根文件系统目录下程序和核心模块的共享库。
    /boot 于自举加载程序(LILO或GRUB)的文件。当计算机启动时(如果有多个操作系统,有可能允许你选择启动哪一个操作系统),这些文件首先被装载。这个
    目录也会包含LINUX核(压缩文件vmlinuz),但LINUX核也可以存在别处,只要配置LILO并且LILO知道LINUX核在哪儿。
    /opt 可选的应用程序,譬如,REDHAT 5.2下的KDE (REDHAT 6.0下,KDE放在其它的XWINDOWS应用程序中,主执行程序在/usr/bin目录下)
    /tmp 临时文件。该目录会被自动清理干净。
    /lost+found 在文件系统修复时恢复的文件

    (2)“/usr”目录下比较重要的部分有:
    /usr/X11R6 X-WINDOWS系统(version 11, release 6)
    /usr/X11 同/usr/X11R6 (/usr/X11R6的符号连接)
    /usr/X11R6/bin 大量的小X-WINDOWS应用程序(也可能是一些在其它子目录下大执行文件的符号连接)。 
    /usr/doc LINUX的文档资料(在更新的系统中,这个目录移到/usr/share/doc)。
    /usr/share 独立与你计算机结构的数据,譬如,字典中的词。
    /usr/bin和/usr/sbin 类似与“/”根目录下对应的目录(/bin和/sbin),但不用于基本的启动(譬如,在紧急维护中)。大多数命令在这个目录下。
    /usr/local 本地管理员安装的应用程序(也可能每个应用程序有单独的子目录)。在“main”安装后,这个目录可能是空的。这个目录下的内容在重安装或升级操作系统后应该存在。
    /usr/local/bin 可能是用户安装的小的应用程序,和一些在/usr/local目录下大应用程序的符号连接。
    (3)“/proc”目录的内容:
    /proc/cpuinfo 关于处理器的信息,如类型、厂家、型号和性能等。
    /proc/devices 当前运行内核所配置的所有设备清单。
    /proc/dma 当前正在使用的DMA通道。/proc/filesystems 当前运行内核所配置的文件系统。
    /proc/interrupts 正在使用的中断,和曾经有多少个中断。
    /proc/ioports 当前正在使用的I/O端口。

     

     

    原文地址 http://linux.ccidnet.com/art/302/20070315/1037337_1.html


     

  • puTTY与SecureCRT

    2011-04-16 16:01:50

    1. Putty是免费的,SecureCRT是收费的.

    在各种远程登录工具中,Putty是出色的工具之,Putty是一个免费的、Windows 32平台下的telnet、rlogin和ssh客户端,但是功能丝毫不逊色于商业的telnet类工具。

    SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,同时支持Telnet和rlogin协议。SecureCRT是一款用于连接运行包括Windows、UNIX和VMS的远程系统的理想工具。通过使用内含的VCP命令行程序可以进行加密文件的传输。

    SecureCRT6.6.1破解步骤(破解文件如附件):
    1、运行scrt661-x86.exe安装secureCRT6.6。
    2、将SecureCRT-kg.exe拷贝到安装目录运行,点击Patch按钮打补丁。
    3、然后输入Name和Company,点击Generate按钮,生成License key。
    4、运行secureCRT.exe,点击菜单->Help->Enter License Data...,输入刚才的姓名、公司和生成的注册码。


    2. SecureCRT的缺省配置不是为linux准备的比较难看,Putty缺省配置就很好看很好用,用它来远程管理Linux十分好用,其主要优点如下:   
    ◆ 完全免费;   
    ◆ 在Windows 9x/NT/2000/XP下运行的都非常好;   
    ◆ 全面支持ssh1和ssh2;   
    ◆ 绿色软件,无需安装,下载后在桌面建个快捷方式即可使用;   
    ◆ 体积很小;
    ◆ 操作简单,所有的操作都在一个控制面板中实现


    3. Putty不支持自动登录linux,SecureCRT支持自动登录linux。这个区别显得Putty更安全,SecureCRT更方便。
    4. Putty不支持同时登录多个linux,SecureCRT可以在每个tab page里面登录一个linux。
    基于3,4两个区别使得SecureCRT更适合系统管理员使用。


     

  • 用脚本实现向Oracle表中插入数据

    2011-04-15 15:17:53


    首先,安装及环境配置

    1. 安装Oracle - OraClient10g_home2


    2. Net Configuration Assistant 配置步骤:

    假设数据库所在服务器IP地址为:  192.168.0.1

    数据库实例名为:ora92

    用户名: umap

    密码:umap

    第一步:打开配置程序

    位于:程序-->Oracle - OraClient10g_home2-->Configuration and Migration Tools-->Net Configuration Assistant ;

    第二步:选择配置项:

    打开程序后,出现的界面中有四个选项, 分别为(1)监听程序配置,(2)命名方法配置,(3)本地NET服务名配置,(4)目录使用配置. 这里我们选择第3个,点下一步

    第三步:根据需要选择操作内容,是添加还是对以前的配置进行修改或删除;

    第四步:根据您要连接的Oracle数据据库版本选择, 这里我们选择Oracle8i或更高版本数据库或服务;

    第五步:服务名,输入示例中的实例名;

    第六步:选择TCP;

    第七步:主机名:输入示例中的IP地址; 使用默认端口1521;

    第八步:使用您的登录帐户与密码进行连接测试,正常情况下测试通过。

    第九步:打开:程序-->Oracle - OraClient10g_home2-->Application Developer-->SQL Plus
    录入select * from dual;回车,有数据返回,则连接正常。

     

    然后,脚本录制

    第一步:打开Loadrunner,选择Oracle(2-Tier)协议
    Start Recording设置
    Application Type:Win32Applications
    Program to Record:选择sqlplus可执行程序的路径,如D:\oracle\product\10.2.0\client_2\BIN\sqlplusw.exe
    Record into Action:vuser_init

    第二步:开始录制
    输入:用户名(U),口令(P),主机字符串(H)
    点击确定按钮

    第三步:选择Action
    键入insert into lis.lcoldinfo (SERIALNO, CONTNO, PROPOSALCONTNO, CUSTOMERNO, CUSTOMERTYPE, NAME, SEX, BIRTHDAY, AGE, IDTYPE, IDNO, POLNO, RISKCODE, MAINPREM, PREM, PAYMONEY, HEALTHIMPARTFLAG, HEALTHIMPART1, HEALTHIMPART2, MANAGECOM, OERATOR, MAKEDATE, MAKETIME, MODIFYDATE, MODIFYTIME, STANDBYFLAG1, STANDBYFLAG2, STANDBYFLAG3, STANDBYFLAG4, STANDBYFLAG5)""values ('{Value_Pv}', '000', '6001237544', 'T000067060', '1', '李芬', '1', to_date('10-04-1983', 'dd-mm-yyyy'), 25, '0', '410103198304107040', '110600000004237', 'BENE11', 7680.00, 7680.00, 0.00, '3', '', '', '8660000000', '001', to_date('15-01-2009', 'dd-mm-yyyy'), '17:16:11', to_date('15-01-2009', 'dd-mm-yyyy'), '17:16:11', '', '', '', '', '';

    回车
    键入commit;回车

    第四步:选择vuser_end
    键入quit;回车
    停止录制

    第五步:修改Action部分脚本:
    Action()
    {

    int i;
    lr_output_message("当前时间为%s",lr_eval_string("{NewParam}"));


    for (i=0;i<4;i++) {

     char Value_P[20]="";
     char Value_Pv[20]="";
     char path[20]="";
     char separator[]=".";
     char * token;
     strcat(path,lr_eval_string("{DateTime}"));
     token = (char *)strtok(path,separator);
     if(!token){
      lr_output_message("No token found in string!);
            return(-1);
            }
     while(token != Null) {
      strcat(Value_P,lr_eval_string(token));
      token =(char*)strtok(NULL,separator);
            }
     strcat(Value_P,lr_eval_string("{VuserId}"));
     lr_eval_string(Value_P,"Value_Pv");
        lr_output_message( "当前流水号为 %s", lr_eval_string("{Value_Pv}") );

     //插入数据的过程中需要注意:ORA-00001:违反唯一约束条件-----------------------------------------------insert
      
    lrd_ora8_handle_alloc(OraEnv1, STMT, &OraStm7, 0);
    lrd_ora8_stmt(OraStm7, "insert into lis.lcoldinfo (SERIALNO, CONTNO, PROPOSALCONTNO, CUSTOMERNO, CUSTOMERTYPE, NAME, SEX, BIRTHDAY, AGE, IDTYPE, IDNO, POLNO, RISKCODE, MAINPREM, PREM, PAYMONEY, HEALTHIMPARTFLAG, HEALTHIMPART1, HEALTHIMPART2, MANAGECOM, OERATOR, MAKEDATE, MAKETIME, MODIFYDATE, MODIFYTIME, STANDBYFLAG1, STANDBYFLAG2, STANDBYFLAG3, STANDBYFLAG4, STANDBYFLAG5)"
    "values ('{Value_Pv}', '000', '6001237544', 'T000067060', '1', '李芬', '1', to_date('10-04-1983', 'dd-mm-yyyy'), 25, '0', '410103198304107040', '110600000004237', 'BENE11', 7680.00, 7680.00, 0.00, '3', '', '', '8660000000', '001', to_date('15-01-2009', 'dd-mm-yyyy'), '17:16:11', to_date('15-01-2009', 'dd-mm-yyyy'), '17:16:11', '', '', '', '', '')", 1, 32, 0);
      lrd_ora8_exec(OraSvc1, OraStm7, 1, 0, &uliRowsProcessed, 0, 0, 0, 0,  0);lrd_ora8_exec(OraSvc1, OraStm7, 1, 0, &uliRowsProcessed, 0, 0, 0, 0,  0);
    lrd_handle_free(&OraStm7, 0);
    }  //循环结束

    lr_output_message("当前时间为%s",lr_eval_string("{NewParam}"));
    return 0;

    }

    第六步:脚本完成


     

  • Loadrunner8.1 + JDK1.5如何解决System Exceptions: EXCEPTION_ACCESS_VIOLATION

    2011-04-14 15:38:40

    Java Vuser协议的遇到Exception was raised when calling abort-cleanup function in extension java_int.dll: System Exceptions: EXCEPTION_ACCESS_VIOLATION问题,现讲解下这个问题的解决方法。


    首先,保证纯净的操作系统


    我之前装的是Loadrunner9.5,准备配JDK1.6,最后怎么都是报错,然后采用Loadrunner8.1 + JDK1.5问题依旧,最后重装了系统,采用Loadrunner8.1 + JDK1.5问题解决。连网上说的A_lrunner_java_protocol_fixes_Feb_05.exe的补丁也未打。

    其次:确认JDK环境变量是否正确设置
    Windows xp下配置JDK环境变量:
          1.安装JDK,安装过程中可以自定义安装目录等信息,例如我们选择安装目录为D:\java\jdk1.5.0_08;
      2.安装完成后,右击“我的电脑”,点击“属性”;
          3.选择“高级”选项卡,点击“环境变量”;
          4.在“系统变量”中,设置3项属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),若已存在则点击“编辑”,不存在则点击“新建”;
          5.JAVA_HOME指明JDK安装路径,就是刚才安装时所选择的路径D:\java\jdk1.5.0_08,此路径下包括lib,bin,jre等文件夹(此变量最好设置,因为以后运行tomcat,eclipse等都需要依*此变量);      
           Path使得系统可以在任何路径下识别java命令,设为:
    %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin
        CLASSPATH为java加载类(class or lib)路径,只有类在classpath中,java命令才能识别,设为:
    .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar (要加.表示当前路径)
      %JAVA_HOME%就是引用前面指定的JAVA_HOME;
           6.“开始”->;“运行”,键入“cmd”;
           7.键入命令“java -version”,“java”,“javac”几个命令,出现画面,说明环境变量配置成功;
          8. DOS中查看相关环境变量是否正常显示echo %path%,echo %classpath%,echo %java_home%。

    再则,相关的Class有没有Import进去。


    保证上面三步,就可以解决System Exceptions: CEPTION_ACCESS_VIOLATION报错问题。

  • XML Functions with Loadrunner

    2011-02-28 15:03:41

    XML Function

    Retrieves values of XML elements found by a query
    Sets the values of XML elements found by a query
    Extracts XML string fragments from an XML string
    Deletes fragments from an XML string
    Replaces fragments of an XML string
    Inserts a new XML fragment into an XML string
    Verifies that XML values are returned by a query
    Applies Extensible Stylesheet Language (XSL) Transformation to XML data

    如果要找到XML元素指定属性名,使用@attribute_name
    [@attribute_name=\"value\"].
    实例中节点:<employee level="manager">
    XMLQuery = /employee[@level=\"manager\"]


    lr_xml_get_values
    XML:the XML Input String to query
    ValueParam:the name of the output parameter which stores the result of the query,if not exist,it's created.
    Query:the XML Query or Fast Query on the input string XML.
    SelectAll:yes-Multiple Query Matching
    所有的XML函数都是返回找到的匹配数或者是0;

    例一(XML Query):
    #include "as_web.h"
    char *xml_input=
         "<employee>"
              "<name>John Smith</name>"
              "<cubicle>227</cubicle>"
         "</employee>";

    Action() {

         lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter

         lr_xml_get_values("XML={XML_Input_Param}",
              "ValueParam=OutputParam",
              "Query=/employee/name",
              LAST);

         lr_output_message(lr_eval_string("Query result = {OutputParam}"));

         return 0;
    }


    例二(Multiple Query Matching)
    在默认情况下,所有的函数都是返回第一个XML Query匹配的项。Multiple Query Matching可以
    处理每一个连续的匹配项,并且把每个匹配项写入到参数集合中(Parameter Set)
    Param_1, Param_2, Param_3, ...
    #include "as_web.h"
    char * xml_input =
    "<acme_org>"
         " <accounts_dept>"
              "<employee>"
                   " <name>John Smith</name>"
                   "<cubicle>227</cubicle>"
                   "<extension>2145</extension>"
              "</employee>"
         "</accounts_dept>"
         "<engineering_dept>"
              "<employee>"
                   "<name>Sue Jones</name>"
                   "<extension>2375</extension>"
              "</employee>"
         "</engineering_dept>"
    "</acme_org>";

    Action() {
         int i, NumOfValues;
         char buf[64];
         lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter
         NumOfValues= lr_xml_get_values("XML={XML_Input_Param}",
              "ValueParam=OutputParam",
              "Query=/acme_org/*/employee/extension",
              "SelectAll=yes", LAST);
         for ( i = 0; i < NumOfValues; i++) { /* Print multiple values of OutputParam */
              sprintf (buf, "Retrieved value %d : {OutputParam_%d}", i+1, i+1);
              lr_output_message(lr_eval_string(buf));
         }
         return 0;
    }

     

     

    lr_xml_set_values

    设置搜索到的XML元素的值。
    XML:the XML Input String to query
    ResultParam:the output parameter containing the XML data after setting the new value.(包含新值的输出参数)
    Query:the XML Query on the input string XML.
    Value:the string value to set as the XML element
    ValueParam:the parameter name containing the value to set as the XML element.(包含设置为XML元素值的参数名)
    SelectAll:yes-Multiple Query Matching

     

    例三(XML Set):
    #include "as_web.h"
    char * xml_input =
    "<acme_org>"
        " <accounts_dept>"
            "<employee>"
                " <name>John Smith</name>"
                "<cubicle>227</cubicle>"
                "<extension>2145</extension>"
            "</employee>"
        "</accounts_dept>"
        "<engineering_dept>"
            "<employee>"
                "<name>Sue Jones</name>"
                "<extension>2375</extension>"
            "</employee>"
        "</engineering_dept>"
    "</acme_org>";
    Action() {
        int i, NumOfValues;
        char buf[64];
        lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter
        lr_save_string("1111", "ExtensionParam_1");
        lr_save_string("2222", "ExtensionParam_2");
        lr_xml_set_values("XML={XML_Input_Param}",
           "ResultParam=NewXmlParam",
           "ValueParam=ExtensionParam",
           "SelectAll=yes",
           "Query=//extension",
           LAST);
     NumOfValues=lr_xml_get_values("XML={NewXmlParam}",
              "ValueParam=OutputParam",
              "Query=//extension",
              "SelectAll=yes",
              LAST);
     for(i=0;i<NumOfValues;i++) {/* Print the multiple values of MultiParam */

      sprintf(buf,"Retrived value %d:{OutputParam_%d}",i+1,i+1);
      lr_output_message(lr_eval_string(buf));
     
     }

     return 0;
    }

     

    lr_xml_extract
    Extracts XML fragments from an XML string.
    XML:the XML Input String to query.
    XMLFragmentParam:the name of the output parameter containing the extracted XML string fragment.(包含抽取的XML字符片段的输出参数)
    Query: the XML Query or Fast Query on the input string XML.
    SelectAll: If "yes", Multiple Query Matching
    ResolveNameSpaces:If "no", then XMLFragmentParam will contain the extracted string as it appears in the XML input. If "yes", then XMLFragmentParam will include full resolution of any namespace prefixes (e.g., "a:body") in the XML input string. The Default is "no".

    例四(XML Extract):
    #include "as_web.h"
    char * xml_input =
    "<acme_org>"
         " <accounts_dept>"
              "<employee>"
                   " <name>John Smith</name>"
                   "<cubicle>227</cubicle>"
                   "<extension>2145</extension>"
              "</employee>"
         "</accounts_dept>"
         "<engineering_dept>"
              "<employee level=\"manager\">"
                   "<name>Sue Jones</name>"
                   "<extension>2375</extension>"
              "</employee>"
         "</engineering_dept>"
    "</acme_org>";

    Action() {
         int i, NumOfValues;
         char buf[64];
         lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter
         lr_xml_extract("XML={XML_Input_Param}",
                        "XMLFragmentParam=Result",
         "Query=/acme_org/engineering_dept/employee",
         LAST);
         lr_output_message(lr_eval_string("Extracted: {Result}"));

         return 0;
    }

    lr_xml_delete
    The lr_xml_delete function queries the XML input string XML and deletes the fragments of the XML
    tree that match the Query criteria.you can delete elements by specifying the element name or its
    attribute in the XML Query.The output parameter ResultParam contains the modified XML string subsequent
    to deletion.
    XML: the XML Input String to query
    ResultParam: the name of the output parameter containing the XML data after deleting the fragment.
    Query: the XML Query on the input string XML.
    SelectAll: If "yes",Multiple Query Matching

    Note: After deleting the contents of an element, the empty element, e, is signified <e/>. For example, the string result after deleting the element c from the XML string "<a><b><c></c></b></a>" is:
    "<a><b/></a>"
    since the element b is now empty.

    例五(XML Delete):
    #include "as_web.h"
    char * xml_input =
    "<acme_org>"
         "<accounts_dept>"
              "<employee>"
                   " <name>John Smith</name>"
                   "<cubicle>227</cubicle>"
                   "<extension>2145</extension>"
              "</employee>"
         "</accounts_dept>"
    "</acme_org>";
    Action() {

        lr_save_string(xml_input, "XML_Input_Param"); // Save input as parameter
        lr_xml_delete("XML={XML_Input_Param}",
            "ResultParam=Result",
            "Query=/acme_org/accounts_dept/employee/extension",
      LAST);
        lr_output_message(lr_eval_string("String after deletion: {Result}"));
        return 0;

    }


    lr_xml_replace
    Replaces fragments of an XML string.
    XML: the XML Input String to query
    ResultParam: the name of the output parameter containing the XML data after replacing the new value
    Query: the XML Query on the input string XML.
    XmlFragment: the string value to use as replacement of the query match—an element or an attribute.
    XmlFragmentParam: the name of the parameter containing the string value to use as replacement
    SelectAll: If "yes",Multiple Query Matching


    The lr_xml_replace function queries the XML input string XML for values matching the Query criteria
    and replaces them either with XMLFragment or XMLFragmentsParam as the value of the elements matched by
    the query, you can replace elements by specifying either its element name or attribute in the XML Query

    If there is more than one value to be replaced, then pass the "XmlFragmentParam=" specification. Save the values in a series of parameters with the names:
    Param_1, Param_2, Param_3, ...

    例六(XML Replace):
    #include "as_web.h"
    char *xml_input =
    "<acme_org>"
         "<employee>"
              " <name>John Smith</name>"
              "<cubicle>227</cubicle>"
              "<extension>2145</extension>"
         "</employee>"
    "</acme_org>";
    Action() {

         lr_save_string(xml_input, "XML_Input_Param");
      lr_xml_replace("XML={XML_Input_Param}",
         "ResultParam=Result",
         "Query=/acme_org/employee/extension",
         "XmlFragment=<extension>4444</extension>",
         LAST);
      lr_output_message(lr_eval_string("String after replacement:{Result}"));
      return 0;
    }


    lr_xml_insert
    Inserts a new XML fragment into an XML string
    The lr_xml_insert function queries the xml input string XML for values matching the Query criteria.
    It then insets XmlFragment or XmlFragmentParam at the position in the XML string returned by the Query.

    XML: the XML Input String to query
    ResultParam: The output parameter containing the XML data after inserting the new fragment.
    Query: the XML Query on the input string XML.
    XmlFragment: the string to insert. It can be a new element or a attribute of an existing element.
    XmlFragmentParam: the name of the parameter containing the string value to insert
    SelectAll: If "yes",Multiple Query Matching
    Position: the position to insert the XML fragment. Choose one of:
    - before: place the fragment before the tag returned
                   by a Query
    - after: place the fragment after the tag returned
                   by a Query (this is the default value)
    - child: place the fragment as a child of the tag
               returned by a Query
    - attribute: indicates an attribute of an element
                   returned by a Query

    Postion specifies whether the insertion is done before or after the point returned.Additionally, the child Position specifies that the fragment is inserted before the end of the tag found by the query. For example, if the input string is
    <a>53</a>
    an inserted fragment ("<b>ZZ</b>") in the child position will result in the string:
    <a>53<b>ZZ</b></a>

    例七(XML Insert):
    #include "as_web.h"
    char *xml_input =
    "<acme_org>"
         "<employee>"
              " <name>John Smith</name>"
              "<cubicle>227</cubicle>"
         "</employee>"
    "</acme_org>";
    Action() {
     lr_save_string(xml_input, "XML_Input_Param");
     lr_xml_insert("XML={XML_Input_Param}",
                      "ResultParam=Result",
                      "XmlFragment=<extension>2145</extension>",
                      "Query=/acme_org/employee",
          "Position=child",
          LAST);
    lr_output_message(lr_eval_string("String after insertion: {Result}"));

         return 0;
    }

     

     

    lr_xml_find
    Verifies that XML values are returned by a query
    Query: the XML Query or Fast Query on the input string XML.
    XML: the XML Input String to query
    Value: the string to find. This can be the element value or its attribute value.
    ValueParam: the parameter name containing the string to find.
    SelectAll: If "yes",Multiple Query Matching
    IgnoreCase:If "yes", the search will ignore the difference between uppercase and lowercase characters of Value or ValueParam and query results. Default is "no".
    UseRegExp: If "yes", Value and ValueParam can be regular expressions that the function will search for. For more information
    NotFound: Specifies whether the script. fails or continues if the search value is not found. Value is "continue" or "error". If NotFound is not specified, the script. fails.

    The lr_xml_find function queries the XML input string XML for values matching the Query criteria(Value or ValueParam)and returns the number of occurrences.If SelectAll is "no", lr_xml_find returns either 1 or 0.
    例八(XML Find):
    #include "as_web.h"
    char *xml_input =
    "<acme_org>"
        "<employee level=\"manager\">John Smith"
            "<cubicle>227</cubicle>"
        "</employee>"
    "</acme_org>";
    Action() {
    int find_cnt;
        lr_save_string(xml_input, "XML_Input_Param");
        /* Verify that employee John Smith exists */
        find_cnt = lr_xml_find("XML={XML_Input_Param}",
               "Value=John Smith",
               "Query=/acme_org/employee",
               LAST);
        if (find_cnt >0)
    {
            /* Now insert John Smith's telephone extension number */
            lr_xml_insert("XML={XML_Input_Param}", "ResultParam=Result",
            "XmlFragment=<extension>2145</extension>",
            "Query=/acme_org/employee",
            "Position=child", LAST);
            lr_output_message(lr_eval_string("String after insertion: {Result}"));
        } // end if find_cnt > 0
    return 0;
    }


    lr_xml_transform
    The lr_xml_transform. function transforms the XML input string XML using the Extensible Stylesheet Language (XSL) specifications in Stylesheet and saves the resulting formatted data in ResultParam,
    XML: the XML Input String to query
    Stylesheet: the XSL specifications. Has the format of an XSL string.
    ResultParam: the name of the output parameter containing the XML formatted data after XSL transformation

    例九(XML Transfer):
    #include "as_web.h"
    char *xml_input =
    "<?xml version=\"1.0\" ?>"
         "<sales>"
              "<summary>"
                   "<heading>Acme Organization</heading>"
                   "<subhead>IT Management Report</subhead>"
                   "<description>Report by Department</description>"
              "</summary>"
         "</sales>";

    char *stylesheet =
    "<?xml version=\"1.0\"?>"
    "<xsl:stylesheet xmlns:xsl=\"
    http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">"
    "<xsl:output method=\"html\"/>"
    "<xsl:template match=\"/\">"
         "<HTML>"
              "<HEAD>"
                   "<TITLE><xsl:value-of select=\"//summary/heading\"/></TITLE>"
              "</HEAD>"
              "<BODY>"
                   "<h1><xsl:value-of select=\"//summary/heading\"/></h1>"
                   "<h2><xsl:value-of select=\"//summary/subhead\"/></h2>"
                   "<p><xsl:value-of select=\"//summary/description\"/></p>"
              "</BODY>"
         "</HTML>"
    "</xsl:template>"
    "</xsl:stylesheet>";

    Action() {

         lr_save_string(xml_input, "XML_Input_Param"); // Save to a parameter
         lr_save_string(stylesheet, "XML_StyleSheet_Param");// Save to a parameter
         lr_xml_transform("XML={XML_Input_Param}", "ResultParam=Result",
           "Stylesheet={XML_StyleSheet_Param}",
           LAST);
         lr_output_message(lr_eval_string("String after transformation: {Result}"));
         return 0;
    }

     

  • QTP指南中Flight的例子

    2011-02-16 09:39:02

    依照Tutorial的描述操作如下步骤:

    1.         Record Test

    2.         Add CheckPoints

    A.        Checking Objects

    B.        Checking Pages

    C.        Checking Text

    D.        Checking Tables

     

    3.         Parameterizing Test

    A.     Add Parameter Values to a Data Table

    B.     Modifying Steps Affected by Parameterization

     

    4.         Create Output Value

    Creating an Output Value

     

    5.         Using Regular Expression

    Working with Regular Expressions

     

     

    Testing your own application – getting started

    Procedure outlined

    1.         Plan your test

    Decide how to organize your test

    Which operations to record

    Decide how to store the objects in your test

    You can store the objects for each action in its corresponding local object repository, or you Can store the objects for each action in shared object repository, you can also use the same shared object repository for multiple actions. If you are new to testing, you may want to use a local object repository for each action. This is the default setting, and all objects are automatically added to the local repository of each action. If you are familiar with testing, it is probably most efficient to work in the shared object repository mode. In this mode, you can use shared object repository for one or more actions. This means that object information is kept in one central location. When the objects in your application change, you can update then in one location for multiple actions in multiple tests.

     

    2.         Recoded your test

    3.         Enhance your recorded test

    Add checkpoint

    Parameters

    Create output values

    Use regular expressions

    You can further enhance your test with programming and conditional and loop statements, which Add logic to your test!

     

    4.         Debug your test

    Debug your test to check that it operations smoothly and without interruption.

     

    5.         Run your test

    Run your test on your application or web site to check that the application functions as expected.

     

    6.        Analyze the test results

    Examine the result of your test to pinpoint defects in your application

     

    7.         Report defects

    If you have quality center installed, you can submit any defects discovered to a

    quality center database.

     

     

  • 本地对象库与共享对象库理解

    2011-02-14 14:20:46

    Work with Test Object

    Object repository:

    一般来讲,测试对象都是保存在库里面,库又可以分为本地库和共享库,那么该如何选择恰当的库来保存测试对象呢?

     

    在创建一个简单的测试的时候经常使用的库是本地对象库,尤其一下情况:

    1.         针对一个指定的程序,接口或者对象设置的时候,录制一个很少测试的时候;

    2.         不需要频繁修改对象属性是;

    3.         创建单一操作测试时;

    相反在下一情况下建议使用共享对象库:

    1.         使用关键字驱动测试技术创建测试时;

    2.         包含多个测试程序,接口或对象设置的多个测试时;

    3.         需要实施修改测试对象的属性或有规律的更新测试对象属性是;

    4.         经常进行多个测试和有规律的使用“Insert Copy of Action”和“Insert Call to Action”时;

     

    如何理解本地对象库?

    1.         QTP正对动作创建的一个新的对象库;

    2.         QTP获得这些新的对象的时候,会自动保存这些对象的信息到指定的本地对象库中,当共享数据库和这些新的对象存在一定关系时,QTP依然会把新的对象添加到本地对象库中;

    3.         当一个子对象被添加到本地对象库中,而父对象在共享对象库中时,QTP会自动的把共享库中的父对象异动到本地对象库中;

    4.         QTP在每次创建一个新的动作的时候,QTP会创建一个新的,指定的对象库并把这个新的测试对象保存在这个库中;

    5.         QTP在录制测试的时候,在不同的测试步骤中,遇到两个相同的测试对象,QTP会保存两个不同的测试对象到每一个对应的本地对象库中;

    6.         在保存测试的时候,本地对象库会一起被保存到这个测试中,不能单独保存;

     

    如何理解共享对象库呢?

    对于指定的动作,QTP会使用一个或多个共享对象库。在创建测试的时候,你可以指定一个共享对象库,也可以新建一个与之相关的共享对象库。在运行这个测试前必须保证你的测试中使用的共享对象库包含了所有的测试对象,否则运行失败。

    编辑共享对象库可以使用Object Repository Manager工具。共享对象库具有以下的属性:

    1.         QTP在获取一个已经存在共享库或本地库中的对象的时候,它会利用这些信息,而不会将该对象加入到对象库中;

    2.         当子对象被保存在本地对象库时,父对象如果在共享对象库,QTP会自动将父对象转移到本地对象库中;

    3.         QTP在获取测试对象的时候,首先会将对象添加本地对象库中,除非这个对象已经存在共享数据中;

    本地对象库可以被导出到共享对象库中,也可以替换共享对象库;对于相同的动作的对象,QTP可以直接把本地对象库的对象合并到共享数据库中。

     

    Local object Repository > Object Repository > only the specific component can access the stored objects.

    Notes: If you modify an object in the local object repository, your changes do not have any effect on any other component

     

    Shared object repository> Object Repository Manager> can be accessed by multiple components

    Notes: You can update them in one location for all the components that use this shared object repository.

     

     

    Local objects are saved locally with the component, and can be accessed only from that component. When using a shared object repository, you can use the same object repository for multiple components. You can also use multiple object repositories for each component.

     

     

    Deciding Whether to Use Local or Shared Object Repositories

     

     

    Local Object Repositories

    Few components

    Not frequently modify test object properties

     

    1.         QTP create new object repository for each component

    2.         QTP automatically stores the information with objects if the objects not exist in an associated shared object repository.

    3.         QTP add new objects to local object repository even if one or more shared object repositories are already associated with the component. Assumes object not exist the associated shared object.

    4.         If a child object is added to a local object repository, and its parents are in shared object repository, its parents are automatically moved to the local object repository.

    5.         When you save your component, the local object repository is automatically saved with it.

     

     

    Shared Object Repositories

    Creating components using keyword-driven methodologies

    1.         If you record operations on an object that already exists in either the shared or local object repository, QTP uses the existing information and does not add the object to the object repository.

    2.         If a child object is added to a local object repository, and its parents are in a shared object repository, its parents are automatically moved to the local object repository.

     

    Associated with the selected component

    Local objects are editable (black); shared objects are in read-only format (gray)

     

    This dialog box lists the object repository files associated with all the actions in the current test. You can change the associations and perform. other administrative tasks.

     

    Delete object

    You can delete objects from the local object repository using the Object Repository window. You can delete objects from a shared object repository using the Object Repository Manager. For more information

     

    Filter toolbar list, filter function.

     

     

    1.         Copy an object to the local object repository, its parent objects are also copied to the local object repository.

    2.         If an object or its parent objects use unmapped repository parameters, you cannot copy the object to the local object repository, make sure all repository parameters are mapped before copy.

    3.         If an object or its parent objects are parameterized using one or more repository parameters, the repository parameter values are converted when you copy the object to the local object repository.

    4.         If you are copying multiple objects to the local object repository, during the copy process you can choose to skip a specific object if it has unmapped repository parameters, or if it has mapped repository parameters whose values you do not want to convert. You can then continue copying the next object from your original selection.

     

    Object Properties and Property values—description properties, ordinal identifier, and additional details.

     

     

    Edit > Step Properties > Object Properties.

     

    Test object Details  > Restore mandatory property set

     

     

    Renaming Test Objects

     

     

    If you do not want to automatically update test object names for all occurrences of the test object, you can clear the Automatically update test and component steps when you rename test objects check box in the General tab of the Options dialog box (Tools > Options). If you clear this option, you will need to manually change the test object names in all steps in which they are used, otherwise your component run will fail.

     

     

    Define new property

     

    Mapping repository parameter value??

     

    Locating an object in the object repository

     

    Export local objects to a new shared object repository = a file with a .tsr extension

     

     

    Test object classes:

    Standard Windows

    Visual Basic

    Web

     

    Ordinal identifier

    Note: You cannot include the same property in both the mandatory and assistive property lists

     

    Reset Test Object: the system default.

    Reset Environment: the system default.

    Reset ALL

     

     

    Managing Object Repositories

     

     

    Working with Repository Parameters ?

    Managing Repository Parameters

    The Manage Repository Parameters dialog box enables you to add, edit, and delete repository parameters for a single shared object repository.

    Clear default value button.

  • QTP指南中Action调用例子

    2011-02-14 13:04:43

    如下是记录Action的一些知识点:

     

    Call to copy of action

    对于调用复制的Action的时候,此Action可以变更,不会影响和被其余的Action影响。相对独立。

     

     

    Call to existing action

    调用的已存在的Action是只读的,因此只能修改已保存的原Action,这有一个好处:

    1.         可以从不同的Test调用Action

    2.         维护Action变得简单,因为只需要更新最初的已存在的Action

     

    如果原封不动,选择Calls to existing action

    如果稍微改动,选择Copy of another existing action

     

     

    From Test:选择你需要调用action所在的Test

    Action:只显示Test中可复用的Action

     

    Sign_in[ActionPractice] 

    external action

     

    所谓Test Flow就是Test主干部分

     

    关于Action位置的放置问题:

    只读的在前,可修改的在后面

     

     

    调用的Action Item样子如下

    Copy: Copy of FlightOrder

    Existing: Sign_in[ActionPractice]

     

    Parameterizing an action

    参数化Action

    DataTable显示

    DataTableViewsheet显示为相关的Actions

    Global, Sign_in [ActionA], ReturnHome [ActionA], and Copy of FlightOrder

     

    The Global tab is data sheet whose data is used for the entire test. If five rows of data are displayed in the global table, the test will run five times. You can create data sets in each action using the relevant action sheet. So you can define action to run many times within each test iteration.

     

    Note: The call action data sheets are displayed in gray and cannot be edited because each of these data sheets belong to the corresponding called action and can be edited from the called action’s original test only.

     

    Exclusively

    选择参数化的Action只可以用于当前Action

     

     

    By default, QTP only runs one iteration of each action in a test.

     

    Action Call Properties

    Hint: When an action runs in iterations, it must end in the same condition in which it started.

    Otherwise, the test run may fail when beginning a new iteration.

1081/6123456>
Open Toolbar