2 //=============================================================================
6 * Defines a helper class that can generate values for the parameters used
7 * for the Alt_Mapping example
11 //=============================================================================
15 #include "ace/OS_NS_ctype.h"
17 const CORBA::ULong TEST_BUFSIZE
= 128;
19 Generator::Generator (void)
23 Generator::~Generator (void)
28 Generator::gen_short (void)
30 return (CORBA::Short
) (ACE_OS::rand () % TEST_BUFSIZE
);
34 Generator::gen_long (void)
36 return ::ACE_OS::rand () % TEST_BUFSIZE
;
40 Generator::gen_string (void)
42 return gen_string (TEST_BUFSIZE
);
46 Generator::gen_string (int max_length
)
48 CORBA::ULong len
= (CORBA::ULong
) (::ACE_OS::rand () % max_length
);
49 char *buf
= CORBA::string_alloc (len
);
54 int c
= ACE_OS::rand () % 128;
55 if (ACE_OS::ace_isprint (c
) && !ACE_OS::ace_isspace (c
))
67 Generator::gen_wstring (void)
69 return gen_wstring (TEST_BUFSIZE
);
73 Generator::gen_wstring (int max_length
)
75 CORBA::ULong len
= (CORBA::ULong
) (::ACE_OS::rand () % max_length
);
76 CORBA::WChar
*buf
= CORBA::wstring_alloc (len
);
79 ACE_OutputCDR::wchar_maxbytes() == 1 ? ACE_OCTET_MAX
: ACE_WCHAR_MAX
;
82 CORBA::WChar wc
= ACE_OS::rand () % limit
;
94 const Alt_Mapping::Fixed_Struct
95 Generator::gen_fixed_struct (void)
97 this->fixed_struct_
.l
= ACE_OS::rand ();
98 this->fixed_struct_
.c
= ACE_OS::rand () % 128;
99 this->fixed_struct_
.s
= (CORBA::Short
) ACE_OS::rand ();
100 this->fixed_struct_
.o
= ACE_OS::rand () % 128;
101 this->fixed_struct_
.f
= (CORBA::Float
) (ACE_OS::rand () * 1.0);
102 this->fixed_struct_
.b
= (CORBA::Boolean
) (ACE_OS::rand () % 2);
103 this->fixed_struct_
.d
= (ACE_OS::rand () * 1.0);
104 return this->fixed_struct_
;
107 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton
, Generator
, ACE_Recursive_Thread_Mutex
);