index.uts 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 引入 interface.uts 文件中定义的变量 */
import { GetLog } from '../interface.uts';
import File from 'java.io.File';


export const getLog : GetLog = function (param : Any|null) : string {
  let allLog = console.getLogV2(param);
  /**
   * 移除掉干扰因素,仅返回打印对象本身的序列化结果
   */
  if(!allLog.startsWith("---BEGIN:CONSOLE---")){
	  return ""
  }
  if(!allLog.endsWith("---END:CONSOLE---")){
  	  return ""
  }
  let jsonLog = allLog
  jsonLog = jsonLog.replace("---BEGIN:CONSOLE---", "")
  jsonLog = jsonLog.replace("---END:CONSOLE---", "")
杜庆泉's avatar
杜庆泉 已提交
20
  let jsonArrayObj = JSON.parse<Array<UTSJSONObject>>(jsonLog)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  return jsonArrayObj![0].toJSONString()
}

type ParamOptions = {
	title : string,
	array : Array<string>
}

class C {
  name:string = "default"
  sayBye = function(word:string){
    console.log("sayBye",word)
  }
  sayHello(word:string){
    console.log("sayHello",word)
  }
}

杜庆泉's avatar
杜庆泉 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
/**
 * 高频对象测试,主要是系统组件对象
 */
export function frequentlyObjectTest():boolean{
	
  let typeLogRet = getLog(UTSAndroid.getUniActivity())
  console.log(typeLogRet)
  let typeLogObj = JSON.parseObject(typeLogRet)!
  
  // let typeLogObjPos = typeLogObj.getJSON("__$originalPosition")!
  // if("ParamOptions" != typeLogObjPos['name']){
  //   return false
  // }
  // /**
  //  * 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
  //  */
  // typeLogObj.set("__$originalPosition","")
  // console.log(typeLogObj.toJSONString())
  return true
}


61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
export function logObjectTest():string{
	let ret : ParamOptions = {
		title: "logObjectTest",
		array: ['1', '2', '3']
	}
  let typeLogRet = getLog(ret)
  let typeLogObj = JSON.parseObject(typeLogRet)!
  
  let typeLogObjPos = typeLogObj.getJSON("__$originalPosition")!
  if("ParamOptions" != typeLogObjPos['name']){
    return ""
  }
  /**
   * 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
   */
  typeLogObj.set("__$originalPosition","")
	return typeLogObj.toJSONString()
}


export function logFunctionTest():string{
	
	let testFun = function(){
		console.log("testFun")
	}
	return getLog(testFun)
}

export function logFileTest():string{
  return getLog(new File("/sdcard/temp/1.txt"))
}

export function logDateTest():string{
  return getLog(new Date('1998-08-08'))
}

杜庆泉's avatar
杜庆泉 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
export function logUTSJSONObjectTest():string{
  

  let classLogRet = getLog({a:1})
  let classLogObj = JSON.parseObject(classLogRet)!
  
  let classLogObjPos = classLogObj.getJSON("__$originalPosition")
  
  if(classLogObjPos == null){
    return ""
  }
  
  if("UTSJSONObject" != classLogObjPos['name']){
    return ""
  }
  
  classLogObj.set("__$originalPosition","")
  return classLogObj.toJSONString()
  
}

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
export function logClassTest():string{
  let c = new C()
  c.name="ccc"
  
  let classLogRet = getLog(c)
  let classLogObj = JSON.parseObject(classLogRet)!
  
  let classLogObjPos = classLogObj.getJSON("__$originalPosition")!
  
  if("C" != classLogObjPos['name']){
    return ""
  }
  /**
   * 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
   */
  classLogObj.set("__$originalPosition","")
  return classLogObj.toJSONString()
}