From 02a1f1a7ec7b1bad7e8a1423b7f7cc189a37963e Mon Sep 17 00:00:00 2001 From: Nicolas Peugnet Date: Thu, 11 Jan 2024 14:49:05 +0100 Subject: Allow to easily run tests that only require Junit With this, it is possible to at least run some of the tests by simply running `../../gradlew test` from the humla submodule folder cloned from Mumla. --- build.gradle | 1 + .../java/se/lublin/humla/test/MixerTest.java | 66 ------------- .../java/se/lublin/humla/test/ModelTest.java | 50 ---------- .../java/se/lublin/humla/test/URLParserTest.java | 103 --------------------- src/test/java/se/lublin/humla/test/MixerTest.java | 66 +++++++++++++ src/test/java/se/lublin/humla/test/ModelTest.java | 50 ++++++++++ .../java/se/lublin/humla/test/URLParserTest.java | 103 +++++++++++++++++++++ 7 files changed, 220 insertions(+), 219 deletions(-) delete mode 100644 src/androidTest/java/se/lublin/humla/test/MixerTest.java delete mode 100644 src/androidTest/java/se/lublin/humla/test/ModelTest.java delete mode 100644 src/androidTest/java/se/lublin/humla/test/URLParserTest.java create mode 100644 src/test/java/se/lublin/humla/test/MixerTest.java create mode 100644 src/test/java/se/lublin/humla/test/ModelTest.java create mode 100644 src/test/java/se/lublin/humla/test/URLParserTest.java diff --git a/build.gradle b/build.gradle index 23aab6b..dc30647 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,7 @@ dependencies { implementation 'org.minidns:minidns-hla:0.3.4' implementation 'org.minidns:minidns-android21:0.3.4' implementation 'com.google.guava:guava:28.2-android' + testImplementation 'junit:junit:4.13.2' } allprojects { diff --git a/src/androidTest/java/se/lublin/humla/test/MixerTest.java b/src/androidTest/java/se/lublin/humla/test/MixerTest.java deleted file mode 100644 index 43c880b..0000000 --- a/src/androidTest/java/se/lublin/humla/test/MixerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package se.lublin.humla.test; - -import junit.framework.TestCase; - -import java.util.ArrayList; -import java.util.List; - -import se.lublin.humla.audio.BasicClippingShortMixer; -import se.lublin.humla.audio.IAudioMixer; -import se.lublin.humla.audio.IAudioMixerSource; - -/** - * Created by andrew on 16/07/15. - */ -public class MixerTest extends TestCase { - /** - * Tests that mixing order should not affect the output. - */ - public void testMixerCommutativity(IAudioMixer mixer) { - BasicSource pcmA = new BasicSource<>(new float[] { 0.2f, 0.5f, 0.7f }, 3); - BasicSource pcmB = new BasicSource<>(new float[] { 0.3f, 0.5f, 0.5f }, 3); - BasicSource pcmC = new BasicSource<>(new float[] { 0.0f, 0.0f, -0.5f }, 3); - final short[] outputABC = new short[3]; - final short[] outputCBA = new short[3]; - - List> sourcesABC = new ArrayList<>(); - sourcesABC.add(pcmA); - sourcesABC.add(pcmB); - sourcesABC.add(pcmC); - List> sourcesCBA = new ArrayList<>(); - sourcesCBA.add(pcmC); - sourcesCBA.add(pcmB); - sourcesCBA.add(pcmA); - - mixer.mix(sourcesABC, outputABC, 0, 3); - mixer.mix(sourcesCBA, outputCBA, 0, 3); - - for (int i = 0; i < 3; i++) { - assertEquals("Mixing should be commutative.", outputABC[i], outputCBA[i]); - } - } - - public void testBasicClippingShortMixer() { - testMixerCommutativity(new BasicClippingShortMixer()); - } - - private static class BasicSource implements IAudioMixerSource { - private T mSamples; - private int mLength; - - public BasicSource(T samples, int length) { - mSamples = samples; - mLength = length; - } - - @Override - public T getSamples() { - return mSamples; - } - - @Override - public int getNumSamples() { - return mLength; - } - } -} diff --git a/src/androidTest/java/se/lublin/humla/test/ModelTest.java b/src/androidTest/java/se/lublin/humla/test/ModelTest.java deleted file mode 100644 index 09d69a7..0000000 --- a/src/androidTest/java/se/lublin/humla/test/ModelTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2015 Andrew Comminos - * - * 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 se.lublin.humla.test; - -import junit.framework.TestCase; - -import se.lublin.humla.model.Channel; -import se.lublin.humla.model.User; - -/** - * Tests the Channel-User tree model. - * Created by andrew on 24/10/15. - */ -public class ModelTest extends TestCase { - - public void testUserAddRemove() { - Channel root = new Channel(0, false); - User user = new User(0, "Test user"); - user.setChannel(root); - assertEquals("Channel user list count is sane", 1, root.getUsers().size()); - assertEquals("Channel subchannel user count is sane", 1, root.getSubchannelUserCount()); - - Channel sub = new Channel(1, false); - root.addSubchannel(sub); - User subuser = new User(1, "Test user in subchannel"); - subuser.setChannel(sub); - assertEquals("Adding a user to a subchannel doesn't affect the number of direct children of the root", 1, root.getUsers().size()); - assertEquals("Adding a user to a subchannel updates the recursive user count", 2, root.getSubchannelUserCount()); - - user.setChannel(sub); - assertEquals("Moving a user to a subchannel updates the number of children of the root", 0, root.getUsers().size()); - assertEquals("Moving a user to a subchannel does not change the recursive user count of the root", 2, root.getSubchannelUserCount()); - assertEquals("Subchannel user count is sane", 2, sub.getUsers().size()); - } -} diff --git a/src/androidTest/java/se/lublin/humla/test/URLParserTest.java b/src/androidTest/java/se/lublin/humla/test/URLParserTest.java deleted file mode 100644 index 851f0ac..0000000 --- a/src/androidTest/java/se/lublin/humla/test/URLParserTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2014 Andrew Comminos - * - * 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 se.lublin.humla.test; - -import junit.framework.TestCase; - -import java.net.MalformedURLException; - -import se.lublin.humla.Constants; -import se.lublin.humla.model.Server; -import se.lublin.humla.util.MumbleURLParser; - -/** - * Tests the Mumble URL parser. - * Created by andrew on 03/03/14. - */ -public class URLParserTest extends TestCase { - - public void testURL() { - String url = "mumble://server.com/"; - try { - Server server = MumbleURLParser.parseURL(url); - assertEquals(server.getHost(), "server.com"); - assertEquals(server.getPort(), Constants.DEFAULT_PORT); - } catch (MalformedURLException e) { - fail("Failed to parse URL."); - } - } - - public void testURLWithPort() { - String url = "mumble://server.com:5000/"; - try { - Server server = MumbleURLParser.parseURL(url); - assertEquals(server.getHost(), "server.com"); - assertEquals(server.getPort(), 5000); - } catch (MalformedURLException e) { - fail("Failed to parse URL."); - } - } - - public void testURLWithUsername() { - String url = "mumble://TestUser@server.com/"; - try { - Server server = MumbleURLParser.parseURL(url); - assertEquals(server.getHost(), "server.com"); - assertEquals(server.getUsername(), "TestUser"); - assertEquals(server.getPort(), Constants.DEFAULT_PORT); - } catch (MalformedURLException e) { - fail("Failed to parse URL."); - } - } - - public void testURLWithCredentials() { - String url = "mumble://TestUser:mypassword@server.com:5000/"; - try { - Server server = MumbleURLParser.parseURL(url); - assertEquals(server.getHost(), "server.com"); - assertEquals(server.getUsername(), "TestUser"); - assertEquals(server.getPassword(), "mypassword"); - assertEquals(server.getPort(), 5000); - } catch (MalformedURLException e) { - fail("Failed to parse URL."); - } - } - - public void testURLWithPassword() { - String url = "mumble://:mypassword@server.com/"; - try { - Server server = MumbleURLParser.parseURL(url); - assertEquals(server.getHost(), "server.com"); - assertEquals(server.getPassword(), "mypassword"); - assertEquals(server.getPort(), Constants.DEFAULT_PORT); - } catch (MalformedURLException e) { - fail("Failed to parse URL."); - } - } - - public void testInvalidScheme() { - String url = "grumble://server.com/"; - try { - MumbleURLParser.parseURL(url); - fail("Successfully parsed bad scheme!"); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - } - -} diff --git a/src/test/java/se/lublin/humla/test/MixerTest.java b/src/test/java/se/lublin/humla/test/MixerTest.java new file mode 100644 index 0000000..43c880b --- /dev/null +++ b/src/test/java/se/lublin/humla/test/MixerTest.java @@ -0,0 +1,66 @@ +package se.lublin.humla.test; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.List; + +import se.lublin.humla.audio.BasicClippingShortMixer; +import se.lublin.humla.audio.IAudioMixer; +import se.lublin.humla.audio.IAudioMixerSource; + +/** + * Created by andrew on 16/07/15. + */ +public class MixerTest extends TestCase { + /** + * Tests that mixing order should not affect the output. + */ + public void testMixerCommutativity(IAudioMixer mixer) { + BasicSource pcmA = new BasicSource<>(new float[] { 0.2f, 0.5f, 0.7f }, 3); + BasicSource pcmB = new BasicSource<>(new float[] { 0.3f, 0.5f, 0.5f }, 3); + BasicSource pcmC = new BasicSource<>(new float[] { 0.0f, 0.0f, -0.5f }, 3); + final short[] outputABC = new short[3]; + final short[] outputCBA = new short[3]; + + List> sourcesABC = new ArrayList<>(); + sourcesABC.add(pcmA); + sourcesABC.add(pcmB); + sourcesABC.add(pcmC); + List> sourcesCBA = new ArrayList<>(); + sourcesCBA.add(pcmC); + sourcesCBA.add(pcmB); + sourcesCBA.add(pcmA); + + mixer.mix(sourcesABC, outputABC, 0, 3); + mixer.mix(sourcesCBA, outputCBA, 0, 3); + + for (int i = 0; i < 3; i++) { + assertEquals("Mixing should be commutative.", outputABC[i], outputCBA[i]); + } + } + + public void testBasicClippingShortMixer() { + testMixerCommutativity(new BasicClippingShortMixer()); + } + + private static class BasicSource implements IAudioMixerSource { + private T mSamples; + private int mLength; + + public BasicSource(T samples, int length) { + mSamples = samples; + mLength = length; + } + + @Override + public T getSamples() { + return mSamples; + } + + @Override + public int getNumSamples() { + return mLength; + } + } +} diff --git a/src/test/java/se/lublin/humla/test/ModelTest.java b/src/test/java/se/lublin/humla/test/ModelTest.java new file mode 100644 index 0000000..09d69a7 --- /dev/null +++ b/src/test/java/se/lublin/humla/test/ModelTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 Andrew Comminos + * + * 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 se.lublin.humla.test; + +import junit.framework.TestCase; + +import se.lublin.humla.model.Channel; +import se.lublin.humla.model.User; + +/** + * Tests the Channel-User tree model. + * Created by andrew on 24/10/15. + */ +public class ModelTest extends TestCase { + + public void testUserAddRemove() { + Channel root = new Channel(0, false); + User user = new User(0, "Test user"); + user.setChannel(root); + assertEquals("Channel user list count is sane", 1, root.getUsers().size()); + assertEquals("Channel subchannel user count is sane", 1, root.getSubchannelUserCount()); + + Channel sub = new Channel(1, false); + root.addSubchannel(sub); + User subuser = new User(1, "Test user in subchannel"); + subuser.setChannel(sub); + assertEquals("Adding a user to a subchannel doesn't affect the number of direct children of the root", 1, root.getUsers().size()); + assertEquals("Adding a user to a subchannel updates the recursive user count", 2, root.getSubchannelUserCount()); + + user.setChannel(sub); + assertEquals("Moving a user to a subchannel updates the number of children of the root", 0, root.getUsers().size()); + assertEquals("Moving a user to a subchannel does not change the recursive user count of the root", 2, root.getSubchannelUserCount()); + assertEquals("Subchannel user count is sane", 2, sub.getUsers().size()); + } +} diff --git a/src/test/java/se/lublin/humla/test/URLParserTest.java b/src/test/java/se/lublin/humla/test/URLParserTest.java new file mode 100644 index 0000000..851f0ac --- /dev/null +++ b/src/test/java/se/lublin/humla/test/URLParserTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2014 Andrew Comminos + * + * 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 se.lublin.humla.test; + +import junit.framework.TestCase; + +import java.net.MalformedURLException; + +import se.lublin.humla.Constants; +import se.lublin.humla.model.Server; +import se.lublin.humla.util.MumbleURLParser; + +/** + * Tests the Mumble URL parser. + * Created by andrew on 03/03/14. + */ +public class URLParserTest extends TestCase { + + public void testURL() { + String url = "mumble://server.com/"; + try { + Server server = MumbleURLParser.parseURL(url); + assertEquals(server.getHost(), "server.com"); + assertEquals(server.getPort(), Constants.DEFAULT_PORT); + } catch (MalformedURLException e) { + fail("Failed to parse URL."); + } + } + + public void testURLWithPort() { + String url = "mumble://server.com:5000/"; + try { + Server server = MumbleURLParser.parseURL(url); + assertEquals(server.getHost(), "server.com"); + assertEquals(server.getPort(), 5000); + } catch (MalformedURLException e) { + fail("Failed to parse URL."); + } + } + + public void testURLWithUsername() { + String url = "mumble://TestUser@server.com/"; + try { + Server server = MumbleURLParser.parseURL(url); + assertEquals(server.getHost(), "server.com"); + assertEquals(server.getUsername(), "TestUser"); + assertEquals(server.getPort(), Constants.DEFAULT_PORT); + } catch (MalformedURLException e) { + fail("Failed to parse URL."); + } + } + + public void testURLWithCredentials() { + String url = "mumble://TestUser:mypassword@server.com:5000/"; + try { + Server server = MumbleURLParser.parseURL(url); + assertEquals(server.getHost(), "server.com"); + assertEquals(server.getUsername(), "TestUser"); + assertEquals(server.getPassword(), "mypassword"); + assertEquals(server.getPort(), 5000); + } catch (MalformedURLException e) { + fail("Failed to parse URL."); + } + } + + public void testURLWithPassword() { + String url = "mumble://:mypassword@server.com/"; + try { + Server server = MumbleURLParser.parseURL(url); + assertEquals(server.getHost(), "server.com"); + assertEquals(server.getPassword(), "mypassword"); + assertEquals(server.getPort(), Constants.DEFAULT_PORT); + } catch (MalformedURLException e) { + fail("Failed to parse URL."); + } + } + + public void testInvalidScheme() { + String url = "grumble://server.com/"; + try { + MumbleURLParser.parseURL(url); + fail("Successfully parsed bad scheme!"); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + +} -- cgit v1.2.3