• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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*/
15let genDir = "../../src/gen/"
16const { generateGYP } = require(genDir + "extend/binding_gyp");
17const { generateGN } = require(genDir + "extend/build_gn");
18const { generateBase } = require(genDir + "extend/tool_utility");
19var assert = require("assert");
20const { readFile } = require("../../src/gen/tools/FileRW");
21
22describe('Extend', function () {
23
24    it('test gen/extend/binding_gyp generateGYP', function () {
25        generateGYP('test/unittest', 'napitest', '/*\n* Copyright (c) 2022 Shenzhen Kaihong\n*/');
26        let data = readFile("test/unittest/binding.gyp")
27        let retJson = JSON.stringify(data)
28        let copyRight = retJson.substring(1, retJson.indexOf("Kaihong"))
29        assert.strictEqual(copyRight, "# Copyright (c) 2022 Shenzhen ")
30        let dataTest = readFile("test/unittest/test.sh")
31        let retTest = JSON.stringify(dataTest)
32        assert.strictEqual(retTest, "\"node-gyp configure build && sleep 0.5 && node --expose-gc test.js\"")
33
34    });
35
36    it('test gen/extend/build_gn generateGN', function () {
37        var fs = require("fs");
38        if (fs.existsSync('test/unittest/BUILD.gn')) {
39            fs.unlink('test/unittest/BUILD.gn', function (err) {
40                if (err) {
41                    return console.error(err);
42                }
43            });
44        }
45        let Copyright = '/*\n* Copyright (c) 2022 Shenzhen Kaihong\n*/';
46        generateGN('test/unittest', 'napitest', Copyright, 'input_sample');
47        let data = readFile("test/unittest/BUILD.gn")
48        let retJson = JSON.stringify(data)
49        let copyRight = retJson.substring(1, retJson.indexOf("Kaihong"))
50        assert.strictEqual(copyRight, "# Copyright (c) 2022 Shenzhen ")
51    });
52
53    partGenerateBase();
54});
55
56function partGenerateBase(){
57    it('test gen/extend/tool_utility generateBase', function () {
58        var fs = require("fs");
59        if (fs.existsSync('test/unittest/tool_utility.cpp')) {
60            fs.unlink('test/unittest/tool_utility.cpp', function (err) {
61                if (err) {
62                    return console.error(err);
63                }
64            });
65        }
66        if (fs.existsSync('test/unittest/tool_utility.h')) {
67            fs.unlink('test/unittest/tool_utility.h', function (err) {
68                if (err) {
69                    return console.error(err);
70                }
71            });
72        }
73        generateBase('test/unittest', '/*\n* Copyright (c) 2022 Shenzhen Kaihong\n*/');
74        let data = readFile("test/unittest/tool_utility.cpp")
75        let retJson = JSON.stringify(data)
76        let copyRight = retJson.substring(1, retJson.indexOf("Kaihong"))
77        assert.strictEqual(copyRight, "/*\\n* Copyright (c) 2022 Shenzhen ")
78
79        let data1 = readFile("test/unittest/tool_utility.h")
80        let retJson1 = JSON.stringify(data1)
81        let copyRight1 = retJson.substring(1, retJson1.indexOf("Kaihong"))
82        assert.strictEqual(copyRight1, "/*\\n* Copyright (c) 2022 Shenzhen ")
83    });
84
85}
86