Add a unit test for DnsConfig.intToInetString

adds JUnit dependencies and basic gradle support to run unit tests,
and a test for DnsConfig.intToInetString().

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
pull/51/head
Denton Gentry 2 years ago
parent 63dba694af
commit 283dd77bcc

@ -53,7 +53,7 @@ endif
$(DEBUG_APK): toolchain $(DEBUG_APK): toolchain
mkdir -p android/libs mkdir -p android/libs
go run gioui.org/cmd/gogio -buildmode archive -target android -appid $(APPID) -tags novulkan -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale go run gioui.org/cmd/gogio -buildmode archive -target android -appid $(APPID) -tags novulkan -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale
(cd android && ./gradlew assemblePlayDebug) (cd android && ./gradlew test assemblePlayDebug)
mv android/build/outputs/apk/play/debug/android-play-debug.apk $@ mv android/build/outputs/apk/play/debug/android-play-debug.apk $@
rundebug: $(DEBUG_APK) rundebug: $(DEBUG_APK)
@ -66,7 +66,7 @@ rundebug: $(DEBUG_APK)
tailscale-fdroid.apk: toolchain tailscale-fdroid.apk: toolchain
mkdir -p android/libs mkdir -p android/libs
go run gioui.org/cmd/gogio -buildmode archive -target android -appid $(APPID) -tags novulkan -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale go run gioui.org/cmd/gogio -buildmode archive -target android -appid $(APPID) -tags novulkan -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale
(cd android && ./gradlew assembleFdroidDebug) (cd android && ./gradlew test assembleFdroidDebug)
mv android/build/outputs/apk/fdroid/debug/android-fdroid-debug.apk $@ mv android/build/outputs/apk/fdroid/debug/android-fdroid-debug.apk $@
# This target is also used by the F-Droid builder. # This target is also used by the F-Droid builder.
@ -76,7 +76,7 @@ release_aar:
go run gioui.org/cmd/gogio -ldflags "-X tailscale.com/version.Long=$(VERSIONNAME) -X tailscale.com/version.Short=$(VERSIONNAME_SHORT) -X tailscale.com/version.GitCommit=$(TAILSCALE_COMMIT) -X tailscale.com/version.ExtraGitCommit=$(OUR_VERSION)" -buildmode archive -target android -appid $(APPID) -tags novulkan -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale go run gioui.org/cmd/gogio -ldflags "-X tailscale.com/version.Long=$(VERSIONNAME) -X tailscale.com/version.Short=$(VERSIONNAME_SHORT) -X tailscale.com/version.GitCommit=$(TAILSCALE_COMMIT) -X tailscale.com/version.ExtraGitCommit=$(OUR_VERSION)" -buildmode archive -target android -appid $(APPID) -tags novulkan -o $(AAR) github.com/tailscale/tailscale-android/cmd/tailscale
$(RELEASE_AAB): release_aar $(RELEASE_AAB): release_aar
(cd android && ./gradlew bundlePlayRelease) (cd android && ./gradlew test bundlePlayRelease)
mv ./android/build/outputs/bundle/playRelease/android-play-release.aab $@ mv ./android/build/outputs/bundle/playRelease/android-play-release.aab $@
release: $(RELEASE_AAB) release: $(RELEASE_AAB)

@ -50,6 +50,7 @@ dependencies {
implementation "androidx.browser:browser:1.2.0" implementation "androidx.browser:browser:1.2.0"
implementation "androidx.security:security-crypto:1.1.0-alpha03" implementation "androidx.security:security-crypto:1.1.0-alpha03"
implementation ':ipn@aar' implementation ':ipn@aar'
testCompile "junit:junit:4.12"
// Non-free dependencies. // Non-free dependencies.
playImplementation 'com.google.android.gms:play-services-auth:18.0.0' playImplementation 'com.google.android.gms:play-services-auth:18.0.0'

@ -229,7 +229,7 @@ public class DnsConfig {
} }
String intToInetString(int hostAddress) { public String intToInetString(int hostAddress) {
return String.format(java.util.Locale.ROOT, "%d.%d.%d.%d", return String.format(java.util.Locale.ROOT, "%d.%d.%d.%d",
(0xff & hostAddress), (0xff & hostAddress),
(0xff & (hostAddress >> 8)), (0xff & (hostAddress >> 8)),

@ -0,0 +1,21 @@
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import com.tailscale.ipn.DnsConfig;
public class DnsConfigTest {
DnsConfig dns;
@Before
public void setup() {
dns = new DnsConfig(null);
}
@Test
public void dnsConfig_intToInetStringTest() {
assertEquals(dns.intToInetString(0x0101a8c0), "192.168.1.1");
assertEquals(dns.intToInetString(0x04030201), "1.2.3.4");
assertEquals(dns.intToInetString(0), "0.0.0.0");
}
}
Loading…
Cancel
Save