From d249550e0a304c685e8dc9cd6fa709d74b79dcc2 Mon Sep 17 00:00:00 2001
From: Gautier Pelloux-Prayer
 <gautier.pelloux-prayer@belledonne-communications.com>
Date: Wed, 12 Nov 2014 15:33:23 +0100
Subject: [PATCH] Fix log collection test suite for Android

---
 build/android/liblinphone_tester.mk |  1 +
 oRTP                                |  2 +-
 tester/log_collection_tester.c      | 86 +++++++++++++++++++++++------
 3 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/build/android/liblinphone_tester.mk b/build/android/liblinphone_tester.mk
index e4387132f6..430f203bef 100644
--- a/build/android/liblinphone_tester.mk
+++ b/build/android/liblinphone_tester.mk
@@ -14,6 +14,7 @@ common_SRC_FILES := \
 	tester.c \
 	remote_provisioning_tester.c \
 	quality_reporting_tester.c \
+	log_collection_tester.c \
 	transport_tester.c \
 	player_tester.c \
 	dtmf_tester.c
diff --git a/oRTP b/oRTP
index a8dcd5b3ee..913099228e 160000
--- a/oRTP
+++ b/oRTP
@@ -1 +1 @@
-Subproject commit a8dcd5b3ee563b5746199a605b94459308f5d009
+Subproject commit 913099228e4f6faf92669e03e209c6ab19268bdd
diff --git a/tester/log_collection_tester.c b/tester/log_collection_tester.c
index 6397e62992..b9c1835c5c 100644
--- a/tester/log_collection_tester.c
+++ b/tester/log_collection_tester.c
@@ -1,19 +1,19 @@
 /*
 	belle-sip - SIP (RFC3261) library.
-    Copyright (C) 2010  Belledonne Communications SARL
+	Copyright (C) 2010  Belledonne Communications SARL
 
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 2 of the License, or
-    (at your option) any later version.
+	This program is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+	You should have received a copy of the GNU General Public License
+	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include <stdio.h>
@@ -27,6 +27,63 @@
 #include "private.h"
 #include "liblinphone_tester.h"
 
+
+/*getline is not available on android...*/
+#ifdef ANDROID
+/* This code is public domain -- Will Hartung 4/9/09 */
+size_t getline(char **lineptr, size_t *n, FILE *stream) {
+	char *bufptr = NULL;
+	char *p = bufptr;
+	size_t size;
+	int c;
+
+	if (lineptr == NULL) {
+		return -1;
+	}
+	if (stream == NULL) {
+		return -1;
+	}
+	if (n == NULL) {
+		return -1;
+	}
+	bufptr = *lineptr;
+	size = *n;
+
+	c = fgetc(stream);
+	if (c == EOF) {
+		return -1;
+	}
+	if (bufptr == NULL) {
+		bufptr = malloc(128);
+		if (bufptr == NULL) {
+			return -1;
+		}
+		size = 128;
+	}
+	p = bufptr;
+	while(c != EOF) {
+		if ((p - bufptr) > (size - 1)) {
+			size = size + 128;
+			bufptr = realloc(bufptr, size);
+			if (bufptr == NULL) {
+				return -1;
+			}
+		}
+		*p++ = c;
+		if (c == '\n') {
+			break;
+		}
+		c = fgetc(stream);
+	}
+
+	*p++ = '\0';
+	*lineptr = bufptr;
+	*n = size;
+
+	return p - bufptr - 1;
+}
+#endif
+
 LinphoneCoreManager* setup(bool_t enable_logs)  {
 	LinphoneCoreManager *marie;
 	int timeout = 300;
@@ -65,13 +122,11 @@ time_t check_file(char * filepath)  {
 			if (strlen(line) > 24) {
 				char date[24] = {'\0'};
 				memcpy(date, line, 23);
-				#ifndef ANDROID
 				if (strptime(date, "%Y-%m-%d %H:%M:%S", &tm_curr) != NULL) {
 					time_curr = mktime(&tm_curr);
 					CU_ASSERT_TRUE(time_curr >= time_prev);
 					time_prev = time_curr;
 				}
-				#endif
 			}
 		}
 		CU_ASSERT_TRUE(line_count > 25);
@@ -80,12 +135,7 @@ time_t check_file(char * filepath)  {
 		ms_free(filepath);
 	}
 	// return latest time in file
-	#ifdef ANDROID
-	ms_warning("fix me: Use mktime function on android");
-	return ms_time(0); //should be fixed
-	#else
 	return time_curr;
-	#endif
 }
 
 static LinphoneLogCollectionState old_collection_state;
-- 
GitLab