/*		CLIENT program for test package FRED		    FRED_PROG_C

  Stub Version Number: 9524  */

#include <rpcrts.h>

typedef    rpc_byte byte_type;
typedef    rpc_char char_type;
typedef    rpc_short short_type;
typedef    rpc_long long_type;
typedef    rpc_integer int_type;
typedef    rpc_real32 real_type;
typedef    rpc_char str_type[21];
typedef    rpc_char array_type[11][8];
typedef    rpc_long seq_type[81];
typedef    rpc_char arr_str[10][21];
typedef    rpc_char s_of_string[11][21];
typedef    rpc_char seq_of_str_2[10][21];
typedef    struct {
      rpc_integer field1;
      rpc_real32 field2;
      rpc_char field3[21];
   } rpc_stype_0;
typedef    struct {
      rpc_integer my_int;
      rpc_char my_a_s[10][21];
      struct {
         rpc_integer field1;
         rpc_real32 field2;
         rpc_char field3[21];
      } my_rec2;
   } my_rec;

extern fred_in();
extern fred_out();
extern fred_in_out();

main()
{
    my_rec x, y;
    rpc_char temp[21];
    int err;		/* Error number so far */
    int i;		/* Loop counter */

    err = 0;		/* Initialise error count */

/*  Set up initial dataset:
*/
    x.my_int = 31;
    for (i=0; i<10; i++) {
	strcpy(x.my_a_s[i], "This is string X");
	x.my_a_s[i][15]=('A'+i);
    }
    x.my_rec2.field1 = 12345;
    x.my_rec2.field2 = 3.14159;
    strcpy(x.my_rec2.field3,"Inside nested record");

/*  Pass the data there and back:
 */
    fred_in(&x);
    fred_out(&y);

/*  Check the results returned:
 */
    if (y.my_int !=31)
	printf("Error in my_int : %lx -> %lx\n", 31, y.my_int);
    for (i=0; i<10; i++) {
	strcpy(temp, "This is string X");
	temp[15]=('A'+i);
	if (strcmp(y.my_a_s[i], temp))
	    printf("%d) Bad string %d is '%s'\nShould be '%s'\n",
		     ++err, i, y.my_a_s[i], temp);
    }
    if (y.my_rec2.field1!=12345)
	printf("%d) Bad field1 is %lx \n", ++err, y.my_rec2.field1);
    if (y.my_rec2.field2!=x.my_rec2.field2)
	printf("%d) Bad field2 is %f\nShould be %f\n",
		 ++err, y.my_rec2.field2, x.my_rec2.field2);
    if (strcmp(y.my_rec2.field3,"Inside nested record"))
	printf("%d) Bad field3 is '%s'\n", ++err, y.my_rec2.field3);

    if (err) {
	printf("\nTest failed, total of %d errors\n", err);
	exit(2);
    }
    printf("Test of data passed IN then OUT passed.\n");

/*  Get the data modified:
 */
     fred_in_out(&x);

/*  Check the results returned:
 */
    if (x.my_int !=31+3)	    /* changed */
	printf("%d) Error in my_int : %lx -> %lx\n", ++err, 31, x.my_int);
    for (i=0; i<10; i++) {
	strcpy(temp, "This is string X");
	temp[15]=('A'+i);
	if (strcmp(x.my_a_s[i], temp))
	    printf("%d) Bad string %d is '%s'\nShould be '%s'\n",
		     ++err, i, y.my_a_s[i], temp);
    }
    if (x.my_rec2.field1!=12345+5) /* changed */
	printf("%d) Bad field1 is %lx\n", ++err, x.my_rec2.field1);
    if (y.my_rec2.field2!=x.my_rec2.field2)
	printf("%d) Bad field2 is %f\nShould be %f\n",
		 ++err, x.my_rec2.field2, y.my_rec2.field2);
    if (strcmp(x.my_rec2.field3,"Inside nested record"))
	printf("%d) Bad field3 is '%s'\n", ++err, x.my_rec2.field3);

    printf("Test of data passed IN OUT finished.\n");

    if (err)
	printf("\nTest failed, total of %d errors\n", err);
    else
	printf("Tests completed, parameters passed OK\n");

} /* end of main */
