test: 添加 Windows 测试脚本

- test_network.py: 网络功能测试 (IP/DNS/WiFi/流量)
- test_system.py: 系统工具测试 (设备信息/电源/进程)
- test_android_api.py: Android API 综合测试 (Intent/集合/文件/Base64/数学/日历)
- 所有测试通过
This commit is contained in:
shuiyu1123 committed 2026-06-26 21:59:36 +08:00
1 parent b3d75f8cc2
commit 144b5ce45e
7 files changed
+311

No files matched your search

+141
View File
@@ -0,0 +1,141 @@
"""
Android API 综合测试脚本
测试 Android-pyApi 的核心 API 功能
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from android_pyapi import (
Intent, Uri, Bundle, ComponentName,
ArrayList, HashMap, HashSet, JSONObject, JSONArray,
String, StringBuilder, Integer, Math, System, Thread,
File, FileInputStream, FileOutputStream,
Log, Base64, Scanner,
Calendar, Date, SimpleDateFormat,
)
def test_intent():
"""测试 Intent"""
print("\n[Intent 测试]")
intent = Intent("android.intent.action.VIEW")
intent.setData(Uri.parse("https://example.com"))
intent.putExtra("key1", "value1")
intent.putExtra("key2", 42)
print(f" Action: {intent.getAction()}")
print(f" Data: {intent.getData()}")
print(f" Extra String: {intent.getStringExtra('key1')}")
print(f" Extra Int: {intent.getIntExtra('key2', 0)}")
def test_collections():
"""测试集合类"""
print("\n[集合类测试]")
lst = ArrayList()
lst.add("Apple")
lst.add("Banana")
lst.add("Cherry")
print(f" ArrayList size: {lst.size()}")
print(f" First: {lst.get(0)}")
m = HashMap()
m.put("name", "Android-pyApi")
m.put("version", "1.0.0")
print(f" HashMap get: {m.get('name')}")
json = JSONObject()
json.put("platform", "Windows")
json.put("ok", True)
print(f" JSONObject: {json.toString()}")
def test_string():
"""测试字符串类"""
print("\n[字符串测试]")
s = String("Hello, Android-pyApi!")
print(f" Length: {s.length()}")
print(f" Upper: {s.toUpperCase()}")
print(f" Contains 'Android': {s.contains('Android')}")
sb = StringBuilder()
sb.append("Hello")
sb.append(", World!")
print(f" StringBuilder: {sb.toString()}")
def test_file():
"""测试文件类"""
print("\n[文件测试]")
import tempfile
temp_file = os.path.join(tempfile.gettempdir(), "android_pyapi_test.txt")
f = File(temp_file)
print(f" Path: {f.getAbsolutePath()}")
with open(temp_file, 'w') as file:
file.write("Android-pyApi test")
print(f" Exists: {f.exists()}")
print(f" Name: {f.getName()}")
print(f" Size: {f.length()} bytes")
os.remove(temp_file)
print(f" After delete: {f.exists()}")
def test_base64():
"""测试 Base64"""
print("\n[Base64 测试]")
text = "Hello, Android-pyApi!"
encoded = Base64.encodeToString(text.encode('utf-8'))
decoded = Base64.decode(encoded).decode('utf-8')
print(f" Original: {text}")
print(f" Encoded: {encoded}")
print(f" Decoded: {decoded}")
print(f" Match: {text == decoded}")
def test_math():
"""测试数学类"""
print("\n[数学测试]")
print(f" PI: {Math.PI}")
print(f" abs(-42): {Math.abs(-42)}")
print(f" max(10, 20): {Math.max(10, 20)}")
print(f" sqrt(144): {Math.sqrt(144)}")
print(f" pow(2, 10): {Math.pow(2, 10)}")
def test_calendar():
"""测试日历类"""
print("\n[日历测试]")
cal = Calendar.getInstance()
print(f" Year: {cal.get(Calendar.YEAR)}")
print(f" Month: {cal.get(Calendar.MONTH) + 1}")
print(f" Day: {cal.get(Calendar.DAY_OF_MONTH)}")
print(f" Hour: {cal.get(Calendar.HOUR_OF_DAY)}")
print(f" Minute: {cal.get(Calendar.MINUTE)}")
def main():
"""主测试函数"""
print("=" * 60)
print("Android-pyApi 综合测试")
print("=" * 60)
test_intent()
test_collections()
test_string()
test_file()
test_base64()
test_math()
test_calendar()
print("\n" + "=" * 60)
print("所有测试完成!")
print("=" * 60)
if __name__ == "__main__":
main()