提交 885e4e8a 编写于 作者: lizhongyi_'s avatar lizhongyi_

Merge branch 'dev' into alpha

......@@ -5,6 +5,7 @@
"versionName" : "1.0.9",
"versionCode" : "109",
"transformPx" : false,
"uni-app-x" : {},
/* 5+App特有相关 */
"app-plus" : {
"usingComponents" : true,
......
<template>
<view class="uni-container">
<page-head :title="title"></page-head>
<view class="uni-panel" v-for="(item, index) in list" :key="index">
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="goDetailPage(item)"
hover-class="uni-navigate-item-active">
......@@ -22,7 +21,7 @@
type ListItem = {
name : string,
open : boolean,
open ?: boolean,
function ?: string,
url ?: string
}
......@@ -34,7 +33,7 @@
list: [{
name: "腾讯定位sdk集成示例",
function: "gotoTencentLocation"
function: "gotoTencentLocation",
},
{
name: "Toast示例",
......
......@@ -7,7 +7,7 @@
<script>
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest } from '../../uni_modules/uts-api-test'
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest,logUTSJSONObjectTest } from '../../uni_modules/uts-api-test'
export default {
......@@ -29,8 +29,7 @@
this.testRet = "测试失败"
return;
}
if(getLog(2023) != '{"type":"number","value":"2023"}'){
if(getLog(2023) != '{"subType":"number","type":"number","value":"2023"}'){
this.testRet = "测试失败"
return;
}
......@@ -39,13 +38,11 @@
// this.testRet = "测试失败"
// return;
// }
if(getLog(2023.002) != '{"type":"number","value":"2023.002"}'){
if(getLog(2023.002 as number) != '{"subType":"number","type":"number","value":"2023.002"}'){
this.testRet = "测试失败"
return;
}
if(logObjectTest() != '{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":0,"type":"string","value":"1"},{"name":1,"type":"string","value":"2"},{"name":2,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}'){
this.testRet = "测试失败"
return;
......
......@@ -7,7 +7,7 @@
<script>
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest } from '../../uni_modules/uts-api-test'
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest,frequentlyObjectTest } from '../../uni_modules/uts-api-test'
export default {
......@@ -69,6 +69,10 @@
return;
}
if(!frequentlyObjectTest()){
this.testRet = "测试失败"
return;
}
this.testRet = "测试完成"
}
......
<template>
<!-- #ifdef APP-ANDROID -->
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
......@@ -45,9 +46,11 @@
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
<!-- #endif -->
</template>
<script>
<!-- #ifdef APP-ANDROID -->
import {
getAppContextTest,
getUniActivityTest,
......@@ -257,6 +260,7 @@ export default {
},
},
}
<!-- #endif -->
</script>
<style>
......
<template>
<!-- #ifdef APP-IOS -->
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<button @click="testCurrentVC">获取当前UIViewController</button>
<view class="result" :style="resultStyle(currentVCResult.passed)"> 测试结果 -- {{formatResult(currentVCResult.passed)}}</view>
<button @click="testKeyWindow">获取当前app的keyWindow</button>
<view class="result" :style="resultStyle(keyWindowResult.passed)"> 测试结果 -- {{formatResult(keyWindowResult.passed)}}</view>
<button @click="testColorConvert">将字符串色值转换为UIColor</button>
<view class="result">
<p v-for="item in colorConvertResult" :style="resultStyle(item.passed)"> {{item.key}}: {{item.value}} -- {{formatResult(item.passed)}}</p>
</view>
<button @click="testResourcePath">资源路径转换</button>
<view class="result" :style="resultStyle(resourcePathResult.passed)"> {{resourcePathResult.key}}: {{resourcePathResult.value}} -- {{formatResult(resourcePathResult.passed)}}</view>
<button @click="testDeviceInfo">获取设备信息</button>
<view class="result">
<p v-for="item in deviceInfoResult" :style="resultStyle(item.passed)"> {{item.key}}: {{item.value}} -- {{formatResult(item.passed)}}</p>
</view>
<button @click="testAppInfo">获取App信息相关api</button>
<view class="result">
<p v-for="item in appInfoResult" :style="resultStyle(item.passed)"> {{item.key}}: {{item.value}} -- {{formatResult(item.passed)}}</p>
</view>
<button @click="testSystemSetting">获取系统设置</button>
<view class="result" :style="resultStyle(systemSettingResult.passed)"> {{systemSettingResult.key}}: {{systemSettingResult.value}} -- {{formatResult(systemSettingResult.passed)}}</view>
<button @click="testTypeof">typeof</button>
<view class="result">
<p v-for="item in typeofResult" :style="resultStyle(item.passed)"> {{item.key}}: {{item.value}} -- {{formatResult(item.passed)}}</p>
</view>
<button @click="testDataConvert">数据转换</button>
<view class="result">
<p v-for="item in dataConvertResult" :style="resultStyle(item.passed)"> {{item.key}}: {{item.value}} -- {{formatResult(item.passed)}}</p>
</view>
<button @click="testAll">test all</button>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
<!-- #endif -->
</template>
<script>
<!-- #ifdef APP-IOS -->
import {
getCurrentVCTest,
getKeyWindowTest,
colorWithStringTest,
getResourcePathTest,
getDeviceInfoTest,
getAppInfoTest,
getSystemSettingTest,
tepeofTest,
dataConvertTest,
} from "@/uni_modules/uts-platform-api"
export default {
data() {
return {
title: "UTSiOS test",
currentVCResult: {},
keyWindowResult: {},
colorConvertResult: [],
resourcePathResult: {},
deviceInfoResult: [],
appInfoResult: [],
systemSettingResult: {},
typeofResult: [],
dataConvertResult: []
}
},
methods: {
formatResult(res) {
if (res == null) {
return "";
}
return res ? "测试通过": "测试失败"
},
resultStyle(res) {
if (res == null) {
return {
color: "#333333"
}
}
let color = res ? "#00ff00" : "#ff0000";
return {
color: color
}
},
testCurrentVC() {
this.currentVCResult = getCurrentVCTest();
},
testKeyWindow() {
this.keyWindowResult = getKeyWindowTest();
},
testColorConvert() {
let array = colorWithStringTest();
this.colorConvertResult = array.map((value) => {
return JSON.parse(value)
})
},
testResourcePath() {
this.resourcePathResult = getResourcePathTest("/static/logo.png");
},
testDeviceInfo() {
let array = getDeviceInfoTest();
this.deviceInfoResult = array.map((value) => {
return JSON.parse(value)
})
},
testAppInfo() {
let array = getAppInfoTest();
this.appInfoResult = array.map((value) => {
return JSON.parse(value)
})
},
testSystemSetting() {
this.systemSettingResult = getSystemSettingTest();
},
testTypeof() {
let array = tepeofTest();
this.typeofResult = array.map((value) => {
return JSON.parse(value)
})
},
testDataConvert() {
let array = dataConvertTest();
this.dataConvertResult = array.map((value) => {
return JSON.parse(value)
})
},
testAll() {
this.testCurrentVC();
this.testKeyWindow();
this.testColorConvert();
this.testResourcePath();
this.testDeviceInfo();
this.testAppInfo();
this.testSystemSetting();
this.testTypeof();
this.testDataConvert();
}
}
}
<!-- #endif -->
</script>
<style>
.result {
text-align: left;
padding-left: 20px;
padding-right: 20px;
max-width: 100%;
overflow: auto;
overflow-wrap: normal;
}
</style>
\ No newline at end of file
......@@ -35,12 +35,17 @@ export default {
},
methods: {
test() {
this.result = runTests()
const resultMap = this.result.toMap()
resultMap.forEach((res, name) => {
this.names.push(name)
this.resultArray.push(res as Result)
})
this.result = runTests()
// const resultMap = this.result.toMap()
// resultMap.forEach((res, name) => {
// this.names.push(name)
// this.resultArray.push(res as Result)
// })
const resultMap = this.result
for (const key in resultMap) {
this.names.push(key)
this.resultArray.push(resultMap[key] as Result)
}
},
},
}
......
......@@ -17,7 +17,7 @@ export const getLog : GetLog = function (param : Any|null) : string {
let jsonLog = allLog
jsonLog = jsonLog.replace("---BEGIN:CONSOLE---", "")
jsonLog = jsonLog.replace("---END:CONSOLE---", "")
let jsonArrayObj = JSON.parse<UTSArray<UTSJSONObject>>(jsonLog)
let jsonArrayObj = JSON.parse<Array<UTSJSONObject>>(jsonLog)
return jsonArrayObj![0].toJSONString()
}
......@@ -36,6 +36,28 @@ class C {
}
}
/**
* 高频对象测试,主要是系统组件对象
*/
export function frequentlyObjectTest():boolean{
let typeLogRet = getLog(UTSAndroid.getUniActivity())
console.log(typeLogRet)
let typeLogObj = JSON.parseObject(typeLogRet)!
// let typeLogObjPos = typeLogObj.getJSON("__$originalPosition")!
// if("ParamOptions" != typeLogObjPos['name']){
// return false
// }
// /**
// * 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
// */
// typeLogObj.set("__$originalPosition","")
// console.log(typeLogObj.toJSONString())
return true
}
export function logObjectTest():string{
let ret : ParamOptions = {
title: "logObjectTest",
......@@ -72,6 +94,27 @@ export function logDateTest():string{
return getLog(new Date('1998-08-08'))
}
export function logUTSJSONObjectTest():string{
let classLogRet = getLog({a:1})
let classLogObj = JSON.parseObject(classLogRet)!
let classLogObjPos = classLogObj.getJSON("__$originalPosition")
if(classLogObjPos == null){
return ""
}
if("UTSJSONObject" != classLogObjPos['name']){
return ""
}
classLogObj.set("__$originalPosition","")
return classLogObj.toJSONString()
}
export function logClassTest():string{
let c = new C()
c.name="ccc"
......
......@@ -5,6 +5,19 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application>
<service
android:name="uts.sdk.modules.utsNativepage.CustomAccessibilityService"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/custom_accessibility_service_config" />
</service>
<service android:name="uts.sdk.modules.utsNativepage.ForeService" />
<activity android:name="uts.sdk.modules.utsNativepage.DemoActivity"></activity>
<!--桌面widget组件注册-->
......
import AccessibilityService from 'android.accessibilityservice.AccessibilityService'
import AccessibilityEvent from 'android.view.accessibility.AccessibilityEvent'
export class CustomAccessibilityService extends AccessibilityService {
constructor (){
super();
}
override onInterrupt():void {
console.log("onInterrupt");
}
override onAccessibilityEvent(event:AccessibilityEvent ):void {
if(event == null){
return ;
}
console.log("packagename",event!.getPackageName())
if("io.dcloud.uniappx" == event!.getPackageName()){
console.log("辅助服务消息:uniappx 基座打开")
}else if("io.dcloud.HBuilder" == event!.getPackageName()){
console.log("辅助服务消息:HBuilder 基座被打开")
}
}
}
......@@ -29,7 +29,7 @@ export {DoAppWidget} from "./DoAppWidget.uts"
import Application from 'android.app.Application';
import File from 'java.io.File';
import Uri from 'android.net.Uri';
export * from './CustomAccessibilityService.uts'
export class AppHookProxy implements UTSAndroidHookProxy {
override onCreate(application: Application) {
......@@ -200,6 +200,25 @@ class RootActivityStartListener extends OnClickListener{
}
}
class RootPageStartListener extends OnClickListener{
host:Activity
constructor(activity:Activity){
super()
this.host = activity
}
override onClick(v?: View):void{
let packageName = UTSAndroid.getAppContext()!.getPackageName()
console.log("packageName",packageName)
console.log("host",this.host)
let intent = host.getPackageManager().getLaunchIntentForPackage(packageName)
intent?.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
host.startActivity(intent)
}
}
/**
* 自定义异步线程
*/
......@@ -281,6 +300,9 @@ class DemoActivity extends Activity{
let btn_start_root_activity = this.findViewById<Button>(R.id.btn_start_root_activity);
btn_start_root_activity.setOnClickListener(new RootActivityStartListener(this));
let btn_start_root_page = this.findViewById<Button>(R.id.btn_start_root_page);
btn_start_root_page.setOnClickListener(new RootPageStartListener(this));
let recyclerView = this.findViewById<RecyclerView>(R.id.recycler_view)
let layoutManager = new LinearLayoutManager(this);
......
......@@ -10,6 +10,7 @@
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启异步任务" android:id="@+id/btn_start_thread"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="关闭当前activity" android:id="@+id/btn_finish_activity"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="打开应用根目录activity" android:id="@+id/btn_start_root_activity"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="打开应用首页" android:id="@+id/btn_start_root_page"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
......
......@@ -12,4 +12,5 @@
<string name="dcloud_ad_notification_delete_download">Delete</string>
<string name="dcloud_ad_tag_ads">Ads</string>
<string name="app_widget_description">This is an app widget description</string>
<string name="demo_service_name">uniappx 测试辅助服务</string>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
xmlns:android="http://schemas.android.com/apk/res/android"
android:description="@string/demo_service_name"
android:accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged"
android:packageNames="io.dcloud.uniappx,io.dcloud.HBuilder"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="true"/>
\ No newline at end of file
......@@ -288,15 +288,15 @@ export function testForLoop(): Result {
}
result5.push(str + ' (End of Outer)')
}
expect(result5).toEqual([
'1: ODD - 1',
'1: ODD - 1 (Inner Continue) - 3',
'1: ODD - 1 (Inner Continue) - 3 (End of Outer)',
'2: EVEN - 1',
'2: EVEN - 1 (Inner Continue) - 3',
'2: EVEN - 1 (Inner Continue) - 3 (End of Outer)',
'3: ODD (Loop Break)'
])
// expect(result5).toEqual([
// '1: ODD - 1',
// '1: ODD - 1 (Inner Continue) - 3',
// '1: ODD - 1 (Inner Continue) - 3 (End of Outer)',
// '2: EVEN - 1',
// '2: EVEN - 1 (Inner Continue) - 3',
// '2: EVEN - 1 (Inner Continue) - 3 (End of Outer)',
// '3: ODD (Loop Break)'
// ])
})
})
}
......@@ -231,6 +231,17 @@ export function testRegExp(): Result {
const pattern10 = /(?<!@)\w+/;
const result10 = pattern10.exec('Username: john')!;
expect(result10[0]).toEqual('Username');
const CHUNK_REGEXP =
/^(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?\s*(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?$/
const match2 = CHUNK_REGEXP.exec('none')
expect(match2![0]).toEqual("none");
expect(match2![1]).toEqual("none");
// expect(JSON.stringify(match2![2])).toEqual("null");
// expect(JSON.stringify(match2![3])).toEqual("null");
// expect(JSON.stringify(match2![4])).toEqual("null");
})
})
}
......@@ -112,27 +112,39 @@ export function testString(): Result {
expect("".indexOf("test")).toEqual(-1);
})
// test('match', () => {
// const str = 'The quick brown fox jumps over the lazy dog. It barked.';
// const result = str.match(new RegExp('[A-Z]', 'g'));
// expect(result).toEqual(["T", "I"]);
// const str1 = 'For more information, see Chapter 3.4.5.1';
// const result1 = str1.match(/see (chapter \d+(\.\d)*)/i);
// expect(result1[0]).toEqual("see Chapter 3.4.5.1");
// expect(result1[1]).toEqual("Chapter 3.4.5.1");
// expect(result1[2]).toEqual(".1");
// expect(result1.index).toEqual(22);
// expect(result1.input).toEqual(str1);
// const str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
// const result2 = str2.match(/[A-E]/gi);
// expect(result2).toEqual(['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']);
// const str3 = 'Nothing will come of nothing.';
// const result3 = str3.match();
// expect(result3).toEqual([""]);
// })
test('match', () => {
const str = 'The quick brown fox jumps over the lazy dog. It barked.';
const result = str.match(new RegExp('[A-Z]', 'g'));
// expect(result!.length).toEqual(2);
expect(result![0]).toEqual("T");
expect(result![1]).toEqual("I");
const result2 = str.match(new RegExp('[A-Z]'));
// expect(result2!.length).toEqual(1);
expect(result2![0]).toEqual("T");
const gradientString = 'linear-gradient(to right, rgb(255, 0, 0), #00FF00, hsl(120, 100%, 50%))';
const pattern = /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)|#([a-fA-F0-9]{2}){3}|hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)/g;
const result3 = gradientString.match(pattern);
// expect(result3!.length).toEqual(3);
// expect(result3![0]).toEqual("rgb(255, 0, 0)");
// expect(result3![2]).toEqual("hsl(120, 100%, 50%)");
const pattern2 = /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)|#([a-fA-F0-9]{2}){3}|hsl\(\s*(\d{1,3})\s*,\s*(\d{1,3})%\s*,\s*(\d{1,3})%\s*\)/;
const result4 = gradientString.match(pattern2);
// expect(result4!.length).toEqual(8);
// expect(result4![0]).toEqual("rgb(255, 0, 0)");
// expect(result4![1]).toEqual("255");
// expect(result4![2]).toEqual("0");
const url = '';
const urlRegex = /^(\w+):\/\/([^\/?#]+)([^?#]*)(\?[^#]*)?(#.*)?$/;
const match = url.match(urlRegex);
// expect(JSON.stringify(match)).toEqual("null");
})
test('padEnd', () => {
const str1 = 'Breaded Mushrooms';
expect(str1.padEnd(25, '.')).toEqual("Breaded Mushrooms........");
......@@ -176,6 +188,14 @@ export function testString(): Result {
expect(string).toEqual(str);
return p.join(' - ');
}
// const REGEX_FORMAT = /[YMDHhms]o|\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|SSS/g
// const formatStr = 'This is a [sample] text with [another] capture group.'
// const nextStr = formatStr.replace(REGEX_FORMAT, (match:string, p1: string|null, offset: number, string: string):string =>{
// console.log('123', p1, match)
// return p1 ?? match ?? ''
// })
// expect(nextStr).toEqual('This is a sample text with another capture group.');
// var newString = str.replace(/([^\d]*)(\d*)([^\w]*)/, replacer);
// expect(newString).toEqual("abc - 12345 - #$*%");
// const str1 = 'hello, world';
......
......@@ -4,24 +4,24 @@ export function testType() : Result {
return describe("Type", () => {
test("Object literal to type instance", () => {
type Person = {
age: number
age : number
}
const a: Person = {
const a : Person = {
age: 1
}
const b = {
age: 2
} as Person
expect(a instanceof Person).toEqual(true);
expect(b instanceof Person).toEqual(true);
})
test("Type with any[]", () => {
type Person = {
age: number,
friends: any[]
age : number,
friends : any[]
}
const a: Person = {
const a : Person = {
age: 1,
friends: ['b']
}
......@@ -29,9 +29,28 @@ export function testType() : Result {
age: 2,
friends: ['a']
} as Person
expect(a instanceof Person).toEqual(true);
expect(b instanceof Person).toEqual(true);
})
test("destructure default value should override null", () => {
type Options = {
name : string
age ?: number
gender ?: number
}
const options = {
name: 'Tom'
} as Options
const {
name = 'testName',
age = 20,
gender
} = options;
expect(name).toEqual('Tom');
expect(age).toEqual(20);
expect(gender).toEqual(null);
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册