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 (void)
15 Bank_Client_i::~Bank_Client_i (void)
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 (void)
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 (void)
75 const char *name
= "Name";
76 CORBA::Float initial_bal
= 0.00;
78 Bank::Account_var acct_id1
= client_
->open (name
,
81 Bank::Account_var acct_id2
= client_
->open (name
,
84 ACE_ASSERT (acct_id1
->_is_equivalent (acct_id2
.in ()) != 0);
86 client_
->close (acct_id1
.in ());
89 // This method tests whether an account with different names can be opened
91 Bank_Client_i::test_for_different_name (void)
93 const char *name1
= "Name1";
94 const char *name2
= "Name2";
96 CORBA::Float initial_bal
= 0.0;
98 Bank::Account_var acct_id1
= client_
->open (name1
,
101 Bank::Account_var acct_id2
= client_
->open (name2
,
103 ACE_ASSERT (acct_id1
->_is_equivalent (acct_id2
.in ()) == 0);
105 client_
->close (acct_id1
.in ());
107 client_
->close (acct_id2
.in ());
110 // This method tests the Overdraft exception.
112 Bank_Client_i::test_for_overdraft (void)
114 CORBA::Float initial_bal
= 100.0;
115 const char *name
= "Name";
116 Bank::Account_var acct_id
= client_
->open (name
, initial_bal
);
117 acct_id
->deposit (100.00);
119 CORBA::Float bal
= acct_id
->balance ();
123 acct_id
->withdraw (bal
+ 20);
125 catch (Bank::Account::Overdraft
&)
127 ACE_DEBUG ((LM_DEBUG
,
128 ACE_TEXT ("Overdraft caught.\n")));
131 client_
->close (acct_id
.in ());