From bee5eb3d97622456909efa6cc4cd7eee605fa447 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Wed, 7 Feb 2024 16:39:17 +0800 Subject: [PATCH 1/7] feat: idl support function with same name Signed-off-by: j30052480 --- framework/tools/hdi-gen/ast/ast_method.cpp | 19 ++++++++++++ framework/tools/hdi-gen/ast/ast_method.h | 13 ++++++++ .../tools/hdi-gen/codegen/code_emitter.cpp | 3 +- .../codegen/cpp_interface_code_emitter.cpp | 6 ++++ .../codegen/cpp_service_stub_code_emitter.cpp | 31 +++++++++++-------- framework/tools/hdi-gen/parser/parser.cpp | 8 +++++ 6 files changed, 66 insertions(+), 14 deletions(-) diff --git a/framework/tools/hdi-gen/ast/ast_method.cpp b/framework/tools/hdi-gen/ast/ast_method.cpp index 0dc89a367..6b0e94f7a 100644 --- a/framework/tools/hdi-gen/ast/ast_method.cpp +++ b/framework/tools/hdi-gen/ast/ast_method.cpp @@ -7,10 +7,29 @@ */ #include "ast/ast_method.h" + +#include "ast/ast_interface_type.h" #include "util/string_builder.h" namespace OHOS { namespace HDI { +bool ASTMethod::IsOverload(AutoPtr interface) +{ + if (interface == nullptr) { + return false; + } + interface = interface->GetExtendsInterface(); + while (interface != nullptr) { + for (const auto &method : interface->GetMethodsBySystem(Options::GetInstance().GetSystemLevel())) { + if (name_ == method->GetName()) { + return true; + } + } + interface = interface->GetExtendsInterface(); + } + return false; +} + void ASTMethod::AddParameter(const AutoPtr ¶meter) { if (parameter == nullptr) { diff --git a/framework/tools/hdi-gen/ast/ast_method.h b/framework/tools/hdi-gen/ast/ast_method.h index 89e44ce4a..fbda26ac4 100644 --- a/framework/tools/hdi-gen/ast/ast_method.h +++ b/framework/tools/hdi-gen/ast/ast_method.h @@ -61,6 +61,8 @@ public: return attr_->HasValue(ASTAttr::MINI); } + bool IsOverload(AutoPtr interface); + void AddParameter(const AutoPtr ¶meter); AutoPtr GetParameter(size_t index); @@ -70,12 +72,23 @@ public: return parameters_.size(); } + inline void SetCmdId(size_t cmdId) + { + cmdId_ = cmdId; + } + + inline size_t GetCmdId() + { + return cmdId_; + } + std::string Dump(const std::string &prefix) override; private: std::string name_; AutoPtr attr_ = new ASTAttr(); std::vector> parameters_; + size_t cmdId_; }; } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/codegen/code_emitter.cpp b/framework/tools/hdi-gen/codegen/code_emitter.cpp index d5645eb24..289806139 100644 --- a/framework/tools/hdi-gen/codegen/code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/code_emitter.cpp @@ -153,7 +153,8 @@ std::string CodeEmitter::InterfaceToFilePath(const std::string &interfaceName) c std::string CodeEmitter::EmitMethodCmdID(const AutoPtr &method) { - return StringHelper::Format("CMD_%s_%s", ConstantName(baseName_).c_str(), ConstantName(method->GetName()).c_str()); + return StringHelper::Format("CMD_%s_%s_%d", + ConstantName(baseName_).c_str(), ConstantName(method->GetName()).c_str(), method->GetCmdId()); } void CodeEmitter::EmitInterfaceMethodCommands(StringBuilder &sb, const std::string &prefix) diff --git a/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp index 91982cd02..16224d009 100644 --- a/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp @@ -196,6 +196,12 @@ void CppInterfaceCodeEmitter::EmitInterfaceMethodsDecl(StringBuilder &sb, const void CppInterfaceCodeEmitter::EmitInterfaceMethodDecl( const AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { + if (interface_->GetExtendsInterface() != nullptr && method->IsOverload(interface_)) { + sb.Append(prefix).AppendFormat("using %s::%s;\n", + EmitDefinitionByInterface(interface_->GetExtendsInterface(), interfaceName_).c_str(), + method->GetName().c_str()); + } + if (method->GetParameterNumber() == 0) { sb.Append(prefix).AppendFormat("virtual int32_t %s() = 0;\n", method->GetName().c_str()); } else { diff --git a/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp index e48f11c22..2bba7d98d 100644 --- a/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp @@ -150,17 +150,18 @@ void CppServiceStubCodeEmitter::EmitStubMethodDecls(StringBuilder &sb, const std void CppServiceStubCodeEmitter::EmitStubMethodDecl( const AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("int32_t %s%s(MessageParcel& %s, MessageParcel& %s, MessageOption& %s);\n", - stubName_.c_str(), method->GetName().c_str(), dataParcelName_.c_str(), replyParcelName_.c_str(), - optionName_.c_str()); + sb.Append(prefix).AppendFormat("int32_t %s%s_%d(MessageParcel& %s, MessageParcel& %s, MessageOption& %s);\n", + stubName_.c_str(), method->GetName().c_str(), method->GetCmdId(), + dataParcelName_.c_str(), replyParcelName_.c_str(), optionName_.c_str()); } void CppServiceStubCodeEmitter::EmitStubStaticMethodDecl( const AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { sb.Append(prefix).AppendFormat( - "static int32_t %s%s_(MessageParcel& %s, MessageParcel& %s, MessageOption& %s, sptr<%s> impl);\n", - stubName_.c_str(), method->GetName().c_str(), dataParcelName_.c_str(), replyParcelName_.c_str(), + "static int32_t %s%s_%d_(MessageParcel& %s, MessageParcel& %s, MessageOption& %s, sptr<%s> impl);\n", + stubName_.c_str(), method->GetName().c_str(), method->GetCmdId(), + dataParcelName_.c_str(), replyParcelName_.c_str(), optionName_.c_str(), EmitDefinitionByInterface(interface_, interfaceName_).c_str()); } @@ -344,13 +345,15 @@ void CppServiceStubCodeEmitter::EmitStubOnRequestMethodImpl(StringBuilder &sb, c AutoPtr getVerMethod = interface_->GetVersionMethod(); sb.Append(prefix + TAB + TAB).AppendFormat("case %s:\n", EmitMethodCmdID(getVerMethod).c_str()); sb.Append(prefix + TAB + TAB + TAB) - .AppendFormat("return %sStub%s(data, reply, option);\n", baseName_.c_str(), getVerMethod->GetName().c_str()); + .AppendFormat("return %sStub%s_%d(data, reply, option);\n", + baseName_.c_str(), getVerMethod->GetName().c_str(), getVerMethod->GetCmdId()); AutoPtr interface = interface_; while (interface != nullptr) { for (const auto &method : interface->GetMethodsBySystem(Options::GetInstance().GetSystemLevel())) { sb.Append(prefix + TAB + TAB).AppendFormat("case %s:\n", EmitMethodCmdID(method).c_str()); sb.Append(prefix + TAB + TAB + TAB) - .AppendFormat("return %sStub%s(data, reply, option);\n", baseName_.c_str(), method->GetName().c_str()); + .AppendFormat("return %sStub%s_%d(data, reply, option);\n", + baseName_.c_str(), method->GetName().c_str(), method->GetCmdId()); } interface = interface->GetExtendsInterface(); } @@ -393,13 +396,14 @@ void CppServiceStubCodeEmitter::EmitStubMethodImpls(StringBuilder &sb, const std void CppServiceStubCodeEmitter::EmitStubMethodImpl(AutoPtr interface, const AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("int32_t %s::%s%s(MessageParcel& %s, MessageParcel& %s, MessageOption& %s)\n", - EmitDefinitionByInterface(interface_, stubName_).c_str(), stubName_.c_str(), method->GetName().c_str(), + sb.Append(prefix).AppendFormat("int32_t %s::%s%s_%d(MessageParcel& %s, MessageParcel& %s, MessageOption& %s)\n", + EmitDefinitionByInterface(interface_, stubName_).c_str(), + stubName_.c_str(), method->GetName().c_str(), method->GetCmdId(), dataParcelName_.c_str(), replyParcelName_.c_str(), optionName_.c_str()); sb.Append(prefix).Append("{\n"); - sb.Append(prefix + TAB).AppendFormat("return %s::%s%s_(%s, %s, %s, impl_);\n", + sb.Append(prefix + TAB).AppendFormat("return %s::%s%s_%d_(%s, %s, %s, impl_);\n", EmitDefinitionByInterface(interface, stubName_).c_str(), - stubName_.c_str(), method->GetName().c_str(), + stubName_.c_str(), method->GetName().c_str(), method->GetCmdId(), dataParcelName_.c_str(), replyParcelName_.c_str(), optionName_.c_str()); sb.Append("}\n"); @@ -409,8 +413,9 @@ void CppServiceStubCodeEmitter::EmitStubStaticMethodImpl( const AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { sb.Append(prefix).AppendFormat( - "int32_t %s::%s%s_(MessageParcel& %s, MessageParcel& %s, MessageOption& %s, sptr<%s> impl)\n", - EmitDefinitionByInterface(interface_, stubName_).c_str(), stubName_.c_str(), method->GetName().c_str(), + "int32_t %s::%s%s_%d_(MessageParcel& %s, MessageParcel& %s, MessageOption& %s, sptr<%s> impl)\n", + EmitDefinitionByInterface(interface_, stubName_).c_str(), + stubName_.c_str(), method->GetName().c_str(), method->GetCmdId(), dataParcelName_.c_str(), replyParcelName_.c_str(), optionName_.c_str(), EmitDefinitionByInterface(interface_, interfaceName_).c_str()); sb.Append(prefix).Append("{\n"); diff --git a/framework/tools/hdi-gen/parser/parser.cpp b/framework/tools/hdi-gen/parser/parser.cpp index 7f95b33b1..242790fc3 100644 --- a/framework/tools/hdi-gen/parser/parser.cpp +++ b/framework/tools/hdi-gen/parser/parser.cpp @@ -546,6 +546,14 @@ AutoPtr Parser::ParseMethod(const AutoPtr &interfac lexer_.GetToken(); } + size_t methodsCount = interface->GetMethodNumber() + 1; + AutoPtr extInterface = interface->GetExtendsInterface(); + while (extInterface != nullptr) { + methodsCount += extInterface->GetMethodNumber(); + extInterface = extInterface->GetExtendsInterface(); + } + method->SetCmdId(methodsCount); + return method; } -- Gitee From 1c45397015d8581f46a0bc6bc451cc7545068f15 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Thu, 8 Feb 2024 17:17:13 +0800 Subject: [PATCH 2/7] feat: idl support function with same name Signed-off-by: j30052480 --- .../unittest/01_empty_idl/foo/v1_0/IFoo.idl | 14 ++ .../foo/v1_0/IFoo.idl | 24 ++ .../foo/v1_0/IFoo.idl | 14 ++ .../foo/v1_0/IFoo.idl | 14 ++ .../unittest/05_types_idl/foo/v1_0/IFoo.idl | 14 ++ .../06_extended_enum_idl/foo/v1_0/IFoo.idl | 14 ++ .../07_extended_struct_idl/foo/v1_0/IFoo.idl | 14 ++ .../08_overload_method_idl/foo/v1_0/IFoo.idl | 14 ++ .../tools/hdi-gen/test/unittest/unit_test.py | 229 ++++++++++++++++++ 9 files changed, 351 insertions(+) create mode 100644 framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/unit_test.py diff --git a/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..8174d0f99 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..7a0deda87 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.foo.v1_0; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] String info); + + InfoTest([in] int inParam, [out] double outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..8174d0f99 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..8174d0f99 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..8174d0f99 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..8174d0f99 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..8174d0f99 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl new file mode 100644 index 000000000..8174d0f99 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/unit_test.py b/framework/tools/hdi-gen/test/unittest/unit_test.py new file mode 100644 index 000000000..d966d91c3 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/unit_test.py @@ -0,0 +1,229 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright (c) 2023 Huawei Device Co., Ltd. +# +# HDF is dual licensed: you can use it either under the terms of +# the GPL, or the BSD license, at your option. +# See the LICENSE file in the root of this repository for complete details. + +import os +import subprocess +import time + + +def get_time_stamp(): + return int(round(time.time() * 1000)) + + +def print_success(info): + print("\033[32m{}\033[0m".format(info)) + + +def print_failure(info): + print("\033[31m{}\033[0m".format(info)) + + +def compare_file(first_file, second_file): + with open(first_file, 'r') as first_hash_file: + with open(second_file, 'r') as second_hash_file: + first_hash_info = first_hash_file.read() + second_hash_info = second_hash_file.read() + return first_hash_info == second_hash_info + + +def compare_files(first_file_path, second_file_path): + first_files = set(os.listdir(first_file_path)) + second_files = set(os.listdir(second_file_path)) + + if first_files != second_files: + return False + + for files in first_files: + if not compare_file(os.path.join(first_file_path, files), os.path.join(second_file_path, files)): + return False + return True + + +def exec_command(command): + return subprocess.getstatusoutput(command) + + +def file_exists(file_path): + return os.path.isfile(file_path) + + +def make_binary_file(file_path): + print("making hdi-gen...") + return exec_command("make --directory={} --jobs=4".format(file_path)) + + +class Test: + def __init__(self, name, working_dir): + self.name = name + self.working_dir = working_dir + self.idl_dir = os.path.join(self.working_dir, "foo") + self.output_dir = os.path.join(working_dir, "out") + self.target_dir = os.path.join(working_dir, "target") + self.command = "../../hdi-gen -s full -m ipc -l cpp -r ohos.hdi:{} -d {}".format(working_dir, self.output_dir) + + def run(self): + # please add test code here + return False + + def remove_output(self): + exec_command("rm -rf {}".format(self.output_dir)) + + def test(self): + print_success("[ RUN ] {}".format(self.name)) + start_time = get_time_stamp() + result = self.run() + end_time = get_time_stamp() + + if result: + print_success("[ OK ] {} ({}ms)".format(self.name, end_time - start_time)) + else: + print_failure("[ FAILED ] {} ({}ms)".format(self.name, end_time - start_time)) + return result + + +# compile empty idl file +class UnitTest01(Test): + def add_idl_files(self): + self.command += "-c {}".format(os.path.join(self.idl_dir, "v1_0", "IFoo.idl")) + + def run(self): + self.add_idl_files() + status, _ = exec_command(self.command) + if status != 0 and _ == "[HDI-GEN]: no idl files.": + return True + return False + + +# compile empty idl file +class UnitTest02(Test): + def add_idl_files(self): + self.command += "-c {}".format(os.path.join(self.idl_dir, "v1_0", "IFoo.idl")) + + def run(self): + self.add_idl_files() + status, _ = exec_command(self.command) + if status == 0 and compare_files(self.output_dir, self.target_dir): + return True + return False + +''' +# get hash key and print standard ouput +class TestHashGood1(Test): + def run(self): + result_hash_file_path = "./good/hash.txt" + command = "../../hdi-gen -D ./good/ -r ohos.hdi:./good/ --hash" + status, exec_result = exec_command(command) + if status != 0: + print(exec_result) + return False + temp_hash_info = exec_result + + with open(result_hash_file_path, 'r') as result_hash_file: + result_hash_info = result_hash_file.read().rstrip() + return temp_hash_info == result_hash_info + + +# get hash key and print file +class TestHashGood2(Test): + def run(self): + result_hash_file_path = "./good/hash.txt" + temp_hash_file_path = "./good/temp.txt" + command = "../../hdi-gen -D ./good/ -r ohos.hdi:./good/ --hash -o {}".format(temp_hash_file_path) + status, result = exec_command(command) + if status != 0: + print(result) + return False + + result = False + if compare_file(temp_hash_file_path, result_hash_file_path): + result = True + exec_command("rm -f ./good/temp.txt") + return result + + +# nothing idl files +class TestBadHash01(Test): + def run(self): + command = "../../hdi-gen -D ./bad_01/ -r ohos.hdi:./bad_01/ --hash" + status, _ = exec_command(command) + return status != 0 + + +# empty idl file +class TestBadHash02(Test): + def run(self): + command = "../../hdi-gen -D ./bad_02/ -r ohos.hdi:./bad_02/ --hash" + status, _ = exec_command(command) + return status != 0 + + +# the idl file has no package name +class TestBadHash03(Test): + def run(self): + command = "../../hdi-gen -D ./bad_03/ -r ohos.hdi:./bad_03/ --hash" + status, _ = exec_command(command) + return status != 0 + + +# the idl file has error package name +class TestBadHash04(Test): + def run(self): + command = "../../hdi-gen -D ./bad_04/ -r ohos.hdi:./bad_04/ --hash" + status, _ = exec_command(command) + return status != 0 +''' + +class Tests: + test_cases = [ + UnitTest01("UnitTestEmptyIdl", "01_empty_idl"), + UnitTest02("UnitTestStandardInterface", "02_standard_interface_idl"), + # UnitTest03("UnitTestStandardCallback", "03_standard_callback_idl"), + # UnitTest04("UnitTestExtendedInterface", "04_extended_interface_idl"), + # UnitTest05("UnitTestTypesIdl", "05_types_idl"), + # UnitTest06("UnitTestEnumExtension", "06_extended_enum_idl"), + # UnitTest06("UnitTestStructExtension", "07_extended_struct_idl"), + # UnitTest06("UnitTestOverloadMethod", "08_overload_method_idl"), + ] + + @staticmethod + def set_up_test_case(): + hdi_gen_file = "../../hdi-gen" + ret = file_exists(hdi_gen_file) + if not ret: + hdi_gen_path = "../../" + ret = make_binary_file(hdi_gen_path) + if not ret: + print_failure("[===========] failed to make hdi-gen") + return ret + + @staticmethod + def tear_down_test_case(): + for case in Tests.test_cases: + case.remove_output() + + @staticmethod + def test(): + test_case_num = len(Tests.test_cases) + success_case_num = 0 + print_success("[===========] start {} test".format(test_case_num)) + for test_case in Tests.test_cases: + if test_case.test(): + success_case_num += 1 + print_success("[ PASSED ] {} test".format(success_case_num)) + failure_case_num = test_case_num - success_case_num + if failure_case_num > 0: + print_failure("[ FAILED ] {} test".format(failure_case_num)) + + +if __name__ == "__main__": + if not Tests.set_up_test_case(): + print_failure("test case set up failed!") + exit(-1) + Tests.test() + Tests.tear_down_test_case() -- Gitee From a863081820610627f61cb3e353003d4fb634a177 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Sun, 18 Feb 2024 10:43:18 +0800 Subject: [PATCH 3/7] feat: idl support function with same name Signed-off-by: j30052480 --- .../tools/hdi-gen/ast/ast_struct_type.cpp | 19 +- framework/tools/hdi-gen/ast/ast_struct_type.h | 8 + framework/tools/hdi-gen/parser/parser.cpp | 33 +++- framework/tools/hdi-gen/parser/parser.h | 2 + .../unittest/01_empty_idl/foo/v1_0/IFoo.idl | 2 +- .../01_empty_idl/target/fail_output.txt | 2 + .../foo/v1_0/IFoo.idl | 2 +- .../target/foo/v1_0/foo_service.h.txt | 42 +++++ .../target/foo/v1_0/ifoo.h.txt | 96 ++++++++++ .../foo/v1_0/IFoo.idl | 14 +- .../foo/v1_0/IFooCallback.idl | 20 +++ .../foo/v1_0/foo_callback_service.h.txt | 38 ++++ .../target/foo/v1_0/foo_service.h.txt | 42 +++++ .../target/foo/v1_0/ifoo.h.txt | 96 ++++++++++ .../target/foo/v1_0/ifoo_callback.h.txt | 87 +++++++++ .../foo/v1_0/IFoo.idl | 14 +- .../foo/v1_1/IFoo.idl | 24 +++ .../target/foo/v1_0/foo_service.h.txt | 42 +++++ .../target/foo/v1_0/ifoo.h.txt | 96 ++++++++++ .../target/foo/v1_1/foo_proxy.h.txt | 64 +++++++ .../target/foo/v1_1/foo_service.h.txt | 46 +++++ .../target/foo/v1_1/foo_stub.h.txt | 66 +++++++ .../target/foo/v1_1/ifoo.h.txt | 91 ++++++++++ .../unittest/05_types_idl/foo/v1_0/IFoo.idl | 16 +- .../unittest/05_types_idl/foo/v1_0/Types.idl | 27 +++ .../target/foo/v1_0/types.cpp.txt | 75 ++++++++ .../05_types_idl/target/foo/v1_0/types.h.txt | 75 ++++++++ .../06_extended_enum_idl/foo/v1_0/IFoo.idl | 16 +- .../06_extended_enum_idl/foo/v1_0/Types.idl | 32 ++++ .../target/foo/v1_0/types.cpp.txt | 75 ++++++++ .../target/foo/v1_0/types.h.txt | 82 +++++++++ .../07_extended_struct_idl/foo/v1_0/IFoo.idl | 16 +- .../07_extended_struct_idl/foo/v1_0/Types.idl | 32 ++++ .../target/foo/v1_0/types.cpp.txt | 141 +++++++++++++++ .../target/foo/v1_0/types.h.txt | 87 +++++++++ .../08_overload_method_idl/foo/v1_0/IFoo.idl | 14 +- .../08_overload_method_idl/foo/v1_1/IFoo.idl | 24 +++ .../target/foo/v1_1/foo_proxy.h.txt | 65 +++++++ .../target/foo/v1_1/foo_service.h.txt | 46 +++++ .../target/foo/v1_1/foo_stub.h.txt | 66 +++++++ .../target/foo/v1_1/ifoo.h.txt | 93 ++++++++++ .../tools/hdi-gen/test/unittest/unit_test.py | 167 +++++++++--------- 42 files changed, 1998 insertions(+), 97 deletions(-) create mode 100644 framework/tools/hdi-gen/test/unittest/01_empty_idl/target/fail_output.txt create mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFooCallback.idl create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_1/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/Types.idl create mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt create mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/Types.idl create mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt create mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/Types.idl create mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt create mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_1/IFoo.idl create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt diff --git a/framework/tools/hdi-gen/ast/ast_struct_type.cpp b/framework/tools/hdi-gen/ast/ast_struct_type.cpp index ff7f14bdc..7b8f277c3 100644 --- a/framework/tools/hdi-gen/ast/ast_struct_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_struct_type.cpp @@ -11,6 +11,19 @@ namespace OHOS { namespace HDI { +void ASTStructType::SetParentType(const AutoPtr &parentType) +{ + if (parentType == nullptr) { + return; + } + + std::vector>> parentMembers = parentType->GetMembers(); + for (auto member : parentMembers) { + AddMember(std::get<1>(member), std::get<0>(member)); + } + parentType_ = parentType; +} + void ASTStructType::AddMember(const AutoPtr &typeName, std::string name) { for (auto it : members_) { @@ -34,7 +47,11 @@ std::string ASTStructType::Dump(const std::string &prefix) { StringBuilder sb; sb.Append(prefix).Append(attr_->Dump(prefix)).Append(" "); - sb.AppendFormat("struct %s {\n", name_.c_str()); + if (parentType_ == nullptr) { + sb.AppendFormat("struct %s {\n", name_.c_str()); + } else { + sb.AppendFormat("struct %s : %s {\n", name_.c_str(), parentType_->ToString().c_str()); + } if (members_.size() > 0) { for (auto it : members_) { sb.Append(prefix + " "); diff --git a/framework/tools/hdi-gen/ast/ast_struct_type.h b/framework/tools/hdi-gen/ast/ast_struct_type.h index 81ad65be2..b6fe4cdaa 100644 --- a/framework/tools/hdi-gen/ast/ast_struct_type.h +++ b/framework/tools/hdi-gen/ast/ast_struct_type.h @@ -49,8 +49,15 @@ public: return attr_ != nullptr ? attr_->HasValue(ASTAttr::LITE) : false; } + void SetParentType(const AutoPtr &parentType); + void AddMember(const AutoPtr &typeName, std::string name); + inline std::vector>> GetMembers() + { + return members_; + } + inline size_t GetMemberNumber() { return members_.size(); @@ -123,6 +130,7 @@ public: private: AutoPtr attr_; std::vector>> members_; + AutoPtr parentType_; }; } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/parser/parser.cpp b/framework/tools/hdi-gen/parser/parser.cpp index 242790fc3..351c255b4 100644 --- a/framework/tools/hdi-gen/parser/parser.cpp +++ b/framework/tools/hdi-gen/parser/parser.cpp @@ -1124,7 +1124,10 @@ void Parser::ParseStructDeclaration(const AttrSet &attrs) } token = lexer_.PeekToken(); - if (token.kind != TokenType::BRACES_LEFT) { + if (token.kind == TokenType::COLON) { + AutoPtr parentType = ParseStructParentType(); + structType->SetParentType(parentType); + } else if (token.kind != TokenType::BRACES_LEFT) { LogError(token, StringHelper::Format("expected '{' before '%s' token", token.value.c_str())); } else { lexer_.GetToken(); @@ -1150,6 +1153,34 @@ void Parser::ParseStructDeclaration(const AttrSet &attrs) ast_->AddTypeDefinition(structType.Get()); } +AutoPtr Parser::ParseStructParentType() +{ + lexer_.GetToken(); + Token token = lexer_.PeekToken(); + AutoPtr baseType = ParseType(); + if (baseType == nullptr) { + LogError(token, StringHelper::Format("expected base type name before '{' token")); + return nullptr; + } + + switch (baseType->GetTypeKind()) { + case TypeKind::TYPE_STRUCT: + break; + default: { + LogError(token, StringHelper::Format("illegal base type of struct: '%s'", baseType->ToString().c_str())); + lexer_.SkipUntilToken(TokenType::BRACES_LEFT); + } + } + + AutoPtr parentType = dynamic_cast(baseType.Get()); + token = lexer_.PeekToken(); + if (token.kind != TokenType::BRACES_LEFT) { + LogError(token, StringHelper::Format("expected '{' before '%s' token", token.value.c_str())); + } + lexer_.GetToken(); + return parentType; +} + void Parser::ParseStructMember(const AutoPtr &structType) { Token token = lexer_.PeekToken(); diff --git a/framework/tools/hdi-gen/parser/parser.h b/framework/tools/hdi-gen/parser/parser.h index 9b307f6ee..b8870966c 100644 --- a/framework/tools/hdi-gen/parser/parser.h +++ b/framework/tools/hdi-gen/parser/parser.h @@ -134,6 +134,8 @@ private: // parse declaration of struct void ParseStructDeclaration(const AttrSet &attrs = {}); + AutoPtr ParseStructParentType(); + void ParseStructMember(const AutoPtr &structType); // parse declaration of union diff --git a/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl index 8174d0f99..96d02c8e1 100644 --- a/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/framework/tools/hdi-gen/test/unittest/01_empty_idl/target/fail_output.txt b/framework/tools/hdi-gen/test/unittest/01_empty_idl/target/fail_output.txt new file mode 100644 index 000000000..3c62fc974 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/01_empty_idl/target/fail_output.txt @@ -0,0 +1,2 @@ +[HDI-GEN]: IFoo.idl:1:1: expected 'package' before '' token +[MAIN]: failed to preprocess \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl index 7a0deda87..301e8791e 100644 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt new file mode 100644 index 000000000..0e5d0ee8d --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOSERVICE_H +#define OHOS_HDI_FOO_V1_0_FOOSERVICE_H + +#include "v1_0/ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +class FooService : public OHOS::HDI::Foo::V1_0::IFoo { +public: + FooService() = default; + virtual ~FooService() = default; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOSERVICE_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt new file mode 100644 index 000000000..0e9b64b0e --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_IFOO_H +#define OHOS_HDI_FOO_V1_0_IFOO_H + +#include +#include +#include +#include + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +using namespace OHOS; +using namespace OHOS::HDI; + +enum { + CMD_FOO_GET_VERSION_0 = 0, + CMD_FOO_PING_1 = 1, + CMD_FOO_GET_DATA_2 = 2, + CMD_FOO_INFO_TEST_3 = 3, +}; + +class IFoo : public HdiBase { +public: + DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFoo"); + + virtual ~IFoo() = default; + + static sptr Get(bool isStub = false); + static sptr Get(const std::string &serviceName, bool isStub = false); + + virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg) = 0; + + virtual int32_t GetData(std::string& info) = 0; + + virtual int32_t InfoTest(int32_t inParam, double& outParam) = 0; + + virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) + { + majorVer = 1; + minorVer = 0; + return HDF_SUCCESS; + } + + virtual bool IsProxy() + { + return false; + } + + virtual const std::u16string GetDesc() + { + return metaDescriptor_; + } +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl index 8174d0f99..301e8791e 100644 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -11,4 +11,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ \ No newline at end of file + */ + +package ohos.hdi.foo.v1_0; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] String info); + + InfoTest([in] int inParam, [out] double outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFooCallback.idl b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFooCallback.idl new file mode 100644 index 000000000..2e991fcc7 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFooCallback.idl @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.foo.v1_0; + +[callback] interface IFooCallback { + PushData([in] String message); +} \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt new file mode 100644 index 000000000..e389f491b --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOCALLBACKSERVICE_H +#define OHOS_HDI_FOO_V1_0_FOOCALLBACKSERVICE_H + +#include "v1_0/ifoo_callback.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +class FooCallbackService : public OHOS::HDI::Foo::V1_0::IFooCallback { +public: + FooCallbackService() = default; + virtual ~FooCallbackService() = default; + + int32_t PushData(const std::string& message) override; + +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOCALLBACKSERVICE_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt new file mode 100644 index 000000000..0e5d0ee8d --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOSERVICE_H +#define OHOS_HDI_FOO_V1_0_FOOSERVICE_H + +#include "v1_0/ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +class FooService : public OHOS::HDI::Foo::V1_0::IFoo { +public: + FooService() = default; + virtual ~FooService() = default; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOSERVICE_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt new file mode 100644 index 000000000..0e9b64b0e --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_IFOO_H +#define OHOS_HDI_FOO_V1_0_IFOO_H + +#include +#include +#include +#include + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +using namespace OHOS; +using namespace OHOS::HDI; + +enum { + CMD_FOO_GET_VERSION_0 = 0, + CMD_FOO_PING_1 = 1, + CMD_FOO_GET_DATA_2 = 2, + CMD_FOO_INFO_TEST_3 = 3, +}; + +class IFoo : public HdiBase { +public: + DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFoo"); + + virtual ~IFoo() = default; + + static sptr Get(bool isStub = false); + static sptr Get(const std::string &serviceName, bool isStub = false); + + virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg) = 0; + + virtual int32_t GetData(std::string& info) = 0; + + virtual int32_t InfoTest(int32_t inParam, double& outParam) = 0; + + virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) + { + majorVer = 1; + minorVer = 0; + return HDF_SUCCESS; + } + + virtual bool IsProxy() + { + return false; + } + + virtual const std::u16string GetDesc() + { + return metaDescriptor_; + } +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt new file mode 100644 index 000000000..6334b6e06 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_IFOOCALLBACK_H +#define OHOS_HDI_FOO_V1_0_IFOOCALLBACK_H + +#include +#include +#include +#include + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +using namespace OHOS; +using namespace OHOS::HDI; + +enum { + CMD_FOO_CALLBACK_GET_VERSION_0 = 0, + CMD_FOO_CALLBACK_PUSH_DATA_1 = 1, +}; + +class IFooCallback : public HdiBase { +public: + DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFooCallback"); + + virtual ~IFooCallback() = default; + + virtual int32_t PushData(const std::string& message) = 0; + + virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) + { + majorVer = 1; + minorVer = 0; + return HDF_SUCCESS; + } + + virtual bool IsProxy() + { + return false; + } + + virtual const std::u16string GetDesc() + { + return metaDescriptor_; + } +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_IFOOCALLBACK_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl index 8174d0f99..301e8791e 100644 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -11,4 +11,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ \ No newline at end of file + */ + +package ohos.hdi.foo.v1_0; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] String info); + + InfoTest([in] int inParam, [out] double outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_1/IFoo.idl b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_1/IFoo.idl new file mode 100644 index 000000000..b58ae9415 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_1/IFoo.idl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.foo.v1_1; + +import ohos.hdi.foo.v1_0.IFoo; + +interface IFoo extends ohos.hdi.foo.v1_0.IFoo { + TestPingV1_1([in] String sendMsg,[out] String recvMsg); + + TestGetData([out] String info); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt new file mode 100644 index 000000000..0e5d0ee8d --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_FOOSERVICE_H +#define OHOS_HDI_FOO_V1_0_FOOSERVICE_H + +#include "v1_0/ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +class FooService : public OHOS::HDI::Foo::V1_0::IFoo { +public: + FooService() = default; + virtual ~FooService() = default; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_FOOSERVICE_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt new file mode 100644 index 000000000..0e9b64b0e --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_IFOO_H +#define OHOS_HDI_FOO_V1_0_IFOO_H + +#include +#include +#include +#include + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { +using namespace OHOS; +using namespace OHOS::HDI; + +enum { + CMD_FOO_GET_VERSION_0 = 0, + CMD_FOO_PING_1 = 1, + CMD_FOO_GET_DATA_2 = 2, + CMD_FOO_INFO_TEST_3 = 3, +}; + +class IFoo : public HdiBase { +public: + DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFoo"); + + virtual ~IFoo() = default; + + static sptr Get(bool isStub = false); + static sptr Get(const std::string &serviceName, bool isStub = false); + + virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg) = 0; + + virtual int32_t GetData(std::string& info) = 0; + + virtual int32_t InfoTest(int32_t inParam, double& outParam) = 0; + + virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) + { + majorVer = 1; + minorVer = 0; + return HDF_SUCCESS; + } + + virtual bool IsProxy() + { + return false; + } + + virtual const std::u16string GetDesc() + { + return metaDescriptor_; + } +}; +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt new file mode 100644 index 000000000..b2a91b643 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H +#define OHOS_HDI_FOO_V1_1_FOOPROXY_H + +#include "v1_0/foo_proxy.h" +#include "v1_1/ifoo.h" +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + +class FooProxy : public IProxyBroker { +public: + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) {} + + virtual ~FooProxy() = default; + + inline bool IsProxy() override + { + return true; + } + + int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t TestGetData(std::string& info) override; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t TestPingV1_1_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); + + static int32_t TestGetData_(std::string& info, const sptr remote); + +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt new file mode 100644 index 000000000..fdd5ca0d4 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOSERVICE_H +#define OHOS_HDI_FOO_V1_1_FOOSERVICE_H + +#include "v1_1/ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { +class FooService : public OHOS::HDI::Foo::V1_1::IFoo { +public: + FooService() = default; + virtual ~FooService() = default; + + int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t TestGetData(std::string& info) override; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + +}; +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOSERVICE_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt new file mode 100644 index 000000000..807d05b75 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOSTUB_H +#define OHOS_HDI_FOO_V1_1_FOOSTUB_H + +#include +#include +#include +#include +#include +#include "v1_0/foo_stub.h" +#include "v1_1/ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + +using namespace OHOS; +class FooStub : public IPCObjectStub { +public: + explicit FooStub(const sptr &impl); + virtual ~FooStub(); + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + static int32_t FooStubTestPingV1_1_4_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); + + static int32_t FooStubTestGetData_5_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); + +private: + int32_t FooStubTestPingV1_1_4(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubTestGetData_5(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubPing_1(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubGetData_2(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubInfoTest_3(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubGetVersion_0(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + + static inline ObjectDelegator objDelegator_; + sptr impl_; +}; +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOSTUB_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt new file mode 100644 index 000000000..39bc8b46f --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_IFOO_H +#define OHOS_HDI_FOO_V1_1_IFOO_H + +#include +#include +#include +#include +#include "foo/v1_0/ifoo.h" + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { +using namespace OHOS; +using namespace OHOS::HDI; +using namespace OHOS::HDI::Foo::V1_0; + +enum { + CMD_FOO_TEST_PING_V1_1_4 = 4, + CMD_FOO_TEST_GET_DATA_5 = 5, +}; + +class IFoo : public OHOS::HDI::Foo::V1_0::IFoo { +public: + DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_1.IFoo"); + + virtual ~IFoo() = default; + + static sptr Get(bool isStub = false); + static sptr Get(const std::string &serviceName, bool isStub = false); + + static sptr CastFrom(const sptr &parent); + + virtual int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) = 0; + + virtual int32_t TestGetData(std::string& info) = 0; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override + { + majorVer = 1; + minorVer = 1; + return HDF_SUCCESS; + } + + const std::u16string GetDesc() override + { + return metaDescriptor_; + } +}; +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl index 8174d0f99..6ed1975b3 100644 --- a/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -11,4 +11,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ \ No newline at end of file + */ + +package ohos.hdi.foo.v1_0; + +import ohos.hdi.foo.v1_0.Types; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] struct FooInfo info); + + InfoTest([in] struct FooInfo inParam, [out] struct FooInfo outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/Types.idl b/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/Types.idl new file mode 100644 index 000000000..ed068503d --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/Types.idl @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.foo.v1_0; + +enum FooType { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, +}; + +struct FooInfo { + unsigned int id; + String name; + enum FooType type; +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt new file mode 100644 index 000000000..3ba16174e --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "v1_0/types.h" +#include +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + + +bool FooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) +{ + if (!data.WriteUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: write dataBlock.id failed!", __func__); + return false; + } + + if (!data.WriteCString(dataBlock.name.c_str())) { + HDF_LOGE("%{public}s: write dataBlock.name failed!", __func__); + return false; + } + + if (!data.WriteUint64(static_cast(dataBlock.type))) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + return true; +} + +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) +{ + if (!data.ReadUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: read dataBlock.id failed!", __func__); + return false; + } + + const char* nameCp = data.ReadCString(); + if (nameCp == nullptr) { + HDF_LOGE("%{public}s: read nameCp failed", __func__); + return false; + } + dataBlock.name = nameCp; + + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + dataBlock.type = static_cast(enumTmp); + } + return true; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt new file mode 100644 index 000000000..55eb32f0a --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_TYPES_H +#define OHOS_HDI_FOO_V1_0_TYPES_H + +#include +#include +#include + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +class MessageParcel; +} + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +using namespace OHOS; + +enum FooType : int32_t { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, +}; + +struct FooInfo { + uint32_t id; + std::string name; + OHOS::HDI::Foo::V1_0::FooType type; +}; + +bool FooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); + +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_TYPES_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl index 8174d0f99..6ed1975b3 100644 --- a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -11,4 +11,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ \ No newline at end of file + */ + +package ohos.hdi.foo.v1_0; + +import ohos.hdi.foo.v1_0.Types; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] struct FooInfo info); + + InfoTest([in] struct FooInfo inParam, [out] struct FooInfo outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/Types.idl b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/Types.idl new file mode 100644 index 000000000..0486a8572 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/Types.idl @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.foo.v1_0; + +enum FooType { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, +}; + +enum FooType2 : FooType{ + FOO_TYPE_THREE = 3, + FOO_TYPE_FOUR = 4, +}; + +struct FooInfo { + unsigned int id; + String name; + enum FooType2 type; +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt new file mode 100644 index 000000000..14f7f8a35 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "v1_0/types.h" +#include +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + + +bool FooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) +{ + if (!data.WriteUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: write dataBlock.id failed!", __func__); + return false; + } + + if (!data.WriteCString(dataBlock.name.c_str())) { + HDF_LOGE("%{public}s: write dataBlock.name failed!", __func__); + return false; + } + + if (!data.WriteUint64(static_cast(dataBlock.type))) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + return true; +} + +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) +{ + if (!data.ReadUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: read dataBlock.id failed!", __func__); + return false; + } + + const char* nameCp = data.ReadCString(); + if (nameCp == nullptr) { + HDF_LOGE("%{public}s: read nameCp failed", __func__); + return false; + } + dataBlock.name = nameCp; + + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + dataBlock.type = static_cast(enumTmp); + } + return true; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt new file mode 100644 index 000000000..8c2ba001c --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_TYPES_H +#define OHOS_HDI_FOO_V1_0_TYPES_H + +#include +#include +#include + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +class MessageParcel; +} + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +using namespace OHOS; + +enum FooType : int32_t { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, +}; + +enum FooType2 : int32_t { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, + FOO_TYPE_THREE = 3, + FOO_TYPE_FOUR = 4, +}; + +struct FooInfo { + uint32_t id; + std::string name; + OHOS::HDI::Foo::V1_0::FooType2 type; +}; + +bool FooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); + +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_TYPES_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl index 8174d0f99..884fa5a04 100644 --- a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -11,4 +11,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ \ No newline at end of file + */ + +package ohos.hdi.foo.v1_0; + +import ohos.hdi.foo.v1_0.Types; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] struct ExtendedFooInfo info); + + InfoTest([in] struct ExtendedFooInfo inParam, [out] struct ExtendedFooInfo outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/Types.idl b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/Types.idl new file mode 100644 index 000000000..eb20b8cd1 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/Types.idl @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.foo.v1_0; + +enum FooType { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, +}; + +struct FooInfo { + unsigned int id; + String name; + enum FooType type; +}; + +struct ExtendedFooInfo : FooInfo { + unsigned int extendedId; + String extendedInfo; +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt new file mode 100644 index 000000000..4bcb016f4 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "v1_0/types.h" +#include +#include +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + + + +bool FooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) +{ + if (!data.WriteUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: write dataBlock.id failed!", __func__); + return false; + } + + if (!data.WriteCString(dataBlock.name.c_str())) { + HDF_LOGE("%{public}s: write dataBlock.name failed!", __func__); + return false; + } + + if (!data.WriteUint64(static_cast(dataBlock.type))) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + return true; +} + +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) +{ + if (!data.ReadUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: read dataBlock.id failed!", __func__); + return false; + } + + const char* nameCp = data.ReadCString(); + if (nameCp == nullptr) { + HDF_LOGE("%{public}s: read nameCp failed", __func__); + return false; + } + dataBlock.name = nameCp; + + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + dataBlock.type = static_cast(enumTmp); + } + return true; +} + +bool ExtendedFooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock) +{ + if (!data.WriteUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: write dataBlock.id failed!", __func__); + return false; + } + + if (!data.WriteCString(dataBlock.name.c_str())) { + HDF_LOGE("%{public}s: write dataBlock.name failed!", __func__); + return false; + } + + if (!data.WriteUint64(static_cast(dataBlock.type))) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + + if (!data.WriteUint32(dataBlock.extendedId)) { + HDF_LOGE("%{public}s: write dataBlock.extendedId failed!", __func__); + return false; + } + + if (!data.WriteCString(dataBlock.extendedInfo.c_str())) { + HDF_LOGE("%{public}s: write dataBlock.extendedInfo failed!", __func__); + return false; + } + return true; +} + +bool ExtendedFooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock) +{ + if (!data.ReadUint32(dataBlock.id)) { + HDF_LOGE("%{public}s: read dataBlock.id failed!", __func__); + return false; + } + + const char* nameCp = data.ReadCString(); + if (nameCp == nullptr) { + HDF_LOGE("%{public}s: read nameCp failed", __func__); + return false; + } + dataBlock.name = nameCp; + + { + uint64_t enumTmp = 0; + if (!data.ReadUint64(enumTmp)) { + HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); + return false; + } + dataBlock.type = static_cast(enumTmp); + } + + if (!data.ReadUint32(dataBlock.extendedId)) { + HDF_LOGE("%{public}s: read dataBlock.extendedId failed!", __func__); + return false; + } + + const char* extendedInfoCp = data.ReadCString(); + if (extendedInfoCp == nullptr) { + HDF_LOGE("%{public}s: read extendedInfoCp failed", __func__); + return false; + } + dataBlock.extendedInfo = extendedInfoCp; + return true; +} + +} // V1_0 +} // Foo +} // HDI +} // OHOS diff --git a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt new file mode 100644 index 000000000..e0717a4cd --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_0_TYPES_H +#define OHOS_HDI_FOO_V1_0_TYPES_H + +#include +#include +#include + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +class MessageParcel; +} + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_0 { + +using namespace OHOS; + +enum FooType : int32_t { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, +}; + +struct FooInfo { + uint32_t id; + std::string name; + OHOS::HDI::Foo::V1_0::FooType type; +}; + +struct ExtendedFooInfo { + uint32_t id; + std::string name; + OHOS::HDI::Foo::V1_0::FooType type; + uint32_t extendedId; + std::string extendedInfo; +}; + +bool FooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); + +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); + +bool ExtendedFooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock); + +bool ExtendedFooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock); + +} // V1_0 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_0_TYPES_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl index 8174d0f99..301e8791e 100644 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -11,4 +11,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ \ No newline at end of file + */ + +package ohos.hdi.foo.v1_0; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] String info); + + InfoTest([in] int inParam, [out] double outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_1/IFoo.idl b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_1/IFoo.idl new file mode 100644 index 000000000..ff3783f02 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_1/IFoo.idl @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.hdi.foo.v1_1; + +import ohos.hdi.foo.v1_0.IFoo; + +interface IFoo extends ohos.hdi.foo.v1_0.IFoo { + Ping([in] String sendMsg,[out] String recvMsg, [in] int code); + + GetData([out] String info, [out] String ver); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt new file mode 100644 index 000000000..d5f15ed81 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H +#define OHOS_HDI_FOO_V1_1_FOOPROXY_H + +#include "v1_0/foo_proxy.h" +#include "v1_1/ifoo.h" +#include + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + +class FooProxy : public IProxyBroker { +public: + explicit FooProxy(const sptr& remote) : IProxyBroker(remote) {} + + virtual ~FooProxy() = default; + + inline bool IsProxy() override + { + return true; + } + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) override; + + int32_t GetData(std::string& info, std::string& ver) override; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; + + static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, int32_t code, + const sptr remote); + + static int32_t GetData_(std::string& info, std::string& ver, const sptr remote); + +private: + static inline BrokerDelegator delegator_; +}; + +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt new file mode 100644 index 000000000..76abf0f82 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOSERVICE_H +#define OHOS_HDI_FOO_V1_1_FOOSERVICE_H + +#include "v1_1/ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { +class FooService : public OHOS::HDI::Foo::V1_1::IFoo { +public: + FooService() = default; + virtual ~FooService() = default; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) override; + + int32_t GetData(std::string& info, std::string& ver) override; + + int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; + + int32_t GetData(std::string& info) override; + + int32_t InfoTest(int32_t inParam, double& outParam) override; + +}; +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOSERVICE_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt new file mode 100644 index 000000000..2b988d71f --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_FOOSTUB_H +#define OHOS_HDI_FOO_V1_1_FOOSTUB_H + +#include +#include +#include +#include +#include +#include "v1_0/foo_stub.h" +#include "v1_1/ifoo.h" + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { + +using namespace OHOS; +class FooStub : public IPCObjectStub { +public: + explicit FooStub(const sptr &impl); + virtual ~FooStub(); + + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + static int32_t FooStubPing_4_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); + + static int32_t FooStubGetData_5_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); + +private: + int32_t FooStubPing_4(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubGetData_5(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubPing_1(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubGetData_2(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubInfoTest_3(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + int32_t FooStubGetVersion_0(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); + + + static inline ObjectDelegator objDelegator_; + sptr impl_; +}; +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_FOOSTUB_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt new file mode 100644 index 000000000..22527f1cd --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_FOO_V1_1_IFOO_H +#define OHOS_HDI_FOO_V1_1_IFOO_H + +#include +#include +#include +#include +#include "foo/v1_0/ifoo.h" + +#ifndef HDI_BUFF_MAX_SIZE +#define HDI_BUFF_MAX_SIZE (1024 * 200) +#endif + +#ifndef HDI_CHECK_VALUE_RETURN +#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ + if ((lv) compare (rv)) { \ + return ret; \ + } \ +} while (false) +#endif + +#ifndef HDI_CHECK_VALUE_RET_GOTO +#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ + if ((lv) compare (rv)) { \ + ret = value; \ + goto table; \ + } \ +} while (false) +#endif + +namespace OHOS { +namespace HDI { +namespace Foo { +namespace V1_1 { +using namespace OHOS; +using namespace OHOS::HDI; +using namespace OHOS::HDI::Foo::V1_0; + +enum { + CMD_FOO_PING_4 = 4, + CMD_FOO_GET_DATA_5 = 5, +}; + +class IFoo : public OHOS::HDI::Foo::V1_0::IFoo { +public: + DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_1.IFoo"); + + virtual ~IFoo() = default; + + static sptr Get(bool isStub = false); + static sptr Get(const std::string &serviceName, bool isStub = false); + + static sptr CastFrom(const sptr &parent); + + using OHOS::HDI::Foo::V1_0::IFoo::Ping; + virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) = 0; + + using OHOS::HDI::Foo::V1_0::IFoo::GetData; + virtual int32_t GetData(std::string& info, std::string& ver) = 0; + + int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override + { + majorVer = 1; + minorVer = 1; + return HDF_SUCCESS; + } + + const std::u16string GetDesc() override + { + return metaDescriptor_; + } +}; +} // V1_1 +} // Foo +} // HDI +} // OHOS + +#endif // OHOS_HDI_FOO_V1_1_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/unit_test.py b/framework/tools/hdi-gen/test/unittest/unit_test.py index d966d91c3..d31f936c9 100644 --- a/framework/tools/hdi-gen/test/unittest/unit_test.py +++ b/framework/tools/hdi-gen/test/unittest/unit_test.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2024 Huawei Device Co., Ltd. # # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. @@ -32,15 +32,18 @@ def compare_file(first_file, second_file): return first_hash_info == second_hash_info -def compare_files(first_file_path, second_file_path): - first_files = set(os.listdir(first_file_path)) - second_files = set(os.listdir(second_file_path)) +def compare_target_files(first_file_path, second_file_path): + first_files = get_all_files(first_file_path) + second_files = get_all_files(second_file_path) - if first_files != second_files: - return False + first_files = set([file[len(first_file_path):] for file in first_files]) + second_files = set([file[len(second_file_path):-4] for file in second_files]) + + common_files = first_files & second_files - for files in first_files: - if not compare_file(os.path.join(first_file_path, files), os.path.join(second_file_path, files)): + for files in common_files: + if not compare_file(first_file_path + files, second_file_path + files + ".txt"): + print(first_file_path + files, second_file_path + files + ".txt") return False return True @@ -58,6 +61,27 @@ def make_binary_file(file_path): return exec_command("make --directory={} --jobs=4".format(file_path)) +def get_all_files(path): + file_list = [] + for item in os.listdir(path): + item = os.path.join(path, item) + if os.path.isdir(item): + file_list += get_all_files(item) + else: + file_list.append(item) + return file_list + + +def get_all_idl_files(idl_path): + file_list = get_all_files(idl_path) + idl_file_list = [] + for file in file_list: + if os.path.splitext(file)[-1] == ".idl": + idl_file_list.append(file) + return idl_file_list + + + class Test: def __init__(self, name, working_dir): self.name = name @@ -71,8 +95,33 @@ class Test: # please add test code here return False + def run_success(self): + self.add_idl_files() + status, _ = exec_command(self.command) + if status == 0 and compare_target_files(self.output_dir, self.target_dir): + return True + return False + + def run_fail(self): + self.add_idl_files() + status, _ = exec_command(self.command) + + expected_fail_output = "" + with open(os.path.join(self.target_dir, "fail_output.txt"), 'r') as target_output: + expected_fail_output = target_output.read() + + if status != 0 and expected_fail_output == _: + return True + return False + def remove_output(self): exec_command("rm -rf {}".format(self.output_dir)) + return True + + def add_idl_files(self): + idl_list = get_all_idl_files(self.idl_dir) + for idl in idl_list: + self.command += " -c {}".format(idl) def test(self): print_success("[ RUN ] {}".format(self.name)) @@ -89,106 +138,62 @@ class Test: # compile empty idl file class UnitTest01(Test): - def add_idl_files(self): - self.command += "-c {}".format(os.path.join(self.idl_dir, "v1_0", "IFoo.idl")) - def run(self): - self.add_idl_files() - status, _ = exec_command(self.command) - if status != 0 and _ == "[HDI-GEN]: no idl files.": - return True - return False + return self.run_fail() -# compile empty idl file +# standard interface idl file class UnitTest02(Test): - def add_idl_files(self): - self.command += "-c {}".format(os.path.join(self.idl_dir, "v1_0", "IFoo.idl")) - def run(self): - self.add_idl_files() - status, _ = exec_command(self.command) - if status == 0 and compare_files(self.output_dir, self.target_dir): - return True - return False + return self.run_success() -''' -# get hash key and print standard ouput -class TestHashGood1(Test): - def run(self): - result_hash_file_path = "./good/hash.txt" - command = "../../hdi-gen -D ./good/ -r ohos.hdi:./good/ --hash" - status, exec_result = exec_command(command) - if status != 0: - print(exec_result) - return False - temp_hash_info = exec_result - with open(result_hash_file_path, 'r') as result_hash_file: - result_hash_info = result_hash_file.read().rstrip() - return temp_hash_info == result_hash_info +# standard callback idl file +class UnitTest03(Test): + def run(self): + return self.run_success() -# get hash key and print file -class TestHashGood2(Test): +# extended interface idl file +class UnitTest04(Test): def run(self): - result_hash_file_path = "./good/hash.txt" - temp_hash_file_path = "./good/temp.txt" - command = "../../hdi-gen -D ./good/ -r ohos.hdi:./good/ --hash -o {}".format(temp_hash_file_path) - status, result = exec_command(command) - if status != 0: - print(result) - return False + return self.run_success() - result = False - if compare_file(temp_hash_file_path, result_hash_file_path): - result = True - exec_command("rm -f ./good/temp.txt") - return result - -# nothing idl files -class TestBadHash01(Test): +# interface with types idl file +class UnitTest05(Test): def run(self): - command = "../../hdi-gen -D ./bad_01/ -r ohos.hdi:./bad_01/ --hash" - status, _ = exec_command(command) - return status != 0 + return self.run_success() -# empty idl file -class TestBadHash02(Test): +# extended enum idl file +class UnitTest06(Test): def run(self): - command = "../../hdi-gen -D ./bad_02/ -r ohos.hdi:./bad_02/ --hash" - status, _ = exec_command(command) - return status != 0 + return self.run_success() -# the idl file has no package name -class TestBadHash03(Test): +# extended struct idl file +class UnitTest07(Test): def run(self): - command = "../../hdi-gen -D ./bad_03/ -r ohos.hdi:./bad_03/ --hash" - status, _ = exec_command(command) - return status != 0 + return self.run_success() -# the idl file has error package name -class TestBadHash04(Test): +# overload method idl file +class UnitTest08(Test): def run(self): - command = "../../hdi-gen -D ./bad_04/ -r ohos.hdi:./bad_04/ --hash" - status, _ = exec_command(command) - return status != 0 -''' + return self.run_success() + class Tests: test_cases = [ UnitTest01("UnitTestEmptyIdl", "01_empty_idl"), UnitTest02("UnitTestStandardInterface", "02_standard_interface_idl"), - # UnitTest03("UnitTestStandardCallback", "03_standard_callback_idl"), - # UnitTest04("UnitTestExtendedInterface", "04_extended_interface_idl"), - # UnitTest05("UnitTestTypesIdl", "05_types_idl"), - # UnitTest06("UnitTestEnumExtension", "06_extended_enum_idl"), - # UnitTest06("UnitTestStructExtension", "07_extended_struct_idl"), - # UnitTest06("UnitTestOverloadMethod", "08_overload_method_idl"), + UnitTest03("UnitTestStandardCallback", "03_standard_callback_idl"), + UnitTest04("UnitTestExtendedInterface", "04_extended_interface_idl"), + UnitTest05("UnitTestTypesIdl", "05_types_idl"), + UnitTest06("UnitTestEnumExtension", "06_extended_enum_idl"), + UnitTest07("UnitTestStructExtension", "07_extended_struct_idl"), + UnitTest08("UnitTestOverloadMethod", "08_overload_method_idl"), ] @staticmethod -- Gitee From 9df1332f3f1a7166027f33a29ef44460ecbed780 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Sun, 18 Feb 2024 14:22:56 +0800 Subject: [PATCH 4/7] feat: idl support function with same name Signed-off-by: j30052480 --- framework/tools/hdi-gen/test/unittest/unit_test.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/framework/tools/hdi-gen/test/unittest/unit_test.py b/framework/tools/hdi-gen/test/unittest/unit_test.py index d31f936c9..2abf16098 100644 --- a/framework/tools/hdi-gen/test/unittest/unit_test.py +++ b/framework/tools/hdi-gen/test/unittest/unit_test.py @@ -33,11 +33,11 @@ def compare_file(first_file, second_file): def compare_target_files(first_file_path, second_file_path): - first_files = get_all_files(first_file_path) - second_files = get_all_files(second_file_path) + first_files_list = get_all_files(first_file_path) + second_files_list = get_all_files(second_file_path) - first_files = set([file[len(first_file_path):] for file in first_files]) - second_files = set([file[len(second_file_path):-4] for file in second_files]) + first_files = set([file[len(first_file_path):] for file in first_files_list]) + second_files = set([file[len(second_file_path):-4] for file in second_files_list]) common_files = first_files & second_files @@ -202,7 +202,8 @@ class Tests: ret = file_exists(hdi_gen_file) if not ret: hdi_gen_path = "../../" - ret = make_binary_file(hdi_gen_path) + if make_binary_file(hdi_gen_path)[0] == 0: + ret = True if not ret: print_failure("[===========] failed to make hdi-gen") return ret -- Gitee From d341b3435cf5b57726c2321a3f87528a93cebcde Mon Sep 17 00:00:00 2001 From: j30052480 Date: Tue, 20 Feb 2024 10:33:05 +0800 Subject: [PATCH 5/7] feat: idl support function with same name and nested enum Signed-off-by: j30052480 --- framework/tools/hdi-gen/ast/ast_enum_type.h | 10 ++ framework/tools/hdi-gen/ast/ast_expr.cpp | 17 ++ framework/tools/hdi-gen/ast/ast_expr.h | 6 + framework/tools/hdi-gen/parser/parser.cpp | 23 +++ framework/tools/hdi-gen/parser/parser.h | 2 + .../target/foo/v1_0/foo_proxy.cpp.txt | 120 +++++++++++++ .../target/foo/v1_0/foo_service.h.txt | 35 +--- .../target/foo/v1_0/foo_stub.cpp.txt | 108 ++++++++++++ .../target/foo/v1_0/ifoo.h.txt | 52 +----- .../foo/v1_0/foo_callback_proxy.cpp.txt | 46 +++++ .../foo/v1_0/foo_callback_service.h.txt | 20 --- .../target/foo/v1_0/foo_callback_stub.cpp.txt | 53 ++++++ .../target/foo/v1_0/ifoo.h.txt | 96 ----------- .../target/foo/v1_0/ifoo_callback.h.txt | 78 +-------- .../target/foo/v1_0/ifoo.h.txt | 96 ----------- .../target/foo/v1_1/foo_proxy.cpp.txt | 162 ++++++++++++++++++ .../target/foo/v1_1/foo_proxy.h.txt | 64 ------- .../target/foo/v1_1/foo_service.h.txt | 28 --- .../target/foo/v1_1/foo_stub.cpp.txt | 112 ++++++++++++ .../target/foo/v1_1/foo_stub.h.txt | 66 ------- .../target/foo/v1_1/ifoo.h.txt | 66 ------- .../target/foo/v1_0/types.cpp.txt | 29 +--- .../05_types_idl/target/foo/v1_0/types.h.txt | 46 ----- .../target/foo/v1_0/types.cpp.txt | 69 +------- .../target/foo/v1_0/types.h.txt | 57 +----- .../target/foo/v1_0/types.cpp.txt | 69 +------- .../target/foo/v1_0/types.h.txt | 57 +----- .../target/foo/v1_1/foo_proxy.cpp.txt | 74 ++++++++ .../target/foo/v1_1/foo_proxy.h.txt | 65 ------- .../target/foo/v1_1/foo_service.h.txt | 32 +--- .../target/foo/v1_1/foo_stub.cpp.txt | 99 +++++++++++ .../target/foo/v1_1/foo_stub.h.txt | 66 ------- .../target/foo/v1_1/ifoo.h.txt | 83 +-------- .../foo/v1_0/IFoo.idl} | 42 ++--- .../foo/v1_0/Types.idl} | 60 +++---- .../target/foo/v1_0/types.h.txt | 23 +++ .../tools/hdi-gen/test/unittest/unit_test.py | 32 +++- 37 files changed, 926 insertions(+), 1237 deletions(-) create mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_proxy.cpp.txt create mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_stub.cpp.txt create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_proxy.cpp.txt create mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_stub.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt create mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt rename framework/tools/hdi-gen/test/unittest/{04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt => 09_enum_nesting_idl/foo/v1_0/IFoo.idl} (51%) rename framework/tools/hdi-gen/test/unittest/{03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt => 09_enum_nesting_idl/foo/v1_0/Types.idl} (51%) create mode 100644 framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/target/foo/v1_0/types.h.txt diff --git a/framework/tools/hdi-gen/ast/ast_enum_type.h b/framework/tools/hdi-gen/ast/ast_enum_type.h index e371055b5..0a37586bd 100644 --- a/framework/tools/hdi-gen/ast/ast_enum_type.h +++ b/framework/tools/hdi-gen/ast/ast_enum_type.h @@ -110,6 +110,16 @@ public: return members_[index]; } + inline bool HasMember(std::string memberName) + { + for (size_t i = 0; i < members_.size(); i++) { + if (members_[i]->GetName() == memberName) { + return true; + } + } + return false; + } + bool IsEnumType() override; std::string Dump(const std::string &prefix) override; diff --git a/framework/tools/hdi-gen/ast/ast_expr.cpp b/framework/tools/hdi-gen/ast/ast_expr.cpp index 81da7d0b1..e5f6d806f 100644 --- a/framework/tools/hdi-gen/ast/ast_expr.cpp +++ b/framework/tools/hdi-gen/ast/ast_expr.cpp @@ -103,5 +103,22 @@ std::string ASTNumExpr::Dump(const std::string &prefix) return sb.ToString(); } + +std::string ASTEnumExpr::Dump(const std::string &prefix) +{ + StringBuilder sb; + sb.Append(prefix); + if (isParenExpr) { + sb.Append("("); + } + + sb.AppendFormat("%s", value_.c_str()); + + if (isParenExpr) { + sb.Append("("); + } + + return sb.ToString(); +} } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/ast/ast_expr.h b/framework/tools/hdi-gen/ast/ast_expr.h index a50e3003e..4dafec0d6 100644 --- a/framework/tools/hdi-gen/ast/ast_expr.h +++ b/framework/tools/hdi-gen/ast/ast_expr.h @@ -69,6 +69,12 @@ public: std::string Dump(const std::string &prefix) override; std::string value_; }; + +class ASTEnumExpr : public ASTExpr { +public: + std::string Dump(const std::string &prefix) override; + std::string value_; +}; } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/parser/parser.cpp b/framework/tools/hdi-gen/parser/parser.cpp index 351c255b4..063065244 100644 --- a/framework/tools/hdi-gen/parser/parser.cpp +++ b/framework/tools/hdi-gen/parser/parser.cpp @@ -43,6 +43,7 @@ static std::regex g_binaryNumRe(RE_BIN_DIGIT RE_DIGIT_SUFFIX, std::regex_constan static std::regex g_octNumRe(RE_OCT_DIGIT RE_DIGIT_SUFFIX, std::regex_constants::icase); static std::regex g_decNumRe(RE_DEC_DIGIT RE_DIGIT_SUFFIX, std::regex_constants::icase); static std::regex g_hexNumRe(RE_HEX_DIFIT RE_DIGIT_SUFFIX, std::regex_constants::icase); +AutoPtr g_currentEnum = nullptr; bool Parser::Parse(const std::vector &fileDetails) { @@ -1002,6 +1003,7 @@ AutoPtr Parser::ParseUserDefType() void Parser::ParseEnumDeclaration(const AttrSet &attrs) { AutoPtr enumType = new ASTEnumType; + g_currentEnum = enumType; enumType->SetAttribute(ParseUserDefTypeAttr(attrs)); lexer_.GetToken(); @@ -1038,6 +1040,7 @@ void Parser::ParseEnumDeclaration(const AttrSet &attrs) enumType->SetNamespace(ast_->ParseNamespace(ast_->GetFullName())); ast_->AddTypeDefinition(enumType.Get()); + g_currentEnum = nullptr; } AutoPtr Parser::ParseEnumBaseType() @@ -1519,6 +1522,13 @@ AutoPtr Parser::ParsePrimaryExpr() } case TokenType::NUM: return ParseNumExpr(); + case TokenType::ID: + if (g_currentEnum == nullptr) { + LogError(token, StringHelper::Format("this expression is not supported")); + lexer_.SkipUntilToken(TokenType::COMMA); + return nullptr; + } + return ParseEnumExpr(); default: LogError(token, StringHelper::Format("this expression is not supported")); lexer_.SkipUntilToken(TokenType::COMMA); @@ -1539,6 +1549,19 @@ AutoPtr Parser::ParseNumExpr() return expr.Get(); } +AutoPtr Parser::ParseEnumExpr() +{ + Token token = lexer_.GetToken(); + if (!g_currentEnum->HasMember(token.value)) { + LogError(token, StringHelper::Format("unknown enum member: '%s'", token.value.c_str())); + return nullptr; + } + + AutoPtr expr = new ASTEnumExpr; + expr->value_ = token.value; + return expr.Get(); +} + bool Parser::CheckNumber(const std::string& integerVal) const { if (std::regex_match(integerVal, g_binaryNumRe)|| diff --git a/framework/tools/hdi-gen/parser/parser.h b/framework/tools/hdi-gen/parser/parser.h index b8870966c..0d570bb76 100644 --- a/framework/tools/hdi-gen/parser/parser.h +++ b/framework/tools/hdi-gen/parser/parser.h @@ -169,6 +169,8 @@ private: AutoPtr ParseNumExpr(); + AutoPtr ParseEnumExpr(); + bool CheckNumber(const std::string& integerVal) const; bool CheckType(const Token &token, const AutoPtr &type); diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_proxy.cpp.txt b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_proxy.cpp.txt new file mode 100644 index 000000000..9c69b0d39 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_proxy.cpp.txt @@ -0,0 +1,120 @@ +#include "v1_0/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.0", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData(std::string& info) + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest(int32_t inParam, double& outParam) + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING_1, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetData_(std::string& info, const sptr remote) + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::InfoTest_(int32_t inParam, double& outParam, const sptr remote) + +int32_t OHOS::HDI::Foo::V1_0::FooProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt index 0e5d0ee8d..7fa27784c 100644 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt @@ -1,42 +1,9 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOSERVICE_H -#define OHOS_HDI_FOO_V1_0_FOOSERVICE_H - #include "v1_0/ifoo.h" -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { class FooService : public OHOS::HDI::Foo::V1_0::IFoo { -public: - FooService() = default; - virtual ~FooService() = default; - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; int32_t GetData(std::string& info) override; int32_t InfoTest(int32_t inParam, double& outParam) override; - -}; -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOSERVICE_H \ No newline at end of file +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_stub.cpp.txt b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_stub.cpp.txt new file mode 100644 index 000000000..f5a240ff2 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_stub.cpp.txt @@ -0,0 +1,108 @@ +#include "v1_0/foo_stub.h" +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_stub + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(bool isStub) +{ + return OHOS::HDI::Foo::V1_0::IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_0::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (!isStub) { + return nullptr; + } + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.c_str()); + return nullptr; + } + return reinterpret_cast(impl); +} + +int32_t OHOS::HDI::Foo::V1_0::FooStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + switch (code) { + case CMD_FOO_GET_VERSION_0: + return FooStubGetVersion_0(data, reply, option); + case CMD_FOO_PING_1: + return FooStubPing_1(data, reply, option); + case CMD_FOO_GET_DATA_2: + return FooStubGetData_2(data, reply, option); + case CMD_FOO_INFO_TEST_3: + return FooStubInfoTest_3(data, reply, option); + default: { + HDF_LOGE("%{public}s: cmd %{public}d is not supported", __func__, code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + } +} + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubPing_1(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubGetData_2(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubInfoTest_3(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubGetVersion_0(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubPing_1_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) +{ + if (fooData.ReadInterfaceToken() != OHOS::HDI::Foo::V1_0::IFoo::GetDescriptor()) { + HDF_LOGE("%{public}s: interface token check failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + bool fooMemSet = false; + if (!fooData.ReadBool(fooMemSet)) { + HDF_LOGE("%{public}s: failed to read fooMemSet", __func__); + return HDF_ERR_INVALID_PARAM; + } + const char* sendMsgCp = fooData.ReadCString(); + if (sendMsgCp == nullptr) { + HDF_LOGE("%{public}s: read sendMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + std::string sendMsg = sendMsgCp; + + std::string recvMsg; + if (fooMemSet) { + uint32_t capacity = 0; + if (!fooData.ReadUint32(capacity)) { + HDF_LOGE("%{public}s: failed to read capacity", __func__); + return HDF_ERR_INVALID_PARAM; + } + HDI_CHECK_VALUE_RETURN(capacity, >, HDI_BUFF_MAX_SIZE / sizeof(char), HDF_ERR_INVALID_PARAM); + recvMsg.reserve(capacity); + } + + if (impl == nullptr) { + HDF_LOGE("%{public}s: impl is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + int32_t fooRet = impl->Ping(sendMsg, recvMsg); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.WriteCString(recvMsg.c_str())) { + HDF_LOGE("%{public}s: write recvMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubGetData_2_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubInfoTest_3_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) + +int32_t OHOS::HDI::Foo::V1_0::FooStub::FooStubGetVersion_0_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt index 0e9b64b0e..b72a58638 100644 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt +++ b/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt @@ -1,26 +1,3 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_IFOO_H -#define OHOS_HDI_FOO_V1_0_IFOO_H - -#include -#include -#include -#include - #ifndef HDI_BUFF_MAX_SIZE #define HDI_BUFF_MAX_SIZE (1024 * 200) #endif @@ -57,40 +34,13 @@ enum { }; class IFoo : public HdiBase { -public: - DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFoo"); - - virtual ~IFoo() = default; - - static sptr Get(bool isStub = false); - static sptr Get(const std::string &serviceName, bool isStub = false); - virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg) = 0; virtual int32_t GetData(std::string& info) = 0; virtual int32_t InfoTest(int32_t inParam, double& outParam) = 0; - - virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) - { - majorVer = 1; - minorVer = 0; - return HDF_SUCCESS; - } - - virtual bool IsProxy() - { - return false; - } - - virtual const std::u16string GetDesc() - { - return metaDescriptor_; - } }; } // V1_0 } // Foo } // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_IFOO_H \ No newline at end of file +} // OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_proxy.cpp.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_proxy.cpp.txt new file mode 100644 index 000000000..3219dbf47 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_proxy.cpp.txt @@ -0,0 +1,46 @@ +#include "v1_0/foo_callback_proxy.h" +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_callback_proxy + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackProxy::PushData(const std::string& message) + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackProxy::PushData_(const std::string& message, const sptr remote) +{ + MessageParcel fooCallbackData; + MessageParcel fooCallbackReply; + MessageOption fooCallbackOption(MessageOption::TF_SYNC); + + if (!fooCallbackData.WriteInterfaceToken(OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooCallbackData.WriteCString(message.c_str())) { + HDF_LOGE("%{public}s: write message failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooCallbackRet = remote->SendRequest(CMD_FOO_CALLBACK_PUSH_DATA_1, fooCallbackData, fooCallbackReply, fooCallbackOption); + if (fooCallbackRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooCallbackRet); + return fooCallbackRet; + } + + return fooCallbackRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackProxy::GetVersion_(uint32_t& majorVer, uint32_t& minorVer, + const sptr remote) diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt index e389f491b..135aa1a0f 100644 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #ifndef OHOS_HDI_FOO_V1_0_FOOCALLBACKSERVICE_H #define OHOS_HDI_FOO_V1_0_FOOCALLBACKSERVICE_H @@ -23,12 +8,7 @@ namespace HDI { namespace Foo { namespace V1_0 { class FooCallbackService : public OHOS::HDI::Foo::V1_0::IFooCallback { -public: - FooCallbackService() = default; - virtual ~FooCallbackService() = default; - int32_t PushData(const std::string& message) override; - }; } // V1_0 } // Foo diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_stub.cpp.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_stub.cpp.txt new file mode 100644 index 000000000..d5444c6df --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_stub.cpp.txt @@ -0,0 +1,53 @@ +#include "v1_0/foo_callback_stub.h" +#include +#include + +#define HDF_LOG_TAG foo_callback_stub + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + switch (code) { + case CMD_FOO_CALLBACK_GET_VERSION_0: + return FooCallbackStubGetVersion_0(data, reply, option); + case CMD_FOO_CALLBACK_PUSH_DATA_1: + return FooCallbackStubPushData_1(data, reply, option); + default: { + HDF_LOGE("%{public}s: cmd %{public}d is not supported", __func__, code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + } +} + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackStub::FooCallbackStubPushData_1(MessageParcel& fooCallbackData, MessageParcel& fooCallbackReply, MessageOption& fooCallbackOption) + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackStub::FooCallbackStubGetVersion_0(MessageParcel& fooCallbackData, MessageParcel& fooCallbackReply, MessageOption& fooCallbackOption) + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackStub::FooCallbackStubPushData_1_(MessageParcel& fooCallbackData, MessageParcel& fooCallbackReply, MessageOption& fooCallbackOption, sptr impl) +{ + if (fooCallbackData.ReadInterfaceToken() != OHOS::HDI::Foo::V1_0::IFooCallback::GetDescriptor()) { + HDF_LOGE("%{public}s: interface token check failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + const char* messageCp = fooCallbackData.ReadCString(); + if (messageCp == nullptr) { + HDF_LOGE("%{public}s: read message failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + std::string message = messageCp; + + if (impl == nullptr) { + HDF_LOGE("%{public}s: impl is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + int32_t fooCallbackRet = impl->PushData(message); + if (fooCallbackRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooCallbackRet); + return fooCallbackRet; + } + + return fooCallbackRet; +} + +int32_t OHOS::HDI::Foo::V1_0::FooCallbackStub::FooCallbackStubGetVersion_0_(MessageParcel& fooCallbackData, MessageParcel& fooCallbackReply, MessageOption& fooCallbackOption, sptr impl) \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt deleted file mode 100644 index 0e9b64b0e..000000000 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo.h.txt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_IFOO_H -#define OHOS_HDI_FOO_V1_0_IFOO_H - -#include -#include -#include -#include - -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { -using namespace OHOS; -using namespace OHOS::HDI; - -enum { - CMD_FOO_GET_VERSION_0 = 0, - CMD_FOO_PING_1 = 1, - CMD_FOO_GET_DATA_2 = 2, - CMD_FOO_INFO_TEST_3 = 3, -}; - -class IFoo : public HdiBase { -public: - DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFoo"); - - virtual ~IFoo() = default; - - static sptr Get(bool isStub = false); - static sptr Get(const std::string &serviceName, bool isStub = false); - - virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg) = 0; - - virtual int32_t GetData(std::string& info) = 0; - - virtual int32_t InfoTest(int32_t inParam, double& outParam) = 0; - - virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) - { - majorVer = 1; - minorVer = 0; - return HDF_SUCCESS; - } - - virtual bool IsProxy() - { - return false; - } - - virtual const std::u16string GetDesc() - { - return metaDescriptor_; - } -}; -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt index 6334b6e06..aabfea55f 100644 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt +++ b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt @@ -1,51 +1,3 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_IFOOCALLBACK_H -#define OHOS_HDI_FOO_V1_0_IFOOCALLBACK_H - -#include -#include -#include -#include - -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { using namespace OHOS; using namespace OHOS::HDI; @@ -55,33 +7,5 @@ enum { }; class IFooCallback : public HdiBase { -public: - DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFooCallback"); - - virtual ~IFooCallback() = default; - virtual int32_t PushData(const std::string& message) = 0; - - virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) - { - majorVer = 1; - minorVer = 0; - return HDF_SUCCESS; - } - - virtual bool IsProxy() - { - return false; - } - - virtual const std::u16string GetDesc() - { - return metaDescriptor_; - } -}; -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_IFOOCALLBACK_H \ No newline at end of file +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt deleted file mode 100644 index 0e9b64b0e..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/ifoo.h.txt +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_IFOO_H -#define OHOS_HDI_FOO_V1_0_IFOO_H - -#include -#include -#include -#include - -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { -using namespace OHOS; -using namespace OHOS::HDI; - -enum { - CMD_FOO_GET_VERSION_0 = 0, - CMD_FOO_PING_1 = 1, - CMD_FOO_GET_DATA_2 = 2, - CMD_FOO_INFO_TEST_3 = 3, -}; - -class IFoo : public HdiBase { -public: - DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_0.IFoo"); - - virtual ~IFoo() = default; - - static sptr Get(bool isStub = false); - static sptr Get(const std::string &serviceName, bool isStub = false); - - virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg) = 0; - - virtual int32_t GetData(std::string& info) = 0; - - virtual int32_t InfoTest(int32_t inParam, double& outParam) = 0; - - virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) - { - majorVer = 1; - minorVer = 0; - return HDF_SUCCESS; - } - - virtual bool IsProxy() - { - return false; - } - - virtual const std::u16string GetDesc() - { - return metaDescriptor_; - } -}; -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.cpp.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.cpp.txt new file mode 100644 index 000000000..6e3dabf56 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.cpp.txt @@ -0,0 +1,162 @@ +#include "v1_1/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +template +static sptr CastFromTemplate(const sptr &parent) +{ + if (parent == nullptr) { + HDF_LOGE("%{public}s:parent is nullptr!", __func__); + return nullptr; + } + + if (!parent->IsProxy()) { + HDF_LOGE("%{public}s:not proxy, not support castfrom!", __func__); + return nullptr; + } + + sptr remote = OHOS::HDI::hdi_objcast(parent); + if (remote == nullptr) { + HDF_LOGE("%{public}s:hdi_objcast failed!", __func__); + return nullptr; + } + + sptr proxy = OHOS::HDI::hdi_facecast(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:hdi_facecast failed!", __func__); + return nullptr; + } + + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(bool isStub) +{ + return IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (isStub) { + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.data()); + return nullptr; + } + return reinterpret_cast(impl); + } + + using namespace OHOS::HDI::ServiceManager::V1_0; + auto servMgr = IServiceManager::Get(); + if (servMgr == nullptr) { + HDF_LOGE("%{public}s:get IServiceManager failed!", __func__); + return nullptr; + } + + sptr remote = servMgr->GetService(serviceName.c_str()); + if (remote == nullptr) { + HDF_LOGE("%{public}s:get remote object failed!", __func__); + return nullptr; + } + + sptr proxy = new FooProxy(remote); + if (proxy == nullptr) { + HDF_LOGE("%{public}s:iface_cast failed!", __func__); + return nullptr; + } + + uint32_t serMajorVer = 0; + uint32_t serMinorVer = 0; + int32_t fooRet = proxy->GetVersion(serMajorVer, serMinorVer); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s:get version failed!", __func__); + return nullptr; + } + + if (serMajorVer != 1) { + HDF_LOGE("%{public}s:check version failed! version of service:%u.%u, version of client:1.1", __func__, serMajorVer, serMinorVer); + return nullptr; + } + + return proxy; +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::CastFrom(const sptr &parent) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestGetData(std::string& info) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::InfoTest(int32_t inParam, double& outParam) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestPingV1_1_(const std::string& sendMsg, std::string& recvMsg, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_TEST_PING_V1_1_4, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::TestGetData_(std::string& info, const sptr remote) \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt deleted file mode 100644 index b2a91b643..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.h.txt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H -#define OHOS_HDI_FOO_V1_1_FOOPROXY_H - -#include "v1_0/foo_proxy.h" -#include "v1_1/ifoo.h" -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - -class FooProxy : public IProxyBroker { -public: - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) {} - - virtual ~FooProxy() = default; - - inline bool IsProxy() override - { - return true; - } - - int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t TestGetData(std::string& info) override; - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t TestPingV1_1_(const std::string& sendMsg, std::string& recvMsg, const sptr remote); - - static int32_t TestGetData_(std::string& info, const sptr remote); - -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt index fdd5ca0d4..b9623d6d0 100644 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt @@ -1,32 +1,9 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #ifndef OHOS_HDI_FOO_V1_1_FOOSERVICE_H #define OHOS_HDI_FOO_V1_1_FOOSERVICE_H #include "v1_1/ifoo.h" -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { class FooService : public OHOS::HDI::Foo::V1_1::IFoo { -public: - FooService() = default; - virtual ~FooService() = default; - int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) override; int32_t TestGetData(std::string& info) override; @@ -36,11 +13,6 @@ public: int32_t GetData(std::string& info) override; int32_t InfoTest(int32_t inParam, double& outParam) override; - }; -} // V1_1 -} // Foo -} // HDI -} // OHOS #endif // OHOS_HDI_FOO_V1_1_FOOSERVICE_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.cpp.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.cpp.txt new file mode 100644 index 000000000..af7aebf1d --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.cpp.txt @@ -0,0 +1,112 @@ +#include "v1_1/foo_stub.h" +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_stub + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(bool isStub) +{ + return OHOS::HDI::Foo::V1_1::IFoo::Get("foo_service", isStub); +} + +sptr OHOS::HDI::Foo::V1_1::IFoo::Get(const std::string& serviceName, bool isStub) +{ + if (!isStub) { + return nullptr; + } + std::string desc = Str16ToStr8(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()); + void *impl = LoadHdiImpl(desc.c_str(), serviceName == "foo_service" ? "service" : serviceName.c_str()); + if (impl == nullptr) { + HDF_LOGE("failed to load hdi impl %{public}s", desc.c_str()); + return nullptr; + } + return reinterpret_cast(impl); +} + +int32_t OHOS::HDI::Foo::V1_1::FooStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + switch (code) { + case CMD_FOO_GET_VERSION_0: + return FooStubGetVersion_0(data, reply, option); + case CMD_FOO_TEST_PING_V1_1_4: + return FooStubTestPingV1_1_4(data, reply, option); + case CMD_FOO_TEST_GET_DATA_5: + return FooStubTestGetData_5(data, reply, option); + case CMD_FOO_PING_1: + return FooStubPing_1(data, reply, option); + case CMD_FOO_GET_DATA_2: + return FooStubGetData_2(data, reply, option); + case CMD_FOO_INFO_TEST_3: + return FooStubInfoTest_3(data, reply, option); + default: { + HDF_LOGE("%{public}s: cmd %{public}d is not supported", __func__, code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + } +} + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubTestPingV1_1_4(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubTestGetData_5(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubPing_1(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubGetData_2(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubInfoTest_3(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubGetVersion_0(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubTestPingV1_1_4_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) +{ + if (fooData.ReadInterfaceToken() != OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()) { + HDF_LOGE("%{public}s: interface token check failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + bool fooMemSet = false; + if (!fooData.ReadBool(fooMemSet)) { + HDF_LOGE("%{public}s: failed to read fooMemSet", __func__); + return HDF_ERR_INVALID_PARAM; + } + const char* sendMsgCp = fooData.ReadCString(); + if (sendMsgCp == nullptr) { + HDF_LOGE("%{public}s: read sendMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + std::string sendMsg = sendMsgCp; + + std::string recvMsg; + if (fooMemSet) { + uint32_t capacity = 0; + if (!fooData.ReadUint32(capacity)) { + HDF_LOGE("%{public}s: failed to read capacity", __func__); + return HDF_ERR_INVALID_PARAM; + } + HDI_CHECK_VALUE_RETURN(capacity, >, HDI_BUFF_MAX_SIZE / sizeof(char), HDF_ERR_INVALID_PARAM); + recvMsg.reserve(capacity); + } + + if (impl == nullptr) { + HDF_LOGE("%{public}s: impl is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + int32_t fooRet = impl->TestPingV1_1(sendMsg, recvMsg); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.WriteCString(recvMsg.c_str())) { + HDF_LOGE("%{public}s: write recvMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubTestGetData_5_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt deleted file mode 100644 index 807d05b75..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.h.txt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_1_FOOSTUB_H -#define OHOS_HDI_FOO_V1_1_FOOSTUB_H - -#include -#include -#include -#include -#include -#include "v1_0/foo_stub.h" -#include "v1_1/ifoo.h" - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - -using namespace OHOS; -class FooStub : public IPCObjectStub { -public: - explicit FooStub(const sptr &impl); - virtual ~FooStub(); - - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - - static int32_t FooStubTestPingV1_1_4_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); - - static int32_t FooStubTestGetData_5_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); - -private: - int32_t FooStubTestPingV1_1_4(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubTestGetData_5(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubPing_1(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubGetData_2(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubInfoTest_3(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubGetVersion_0(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - - static inline ObjectDelegator objDelegator_; - sptr impl_; -}; -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_FOOSTUB_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt index 39bc8b46f..989d4d478 100644 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt +++ b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #ifndef OHOS_HDI_FOO_V1_1_IFOO_H #define OHOS_HDI_FOO_V1_1_IFOO_H @@ -22,31 +7,6 @@ #include #include "foo/v1_0/ifoo.h" -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { using namespace OHOS; using namespace OHOS::HDI; using namespace OHOS::HDI::Foo::V1_0; @@ -57,35 +17,9 @@ enum { }; class IFoo : public OHOS::HDI::Foo::V1_0::IFoo { -public: - DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_1.IFoo"); - - virtual ~IFoo() = default; - - static sptr Get(bool isStub = false); - static sptr Get(const std::string &serviceName, bool isStub = false); - - static sptr CastFrom(const sptr &parent); - virtual int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) = 0; virtual int32_t TestGetData(std::string& info) = 0; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override - { - majorVer = 1; - minorVer = 1; - return HDF_SUCCESS; - } - - const std::u16string GetDesc() override - { - return metaDescriptor_; - } }; -} // V1_1 -} // Foo -} // HDI -} // OHOS #endif // OHOS_HDI_FOO_V1_1_IFOO_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt index 3ba16174e..d86b2abc8 100644 --- a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt +++ b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt @@ -1,30 +1,8 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #include "v1_0/types.h" #include #include #include -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - - bool FooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) { if (!data.WriteUint32(dataBlock.id)) { @@ -67,9 +45,4 @@ bool FooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0:: dataBlock.type = static_cast(enumTmp); } return true; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS +} \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt index 55eb32f0a..958d52784 100644 --- a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt +++ b/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #ifndef OHOS_HDI_FOO_V1_0_TYPES_H #define OHOS_HDI_FOO_V1_0_TYPES_H @@ -20,36 +5,10 @@ #include #include -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - namespace OHOS { class MessageParcel; } -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - using namespace OHOS; enum FooType : int32_t { @@ -67,9 +26,4 @@ bool FooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1 bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); -} // V1_0 -} // Foo -} // HDI -} // OHOS - #endif // OHOS_HDI_FOO_V1_0_TYPES_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt index 14f7f8a35..e287186b4 100644 --- a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt +++ b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt @@ -1,75 +1,8 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #include "v1_0/types.h" #include #include #include -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - - bool FooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) -{ - if (!data.WriteUint32(dataBlock.id)) { - HDF_LOGE("%{public}s: write dataBlock.id failed!", __func__); - return false; - } - - if (!data.WriteCString(dataBlock.name.c_str())) { - HDF_LOGE("%{public}s: write dataBlock.name failed!", __func__); - return false; - } - - if (!data.WriteUint64(static_cast(dataBlock.type))) { - HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); - return false; - } - return true; -} - -bool FooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) -{ - if (!data.ReadUint32(dataBlock.id)) { - HDF_LOGE("%{public}s: read dataBlock.id failed!", __func__); - return false; - } - - const char* nameCp = data.ReadCString(); - if (nameCp == nullptr) { - HDF_LOGE("%{public}s: read nameCp failed", __func__); - return false; - } - dataBlock.name = nameCp; - - { - uint64_t enumTmp = 0; - if (!data.ReadUint64(enumTmp)) { - HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); - return false; - } - dataBlock.type = static_cast(enumTmp); - } - return true; -} -} // V1_0 -} // Foo -} // HDI -} // OHOS +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt index 8c2ba001c..9b475b7b6 100644 --- a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt +++ b/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt @@ -1,55 +1,7 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_TYPES_H -#define OHOS_HDI_FOO_V1_0_TYPES_H - -#include -#include -#include - -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - namespace OHOS { class MessageParcel; } -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - using namespace OHOS; enum FooType : int32_t { @@ -72,11 +24,4 @@ struct FooInfo { bool FooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); -bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_TYPES_H \ No newline at end of file +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt index 4bcb016f4..9bea95eab 100644 --- a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt +++ b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt @@ -1,73 +1,11 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #include "v1_0/types.h" #include #include #include -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - - - bool FooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) -{ - if (!data.WriteUint32(dataBlock.id)) { - HDF_LOGE("%{public}s: write dataBlock.id failed!", __func__); - return false; - } - - if (!data.WriteCString(dataBlock.name.c_str())) { - HDF_LOGE("%{public}s: write dataBlock.name failed!", __func__); - return false; - } - - if (!data.WriteUint64(static_cast(dataBlock.type))) { - HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); - return false; - } - return true; -} bool FooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock) -{ - if (!data.ReadUint32(dataBlock.id)) { - HDF_LOGE("%{public}s: read dataBlock.id failed!", __func__); - return false; - } - - const char* nameCp = data.ReadCString(); - if (nameCp == nullptr) { - HDF_LOGE("%{public}s: read nameCp failed", __func__); - return false; - } - dataBlock.name = nameCp; - - { - uint64_t enumTmp = 0; - if (!data.ReadUint64(enumTmp)) { - HDF_LOGE("%{public}s: write dataBlock.type failed!", __func__); - return false; - } - dataBlock.type = static_cast(enumTmp); - } - return true; -} bool ExtendedFooInfoBlockMarshalling(OHOS::MessageParcel& data, const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock) { @@ -133,9 +71,4 @@ bool ExtendedFooInfoBlockUnmarshalling(OHOS::MessageParcel& data, OHOS::HDI::Foo } dataBlock.extendedInfo = extendedInfoCp; return true; -} - -} // V1_0 -} // Foo -} // HDI -} // OHOS +} \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt index e0717a4cd..bf4ee00cd 100644 --- a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt +++ b/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt @@ -1,55 +1,7 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_TYPES_H -#define OHOS_HDI_FOO_V1_0_TYPES_H - -#include -#include -#include - -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - namespace OHOS { class MessageParcel; } -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { - using namespace OHOS; enum FooType : int32_t { @@ -77,11 +29,4 @@ bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0:: bool ExtendedFooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock); -bool ExtendedFooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock); - -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_TYPES_H \ No newline at end of file +bool ExtendedFooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::ExtendedFooInfo& dataBlock); \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.cpp.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.cpp.txt new file mode 100644 index 000000000..9e9b296d8 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.cpp.txt @@ -0,0 +1,74 @@ +#include "v1_1/foo_proxy.h" +#include +#include +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_proxy + +sptr OHOS::HDI::Foo::V1_1::IFoo::CastFrom(const sptr &parent) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info, std::string& ver) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping(const std::string& sendMsg, std::string& recvMsg) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData(std::string& info) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::InfoTest(int32_t inParam, double& outParam) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetVersion(uint32_t& majorVer, uint32_t& minorVer) + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::Ping_(const std::string& sendMsg, std::string& recvMsg, int32_t code, + const sptr remote) +{ + MessageParcel fooData; + MessageParcel fooReply; + MessageOption fooOption(MessageOption::TF_SYNC); + + if (!fooData.WriteInterfaceToken(OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor())) { + HDF_LOGE("%{public}s: failed to write interface descriptor!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteBool(false)) { + HDF_LOGE("%{public}s:failed to write flag of memory setting!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteCString(sendMsg.c_str())) { + HDF_LOGE("%{public}s: write sendMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (!fooData.WriteInt32(code)) { + HDF_LOGE("%{public}s: write code failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (remote == nullptr) { + HDF_LOGE("%{public}s: invalid remote object!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + int32_t fooRet = remote->SendRequest(CMD_FOO_PING_4, fooData, fooReply, fooOption); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + const char* recvMsgCp = fooReply.ReadCString(); + if (recvMsgCp == nullptr) { + HDF_LOGE("%{public}s: read recvMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + recvMsg = recvMsgCp; + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_1::FooProxy::GetData_(std::string& info, std::string& ver, const sptr remote) \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt deleted file mode 100644 index d5f15ed81..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.h.txt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_1_FOOPROXY_H -#define OHOS_HDI_FOO_V1_1_FOOPROXY_H - -#include "v1_0/foo_proxy.h" -#include "v1_1/ifoo.h" -#include - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - -class FooProxy : public IProxyBroker { -public: - explicit FooProxy(const sptr& remote) : IProxyBroker(remote) {} - - virtual ~FooProxy() = default; - - inline bool IsProxy() override - { - return true; - } - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) override; - - int32_t GetData(std::string& info, std::string& ver) override; - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override; - - static int32_t Ping_(const std::string& sendMsg, std::string& recvMsg, int32_t code, - const sptr remote); - - static int32_t GetData_(std::string& info, std::string& ver, const sptr remote); - -private: - static inline BrokerDelegator delegator_; -}; - -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_FOOPROXY_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt index 76abf0f82..de316e01d 100644 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt @@ -1,32 +1,9 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #ifndef OHOS_HDI_FOO_V1_1_FOOSERVICE_H #define OHOS_HDI_FOO_V1_1_FOOSERVICE_H #include "v1_1/ifoo.h" -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { class FooService : public OHOS::HDI::Foo::V1_1::IFoo { -public: - FooService() = default; - virtual ~FooService() = default; - int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) override; int32_t GetData(std::string& info, std::string& ver) override; @@ -36,11 +13,4 @@ public: int32_t GetData(std::string& info) override; int32_t InfoTest(int32_t inParam, double& outParam) override; - -}; -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_FOOSERVICE_H \ No newline at end of file +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.cpp.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.cpp.txt new file mode 100644 index 000000000..8d8989fb6 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.cpp.txt @@ -0,0 +1,99 @@ +#include "v1_1/foo_stub.h" +#include +#include +#include +#include +#include + +#define HDF_LOG_TAG foo_stub + +int32_t OHOS::HDI::Foo::V1_1::FooStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + switch (code) { + case CMD_FOO_GET_VERSION_0: + return FooStubGetVersion_0(data, reply, option); + case CMD_FOO_PING_4: + return FooStubPing_4(data, reply, option); + case CMD_FOO_GET_DATA_5: + return FooStubGetData_5(data, reply, option); + case CMD_FOO_PING_1: + return FooStubPing_1(data, reply, option); + case CMD_FOO_GET_DATA_2: + return FooStubGetData_2(data, reply, option); + case CMD_FOO_INFO_TEST_3: + return FooStubInfoTest_3(data, reply, option); + default: { + HDF_LOGE("%{public}s: cmd %{public}d is not supported", __func__, code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + } +} + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubPing_4(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubGetData_5(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubPing_1(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubGetData_2(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubInfoTest_3(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubGetVersion_0(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption) + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubPing_4_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) +{ + if (fooData.ReadInterfaceToken() != OHOS::HDI::Foo::V1_1::IFoo::GetDescriptor()) { + HDF_LOGE("%{public}s: interface token check failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + bool fooMemSet = false; + if (!fooData.ReadBool(fooMemSet)) { + HDF_LOGE("%{public}s: failed to read fooMemSet", __func__); + return HDF_ERR_INVALID_PARAM; + } + const char* sendMsgCp = fooData.ReadCString(); + if (sendMsgCp == nullptr) { + HDF_LOGE("%{public}s: read sendMsg failed", __func__); + return HDF_ERR_INVALID_PARAM; + } + std::string sendMsg = sendMsgCp; + + std::string recvMsg; + if (fooMemSet) { + uint32_t capacity = 0; + if (!fooData.ReadUint32(capacity)) { + HDF_LOGE("%{public}s: failed to read capacity", __func__); + return HDF_ERR_INVALID_PARAM; + } + HDI_CHECK_VALUE_RETURN(capacity, >, HDI_BUFF_MAX_SIZE / sizeof(char), HDF_ERR_INVALID_PARAM); + recvMsg.reserve(capacity); + } + + int32_t code = 0; + if (!fooData.ReadInt32(code)) { + HDF_LOGE("%{public}s: read code failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (impl == nullptr) { + HDF_LOGE("%{public}s: impl is nullptr!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + int32_t fooRet = impl->Ping(sendMsg, recvMsg, code); + if (fooRet != HDF_SUCCESS) { + HDF_LOGE("%{public}s failed, error code is %{public}d", __func__, fooRet); + return fooRet; + } + + if (!fooReply.WriteCString(recvMsg.c_str())) { + HDF_LOGE("%{public}s: write recvMsg failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return fooRet; +} + +int32_t OHOS::HDI::Foo::V1_1::FooStub::FooStubGetData_5_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl) \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt deleted file mode 100644 index 2b988d71f..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.h.txt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_1_FOOSTUB_H -#define OHOS_HDI_FOO_V1_1_FOOSTUB_H - -#include -#include -#include -#include -#include -#include "v1_0/foo_stub.h" -#include "v1_1/ifoo.h" - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { - -using namespace OHOS; -class FooStub : public IPCObjectStub { -public: - explicit FooStub(const sptr &impl); - virtual ~FooStub(); - - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - - static int32_t FooStubPing_4_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); - - static int32_t FooStubGetData_5_(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption, sptr impl); - -private: - int32_t FooStubPing_4(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubGetData_5(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubPing_1(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubGetData_2(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubInfoTest_3(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - int32_t FooStubGetVersion_0(MessageParcel& fooData, MessageParcel& fooReply, MessageOption& fooOption); - - - static inline ObjectDelegator objDelegator_; - sptr impl_; -}; -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_FOOSTUB_H \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt index 22527f1cd..dd3f2f23a 100644 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt +++ b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt @@ -1,93 +1,12 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_1_IFOO_H -#define OHOS_HDI_FOO_V1_1_IFOO_H - -#include -#include -#include -#include -#include "foo/v1_0/ifoo.h" - -#ifndef HDI_BUFF_MAX_SIZE -#define HDI_BUFF_MAX_SIZE (1024 * 200) -#endif - -#ifndef HDI_CHECK_VALUE_RETURN -#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ - if ((lv) compare (rv)) { \ - return ret; \ - } \ -} while (false) -#endif - -#ifndef HDI_CHECK_VALUE_RET_GOTO -#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ - if ((lv) compare (rv)) { \ - ret = value; \ - goto table; \ - } \ -} while (false) -#endif - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_1 { -using namespace OHOS; -using namespace OHOS::HDI; -using namespace OHOS::HDI::Foo::V1_0; - enum { CMD_FOO_PING_4 = 4, CMD_FOO_GET_DATA_5 = 5, }; class IFoo : public OHOS::HDI::Foo::V1_0::IFoo { -public: - DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.foo.v1_1.IFoo"); - - virtual ~IFoo() = default; - - static sptr Get(bool isStub = false); - static sptr Get(const std::string &serviceName, bool isStub = false); - - static sptr CastFrom(const sptr &parent); - using OHOS::HDI::Foo::V1_0::IFoo::Ping; virtual int32_t Ping(const std::string& sendMsg, std::string& recvMsg, int32_t code) = 0; using OHOS::HDI::Foo::V1_0::IFoo::GetData; virtual int32_t GetData(std::string& info, std::string& ver) = 0; - - int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) override - { - majorVer = 1; - minorVer = 1; - return HDF_SUCCESS; - } - - const std::u16string GetDesc() override - { - return metaDescriptor_; - } -}; -} // V1_1 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_1_IFOO_H \ No newline at end of file +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/IFoo.idl similarity index 51% rename from framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt rename to framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/IFoo.idl index 0e5d0ee8d..6ed1975b3 100644 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_0/foo_service.h.txt +++ b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/IFoo.idl @@ -11,32 +11,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - -#ifndef OHOS_HDI_FOO_V1_0_FOOSERVICE_H -#define OHOS_HDI_FOO_V1_0_FOOSERVICE_H - -#include "v1_0/ifoo.h" - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { -class FooService : public OHOS::HDI::Foo::V1_0::IFoo { -public: - FooService() = default; - virtual ~FooService() = default; - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; - -}; -} // V1_0 -} // Foo -} // HDI -} // OHOS - -#endif // OHOS_HDI_FOO_V1_0_FOOSERVICE_H \ No newline at end of file + */ + +package ohos.hdi.foo.v1_0; + +import ohos.hdi.foo.v1_0.Types; + +interface IFoo { + Ping([in] String sendMsg,[out] String recvMsg); + + GetData([out] struct FooInfo info); + + InfoTest([in] struct FooInfo inParam, [out] struct FooInfo outParam); +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/Types.idl similarity index 51% rename from framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt rename to framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/Types.idl index 0e5d0ee8d..b554fedb8 100644 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_service.h.txt +++ b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/Types.idl @@ -1,42 +1,28 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -#ifndef OHOS_HDI_FOO_V1_0_FOOSERVICE_H -#define OHOS_HDI_FOO_V1_0_FOOSERVICE_H - -#include "v1_0/ifoo.h" - -namespace OHOS { -namespace HDI { -namespace Foo { -namespace V1_0 { -class FooService : public OHOS::HDI::Foo::V1_0::IFoo { -public: - FooService() = default; - virtual ~FooService() = default; - - int32_t Ping(const std::string& sendMsg, std::string& recvMsg) override; - - int32_t GetData(std::string& info) override; - - int32_t InfoTest(int32_t inParam, double& outParam) override; +package ohos.hdi.foo.v1_0; +enum FooType { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, + FOO_TYPE_NESTING = (FOO_TYPE_ONE << FOO_TYPE_TWO), }; -} // V1_0 -} // Foo -} // HDI -} // OHOS -#endif // OHOS_HDI_FOO_V1_0_FOOSERVICE_H \ No newline at end of file +struct FooInfo { + unsigned int id; + String name; + enum FooType type; +}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/target/foo/v1_0/types.h.txt b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/target/foo/v1_0/types.h.txt new file mode 100644 index 000000000..3b51b25f5 --- /dev/null +++ b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/target/foo/v1_0/types.h.txt @@ -0,0 +1,23 @@ +#include +#include +#include + +namespace OHOS { +class MessageParcel; +} + +enum FooType : int32_t { + FOO_TYPE_ONE = 1, + FOO_TYPE_TWO = 2, + FOO_TYPE_NESTING = (FOO_TYPE_ONE << FOO_TYPE_TWO), +}; + +struct FooInfo { + uint32_t id; + std::string name; + OHOS::HDI::Foo::V1_0::FooType type; +}; + +bool FooInfoBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); + +bool FooInfoBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Foo::V1_0::FooInfo& dataBlock); \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/unit_test.py b/framework/tools/hdi-gen/test/unittest/unit_test.py index 2abf16098..654648211 100644 --- a/framework/tools/hdi-gen/test/unittest/unit_test.py +++ b/framework/tools/hdi-gen/test/unittest/unit_test.py @@ -24,12 +24,17 @@ def print_failure(info): print("\033[31m{}\033[0m".format(info)) -def compare_file(first_file, second_file): - with open(first_file, 'r') as first_hash_file: - with open(second_file, 'r') as second_hash_file: - first_hash_info = first_hash_file.read() - second_hash_info = second_hash_file.read() - return first_hash_info == second_hash_info +def compare_file(first_file_path, second_file_path): + with open(first_file_path, 'r') as first_file: + with open(second_file_path, 'r') as second_file: + first_info = first_file.read() + second_info = second_file.readline() + while second_info: + if first_info.find(second_info) == -1: + print("line\n", second_info, "is not in output file", first_file_path) + return False + second_info = second_file.readline() + return True def compare_target_files(first_file_path, second_file_path): @@ -43,7 +48,7 @@ def compare_target_files(first_file_path, second_file_path): for files in common_files: if not compare_file(first_file_path + files, second_file_path + files + ".txt"): - print(first_file_path + files, second_file_path + files + ".txt") + print("file ", first_file_path + files, second_file_path + files + ".txt", "is different") return False return True @@ -61,6 +66,10 @@ def make_binary_file(file_path): return exec_command("make --directory={} --jobs=4".format(file_path)) +def clean_binary_file(file_path): + return exec_command("make --directory={} clean".format(file_path)) + + def get_all_files(path): file_list = [] for item in os.listdir(path): @@ -184,6 +193,12 @@ class UnitTest08(Test): return self.run_success() +# enum nesting idl file +class UnitTest09(Test): + def run(self): + return self.run_success() + + class Tests: test_cases = [ UnitTest01("UnitTestEmptyIdl", "01_empty_idl"), @@ -194,6 +209,7 @@ class Tests: UnitTest06("UnitTestEnumExtension", "06_extended_enum_idl"), UnitTest07("UnitTestStructExtension", "07_extended_struct_idl"), UnitTest08("UnitTestOverloadMethod", "08_overload_method_idl"), + UnitTest09("UnitTestEnumNesting", "09_enum_nesting_idl"), ] @staticmethod @@ -212,6 +228,8 @@ class Tests: def tear_down_test_case(): for case in Tests.test_cases: case.remove_output() + hdi_gen_path = "../../" + clean_binary_file(hdi_gen_path) @staticmethod def test(): -- Gitee From bccc8c6e53f3e80d930f241df54c84cbfe0c3e90 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Tue, 20 Feb 2024 11:16:13 +0800 Subject: [PATCH 6/7] feat: idl support function with same name and nested enum Signed-off-by: j30052480 --- .../tools/hdi-gen/test/unittest/unit_test.py | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/framework/tools/hdi-gen/test/unittest/unit_test.py b/framework/tools/hdi-gen/test/unittest/unit_test.py index 654648211..c72c251ac 100644 --- a/framework/tools/hdi-gen/test/unittest/unit_test.py +++ b/framework/tools/hdi-gen/test/unittest/unit_test.py @@ -24,17 +24,21 @@ def print_failure(info): print("\033[31m{}\033[0m".format(info)) +def is_subsequence(first_file, second_file): + first_info = first_file.read() + second_info = second_file.readline() + while second_info: + if first_info.find(second_info) == -1: + print("line\n", second_info, "is not in output file", first_file_path) + return False + second_info = second_file.readline() + return True + + def compare_file(first_file_path, second_file_path): with open(first_file_path, 'r') as first_file: with open(second_file_path, 'r') as second_file: - first_info = first_file.read() - second_info = second_file.readline() - while second_info: - if first_info.find(second_info) == -1: - print("line\n", second_info, "is not in output file", first_file_path) - return False - second_info = second_file.readline() - return True + return is_subsequence(first_file, second_file) def compare_target_files(first_file_path, second_file_path): @@ -72,12 +76,13 @@ def clean_binary_file(file_path): def get_all_files(path): file_list = [] - for item in os.listdir(path): - item = os.path.join(path, item) - if os.path.isdir(item): - file_list += get_all_files(item) + items = os.listdir(path) + for item in items: + item_path = os.path.join(path, item) + if not os.path.isdir(item_path): + file_list.append(item_path) else: - file_list.append(item) + file_list += get_all_files(item_path) return file_list -- Gitee From be6d3eeae50cf3d4c49254bdb5b5ed96c77f21a3 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Thu, 22 Feb 2024 16:28:06 +0800 Subject: [PATCH 7/7] feat: idl support function with same name and nested enum Signed-off-by: j30052480 --- framework/tools/hdi-gen/ast/ast_expr.h | 7 +++++++ framework/tools/hdi-gen/ast/ast_method.h | 2 +- framework/tools/hdi-gen/ast/ast_struct_type.h | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/framework/tools/hdi-gen/ast/ast_expr.h b/framework/tools/hdi-gen/ast/ast_expr.h index 4dafec0d6..767bab6cd 100644 --- a/framework/tools/hdi-gen/ast/ast_expr.h +++ b/framework/tools/hdi-gen/ast/ast_expr.h @@ -70,6 +70,13 @@ public: std::string value_; }; +/** + * @brief Defines the enumeration object structure in expression. + * + * This structure includes the enumeration information when using enum nesting identify in idl. + * + * @since 5.0 + */ class ASTEnumExpr : public ASTExpr { public: std::string Dump(const std::string &prefix) override; diff --git a/framework/tools/hdi-gen/ast/ast_method.h b/framework/tools/hdi-gen/ast/ast_method.h index fbda26ac4..d7e4ab674 100644 --- a/framework/tools/hdi-gen/ast/ast_method.h +++ b/framework/tools/hdi-gen/ast/ast_method.h @@ -88,7 +88,7 @@ private: std::string name_; AutoPtr attr_ = new ASTAttr(); std::vector> parameters_; - size_t cmdId_; + size_t cmdId_; // used to identify same name method }; } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/ast/ast_struct_type.h b/framework/tools/hdi-gen/ast/ast_struct_type.h index b6fe4cdaa..e2a6d80ad 100644 --- a/framework/tools/hdi-gen/ast/ast_struct_type.h +++ b/framework/tools/hdi-gen/ast/ast_struct_type.h @@ -130,7 +130,7 @@ public: private: AutoPtr attr_; std::vector>> members_; - AutoPtr parentType_; + AutoPtr parentType_; // used to dump parent type when using struct extension identify in idl }; } // namespace HDI } // namespace OHOS -- Gitee