From 30b56c97eac761d5d80c7bc7d852d46015427cc9 Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 14 Dec 2017 14:54:44 -0800 Subject: [PATCH] Add more tests, fix lint errors and add check to travis --- .travis.yml | 2 +- mobile/build.gradle | 5 +- mobile/lint.xml | 9 +++ .../com/github/shadowsocks/acl/AclTest.kt | 41 +++++++++++++ .../shadowsocks/database/ProfileTest.kt | 36 +++++++++++ .../java/com/github/shadowsocks/AppManager.kt | 4 +- .../com/github/shadowsocks/ScannerActivity.kt | 4 +- .../shadowsocks/database/KeyValuePair.kt | 4 +- .../src/main/res/layout/dialog_acl_rule.xml | 1 + mobile/src/main/res/layout/layout_header.xml | 3 +- mobile/src/main/res/layout/layout_main.xml | 3 +- .../src/main/res/menu/custom_rules_menu.xml | 59 ++++++++++--------- .../shadowsocks/database/KeyValuePairTest.kt | 39 ++++++++++++ plugin/lint.xml | 4 ++ 14 files changed, 175 insertions(+), 39 deletions(-) create mode 100644 mobile/lint.xml create mode 100644 mobile/src/androidTest/java/com/github/shadowsocks/acl/AclTest.kt create mode 100644 mobile/src/androidTest/java/com/github/shadowsocks/database/ProfileTest.kt create mode 100644 mobile/src/test/java/com/github/shadowsocks/database/KeyValuePairTest.kt create mode 100644 plugin/lint.xml diff --git a/.travis.yml b/.travis.yml index 7024fa8b..69a1beb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,4 +30,4 @@ install: >/dev/null script: - - ./gradlew assembleDebug + - ./gradlew assembleDebug check diff --git a/mobile/build.gradle b/mobile/build.gradle index 4c68cddb..d5e31b82 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -9,7 +9,7 @@ def getCurrentFlavor() { .matcher(getGradle().getStartParameter().getTaskRequests().toString()) if (matcher.find()) return matcher.group(1).toLowerCase() else { println "NO MATCH FOUND" - return "" + return "debug" } } @@ -36,9 +36,6 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - lintOptions { - abortOnError false - } sourceSets.main.jniLibs.srcDirs += new File(project(':core').buildDir, "intermediates/bundles/${getCurrentFlavor()}/jni") sourceSets.main.jniLibs.srcDirs += new File(project(':core').projectDir, "src/overture/bin") diff --git a/mobile/lint.xml b/mobile/lint.xml new file mode 100644 index 00000000..150b6a37 --- /dev/null +++ b/mobile/lint.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/mobile/src/androidTest/java/com/github/shadowsocks/acl/AclTest.kt b/mobile/src/androidTest/java/com/github/shadowsocks/acl/AclTest.kt new file mode 100644 index 00000000..e7c4c454 --- /dev/null +++ b/mobile/src/androidTest/java/com/github/shadowsocks/acl/AclTest.kt @@ -0,0 +1,41 @@ +/******************************************************************************* + * * + * Copyright (C) 2017 by Max Lv * + * Copyright (C) 2017 by Mygod Studio * + * * + * 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.github.shadowsocks.acl + +import org.junit.Assert +import org.junit.Test +import java.io.StringReader + +class AclTest { + companion object { + private const val INPUT1 = """[proxy_all] +[bypass_list] +1.0.1.0/24 +[proxy_list] +(^|\.)4tern\.com${'$'} +""" + } + + @Test + fun parse() { + Assert.assertEquals(INPUT1, Acl().fromReader(StringReader(INPUT1)).toString()); + } +} diff --git a/mobile/src/androidTest/java/com/github/shadowsocks/database/ProfileTest.kt b/mobile/src/androidTest/java/com/github/shadowsocks/database/ProfileTest.kt new file mode 100644 index 00000000..2068dd54 --- /dev/null +++ b/mobile/src/androidTest/java/com/github/shadowsocks/database/ProfileTest.kt @@ -0,0 +1,36 @@ +/******************************************************************************* + * * + * Copyright (C) 2017 by Max Lv * + * Copyright (C) 2017 by Mygod Studio * + * * + * 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.github.shadowsocks.database + +import android.net.Uri +import org.junit.Assert +import org.junit.Test + +class ProfileTest { + @Test + fun parsing() { + val results = Profile.findAll("garble ss://YmYtY2ZiOnRlc3RAMTkyLjE2OC4xMDAuMTo4ODg4#example-server garble") + .toList() + Assert.assertEquals(1, results.size) + Assert.assertEquals(Uri.parse("ss://YmYtY2ZiOnRlc3Q@192.168.100.1:8888#example-server"), + results.single().toUri()) + } +} diff --git a/mobile/src/main/java/com/github/shadowsocks/AppManager.kt b/mobile/src/main/java/com/github/shadowsocks/AppManager.kt index dbab37ee..46f6cf8f 100644 --- a/mobile/src/main/java/com/github/shadowsocks/AppManager.kt +++ b/mobile/src/main/java/com/github/shadowsocks/AppManager.kt @@ -180,7 +180,9 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener { setContentView(R.layout.layout_apps) toolbar = findViewById(R.id.toolbar) toolbar.setTitle(R.string.proxied_apps) - toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material) + val arr = obtainStyledAttributes(intArrayOf(R.attr.homeAsUpIndicator)) + toolbar.navigationIcon = arr.getDrawable(0) + arr.recycle() toolbar.setNavigationOnClickListener { val intent = parentActivityIntent if (shouldUpRecreateTask(intent) || isTaskRoot) diff --git a/mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt b/mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt index b7be6292..dacb0a0d 100644 --- a/mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt +++ b/mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt @@ -54,7 +54,9 @@ class ScannerActivity : AppCompatActivity(), ZXingScannerView.ResultHandler { setContentView(R.layout.layout_scanner) val toolbar = findViewById(R.id.toolbar) toolbar.title = title - toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material) + val arr = obtainStyledAttributes(intArrayOf(R.attr.homeAsUpIndicator)) + toolbar.navigationIcon = arr.getDrawable(0) + arr.recycle() toolbar.setNavigationOnClickListener { navigateUp() } scannerView = findViewById(R.id.scanner) if (Build.VERSION.SDK_INT >= 25) getSystemService(ShortcutManager::class.java).reportShortcutUsed("scan") diff --git a/mobile/src/main/java/com/github/shadowsocks/database/KeyValuePair.kt b/mobile/src/main/java/com/github/shadowsocks/database/KeyValuePair.kt index 970e7550..6998c15a 100644 --- a/mobile/src/main/java/com/github/shadowsocks/database/KeyValuePair.kt +++ b/mobile/src/main/java/com/github/shadowsocks/database/KeyValuePair.kt @@ -53,7 +53,7 @@ class KeyValuePair() { get() = if (valueType == TYPE_LONG) ByteBuffer.wrap(value).long else null val string: String? get() = if (valueType == TYPE_STRING) String(value) else null - val stringSet: MutableSet? + val stringSet: Set? get() = if (valueType == TYPE_STRING_SET) { val buffer = ByteBuffer.wrap(value) val result = HashSet() @@ -95,7 +95,7 @@ class KeyValuePair() { this.value = value.toByteArray() return this } - fun put(value: MutableSet): KeyValuePair { + fun put(value: Set): KeyValuePair { valueType = TYPE_STRING_SET val stream = ByteArrayOutputStream() for (v in value) { diff --git a/mobile/src/main/res/layout/dialog_acl_rule.xml b/mobile/src/main/res/layout/dialog_acl_rule.xml index dfb27e8d..88668903 100644 --- a/mobile/src/main/res/layout/dialog_acl_rule.xml +++ b/mobile/src/main/res/layout/dialog_acl_rule.xml @@ -6,6 +6,7 @@ - + android:layout_height="wrap_content" + tools:ignore="RtlSymmetry"/> - + - - - - + + + + * + * Copyright (C) 2017 by Mygod Studio * + * * + * 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.github.shadowsocks.database + +import org.junit.Assert +import org.junit.Test + +class KeyValuePairTest { + @Test + fun putAndGet() { + val kvp = KeyValuePair() + Assert.assertEquals(true, kvp.put(true).boolean) + Assert.assertEquals(3f, kvp.put(3f).float) + Assert.assertEquals(3, kvp.put(3).int) + Assert.assertEquals(3L, kvp.put(3L).long) + Assert.assertEquals("3", kvp.put("3").string) + val set = (0 until 3).map(Int::toString).toSet() + Assert.assertEquals(set, kvp.put(set).stringSet) + Assert.assertEquals(null, kvp.boolean) + } +} diff --git a/plugin/lint.xml b/plugin/lint.xml new file mode 100644 index 00000000..0eafbde3 --- /dev/null +++ b/plugin/lint.xml @@ -0,0 +1,4 @@ + + + +