Unnamed Fossil Project

Check-in [d07351188b]
Login

Check-in [d07351188b]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:updated
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d07351188b1b4f9f133d90962da43a9d37e87e49
User & Date: monster 2012-07-24 17:27:34.765
Context
2012-07-24
22:17
sha/rsa for xdata check-in: 718eda106a user: monster tags: trunk
17:27
updated check-in: d07351188b user: monster tags: trunk
17:26
updated check-in: ace7839bf1 user: monster tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Added tests/cgi.c.














































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#define _LIBYOYO

#include "../yoyo.hc"
#include "../cgi.hc"
#include "../httpd.hc"
#include "../httpx.hc"
#include "../webhost.hc"
#include "../prog.hc"
#include "../tesuite.hc"

void test_client_simple(YO_CGI *cgi)
  {
    Tesuite_Case("CGI: test simple");
    Cgi_Append(cgi,"SIMPLE",-1);
    Cgi_Write_Out(cgi,YO_CGI_OUT_TEXTHTML);
    Tesuite_Case_Successed();
  }

void test_client()
  {
    __Auto_Release
      {
        char *test;
        YO_CGI *cgi = Cgi_Init();
        Cgi_Query_Params(cgi,0,0);
        
        test = Xnode_Value_Get_Str(cgi->params,"test",0);
        if ( !test )
          ;
        else if ( !strcmp_I(test,"simple") )
          test_client_simple(cgi); 
      }
  }

void test_server_0()
  {
    Tesuite_Case("client/server: simple GET request");
    __Auto_Release
      {
        int http_status;
        YO_BUFFER *bf = Buffer_Init(0);
        YO_WEBHOST *webhost = Webhost_Init();
        YO_HTTPD *httpd = Httpd_Server(Webhost_Callback,webhost);
        Webhost_Set_Exec_Root(webhost,Prog_Directory());
        Httpd_Listen(httpd,"0.0.0.0",9000);        
        http_status = Httpx_Get(0,"http://localhost:9000/cgi?test=simple",0,Buffer_As_File(bf),0);
        Httpd_Shutdown(httpd);
        while ( Tasque_Perform_Update(0,0) ) ;
        if ( http_status != 200 || !bf->count || !!strcmp(bf->at,"SIMPLE") )
          __Raise_Format(YO_ERROR_TESUITE_FAIL,("response: %d, %s",http_status,bf->at?bf->at:"<null>"));
      }
    Tesuite_Case_Successed();
  }

int main(int argc, char **argv)
  {
    Prog_Init(argc,argv,0,0);
    
    __Try_Abort 
      {
        Tesuite_Init();
   
        if ( getenv("GATEWAY_INTERFACE") ) 
          {
            Tesuite_Perform(test_client());
          }
        else      
          Tesuite_Perform(test_server_0());
      }
  }
Added tests/httpx.c.




























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#define _LIBYOYO

#include "../yoyo.hc"
#include "../prog.hc"
#include "../file.hc"
#include "../httpx.hc"

int main(int argc, char **argv)
  {
    int i;
    Prog_Init(argc,argv,"?|h,a",PROG_EXIT_ON_ERROR);

    __Try_Exit(0)
      {
        int flags = Prog_Has_Opt("a")?HTTPX_ASYNC:0; 
        
        for ( i = 0; i < Prog_Arguments_Count(); ++i ) __Auto_Release
          {
            YO_URL *url = Url_Parse(Prog_Argument(i));
            Httpx_Get(Httpx_Client(url->endpoint,flags),url->uri,0,Cfile_Open(Path_Basename(url->query),"w+"),-1);
          }
        
        if ( flags&HTTPX_ASYNC )
          while ( Tasque_Perform_Update(10,0) )
            {;}
      }
            
    return 0;
  }
Added tests/xddb.c.














































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

#define _LIBYOYO

#include "../xddbfs.hc"
#include "../prog.hc"
#include "../tesuite.hc"

YO_XDDB *Open_Xddb(int create_new)
  {
    char *db_source = Prog_Arguments_Count()?Prog_Argument(0):"xddb"; 
    YO_XDDB *xddb;
    
    if ( 0 ) ;
    else
      {
        xddb = Xddbfs_Open(db_source,create_new,XDDB_FORMAT_TEXT,0);
      }
      
    return xddb;
  }

void test_0()
  {
    __Auto_Release
      {
        YO_XDDB *xddb;
        YO_XDATA *doc;
        char *key;
        char *unique;
        
        Tesuite_Case("create/read/delete document");
        
        xddb = Open_Xddb(XDDB_CREATE_ALWAYS);
        Tesuite_Info(__Format("xddb test, source: %s, format: %s",
                                    Xddb_Source_String(xddb),
                                    Xddb_Format_String(xddb)));
                                    
        unique = Xddb_Build_Unique_Key();
        doc = Xdata_Init();
        Xnode_Value_Set_Str(&doc->root,"unique",unique);
        key = Xddb_Unique(xddb,doc);
        doc = Xddb_Get(xddb,key,XDDB_RAISE_IF_DSNT_EXSIS);
        if ( strcmp(Xnode_Value_Get_Str(&doc->root,"unique",""),unique) )
          __Raise(YO_ERROR_TESUITE_FAIL,"document is not consistent");
        Xddb_Delete(xddb,key);
        if ( Xddb_Has(xddb,key) )
          __Raise(YO_ERROR_TESUITE_FAIL,"document still present in store");
        
        Tesuite_Case_Successed();
      }
  }

void test_1()
  {
    __Auto_Release
      {
        YO_XDDB *xddb;
        YO_XDATA *doc;
        char *key;
        char *unique;

        unique = Xddb_Build_Unique_Key();
        
        __Auto_Ptr(key)
          {
            Tesuite_Case("create db/create document");            
            xddb = Open_Xddb(XDDB_CREATE_ALWAYS);
            Tesuite_Info(__Format("xddb test, source: %s, format: %s",
                                        Xddb_Source_String(xddb),
                                        Xddb_Format_String(xddb)));
                                        
            doc = Xdata_Init();
            Xnode_Value_Set_Str(&doc->root,"unique",unique);
            key = Xddb_Unique(xddb,doc);
            Tesuite_Info(__Format("document key: %s",key));
            Tesuite_Case_Successed();
          }
          
        __Auto_Release
          {
            Tesuite_Case("open db/get document");
            xddb = Open_Xddb(XDDB_OPEN_EXISTING);
            Tesuite_Info(__Format("xddb test, source: %s, format: %s",
                                        Xddb_Source_String(xddb),
                                        Xddb_Format_String(xddb)));
            Tesuite_Info(__Format("document key: %s",key));
            doc = Xddb_Get(xddb,key,XDDB_RAISE_IF_DSNT_EXSIS);
            if ( strcmp(Xnode_Value_Get_Str(&doc->root,"unique",""),unique) )
              __Raise(YO_ERROR_TESUITE_FAIL,"document is not consistent");
            Tesuite_Case_Successed();
          }

        __Auto_Release
          {
            Tesuite_Case("open db/delete document");
            xddb = Open_Xddb(XDDB_OPEN_EXISTING);
            Tesuite_Info(__Format("xddb test, source: %s, format: %s",
                                        Xddb_Source_String(xddb),
                                        Xddb_Format_String(xddb)));
            Tesuite_Info(__Format("document key: %s",key));
            Xddb_Delete(xddb,key);
            if ( Xddb_Has(xddb,key) )
              __Raise(YO_ERROR_TESUITE_FAIL,"document still present in store");
            Tesuite_Case_Successed();
          }
      }
  }

int main(int argc, char **argv)
  {
    Prog_Init(argc,argv,"fs,ldb,sql3,msql",0);
    
    __Try_Abort
      {
        Tesuite_Init();
        Tesuite_Perform(test_0());
        Tesuite_Perform(test_1());
      }
  }