/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/
 
Interface sample; 
 
	Invoke boolop 6 
		Boolean(1),Boolean(1), 
		Boolean(2),Boolean(2), 
		Boolean(4), Boolean(4), 
		Boolean(8),Boolean(8),  
		Boolean(300),Boolean(300),Boolean(300),Boolean(300); 
 
End; 
 
#define LITTLE_ENDIAN ((*( (int *) ENDIAN_STRUCT.chars )) == 1)

static struct
{
   char chars[8];
} ENDIAN_STRUCT = { "\1\0\0\0\0\0\0" };

main( argc, argv ) 
   int argc; 
   char *argv[]; 
{ 
   Boolean(1) B1_BitHigh, B1_BitLow, B1_HighR, B1_LowR; 
   Boolean(2) B2_BitHigh, B2_BitLow, B2_HighR, B2_LowR; 
   Boolean(4) B4_BitHigh, B4_BitLow, B4_HighR, B4_LowR; 
   Boolean(8) B8_BitHigh, B8_BitLow, B8_HighR, B8_LowR; 
   Boolean(300) B300_BitHigh,B300_BitLow,B300_BitMiddle,B300_BitFalse, 
		B300_HighR,B300_MidR,B300_LowR,B300_FalseR; 
 
   Control (sample) inst; 
  
   int i, index; 
 
   if( argc != 2 ) 
   { 
     printf("Need to supply data file name.\n"); 
     exit(1); 
   } 
   
   B1_BitLow = 0x80; 
   B1_BitHigh = 0x01; 
 
   B2_BitLow = 0x0100;    
   B2_BitHigh = 0x0001;    
 
   B4_BitLow = 0x00000000;    
   B4_BitHigh = 0x01000000;    
 
#ifdef CRAY 
   B8_BitLow = 0x0100000000000000; 
   B8_BitHigh = 0x0000000000000001; 
#else 
   memset( B8_BitLow.val, 0, 8 ); 
   memset( B8_BitHigh.val, 0, 8 ); 
   B8_BitLow.val[0] = 0x01; 
   B8_BitHigh.val[7] = 0x01; 
#endif 
 
   memset( B300_BitLow.val, 0, 300 ); 
   memset( B300_BitMiddle.val, 0, 300 ); 
   memset( B300_BitHigh.val, 0, 300 ); 
   memset( B300_BitFalse.val, 0, 300 ); 
   B300_BitLow.val[0] = 0x01;    
   B300_BitMiddle.val[150] = 0x01;    
   B300_BitHigh.val[299] = 0x01;    
 
/***************** send it out ************************/

   Bind_STUB( inst, argv[1], "w", Asn_1_ber); 
   Give inst 
   { 
      boolop(B1_BitLow, B1_BitHigh, B2_BitLow, B2_BitHigh, B4_BitLow,  
	     B4_BitHigh, B8_BitLow, B8_BitHigh, 
	     B300_BitLow, B300_BitMiddle, B300_BitHigh, B300_BitFalse); 
   } 
   Unbind(inst); 
 
/***************** receive it back ********************/

   Bind_STUB( inst, argv[1], "r", Asn_1_ber); 
 
   Accept inst 
    { 
       On boolop(B1_LowR, B1_HighR, B2_LowR, B2_HighR, B4_LowR,  
		 B4_HighR, B8_LowR, B8_HighR, B300_LowR, B300_MidR,  
		 B300_HighR, B300_FalseR ) 
	{ 
/***************** report results *********************/

	   if( B1_LowR != 0x01 ) 
		printf("### Compare B1_BitLow failed.\n"); 
 
	   if( B1_HighR != 0x01 ) 
		printf("### Compare B1_BitHigh failed.\n"); 
 
	   if(  B2_LowR != 0x01 ) 
		printf("### Compare B2_BitLow failed.\n"); 
 
	   if(  B2_HighR != 0x01 ) 
		printf("### Compare B2_BitHigh failed.\n"); 
 
	   if(  B4_LowR != 0x00 ) 
		printf("### Compare B4_BitLow failed.\n"); 
 
	   if(  B4_HighR != 0x01 ) 
		printf("### Compare B4_BitHigh failed.\n"); 
 
#ifdef CRAY 
           if(  B8_LowR != 0x01 ) 
#else 
	   index = LITTLE_ENDIAN ? 0 : 7;
           if(  B8_LowR.val[index] != 0x01) 
#endif 
                printf("### Compare B8_BitLow failed.\n"); 
 
#ifdef CRAY 
           if(  B8_HighR != 0x01 ) 
#else 
           if(  B8_HighR.val[index] != 0x01 ) 
#endif 
		printf("### Compare B8_BitHigh failed.\n"); 
 
	   index = LITTLE_ENDIAN ? 0 : 299;

	   if(  B300_LowR.val[index] != 0x01 ) 
		printf("### Compare B300_BitLow failed.\n"); 
 
	   if(  B300_MidR.val[index]  != 0x01 ) 
		printf("### Compare B300_BitMid failed.\n"); 
 
	   if(  B300_HighR.val[index]  != 0x01 ) 
		printf("### Compare B300_BitHigh failed.\n"); 
 
           for (i = 0; i < 300; i++) 
		if (B300_FalseR.val[i] != 0) { 
		  printf("### Compare B300_BitFalse[%d] failed.\n",i); 
		  break; 
		} 
 	} 
    } 
    Unbind( inst ); 
 
    printf("test completed\n");
    return(0); 
} 
  
 
 
