Skip to content

Commit 0b7b6ae

Browse files
committed
test: setup test and assert framework
1 parent 0fe7f3a commit 0b7b6ae

File tree

11 files changed

+575
-54
lines changed

11 files changed

+575
-54
lines changed
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
1+
import { hapTasks } from "@ohos/hvigor-ohos-plugin";
22

33
export default {
4-
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5-
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
6-
}
4+
system: hapTasks /* Built-in plugin of Hvigor. It cannot be modified. */,
5+
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */
6+
};
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {}
1+
export {};
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
import { describe, expect, it, DEFAULT } from '../util/framework.test';
2-
import binding from '../util/binding';
1+
import { describe, it, DEFAULT } from "../util/framework.test";
2+
import binding from "../util/binding";
3+
import assert from "../util/assert.test";
34

45
export default function basicTypeArray() {
56
describe("basic_type_array_test", () => {
67
it("RunArray", DEFAULT, () => {
7-
const basic_types_array: ESObject = binding.basic_types_array;
8-
9-
const array = basic_types_array.createArray();
10-
expect(basic_types_array.getLength(array)).assertEqual(0);
11-
12-
const arrayWithLength = basic_types_array.createArray(10);
13-
expect(basic_types_array.getLength(arrayWithLength)).assertEqual(10);
14-
15-
basic_types_array.set(array, 0, 10);
16-
basic_types_array.set(array, 1, "test");
17-
basic_types_array.set(array, 2, 3.0);
18-
19-
expect(basic_types_array.getLength(array)).assertEqual(3);
20-
21-
expect(basic_types_array.get(array, 0)).assertEqual(10);
22-
expect(basic_types_array.get(array, 1)).assertEqual("test");
23-
expect(basic_types_array.get(array, 2)).assertEqual(3.0);
24-
25-
basic_types_array.set(array, 0, 5);
26-
27-
expect(basic_types_array.get(array, 0)).assertEqual(5);
28-
29-
expect(basic_types_array.get(array, 5)).assertUndefined();
30-
})
31-
})
32-
}
8+
const array = binding.basic_types_array.createArray();
9+
assert.strictEqual(binding.basic_types_array.getLength(array), 0);
10+
11+
// create array with length
12+
const arrayWithLength = binding.basic_types_array.createArray(10);
13+
assert.strictEqual(
14+
binding.basic_types_array.getLength(arrayWithLength),
15+
10
16+
);
17+
18+
// set function test
19+
binding.basic_types_array.set(array, 0, 10);
20+
binding.basic_types_array.set(array, 1, "test");
21+
binding.basic_types_array.set(array, 2, 3.0);
22+
23+
// check length after set data
24+
assert.strictEqual(binding.basic_types_array.getLength(array), 3);
25+
26+
// get function test
27+
assert.strictEqual(binding.basic_types_array.get(array, 0), 10);
28+
assert.strictEqual(binding.basic_types_array.get(array, 1), "test");
29+
assert.strictEqual(binding.basic_types_array.get(array, 2), 3.0);
30+
31+
// overwrite test
32+
binding.basic_types_array.set(array, 0, 5);
33+
assert.strictEqual(binding.basic_types_array.get(array, 0), 5);
34+
35+
// out of index test
36+
assert.strictEqual(binding.basic_types_array.get(array, 5), undefined);
37+
});
38+
});
39+
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1-
import { describe, expect, it, DEFAULT } from '../util/framework.test';
2-
import binding from '../util/binding';
1+
import { describe, it, DEFAULT } from "../util/framework.test";
2+
import binding from "../util/binding";
3+
import assert from "../util/assert.test";
34

45
export default function basicTypeBoolean() {
56
describe("basic_type_boolean_test", () => {
67
it("RunBoolean", DEFAULT, () => {
7-
const basic_types_boolean: ESObject = binding.basic_types_boolean;
8+
const bool1 = binding.basic_types_boolean.createBoolean(true);
9+
assert.strictEqual(bool1, true);
810

9-
expect(basic_types_boolean.createBoolean(true)).assertTrue();
10-
expect(basic_types_boolean.createBoolean(false)).assertFalse();
11+
const bool2 = binding.basic_types_boolean.createBoolean(false);
12+
assert.strictEqual(bool2, false);
1113

12-
expect(basic_types_boolean.createEmptyBoolean()).assertTrue();
14+
const emptyBoolean = binding.basic_types_boolean.createEmptyBoolean();
15+
assert.strictEqual(emptyBoolean, true);
1316

14-
expect(basic_types_boolean.createBooleanFromExistingValue(true)).assertTrue();
15-
expect(basic_types_boolean.createBoolean(false)).assertFalse();
17+
const bool3 =
18+
binding.basic_types_boolean.createBooleanFromExistingValue(true);
19+
assert.strictEqual(bool3, true);
1620

17-
expect(basic_types_boolean.createBooleanFromPrimitive(true)).assertTrue();
18-
expect(basic_types_boolean.createBoolean(false)).assertFalse();
21+
const bool4 =
22+
binding.basic_types_boolean.createBooleanFromExistingValue(false);
23+
assert.strictEqual(bool4, false);
1924

20-
expect(basic_types_boolean.operatorBool(true)).assertTrue();
21-
expect(basic_types_boolean.operatorBool(false)).assertFalse();
22-
})
23-
})
24-
}
25+
const bool5 =
26+
binding.basic_types_boolean.createBooleanFromPrimitive(true);
27+
assert.strictEqual(bool5, true);
28+
29+
const bool6 =
30+
binding.basic_types_boolean.createBooleanFromPrimitive(false);
31+
assert.strictEqual(bool6, false);
32+
33+
const bool7 = binding.basic_types_boolean.operatorBool(true);
34+
assert.strictEqual(bool7, true);
35+
36+
const bool8 = binding.basic_types_boolean.operatorBool(false);
37+
assert.strictEqual(bool8, false);
38+
});
39+
});
40+
}

0 commit comments

Comments
 (0)