/*****************************************************************/
/**                                                             **/
/**             (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; 
 
Array Integer(4) intarray[5]; 

Record <Noautotag Sequence> 
{ 
   Integer(2) i; 
   Integer(2) j; 
   Integer(2) k; 
} intrec; 

Array <Set> Integer(2) logarray[5]; 

Union  
{  
   GeneralString(16) cs;  
   PrintableString(16) rs;  
} thisun;  

Record  
{  
   Boolean(1) b;  
   Integer(4) i;  
   BitString(17) bs;  
   OctetString(10) os;
   Null nl;
   ObjectIdentifier(5,2) oid;  
   IA5String(30) s; 
   intarray a_si;
   intrec r_nn;
   logarray a_lv;
   Record <Noautotag Set>  
   {  
      Real(20,5) <Application 300 Implicit> f;  
      Real(48,10) <Application 301 Implicit> d;  
   } r_flt;  
   thisun <Application 10> u1;  
   thisun <Application 11> u2; 
} Amalgamated;  
 
Names Amalgamated Red 257;  
Names Amalgamated White 258;  
Names Amalgamated Blue 259; 
 
   Invoke iop 5 
	Red,White,Blue; 
 
End; 

  
main(argc,argv) 
   int argc; 
   char *argv[]; 
{ 
   Amalgamated quartz; 
   Amalgamated x,y; 
   Control (sample) inst; 
  
   int i,l,l2; 
 
   if (argc != 2) 
      exit(1);    
 
   quartz.b = 1; 
   quartz.i = 15; 
   quartz.bs.len=17;
   quartz.bs.val[0] = 0xA5; 
   quartz.bs.val[1] = 0xA5; 
   quartz.bs.val[2] = 0xA5; 
   memset(quartz.os.val,0x5A,10); 
   quartz.os.len=10;
   quartz.oid.size = 3; 
   quartz.oid.comp[0] = 2; 
   quartz.oid.comp[1] = 16; 
   quartz.oid.comp[2] = 31775; 
   quartz.s.len = 16;
   memcpy(quartz.s.val,"Ciao, bello\\\001\02\t\n",16); 
   quartz.a_si[0] = -16; 
   quartz.a_si[1] = 2032367742; 
   quartz.a_si[2] = 148; 
   quartz.a_si[3] = -326032210; 
   quartz.a_si[4] = 2188; 
   quartz.r_nn.i = 42; 
   quartz.r_nn.j = 411; 
   quartz.r_nn.k = 32700; 
   quartz.a_lv[0] = 0x1234; 
   quartz.a_lv[1] = 0x6D8A; 
   quartz.a_lv[2] = 0x1000; 
   quartz.a_lv[3] = 0x00C0; 
   quartz.a_lv[4] = 0x7030; 
   quartz.r_flt.f = -31.02; 
   quartz.r_flt.d = 81.01164328; 
   quartz.u1.tag = 0; 
   quartz.u1.un.cs.len = 16;
   memcpy(quartz.u1.un.cs.val,"0123456789ABCDEF",16); 
   quartz.u2.tag = 1; 
   strcpy(quartz.u2.un.rs,"0123456789ABCDEF"); 
 
   Roprinti("Amalgamated",&quartz,sample); 
 
   memset(&y,0xF1,sizeof(y)); 
  
/***************** send it out ************************/

   Bind_STUB(inst,argv[1],"w",Asn_1_ber); 
   Give inst 
   { 
      iop(Red:quartz,Blue:quartz); 
   } 
   Unbind(inst); 
  
/***************** receive it back ********************/

   Bind_STUB(inst,argv[1],"r",Asn_1_ber); 
 
   Accept inst 
   { 
      On iop(Red:x,White:y , ...) ; 
   } 
   Unbind(inst); 
  
/***************** report results *********************/

   if (!!quartz.b != !!x.b) 
      printf("###Compare 'b' failed\n"); 
   if (quartz.i != x.i) 
      printf("###Compare 'i' failed\n"); 
   if (!__ROr_cmpP_BitString(&quartz.bs,&x.bs,(l2=17,&l2),0)) 
      printf("###Compare 'bs' failed\n"); 
   if (x.bs.val[2] != 0x80) 
      printf("###Trailer 'bs' failed\n"); 
   if (!__ROr_CMPP_OctetString(quartz.os,x.os,(l2=10,&l2),0))
      printf("###Compare 'os' failed\n"); 
   if (!__ROr_cmpP_ObjectIdentifier(&quartz.oid,&x.oid,(l=5,&l),(l2=2,&l2))) 
      printf("###Compare 'oid' failed\n"); 
   if (!__ROr_CMPP_IA5String(quartz.s,x.s,(l=16,&l),0)) 
      printf("###Compare 's' failed\n"); 
   if (quartz.a_si[0] != x.a_si[0] || 
       quartz.a_si[1] != x.a_si[1] || 
       quartz.a_si[2] != x.a_si[2] || 
       quartz.a_si[3] != x.a_si[3] || 
       quartz.a_si[4] != x.a_si[4]) 
      printf("###Compare 'a_si' failed\n"); 
   if (quartz.r_nn.i != x.r_nn.i || 
       quartz.r_nn.j != x.r_nn.j || 
       quartz.r_nn.k != x.r_nn.k) 
      printf("###Compare 'r_nn' failed\n"); 
   if (quartz.a_lv[0] != x.a_lv[0] || 
       quartz.a_lv[1] != x.a_lv[1] || 
       quartz.a_lv[2] != x.a_lv[2] || 
       quartz.a_lv[3] != x.a_lv[3] || 
       quartz.a_lv[4] != x.a_lv[4]) 
      printf("###Compare 'a_lv' failed\n"); 
   if (!(x.a_lv[0]|x.a_lv[1]|x.a_lv[2]|x.a_lv[3]|x.a_lv[4])) 
      printf("###Or of 'a_lv' failed\n"); 
   if (quartz.r_flt.f != x.r_flt.f || 
       quartz.r_flt.d != x.r_flt.d) 
      printf("###Compare 'r_flt' failed\n"); 
   if (x.u1.tag != 0) 
      printf("###Tag 'u1' failed\n"); 
   if (!__ROr_CMPP_GeneralString(quartz.u1.un.cs,x.u1.un.cs,(l=16,&l),0)) 
      printf("###Value 'u1' failed\n"); 
   if (x.u2.tag != 1) 
      printf("###Tag 'u2' failed\n"); 
   if (!__ROr_CMPP_PrintableString(quartz.u2.un.rs,x.u2.un.rs,(l2=16,&l2),0))
      printf("###Value 'u2' failed\n"); 
   { 
      unsigned char *p = (unsigned char *)&y; 
      for (i=0;i<sizeof(y);i++,p++) 
         if (*p != 0xF1) 
         { 
            printf("###Untouched failed (byte %d)\n",i); 
            break; 
         } 
   } 
  
   printf("test completed\n");
   return(0); 
} 
