1 #include "Bank_Client_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Read_Buffer.h"
4 #include "ace/OS_NS_unistd.h"
6 // This is the interface program that accesses the remote object
9 Bank_Client_i::Bank_Client_i ()
15 Bank_Client_i::~Bank_Client_i ()
21 Bank_Client_i::run (const char *name
,
25 // Initialize the client.
26 if (client_
.init (name
, argc
, argv
) == -1)
31 this->check_accounts ();
32 if (client_
.do_shutdown () == 1)
35 catch (const CORBA::Exception
&)
38 ACE_TEXT ("\nException caught in run\n")));
45 Bank_Client_i::check_accounts ()
50 ACE_TEXT ("\nTests for account with same name\n")));
51 this->test_for_same_name ();
54 ACE_TEXT ("\nTests for account with different names\n")));
55 this->test_for_different_name ();
58 ACE_TEXT ("\nTests for overdrafts\n")));
59 this->test_for_overdraft ();
61 catch (const CORBA::Exception
&)
64 ACE_TEXT ("From Bank_Client_i::check_accounts()")));
69 // This method tests whether an account with a
70 // a same name can be opened
72 Bank_Client_i::test_for_same_name ()
74 const char *name
= "Name";
75 CORBA::Float initial_bal
= 0.00;
77 Bank::Account_var acct_id1
= client_
->open (name
,
80 Bank::Account_var acct_id2
= client_
->open (name
,
83 ACE_ASSERT (acct_id1
->_is_equivalent (acct_id2
.in ()) != 0);
85 client_
->close (acct_id1
.in ());
88 // This method tests whether an account with different names can be opened
90 Bank_Client_i::test_for_different_name ()
92 const char *name1
= "Name1";
93 const char *name2
= "Name2";
95 CORBA::Float initial_bal
= 0.0;
97 Bank::Account_var acct_id1
= client_
->open (name1
,
100 Bank::Account_var acct_id2
= client_
->open (name2
,
102 ACE_ASSERT (acct_id1
->_is_equivalent (acct_id2
.in ()) == 0);
104 client_
->close (acct_id1
.in ());
106 client_
->close (acct_id2
.in ());
109 // This method tests the Overdraft exception.
111 Bank_Client_i::test_for_overdraft ()
113 CORBA::Float initial_bal
= 100.0;
114 const char *name
= "Name";
115 Bank::Account_var acct_id
= client_
->open (name
, initial_bal
);
116 acct_id
->deposit (100.00);
118 CORBA::Float bal
= acct_id
->balance ();
122 acct_id
->withdraw (bal
+ 20);
124 catch (Bank::Account::Overdraft
&)
126 ACE_DEBUG ((LM_DEBUG
,
127 ACE_TEXT ("Overdraft caught.\n")));
130 client_
->close (acct_id
.in ());