18c339a94Sopenharmony_ci/* 28c339a94Sopenharmony_ci* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. 38c339a94Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License"); 48c339a94Sopenharmony_ci* you may not use this file except in compliance with the License. 58c339a94Sopenharmony_ci* You may obtain a copy of the License at 68c339a94Sopenharmony_ci* 78c339a94Sopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0 88c339a94Sopenharmony_ci* 98c339a94Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software 108c339a94Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS, 118c339a94Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128c339a94Sopenharmony_ci* See the License for the specific language governing permissions and 138c339a94Sopenharmony_ci* limitations under the License. 148c339a94Sopenharmony_ci*/ 158c339a94Sopenharmony_cilet genDir = "../../src/gen/" 168c339a94Sopenharmony_ciconst { generateGYP } = require(genDir + "extend/binding_gyp"); 178c339a94Sopenharmony_ciconst { generateGN } = require(genDir + "extend/build_gn"); 188c339a94Sopenharmony_ciconst { generateBase } = require(genDir + "extend/tool_utility"); 198c339a94Sopenharmony_civar assert = require("assert"); 208c339a94Sopenharmony_ciconst { readFile } = require("../../src/gen/tools/FileRW"); 218c339a94Sopenharmony_ci 228c339a94Sopenharmony_cidescribe('Extend', function () { 238c339a94Sopenharmony_ci 248c339a94Sopenharmony_ci it('test gen/extend/binding_gyp generateGYP', function () { 258c339a94Sopenharmony_ci generateGYP('test/unittest', 'napitest', '/*\n* Copyright (c) 2022 Shenzhen Kaihong\n*/'); 268c339a94Sopenharmony_ci let data = readFile("test/unittest/binding.gyp") 278c339a94Sopenharmony_ci let retJson = JSON.stringify(data) 288c339a94Sopenharmony_ci let copyRight = retJson.substring(1, retJson.indexOf("Kaihong")) 298c339a94Sopenharmony_ci assert.strictEqual(copyRight, "# Copyright (c) 2022 Shenzhen ") 308c339a94Sopenharmony_ci let dataTest = readFile("test/unittest/test.sh") 318c339a94Sopenharmony_ci let retTest = JSON.stringify(dataTest) 328c339a94Sopenharmony_ci assert.strictEqual(retTest, "\"node-gyp configure build && sleep 0.5 && node --expose-gc test.js\"") 338c339a94Sopenharmony_ci 348c339a94Sopenharmony_ci }); 358c339a94Sopenharmony_ci 368c339a94Sopenharmony_ci it('test gen/extend/build_gn generateGN', function () { 378c339a94Sopenharmony_ci var fs = require("fs"); 388c339a94Sopenharmony_ci if (fs.existsSync('test/unittest/BUILD.gn')) { 398c339a94Sopenharmony_ci fs.unlink('test/unittest/BUILD.gn', function (err) { 408c339a94Sopenharmony_ci if (err) { 418c339a94Sopenharmony_ci return console.error(err); 428c339a94Sopenharmony_ci } 438c339a94Sopenharmony_ci }); 448c339a94Sopenharmony_ci } 458c339a94Sopenharmony_ci let Copyright = '/*\n* Copyright (c) 2022 Shenzhen Kaihong\n*/'; 468c339a94Sopenharmony_ci generateGN('test/unittest', 'napitest', Copyright, 'input_sample'); 478c339a94Sopenharmony_ci let data = readFile("test/unittest/BUILD.gn") 488c339a94Sopenharmony_ci let retJson = JSON.stringify(data) 498c339a94Sopenharmony_ci let copyRight = retJson.substring(1, retJson.indexOf("Kaihong")) 508c339a94Sopenharmony_ci assert.strictEqual(copyRight, "# Copyright (c) 2022 Shenzhen ") 518c339a94Sopenharmony_ci }); 528c339a94Sopenharmony_ci 538c339a94Sopenharmony_ci partGenerateBase(); 548c339a94Sopenharmony_ci}); 558c339a94Sopenharmony_ci 568c339a94Sopenharmony_cifunction partGenerateBase(){ 578c339a94Sopenharmony_ci it('test gen/extend/tool_utility generateBase', function () { 588c339a94Sopenharmony_ci var fs = require("fs"); 598c339a94Sopenharmony_ci if (fs.existsSync('test/unittest/tool_utility.cpp')) { 608c339a94Sopenharmony_ci unlinkCppFile(fs); 618c339a94Sopenharmony_ci } 628c339a94Sopenharmony_ci if (fs.existsSync('test/unittest/tool_utility.h')) { 638c339a94Sopenharmony_ci unlinkHFile(fs); 648c339a94Sopenharmony_ci } 658c339a94Sopenharmony_ci generateBase('test/unittest', '/*\n* Copyright (c) 2022 Shenzhen Kaihong\n*/'); 668c339a94Sopenharmony_ci let data = readFile("test/unittest/tool_utility.cpp") 678c339a94Sopenharmony_ci let retJson = JSON.stringify(data) 688c339a94Sopenharmony_ci let copyRight = retJson.substring(1, retJson.indexOf("Kaihong")) 698c339a94Sopenharmony_ci assert.strictEqual(copyRight, "/*\\n* Copyright (c) 2022 Shenzhen ") 708c339a94Sopenharmony_ci 718c339a94Sopenharmony_ci let data1 = readFile("test/unittest/tool_utility.h") 728c339a94Sopenharmony_ci let retJson1 = JSON.stringify(data1) 738c339a94Sopenharmony_ci let copyRight1 = retJson.substring(1, retJson1.indexOf("Kaihong")) 748c339a94Sopenharmony_ci assert.strictEqual(copyRight1, "/*\\n* Copyright (c) 2022 Shenzhen ") 758c339a94Sopenharmony_ci }); 768c339a94Sopenharmony_ci 778c339a94Sopenharmony_ci} 788c339a94Sopenharmony_cifunction unlinkHFile(fs) { 798c339a94Sopenharmony_ci fs.unlink('test/unittest/tool_utility.h', function (err) { 808c339a94Sopenharmony_ci if (err) { 818c339a94Sopenharmony_ci return console.error(err); 828c339a94Sopenharmony_ci } 838c339a94Sopenharmony_ci }); 848c339a94Sopenharmony_ci} 858c339a94Sopenharmony_ci 868c339a94Sopenharmony_cifunction unlinkCppFile(fs) { 878c339a94Sopenharmony_ci fs.unlink('test/unittest/tool_utility.cpp', function (err) { 888c339a94Sopenharmony_ci if (err) { 898c339a94Sopenharmony_ci return console.error(err); 908c339a94Sopenharmony_ci } 918c339a94Sopenharmony_ci }); 928c339a94Sopenharmony_ci} 938c339a94Sopenharmony_ci 94