Add copyright statement
This commit is contained in:
parent
1c65017045
commit
4907960d47
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
</project>
|
||||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import relationalStore from '@ohos.data.relationalStore';
|
||||
import Student from './student'
|
||||
import Course from './course'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export default class ThreeTable {
|
||||
sid: number; // 学生ID
|
||||
sname: string; // 姓名
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export default class Course {
|
||||
cid: number; // 课程ID
|
||||
cname: string; // 课程名字
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export default class Sc {
|
||||
sid: number | null; // 学生ID
|
||||
cid: number | null; // 课程ID
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export default class Student {
|
||||
sid: number; // 学生ID
|
||||
sname: string; // 姓名
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import relationalStore from '@ohos.data.relationalStore'; // 导入模块
|
||||
import Student from '../common/rdbUtils/student'
|
||||
import RdbUtils from '../common/rdbUtils/RdbUtils';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import relationalStore from '@ohos.data.relationalStore'; // 导入模块
|
||||
import Student from '../common/rdbUtils/student'
|
||||
import RdbUtils from '../common/rdbUtils/RdbUtils';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import relationalStore from '@ohos.data.relationalStore'; // 导入模块
|
||||
import Student from '../common/rdbUtils/student'
|
||||
import RdbUtils from '../common/rdbUtils/RdbUtils';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
@Entry
|
||||
@Component
|
||||
struct Page {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* 字体大小(大)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { cp } from '../../utils/algorithm/customPath'
|
||||
import { showToast } from '../../utils/functions/showToast'
|
||||
import Node from '../dataStruct/class/Node'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import Node from '../dataStruct/class/Node'
|
||||
|
||||
@CustomDialog
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { RouteData } from './RouteData'
|
||||
|
||||
export class Data{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export default class Edge {
|
||||
id: number; // “连接对象编号”:连接线唯一标识,通常是自然数编号
|
||||
node1: number; // “节点对象1编号”
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
@Observed
|
||||
export default class Node {
|
||||
id: number; // “节点编号”:唯一标识一个节点,通常是自然数编号
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { StepData } from './StepData'
|
||||
|
||||
export class PathData{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { PathData } from './PathData'
|
||||
|
||||
export class RouteData{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export class StepData{
|
||||
step:string
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
interface urbanTransitionCost {
|
||||
distance: number,
|
||||
time: number
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export interface nodeInfo {
|
||||
to: number,
|
||||
weight: number
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export interface solutionData{
|
||||
count?:number
|
||||
time:string
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SMALL_SIZE_FONT } from '../common/CommonConstant'
|
||||
import { setNodeCount } from '../common/customDialog/SetNodeCount'
|
||||
import Node from '../common/dataStruct/class/Node'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { DRAW_NODE_SIZE, NORMAL_CONTEXT, SELECTED_CONTEXT } from '../common/CommonConstant'
|
||||
import Edge from '../common/dataStruct/class/Edge'
|
||||
import Node from '../common/dataStruct/class/Node'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { BIG_SIZE_FONT , SMALL_SIZE_FONT } from '../common/CommonConstant'
|
||||
import { setNodeNameDialog } from '../common/customDialog/SetNodeNameDialog'
|
||||
import Edge from '../common/dataStruct/class/Edge'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { CityInfo } from '../common/dataStruct/interface/CityInfo';
|
||||
import { X_CENTER, Y_CENTER } from '../common/CommonConstant';
|
||||
import Edge from '../common/dataStruct/class/Edge';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import hilog from '@ohos.hilog';
|
||||
|
||||
const DOMAIN = 0
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { cp } from "./customPath";
|
||||
import Node from '../../common/dataStruct/class/Node';
|
||||
import Edge from '../../common/dataStruct/class/Edge';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { showToast } from "../functions/showToast"
|
||||
import Node from '../../common/dataStruct/class/Node'
|
||||
import Edge from '../../common/dataStruct/class/Edge'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { CITY } from '../../common/CommonConstant';
|
||||
import { CityInfo } from '../../common/dataStruct/interface/CityInfo';
|
||||
import { Logger } from '../Logger';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { Graph, nodeInfo } from '../../common/dataStruct/interface/Graph';
|
||||
|
||||
export function deepCopyGraph(graph: Graph): Graph {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export function degreesToRadians(degrees: number): number {
|
||||
return degrees * Math.PI / 180;
|
||||
}
|
||||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { DRAW_NODE_SIZE, NORMAL_CONTEXT, SELECTED_CONTEXT } from '../../common/CommonConstant'
|
||||
import Edge from '../../common/dataStruct/class/Edge'
|
||||
import { cp } from '../algorithm/customPath'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import Node from '../../common/dataStruct/class/Node'
|
||||
import { BOTTOM_RIGHT_X, BOTTOM_RIGHT_Y, DRAW_NODE_SIZE, TOP_LEFT_X, TOP_LEFT_Y,
|
||||
X_CENTER,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { CITY, KEY } from '../../common/CommonConstant'
|
||||
import http from '@ohos.net.http'
|
||||
import { Logger } from '../Logger'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import promptAction from '@ohos.promptAction'
|
||||
|
||||
export let showToast = (message:string,duration:number = 2000)=>{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase } from "./SimBase"
|
||||
|
||||
@Observed
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimPacket } from './OtherSimObjects';
|
||||
|
||||
// 路由表和mac表项
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export class TopMenu {
|
||||
title: string
|
||||
menuItemArr: TopMenuItem[] | undefined
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase } from '../classes/SimBase'
|
||||
|
||||
interface SimClickObj {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase, Table } from "../classes/SimBase"
|
||||
import { SimConnect, SimPacket } from '../classes/OtherSimObjects'
|
||||
import promptAction from '@ohos.promptAction'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import { SimConnect, SimHost, SimHub, SimRouter, SimSwitch } from '../classes/OtherSimObjects'
|
||||
import { SimBase } from '../classes/SimBase'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase, Table } from '../classes/SimBase'
|
||||
|
||||
@Component
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import { SimBase } from '../classes/SimBase'
|
||||
import { SimConnect, SimPacket } from '../classes/OtherSimObjects'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase } from "../classes/SimBase"
|
||||
|
||||
function ValidateIPAddress(ipAddress: string): boolean {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { TopMenuBar } from "../components/TopMenuBar" // 顶部功能栏
|
||||
import { MiddleContent } from "../components/MiddleContent" // 中间控制区
|
||||
import { BottomMenuBar } from "../components/ButtomMenuBar" // 底部选择栏
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimHost } from "./OtherSimObjects"
|
||||
|
||||
// 应用层数据包(解封包)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase } from "./SimBase"
|
||||
import { AppData, IPData, MACData, TransData, macData, ipData, transData, appData } from "../classes/Datas"
|
||||
import { updatePacketLog } from "../functions/functions"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimPacket } from "./OtherSimObjects";
|
||||
import { updatePacketLog } from "../functions/functions"
|
||||
import { AppData, IPData, MACData, TransData, macData, ipData, transData, appData } from "../classes/Datas"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
export class TopMenu {
|
||||
title: string
|
||||
menuItemArr: TopMenuItem[] | undefined
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase } from "../classes/SimBase"
|
||||
|
||||
interface SimClickObj {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase, Table } from "../classes/SimBase"
|
||||
import { SimConnect, SimPacket } from "../classes/OtherSimObjects"
|
||||
import promptAction from "@ohos.promptAction"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import promptAction from "@ohos.promptAction"
|
||||
import { SimPacket, SimConnect, SimHost, SimHub, SimRouter, SimSwitch } from "../classes/OtherSimObjects"
|
||||
import { SimBase } from "../classes/SimBase"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimPacket } from '../classes/OtherSimObjects'
|
||||
import { SimBase, Table } from '../classes/SimBase'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import promptAction from "@ohos.promptAction";
|
||||
import { SimBase } from "../classes/SimBase"
|
||||
import { SimConnect, SimPacket } from "../classes/OtherSimObjects"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { SimBase } from "../classes/SimBase"
|
||||
|
||||
function ValidateIPAddress(ipAddress: string): boolean {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
Copyright 2026 LI Meng
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { TopMenuBar } from "../components/TopMenuBar" // 顶部功能栏
|
||||
import { MiddleContent } from "../components/MiddleContent" // 中间控制区
|
||||
import { BottomMenuBar } from "../components/ButtomMenuBar" // 底部选择栏
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,122 @@
|
|||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
ColumnLimit: 120
|
||||
TabWidth: 4
|
||||
IndentWidth: 4
|
||||
UseTab: Never
|
||||
AccessModifierOffset: -4
|
||||
ContinuationIndentWidth: 4
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: false
|
||||
IndentGotoLabels: true
|
||||
IndentWrappedFunctionNames: false
|
||||
SortUsingDeclarations: false
|
||||
NamespaceIndentation: None
|
||||
IndentAccessModifiers: false
|
||||
IndentPPDirectives: None
|
||||
PPIndentWidth: -1
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInAngles: Never
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
AlignTrailingComments: true
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
PointerAlignment: Right
|
||||
QualifierAlignment: Leave
|
||||
ReferenceAlignment: Pointer
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeParens: ControlStatements
|
||||
DerivePointerAlignment: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: true
|
||||
InsertBraces: false
|
||||
IndentExternBlock: NoIndent
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
ReflowComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
BreakBeforeConceptDeclarations: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
BitFieldColonSpacing: Both
|
||||
BreakBeforeBinaryOperators: None
|
||||
PackConstructorInitializers: BinPack
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
CompactNamespaces: false
|
||||
Cpp11BracedListStyle: true
|
||||
FixNamespaceComments: true
|
||||
DisableFormat: false
|
||||
RemoveBracesLLVM: false
|
||||
RemoveSemicolon: false
|
||||
SortIncludes: Never
|
||||
Standard: Auto
|
||||
RequiresClausePosition: OwnLine
|
||||
RemoveParentheses: Leave
|
||||
IncludeBlocks: Preserve
|
||||
MaxEmptyLinesToKeep: 2
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
SeparateDefinitionBlocks: Leave
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="EMPTY_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$/../.." />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
<div style="text-align: center;font-size: xxx-large" >Hypium</div>
|
||||
<div style="text-align: center">A unit test framework for OpenHarmonyOS application</div>
|
||||
|
||||
## Hypium是什么?
|
||||
***
|
||||
- Hypium是OpenHarmony上的测试框架,提供测试用例编写、执行、结果显示能力,用于OpenHarmony系统应用接口以及应用界面测试。
|
||||
- Hypium结构化模型:hypium工程主要由List.test.js与TestCase.test.js组成。
|
||||
```
|
||||
rootProject // Hypium工程根目录
|
||||
├── moduleA
|
||||
│ ├── src
|
||||
│ ├── main // 被测试应用目录
|
||||
│ ├── ohosTest // 测试用例目录
|
||||
│ ├── js/ets
|
||||
│ └── test
|
||||
│ └── List.test.js // 测试用例加载脚本,ets目录下为.ets后缀
|
||||
│ └── TestCase.test.js // 测试用例脚本,ets目录下为.ets后缀
|
||||
└── moduleB
|
||||
...
|
||||
│ └── List.test.js // 测试用例加载脚本,ets目录下为.ets后缀
|
||||
│ └── TestCase.test.js // 测试用例脚本,ets目录下为.ets后缀
|
||||
```
|
||||
|
||||
## 安装使用
|
||||
***
|
||||
- 在DevEco Studio内使用Hypium
|
||||
- 工程级package.json内配置:
|
||||
```json
|
||||
"dependencies": {
|
||||
"@ohos/hypium": "1.0.7"
|
||||
}
|
||||
```
|
||||
注:
|
||||
hypium服务于OpenHarmonyOS应用对外接口测试、系统对外接口测试(SDK中接口),完成HAP自动化测试。详细指导:
|
||||
[Deveco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio)
|
||||
|
||||
#### 通用语法
|
||||
|
||||
- 测试用例采用业内通用语法,describe代表一个测试套, it代表一条用例。
|
||||
|
||||
| No. | API | 功能说明 |
|
||||
| --- | ---------- | ---------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1 | describe | 定义一个测试套,支持两个参数:测试套名称和测试套函数 |
|
||||
| 2 | beforeAll | 在测试套内定义一个预置条件,在所有测试用例开始前执行且仅执行一次,支持一个参数:预置动作函数 |
|
||||
| 3 | beforeEach | 在测试套内定义一个单元预置条件,在每条测试用例开始前执行,执行次数与it定义的测试用例数一致,支持一个参数:预置动作函数 |
|
||||
| 4 | afterEach | 在测试套内定义一个单元清理条件,在每条测试用例结束后执行,执行次数与it定义的测试用例数一致,支持一个参数:清理动作函数 |
|
||||
| 5 | afterAll | 在测试套内定义一个清理条件,在所有测试用例结束后执行且仅执行一次,支持一个参数:清理动作函数 |
|
||||
| 6 | it | 定义一条测试用例,支持三个参数:用例名称,过滤参数和用例函数 |
|
||||
| 7 | expect | 支持bool类型判断等多种断言方法 |
|
||||
|
||||
#### 断言库
|
||||
|
||||
- 示例代码:
|
||||
|
||||
```javascript
|
||||
expect(${actualvalue}).assertX(${expectvalue})
|
||||
```
|
||||
|
||||
- 断言功能列表:
|
||||
|
||||
| No. | API | 功能说明 |
|
||||
| :--- | :------------------------------- | ---------------------------------------------------------------------------------------------- |
|
||||
| 1 | assertClose | 检验actualvalue和expectvalue(0)的接近程度是否是expectValue(1) |
|
||||
| 2 | assertContain | 检验actualvalue中是否包含expectvalue |
|
||||
| 3 | assertDeepEquals | @since1.0.4 检验actualvalue和expectvalue(0)是否是同一个对象 |
|
||||
| 4 | assertEqual | 检验actualvalue是否等于expectvalue[0] |
|
||||
| 5 | assertFail | 抛出一个错误 |
|
||||
| 6 | assertFalse | 检验actualvalue是否是false |
|
||||
| 7 | assertTrue | 检验actualvalue是否是true |
|
||||
| 8 | assertInstanceOf | 检验actualvalue是否是expectvalue类型 |
|
||||
| 9 | assertLarger | 检验actualvalue是否大于expectvalue |
|
||||
| 10 | assertLess | 检验actualvalue是否小于expectvalue |
|
||||
| 11 | assertNaN | @since1.0.4 检验actualvalue是否是NaN |
|
||||
| 12 | assertNegUnlimited | @since1.0.4 检验actualvalue是否等于Number.NEGATIVE_INFINITY |
|
||||
| 13 | assertNull | 检验actualvalue是否是null |
|
||||
| 14 | assertPosUnlimited | @since1.0.4 检验actualvalue是否等于Number.POSITIVE_INFINITY |
|
||||
| 15 | assertPromiseIsPending | @since1.0.4 检验actualvalue是否处于Pending状态【actualvalue为promse对象】 |
|
||||
| 16 | assertPromiseIsRejected | @since1.0.4 检验actualvalue是否处于Rejected状态【同15】 |
|
||||
| 17 | assertPromiseIsRejectedWith | @since1.0.4 检验actualvalue是否处于Rejected状态,并且比较执行的结果值【同15】 |
|
||||
| 18 | assertPromiseIsRejectedWithError | @since1.0.4 检验actualvalue是否处于Rejected状态并有异常,同时比较异常的类型和message值【同15】 |
|
||||
| 19 | assertPromiseIsResolved | @since1.0.4 检验actualvalue是否处于Resolved状态【同15】 |
|
||||
| 20 | assertPromiseIsResolvedWith | @since1.0.4 检验actualvalue是否处于Resolved状态,并且比较执行的结果值【同15】 |
|
||||
| 21 | assertThrowError | 检验actualvalue抛出Error内容是否是expectValue |
|
||||
| 22 | assertUndefined | 检验actualvalue是否是undefined |
|
||||
| 23 | not | @since1.0.4 断言结果取反 |
|
||||
|
||||
|
||||
示例代码:
|
||||
|
||||
```javascript
|
||||
import { describe, it, expect } from '@ohos/hypium';
|
||||
|
||||
export default async function assertCloseTest() {
|
||||
describe('assertClose', function () {
|
||||
it('assertClose_success', 0, function () {
|
||||
let a = 100;
|
||||
let b = 0.1;
|
||||
expect(a).assertClose(99, b);
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
#### 公共系统能力
|
||||
|
||||
| No. | API | 功能描述 |
|
||||
| ---- | ------------------------------------------------------- | ------------------------------------------------------------ |
|
||||
| 1 | existKeyword(keyword: string, timeout: number): boolean | @since1.0.3 hilog日志中查找指定字段是否存在,keyword是待查找关键字,timeout为设置的查找时间 |
|
||||
| 2 | actionStart(tag: string): void | @since1.0.3 cmd窗口输出开始tag |
|
||||
| 3 | actionEnd(tag: string): void | @since1.0.3 cmd窗口输出结束tag |
|
||||
|
||||
示例代码:
|
||||
|
||||
```javascript
|
||||
import { describe, it, expect, SysTestKit} from '@ohos/hypium';
|
||||
|
||||
export default function existKeywordTest() {
|
||||
describe('existKeywordTest', function () {
|
||||
it('existKeyword',DEFAULT, async function () {
|
||||
console.info("HelloTest");
|
||||
let isExist = await SysTestKit.existKeyword('HelloTest');
|
||||
console.info('isExist ------>' + isExist);
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
```javascript
|
||||
import { describe, it, expect, SysTestKit} from '@ohos/hypium';
|
||||
|
||||
export default function actionTest() {
|
||||
describe('actionTest', function () {
|
||||
it('existKeyword',DEFAULT, async function () {
|
||||
let tag = '[MyTest]';
|
||||
SysTestKit.actionStart(tag);
|
||||
//do something
|
||||
SysTestKit.actionEnd(tag);
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
#### 专项能力
|
||||
|
||||
- 测试用例属性筛选能力:hypium支持根据用例属性筛选执行指定测试用例,使用方式是先在测试用例上标记用例属性后,再在测试应用的启动shell命令后新增" -s ${Key} ${Value}"。
|
||||
|
||||
| Key | 含义说明 | Value取值范围 |
|
||||
| -------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| level | 用例级别 | "0","1","2","3","4", 例如:-s level 1 |
|
||||
| size | 用例粒度 | "small","medium","large", 例如:-s size small |
|
||||
| testType | 用例测试类型 | "function","performance","power","reliability","security","global","compatibility","user","standard","safety","resilience", 例如:-s testType function |
|
||||
|
||||
示例代码
|
||||
|
||||
```javascript
|
||||
import { describe, it, expect, TestType, Size, Level } from '@ohos/hypium';
|
||||
|
||||
export default function attributeTest() {
|
||||
describe('attributeTest', function () {
|
||||
it("testAttributeIt", TestType.FUNCTION | Size.SMALLTEST | Level.LEVEL0, function () {
|
||||
console.info('Hello Test');
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
示例命令
|
||||
```shell
|
||||
XX -s level 1 -s size small -s testType function
|
||||
```
|
||||
该命令的作用是:筛选测试应用中同时满足a)用例级别是1 b)用例粒度是small c)用例测试类型是function 三个条件的用例执行。
|
||||
|
||||
- 测试套/测试用例名称筛选能力(测试套与用例名称用“#”号连接,多个用“,”英文逗号分隔)
|
||||
|
||||
| Key | 含义说明 | Value取值范围 |
|
||||
| -------- | ----------------------- | -------------------------------------------------------------------------------------------- |
|
||||
| class | 指定要执行的测试套&用例 | ${describeName}#${itName},${describeName} , 例如:-s class attributeTest#testAttributeIt |
|
||||
| notClass | 指定不执行的测试套&用例 | ${describeName}#${itName},${describeName} , 例如:-s notClass attributeTest#testAttributeIt |
|
||||
|
||||
示例命令
|
||||
```shell
|
||||
XX -s class attributeTest#testAttributeIt,abilityTest#testAbilityIt
|
||||
```
|
||||
该命令的作用是:筛选测试应用中attributeTest测试套下的testAttributeIt测试用例,abilityTest测试套下的testAbilityIt测试用例,只执行这两条用例。
|
||||
|
||||
- 其他能力
|
||||
|
||||
| 能力项 | Key | 含义说明 | Value取值范围 |
|
||||
| ------------ | ------- | ---------------------------- | ---------------------------------------------- |
|
||||
| 随机执行能力 | random | 测试套&测试用例随机执行 | true, 不传参默认为false, 例如:-s random true |
|
||||
| 空跑能力 | dryRun | 显示要执行的测试用例信息全集 | true , 不传参默认为false,例如:-s dryRun true |
|
||||
| 异步超时能力 | timeout | 异步用例执行的超时时间 | 正整数 , 单位ms,例如:-s timeout 5000 |
|
||||
|
||||
##### 约束限制
|
||||
随机执行能力和空跑能力从npm包1.0.3版本开始支持
|
||||
|
||||
#### Mock能力
|
||||
|
||||
##### 约束限制
|
||||
|
||||
单元测试框架Mock能力从npm包[1.0.1版本](https://repo.harmonyos.com/#/cn/application/atomService/@ohos%2Fhypium/v/1.0.1)开始支持
|
||||
|
||||
## 约束
|
||||
|
||||
***
|
||||
本模块首批接口从OpenHarmony SDK API version 8开始支持。
|
||||
|
||||
## Hypium开放能力隐私声明
|
||||
|
||||
- 我们如何收集和使用您的个人信息
|
||||
您在使用集成了Hypium开放能力的测试应用时,Hypium不会处理您的个人信息。
|
||||
- SDK处理的个人信息
|
||||
不涉及。
|
||||
- SDK集成第三方服务声明
|
||||
不涉及。
|
||||
- SDK数据安全保护
|
||||
不涉及。
|
||||
- SDK版本更新声明
|
||||
为了向您提供最新的服务,我们会不时更新Hypium版本。我们强烈建议开发者集成使用最新版本的Hypium。
|
||||
|
||||
140
fenxingshuing/fenxingshu/oh_modules/.ohpm/oh_modules/@ohos/hypium/index.d.ts
vendored
Normal file
140
fenxingshuing/fenxingshu/oh_modules/.ohpm/oh_modules/@ohos/hypium/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const DEFAULT = 0B0000
|
||||
|
||||
export const when: when;
|
||||
|
||||
export enum TestType {
|
||||
FUNCTION = 0B1,
|
||||
PERFORMANCE = 0B1 << 1,
|
||||
POWER = 0B1 << 2,
|
||||
RELIABILITY = 0B1 << 3,
|
||||
SECURITY = 0B1 << 4,
|
||||
GLOBAL = 0B1 << 5,
|
||||
COMPATIBILITY = 0B1 << 6,
|
||||
USER = 0B1 << 7,
|
||||
STANDARD = 0B1 << 8,
|
||||
SAFETY = 0B1 << 9,
|
||||
RESILIENCE = 0B1 << 10
|
||||
}
|
||||
|
||||
export enum Size {
|
||||
SMALLTEST = 0B1 << 16,
|
||||
MEDIUMTEST = 0B1 << 17,
|
||||
LARGETEST = 0B1 << 18
|
||||
}
|
||||
|
||||
export enum Level {
|
||||
LEVEL0 = 0B1 << 24,
|
||||
LEVEL1 = 0B1 << 25,
|
||||
LEVEL2 = 0B1 << 26,
|
||||
LEVEL3 = 0B1 << 27,
|
||||
LEVEL4 = 0B1 << 28
|
||||
}
|
||||
|
||||
export function describe(testSuiteName: string, callback: Function): void
|
||||
|
||||
export function beforeItSpecified(testCaseNames: Array<string> | string, callback: Function): void
|
||||
|
||||
export function afterItSpecified(testCaseNames: Array<string> | string, callback: Function): void
|
||||
|
||||
export function beforeEach(callback: Function): void
|
||||
|
||||
export function afterEach(callback: Function): void
|
||||
|
||||
export function beforeAll(callback: Function): void
|
||||
|
||||
export function afterAll(callback: Function): void
|
||||
|
||||
export function it(testCaseName: string, attribute: (TestType | Size | Level), callback: Function)
|
||||
|
||||
export interface Assert {
|
||||
assertClose(expectValue: number, precision: number): void
|
||||
assertContain(expectValue: any): void
|
||||
assertEqual(expectValue: any): void
|
||||
assertFail(): void
|
||||
assertFalse(): void
|
||||
assertTrue(): void
|
||||
assertInstanceOf(expectValue: string): void
|
||||
assertLarger(expectValue: number): void
|
||||
assertLess(expectValue: number): void
|
||||
assertNull(): void
|
||||
assertThrowError(expectValue: string): void
|
||||
assertUndefined(): void
|
||||
assertLargerOrEqual(expectValue: number):void
|
||||
assertLessOrEqual(expectValue: number):void
|
||||
assertNaN():void
|
||||
assertNegUnlimited(): void
|
||||
assertPosUnlimited(): void
|
||||
not(): Assert;
|
||||
assertDeepEquals(expectValue: any):void
|
||||
assertPromiseIsPending(): void
|
||||
assertPromiseIsRejected(): void
|
||||
assertPromiseIsRejectedWith(expectValue?: any): void
|
||||
assertPromiseIsRejectedWithError(...expectValue): void
|
||||
assertPromiseIsResolved(): void
|
||||
assertPromiseIsResolvedWith(expectValue?: any): void
|
||||
}
|
||||
|
||||
export function expect(actualValue?: any): Assert
|
||||
|
||||
export class ArgumentMatchers {
|
||||
static any;
|
||||
static anyString;
|
||||
static anyBoolean;
|
||||
static anyNumber;
|
||||
static anyObj;
|
||||
static anyFunction;
|
||||
static matchRegexs(Regex: RegExp): void
|
||||
}
|
||||
|
||||
declare interface when {
|
||||
afterReturn(value: any): any
|
||||
afterReturnNothing(): undefined
|
||||
afterAction(action: any): any
|
||||
afterThrow(e_msg: string): string
|
||||
(argMatchers?: any): when;
|
||||
}
|
||||
|
||||
export interface VerificationMode {
|
||||
times(count: Number): void
|
||||
never(): void
|
||||
once(): void
|
||||
atLeast(count: Number): void
|
||||
atMost(count: Number): void
|
||||
}
|
||||
|
||||
export class MockKit {
|
||||
constructor()
|
||||
mockFunc(obj: Object, func: Function): Function
|
||||
mockObject(obj: Object): Object
|
||||
verify(methodName: String, argsArray: Array<any>): VerificationMode
|
||||
ignoreMock(obj: Object, func: Function): void
|
||||
clear(obj: Object): void
|
||||
clearAll(): void
|
||||
}
|
||||
|
||||
export class SysTestKit {
|
||||
static actionStart(tag: string): void
|
||||
static actionEnd(tag: string): void
|
||||
static existKeyword(keyword: string, timeout?: number): boolean
|
||||
}
|
||||
|
||||
export class Hypium {
|
||||
static setData(data: {[key: string]: any}): void
|
||||
static setTimeConfig(systemTime: any)
|
||||
static hypiumTest(abilityDelegator: any, abilityDelegatorArguments: any, testsuite: Function): void
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Core from './src/main/core';
|
||||
import {ConfigService} from './src/main/module/config/configService'
|
||||
import {DEFAULT, TestType, Size, Level, TAG} from './src/main/Constant';
|
||||
import DataDriver from './src/main/module/config/DataDriver';
|
||||
import ExpectExtend from './src/main/module/assert/ExpectExtend';
|
||||
import OhReport from './src/main/module/report/OhReport';
|
||||
import SysTestKit from './src/main/module/kit/SysTestKit';
|
||||
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, beforeItSpecified, afterItSpecified} from './src/main/interface';
|
||||
import {MockKit, when} from './src/main/module/mock/MockKit';
|
||||
import ArgumentMatchers from './src/main/module/mock/ArgumentMatchers';
|
||||
|
||||
class Hypium {
|
||||
static setData(data:Object) {
|
||||
const core:Core = Core.getInstance();
|
||||
const dataDriver:DataDriver = new DataDriver({data});
|
||||
core.addService('dataDriver', dataDriver);
|
||||
}
|
||||
|
||||
static setTimeConfig(systemTime:Object) {
|
||||
SysTestKit.systemTime = systemTime;
|
||||
}
|
||||
|
||||
static hypiumTest(abilityDelegator:Object, abilityDelegatorArguments:Object, testsuite:Function) {
|
||||
const core:Core = Core.getInstance();
|
||||
const expectExtend:ExpectExtend = new ExpectExtend({
|
||||
id: 'extend'
|
||||
});
|
||||
core.addService('expect', expectExtend);
|
||||
const ohReport:OhReport = new OhReport({
|
||||
delegator: abilityDelegator,
|
||||
abilityDelegatorArguments: abilityDelegatorArguments
|
||||
});
|
||||
SysTestKit.delegator = abilityDelegator;
|
||||
core.addService('report', ohReport);
|
||||
core.init();
|
||||
core.subscribeEvent('spec', ohReport);
|
||||
core.subscribeEvent('suite', ohReport);
|
||||
core.subscribeEvent('task', ohReport);
|
||||
const configService:ConfigService = core.getDefaultService('config');
|
||||
if (abilityDelegatorArguments !== null) {
|
||||
let testParameters:Object = configService.translateParams((abilityDelegatorArguments as Record<string, Object>).parameters);
|
||||
console.info(`${TAG}parameters:${JSON.stringify(testParameters)}`);
|
||||
configService.setConfig(testParameters);
|
||||
}
|
||||
testsuite();
|
||||
core.execute(abilityDelegator);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Hypium,
|
||||
Core,
|
||||
DEFAULT,
|
||||
TestType,
|
||||
Size,
|
||||
Level,
|
||||
DataDriver,
|
||||
ExpectExtend,
|
||||
OhReport,
|
||||
SysTestKit,
|
||||
describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, beforeItSpecified, afterItSpecified,
|
||||
MockKit, when,
|
||||
ArgumentMatchers
|
||||
};
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Core from './src/main/core';
|
||||
import {DEFAULT, TestType, Size, Level, TAG} from './src/main/Constant';
|
||||
import DataDriver from './src/main/module/config/DataDriver';
|
||||
import ExpectExtend from './src/main/module/assert/ExpectExtend';
|
||||
import OhReport from './src/main/module/report/OhReport';
|
||||
import SysTestKit from './src/main/module/kit/SysTestKit';
|
||||
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, beforeItSpecified, afterItSpecified} from './src/main/interface';
|
||||
import {MockKit, when} from './src/main/module/mock/MockKit';
|
||||
import ArgumentMatchers from './src/main/module/mock/ArgumentMatchers';
|
||||
|
||||
class Hypium {
|
||||
static setData(data) {
|
||||
const core = Core.getInstance();
|
||||
const dataDriver = new DataDriver({data});
|
||||
core.addService('dataDriver', dataDriver);
|
||||
}
|
||||
|
||||
static setTimeConfig(systemTime) {
|
||||
SysTestKit.systemTime = systemTime;
|
||||
}
|
||||
|
||||
static hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) {
|
||||
const core = Core.getInstance();
|
||||
const expectExtend = new ExpectExtend({
|
||||
'id': 'extend'
|
||||
});
|
||||
core.addService('expect', expectExtend);
|
||||
const ohReport = new OhReport({
|
||||
'delegator': abilityDelegator,
|
||||
'abilityDelegatorArguments': abilityDelegatorArguments
|
||||
});
|
||||
SysTestKit.delegator = abilityDelegator;
|
||||
core.addService('report', ohReport);
|
||||
core.init();
|
||||
core.subscribeEvent('spec', ohReport);
|
||||
core.subscribeEvent('suite', ohReport);
|
||||
core.subscribeEvent('task', ohReport);
|
||||
const configService = core.getDefaultService('config');
|
||||
if (abilityDelegatorArguments !== null) {
|
||||
let testParameters = configService.translateParams(abilityDelegatorArguments.parameters);
|
||||
console.info(`${TAG}parameters:${JSON.stringify(testParameters)}`);
|
||||
configService.setConfig(testParameters);
|
||||
}
|
||||
testsuite();
|
||||
core.execute(abilityDelegator);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Hypium,
|
||||
Core,
|
||||
DEFAULT,
|
||||
TestType,
|
||||
Size,
|
||||
Level,
|
||||
DataDriver,
|
||||
ExpectExtend,
|
||||
OhReport,
|
||||
SysTestKit,
|
||||
describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, beforeItSpecified, afterItSpecified,
|
||||
MockKit, when,
|
||||
ArgumentMatchers
|
||||
};
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "@ohos/hypium",
|
||||
"version": "1.0.11",
|
||||
"description": "A unit test framework for OpenHarmony application",
|
||||
"main": "index.js",
|
||||
"keywords": [],
|
||||
"author": "huawei",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* define the testcase type : TestType, Size , Level
|
||||
*/
|
||||
export const TAG = '[Hypium]';
|
||||
|
||||
export const DEFAULT = 0B0000;
|
||||
|
||||
export class TestType {
|
||||
static FUNCTION = 0B1;
|
||||
static PERFORMANCE = 0B1 << 1;
|
||||
static POWER = 0B1 << 2;
|
||||
static RELIABILITY = 0B1 << 3;
|
||||
static SECURITY = 0B1 << 4;
|
||||
static GLOBAL = 0B1 << 5;
|
||||
static COMPATIBILITY = 0B1 << 6;
|
||||
static USER = 0B1 << 7;
|
||||
static STANDARD = 0B1 << 8;
|
||||
static SAFETY = 0B1 << 9;
|
||||
static RESILIENCE = 0B1 << 10;
|
||||
}
|
||||
|
||||
export class Size {
|
||||
static SMALLTEST = 0B1 << 16;
|
||||
static MEDIUMTEST = 0B1 << 17;
|
||||
static LARGETEST = 0B1 << 18;
|
||||
}
|
||||
|
||||
export class Level {
|
||||
static LEVEL0 = 0B1 << 24;
|
||||
static LEVEL1 = 0B1 << 25;
|
||||
static LEVEL2 = 0B1 << 26;
|
||||
static LEVEL3 = 0B1 << 27;
|
||||
static LEVEL4 = 0B1 << 28;
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {SuiteService, SpecService, ExpectService, ReportService} from './service';
|
||||
import {ConfigService} from './module/config/configService';
|
||||
import {SpecEvent, TaskEvent, SuiteEvent} from './event';
|
||||
|
||||
/**
|
||||
* core service for execute testcase.
|
||||
*/
|
||||
class Core {
|
||||
static getInstance() {
|
||||
if (!this.instance) {
|
||||
this.instance = new Core();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.instance = null;
|
||||
this.services = {
|
||||
suite: {},
|
||||
spec: {},
|
||||
config: {},
|
||||
expect: {},
|
||||
log: {},
|
||||
report: {}
|
||||
|
||||
};
|
||||
this.events = {
|
||||
suite: {},
|
||||
spec: {},
|
||||
task: {}
|
||||
};
|
||||
}
|
||||
|
||||
addService(name, service) {
|
||||
let serviceObj = {};
|
||||
if (!this.services[name]) {
|
||||
this.services[name] = serviceObj;
|
||||
} else {
|
||||
serviceObj = this.services[name];
|
||||
}
|
||||
serviceObj[service.id] = service;
|
||||
}
|
||||
|
||||
getDefaultService(name) {
|
||||
return this.services[name].default;
|
||||
}
|
||||
|
||||
getServices(name) {
|
||||
return this.services[name];
|
||||
}
|
||||
|
||||
registerEvent(serviceName, event) {
|
||||
let eventObj = {};
|
||||
if (!this.events[serviceName]) {
|
||||
this.events[serviceName] = eventObj;
|
||||
} else {
|
||||
eventObj = this.events[serviceName];
|
||||
}
|
||||
eventObj[event.id] = event;
|
||||
}
|
||||
|
||||
unRegisterEvent(serviceName, eventID) {
|
||||
const eventObj = this.events[serviceName];
|
||||
if (eventObj) {
|
||||
delete eventObj[eventID];
|
||||
}
|
||||
}
|
||||
|
||||
subscribeEvent(serviceName, serviceObj) {
|
||||
const eventObj = this.events[serviceName];
|
||||
if (eventObj) {
|
||||
for (const attr in eventObj) {
|
||||
eventObj[attr]['subscribeEvent'](serviceObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fireEvents(serviceName, eventName) {
|
||||
const eventObj = this.events[serviceName];
|
||||
if (!eventObj) {
|
||||
return;
|
||||
}
|
||||
for (const attr in eventObj) {
|
||||
await eventObj[attr][eventName]();
|
||||
}
|
||||
}
|
||||
|
||||
addToGlobal(apis) {
|
||||
if (typeof globalThis !== 'undefined') {
|
||||
for (let api in apis) {
|
||||
globalThis[api] = apis[api];
|
||||
}
|
||||
}
|
||||
for (const api in apis) {
|
||||
this[api] = apis[api];
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
this.addService('suite', new SuiteService({id: 'default'}));
|
||||
this.addService('spec', new SpecService({id: 'default'}));
|
||||
this.addService('expect', new ExpectService({id: 'default'}));
|
||||
this.addService('report', new ReportService({id: 'default'}));
|
||||
this.addService('config', new ConfigService({id: 'default'}));
|
||||
this.registerEvent('task', new TaskEvent({id: 'default', coreContext: this}));
|
||||
this.registerEvent('suite', new SuiteEvent({id: 'default', coreContext: this}));
|
||||
this.registerEvent('spec', new SpecEvent({id: 'default', coreContext: this}));
|
||||
this.subscribeEvent('spec', this.getDefaultService('report'));
|
||||
this.subscribeEvent('suite', this.getDefaultService('report'));
|
||||
this.subscribeEvent('task', this.getDefaultService('report'));
|
||||
const context = this;
|
||||
for (const key in this.services) {
|
||||
const serviceObj = this.services[key];
|
||||
for (const serviceID in serviceObj) {
|
||||
const service = serviceObj[serviceID];
|
||||
service.init(context);
|
||||
|
||||
if (typeof service.apis !== 'function') {
|
||||
continue;
|
||||
}
|
||||
const apis = service.apis();
|
||||
if (apis) {
|
||||
this.addToGlobal(apis);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
execute(abilityDelegator) {
|
||||
const suiteService = this.getDefaultService('suite');
|
||||
const configService = this.getDefaultService('config');
|
||||
if (configService['dryRun'] === 'true') {
|
||||
(async function () {
|
||||
await suiteService.dryRun(abilityDelegator);
|
||||
})();
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
suiteService.execute();
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
export default Core;
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class SpecEvent {
|
||||
constructor(attr) {
|
||||
this.id = attr.id;
|
||||
this.coreContext = attr.context;
|
||||
this.eventMonitors = [];
|
||||
}
|
||||
|
||||
subscribeEvent(service) {
|
||||
this.eventMonitors.push(service);
|
||||
}
|
||||
|
||||
async specStart() {
|
||||
for (const monitor of this.eventMonitors) {
|
||||
await monitor['specStart']();
|
||||
}
|
||||
}
|
||||
|
||||
async specDone() {
|
||||
for (const monitor of this.eventMonitors) {
|
||||
await monitor['specDone']();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SuiteEvent {
|
||||
constructor(attr) {
|
||||
this.id = attr.id;
|
||||
this.suiteContext = attr.coreContext;
|
||||
this.eventMonitors = [];
|
||||
}
|
||||
|
||||
subscribeEvent(service) {
|
||||
this.eventMonitors.push(service);
|
||||
}
|
||||
|
||||
async suiteStart() {
|
||||
for (const monitor of this.eventMonitors) {
|
||||
await monitor['suiteStart']();
|
||||
}
|
||||
}
|
||||
|
||||
async suiteDone() {
|
||||
for (const monitor of this.eventMonitors) {
|
||||
await monitor['suiteDone']();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TaskEvent {
|
||||
constructor(attr) {
|
||||
this.id = attr.id;
|
||||
this.coreContext = attr.coreContext;
|
||||
this.eventMonitors = [];
|
||||
}
|
||||
|
||||
subscribeEvent(service) {
|
||||
this.eventMonitors.push(service);
|
||||
}
|
||||
|
||||
async taskStart() {
|
||||
for (const monitor of this.eventMonitors) {
|
||||
await monitor['taskStart']();
|
||||
}
|
||||
}
|
||||
|
||||
async taskDone() {
|
||||
for (const monitor of this.eventMonitors) {
|
||||
await monitor['taskDone']();
|
||||
}
|
||||
}
|
||||
|
||||
incorrectFormat() {
|
||||
for (const monitor of this.eventMonitors) {
|
||||
monitor['incorrectFormat']();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {SpecEvent, TaskEvent, SuiteEvent};
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Core from './core';
|
||||
|
||||
const core = Core.getInstance();
|
||||
|
||||
const describe = function (desc, func) {
|
||||
return Reflect.has(core, 'describe') ? core.describe(desc, func) : (desc, func) => { };
|
||||
};
|
||||
const it = function (desc, filter, func) {
|
||||
return Reflect.has(core, 'it') ? core.it(desc, filter, func) : (desc, filter, func) => { };
|
||||
};
|
||||
const beforeItSpecified = function (itDescs, func) {
|
||||
return Reflect.has(core, 'beforeItSpecified') ? core.beforeItSpecified(itDescs, func) : (itDescs, func) => { };
|
||||
};
|
||||
|
||||
const afterItSpecified = function (itDescs, func) {
|
||||
return Reflect.has(core, 'afterItSpecified') ? core.afterItSpecified(itDescs, func) : (itDescs, func) => { };
|
||||
};
|
||||
const beforeEach = function (func) {
|
||||
return Reflect.has(core, 'beforeEach') ? core.beforeEach(func) : (func) => { };
|
||||
};
|
||||
const afterEach = function (func) {
|
||||
return Reflect.has(core, 'afterEach') ? core.afterEach(func) : (func) => { };
|
||||
};
|
||||
const beforeAll = function (func) {
|
||||
return Reflect.has(core, 'beforeAll') ? core.beforeAll(func) : (func) => { };
|
||||
};
|
||||
const afterAll = function (func) {
|
||||
return Reflect.has(core, 'afterAll') ? core.afterAll(func) : (func) => { };
|
||||
};
|
||||
const expect = function (actualValue) {
|
||||
return Reflect.has(core, 'expect') ? core.expect(actualValue) : (actualValue) => { };
|
||||
};
|
||||
|
||||
export {
|
||||
describe, it, beforeAll, beforeEach, afterEach, afterAll, expect, beforeItSpecified, afterItSpecified
|
||||
};
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assertNull from './assertNull';
|
||||
import assertClose from './assertClose';
|
||||
import assertContain from './assertContain';
|
||||
import assertLess from './assertLess';
|
||||
import assertLarger from './assertLarger';
|
||||
import assertFail from './assertFail';
|
||||
import assertUndefined from './assertUndefined';
|
||||
import assertFalse from './assertFalse';
|
||||
import assertInstanceOf from './assertInstanceOf';
|
||||
import assertThrowError from './assertThrowError';
|
||||
import assertLargerOrEqual from './assertLargerOrEqual'
|
||||
import assertLessOrEqual from './assertLessOrEqual'
|
||||
import assertNaN from './assertNaN'
|
||||
import assertNegUnlimited from './assertNegUnlimited'
|
||||
import assertPosUnlimited from './assertPosUnlimited'
|
||||
import assertDeepEquals from './deepEquals/assertDeepEquals'
|
||||
import assertPromiseIsPending from './assertPromiseIsPending';
|
||||
import assertPromiseIsRejected from './assertPromiseIsRejected';
|
||||
import assertPromiseIsRejectedWith from './assertPromiseIsRejectedWith';
|
||||
import assertPromiseIsRejectedWithError from './assertPromiseIsRejectedWithError';
|
||||
import assertPromiseIsResolved from './assertPromiseIsResolved';
|
||||
import assertPromiseIsResolvedWith from './assertPromiseIsResolvedWith';
|
||||
class ExpectExtend {
|
||||
constructor(attr) {
|
||||
this.id = attr.id;
|
||||
this.matchers = {};
|
||||
}
|
||||
|
||||
extendsMatchers() {
|
||||
this.matchers.assertNull = assertNull;
|
||||
this.matchers.assertClose = assertClose;
|
||||
this.matchers.assertContain = assertContain;
|
||||
this.matchers.assertLess = assertLess;
|
||||
this.matchers.assertLarger = assertLarger;
|
||||
this.matchers.assertFail = assertFail;
|
||||
this.matchers.assertUndefined = assertUndefined;
|
||||
this.matchers.assertFalse = assertFalse;
|
||||
this.matchers.assertInstanceOf = assertInstanceOf;
|
||||
this.matchers.assertThrowError = assertThrowError;
|
||||
this.matchers.assertLargerOrEqual = assertLargerOrEqual;
|
||||
this.matchers.assertLessOrEqual = assertLessOrEqual;
|
||||
this.matchers.assertNaN = assertNaN;
|
||||
this.matchers.assertNegUnlimited = assertNegUnlimited;
|
||||
this.matchers.assertPosUnlimited = assertPosUnlimited;
|
||||
this.matchers.assertDeepEquals = assertDeepEquals;
|
||||
this.matchers.assertPromiseIsPending = assertPromiseIsPending;
|
||||
this.matchers.assertPromiseIsRejected = assertPromiseIsRejected;
|
||||
this.matchers.assertPromiseIsRejectedWith = assertPromiseIsRejectedWith;
|
||||
this.matchers.assertPromiseIsRejectedWithError = assertPromiseIsRejectedWithError;
|
||||
this.matchers.assertPromiseIsResolved = assertPromiseIsResolved;
|
||||
this.matchers.assertPromiseIsResolvedWith = assertPromiseIsResolvedWith;
|
||||
}
|
||||
|
||||
init(coreContext) {
|
||||
this.coreContext = coreContext;
|
||||
this.extendsMatchers();
|
||||
const expectService = this.coreContext.getDefaultService('expect');
|
||||
expectService.addMatchers(this.matchers);
|
||||
}
|
||||
|
||||
apis() {
|
||||
return {
|
||||
'expect': function (actualValue) {
|
||||
return this.coreContext.getDefaultService('expect').expect(actualValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default ExpectExtend;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertClose(actualValue, expected) {
|
||||
console.log('expected:' + expected[0] + ',precision:' + expected[1]);
|
||||
if (actualValue === null && expected[0] === null) {
|
||||
throw new Error('actualValue and expected can not be both null!!!');
|
||||
}
|
||||
let result;
|
||||
let diff = Math.abs(expected[0] - actualValue);
|
||||
let actualAbs = Math.abs(actualValue);
|
||||
if ((actualAbs - 0) === 0) {
|
||||
if ((diff - 0) === 0) {
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else if (diff / actualAbs < expected[1]) {
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
return {
|
||||
pass: result,
|
||||
message: '|' + actualValue + ' - ' + expected[0] + '|/' + actualValue + ' is not less than ' + expected[1]
|
||||
};
|
||||
}
|
||||
|
||||
export default assertClose;
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertContain(actualValue, expect) {
|
||||
let result = false;
|
||||
if (Object.prototype.toString.call(actualValue).indexOf('Array')) {
|
||||
for (let i in actualValue) {
|
||||
if (actualValue[i] == expect[0]) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
let type = Object.prototype.toString.call(actualValue);
|
||||
if (type === '[object String]') {
|
||||
result = actualValue.indexOf(expect[0]) >= 0;
|
||||
}
|
||||
return {
|
||||
pass: result,
|
||||
message: 'expect false, ' + actualValue + ' do not have ' + expect[0]
|
||||
};
|
||||
}
|
||||
|
||||
export default assertContain;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertFail() {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'fail '
|
||||
};
|
||||
}
|
||||
|
||||
export default assertFail;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertFalse(actualValue) {
|
||||
return {
|
||||
pass: (actualValue) === false,
|
||||
message: 'expect false, actualValue is ' + actualValue
|
||||
};
|
||||
}
|
||||
|
||||
export default assertFalse;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertInstanceOf(actualValue, expected) {
|
||||
if (Object.prototype.toString.call(actualValue) == '[object ' + expected[0] + ']') {
|
||||
return {
|
||||
pass: true
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: actualValue + ' is ' + Object.prototype.toString.call(actualValue) + 'not ' + expected[0]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default assertInstanceOf;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertLarger(actualValue, expected) {
|
||||
return {
|
||||
pass: (actualValue) > expected[0],
|
||||
message: (actualValue) + ' is not larger than ' + expected[0]
|
||||
};
|
||||
}
|
||||
|
||||
export default assertLarger;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertLargerOrEqual(actualValue, expected) {
|
||||
return {
|
||||
pass: (actualValue) >= expected[0],
|
||||
message: (actualValue) + ' is not larger than ' + expected[0]
|
||||
};
|
||||
}
|
||||
|
||||
export default assertLargerOrEqual;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertLess(actualValue, expected) {
|
||||
return {
|
||||
pass: (actualValue) < expected[0],
|
||||
message: (actualValue) + ' is not less than ' + expected[0]
|
||||
};
|
||||
}
|
||||
|
||||
export default assertLess;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertLessOrEqual(actualValue, expected) {
|
||||
return {
|
||||
pass: (actualValue) <= expected[0],
|
||||
message: (actualValue) + ' is not less than ' + expected[0]
|
||||
};
|
||||
}
|
||||
|
||||
export default assertLessOrEqual;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertNaN(actualValue) {
|
||||
return {
|
||||
pass: actualValue !== actualValue,
|
||||
message: 'expect NaN, actualValue is ' + actualValue
|
||||
};
|
||||
}
|
||||
|
||||
export default assertNaN;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertNegUnlimited(actualValue) {
|
||||
return {
|
||||
pass: actualValue === Number.NEGATIVE_INFINITY,
|
||||
message: 'Expected actualValue not to be -Infinity. actualValue is,' + actualValue
|
||||
};
|
||||
}
|
||||
|
||||
export default assertNegUnlimited;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertNull(actualValue) {
|
||||
return {
|
||||
pass: (actualValue) === null,
|
||||
message: 'expect null, actualValue is ' + (actualValue)
|
||||
};
|
||||
}
|
||||
|
||||
export default assertNull;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertPosUnlimited(actualValue) {
|
||||
return {
|
||||
pass: actualValue === Number.POSITIVE_INFINITY,
|
||||
message: 'Expected actualValue is POSITIVE_INFINITY. actualValue is,' + actualValue
|
||||
};
|
||||
}
|
||||
|
||||
export default assertPosUnlimited;
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import isPromiseLike from './isPromiseLike';
|
||||
|
||||
function assertPromiseIsPending(actualPromise) {
|
||||
if (!isPromiseLike(actualPromise)) {
|
||||
return Promise.reject().then(function () {
|
||||
}, function () {
|
||||
return {pass: false, message: 'Expected not be called on a promise.'};
|
||||
});
|
||||
}
|
||||
const helper = {};
|
||||
return Promise.race([actualPromise, Promise.resolve(helper)]).then(
|
||||
function (got) {
|
||||
return helper === got ? {pass: true, message: 'actualValue is isPending'}
|
||||
: {
|
||||
pass: false,
|
||||
message: 'expect isPending, actualValue is resolve'
|
||||
};
|
||||
},
|
||||
function () {
|
||||
return {
|
||||
pass: false
|
||||
, message: 'expect isPending, actualValue is reject'
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default assertPromiseIsPending;
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import isPromiseLike from './isPromiseLike';
|
||||
|
||||
function assertPromiseIsRejected(actualPromise) {
|
||||
if (!isPromiseLike(actualPromise)) {
|
||||
return Promise.reject().then(function () {
|
||||
}, function () {
|
||||
return {pass: false, message: 'Expected not be called on a promise.'};
|
||||
});
|
||||
}
|
||||
const helper = {};
|
||||
return Promise.race([actualPromise, Promise.resolve(helper)]).then(
|
||||
function (got) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'expect isRejected, but actualValue is '
|
||||
+ (helper === got ? 'isPending' : 'resolve')
|
||||
};
|
||||
},
|
||||
function () {
|
||||
return {pass: true, message: 'actualValue is isRejected'};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default assertPromiseIsRejected;
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import isPromiseLike from './isPromiseLike';
|
||||
|
||||
function assertPromiseIsRejectedWith(actualPromise, expectedValue) {
|
||||
|
||||
if (!isPromiseLike(actualPromise)) {
|
||||
return Promise.reject().then(function () {
|
||||
}, function () {
|
||||
return {pass: false, message: 'Expected not be called on a promise.'};
|
||||
});
|
||||
}
|
||||
|
||||
function tips(passed) {
|
||||
return ('Expected a promise ' + (passed ? 'not ' : '') +
|
||||
'to be rejected with ' + JSON.stringify(expectedValue[0]));
|
||||
}
|
||||
|
||||
const helper = {};
|
||||
return Promise.race([actualPromise, Promise.resolve(helper)]).then(
|
||||
function (got) {
|
||||
return {
|
||||
pass: false,
|
||||
message: tips(false) + ' but actualValue is '
|
||||
+ (helper === got ? 'isPending' : 'resolve')
|
||||
};
|
||||
},
|
||||
function (actualValue) {
|
||||
if (JSON.stringify(actualValue) == JSON.stringify(expectedValue[0])) {
|
||||
return {
|
||||
pass: true,
|
||||
message: 'actualValue was rejected with ' + JSON.stringify(actualValue) + '.'
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: tips(false) + ' but it was rejected with ' + JSON.stringify(actualValue) + '.'
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default assertPromiseIsRejectedWith;
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import isPromiseLike from './isPromiseLike';
|
||||
|
||||
function assertPromiseIsRejectedWithError(actualPromise, expectedValue) {
|
||||
if (!isPromiseLike(actualPromise)) {
|
||||
return Promise.reject().then(function () {
|
||||
}, function () {
|
||||
return {pass: false, message: 'Expected not be called on a promise.'};
|
||||
});
|
||||
}
|
||||
const helper = {};
|
||||
return Promise.race([actualPromise, Promise.resolve(helper)]).then(
|
||||
function (got) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Expected a promise to be rejected but actualValue is '
|
||||
+ (helper === got ? 'isPending' : 'resolve')
|
||||
};
|
||||
},
|
||||
function (actualValue) {
|
||||
return matchError(actualValue, expectedValue);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function matchError(actualValue, expectedValue) {
|
||||
if (expectedValue.length == 1 && typeof expectedValue[0] === 'function') {
|
||||
if (expectedValue[0].name === actualValue.__proto__.name) {
|
||||
return {pass: true, message: 'actual error type is ' + actualValue.name + '.'};
|
||||
}
|
||||
return {pass: false, message: `except error type is ${expectedValue[0].name},but actual is ${actualValue.name}.`};
|
||||
}
|
||||
|
||||
if (expectedValue.length == 1 && typeof expectedValue[0] === 'string') {
|
||||
if (expectedValue[0] === actualValue.message) {
|
||||
return {pass: true, message: `actual error message is ${actualValue.message}.`};
|
||||
}
|
||||
return {pass: false, message: `except error message ${expectedValue[0]},but actual is ${actualValue.message}.`};
|
||||
}
|
||||
|
||||
if (expectedValue.length == 1) {
|
||||
return {pass: false, message: 'When only one parameter, it should be error type or error message.'};
|
||||
}
|
||||
|
||||
if (expectedValue.length == 2 && typeof expectedValue[0] === 'function' && expectedValue[0].name === actualValue.name) {
|
||||
if (typeof expectedValue[1] === 'string' && actualValue.message === expectedValue[1]) {
|
||||
return {pass: true, message: 'actual error message is ' + actualValue.message + '.'};
|
||||
}
|
||||
return {pass: false, message: `except error message is ${expectedValue[1]},but actual is ${actualValue.message}.`};
|
||||
}
|
||||
|
||||
if (expectedValue.length == 2 && typeof expectedValue[0] === 'function' && expectedValue[0].name !== actualValue.name) {
|
||||
if (typeof expectedValue[1] === 'string' && actualValue.message === expectedValue[1]) {
|
||||
return {pass: false, message: `except error type is ${expectedValue[0].name},but actual is ${actualValue.name}.`};
|
||||
}
|
||||
return {pass: false, message: 'except error type and message are incorrect.'};
|
||||
}
|
||||
if (expectedValue.length > 2) {
|
||||
return {pass: false, message: 'Up to two parameters are supported.'};
|
||||
}
|
||||
}
|
||||
|
||||
export default assertPromiseIsRejectedWithError;
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import isPromiseLike from './isPromiseLike';
|
||||
|
||||
function assertPromiseIsResolved(actualPromise) {
|
||||
if (!isPromiseLike(actualPromise)) {
|
||||
return Promise.reject().then(function () {
|
||||
}, function () {
|
||||
return {pass: false, message: 'Expected not be called on a promise.'};
|
||||
});
|
||||
}
|
||||
|
||||
const helper = {};
|
||||
return Promise.race([actualPromise, Promise.resolve(helper)]).then(
|
||||
function (got) {
|
||||
return helper === got ? {
|
||||
pass: false,
|
||||
message: 'expect resolve, actualValue is isPending'
|
||||
}
|
||||
: {pass: true, message: 'actualValue is isResolved'};
|
||||
},
|
||||
function (rej) {
|
||||
return {
|
||||
pass: false,
|
||||
message: 'Expected a promise to be resolved but it was ' +
|
||||
'rejected with ' + JSON.stringify(rej) + '.'
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default assertPromiseIsResolved;
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import isPromiseLike from './isPromiseLike';
|
||||
|
||||
function assertPromiseIsResolvedWith(actualPromise, expectedValue) {
|
||||
if (!isPromiseLike(actualPromise)) {
|
||||
return Promise.reject().then(function () {
|
||||
}, function () {
|
||||
return {pass: false, message: 'Expected not be called on a promise.'};
|
||||
});
|
||||
}
|
||||
|
||||
function tips(passed) {
|
||||
return (
|
||||
'Expected a promise ' + (passed ? 'not ' : '') +
|
||||
'to be resolved with ' + JSON.stringify(expectedValue[0]));
|
||||
}
|
||||
|
||||
const helper = {};
|
||||
return Promise.race([actualPromise, Promise.resolve(helper)]).then(
|
||||
function (got) {
|
||||
if (helper === got) {
|
||||
return {pass: false, message: 'expect resolve, actualValue is isPending'};
|
||||
}
|
||||
if (JSON.stringify(got) == JSON.stringify(expectedValue[0])) {
|
||||
return {
|
||||
pass: true,
|
||||
message: 'actualValue was resolved with ' + JSON.stringify(got) + '.'
|
||||
};
|
||||
}
|
||||
return {
|
||||
pass: false,
|
||||
message: tips(false) + ' but it was resolved with ' +
|
||||
JSON.stringify(got) + '.'
|
||||
};
|
||||
},
|
||||
function (rej) {
|
||||
return {
|
||||
pass: false,
|
||||
message: tips(false) + ' but it was rejected with ' + JSON.stringify(rej) + '.'
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default assertPromiseIsResolvedWith;
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertThrowError(actualValue, expected) {
|
||||
let result = false;
|
||||
let err;
|
||||
if (typeof actualValue !== 'function') {
|
||||
throw new Error('actualValue is not a function');
|
||||
}
|
||||
try {
|
||||
actualValue();
|
||||
return {
|
||||
pass: result,
|
||||
message: ' An error is not thrown while it is expected!'
|
||||
};
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
if (err instanceof Error) {
|
||||
console.log(err.message);
|
||||
if (err.message == expected[0]) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return {
|
||||
pass: result,
|
||||
message: 'expected throw failed , ' + err.message + ' is not ' + expected[0]
|
||||
};
|
||||
}
|
||||
|
||||
export default assertThrowError;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function assertUndefined(actualValue) {
|
||||
return {
|
||||
pass: undefined === (actualValue),
|
||||
message: 'expect Undefined, actualValue is ' + (actualValue)
|
||||
};
|
||||
}
|
||||
|
||||
export default assertUndefined;
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class DeepTypeUtils {
|
||||
static getType_(value) {
|
||||
return Object.prototype.toString.apply(value);
|
||||
}
|
||||
static isA_(typeName, value) {
|
||||
return this.getType_(value) === '[object ' + typeName + ']';
|
||||
}
|
||||
static isAsymmetricEqualityTester_(obj) {
|
||||
return obj ? this.isA_('Function', obj.asymmetricMatch) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是function
|
||||
* @param value
|
||||
*/
|
||||
static isFunction_(value) {
|
||||
return this.isA_('Function', value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是undefined
|
||||
* @param obj
|
||||
*/
|
||||
static isUndefined(obj) {
|
||||
return obj === void 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是Node
|
||||
* @param obj
|
||||
*/
|
||||
static isDomNode(obj) {
|
||||
return obj !== null &&
|
||||
typeof obj === 'object' &&
|
||||
typeof obj.nodeType === 'number' &&
|
||||
typeof obj.nodeName === 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是promise对象
|
||||
* @param obj
|
||||
*/
|
||||
static isPromise (obj) {
|
||||
return !!obj && obj.constructor === Promise;
|
||||
};
|
||||
/**
|
||||
* 是否是map对象
|
||||
* @param obj
|
||||
*/
|
||||
static isMap(obj) {
|
||||
return (
|
||||
obj !== null &&
|
||||
typeof obj !== 'undefined' &&
|
||||
obj.constructor === Map
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是set对象
|
||||
* @param obj 对象
|
||||
*/
|
||||
static isSet(obj) {
|
||||
return (
|
||||
obj !== null &&
|
||||
typeof obj !== 'undefined' &&
|
||||
obj.constructor === Set
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象是否有key属性
|
||||
* @param obj 对象
|
||||
* @param key 对象属性名称
|
||||
*/
|
||||
static has(obj, key) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象的自有属性
|
||||
* @param obj 对象
|
||||
* @param isArray 是否是数组,[object Array]
|
||||
*/
|
||||
static keys(obj, isArray) {
|
||||
const extraKeys = [];
|
||||
// 获取对象所有属性
|
||||
const allKeys = this.getAllKeys(obj);
|
||||
if (!isArray) {
|
||||
return allKeys;
|
||||
}
|
||||
if (allKeys.length === 0) {
|
||||
return allKeys;
|
||||
}
|
||||
for (const k of allKeys) {
|
||||
if (typeof k === 'symbol' || !/^[0-9]+$/.test(k)) {
|
||||
extraKeys.push(k);
|
||||
}
|
||||
}
|
||||
return extraKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取obj对象的所有属性
|
||||
* @param obj obj对象
|
||||
*/
|
||||
static getAllKeys(obj) {
|
||||
const keys = [];
|
||||
for (let key in obj) {
|
||||
if(this.has(obj, key)) {
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
const symbols = Object.getOwnPropertySymbols(obj);
|
||||
for (const sym of symbols) {
|
||||
if (obj.propertyIsEnumerable(sym)) {
|
||||
keys.push(sym);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
}
|
||||
export default DeepTypeUtils;
|
||||
|
|
@ -0,0 +1,315 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import DeepTypeUtils from './DeepTypeUtils'
|
||||
function assertDeepEquals(actualValue, expected) {
|
||||
console.log('actualValue:' + actualValue + ',expected:' + expected[0]);
|
||||
let result = eq(actualValue, expected[0],[], [])
|
||||
let msg = logMsg(actualValue, expected[0]);
|
||||
return {
|
||||
pass: result,
|
||||
message: msg
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取失败显示日志
|
||||
* @param actualValue 实际对象
|
||||
* @param expected 期待比较对象
|
||||
*/
|
||||
function logMsg(actualValue, expected) {
|
||||
// 获取a的对象名称
|
||||
const aClassName = Object.prototype.toString.call(actualValue);
|
||||
const bClassName = Object.prototype.toString.call(expected);
|
||||
let actualMsg;
|
||||
let expectMsg;
|
||||
if(aClassName == "[object Function]") {
|
||||
actualMsg = "actualValue Function"
|
||||
}else if(aClassName == "[object Promise]") {
|
||||
actualMsg = "actualValue Promise"
|
||||
}else if(aClassName == "[object Set]" || aClassName == "[object Map]") {
|
||||
actualMsg = JSON.stringify(Array.from(actualValue));;
|
||||
}else if(aClassName == "[object RegExp]") {
|
||||
actualMsg = JSON.stringify(actualValue.source.replace("\\",""));;
|
||||
}else if(aClassName == "[object BigInt]") {
|
||||
actualMsg = actualValue;
|
||||
}
|
||||
else{
|
||||
actualMsg = JSON.stringify(actualValue);
|
||||
}
|
||||
if(bClassName == "[object Function]") {
|
||||
expectMsg = "expected Function"
|
||||
}else if(bClassName == "[object Promise]") {
|
||||
expectMsg = "expected Promise"
|
||||
}else if(bClassName == "[object Set]" || bClassName == "[object Map]") {
|
||||
expectMsg = JSON.stringify(Array.from(expected));
|
||||
}else if(bClassName == "[object RegExp]") {
|
||||
expectMsg = JSON.stringify(expected.source.replace("\\",""));;
|
||||
}else if(bClassName == "[object BigInt]") {
|
||||
expectMsg = expected;
|
||||
}
|
||||
else{
|
||||
expectMsg = JSON.stringify(expected);
|
||||
}
|
||||
return actualMsg + " is not deep equal " + expectMsg;
|
||||
}
|
||||
|
||||
function eq(a, b, aStack, bStack) {
|
||||
let result = true;
|
||||
console.log('a is:' + a + ',b is:' + b);
|
||||
const asymmetricResult = asymmetricMatch_(a,b);
|
||||
if (!DeepTypeUtils.isUndefined(asymmetricResult)) {
|
||||
return asymmetricResult;
|
||||
}
|
||||
|
||||
if (a instanceof Error && b instanceof Error) {
|
||||
result = a.message == b.message;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (a === b) {
|
||||
result = a !== 0 || 1 / a == 1 / b;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (a === null || b === null) {
|
||||
result = a === b;
|
||||
return result;
|
||||
}
|
||||
// 获取a的对象名称
|
||||
const aClassName = Object.prototype.toString.call(a);
|
||||
const bClassName = Object.prototype.toString.call(b);
|
||||
console.log('aClassName is:' + aClassName);
|
||||
console.log('bClassName is:' + bClassName);
|
||||
// 不同类型不同对象
|
||||
if (aClassName != bClassName) {
|
||||
return false;
|
||||
}
|
||||
// 俩个string对象
|
||||
if(aClassName === '[object String]') {
|
||||
result = a == String(b);
|
||||
return result;
|
||||
}
|
||||
// 俩个Number对象
|
||||
if(aClassName === '[object Number]') {
|
||||
result = a != +a ? b != +b : a === 0 && b === 0 ? 1 / a == 1 / b : a == +b;
|
||||
return result;
|
||||
}
|
||||
|
||||
if(aClassName === '[object Date]' || aClassName === '[object Boolean]') {
|
||||
result = +a == +b;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 数组
|
||||
if(aClassName === '[object ArrayBuffer]') {
|
||||
return eq(new Uint8Array(a), new Uint8Array(b), aStack, bStack);
|
||||
}
|
||||
|
||||
// 正则表达式
|
||||
if(aClassName === '[object RegExp]') {
|
||||
return (
|
||||
a.source == b.source &&
|
||||
a.global == b.global &&
|
||||
a.multiline == b.multiline &&
|
||||
a.ignoreCase == b.ignoreCase
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof a != 'object' || typeof b != 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const aIsDomNode = DeepTypeUtils.isDomNode(a);
|
||||
const bIsDomNode = DeepTypeUtils.isDomNode(b);
|
||||
if (aIsDomNode && bIsDomNode) {
|
||||
// At first try to use DOM3 method isEqualNode
|
||||
result = a.isEqualNode(b);
|
||||
return result;
|
||||
}
|
||||
if (aIsDomNode || bIsDomNode) {
|
||||
return false;
|
||||
}
|
||||
const aIsPromise = DeepTypeUtils.isPromise(a);
|
||||
const bIsPromise = DeepTypeUtils.isPromise(b);
|
||||
if (aIsPromise && bIsPromise) {
|
||||
return a === b;
|
||||
}
|
||||
let length = aStack.length;
|
||||
while (length--) {
|
||||
if (aStack[length] == a) {
|
||||
return bStack[length] == b;
|
||||
}
|
||||
}
|
||||
aStack.push(a);
|
||||
bStack.push(b);
|
||||
let size = 0;
|
||||
|
||||
// 都是数组
|
||||
if(aClassName == '[object Array]') {
|
||||
const aLength = a.length;
|
||||
const bLength = b.length;
|
||||
if (aLength !== bLength) {
|
||||
// 数组长度不同,不是同一个对象
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < aLength || i < bLength; i++) {
|
||||
// 递归每一个元素是否相同
|
||||
result = eq(i < aLength ? a[i] : void 0, i < bLength ? b[i] : void 0, aStack, bStack) && result;
|
||||
}
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
} else if(DeepTypeUtils.isMap(a) && DeepTypeUtils.isMap(b)) {
|
||||
if (a.size != b.size) {
|
||||
return false;
|
||||
}
|
||||
const keysA = [];
|
||||
const keysB = [];
|
||||
a.forEach(function(valueA, keyA) {
|
||||
keysA.push(keyA);
|
||||
});
|
||||
b.forEach(function(valueB, keyB) {
|
||||
keysB.push(keyB);
|
||||
});
|
||||
const mapKeys = [keysA, keysB];
|
||||
const cmpKeys = [keysB, keysA];
|
||||
for (let i = 0; result && i < mapKeys.length; i++) {
|
||||
const mapIter = mapKeys[i];
|
||||
const cmpIter = cmpKeys[i];
|
||||
|
||||
for (let j = 0; result && j < mapIter.length; j++) {
|
||||
const mapKey = mapIter[j];
|
||||
const cmpKey = cmpIter[j];
|
||||
const mapValueA = a.get(mapKey);
|
||||
let mapValueB;
|
||||
if (
|
||||
DeepTypeUtils.isAsymmetricEqualityTester_(mapKey) ||
|
||||
(DeepTypeUtils.isAsymmetricEqualityTester_(cmpKey) &&
|
||||
eq(mapKey, cmpKey))
|
||||
) {
|
||||
mapValueB = b.get(cmpKey);
|
||||
} else {
|
||||
mapValueB = b.get(mapKey);
|
||||
}
|
||||
result = eq(mapValueA, mapValueB, aStack, bStack);
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
} else if(DeepTypeUtils.isSet(a) && DeepTypeUtils.isSet(b)) {
|
||||
if (a.size != b.size) {
|
||||
return false;
|
||||
}
|
||||
const valuesA = [];
|
||||
a.forEach(function(valueA) {
|
||||
valuesA.push(valueA);
|
||||
});
|
||||
const valuesB = [];
|
||||
b.forEach(function(valueB) {
|
||||
valuesB.push(valueB);
|
||||
});
|
||||
const setPairs = [[valuesA, valuesB], [valuesB, valuesA]];
|
||||
const stackPairs = [[aStack, bStack], [bStack, aStack]];
|
||||
for (let i = 0; result && i < setPairs.length; i++) {
|
||||
const baseValues = setPairs[i][0];
|
||||
const otherValues = setPairs[i][1];
|
||||
const baseStack = stackPairs[i][0];
|
||||
const otherStack = stackPairs[i][1];
|
||||
for (const baseValue of baseValues) {
|
||||
let found = false;
|
||||
for (let j = 0; !found && j < otherValues.length; j++) {
|
||||
const otherValue = otherValues[j];
|
||||
const prevStackSize = baseStack.length;
|
||||
// 深度比较对象
|
||||
found = eq(baseValue, otherValue, baseStack, otherStack);
|
||||
if (!found && prevStackSize !== baseStack.length) {
|
||||
baseStack.splice(prevStackSize);
|
||||
otherStack.splice(prevStackSize);
|
||||
}
|
||||
}
|
||||
result = result && found;
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
const aCtor = a.constructor,
|
||||
bCtor = b.constructor;
|
||||
if (
|
||||
aCtor !== bCtor &&
|
||||
DeepTypeUtils.isFunction_(aCtor) &&
|
||||
DeepTypeUtils.isFunction_(bCtor) &&
|
||||
a instanceof aCtor &&
|
||||
b instanceof bCtor &&
|
||||
!(aCtor instanceof aCtor && bCtor instanceof bCtor)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取对象所有的属性集合
|
||||
const aKeys = DeepTypeUtils.keys(a, aClassName == '[object Array]');
|
||||
size = aKeys.length;
|
||||
|
||||
// 俩个对象属性长度不一致, 俩对象不相同
|
||||
if (DeepTypeUtils.keys(b, bClassName == '[object Array]').length !== size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 俩对象属性数量相同, 递归比较每个属性值得值
|
||||
for (const key of aKeys) {
|
||||
console.log('key is:' + key);
|
||||
// b 没有 key 属性
|
||||
if(!DeepTypeUtils.has(b, key)) {
|
||||
result = false;
|
||||
continue;
|
||||
}
|
||||
if (!eq(a[key], b[key], aStack, bStack)) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
aStack.pop();
|
||||
bStack.pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
function asymmetricMatch_(a, b) {
|
||||
const asymmetricA = DeepTypeUtils.isAsymmetricEqualityTester_(a);
|
||||
const asymmetricB = DeepTypeUtils.isAsymmetricEqualityTester_(b);
|
||||
|
||||
if (asymmetricA === asymmetricB) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对象的自有属性
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param isArray 是否是一个数组
|
||||
*/
|
||||
function keys(obj, isArray) {
|
||||
const keys = [];
|
||||
|
||||
}
|
||||
|
||||
export default assertDeepEquals;
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function isPromiseLike(obj) {
|
||||
return !!obj && isFunction_(obj.then);
|
||||
}
|
||||
|
||||
function isFunction_(value) {
|
||||
return isA_('Function', value);
|
||||
}
|
||||
|
||||
function isA_(typeName, value) {
|
||||
return getType_(value) === '[object ' + typeName + ']';
|
||||
}
|
||||
|
||||
function getType_(value) {
|
||||
return Object.prototype.toString.apply(value);
|
||||
}
|
||||
|
||||
export default isPromiseLike;
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const SUITES_KEY = 'suites';
|
||||
const SPECS_KEY = 'items';
|
||||
const DESCRIBE_KEY = 'describe';
|
||||
const IT_KEY = 'it';
|
||||
const PARAMS_KEY = 'params';
|
||||
const STRESS_KEY = 'stress';
|
||||
|
||||
class ObjectUtils {
|
||||
static get(object, name, defaultValue) {
|
||||
let result = defaultValue;
|
||||
for (const key in object) {
|
||||
if (key === name) {
|
||||
return object[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static has(object, key) {
|
||||
return Object.prototype.hasOwnProperty.call(object, key);
|
||||
}
|
||||
}
|
||||
|
||||
class DataDriver {
|
||||
constructor(attr) {
|
||||
this.id = 'dataDriver';
|
||||
this.data = attr.data || {};
|
||||
}
|
||||
|
||||
init(coreContext) {
|
||||
this.coreContext = coreContext;
|
||||
this.suiteService = this.coreContext.getDefaultService('suite');
|
||||
this.specService = this.coreContext.getDefaultService('spec');
|
||||
}
|
||||
|
||||
getSpecParams() {
|
||||
let specParams = [];
|
||||
let suiteDesc = this.suiteService.getCurrentRunningSuite().description;
|
||||
let specDesc = this.specService.getCurrentRunningSpec().description;
|
||||
let suites = ObjectUtils.get(this.data, SUITES_KEY, []);
|
||||
for (const suiteItem of suites) {
|
||||
let describeValue = ObjectUtils.get(suiteItem, DESCRIBE_KEY, '');
|
||||
if (ObjectUtils.has(suiteItem, DESCRIBE_KEY) && (typeof describeValue === 'object') && describeValue.constructor === Array && describeValue.includes(suiteDesc)) {
|
||||
let specs = ObjectUtils.get(suiteItem, SPECS_KEY, []);
|
||||
for (const specItem of specs) {
|
||||
if (ObjectUtils.has(specItem, IT_KEY) && ObjectUtils.get(specItem, IT_KEY) === specDesc) {
|
||||
return ObjectUtils.get(specItem, PARAMS_KEY, specParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return specParams;
|
||||
}
|
||||
|
||||
getSuiteParams() {
|
||||
let suiteParams = {};
|
||||
let suiteDesc = this.suiteService.getCurrentRunningSuite().description;
|
||||
let suites = ObjectUtils.get(this.data, SUITES_KEY, []);
|
||||
for (const suiteItem of suites) {
|
||||
let describeValue = ObjectUtils.get(suiteItem, DESCRIBE_KEY, []);
|
||||
if (ObjectUtils.has(suiteItem, DESCRIBE_KEY) && (typeof describeValue === 'object') && describeValue.constructor === Array && describeValue.includes(suiteDesc)) {
|
||||
suiteParams = Object.assign({}, suiteParams, ObjectUtils.get(suiteItem, PARAMS_KEY, suiteParams));
|
||||
}
|
||||
}
|
||||
return suiteParams;
|
||||
}
|
||||
|
||||
getSpecStress(specDesc) {
|
||||
let stress = 1;
|
||||
let suiteDesc = this.suiteService.getCurrentRunningSuite().description;
|
||||
let suites = ObjectUtils.get(this.data, SUITES_KEY, []);
|
||||
for (const suiteItem of suites) {
|
||||
let describeValue = ObjectUtils.get(suiteItem, DESCRIBE_KEY, '');
|
||||
if (ObjectUtils.has(suiteItem, DESCRIBE_KEY) && (typeof describeValue === 'object') && describeValue.constructor === Array && describeValue.includes(suiteDesc)) {
|
||||
let specs = ObjectUtils.get(suiteItem, SPECS_KEY, []);
|
||||
for (const specItem of specs) {
|
||||
if (ObjectUtils.has(specItem, IT_KEY) && ObjectUtils.get(specItem, IT_KEY) === specDesc) {
|
||||
let tempStress = ObjectUtils.get(specItem, STRESS_KEY, stress);
|
||||
return (Number.isInteger(tempStress) && tempStress >= 1) ? tempStress : stress;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return stress;
|
||||
}
|
||||
|
||||
getSuiteStress(suiteDesc) {
|
||||
let stress = 1;
|
||||
let suites = ObjectUtils.get(this.data, SUITES_KEY, []);
|
||||
for (const suiteItem of suites) {
|
||||
let describeValue = ObjectUtils.get(suiteItem, DESCRIBE_KEY, []);
|
||||
if (ObjectUtils.has(suiteItem, DESCRIBE_KEY) && (typeof describeValue === 'object') && describeValue.constructor === Array && describeValue.includes(suiteDesc)) {
|
||||
let tempStress = ObjectUtils.get(suiteItem, STRESS_KEY, stress);
|
||||
return (Number.isInteger(tempStress) && tempStress >= 1) ? tempStress : stress;
|
||||
}
|
||||
}
|
||||
return stress;
|
||||
}
|
||||
}
|
||||
|
||||
export default DataDriver;
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class ClassFilter {
|
||||
constructor(suiteName, itName, params) {
|
||||
this.suiteName = suiteName;
|
||||
this.itName = itName;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
filterSuite() {
|
||||
return !this.params.split(',').map(item => item.split('#')[0]).map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
|
||||
}
|
||||
|
||||
filterIt() {
|
||||
let classArray = this.params.split(',') || [];
|
||||
let suiteFilterResult = classArray.filter(item => !item.includes('#')).map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
|
||||
let itFilterResult = classArray.filter(item => item.includes('#')).map(item => item == (this.suiteName + '#' + this.itName)).reduce((pre, cur) => pre || cur, false);
|
||||
return !(suiteFilterResult || itFilterResult);
|
||||
}
|
||||
}
|
||||
|
||||
class NotClassFilter {
|
||||
constructor(suiteName, itName, params) {
|
||||
this.suiteName = suiteName;
|
||||
this.itName = itName;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
filterSuite() {
|
||||
return this.params.split(',').map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
|
||||
}
|
||||
|
||||
filterIt() {
|
||||
return this.params.split(',').some(item => item == (this.suiteName + '#' + this.itName));
|
||||
}
|
||||
}
|
||||
|
||||
class SuiteAndItNameFilter {
|
||||
constructor(suiteName, itName, params) {
|
||||
this.suiteName = suiteName;
|
||||
this.itName = itName;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
filterSuite() {
|
||||
return !this.params.split(',').map(item => item == this.suiteName).reduce((pre, cur) => pre || cur, false);
|
||||
}
|
||||
|
||||
filterIt() {
|
||||
return !this.params.split(',').map(item => item == this.itName).reduce((pre, cur) => pre || cur, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestTypesFilter {
|
||||
constructor(suiteName, itName, fi, params) {
|
||||
this.suiteName = suiteName;
|
||||
this.itName = itName;
|
||||
this.params = params;
|
||||
this.fi = fi;
|
||||
}
|
||||
|
||||
filterIt() {
|
||||
return !((this.params === (this.fi & this.params)) || this.fi === 0);
|
||||
}
|
||||
}
|
||||
|
||||
export {ClassFilter, NotClassFilter, SuiteAndItNameFilter, TestTypesFilter};
|
||||
|
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {ClassFilter, NotClassFilter, SuiteAndItNameFilter, TestTypesFilter} from './Filter';
|
||||
import {TAG} from '../../Constant';
|
||||
const STRESS_RULE = /^[1-9]\d*$/;
|
||||
|
||||
class ConfigService {
|
||||
constructor(attr) {
|
||||
this.id = attr.id;
|
||||
this.supportAsync = false;
|
||||
this.random = false;
|
||||
this.filterValid = [];
|
||||
this.filter = 0;
|
||||
this.flag = false;
|
||||
this.suite = null;
|
||||
this.itName = null;
|
||||
this.testType = null;
|
||||
this.level = null;
|
||||
this.size = null;
|
||||
this.class = null;
|
||||
this.notClass = null;
|
||||
this.timeout = null;
|
||||
// 遇错即停模式配置
|
||||
this.breakOnError = false;
|
||||
// 压力测试配置
|
||||
this.stress = null;
|
||||
}
|
||||
|
||||
init(coreContext) {
|
||||
this.coreContext = coreContext;
|
||||
}
|
||||
|
||||
isNormalInteger(str) {
|
||||
const n = Math.floor(Number(str));
|
||||
return n !== Infinity && String(n) === String(str) && n >= 0;
|
||||
}
|
||||
|
||||
getStress() {
|
||||
if (this.stress === undefined || this.stress === '' || this.stress === null) {
|
||||
return 1;
|
||||
}
|
||||
return !this.stress.match(STRESS_RULE) ? 1 : Number.parseInt(this.stress);
|
||||
}
|
||||
|
||||
basicParamValidCheck(params) {
|
||||
let size = params.size;
|
||||
if (size !== undefined && size !== '' && size !== null) {
|
||||
let sizeArray = ['small', 'medium', 'large'];
|
||||
if (sizeArray.indexOf(size) === -1) {
|
||||
this.filterValid.push('size:' + size);
|
||||
}
|
||||
}
|
||||
let level = params.level;
|
||||
if (level !== undefined && level !== '' && level !== null) {
|
||||
let levelArray = ['0', '1', '2', '3', '4'];
|
||||
if (levelArray.indexOf(level) === -1) {
|
||||
this.filterValid.push('level:' + level);
|
||||
}
|
||||
}
|
||||
let testType = params.testType;
|
||||
if (testType !== undefined && testType !== '' && testType !== null) {
|
||||
let testTypeArray = ['function', 'performance', 'power', 'reliability', 'security',
|
||||
'global', 'compatibility', 'user', 'standard', 'safety', 'resilience'];
|
||||
if (testTypeArray.indexOf(testType) === -1) {
|
||||
this.filterValid.push('testType:' + testType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filterParamValidCheck(params) {
|
||||
let timeout = params.timeout;
|
||||
if (timeout !== undefined && timeout !== '' && timeout !== null) {
|
||||
if (!this.isNormalInteger(timeout)) {
|
||||
this.filterValid.push('timeout:' + timeout);
|
||||
}
|
||||
}
|
||||
|
||||
let paramKeys = ['dryRun', 'random', 'breakOnError', 'coverage'];
|
||||
for (const key of paramKeys) {
|
||||
if (params[key] !== undefined && params[key] !== 'true' && params[key] !== 'false') {
|
||||
this.filterValid.push(`${key}:${params[key]}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 压力测试参数验证,正整数
|
||||
if (params.stress !== undefined && params.stress !== '' && params.stress !== null) {
|
||||
if (!params.stress.match(STRESS_RULE)) {
|
||||
this.filterValid.push('stress:' + params.stress);
|
||||
}
|
||||
}
|
||||
|
||||
let nameRule = /^[A-Za-z]{1}[\w#,.]*$/;
|
||||
let paramClassKeys = ['class', 'notClass'];
|
||||
for (const key of paramClassKeys) {
|
||||
if (params[key] !== undefined && params[key] !== '' && params[key] !== null) {
|
||||
let classArray = params[key].split(',');
|
||||
classArray.forEach(item => !item.match(nameRule) ? this.filterValid.push(`${key}:${params[key]}`) : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setConfig(params) {
|
||||
this.basicParamValidCheck(params);
|
||||
this.filterParamValidCheck(params);
|
||||
try {
|
||||
this.class = params.class;
|
||||
this.notClass = params.notClass;
|
||||
this.flag = params.flag || {flag: false};
|
||||
this.suite = params.suite;
|
||||
this.itName = params.itName;
|
||||
this.filter = params.filter;
|
||||
this.testType = params.testType;
|
||||
this.level = params.level;
|
||||
this.size = params.size;
|
||||
this.timeout = params.timeout;
|
||||
this.dryRun = params.dryRun;
|
||||
this.breakOnError = params.breakOnError;
|
||||
this.random = params.random === 'true' ? true : false;
|
||||
this.stress = params.stress;
|
||||
this.coverage = params.coverage;
|
||||
this.filterParam = {
|
||||
testType: {
|
||||
'function': 1,
|
||||
'performance': 1 << 1,
|
||||
'power': 1 << 2,
|
||||
'reliability': 1 << 3,
|
||||
'security': 1 << 4,
|
||||
'global': 1 << 5,
|
||||
'compatibility': 1 << 6,
|
||||
'user': 1 << 7,
|
||||
'standard': 1 << 8,
|
||||
'safety': 1 << 9,
|
||||
'resilience': 1 << 10,
|
||||
},
|
||||
level: {
|
||||
'0': 1 << 24,
|
||||
'1': 1 << 25,
|
||||
'2': 1 << 26,
|
||||
'3': 1 << 27,
|
||||
'4': 1 << 28,
|
||||
},
|
||||
size: {
|
||||
'small': 1 << 16,
|
||||
'medium': 1 << 17,
|
||||
'large': 1 << 18,
|
||||
}
|
||||
};
|
||||
this.parseParams();
|
||||
} catch (err) {
|
||||
console.info(`${TAG}setConfig error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
parseParams() {
|
||||
if (this.filter != null) {
|
||||
return;
|
||||
}
|
||||
let testTypeFilter = 0;
|
||||
let sizeFilter = 0;
|
||||
let levelFilter = 0;
|
||||
if (this.testType != null) {
|
||||
testTypeFilter = this.testType.split(',')
|
||||
.map(item => this.filterParam.testType[item] || 0)
|
||||
.reduce((pre, cur) => pre | cur, 0);
|
||||
}
|
||||
if (this.level != null) {
|
||||
levelFilter = this.level.split(',')
|
||||
.map(item => this.filterParam.level[item] || 0)
|
||||
.reduce((pre, cur) => pre | cur, 0);
|
||||
}
|
||||
if (this.size != null) {
|
||||
sizeFilter = this.size.split(',')
|
||||
.map(item => this.filterParam.size[item] || 0)
|
||||
.reduce((pre, cur) => pre | cur, 0);
|
||||
}
|
||||
this.filter = testTypeFilter | sizeFilter | levelFilter;
|
||||
console.info(`${TAG}filter params:${this.filter}`);
|
||||
}
|
||||
|
||||
isCurrentSuite(description) {
|
||||
if (this.suite !== undefined && this.suite !== '' && this.suite !== null) {
|
||||
let suiteArray = this.suite.split(',');
|
||||
return suiteArray.indexOf(description) !== -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
filterSuite(currentSuiteName) {
|
||||
let filterArray = [];
|
||||
if (this.suite !== undefined && this.suite !== '' && this.suite !== null) {
|
||||
filterArray.push(new SuiteAndItNameFilter(currentSuiteName, '', this.suite));
|
||||
}
|
||||
if (this.class !== undefined && this.class !== '' && this.class !== null) {
|
||||
filterArray.push(new ClassFilter(currentSuiteName, '', this.class));
|
||||
}
|
||||
if (this.notClass !== undefined && this.notClass !== '' && this.notClass !== null) {
|
||||
filterArray.push(new NotClassFilter(currentSuiteName, '', this.notClass));
|
||||
}
|
||||
|
||||
let result = filterArray.map(item => item.filterSuite()).reduce((pre, cur) => pre || cur, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
filterDesc(currentSuiteName, desc, fi, coreContext) {
|
||||
let filterArray = [];
|
||||
if (this.itName !== undefined && this.itName !== '' && this.itName !== null) {
|
||||
filterArray.push(new SuiteAndItNameFilter(currentSuiteName, desc, this.itName));
|
||||
}
|
||||
if (this.class !== undefined && this.class !== '' && this.class !== null) {
|
||||
filterArray.push(new ClassFilter(currentSuiteName, desc, this.class));
|
||||
}
|
||||
if (this.notClass !== undefined && this.notClass !== '' && this.notClass !== null) {
|
||||
filterArray.push(new NotClassFilter(currentSuiteName, desc, this.notClass));
|
||||
}
|
||||
if (typeof (this.filter) !== 'undefined' && this.filter !== 0 && fi !== 0) {
|
||||
filterArray.push(new TestTypesFilter('', '', fi, this.filter));
|
||||
}
|
||||
let result = filterArray.map(item => item.filterIt()).reduce((pre, cur) => pre || cur, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
isRandom() {
|
||||
return this.random || false;
|
||||
}
|
||||
|
||||
isBreakOnError() {
|
||||
return this.breakOnError !== 'true' ? false : true;
|
||||
}
|
||||
|
||||
setSupportAsync(value) {
|
||||
this.supportAsync = value;
|
||||
}
|
||||
|
||||
isSupportAsync() {
|
||||
return this.supportAsync;
|
||||
}
|
||||
|
||||
translateParams(parameters) {
|
||||
const keySet = new Set([
|
||||
'-s class', '-s notClass', '-s suite', '-s itName',
|
||||
'-s level', '-s testType', '-s size', '-s timeout',
|
||||
'-s dryRun', '-s random', '-s breakOnError', '-s stress',
|
||||
'-s coverage', 'class', 'notClass', 'suite', 'itName',
|
||||
'level', 'testType', 'size', 'timeout', 'dryRun', 'random',
|
||||
'breakOnError', 'stress', 'coverage'
|
||||
]);
|
||||
let targetParams = {};
|
||||
for (const key in parameters) {
|
||||
if (keySet.has(key)) {
|
||||
var newKey = key.replace("-s ", "");
|
||||
targetParams[newKey] = parameters[key];
|
||||
}
|
||||
}
|
||||
return targetParams;
|
||||
}
|
||||
translateParamsToString(parameters) {
|
||||
const keySet = new Set([
|
||||
'-s class', '-s notClass', '-s suite', '-s itName',
|
||||
'-s level', '-s testType', '-s size', '-s timeout',
|
||||
'-s dryRun', '-s random', '-s breakOnError', '-s stress',
|
||||
'-s coverage', 'class', 'notClass', 'suite', 'itName',
|
||||
'level', 'testType', 'size', 'timeout', 'dryRun', 'random',
|
||||
'breakOnError', 'stress', 'coverage'
|
||||
]);
|
||||
let targetParams = '';
|
||||
for (const key in parameters) {
|
||||
if (keySet.has(key)) {
|
||||
targetParams += ' ' + key + ' ' + parameters[key];
|
||||
}
|
||||
}
|
||||
return targetParams.trim();
|
||||
}
|
||||
|
||||
execute() {
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
ConfigService
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue