• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16{%- if item.method_return_type == "String" %}
17function compareStringTrivial(actual : String, expected : String) : boolean {
18  if (actual == expected) return true;
19  return false;
20}
21{%- endif %}
22
23{%- if item.method_return_type == "StringBuilder" %}
24function compareStringBuilderWithString(actual : StringBuilder, expected : String) : boolean {
25    let tmpString = actual.toString();
26    return expected.equals(tmpString);
27  }
28{%- endif %}
29
30{%- if item.result_nature == "primitive" or item.method_return_type == "UTF_16_CodePoint" or item.method_return_type == "char" or item.method_return_type == "byte" or item.method_return_type == "short" or item.method_return_type == "int" or item.method_return_type == "long" or item.method_return_type == "boolean" or item.method_return_type == "number" or item.method_return_type == "bigint" %}
31{%- if item.method_return_type != "void" %}
32function comparePrimitiveValue(actual : {{.item.method_return_type}}, expected : {{.item.method_return_type}}) : boolean {
33{%- else %}
34function comparePrimitiveValue(actual : {{.item.result_type}}, expected : {{.item.result_type}}) : boolean {
35{%- endif %}
36  if (actual == expected) return true;
37  return false;
38}
39{%- endif %}
40
41{%- if item.method_return_type == "float" or item.method_return_type == "double" or item.method_return_type == "Float" or item.method_return_type == "Double" %}
42const DBL_EPSILON : double = 1.0e-6;
43function compareFloatPointValue(left : double, right : double) : boolean {
44    if (left == right) {
45      return true;
46    }
47    let diff : double;
48    if (left > right) {
49       diff = left - right;
50    } else {
51       diff = right -left;
52    }
53    if (diff < DBL_EPSILON) {
54       return true;
55    } else {
56       return false;
57    }
58}
59{% endif %}
60
61{%- if item.method_return_type == "Char" or item.method_return_type == "Boolean" or item.method_return_type == "Byte" or item.method_return_type == "Short" or item.method_return_type == "Int" or item.method_return_type == "Long" or item.method_return_type == "Float" or item.method_return_type == "Double" %}
62function compareWrapperObjectValue(actual : {{.item.method_return_type}}, expected : {{.item.expected_data_item_type}}) : boolean {
63    let actual2 : {{.item.expected_data_item_type}};
64    actual2 = actual.unboxed();
65  {%- if item.method_return_type == "Float" or item.method_return_type == "Double" %}
66    return compareFloatPointValue(actual2, expected);
67  {% else %}
68    if (actual2 == expected) return true;
69    return false;
70  {%- endif %}
71}
72{%- endif %}
73
74{%- if item.method_name == "compareTo" %}
75function compareCompareToResult(actual : {{.item.method_return_type}}, expected : {{.item.method_return_type}}) : boolean {
76    if (expected > 0 && actual > 0) {
77      return true
78    } else  if (expected == 0 && actual == 0) {
79      return true
80    } else  if (expected <0 && actual <0) {
81      return true;
82    } else {
83      return false;
84    }
85 }
86 {% endif %}
87
88{%- if item.result_nature == "array" %}
89{%- if item.method_return_type != "void" %}
90function comparePrimitiveArray(actual :  {{.item.method_return_type}}, expected : {{.item.expected_test_data_item_type}}) : boolean {
91{% else %}
92function comparePrimitiveArray(actual :  {{.item.param_types[item.result_storage]}}, expected : {{.item.expected_test_data_item_type}}) : boolean {
93{%- endif %}
94   if (actual.length != expected.length) return false;
95   for (let i = 0; i < actual.length; i++) {
96     if (actual[i] != expected[i]) return false;
97   }
98
99   return true;
100 }
101{%- endif %}
102
103{%- if item.result_nature == "RegExpMatchArray" %}
104function compareRegExpMatchArray(actual : {{.item.method_return_type}}, expected : {{.item.expected_test_data_item_type}}) : boolean {
105  if (actual == null && expected == null) {
106    return true;
107  }
108  if (actual == null || expected == null) {
109    return false;
110  }
111  for (let i = 0; i < actual.length; i++) {
112     if (actual.result[i] != expected[i]) return false;
113   }
114  return true;
115}
116{%- endif %}
117
118{% if item.verify_region is defined %}
119function compareRegion(start_region : {{.item.method_return_type}}, end_region : {{.item.method_return_type}}, actual : {{.item.method_return_type}}) : boolean {
120  if ( actual {{.item.start_region_check_operation}} start_region && actual {{.item.end_region_check_operation}} end_region ) return true;
121  return false;
122}
123{% endif %}
124
125
126{% if item.verify_test_result_function == "compareToNAN" %}
127function compareToNAN(actual: {{.item.object_type}}, ignored: {{.item.object_type}}): boolean {
128    return {{.item.object_type}}.isNaN(actual);
129}
130{% endif %}
131
132{%- if item.method_return_type == "Date"  %}
133  function compareDateValueWithString(actual : Date, expected : String) : boolean {
134    let expectedTmp : String = expected + " " +  {{.item.expected_time_zone}};
135    let actualString : String = actual.toString();
136
137    if (actualString == expectedTmp) return true
138    console.println("Actual: " + actualString + ";")
139    console.println("Expected: " + expectedTmp + ";")
140    return false;
141  }
142
143{%- endif %}
144