Commit 93d831a2 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added a new test to check character by character mode, fixed memory leak and...

Added a new test to check character by character mode, fixed memory leak and receiving end unable to read more than one character issue
parent 34190f2d
......@@ -249,7 +249,6 @@ TextStream *text_stream_new2(const char* ip, int loc_rtp_port, int loc_rtcp_port
}
TextStream* text_stream_start(TextStream *stream, RtpProfile *profile, const char *rem_rtp_addr, int rem_rtp_port, const char *rem_rtcp_addr, int rem_rtcp_port, int payload_type /* ignored */) {
ms_debug("before crash?");
rtp_session_set_profile(stream->ms.sessions.rtp_session, profile);
if (rem_rtp_port > 0) {
......@@ -321,7 +320,7 @@ static void process_t140_packet(TextStream *stream, mblk_t *packet) {
ms_warning("packet arrived out of order");
return;
} else if (t > 0) {
stream->inbufsize=3;
stream->inbufsize = 3;
insert_lost_char(stream->inbuf);
}
}
......@@ -408,7 +407,7 @@ static bool_t read_text_packet(TextStream *stream) {
if (!(stream->flags & TS_FLAG_NOTFIRST)) {
stream->flags |= TS_FLAG_NOTFIRST;
}
ortp_free(packet);
freemsg(packet);
return TRUE;
}
......@@ -422,20 +421,17 @@ static bool_t text_stream_ischar(TextStream *stream) {
void text_stream_iterate(TextStream *stream) {
send_data(stream);
if (stream->flags & TS_FLAG_NOCALLBACK) {
return;
}
if (text_stream_ischar(stream)) {
while (text_stream_ischar(stream)) {
OrtpEvent *ev;
OrtpEventData *eventData;
uint32_t character = text_stream_getchar32(stream);
ev = ortp_event_new(ORTP_EVENT_RTT_CHARACTER_RECEIVED);
eventData = ortp_event_get_data(ev);
eventData->info.received_rtt_character = text_stream_getchar32(stream);
rtp_session_dispatch_event(stream->ms.sessions.rtp_session, ev);
stream->flags |= TS_FLAG_NOCALLBACK;
if (character != 0) {
ev = ortp_event_new(ORTP_EVENT_RTT_CHARACTER_RECEIVED);
eventData = ortp_event_get_data(ev);
eventData->info.received_rtt_character = character;
rtp_session_dispatch_event(stream->ms.sessions.rtp_session, ev);
}
}
}
......@@ -444,8 +440,7 @@ void text_stream_putchar(TextStream *stream, const char c) {
if (stream->bufsize[i] < TS_OUTBUF_SIZE) {
stream->buf[i][stream->bufsize[i]++] = c;
}
else {
} else {
ms_warning("Text stream out buf is full, can not add more characters to buffer!");
}
}
......@@ -501,7 +496,6 @@ char text_stream_getchar(TextStream *stream) {
if (read_text_packet(stream)) {
return text_stream_getchar(stream);
}
stream->flags &= ~TS_FLAG_NOCALLBACK;
return '\0';
}
......
......@@ -150,7 +150,7 @@ static void basic_text_stream(void) {
const char* helloworld = "Hello World !";
int i = 0, strcmpresult = -2;
init_text_streams(marielle, margaux, FALSE, FALSE, NULL, T140_PAYLOAD_TYPE);
init_text_streams(marielle, margaux, FALSE, FALSE, NULL, T140_PAYLOAD_TYPE /* ignored */);
for (; i < strlen(helloworld); i++) {
char c = helloworld[i];
......@@ -163,10 +163,38 @@ static void basic_text_stream(void) {
BC_ASSERT_EQUAL(strcmpresult, 0, int, "%d");
uninit_text_streams(marielle, margaux);
text_stream_tester_destroy(marielle);
text_stream_tester_destroy(margaux);
}
static void basic_text_stream2(void) {
text_stream_tester_t* marielle = text_stream_tester_new();
text_stream_tester_t* margaux = text_stream_tester_new();
const char* helloworld = "Hello World !";
int i = 0, strcmpresult = -2;
int dummy = 0;
init_text_streams(marielle, margaux, FALSE, FALSE, NULL, T140_PAYLOAD_TYPE /* ignored */);
for (; i < strlen(helloworld); i++) {
char c = helloworld[i];
text_stream_putchar32(margaux->ts, (uint32_t)c);
wait_for_until_with_parse_events(&marielle->ts->ms, &margaux->ts->ms, &dummy, 1, 500, event_queue_cb, marielle, NULL, NULL);
}
BC_ASSERT_TRUE(wait_for_until(&marielle->ts->ms, &margaux->ts->ms, &marielle->stats.number_of_received_char, strlen(helloworld), 1000));
ms_message("Received message is: %s", marielle->stats.received_chars);
strcmpresult = strcmp(marielle->stats.received_chars, helloworld);
BC_ASSERT_EQUAL(strcmpresult, 0, int, "%d");
uninit_text_streams(marielle, margaux);
text_stream_tester_destroy(marielle);
text_stream_tester_destroy(margaux);
}
static test_t tests[] = {
{ "Basic text stream", basic_text_stream }
{ "Basic text stream: copy paste short text", basic_text_stream },
{ "Basic text stream: slow typing", basic_text_stream2 }
};
test_suite_t text_stream_test_suite = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment