self-initiated test program of a self-defined keyboard simulation test program (c Language)

Source: Internet
Author: User

I. Test PROCEDURE Preparation Instructions
What we do is run the QT application on the end Device. Use the keyboard interface you have Defined. After a long time human-computer interaction test, to determine whether the system function to meet the NEEDS.

Now it is necessary to write a self-motivated test program that can run according to a preset script, for example, a button that needs to run 10,000 times in a row. or run a specific business process 10W times with a few keystrokes in Succession. Through this self-motivated test, can reduce the burden of the test personnel, but also to see the triggering of the n-times after the screen run N times the stability of the system, such as memory usage, Cup usage, and so On.

The device has a 4*4 keyboard, which contains 0-9,c (call). A. U (up) and D (down). F1,f2 function Keys. The corresponding response action is run on different screens of the screen according to the action of the aforementioned Key.

Structural Analysis of test procedure

Based on the above simple Requirements. First analyze the structure of the test program such as the Following:

The read-in script file can be a txt file, such as the following structure:

   --------Script_Sample.txt------------
3A53256A3

The first line in this section represents the 5 actions that are run BELOW. Each is a, U, C, a key and after each key to rest the number of seconds (that is, the value of the following), in which the R 5 1 lines indicate that 1 lines are repeated 5 times. R does not write in the script File. If not written, the order is run Sequentially. There is no loop operation.

The test program constructs a linked list based on this script. The nodes in the list represent the corresponding operations, and the list of one-way loops that form part of the cyclic action in the sequence of actions.

third, the test program to achieve the main logic
1. Define the chain list

typedefstruct List  {      char operation;    int  seconds;    FLAG c_flag;    int  i_repeatCnt;    int  i_repeatLines;    struct//指针域      struct//指针域  }List;  List *oprtData_Set;

2. Escalate input Events

intReportkey (intfd, uint16_t type, uint16_t keycode, int32_tvalue)  {structInput_eventEvent;Event. Type = type;Event. Code = keycode;Event.value=value; Gettimeofday (&Event. time,0);if(write (fd, &Event,sizeof(structInput_event)) <0) {printf ("report Key error!\n");return-1; }return 0; }

3, using the tail interpolation method according to the action of the script to construct the key action chain list

voidTailcreatlist (List *l,Char* Fname)//tail interpolation to create a linked list{List *tmpdata;    List *tail; List *groupheader;intI_repeatnums =0;intI_repeatlines =0, i_repeatlines_tmp =0;Charc_repeatid; Flag flag = HEADER;//flag = 1 Header    Charbuffer[ +];Charc_repeatflag;    FILE *infile; Infile=fopen (fname,"r"); tail=l;//nullgroupheader=tail->nextgp;//null    if(infile==null) {printf("\nfailed to open the file:%s \ n", fname);Exit(0); }Else{printf("open success! \ n "); } fgets (buffer,sizeof(buffer), infile);sscanf(buffer,"%d", &i_stepmaxnum);printf("i_stepmaxnum =%d \ n", i_stepmaxnum);memset(buffer,0,sizeof(buffer)); while(fgets (buffer,sizeof(buffer), Infile)) {tmpdata= (structList*)malloc(sizeof(structList));if(!tmpdata) {printf("malloc () [email protected] \ n");Exit(0); }memset(tmpdata,0,sizeof(structList));            tmpdata->nextmemeber=null; tmpdata->nextgp=null;sscanf(buffer,"%c", &c_repeatflag);if(c_repeatflag = =' R ')            {sscanf(buffer,"%c%d%d", &c_repeatid,&i_repeatnums,&i_repeatlines);printf("Repeat =%c, repeatnums =%d,repeatlines =%d \ n", c_repeatid,i_repeatnums,i_repeatlines);memset(buffer,0,sizeof(buffer));Continue; }Else{sscanf(buffer,"%c%d",& (tmpdata->operation),& (tmpdata->seconds));printf("operation =%c, seconds =%d\n", tmpdata->operation,tmpdata->seconds);if(i_repeatlines >0)                {if(flag==header)                        {groupheader=tmpdata;                        tmpdata->c_flag=flag;                        tmpdata->i_repeatcnt = i_repeatnums;                        Flag = MEMBER;                        tmpdata->nextmemeber=groupheader;                        tmpdata->nextgp=null; tail->nextgp=tmpdata;//pay attention to connecting congestion? each group head is connected with a NEXTGP pointer}Else{tmpdata->c_flag=flag;                        tmpdata->nextmemeber=groupheader;                        tmpdata->nextgp=null; tail->nextmemeber=tmpdata;members of The//group are connected with the Nextmemeber pointer} tail=tmpdata;//change the position of the tail pointer. i_repeatlines--; }Else{//--ok!!flag=header;                    GroupHeader = tmpdata;                    Tmpdata->c_flag = flag;                    tmpdata->nextmemeber=groupheader;                    tmpdata->nextgp=null;                    tail->nextgp=tmpdata;                tail=tmpdata; }if(i_repeatlines==0) {flag=header; }            }memset(buffer,0,sizeof(buffer)); } tail->nextgp=null;//tail->nextmemeber=null;Fclose (infile);return;}

4, the construction of keyboard events, including pressing and lifting

int seconds){    uint16_t keycode;    printf("Key-%c ,%3d Sec |",operation,seconds);    keycode = KeyToVal(operation);    reportkey(KB_Fd, EV_KEY, keycode, KEYDOWN);    reportkey(KB_Fd, EV_KEY, keycode, KEYUP);      sleep(seconds);}

5, according to the data in the linked list to send key events

void emitevent_test(List*L)  {List*p=L->nextgp; int loop=0;Cycle_modeMode_flag =firstcycle; printf"-------emitevent_test-------\ n"); While (p!=NULL) {//printf ("[* *%d **,%c,%d,%d]", p->c_flag, p->operation,p->seconds,p->i_repeatcnt);presskeyevent(p->operation,p->seconds);if(p->nextmemeber->c_flag! =HEADER)//{p = p->nextmemeber; }Else{/* printf ("p->nextmemeber Node is [* *%d **,%c,%d,%d]", p->nextmemeber->c_flag, p->nextmemeber->operation,                 p->nextmemeber->seconds, p->nextmemeber->i_repeatcnt); */if(mode_flag = =firstcycle&& p->nextmemeber->i_repeatcnt >0) {loop = p->nextmemeber->i_repeatcnt; Mode_flag =othercycle;                        p = p->nextmemeber; Loop--;printf"\ n----------------\ n");                    Continue }if(loop >0&& Mode_flag = =othercycle)//not finished repeatedly {p = p->nextmemeber; Loop--;printf"\ n----------------\ n");                    Continue } Mode_flag =firstcycle;//restore Default Value p = p->nextgp; printf"\ n"); }    }  }

Iv. References Source Code program

http://download.csdn.net/detail/flyeagle022/8799555

self-initiated test program of a self-defined keyboard simulation test program (c Language)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.