More tests update
[ACE_TAO.git] / TAO / tests / OctetSeq / client.cpp
blob047fe627f5b308510fdc5d0285eca58c77ea99bf
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "ace/ACE.h"
4 #include "testC.h"
5 #include "ace/OS_NS_time.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_unistd.h"
9 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
10 int niterations = 5;
11 unsigned int seed = 0;
12 int verbose = 0;
14 int
15 parse_args (int argc, ACE_TCHAR *argv[])
17 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("vk:i:s:"));
18 int c;
20 while ((c = get_opts ()) != -1)
21 switch (c)
23 case 'k':
24 ior = get_opts.opt_arg ();
25 break;
27 case 'i':
28 niterations = ACE_OS::atoi (get_opts.opt_arg ());
29 break;
31 case 's':
32 seed = ACE_OS::atoi (get_opts.opt_arg ());
33 break;
35 case 'v':
36 verbose = 1;
37 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-k <ior> "
44 "-i <niterations> "
45 "-s <seed> "
46 "-v "
47 "\n",
48 argv [0]),
49 -1);
51 // Indicates successful parsing of the command line
52 return 0;
55 int
56 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
58 try
60 CORBA::ORB_var orb =
61 CORBA::ORB_init (argc, argv);
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 CORBA::Object_var object =
67 orb->string_to_object (ior);
69 Test::Database_var server =
70 Test::Database::_narrow (object.in ());
72 if (CORBA::is_nil (server.in ()))
74 ACE_ERROR_RETURN ((LM_ERROR,
75 "Object reference <%s> is nil.\n",
76 ior),
77 1);
80 #if (TAO_HAS_MINIMUM_CORBA == 0)
81 CORBA::String_var repository_id =
82 server->_repository_id ();
84 if (ACE_OS::strcmp (repository_id.in (), "IDL:Test/Database:1.0") != 0)
86 ACE_ERROR_RETURN ((LM_ERROR,
87 "Repository id is wrong <%C>\n",
88 repository_id.in ()),
89 1);
91 #endif /* TAO_HAS_MINIMUM_CORBA == 0 */
93 if (seed == 0)
95 seed = static_cast<unsigned int> (ACE_OS::time (0));
96 ACE_DEBUG ((LM_DEBUG, "Seed value is %d\n", seed));
99 const int nelements = 64; // @@ TODO
100 const int maxsize = 1024;
101 Test::OctetSeq elements[nelements];
103 for (int i = 0; i != niterations; ++i)
105 CORBA::ULong r = ACE_OS::rand_r (&seed);
106 Test::Index idx = (r % nelements);
108 if (i % 100 == 0)
110 for (int j = 0; j != nelements; ++j)
112 CORBA::ULong r = ACE_OS::rand_r (&seed);
113 CORBA::ULong l = r % maxsize;
114 elements[j].length (l);
115 CORBA::Double token = 0;
116 for (CORBA::ULong k = 0; k != l; ++k)
118 r = ACE_OS::rand_r (&seed);
119 elements[j][k] = (r % 128);
120 token += r;
122 CORBA::Double returned_token;
123 server->set (Test::Index (j),
124 elements[j],
125 token,
126 returned_token);
128 if (!ACE::is_equal (token, returned_token))
130 ACE_ERROR ((LM_ERROR,
131 "ERROR - invalid token <%f> returned,"
132 " expecting %f in (%d,%d)\n",
133 returned_token, token, i, j));
138 CORBA::ULong crc_remote =
139 server->get_crc (idx);
141 CORBA::ULong crc_local =
142 ACE::crc32 (elements[idx].get_buffer (),
143 elements[idx].length ());
145 if (crc_local != crc_remote)
147 ACE_DEBUG ((LM_DEBUG,
148 "CRC mismatch for element %d\n", idx));
150 else if (verbose == 1)
152 ACE_DEBUG ((LM_DEBUG,
153 "CRC <%u> matched for element %d\n",
154 crc_remote, idx));
159 server->shutdown ();
160 ACE_OS::sleep(1);
161 orb->destroy ();
163 catch (const CORBA::Exception& ex)
165 ex._tao_print_exception ("Caught exception:");
166 return 1;
169 return 0;