~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSTest.cc

Added the PBMS daemon plugin.

(Augen zu und durch!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
 
2
 *
 
3
 * PrimeBase Media Stream for MySQL
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Original author: Paul McCullagh
 
20
 * Continued development: Barry Leslie
 
21
 * H&G2JCtL
 
22
 *
 
23
 * 2007-05-30
 
24
 *
 
25
 * CORE SYSTEM:
 
26
 * Unit tests.
 
27
 *
 
28
 */
 
29
 
 
30
#include "CSConfig.h"
 
31
 
 
32
#include <assert.h>
 
33
#include <signal.h>
 
34
#include <string.h>
 
35
 
 
36
#include "CSGlobal.h"
 
37
#include "CSTest.h"
 
38
#include "CSLog.h"
 
39
#include "CSSocket.h"
 
40
#include "CSStream.h"
 
41
 
 
42
void *tst_test_thread_run()
 
43
{
 
44
        enter_();
 
45
        CSL.log(self, CSLog::Protocol, "Hello from a thread!\n");
 
46
        return_(NULL);
 
47
}
 
48
 
 
49
void *tst_fail_thread_run()
 
50
{
 
51
        enter_();
 
52
        for (;;) {
 
53
                CSThread::sleep(1000);
 
54
                CSException::throwAssertion(CS_CONTEXT, "Fail now!");
 
55
        }
 
56
        return_(NULL);
 
57
}
 
58
 
 
59
void *tst_kill_thread_run()
 
60
{
 
61
        enter_();
 
62
        for (;;) {
 
63
                CSThread::sleep(1000000);
 
64
        }
 
65
        return_(NULL);
 
66
}
 
67
 
 
68
void *tst_telnet_thread_run()
 
69
{
 
70
        CSSocket *listener = NULL;
 
71
        CSSocket *telnet = NULL;
 
72
        CSOutputStream *out = NULL;
 
73
        CSInputStream *in = NULL;
 
74
        CSStringBuffer *sb = NULL;
 
75
 
 
76
        enter_();
 
77
        try_(a) {
 
78
                listener = CSSocket::newSocket();
 
79
                telnet = CSSocket::newSocket();
 
80
 
 
81
                CSL.log(self, CSLog::Protocol, "Waiting for telnet on port 8080...\n");
 
82
                listener->publish(NULL, 8080);
 
83
                telnet->open(listener);
 
84
                out = telnet->getOutputStream();
 
85
                out = CSBufferedOutputStream::newStream(out);
 
86
                in = telnet->getInputStream();
 
87
                in = CSBufferedInputStream::newStream(in);
 
88
                out->printLine("Hallo!, enter quit to exit!");
 
89
                for (;;) {
 
90
                        sb = in->readLine();
 
91
                        out->printLine(sb->getCString());
 
92
                        if (strcmp(sb->getCString(), "quit") == 0)
 
93
                                break;
 
94
                        sb->release();
 
95
                        sb = NULL;
 
96
                }
 
97
        }
 
98
        finally_(a) {
 
99
                if (listener)
 
100
                        listener->release();
 
101
                if (telnet)
 
102
                        telnet->release();
 
103
                if (in)
 
104
                        in->release();
 
105
                if (out)
 
106
                        out->release();
 
107
                if (sb)
 
108
                        sb->release();
 
109
        }
 
110
        cont_(a);
 
111
        return_(NULL);
 
112
}
 
113
 
 
114
/* Run all tests */
 
115
void CSTest::runAll()
 
116
{
 
117
        CSObject *obj;
 
118
 
 
119
        enter_();
 
120
        new_(obj, CSObject);
 
121
        obj->release();
 
122
 
 
123
        new_(obj, CSRefObject);
 
124
        obj->retain();
 
125
        obj->release();
 
126
        obj->release();
 
127
 
 
128
        CSString *s = CSString::newString("This is a log test\nThe 2nd line\n");
 
129
        CSL.log(self, CSLog::Protocol, s);
 
130
        s->release();
 
131
 
 
132
        CSThread *t;
 
133
        
 
134
        t = CSThread::newThread(CSString::newString("test_thread"), tst_test_thread_run, NULL);
 
135
        t->start();
 
136
        t->release();
 
137
 
 
138
        t = CSThread::newThread(CSString::newString("fail_thread"), tst_fail_thread_run, NULL);
 
139
        t->start();
 
140
        t->join();
 
141
        t->release();
 
142
 
 
143
        t = CSThread::newThread(CSString::newString("kill_thread"), tst_kill_thread_run, NULL);
 
144
        t->start();
 
145
        CSThread::sleep(1000);
 
146
        t->signal(SIGTERM);     // Kill the thread
 
147
        t->join();
 
148
        t->release();
 
149
 
 
150
        t = CSThread::newThread(CSString::newString("telnet_thread"), tst_telnet_thread_run, NULL);
 
151
        t->start();
 
152
        t->join();
 
153
        t->release();
 
154
 
 
155
        exit_();
 
156
}
 
157