diff --git a/app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt b/app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt new file mode 100644 index 0000000000..02f5e2ed5b --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt @@ -0,0 +1,64 @@ +/* + * Nextcloud Talk application + * + * @author Samanwith KSN + * Copyright (C) 2023 Samanwith KSN + * + * 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 3 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.utils + +import android.content.Context +import android.os.Build +import android.os.VibrationEffect +import android.os.Vibrator +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.junit.MockitoJUnitRunner + +@RunWith(MockitoJUnitRunner::class) +class VibrationUtilsTest { + + @Mock + private lateinit var mockContext: Context + + @Mock + private lateinit var mockVibrator: Vibrator + + @Before + fun setup() { + Mockito.`when`(mockContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mockVibrator) + } + + @Test + fun testVibrateShort() { + VibrationUtils.vibrateShort(mockContext) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Mockito.verify(mockVibrator) + .vibrate( + VibrationEffect + .createOneShot( + VibrationUtils.SHORT_VIBRATE, + VibrationEffect.DEFAULT_AMPLITUDE + ) + ) + } else { + Mockito.verify(mockVibrator).vibrate(VibrationUtils.SHORT_VIBRATE) + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt index 4f2c2254c1..58f2b68fe9 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/VibrationUtils.kt @@ -25,7 +25,7 @@ import android.os.VibrationEffect import android.os.Vibrator object VibrationUtils { - private const val SHORT_VIBRATE: Long = 100 + const val SHORT_VIBRATE: Long = 100 fun vibrateShort(context: Context) { val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifier.java b/app/src/main/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifier.java index c949cc39f9..9731bfc842 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifier.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifier.java @@ -31,7 +31,8 @@ */ public class DataChannelMessageNotifier { - private final Set dataChannelMessageListeners = new LinkedHashSet<>(); + public final Set dataChannelMessageListeners = + new LinkedHashSet<>(); public synchronized void addListener(PeerConnectionWrapper.DataChannelMessageListener listener) { if (listener == null) { diff --git a/app/src/test/java/com/nextcloud/talk/utils/BundleKeysTest.kt b/app/src/test/java/com/nextcloud/talk/utils/BundleKeysTest.kt new file mode 100644 index 0000000000..72b42a9f16 --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/utils/BundleKeysTest.kt @@ -0,0 +1,103 @@ +/* + * Nextcloud Talk application + * + * @author Samanwith KSN + * Copyright (C) 2023 Samanwith KSN + * + * 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 3 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.utils + +import com.nextcloud.talk.utils.bundle.BundleKeys +import junit.framework.TestCase.assertEquals +import org.junit.Test +class BundleKeysTest { + + @Test + fun testBundleKeysValues() { + assertEquals("KEY_SELECTED_USERS", BundleKeys.KEY_SELECTED_USERS) + assertEquals("KEY_SELECTED_GROUPS", BundleKeys.KEY_SELECTED_GROUPS) + assertEquals("KEY_SELECTED_CIRCLES", BundleKeys.KEY_SELECTED_CIRCLES) + assertEquals("KEY_SELECTED_EMAILS", BundleKeys.KEY_SELECTED_EMAILS) + assertEquals("KEY_USERNAME", BundleKeys.KEY_USERNAME) + assertEquals("KEY_TOKEN", BundleKeys.KEY_TOKEN) + assertEquals("KEY_TRANSLATE_MESSAGE", BundleKeys.KEY_TRANSLATE_MESSAGE) + assertEquals("KEY_BASE_URL", BundleKeys.KEY_BASE_URL) + assertEquals("KEY_IS_ACCOUNT_IMPORT", BundleKeys.KEY_IS_ACCOUNT_IMPORT) + assertEquals("KEY_ORIGINAL_PROTOCOL", BundleKeys.KEY_ORIGINAL_PROTOCOL) + assertEquals("KEY_OPERATION_CODE", BundleKeys.KEY_OPERATION_CODE) + assertEquals("KEY_APP_ITEM_PACKAGE_NAME", BundleKeys.KEY_APP_ITEM_PACKAGE_NAME) + assertEquals("KEY_APP_ITEM_NAME", BundleKeys.KEY_APP_ITEM_NAME) + assertEquals("KEY_CONVERSATION_PASSWORD", BundleKeys.KEY_CONVERSATION_PASSWORD) + assertEquals("KEY_ROOM_TOKEN", BundleKeys.KEY_ROOM_TOKEN) + assertEquals("KEY_ROOM_ONE_TO_ONE", BundleKeys.KEY_ROOM_ONE_TO_ONE) + assertEquals("KEY_NEW_CONVERSATION", BundleKeys.KEY_NEW_CONVERSATION) + assertEquals("KEY_ADD_PARTICIPANTS", BundleKeys.KEY_ADD_PARTICIPANTS) + assertEquals("KEY_EXISTING_PARTICIPANTS", BundleKeys.KEY_EXISTING_PARTICIPANTS) + assertEquals("KEY_CALL_URL", BundleKeys.KEY_CALL_URL) + assertEquals("KEY_NEW_ROOM_NAME", BundleKeys.KEY_NEW_ROOM_NAME) + assertEquals("KEY_MODIFIED_BASE_URL", BundleKeys.KEY_MODIFIED_BASE_URL) + assertEquals("KEY_NOTIFICATION_SUBJECT", BundleKeys.KEY_NOTIFICATION_SUBJECT) + assertEquals("KEY_NOTIFICATION_SIGNATURE", BundleKeys.KEY_NOTIFICATION_SIGNATURE) + assertEquals("KEY_INTERNAL_USER_ID", BundleKeys.KEY_INTERNAL_USER_ID) + assertEquals("KEY_CONVERSATION_TYPE", BundleKeys.KEY_CONVERSATION_TYPE) + assertEquals("KEY_INVITED_PARTICIPANTS", BundleKeys.KEY_INVITED_PARTICIPANTS) + assertEquals("KEY_INVITED_CIRCLE", BundleKeys.KEY_INVITED_CIRCLE) + assertEquals("KEY_INVITED_GROUP", BundleKeys.KEY_INVITED_GROUP) + assertEquals("KEY_INVITED_EMAIL", BundleKeys.KEY_INVITED_EMAIL) + } + + @Test + fun testBundleKeysValues2() { + assertEquals("KEY_CONVERSATION_NAME", BundleKeys.KEY_CONVERSATION_NAME) + assertEquals("KEY_RECORDING_STATE", BundleKeys.KEY_RECORDING_STATE) + assertEquals("KEY_CALL_VOICE_ONLY", BundleKeys.KEY_CALL_VOICE_ONLY) + assertEquals("KEY_CALL_WITHOUT_NOTIFICATION", BundleKeys.KEY_CALL_WITHOUT_NOTIFICATION) + assertEquals("KEY_FROM_NOTIFICATION_START_CALL", BundleKeys.KEY_FROM_NOTIFICATION_START_CALL) + assertEquals("KEY_ROOM_ID", BundleKeys.KEY_ROOM_ID) + assertEquals("KEY_ARE_CALL_SOUNDS", BundleKeys.KEY_ARE_CALL_SOUNDS) + assertEquals("KEY_FILE_PATHS", BundleKeys.KEY_FILE_PATHS) + assertEquals("KEY_ACCOUNT", BundleKeys.KEY_ACCOUNT) + assertEquals("KEY_FILE_ID", BundleKeys.KEY_FILE_ID) + assertEquals("KEY_NOTIFICATION_ID", BundleKeys.KEY_NOTIFICATION_ID) + assertEquals("KEY_NOTIFICATION_TIMESTAMP", BundleKeys.KEY_NOTIFICATION_TIMESTAMP) + assertEquals("KEY_SHARED_TEXT", BundleKeys.KEY_SHARED_TEXT) + assertEquals("KEY_GEOCODING_QUERY", BundleKeys.KEY_GEOCODING_QUERY) + assertEquals("KEY_META_DATA", BundleKeys.KEY_META_DATA) + assertEquals("KEY_FORWARD_MSG_FLAG", BundleKeys.KEY_FORWARD_MSG_FLAG) + assertEquals("KEY_FORWARD_MSG_TEXT", BundleKeys.KEY_FORWARD_MSG_TEXT) + assertEquals("KEY_FORWARD_HIDE_SOURCE_ROOM", BundleKeys.KEY_FORWARD_HIDE_SOURCE_ROOM) + assertEquals("KEY_SYSTEM_NOTIFICATION_ID", BundleKeys.KEY_SYSTEM_NOTIFICATION_ID) + assertEquals("KEY_MESSAGE_ID", BundleKeys.KEY_MESSAGE_ID) + assertEquals("KEY_MIME_TYPE_FILTER", BundleKeys.KEY_MIME_TYPE_FILTER) + assertEquals( + "KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO", + BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO + ) + assertEquals( + "KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO", + BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO + ) + assertEquals("KEY_IS_MODERATOR", BundleKeys.KEY_IS_MODERATOR) + assertEquals("KEY_SWITCH_TO_ROOM", BundleKeys.KEY_SWITCH_TO_ROOM) + assertEquals("KEY_START_CALL_AFTER_ROOM_SWITCH", BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH) + assertEquals("KEY_IS_BREAKOUT_ROOM", BundleKeys.KEY_IS_BREAKOUT_ROOM) + assertEquals("KEY_NOTIFICATION_RESTRICT_DELETION", BundleKeys.KEY_NOTIFICATION_RESTRICT_DELETION) + assertEquals("KEY_DISMISS_RECORDING_URL", BundleKeys.KEY_DISMISS_RECORDING_URL) + assertEquals("KEY_SHARE_RECORDING_TO_CHAT_URL", BundleKeys.KEY_SHARE_RECORDING_TO_CHAT_URL) + assertEquals("KEY_GEOCODING_RESULT", BundleKeys.KEY_GEOCODING_RESULT) + assertEquals("ADD_ACCOUNT", BundleKeys.ADD_ACCOUNT) + assertEquals("SAVED_TRANSLATED_MESSAGE", BundleKeys.SAVED_TRANSLATED_MESSAGE) + } +} diff --git a/app/src/test/java/com/nextcloud/talk/utils/UriUtilsTest.kt b/app/src/test/java/com/nextcloud/talk/utils/UriUtilsTest.kt new file mode 100644 index 0000000000..6737246deb --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/utils/UriUtilsTest.kt @@ -0,0 +1,41 @@ +/* + * Nextcloud Talk application + * + * @author Samanwith KSN + * Copyright (C) 2023 Samanwith KSN + * + * 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 3 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.utils + +import org.junit.Assert +import org.junit.Test + +class UriUtilsTest { + + @Test + fun testHasHttpProtocolPrefixed() { + val uriHttp = "http://www.example.com" + val resultHttp = UriUtils.hasHttpProtocollPrefixed(uriHttp) + Assert.assertTrue(resultHttp) + + val uriHttps = "https://www.example.com" + val resultHttps = UriUtils.hasHttpProtocollPrefixed(uriHttps) + Assert.assertTrue(resultHttps) + + val uriWithoutPrefix = "www.example.com" + val resultWithoutPrefix = UriUtils.hasHttpProtocollPrefixed(uriWithoutPrefix) + Assert.assertFalse(resultWithoutPrefix) + } +} diff --git a/app/src/test/java/com/nextcloud/talk/utils/UserIdUtilsTest.kt b/app/src/test/java/com/nextcloud/talk/utils/UserIdUtilsTest.kt index 02a498cff3..8eee75f2b8 100644 --- a/app/src/test/java/com/nextcloud/talk/utils/UserIdUtilsTest.kt +++ b/app/src/test/java/com/nextcloud/talk/utils/UserIdUtilsTest.kt @@ -1,10 +1,10 @@ /* * Nextcloud Talk application * - * @author Mario Danic * @author Marcel Hibbe + * @author Samanwith KSN * Copyright (C) 2023 Marcel Hibbe - * Copyright (C) 2017-2018 Mario Danic + * Copyright (C) 2023 Samanwith KSN * * 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 diff --git a/app/src/test/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifierTest.kt b/app/src/test/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifierTest.kt new file mode 100644 index 0000000000..30dd53d864 --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifierTest.kt @@ -0,0 +1,88 @@ +/* + * Nextcloud Talk application + * + * @author Samanwith KSN + * Copyright (C) 2023 Samanwith KSN + * + * 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 3 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.webrtc + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.mockito.Mockito.mock +import org.mockito.Mockito.verify + +class DataChannelMessageNotifierTest { + + private lateinit var notifier: DataChannelMessageNotifier + private lateinit var listener: PeerConnectionWrapper.DataChannelMessageListener + + @Before + fun setUp() { + notifier = DataChannelMessageNotifier() + listener = mock(PeerConnectionWrapper.DataChannelMessageListener::class.java) + } + + @Test + fun testAddListener() { + notifier.addListener(listener) + assertTrue(notifier.dataChannelMessageListeners.contains(listener)) + } + + @Test + fun testRemoveListener() { + notifier.addListener(listener) + notifier.removeListener(listener) + assertFalse(notifier.dataChannelMessageListeners.contains(listener)) + } + + @Test + fun testNotifyAudioOn() { + notifier.addListener(listener) + notifier.notifyAudioOn() + verify(listener).onAudioOn() + } + + @Test + fun testNotifyAudioOff() { + notifier.addListener(listener) + notifier.notifyAudioOff() + verify(listener).onAudioOff() + } + + @Test + fun testNotifyVideoOn() { + notifier.addListener(listener) + notifier.notifyVideoOn() + verify(listener).onVideoOn() + } + + @Test + fun testNotifyVideoOff() { + notifier.addListener(listener) + notifier.notifyVideoOff() + verify(listener).onVideoOff() + } + + @Test + fun testNotifyNickChanged() { + notifier.addListener(listener) + val newNick = "NewNick" + notifier.notifyNickChanged(newNick) + verify(listener).onNickChanged(newNick) + } +} diff --git a/app/src/test/java/com/nextcloud/talk/webrtc/GlobalsTest.kt b/app/src/test/java/com/nextcloud/talk/webrtc/GlobalsTest.kt new file mode 100644 index 0000000000..f1ff9a020f --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/webrtc/GlobalsTest.kt @@ -0,0 +1,40 @@ +/* + * Nextcloud Talk application + * + * @author Samanwith KSN + * Copyright (C) 2023 Samanwith KSN + * + * 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 3 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.webrtc + +import org.junit.Assert +import org.junit.Test + +class GlobalsTest { + @Test + fun testRoomToken() { + Assert.assertEquals("roomToken", Globals.ROOM_TOKEN) + } + + @Test + fun testTargetParticipants() { + Assert.assertEquals("participants", Globals.TARGET_PARTICIPANTS) + } + + @Test + fun testTargetRoom() { + Assert.assertEquals("room", Globals.TARGET_ROOM) + } +} diff --git a/app/src/test/java/com/nextcloud/talk/webrtc/PeerConnectionNotifierTest.kt b/app/src/test/java/com/nextcloud/talk/webrtc/PeerConnectionNotifierTest.kt new file mode 100644 index 0000000000..59c0286ccc --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/webrtc/PeerConnectionNotifierTest.kt @@ -0,0 +1,81 @@ +/* + * Nextcloud Talk application + * + * @author Samanwith KSN + * Copyright (C) 2023 Samanwith KSN + * + * 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 3 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.webrtc + +import com.nextcloud.talk.webrtc.PeerConnectionWrapper.PeerConnectionObserver +import org.junit.Before +import org.junit.Test +import org.mockito.Mockito +import org.webrtc.MediaStream +import org.webrtc.PeerConnection + +class PeerConnectionNotifierTest { + private var notifier: PeerConnectionNotifier? = null + private var observer1: PeerConnectionObserver? = null + private var observer2: PeerConnectionObserver? = null + private var mockStream: MediaStream? = null + + @Before + fun setUp() { + notifier = PeerConnectionNotifier() + observer1 = Mockito.mock(PeerConnectionObserver::class.java) + observer2 = Mockito.mock(PeerConnectionObserver::class.java) + mockStream = Mockito.mock(MediaStream::class.java) + } + + @Test + fun testAddObserver() { + notifier!!.addObserver(observer1) + notifier!!.notifyStreamAdded(mockStream) + Mockito.verify(observer1)?.onStreamAdded(mockStream) + Mockito.verify(observer2, Mockito.never())?.onStreamAdded(mockStream) + } + + @Test + fun testRemoveObserver() { + notifier!!.addObserver(observer1) + notifier!!.addObserver(observer2) + notifier!!.removeObserver(observer1) + notifier!!.notifyStreamAdded(mockStream) + Mockito.verify(observer1, Mockito.never())?.onStreamAdded(mockStream) + Mockito.verify(observer2)?.onStreamAdded(mockStream) + } + + @Test + fun testNotifyStreamAdded() { + notifier!!.addObserver(observer1) + notifier!!.notifyStreamAdded(mockStream) + Mockito.verify(observer1)?.onStreamAdded(mockStream) + } + + @Test + fun testNotifyStreamRemoved() { + notifier!!.addObserver(observer1) + notifier!!.notifyStreamRemoved(mockStream) + Mockito.verify(observer1)?.onStreamRemoved(mockStream) + } + + @Test + fun testNotifyIceConnectionStateChanged() { + notifier!!.addObserver(observer1) + notifier!!.notifyIceConnectionStateChanged(PeerConnection.IceConnectionState.CONNECTED) + Mockito.verify(observer1)?.onIceConnectionStateChanged(PeerConnection.IceConnectionState.CONNECTED) + } +}