Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Simple / bank / Bank_Client_i.cpp
blob11d6d825e9457c82a87abe5d641bc5ad8d7f9aaa
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
8 // Constructor.
9 Bank_Client_i::Bank_Client_i (void)
11 //no-op
14 //Destructor.
15 Bank_Client_i::~Bank_Client_i (void)
17 //no-op
20 int
21 Bank_Client_i::run (const char *name,
22 int argc,
23 ACE_TCHAR *argv[])
25 // Initialize the client.
26 if (client_.init (name, argc, argv) == -1)
27 return -1;
29 try
31 this->check_accounts ();
32 if (client_.do_shutdown () == 1)
33 client_->shutdown ();
35 catch (const CORBA::Exception&)
37 ACE_DEBUG ((LM_DEBUG,
38 ACE_TEXT ("\nException caught in run\n")));
41 return 0;
44 int
45 Bank_Client_i::check_accounts (void)
47 try
49 ACE_DEBUG ((LM_DEBUG,
50 ACE_TEXT ("\nTests for account with same name\n")));
51 this->test_for_same_name ();
53 ACE_DEBUG ((LM_DEBUG,
54 ACE_TEXT ("\nTests for account with different names\n")));
55 this->test_for_different_name ();
57 ACE_DEBUG ((LM_DEBUG,
58 ACE_TEXT ("\nTests for overdrafts\n")));
59 this->test_for_overdraft ();
61 catch (const CORBA::Exception&)
63 ACE_DEBUG ((LM_DEBUG,
64 ACE_TEXT ("From Bank_Client_i::check_accounts()")));
66 return 0;
69 // This method tests whether an account with a
70 // a same name can be opened
71 void
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,
79 initial_bal);
81 Bank::Account_var acct_id2 = client_->open (name,
82 initial_bal);
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
90 void
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,
99 initial_bal);
101 Bank::Account_var acct_id2 = client_->open (name2,
102 initial_bal);
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.
111 void
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 ());