|
| 1 | +/* |
| 2 | + * WiFiAnalyzer |
| 3 | + * Copyright (C) 2015 - 2025 VREM Software Development <VREMSoftwareDevelopment@gmail.com> |
| 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 3 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, see <http://www.gnu.org/licenses/> |
| 17 | + */ |
| 18 | +package com.vrem.wifianalyzer.wifi.band |
| 19 | + |
| 20 | +import com.vrem.util.EMPTY |
| 21 | +import com.vrem.wifianalyzer.wifi.model.WiFiWidth |
| 22 | +import org.assertj.core.api.Assertions.assertThat |
| 23 | +import org.junit.runner.RunWith |
| 24 | +import org.junit.runners.Parameterized |
| 25 | +import org.junit.runners.Parameterized.Parameter |
| 26 | +import org.junit.runners.Parameterized.Parameters |
| 27 | +import kotlin.test.Test |
| 28 | + |
| 29 | +@RunWith(Parameterized::class) |
| 30 | +class WiFiChannelsParameterizedTest { |
| 31 | + private val countries: List<WiFiChannelCountry> = WiFiChannelCountry.findAll() |
| 32 | + .filter { !it.locale.country.isEmpty() && !it.locale.displayName.isEmpty() } |
| 33 | + |
| 34 | + @Parameter(0) |
| 35 | + lateinit var wiFiBand: WiFiBand |
| 36 | + |
| 37 | + @Parameter(1) |
| 38 | + lateinit var expectedWiFiInfo: ExpectedWiFiInfo |
| 39 | + |
| 40 | + @Parameter(2) |
| 41 | + lateinit var fixture: WiFiChannels |
| 42 | + |
| 43 | + @Test |
| 44 | + fun inRange() { |
| 45 | + assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.first().frequency)).describedAs("$wiFiBand").isTrue() |
| 46 | + assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.last().frequency)).describedAs("$wiFiBand").isTrue() |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + fun notInRange() { |
| 51 | + assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.first().frequency - 1)).isFalse() |
| 52 | + assertThat(fixture.inRange(expectedWiFiInfo.expectedChannels.last().frequency + 1)).isFalse() |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + fun wiFiChannelByFrequencyInRange() { |
| 57 | + expectedWiFiInfo.expectedChannels.forEach { expected -> |
| 58 | + assertThat(fixture.wiFiChannelByFrequency(expected.frequency)).isEqualTo(expected) |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + fun wiFiChannelByFrequencyOutOfRange() { |
| 64 | + assertThat(fixture.wiFiChannelByFrequency(expectedWiFiInfo.expectedChannels.first().frequency - 1)).isEqualTo(WiFiChannel.UNKNOWN) |
| 65 | + assertThat(fixture.wiFiChannelByFrequency(expectedWiFiInfo.expectedChannels.last().frequency + 1)).isEqualTo(WiFiChannel.UNKNOWN) |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + fun wiFiChannelByChannelInRange() { |
| 70 | + expectedWiFiInfo.expectedChannels.forEach { expected -> |
| 71 | + assertThat(fixture.wiFiChannelByChannel(expected.channel)).isEqualTo(expected) |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + fun wiFiChannelByChannelNotInRange() { |
| 77 | + assertThat(fixture.wiFiChannelByChannel(expectedWiFiInfo.expectedChannels.first().channel - 1)).isEqualTo(WiFiChannel.UNKNOWN) |
| 78 | + assertThat(fixture.wiFiChannelByChannel(expectedWiFiInfo.expectedChannels.last().channel + 1)).isEqualTo(WiFiChannel.UNKNOWN) |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + fun channelRange() { |
| 83 | + assertThat(fixture.channelRange.first).isEqualTo(expectedWiFiInfo.expectedChannels.first()) |
| 84 | + assertThat(fixture.channelRange.second).isEqualTo(expectedWiFiInfo.expectedChannels.last()) |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + fun activeChannels() { |
| 89 | + fixture.activeChannels.forEach { (wiFiWidth, wiFiWidthChannels) -> |
| 90 | + val expected = expectedWiFiInfo.expectedActiveChannels |
| 91 | + .filter { (expectedWiFiWidth) -> expectedWiFiWidth == wiFiWidth } |
| 92 | + .map { (_, expectedWiFiWidthChannels) -> |
| 93 | + expectedWiFiWidthChannels |
| 94 | + } |
| 95 | + .first() |
| 96 | + assertThat(wiFiWidthChannels) |
| 97 | + .describedAs("$wiFiWidth") |
| 98 | + .containsExactlyElementsOf(expected) |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + fun wiFiWidthUsingChannelInRange() { |
| 104 | + fixture.activeChannels.forEach { (wiFiWidth, channels) -> |
| 105 | + if (wiFiBand == WiFiBand.GHZ2 && wiFiWidth == WiFiWidth.MHZ_40) { |
| 106 | + return@forEach |
| 107 | + } |
| 108 | + channels.forEach { channel -> |
| 109 | + assertThat(fixture.wiFiWidthByChannel(channel)) |
| 110 | + .describedAs("$wiFiWidth | Channel: $channel") |
| 111 | + .isEqualTo(wiFiWidth) |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + @Test |
| 117 | + fun wiFiWidthUsingChannelNotInRange() { |
| 118 | + assertThat(fixture.wiFiWidthByChannel(wiFiBand.wiFiChannels.channelRange.first.channel - 1)).isEqualTo(WiFiWidth.MHZ_20) |
| 119 | + assertThat(fixture.wiFiWidthByChannel(wiFiBand.wiFiChannels.channelRange.second.channel + 1)).isEqualTo(WiFiWidth.MHZ_20) |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + fun availableChannels() { |
| 124 | + assertThat(fixture.availableChannels).containsExactlyElementsOf(expectedWiFiInfo.expectedAvailableChannels) |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + fun graphChannels() { |
| 129 | + assertThat(fixture.graphChannels.keys).containsExactlyElementsOf(expectedWiFiInfo.expectedGraphChannels.keys) |
| 130 | + assertThat(fixture.graphChannels.values).containsExactlyElementsOf(expectedWiFiInfo.expectedGraphChannels.values) |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + fun availableChannelsUsingWiFiBandAndCountry() { |
| 135 | + countries.forEach { country -> |
| 136 | + assertThat(fixture.availableChannels(wiFiBand, country.countryCode).map { it -> it.channel }) |
| 137 | + .describedAs("Country: ${country.countryCode}") |
| 138 | + .containsExactlyElementsOf(country.channels(wiFiBand)) |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + fun availableChannelsUsingWiFiWidthWiFiBandAndCountry() { |
| 144 | + WiFiWidth.entries.forEach { wiFiWidth -> |
| 145 | + countries.forEach { country -> |
| 146 | + assertThat(fixture.availableChannels(wiFiWidth, wiFiBand, country.countryCode)) |
| 147 | + .describedAs("$wiFiWidth | Country: $country") |
| 148 | + .containsExactlyElementsOf(expectedWiFiInfo.availableChannels(wiFiWidth, wiFiBand, country.countryCode)) |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + @Test |
| 154 | + fun ratingChannels() { |
| 155 | + countries.forEach { country -> |
| 156 | + assertThat(fixture.ratingChannels(wiFiBand, country.countryCode)) |
| 157 | + .describedAs("$wiFiBand | Country: ${country.countryCode}") |
| 158 | + .containsExactlyElementsOf(expectedWiFiInfo.expectedRatingChannels(wiFiBand, country.countryCode)) |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + fun wiFiChannels() { |
| 164 | + assertThat(fixture.wiFiChannels()).containsAll(expectedWiFiInfo.expectedChannels) |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + fun graphChannelCount() { |
| 169 | + assertThat(fixture.graphChannelCount()).isEqualTo(expectedWiFiInfo.expectedChannelsCount) |
| 170 | + } |
| 171 | + |
| 172 | + @Test |
| 173 | + fun graphChannelByFrequencyInRange() { |
| 174 | + expectedWiFiInfo.expectedChannels.forEach { (channel, frequency) -> |
| 175 | + assertThat(fixture.graphChannelByFrequency(frequency)) |
| 176 | + .describedAs("Channel: $channel | Frequency: $frequency") |
| 177 | + .isEqualTo(expectedWiFiInfo.expectedGraphChannels[channel] ?: String.EMPTY) |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + fun graphChannelByFrequencyOutOfRange() { |
| 183 | + assertThat(fixture.graphChannelByFrequency(expectedWiFiInfo.expectedChannels.first().frequency - 1)).isEmpty() |
| 184 | + assertThat(fixture.graphChannelByFrequency(expectedWiFiInfo.expectedChannels.last().frequency + 1)).isEmpty() |
| 185 | + } |
| 186 | + |
| 187 | + companion object { |
| 188 | + @JvmStatic |
| 189 | + @Parameters(name = "{0}") |
| 190 | + fun data() = listOf( |
| 191 | + arrayOf(WiFiBand.GHZ2, expectedWiFiInfoGHZ2, wiFiChannelsGHZ2), |
| 192 | + arrayOf(WiFiBand.GHZ5, expectedWiFiInfoGHZ5, wiFiChannelsGHZ5), |
| 193 | + arrayOf(WiFiBand.GHZ6, expectedWiFiInfoGHZ6, wiFiChannelsGHZ6) |
| 194 | + ) |
| 195 | + } |
| 196 | + |
| 197 | +} |
0 commit comments