Exemplo n.º 1
0
 void run () override
 {
     testTrivial ();
     testNearTrivial ();
     testPrimitives ();
     testEmpty ();
     testEscaping ();
     testArray ();
     testLongArray ();
     testEmbeddedArraySimple ();
     testObject ();
     testComplexObject ();
     testJson();
 }
Exemplo n.º 2
0
int ut_ANameValuePair_General()
{
  int iRet = 0x0;

  std::cerr << "ut_ANameValuePair_General" << std::endl;
  
  testSimple(iRet);
  NEWLINE_UNIT_TEST();
  testXml(iRet);
  NEWLINE_UNIT_TEST();
  testJson(iRet);
  NEWLINE_UNIT_TEST();
  testRegValue(iRet);
  NEWLINE_UNIT_TEST();
  testHtml(iRet);
  NEWLINE_UNIT_TEST();
  testFormMultiPart(iRet);

  return iRet;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    printf("main~~ \n");
    test1();
    //for sersocket begin
    struct sockaddr_in server_addr;
    bzero(&server_addr,sizeof(server_addr)); 
    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = htons(INADDR_ANY);
    server_addr.sin_port = htons(HELLO_WORLD_SERVER_PORT);
	 
    printf("main~~~~init server scoket\n");
    //create socket server_socket
    int server_socket = socket(PF_INET,SOCK_STREAM,0);
    if( server_socket < 0){
        printf("Create Socket Failed! \n");
        exit(1);
    }
    {
        int opt =1;
        setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
    }
     
    //bind socket
    if( bind(server_socket,(struct sockaddr*)&server_addr,sizeof(server_addr)))
    {
        printf("Server Bind Port : %d Failed! \n", HELLO_WORLD_SERVER_PORT);
        exit(1);
    }
 
    //listen socket
    if ( listen(server_socket, LENGTH_OF_LISTEN_QUEUE) )
    {
        printf("Server Listen Failed!\n");
        exit(1);
    }
    int sendCount = 0;
    while (1) //
    {
        //
        struct sockaddr_in client_addr;
        socklen_t length = sizeof(client_addr);
        printf("main() tid=%d, pid=%d \n", syscall(SYS_gettid), getpid()); 
        printf("wait for connecting...\n");
        int new_server_socket = accept(server_socket,(struct sockaddr*)&client_addr,&length);
        printf("~~~get a connection! time is:%ld \n",getNowMills());
        if ( new_server_socket < 0)
        {
            printf("Server Accept Failed!\n");
            break;
        }
        char buffer[BUFFER_SIZE];
        bzero(buffer, BUFFER_SIZE);
        //add for by lilei begin
        char byteCharsAll[BUFFER_SIZE];
        bzero(byteCharsAll,BUFFER_SIZE);
        int lenAll = 0;
        short read = 1;
        int countRecv = 1;
	while(read)
 	{
	   printf(">>>> recv() %d begin \n",countRecv);
           length = recv(new_server_socket,buffer,BUFFER_SIZE,0);
           if(length < BUFFER_LIMIT)
             read = 0;
           printf(">>>> recv() length:%d,is need next recv():%d \n",length,read);
           if (length < 0)
           {
             printf("Server Recieve Data Failed!\n");
             break;
           }else
	   {
             //printf(">>>>received data length is: %d size char is:%ld \n", length,sizeof(char));
	          
             //writePngFile(buffer,length);
	     char byteChars[length+1];  //for save chars without NULL
             bzero(byteChars,length+1); //clear every char to zero
             int i = 0,len = 0; 
             char null = NULL;
             for(i; i < length; i++){
                if(buffer[i] != null){
		  byteChars[len] = buffer[i];//only save none null ascii char
		  len++;
		}
                //printf(">>>data is %d>>is not ascii zero:%d\n", buffer[i],(buffer[i] != null));
	     }
             const char END_CHAR = '\0'; 
             if(read == 0 && countRecv ==1){ //parse,only recv() one time
               byteChars[len] = END_CHAR;    
               testJson(byteChars,len);
             }else{  //shoul recv more than one time
               int i,j;
               for(j=lenAll;j<lenAll+len;j++){
	         byteCharsAll[j] = byteChars[j-lenAll];
               }
	       lenAll += len;
               if(read ==0){
		 byteCharsAll[lenAll] = END_CHAR;
                 testJson(byteCharsAll,lenAll);

	       }
             }
           }
           //printf(">>>> recv() %d end \n",countRecv);   
           countRecv++;
        }
        printf(">>>>>all recv() end 222 sendCount:%d \n",sendCount);   
        if(sendCount < 2){
           sendCount++; 
     	   //char jsonStr[] = "adam";
    	   //send(new_server_socket,jsonStr,sizeof(jsonStr),0);       //¿¿¿¿
    	   //printf("<<no close new_server_socket  begin send size:%ld json str:%s >>sendCount:%d\n",sizeof(jsonStr),jsonStr,sendCount); //*/
	   //clientSend(sendCount); //
        }
        //close(new_server_socket);
        
    }
    close(server_socket);
    return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]){
    testHash();
    testJson();
    printf("Nb arg : %d\n\n", argc);
    // Debut du prog

    printf("#####START#####\n\n");

    if (3 > argc){
    printf("ERROR: MISSING ARGUMENTS");
    return 0;
    }

    if (4 < argc) {
        printf("TOO MANY ARGUMENTS");
        return 0;
    }

    char* collection=NULL;
    char* insert=NULL;
    char* set=NULL;
    char* where=NULL;
    char* find=NULL;
    char* projection=NULL;
    char* remove=NULL;

    if( startsWith(argv[1],"-collection")) {
        printf("COLLECTION\n");
    } else {
        printf("COLLECTION NOT FOUND\n");
        return 0;
    }

    if (startsWith(argv[2],"-insert")) {
        printf("\tINSERT\n");
    }

    if (startsWith(argv[2],"-set")) {
        printf("\tSET\n");
        if (argv[3] == NULL) {
            printf("\t\tWITHOUT WHERE CONDITION\n");
        } else {
            if (startsWith(argv[3],"-where")) {
                printf("\t\tWITH WHERE CONDITION\n");
            } else {
                printf("\t\tERROR WHERE");
                return 0;
            }
        }
    }

    if (startsWith(argv[2],"-find")) {
        printf("\tFIND\n");
        if (argv[3] == NULL) {
            printf("\t\tMISSING PROJECTION\n");
            return 0;
        }
        if (startsWith(argv[3],"-projection")) {
            printf("\t\tPROJECTION\n");
        } else {
            printf("\t\tERROR PROJECTION");
            return 0;
        }
    }

    if (startsWith(argv[2],"-remove")) {
        printf("\tREMOVE\n");
    }

    //Fin du prog
    printf("\n#####END#####\n");
    return 0;
}