## tests/pc/test_pc.c

/* [<][>][^][v][top][bottom][index][help] */

## DEFINITIONS

This source file includes following functions.

1. CO_set
2. PR_set
3. CO_to_string
4. PR_to_string
5. TH_to_string
6. SK_close
7. SK_puts
8. CO_get_whois_suspended
9. SK_gets
10. SQ_close_connection
11. CO_const_to_string
12. SQ_free_result
13. CO_get_sleep_time
14. CO_get_password
15. CO_get_database
16. SQ_info_to_string
17. CO_get_database_port
18. CO_get_clear_screen
19. TH_get_id
20. CO_get_authenticate
21. CO_get_prompt
22. WQ_to_string
23. PR_get_property
24. CO_set_const
25. CO_get_query
26. SQ_result_to_string
27. CO_get_welcome
28. CO_get_config_logging
29. CO_get_config_logfile
30. CO_get_user
31. SQ_execute_query
32. CO_get_host
33. SQ_get_connection
34. main

       1 /***************************************
       2   $Revision: 1.2 $
       3
       4   Example code: Unit test driver for protocol_config.c
       5
       6   Status: NOT REVIEWED, NOT TESTED
       7
       8   ******************/ /******************
       9   Modification History:
      10         ottrey (09/03/1999) Created.
      11         ottrey (09/03/1999) Documented.
      12   ******************/ /******************
      13   Copyright (c) 1993, 1994, 1995, 1996, 1997  The TERENA Association
      14   Copyright (c) 1998                              RIPE NCC
      15
      16   All Rights Reserved
      17
      18   Permission to use, copy, modify, and distribute this software and its
      19   documentation for any purpose and without fee is hereby granted,
      20   provided that the above copyright notice appear in all copies and that
      21   both that copyright notice and this permission notice appear in
      22   supporting documentation, and that the name of the author not be
      23   used in advertising or publicity pertaining to distribution of the
      24   software without specific, written prior permission.
      25
      26   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
      27   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
      28   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
      29   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
      30   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      31   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      32   ***************************************/
      33 #define UNIT_TEST
      34 #include "../test_.c" /* unit test template */
      35
      36 #define TEST1 "1 General test"
      37 #define TEST2 "2 General test"
      38 #define TEST3 "3 General test"
      39 #define TEST4 "4 General test"
      40
      41 /* Global Default to get the input from stdin */
      42 FILE *Infile = stdin;
      43 int Authenticate=0;
      44 int Config_logging=0;
      45 int Sleep_time=0;
      46 int Clear_screen=0;
      47 char *Password="DBgOHZFNyoSog";
      48 char *Logfile="stdout";
      49
      50 char *CO_set() {
         /* [<][>][^][v][top][bottom][index][help] */
      51   return "call to CO_set()\n";
      52 } /* CO_set() */
      53
      54 char *PR_set() {
         /* [<][>][^][v][top][bottom][index][help] */
      55   return "call to PR_set()\n";
      56 } /* PR_set() */
      57
      58 char *CO_to_string() {
         /* [<][>][^][v][top][bottom][index][help] */
      59   return "CO_to_string() -- all the constants.";
      60 } /* CO_to_string() */
      61
      62 char *PR_to_string() {
         /* [<][>][^][v][top][bottom][index][help] */
      63   return "PR_to_string() -- all the properties.";
      64 } /* PR_to_string() */
      65
      66 char *TH_to_string() {
         /* [<][>][^][v][top][bottom][index][help] */
      67   return "TH_to_string() -- thread info.";
      68 } /* TH_to_string() */
      69
      70 SK_close() {
         /* [<][>][^][v][top][bottom][index][help] */
      71   printf("call to SK_close()\n");
      72 } /* SK_close() */
      73
      74 SK_puts(int sock, char *str) {
         /* [<][>][^][v][top][bottom][index][help] */
      75   if (str != NULL) {
      76     printf(str);
      77   }
      78 } /* SK_puts() */
      79
      80 int CO_get_whois_suspended() {
         /* [<][>][^][v][top][bottom][index][help] */
      81   return 0;
      82 } /* CO_get_whois_suspended() */
      83
      84 int SK_gets(int sock, char *input, int size) {
         /* [<][>][^][v][top][bottom][index][help] */
      85   int input_len;
      86
      87   fgets(input, size, Infile);
      88   input_len = strlen(input);
      89   if (input[input_len-1] == '\n') {
      90     input[input_len-1] = '\0';
      91   }
      92
      93   if (Verbose == 1) {
      94     printf("input=%s\n", input);
      95   }
      96
      97   return 1;
      98 } /* SK_gets() */
      99
     100 SQ_close_connection() {
         /* [<][>][^][v][top][bottom][index][help] */
     101   printf("call to SQ_close_connection()\n");
     102 } /* SQ_close_connection() */
     103
     104 char *CO_const_to_string(char *name) {
         /* [<][>][^][v][top][bottom][index][help] */
     105   return "value";
     106 } /* CO_const_to_string() */
     107
     108 SQ_free_result() {
         /* [<][>][^][v][top][bottom][index][help] */
     109   printf("call to SQ_free_result()\n");
     110 } /* SQ_free_result() */
     111
     112 int CO_get_sleep_time() {
         /* [<][>][^][v][top][bottom][index][help] */
     113   return Sleep_time;
     114 } /* CO_get_sleep_time() */
     115
     116 char *CO_get_password() {
         /* [<][>][^][v][top][bottom][index][help] */
     117   printf("call to CO_get_password()\n");
     118 } /* CO_get_password() */
     119
     120 CO_get_database() {
         /* [<][>][^][v][top][bottom][index][help] */
     121   printf("call to CO_get_database()\n");
     122 } /* CO_get_database() */
     123
     124 char *SQ_info_to_string() {
         /* [<][>][^][v][top][bottom][index][help] */
     125   return "SQ_info_to_string() -- sql info";
     126 } /* SQ_info_to_string() */
     127
     128 CO_get_database_port() {
         /* [<][>][^][v][top][bottom][index][help] */
     129   printf("call to CO_get_database_port()\n");
     130 } /* CO_get_database_port() */
     131
     132 int CO_get_clear_screen() {
         /* [<][>][^][v][top][bottom][index][help] */
     133   return Clear_screen;
     134 } /* CO_get_clear_screen() */
     135
     136 TH_get_id() {
         /* [<][>][^][v][top][bottom][index][help] */
     137   printf("call to TH_get_id()\n");
     138 } /* TH_get_id() */
     139
     140 int CO_get_authenticate() {
         /* [<][>][^][v][top][bottom][index][help] */
     141   printf("CO_get_authenticate()=%d\n", Authenticate);
     142   return Authenticate;
     143 } /* CO_get_authenticate() */
     144
     145 char *CO_get_prompt() {
         /* [<][>][^][v][top][bottom][index][help] */
     146   return "CO_get_prompt() -- prompt> ";
     147 } /* CO_get_prompt() */
     148
     149 char *WQ_to_string() {
         /* [<][>][^][v][top][bottom][index][help] */
     150   return "WQ_to_string() -- whois query info";
     151 } /* WQ_to_string() */
     152
     153 char *PR_get_property(char *name) {
         /* [<][>][^][v][top][bottom][index][help] */
     154   return Password;
     155 } /* PR_get_property() */
     156
     157 CO_set_const() {
         /* [<][>][^][v][top][bottom][index][help] */
     158   printf("call to CO_set_const()\n");
     159 } /* CO_set_const() */
     160
     161 CO_get_query() {
         /* [<][>][^][v][top][bottom][index][help] */
     162   printf("call to CO_get_query()\n");
     163 } /* CO_get_query() */
     164
     165 char *SQ_result_to_string() {
         /* [<][>][^][v][top][bottom][index][help] */
     166   return "SQ_result_to_string() - sql result";
     167 } /* SQ_result_to_string() */
     168
     169 char *CO_get_welcome() {
         /* [<][>][^][v][top][bottom][index][help] */
     170   return "CO_get_welcome() -- Hi!\n";
     171 } /* CO_get_welcome() */
     172
     173 int CO_get_config_logging() {
         /* [<][>][^][v][top][bottom][index][help] */
     174   return Config_logging;
     175 } /* CO_get_config_logging() */
     176
     177 char *CO_get_config_logfile() {
         /* [<][>][^][v][top][bottom][index][help] */
     178   return Logfile;
     179 } /* CO_get_config_logfile() */
     180
     181 CO_get_user() {
         /* [<][>][^][v][top][bottom][index][help] */
     182   printf("call to CO_get_user()\n");
     183 } /* CO_get_user() */
     184
     185 SQ_execute_query() {
         /* [<][>][^][v][top][bottom][index][help] */
     186   printf("call to SQ_execute_query()\n");
     187 } /* SQ_execute_query() */
     188
     189 CO_get_host() {
         /* [<][>][^][v][top][bottom][index][help] */
     190   printf("call to CO_get_host()\n");
     191 } /* CO_get_host() */
     192
     193 SQ_get_connection() {
         /* [<][>][^][v][top][bottom][index][help] */
     194   printf("call to SQ_get_connection()\n");
     195 } /* SQ_get_connection() */
     196
     197
     198 int main(int argc, char** argv) {
         /* [<][>][^][v][top][bottom][index][help] */
     199   int i;
     200
     201   char input[STR_L];
     202
     203   char  *str;
     204
     205   /* Get the options from the command line */
     206   get_options(argc, argv);
     207
     208   /* TEST1 */
     209   if(Test[1] == 1) {
     210     print_title(TEST1);
     211
     212     /* Open Infile */
     213     if (Infile_name != NULL) {
     214       Infile = fopen(Infile_name, "r");
     215
     216       if (Infile == NULL) {
     217         perror("Couldn't load Infile");
     218         return -1;
     219       }
     220     }
     221
     222     PC_interact(1);
     223
     224     close(Infile);
     225   } /* TEST1 */
     226
     227   Authenticate=1;
     228   Config_logging=0;
     229   Sleep_time=0;
     230   Clear_screen=0;
     231
     232   /* TEST2 */
     233   if(Test[2] == 1) {
     234     print_title(TEST2);
     235
     236     /* Open Infile */
     237     if (Infile_name != NULL) {
     238       Infile = fopen(Infile_name, "r");
     239
     240       if (Infile == NULL) {
     241         perror("Couldn't load Infile");
     242         return -1;
     243       }
     244     }
     245
     246     PC_interact(1);
     247
     248     close(Infile);
     249   } /* TEST2 */
     250
     251   Authenticate=0;
     252   Config_logging=1;
     253   Sleep_time=0;
     254   Clear_screen=0;
     255
     256   /* TEST3 */
     257   if(Test[3] == 1) {
     258     print_title(TEST3);
     259
     260     /* Open Infile */
     261     if (Infile_name != NULL) {
     262       Infile = fopen(Infile_name, "r");
     263
     264       if (Infile == NULL) {
     265         perror("Couldn't load Infile");
     266         return -1;
     267       }
     268     }
     269
     270     PC_interact(1);
     271
     272     close(Infile);
     273   } /* TEST3 */
     274
     275   Authenticate=1;
     276   Config_logging=1;
     277   Sleep_time=0;
     278   Clear_screen=0;
     279
     280   /* TEST4 */
     281   if(Test[4] == 1) {
     282     print_title(TEST4);
     283
     284     /* Open Infile */
     285     if (Infile_name != NULL) {
     286       Infile = fopen(Infile_name, "r");
     287
     288       if (Infile == NULL) {
     289         perror("Couldn't load Infile");
     290         return -1;
     291       }
     292     }
     293
     294     PC_interact(1);
     295
     296     close(Infile);
     297   } /* TEST4 */
     298
     299   return(0);
     300
     301 } /* main() */
     302

/* [<][>][^][v][top][bottom][index][help] */