~ubuntu-branches/ubuntu/oneiric/eris/oneiric

« back to all changes in this revision

Viewing changes to test/Connection_unittest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-08-25 21:43:03 UTC
  • mfrom: (5.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090825214303-kvo07z5xcfydytom
Tags: 1.3.14-3
* debian/liberis-1.3-dev.install: Don't include *.la file.
* debian/control: Updated to Standards-Version 3.8.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
// along with this program; if not, write to the Free Software Foundation,
16
16
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
 
// $Id: Connection_unittest.cpp,v 1.2 2007-10-23 11:31:59 alriddoch Exp $
 
18
// $Id$
19
19
 
20
20
#include <Eris/Connection.h>
21
21
 
22
22
#include <Eris/Log.h>
 
23
#include <Eris/Poll.h>
 
24
 
 
25
#include <Atlas/Objects/Root.h>
 
26
#include <Atlas/Objects/SmartPtr.h>
 
27
 
 
28
#include <iostream>
23
29
 
24
30
static void writeLog(Eris::LogLevel, const std::string & msg)
25
31
{       
26
32
    std::cerr << msg << std::endl << std::flush;
27
33
}
28
34
 
 
35
class TestConnection : public Eris::Connection {
 
36
  public:
 
37
    TestConnection(const std::string &cnm, const std::string& host, short port, bool dbg) : Eris::Connection(cnm, host, port, dbg) {
 
38
    }
 
39
 
 
40
    void testSetStatus(Status sc) { setStatus(sc); }
 
41
 
 
42
    void testGotData(Eris::PollData & data) { gotData(data); }
 
43
};
 
44
 
 
45
class TestPollData : public Eris::PollData {
 
46
    virtual bool isReady(const basic_socket_stream*) { return false; }
 
47
};
 
48
 
29
49
int main()
30
50
{
31
51
    Eris::Logged.connect(sigc::ptr_fun(writeLog));
57
77
        assert(ret == 0);
58
78
    }
59
79
 
 
80
    // Test disconnect() when disconnected
 
81
    {
 
82
        TestConnection c("eristest", "localhost", 6767, true);
 
83
 
 
84
        c.disconnect();
 
85
    }
 
86
 
 
87
    // Test disconnect() when disconnecting
 
88
    {
 
89
        TestConnection c("eristest", "localhost", 6767, true);
 
90
 
 
91
        c.testSetStatus(Eris::BaseConnection::DISCONNECTING);
 
92
 
 
93
        c.disconnect();
 
94
 
 
95
        c.testSetStatus(Eris::BaseConnection::DISCONNECTED);
 
96
    }
 
97
 
 
98
    // Test disconnect() when connecting
 
99
    {
 
100
        TestConnection c("eristest", "localhost", 6767, true);
 
101
 
 
102
        c.connect();
 
103
 
 
104
        assert(c.getStatus() == Eris::BaseConnection::CONNECTING);
 
105
 
 
106
        c.disconnect();
 
107
 
 
108
        c.testSetStatus(Eris::BaseConnection::DISCONNECTED);
 
109
    }
 
110
 
 
111
    // Test gotData()
 
112
    {
 
113
        TestConnection c("eristest", "localhost", 6767, true);
 
114
 
 
115
        TestPollData data;
 
116
 
 
117
        c.testGotData(data);
 
118
    }
 
119
 
 
120
    // FIXME Not testing all the code paths through gotData()
 
121
 
 
122
    // Test send()
 
123
    {
 
124
        TestConnection c("eristest", "localhost", 6767, true);
 
125
 
 
126
        Atlas::Objects::Root obj;
 
127
 
 
128
        c.send(obj);
 
129
    }
60
130
    return 0;
61
131
}