Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / examples / Simple / bank / Bank_Client_i.cpp
blob6192e1b171b0c6859cabdc73c44f9b5b0359ac96
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 ()
11 //no-op
14 //Destructor.
15 Bank_Client_i::~Bank_Client_i ()
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 ()
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 ()
74 const char *name = "Name";
75 CORBA::Float initial_bal = 0.00;
77 Bank::Account_var acct_id1 = client_->open (name,
78 initial_bal);
80 Bank::Account_var acct_id2 = client_->open (name,
81 initial_bal);
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
89 void
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,
98 initial_bal);
100 Bank::Account_var acct_id2 = client_->open (name2,
101 initial_bal);
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.
110 void
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 ());