From 91621f8e464db2ba54a89d2e17cf00d233ef1bc7 Mon Sep 17 00:00:00 2001 From: gou-jingjing Date: Mon, 25 Dec 2023 18:54:57 +0800 Subject: [PATCH 01/17] refactor codes Signed-off-by: gou-jingjing --- .../hcs-view/hcsWebView/src/MainEditor.js | 72 ++++++-------- .../hcsWebView/src/attr/AttributeArea.js | 96 +++++-------------- .../hcsWebView/src/engine/RightMenu.js | 33 ++----- .../hcsWebView/src/engine/control/XButton.js | 4 +- .../src/engine/graphics/XTexture.js | 38 ++------ 5 files changed, 70 insertions(+), 173 deletions(-) diff --git a/framework/tools/hcs-view/hcsWebView/src/MainEditor.js b/framework/tools/hcs-view/hcsWebView/src/MainEditor.js index 4f3987009..60a9770d0 100644 --- a/framework/tools/hcs-view/hcsWebView/src/MainEditor.js +++ b/framework/tools/hcs-view/hcsWebView/src/MainEditor.js @@ -43,6 +43,10 @@ const KEY_VALUE_MAX = 30; const ONE_KEY_VALUE_MAX = 29; const TWO_KEY_VALUE_MAX = 28; const THREE_KEY_VALUE_MAX = 27; +const BGPIC_WIDTH = 156; +const BGPIC_HEIGHT = 112; +const DRAWTEXT_OFFSETX = -3; +const DRAWTEXT_OFFSETY = -3; const MouseType = { DOWN: 1, // 按下 @@ -318,19 +322,7 @@ class MainEditor { 32 ); - let bgPic = RightMenu.isDarkBackground_ ? 'pop_background.png' : 'pop_background_light.png'; - let bgPicPath = '../images/' + bgPic; - RightMenu.backgroundImg_ = XTexture.gi().loadTextureFromImage(bgPicPath); - RightMenu.backgroundCut_ = XTexture.gi().makeCut( - RightMenu.backgroundImg_, - 0, - 0, - 156, - 112, - 156, - 112 - ); - this.cutImgDict_['backgroundCut'] = bgPic; + this.reloadBgPic(); RightMenu.popItemFocusImg_ = XTexture.gi().loadTextureFromImage( '../images/pop_item_focus.png' @@ -526,6 +518,13 @@ class MainEditor { } reloadMenuBgPic() { + let bgPic = this.reloadBgPic(); + XMessage.gi().send('reloadMenuBg', { + data: bgPic, + }); + } + + reloadBgPic() { let bgPic = RightMenu.isDarkBackground_ ? 'pop_background.png' : 'pop_background_light.png'; let bgPicPath = '../images/' + bgPic; RightMenu.backgroundImg_ = XTexture.gi().loadTextureFromImage(bgPicPath); @@ -533,15 +532,13 @@ class MainEditor { RightMenu.backgroundImg_, 0, 0, - 156, - 112, - 156, - 112 + BGPIC_WIDTH, + BGPIC_HEIGHT, + BGPIC_WIDTH, + BGPIC_HEIGHT ); - this.cutImgDict_['backgroundCut'] = bgPic; - XMessage.gi().send('reloadMenuBg', { - data: bgPic, - }); + this.cutImgDict_.backgroundCut = bgPic; + return bgPic; } calcPostionY(data, y) { @@ -1223,38 +1220,23 @@ class MainEditor { * @param {} pm2f X2DFast */ drawSelectText(pm2f) { - pm2f.drawText( - '点击选择目标', - MainEditor.NODE_TEXT_SIZE, - this.mousePos_.x, - this.mousePos_.y, - 1, - 1, - 0, - -3, - -3, - MainEditor.NODE_TEXT_COLOR - ); + let drawTextName = '点击选择目标'; + this.callDrawText(pm2f, drawTextName); this.btnCancelSelect_.name_ = '取消选择'; } + callDrawText(pm2f, drawTextName) { + pm2f.drawText(drawTextName, MainEditor.NODE_TEXT_SIZE, this.mousePos_.x, + this.mousePos_.y, 1, 1, 0, DRAWTEXT_OFFSETX, DRAWTEXT_OFFSETY, MainEditor.NODE_TEXT_COLOR); + } + /** * 绘制复制文本 * @param {} pm2f X2DFast */ drawCopyText(pm2f) { - pm2f.drawText( - '已复制' + this.selectNode_.pnode.name_, - MainEditor.NODE_TEXT_SIZE, - this.mousePos_.x, - this.mousePos_.y, - 1, - 1, - 0, - -3, - -3, - MainEditor.NODE_TEXT_COLOR - ); + let drawTextName = '已复制' + this.selectNode_.pnode.name_; + this.callDrawText(pm2f, drawTextName); this.btnCancelSelect_.name_ = '取消复制'; } diff --git a/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js b/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js index c9cfddad7..fe181646b 100644 --- a/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js +++ b/framework/tools/hcs-view/hcsWebView/src/attr/AttributeArea.js @@ -49,6 +49,13 @@ class AttributeArea { '
'; ret += '
'; + this.htmlStr += ret; + } + + addInputFunc(default_, ret, searchId, disable) { if (default_.indexOf('"') >= 0) { ret += ' value=""'; this.freshInputValue_.push([searchId, default_]); @@ -58,36 +65,16 @@ class AttributeArea { if (disable) { ret += ' disabled="disabled"'; } - ret += - ' oninput="document.attrCallback.Event(' + - "'input', " + - "'" + - searchId + - "'" + - ')" />
'; - this.htmlStr += ret; + return ret; } addInput(searchId, label, default_, disable) { let ret = '
'; ret += '= 0) { - ret += ' value=""'; - this.freshInputValue_.push([searchId, default_]); - } else { - ret += ' value="' + default_ + '"'; - } - if (disable) { - ret += ' disabled="disabled"'; - } - ret += - ' oninput="document.attrCallback.Event(' + - "'input', " + - "'" + - searchId + - "'" + - ')" />
'; + ret = this.addInputFunc(default_, ret, searchId, disable); + ret += ' oninput="document.attrCallback.Event(' + "'input', " + "'" + + searchId + "'" + ')" />
'; this.htmlStr += ret; } @@ -101,17 +88,8 @@ class AttributeArea { let validatorId = 'valid_' + searchId; let ret = '
'; ret += '= 0) { - ret += ' value=""'; - this.freshInputValue_.push([searchId, default_]); - } else { - ret += ' value="' + default_ + '"'; - } - if (disable) { - ret += ' disabled="disabled"'; - } + ret += ' class="input_text" maxlength="40" placeholder="' + defaultTxt + '"'; + ret = this.addInputFunc(default_, ret, searchId, disable); ret += ' autofocus="autofocus" onFocus="document.attrCallback.Event(' + "'input', " + @@ -154,56 +132,30 @@ class AttributeArea { } let text = '" class="button_click" type="button" onclick="document.attrCallback.Event('; - this.htmlStr += - '
'; + let htmlString = this.getStrText(searchId, text, label); + this.htmlStr += '
'; + } + addLabelButton(searchId, label, title) { if (label.length > MAX_LABEL_LENGTH) { label = label.substring(0, MAX_LABEL_LENGTH) + '...'; } let text = '" class="label_button_click" type="button" onclick="document.attrCallback.Event('; - this.htmlStr += - '

'; + let htmlString = this.getStrText(searchId, text, label); + this.htmlStr += '

'; + let text = '" class="button_click_delete" type="button" onclick="document.attrCallback.Event('; + this.htmlStr += '
'; } addSelect(searchId, label, selectList, default_, disable) { let ret = '
'; diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/RightMenu.js b/framework/tools/hcs-view/hcsWebView/src/engine/RightMenu.js index 6ae545cfc..58a66e6e1 100755 --- a/framework/tools/hcs-view/hcsWebView/src/engine/RightMenu.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/RightMenu.js @@ -28,6 +28,8 @@ const MenuGroupSize = { }; const MOUSETYPE_MOVE = 2; +const DRAWTEXT_OFFSETX = -3; +const DRAWTEXT_OFFSETY = -2; class RightMenu { static backgroundImg_ = -1; @@ -158,37 +160,20 @@ class RightMenu { } } else if (e.type === MenuType.CONTENT) { if (e.open) { - X2DFast.px2f.drawText( - '<', - RightMenu.TEXT_SIZE, - x + w, - OFFY_, - 1, - 1, - 0, - -3, - -2, - textColor - ); + RightMenu.callDrawText('<', x, w, OFFY_, textColor); RightMenu.DrawGroup(e.group, x + w, y); } else { - X2DFast.px2f.drawText( - '>', - RightMenu.TEXT_SIZE, - x + w, - OFFY_, - 1, - 1, - 0, - -3, - -2, - textColor - ); + RightMenu.callDrawText('>', x, w, OFFY_, textColor); } } y += 32; } } + static callDrawText(symbol, x, w, OFFY_, textColor) { + X2DFast.px2f.drawText(symbol, RightMenu.TEXT_SIZE, x + w, OFFY_, 1, 1, 0, + DRAWTEXT_OFFSETX, DRAWTEXT_OFFSETY, textColor); + } + static Touch(msg, x, y) { if (RightMenu.MENU) { if (RightMenu.TouchGroup(RightMenu.MENU.detail, msg, x, y)) { diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js b/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js index 7e2f757bd..e6c751427 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/control/XButton.js @@ -64,7 +64,7 @@ class XButton { } } - isTouchIn(x, y) { + isTouchInButton(x, y) { if (x < this.posX_) { return false; } @@ -80,7 +80,7 @@ class XButton { return true; } procTouch(msg, x, y) { - let isIn = this.isTouchIn(x, y); + let isIn = this.isTouchInButton(x, y); switch (msg) { case 1: if (isIn) { diff --git a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js index d975455cb..ad46024f7 100644 --- a/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js +++ b/framework/tools/hcs-view/hcsWebView/src/engine/graphics/XTexture.js @@ -115,24 +115,16 @@ export class XTexture { if (h === -1) { h = hh; } - this.allCuts[this.tmpCutid] = { - rid: rid, - x: x, - y: y, - w: w, - h: h, - u0: x / ww, - v0: y / hh, - u1: (x + w) / ww, - v1: y / hh, - u2: (x + w) / ww, - v2: (y + h) / hh, - u3: x / ww, - v3: (y + h) / hh, - }; + this.callAllCuts(this.tmpCutid, rid, x, y, w, h, ww, hh); this.tmpCutid += 1; return this.tmpCutid - 1; } + callAllCuts(param, rid, x, y, w, h, ww, hh) { + this.allCuts[param] = { + rid: rid, x: x, y: y, w: w, h: h, u0: x / ww, v0: y / hh, u1: (x + w) / ww, v1: y / hh, + u2: (x + w) / ww, v2: (y + h) / hh, u3: x / ww, v3: (y + h) / hh, + }; + } makeCut(rid, x = 0, y = 0, w = -1, h = -1, ww = -1, hh = -1) { if (ww === -1) { ww = this.ximages[rid].w; @@ -146,21 +138,7 @@ export class XTexture { if (h === -1) { h = hh; } - this.allCuts[this.aiCutid] = { - rid: rid, - x: x, - y: y, - w: w, - h: h, - u0: x / ww, - v0: y / hh, - u1: (x + w) / ww, - v1: y / hh, - u2: (x + w) / ww, - v2: (y + h) / hh, - u3: x / ww, - v3: (y + h) / hh, - }; + this.callAllCuts(this.aiCutid, rid, x, y, w, h, ww, hh); this.aiCutid += 1; return this.aiCutid - 1; } -- Gitee From 62bfa1646efb3c6f776de4d8b7cb9915ead09f72 Mon Sep 17 00:00:00 2001 From: zwx1283032 Date: Mon, 29 Jan 2024 17:50:41 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9hilog=E6=8F=90=E5=8F=96?= =?UTF-8?q?USB=E6=97=A5=E5=BF=97=E7=9A=84DOMAIN=20ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zwx1283032 --- adapter/khdf/liteos/model/usb/device/BUILD.gn | 1 + adapter/khdf/liteos/model/usb/host/BUILD.gn | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/adapter/khdf/liteos/model/usb/device/BUILD.gn b/adapter/khdf/liteos/model/usb/device/BUILD.gn index 2d33eaa99..de235556b 100644 --- a/adapter/khdf/liteos/model/usb/device/BUILD.gn +++ b/adapter/khdf/liteos/model/usb/device/BUILD.gn @@ -78,5 +78,6 @@ hdf_driver(module_name) { "$FRAMEWORKS_USB_DDK_DEVICE/include", "$FRAMEWORKS_USB_DRIVERS/include", "$LITEOSTOPDIR/../../device/soc/hisilicon/common/hal/usb/hi3516dv300/include", + "$HDF_PERIPHERAL_PATH/usb/utils/include", ] } diff --git a/adapter/khdf/liteos/model/usb/host/BUILD.gn b/adapter/khdf/liteos/model/usb/host/BUILD.gn index 8782d4fae..51a5519e5 100644 --- a/adapter/khdf/liteos/model/usb/host/BUILD.gn +++ b/adapter/khdf/liteos/model/usb/host/BUILD.gn @@ -40,7 +40,7 @@ hdf_driver(module_name) { "$PERIPHERAL_USB_DDK_HOST/src/usb_raw_api.c", "$PERIPHERAL_USB_DDK_HOST/src/usb_raw_api_library.c", ] - include_dirs = [] + include_dirs = [ "$HDF_PERIPHERAL_PATH/usb/utils/include" ] if (defined(LOSCFG_DRIVERS_HDF_USB_PNP_NOTIFY)) { USB_PNP_NOTIFY_SHARED_ROOT = "$HDF_FRAMEWORKS_PATH/core/shared" FRAMEWORKS_USB_DDK_HOST = "$HDF_FRAMEWORKS_PATH/model/usb" @@ -58,6 +58,7 @@ hdf_driver(module_name) { "$HDF_INTERFACE_PATH/inner_api/osal/shared", "$HDF_INTERFACE_PATH/inner_api/host/shared", "$FRAMEWORKS_USB_DDK_HOST/include", + "$HDF_PERIPHERAL_PATH/usb/utils/include", ] public_configs = [ ":public" ] } @@ -81,6 +82,7 @@ hdf_driver(module_name) { "$FRAMEWORKS_USB_SERIAL_DEMO_ROOT/include", "$FRAMEWORKS_USB_NET_DEMO_ROOT/include", "$FRAMEWORKS_USB_DDK_SPEED_TEST_ROOT/include", + "$HDF_PERIPHERAL_PATH/usb/utils/include", ] } @@ -88,6 +90,7 @@ hdf_driver(module_name) { "$PERIPHERAL_USB_DDK_HOST/../../interfaces/ddk/common", "$PERIPHERAL_USB_DDK_HOST/../../interfaces/ddk/host", "$PERIPHERAL_USB_DDK_HOST/include", + "$HDF_PERIPHERAL_PATH/usb/utils/include", ] } @@ -95,5 +98,6 @@ config("public") { include_dirs = [ "include", "$HDF_FRAMEWORKS_PATH/model/usb/include", + "$HDF_PERIPHERAL_PATH/usb/utils/include", ] } -- Gitee From 98d1dff451531bb0dba24a70246678fab1f4f8f4 Mon Sep 17 00:00:00 2001 From: zwx1283032 Date: Sun, 4 Feb 2024 10:08:53 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9hilog=E6=8F=90=E5=8F=96?= =?UTF-8?q?USB=E6=97=A5=E5=BF=97=E7=9A=84DOMAIN=20ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zwx1283032 --- adapter/khdf/liteos/model/usb/device/Makefile | 3 ++- adapter/khdf/liteos/model/usb/host/Makefile | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/adapter/khdf/liteos/model/usb/device/Makefile b/adapter/khdf/liteos/model/usb/device/Makefile index e0462127f..d6ace2a5f 100644 --- a/adapter/khdf/liteos/model/usb/device/Makefile +++ b/adapter/khdf/liteos/model/usb/device/Makefile @@ -39,6 +39,7 @@ LOCAL_INCLUDE := $(USB_DEVICE_ROOT) \ $(USB_DEVICE_ROOT)/gadget/fconfig/include \ $(FRAMEWORKS_USB_DDK_DEVICE)/../../interfaces/ddk/common \ $(FRAMEWORKS_USB_DDK_DEVICE)/../../interfaces/ddk/device \ + $(FRAMEWORKS_USB_DDK_DEVICE)/../../utils/include \ $(FRAMEWORKS_USB_DDK_DEVICE)/include LOCAL_SRCS += $(FRAMEWORKS_USB_DDK_DEVICE)/src/adapter_if_liteos.c \ @@ -71,4 +72,4 @@ endif endif -include $(HDF_DRIVER) +include $(HDF_DRIVER) \ No newline at end of file diff --git a/adapter/khdf/liteos/model/usb/host/Makefile b/adapter/khdf/liteos/model/usb/host/Makefile index 01b1f56a7..e7451681e 100644 --- a/adapter/khdf/liteos/model/usb/host/Makefile +++ b/adapter/khdf/liteos/model/usb/host/Makefile @@ -36,7 +36,8 @@ PERIPHERAL_USB_DDK_HOST = $(LITEOSTOPDIR)/../../drivers/peripheral/usb/ddk/host LOCAL_INCLUDE := $(PERIPHERAL_USB_DDK_HOST)/../../interfaces/ddk/common \ $(PERIPHERAL_USB_DDK_HOST)/../../interfaces/ddk/host \ - $(PERIPHERAL_USB_DDK_HOST)/include + $(PERIPHERAL_USB_DDK_HOST)/include \ + $(PERIPHERAL_USB_DDK_HOST)/../../utils/include LOCAL_SRCS += $(PERIPHERAL_USB_DDK_HOST)/src/liteos_adapter.c \ $(PERIPHERAL_USB_DDK_HOST)/src/usb_raw_api.c \ @@ -56,6 +57,7 @@ LOCAL_INCLUDE := $(USB_PNP_NOTIFY_ROOT)/include \ $(LITEOSTOPDIR)/../../drivers/hdf_core/interfaces/inner_api/utils \ $(LITEOSTOPDIR)/../../drivers/hdf_core/interfaces/inner_api/osal/shared \ $(LITEOSTOPDIR)/../../drivers/hdf_core/interfaces/inner_api/host/shared \ + $(LITEOSTOPDIR)/../../drivers/peripheral/usb/utils/include \ $(FRAMEWORKS_USB_DDK_HOST)/include LOCAL_SRCS += $(USB_PNP_NOTIFY_ROOT)/src/usb_pnp_notify.c \ @@ -73,6 +75,7 @@ LOCAL_INCLUDE := $(FRAMEWORKS_USB_SERIAL_DEMO_ROOT)/../gadget/function/include \ $(FRAMEWORKS_USB_SERIAL_DEMO_ROOT)/../interfaces/ddk/common \ $(FRAMEWORKS_USB_SERIAL_DEMO_ROOT)/../interfaces/ddk/host \ $(FRAMEWORKS_USB_SERIAL_DEMO_ROOT)/../ddk/host/include \ + $(FRAMEWORKS_USB_SERIAL_DEMO_ROOT)/../utils/include \ $(FRAMEWORKS_USB_SERIAL_DEMO_ROOT)/include \ $(FRAMEWORKS_USB_NET_DEMO_ROOT)/include \ $(FRAMEWORKS_USB_DDK_SPEED_TEST_ROOT)/include @@ -88,4 +91,4 @@ endif endif #LOCAL_CFLAGS += -fstack-protector-strong -Wextra -Wall -Werror -fsigned-char -fno-strict-aliasing -fno-common -include $(HDF_DRIVER) +include $(HDF_DRIVER) \ No newline at end of file -- Gitee From 27452e83de3412f8ce22a2d1f44c7a0acf791724 Mon Sep 17 00:00:00 2001 From: zwx1283032 Date: Sun, 4 Feb 2024 10:21:36 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9hilog=E6=8F=90=E5=8F=96?= =?UTF-8?q?USB=E6=97=A5=E5=BF=97=E7=9A=84DOMAIN=20ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zwx1283032 --- adapter/khdf/liteos/model/usb/device/Makefile | 2 +- adapter/khdf/liteos/model/usb/host/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter/khdf/liteos/model/usb/device/Makefile b/adapter/khdf/liteos/model/usb/device/Makefile index d6ace2a5f..4b196267e 100644 --- a/adapter/khdf/liteos/model/usb/device/Makefile +++ b/adapter/khdf/liteos/model/usb/device/Makefile @@ -72,4 +72,4 @@ endif endif -include $(HDF_DRIVER) \ No newline at end of file +include $(HDF_DRIVER) diff --git a/adapter/khdf/liteos/model/usb/host/Makefile b/adapter/khdf/liteos/model/usb/host/Makefile index e7451681e..5fe8dd417 100644 --- a/adapter/khdf/liteos/model/usb/host/Makefile +++ b/adapter/khdf/liteos/model/usb/host/Makefile @@ -91,4 +91,4 @@ endif endif #LOCAL_CFLAGS += -fstack-protector-strong -Wextra -Wall -Werror -fsigned-char -fno-strict-aliasing -fno-common -include $(HDF_DRIVER) \ No newline at end of file +include $(HDF_DRIVER) -- Gitee From bee5eb3d97622456909efa6cc4cd7eee605fa447 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Wed, 7 Feb 2024 16:39:17 +0800 Subject: [PATCH 05/17] 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 06/17] 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 07/17] 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 08/17] 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 09/17] 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 10/17] 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 fe2355779151390438e4790085dcf0719a4c653a Mon Sep 17 00:00:00 2001 From: lwx1281857 Date: Thu, 22 Feb 2024 09:41:43 +0800 Subject: [PATCH 11/17] Description: Code optimization Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: lwx1281857 --- .../common/include/sensor_config_parser.h | 7 --- .../driver/common/src/sensor_config_parser.c | 59 +++++++++++++------ 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/framework/model/sensor/driver/common/include/sensor_config_parser.h b/framework/model/sensor/driver/common/include/sensor_config_parser.h index 3123f701f..1ab2b1ff6 100644 --- a/framework/model/sensor/driver/common/include/sensor_config_parser.h +++ b/framework/model/sensor/driver/common/include/sensor_config_parser.h @@ -20,13 +20,6 @@ #define MAX_SENSOR_INDEX_NUM 48 #define MAX_SENSOR_AXIS_NUM 3 -#define CHECK_PARSER_NAME(ptr, str, cname) do { \ - if (strcpy_s(ptr, SENSOR_INFO_VERSION_MAX_LEN, cname) != EOK) { \ - HDF_LOGE("%s:copy %s failed!", __func__, str); \ - return HDF_FAILURE; \ - } \ -} while (0) - enum SensorRegOpsType { SENSOR_INIT_GROUP = 0, SENSOR_ENABLE_GROUP, diff --git a/framework/model/sensor/driver/common/src/sensor_config_parser.c b/framework/model/sensor/driver/common/src/sensor_config_parser.c index 022346de3..332933b58 100755 --- a/framework/model/sensor/driver/common/src/sensor_config_parser.c +++ b/framework/model/sensor/driver/common/src/sensor_config_parser.c @@ -300,30 +300,12 @@ int32_t DetectSensorDevice(struct SensorCfgData *config) return HDF_SUCCESS; } -static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, +static int32_t ParseSensorValue(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, struct SensorCfgData *config) { int32_t ret; uint16_t id; int32_t value; - const char *name = NULL; - - ret = parser->GetString(infoNode, "sensorName", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorName"); - CHECK_PARSER_NAME(config->sensorInfo.sensorName, "sensorName", name); - - ret = parser->GetString(infoNode, "vendorName", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "vendorName"); - CHECK_PARSER_NAME(config->sensorInfo.vendorName, "vendorName", name); - - ret = parser->GetString(infoNode, "firmwareVersion", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "firmwareVersion"); - CHECK_PARSER_NAME(config->sensorInfo.firmwareVersion, "firmwareVersion", name); - - ret = parser->GetString(infoNode, "hardwareVersion", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "hardwareVersion"); - CHECK_PARSER_NAME(config->sensorInfo.hardwareVersion, "hardwareVersion", name); - ret = parser->GetUint16(infoNode, "sensorTypeId", &id, 0); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorTypeId"); config->sensorInfo.sensorTypeId = id; @@ -350,6 +332,45 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct return ret; } +static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, + struct SensorCfgData *config) +{ + int32_t ret; + const char *name = NULL; + + ret = parser->GetString(infoNode, "sensorName", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorName"); + if (strcpy_s(config->sensorInfo.sensorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy sensorName failed!", __func__); + return HDF_FAILURE; + } + + ret = parser->GetString(infoNode, "vendorName", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "vendorName"); + if (strcpy_s(config->sensorInfo.vendorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy vendorName failed!", __func__); + return HDF_FAILURE; + } + + ret = parser->GetString(infoNode, "firmwareVersion", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "firmwareVersion"); + if (strcpy_s(config->sensorInfo.firmwareVersion, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy firmwareVersion failed!", __func__); + return HDF_FAILURE; + } + + ret = parser->GetString(infoNode, "hardwareVersion", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "hardwareVersion"); + if (strcpy_s(config->sensorInfo.hardwareVersion, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy hardwareVersion failed!", __func__); + return HDF_FAILURE; + } + + ret = ParseSensorValue(parser, infoNode, config); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "ParseSensorValue"); + return ret; +} + static int32_t ParseSensorSpiBus(struct DeviceResourceIface *parser, const struct DeviceResourceNode *spiBusNode, struct SensorBusCfg *busConfig) { -- Gitee From 03c646b5536cbecf346664b0af66c40919115681 Mon Sep 17 00:00:00 2001 From: lwx1281857 Date: Thu, 22 Feb 2024 15:38:37 +0800 Subject: [PATCH 12/17] Description: Code optimization Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: lwx1281857 --- .../driver/common/src/sensor_config_parser.c | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/framework/model/sensor/driver/common/src/sensor_config_parser.c b/framework/model/sensor/driver/common/src/sensor_config_parser.c index 332933b58..b535d63d7 100755 --- a/framework/model/sensor/driver/common/src/sensor_config_parser.c +++ b/framework/model/sensor/driver/common/src/sensor_config_parser.c @@ -300,6 +300,43 @@ int32_t DetectSensorDevice(struct SensorCfgData *config) return HDF_SUCCESS; } +static int32_t ParseSensorString(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, + struct SensorCfgData *config) +{ + int32_t ret; + const char *name = NULL; + + ret = parser->GetString(infoNode, "sensorName", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorName"); + if (strcpy_s(config->sensorInfo.sensorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy sensorName failed!", __func__); + return HDF_FAILURE; + } + + ret = parser->GetString(infoNode, "vendorName", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "vendorName"); + if (strcpy_s(config->sensorInfo.vendorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy vendorName failed!", __func__); + return HDF_FAILURE; + } + + ret = parser->GetString(infoNode, "firmwareVersion", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "firmwareVersion"); + if (strcpy_s(config->sensorInfo.firmwareVersion, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy firmwareVersion failed!", __func__); + return HDF_FAILURE; + } + + ret = parser->GetString(infoNode, "hardwareVersion", &name, NULL); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "hardwareVersion"); + if (strcpy_s(config->sensorInfo.hardwareVersion, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { + HDF_LOGE("%s:copy hardwareVersion failed!", __func__); + return HDF_FAILURE; + } + + return ret; +} + static int32_t ParseSensorValue(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, struct SensorCfgData *config) { @@ -336,35 +373,10 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct struct SensorCfgData *config) { int32_t ret; - const char *name = NULL; - ret = parser->GetString(infoNode, "sensorName", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorName"); - if (strcpy_s(config->sensorInfo.sensorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { - HDF_LOGE("%s:copy sensorName failed!", __func__); - return HDF_FAILURE; - } + ret = ParseSensorString(parser, infoNode, config); + CHECK_PARSER_RESULT_RETURN_VALUE(ret, "ParseSensorString"); - ret = parser->GetString(infoNode, "vendorName", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "vendorName"); - if (strcpy_s(config->sensorInfo.vendorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { - HDF_LOGE("%s:copy vendorName failed!", __func__); - return HDF_FAILURE; - } - - ret = parser->GetString(infoNode, "firmwareVersion", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "firmwareVersion"); - if (strcpy_s(config->sensorInfo.firmwareVersion, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { - HDF_LOGE("%s:copy firmwareVersion failed!", __func__); - return HDF_FAILURE; - } - - ret = parser->GetString(infoNode, "hardwareVersion", &name, NULL); - CHECK_PARSER_RESULT_RETURN_VALUE(ret, "hardwareVersion"); - if (strcpy_s(config->sensorInfo.hardwareVersion, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { - HDF_LOGE("%s:copy hardwareVersion failed!", __func__); - return HDF_FAILURE; - } ret = ParseSensorValue(parser, infoNode, config); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "ParseSensorValue"); -- Gitee From db048fe054ff36fb976ceb8ceeb4a4deff9120fe Mon Sep 17 00:00:00 2001 From: lwx1281857 Date: Thu, 22 Feb 2024 15:43:57 +0800 Subject: [PATCH 13/17] Description: Code optimization Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: lwx1281857 --- framework/model/sensor/driver/common/src/sensor_config_parser.c | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/model/sensor/driver/common/src/sensor_config_parser.c b/framework/model/sensor/driver/common/src/sensor_config_parser.c index b535d63d7..c9cfe3b6d 100755 --- a/framework/model/sensor/driver/common/src/sensor_config_parser.c +++ b/framework/model/sensor/driver/common/src/sensor_config_parser.c @@ -377,7 +377,6 @@ static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct ret = ParseSensorString(parser, infoNode, config); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "ParseSensorString"); - ret = ParseSensorValue(parser, infoNode, config); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "ParseSensorValue"); return ret; -- Gitee From be6d3eeae50cf3d4c49254bdb5b5ed96c77f21a3 Mon Sep 17 00:00:00 2001 From: j30052480 Date: Thu, 22 Feb 2024 16:28:06 +0800 Subject: [PATCH 14/17] 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 From 298ea91fa37bc5f39ece62c38105c9bd1e0063b8 Mon Sep 17 00:00:00 2001 From: lwx1281857 Date: Thu, 22 Feb 2024 20:25:37 +0800 Subject: [PATCH 15/17] Description: Code optimization Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: lwx1281857 --- .../sensor/driver/common/src/sensor_config_parser.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/framework/model/sensor/driver/common/src/sensor_config_parser.c b/framework/model/sensor/driver/common/src/sensor_config_parser.c index c9cfe3b6d..98c89b07c 100755 --- a/framework/model/sensor/driver/common/src/sensor_config_parser.c +++ b/framework/model/sensor/driver/common/src/sensor_config_parser.c @@ -303,10 +303,9 @@ int32_t DetectSensorDevice(struct SensorCfgData *config) static int32_t ParseSensorString(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, struct SensorCfgData *config) { - int32_t ret; const char *name = NULL; - ret = parser->GetString(infoNode, "sensorName", &name, NULL); + int32_t ret = parser->GetString(infoNode, "sensorName", &name, NULL); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorName"); if (strcpy_s(config->sensorInfo.sensorName, SENSOR_INFO_NAME_MAX_LEN, name) != EOK) { HDF_LOGE("%s:copy sensorName failed!", __func__); @@ -340,10 +339,9 @@ static int32_t ParseSensorString(struct DeviceResourceIface *parser, const struc static int32_t ParseSensorValue(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, struct SensorCfgData *config) { - int32_t ret; uint16_t id; int32_t value; - ret = parser->GetUint16(infoNode, "sensorTypeId", &id, 0); + int32_t ret = parser->GetUint16(infoNode, "sensorTypeId", &id, 0); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "sensorTypeId"); config->sensorInfo.sensorTypeId = id; ret = parser->GetUint16(infoNode, "sensorId", &id, 0); @@ -372,9 +370,7 @@ static int32_t ParseSensorValue(struct DeviceResourceIface *parser, const struct static int32_t ParseSensorInfo(struct DeviceResourceIface *parser, const struct DeviceResourceNode *infoNode, struct SensorCfgData *config) { - int32_t ret; - - ret = ParseSensorString(parser, infoNode, config); + int32_t ret = ParseSensorString(parser, infoNode, config); CHECK_PARSER_RESULT_RETURN_VALUE(ret, "ParseSensorString"); ret = ParseSensorValue(parser, infoNode, config); -- Gitee From 9850c2978c89e6b8bc90afc12587ff8d7149a7d5 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Fri, 23 Feb 2024 08:22:30 +0000 Subject: [PATCH 16/17] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!2?= =?UTF-8?q?070=20:=20feat:=20idl=20support=20function=20with=20same=20name?= =?UTF-8?q?=20and=20nested=20enum'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 | 13 - framework/tools/hdi-gen/ast/ast_method.cpp | 19 -- framework/tools/hdi-gen/ast/ast_method.h | 13 - .../tools/hdi-gen/ast/ast_struct_type.cpp | 19 +- framework/tools/hdi-gen/ast/ast_struct_type.h | 8 - .../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 | 64 +---- framework/tools/hdi-gen/parser/parser.h | 4 - .../unittest/01_empty_idl/foo/v1_0/IFoo.idl | 14 - .../01_empty_idl/target/fail_output.txt | 2 - .../foo/v1_0/IFoo.idl | 24 -- .../target/foo/v1_0/foo_proxy.cpp.txt | 120 -------- .../target/foo/v1_0/foo_service.h.txt | 9 - .../target/foo/v1_0/foo_stub.cpp.txt | 108 -------- .../target/foo/v1_0/ifoo.h.txt | 46 ---- .../foo/v1_0/IFoo.idl | 24 -- .../foo/v1_0/IFooCallback.idl | 20 -- .../foo/v1_0/foo_callback_proxy.cpp.txt | 46 ---- .../foo/v1_0/foo_callback_service.h.txt | 18 -- .../target/foo/v1_0/foo_callback_stub.cpp.txt | 53 ---- .../target/foo/v1_0/ifoo_callback.h.txt | 11 - .../foo/v1_0/IFoo.idl | 24 -- .../foo/v1_1/IFoo.idl | 24 -- .../target/foo/v1_1/foo_proxy.cpp.txt | 162 ----------- .../target/foo/v1_1/foo_service.h.txt | 18 -- .../target/foo/v1_1/foo_stub.cpp.txt | 112 -------- .../target/foo/v1_1/ifoo.h.txt | 25 -- .../unittest/05_types_idl/foo/v1_0/IFoo.idl | 26 -- .../unittest/05_types_idl/foo/v1_0/Types.idl | 27 -- .../target/foo/v1_0/types.cpp.txt | 48 ---- .../05_types_idl/target/foo/v1_0/types.h.txt | 29 -- .../06_extended_enum_idl/foo/v1_0/IFoo.idl | 26 -- .../06_extended_enum_idl/foo/v1_0/Types.idl | 32 --- .../target/foo/v1_0/types.cpp.txt | 8 - .../target/foo/v1_0/types.h.txt | 27 -- .../07_extended_struct_idl/foo/v1_0/IFoo.idl | 26 -- .../07_extended_struct_idl/foo/v1_0/Types.idl | 32 --- .../target/foo/v1_0/types.cpp.txt | 74 ----- .../target/foo/v1_0/types.h.txt | 32 --- .../08_overload_method_idl/foo/v1_0/IFoo.idl | 24 -- .../08_overload_method_idl/foo/v1_1/IFoo.idl | 24 -- .../target/foo/v1_1/foo_proxy.cpp.txt | 74 ----- .../target/foo/v1_1/foo_service.h.txt | 16 -- .../target/foo/v1_1/foo_stub.cpp.txt | 99 ------- .../target/foo/v1_1/ifoo.h.txt | 12 - .../09_enum_nesting_idl/foo/v1_0/IFoo.idl | 26 -- .../09_enum_nesting_idl/foo/v1_0/Types.idl | 28 -- .../target/foo/v1_0/types.h.txt | 23 -- .../tools/hdi-gen/test/unittest/unit_test.py | 258 ------------------ 53 files changed, 16 insertions(+), 2022 deletions(-) delete mode 100644 framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/01_empty_idl/target/fail_output.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_proxy.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_stub.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFooCallback.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_proxy.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt delete 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_callback.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_1/IFoo.idl delete 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_service.h.txt delete 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/ifoo.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/Types.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/Types.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/Types.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_1/IFoo.idl delete 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_service.h.txt delete 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/ifoo.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/IFoo.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/Types.idl delete mode 100644 framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/target/foo/v1_0/types.h.txt delete mode 100644 framework/tools/hdi-gen/test/unittest/unit_test.py diff --git a/framework/tools/hdi-gen/ast/ast_enum_type.h b/framework/tools/hdi-gen/ast/ast_enum_type.h index 0a37586bd..e371055b5 100644 --- a/framework/tools/hdi-gen/ast/ast_enum_type.h +++ b/framework/tools/hdi-gen/ast/ast_enum_type.h @@ -110,16 +110,6 @@ 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 e5f6d806f..81da7d0b1 100644 --- a/framework/tools/hdi-gen/ast/ast_expr.cpp +++ b/framework/tools/hdi-gen/ast/ast_expr.cpp @@ -103,22 +103,5 @@ 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 767bab6cd..a50e3003e 100644 --- a/framework/tools/hdi-gen/ast/ast_expr.h +++ b/framework/tools/hdi-gen/ast/ast_expr.h @@ -69,19 +69,6 @@ public: std::string Dump(const std::string &prefix) override; 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; - std::string value_; -}; } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/ast/ast_method.cpp b/framework/tools/hdi-gen/ast/ast_method.cpp index 6b0e94f7a..0dc89a367 100644 --- a/framework/tools/hdi-gen/ast/ast_method.cpp +++ b/framework/tools/hdi-gen/ast/ast_method.cpp @@ -7,29 +7,10 @@ */ #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 d7e4ab674..89e44ce4a 100644 --- a/framework/tools/hdi-gen/ast/ast_method.h +++ b/framework/tools/hdi-gen/ast/ast_method.h @@ -61,8 +61,6 @@ public: return attr_->HasValue(ASTAttr::MINI); } - bool IsOverload(AutoPtr interface); - void AddParameter(const AutoPtr ¶meter); AutoPtr GetParameter(size_t index); @@ -72,23 +70,12 @@ 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_; // used to identify same name method }; } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/ast/ast_struct_type.cpp b/framework/tools/hdi-gen/ast/ast_struct_type.cpp index 7b8f277c3..ff7f14bdc 100644 --- a/framework/tools/hdi-gen/ast/ast_struct_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_struct_type.cpp @@ -11,19 +11,6 @@ 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_) { @@ -47,11 +34,7 @@ std::string ASTStructType::Dump(const std::string &prefix) { StringBuilder sb; sb.Append(prefix).Append(attr_->Dump(prefix)).Append(" "); - 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()); - } + sb.AppendFormat("struct %s {\n", name_.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 e2a6d80ad..81ad65be2 100644 --- a/framework/tools/hdi-gen/ast/ast_struct_type.h +++ b/framework/tools/hdi-gen/ast/ast_struct_type.h @@ -49,15 +49,8 @@ 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(); @@ -130,7 +123,6 @@ public: private: AutoPtr attr_; std::vector>> members_; - AutoPtr parentType_; // used to dump parent type when using struct extension identify in idl }; } // 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 289806139..d5645eb24 100644 --- a/framework/tools/hdi-gen/codegen/code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/code_emitter.cpp @@ -153,8 +153,7 @@ std::string CodeEmitter::InterfaceToFilePath(const std::string &interfaceName) c std::string CodeEmitter::EmitMethodCmdID(const AutoPtr &method) { - return StringHelper::Format("CMD_%s_%s_%d", - ConstantName(baseName_).c_str(), ConstantName(method->GetName()).c_str(), method->GetCmdId()); + return StringHelper::Format("CMD_%s_%s", ConstantName(baseName_).c_str(), ConstantName(method->GetName()).c_str()); } 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 16224d009..91982cd02 100644 --- a/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp @@ -196,12 +196,6 @@ 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 2bba7d98d..e48f11c22 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,18 +150,17 @@ 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_%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()); + 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()); } void CppServiceStubCodeEmitter::EmitStubStaticMethodDecl( const AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { sb.Append(prefix).AppendFormat( - "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(), + "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(), optionName_.c_str(), EmitDefinitionByInterface(interface_, interfaceName_).c_str()); } @@ -345,15 +344,13 @@ 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_%d(data, reply, option);\n", - baseName_.c_str(), getVerMethod->GetName().c_str(), getVerMethod->GetCmdId()); + .AppendFormat("return %sStub%s(data, reply, option);\n", baseName_.c_str(), getVerMethod->GetName().c_str()); 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_%d(data, reply, option);\n", - baseName_.c_str(), method->GetName().c_str(), method->GetCmdId()); + .AppendFormat("return %sStub%s(data, reply, option);\n", baseName_.c_str(), method->GetName().c_str()); } interface = interface->GetExtendsInterface(); } @@ -396,14 +393,13 @@ 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_%d(MessageParcel& %s, MessageParcel& %s, MessageOption& %s)\n", - EmitDefinitionByInterface(interface_, stubName_).c_str(), - stubName_.c_str(), method->GetName().c_str(), method->GetCmdId(), + 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(), dataParcelName_.c_str(), replyParcelName_.c_str(), optionName_.c_str()); sb.Append(prefix).Append("{\n"); - sb.Append(prefix + TAB).AppendFormat("return %s::%s%s_%d_(%s, %s, %s, impl_);\n", + sb.Append(prefix + TAB).AppendFormat("return %s::%s%s_(%s, %s, %s, impl_);\n", EmitDefinitionByInterface(interface, stubName_).c_str(), - stubName_.c_str(), method->GetName().c_str(), method->GetCmdId(), + stubName_.c_str(), method->GetName().c_str(), dataParcelName_.c_str(), replyParcelName_.c_str(), optionName_.c_str()); sb.Append("}\n"); @@ -413,9 +409,8 @@ void CppServiceStubCodeEmitter::EmitStubStaticMethodImpl( const AutoPtr &method, StringBuilder &sb, const std::string &prefix) const { sb.Append(prefix).AppendFormat( - "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(), + "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(), 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 063065244..7f95b33b1 100644 --- a/framework/tools/hdi-gen/parser/parser.cpp +++ b/framework/tools/hdi-gen/parser/parser.cpp @@ -43,7 +43,6 @@ 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) { @@ -547,14 +546,6 @@ 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; } @@ -1003,7 +994,6 @@ AutoPtr Parser::ParseUserDefType() void Parser::ParseEnumDeclaration(const AttrSet &attrs) { AutoPtr enumType = new ASTEnumType; - g_currentEnum = enumType; enumType->SetAttribute(ParseUserDefTypeAttr(attrs)); lexer_.GetToken(); @@ -1040,7 +1030,6 @@ void Parser::ParseEnumDeclaration(const AttrSet &attrs) enumType->SetNamespace(ast_->ParseNamespace(ast_->GetFullName())); ast_->AddTypeDefinition(enumType.Get()); - g_currentEnum = nullptr; } AutoPtr Parser::ParseEnumBaseType() @@ -1127,10 +1116,7 @@ void Parser::ParseStructDeclaration(const AttrSet &attrs) } token = lexer_.PeekToken(); - if (token.kind == TokenType::COLON) { - AutoPtr parentType = ParseStructParentType(); - structType->SetParentType(parentType); - } else if (token.kind != TokenType::BRACES_LEFT) { + if (token.kind != TokenType::BRACES_LEFT) { LogError(token, StringHelper::Format("expected '{' before '%s' token", token.value.c_str())); } else { lexer_.GetToken(); @@ -1156,34 +1142,6 @@ 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(); @@ -1522,13 +1480,6 @@ 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); @@ -1549,19 +1500,6 @@ 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 0d570bb76..9b307f6ee 100644 --- a/framework/tools/hdi-gen/parser/parser.h +++ b/framework/tools/hdi-gen/parser/parser.h @@ -134,8 +134,6 @@ private: // parse declaration of struct void ParseStructDeclaration(const AttrSet &attrs = {}); - AutoPtr ParseStructParentType(); - void ParseStructMember(const AutoPtr &structType); // parse declaration of union @@ -169,8 +167,6 @@ 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/01_empty_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl deleted file mode 100644 index 96d02c8e1..000000000 --- a/framework/tools/hdi-gen/test/unittest/01_empty_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,14 +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. - */ \ No newline at end of file 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 deleted file mode 100644 index 3c62fc974..000000000 --- a/framework/tools/hdi-gen/test/unittest/01_empty_idl/target/fail_output.txt +++ /dev/null @@ -1,2 +0,0 @@ -[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 deleted file mode 100644 index 301e8791e..000000000 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,24 +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. - */ - -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/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 deleted file mode 100644 index 9c69b0d39..000000000 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_proxy.cpp.txt +++ /dev/null @@ -1,120 +0,0 @@ -#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 deleted file mode 100644 index 7fa27784c..000000000 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_service.h.txt +++ /dev/null @@ -1,9 +0,0 @@ -#include "v1_0/ifoo.h" - -class FooService : public OHOS::HDI::Foo::V1_0::IFoo { - 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; -}; \ 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 deleted file mode 100644 index f5a240ff2..000000000 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/foo_stub.cpp.txt +++ /dev/null @@ -1,108 +0,0 @@ -#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 deleted file mode 100644 index b72a58638..000000000 --- a/framework/tools/hdi-gen/test/unittest/02_standard_interface_idl/target/foo/v1_0/ifoo.h.txt +++ /dev/null @@ -1,46 +0,0 @@ -#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 { - 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; -}; -} // V1_0 -} // Foo -} // HDI -} // OHOS \ 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 deleted file mode 100644 index 301e8791e..000000000 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,24 +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. - */ - -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 deleted file mode 100644 index 2e991fcc7..000000000 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/foo/v1_0/IFooCallback.idl +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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_proxy.cpp.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_proxy.cpp.txt deleted file mode 100644 index 3219dbf47..000000000 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_proxy.cpp.txt +++ /dev/null @@ -1,46 +0,0 @@ -#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 deleted file mode 100644 index 135aa1a0f..000000000 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_service.h.txt +++ /dev/null @@ -1,18 +0,0 @@ -#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 { - 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_callback_stub.cpp.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_stub.cpp.txt deleted file mode 100644 index d5444c6df..000000000 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/foo_callback_stub.cpp.txt +++ /dev/null @@ -1,53 +0,0 @@ -#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_callback.h.txt b/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt deleted file mode 100644 index aabfea55f..000000000 --- a/framework/tools/hdi-gen/test/unittest/03_standard_callback_idl/target/foo/v1_0/ifoo_callback.h.txt +++ /dev/null @@ -1,11 +0,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 { - virtual int32_t PushData(const std::string& message) = 0; -}; \ 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 deleted file mode 100644 index 301e8791e..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,24 +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. - */ - -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 deleted file mode 100644 index b58ae9415..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/foo/v1_1/IFoo.idl +++ /dev/null @@ -1,24 +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. - */ - -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_1/foo_proxy.cpp.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.cpp.txt deleted file mode 100644 index 6e3dabf56..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_proxy.cpp.txt +++ /dev/null @@ -1,162 +0,0 @@ -#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_service.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt deleted file mode 100644 index b9623d6d0..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_service.h.txt +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef OHOS_HDI_FOO_V1_1_FOOSERVICE_H -#define OHOS_HDI_FOO_V1_1_FOOSERVICE_H - -#include "v1_1/ifoo.h" - -class FooService : public OHOS::HDI::Foo::V1_1::IFoo { - 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; -}; - -#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 deleted file mode 100644 index af7aebf1d..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/foo_stub.cpp.txt +++ /dev/null @@ -1,112 +0,0 @@ -#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/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt deleted file mode 100644 index 989d4d478..000000000 --- a/framework/tools/hdi-gen/test/unittest/04_extended_interface_idl/target/foo/v1_1/ifoo.h.txt +++ /dev/null @@ -1,25 +0,0 @@ -#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" - -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 { - virtual int32_t TestPingV1_1(const std::string& sendMsg, std::string& recvMsg) = 0; - - virtual int32_t TestGetData(std::string& info) = 0; -}; - -#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 deleted file mode 100644 index 6ed1975b3..000000000 --- a/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,26 +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. - */ - -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 deleted file mode 100644 index ed068503d..000000000 --- a/framework/tools/hdi-gen/test/unittest/05_types_idl/foo/v1_0/Types.idl +++ /dev/null @@ -1,27 +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. - */ - -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 deleted file mode 100644 index d86b2abc8..000000000 --- a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.cpp.txt +++ /dev/null @@ -1,48 +0,0 @@ -#include "v1_0/types.h" -#include -#include -#include - -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; -} \ 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 deleted file mode 100644 index 958d52784..000000000 --- a/framework/tools/hdi-gen/test/unittest/05_types_idl/target/foo/v1_0/types.h.txt +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef OHOS_HDI_FOO_V1_0_TYPES_H -#define OHOS_HDI_FOO_V1_0_TYPES_H - -#include -#include -#include - -namespace OHOS { -class MessageParcel; -} - -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); - -#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 deleted file mode 100644 index 6ed1975b3..000000000 --- a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,26 +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. - */ - -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 deleted file mode 100644 index 0486a8572..000000000 --- a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/foo/v1_0/Types.idl +++ /dev/null @@ -1,32 +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. - */ - -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 deleted file mode 100644 index e287186b4..000000000 --- a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.cpp.txt +++ /dev/null @@ -1,8 +0,0 @@ -#include "v1_0/types.h" -#include -#include -#include - -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/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 deleted file mode 100644 index 9b475b7b6..000000000 --- a/framework/tools/hdi-gen/test/unittest/06_extended_enum_idl/target/foo/v1_0/types.h.txt +++ /dev/null @@ -1,27 +0,0 @@ -namespace OHOS { -class MessageParcel; -} - -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); \ 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 deleted file mode 100644 index 884fa5a04..000000000 --- a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,26 +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. - */ - -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 deleted file mode 100644 index eb20b8cd1..000000000 --- a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/foo/v1_0/Types.idl +++ /dev/null @@ -1,32 +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. - */ - -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 deleted file mode 100644 index 9bea95eab..000000000 --- a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.cpp.txt +++ /dev/null @@ -1,74 +0,0 @@ -#include "v1_0/types.h" -#include -#include -#include - -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) -{ - 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; -} \ 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 deleted file mode 100644 index bf4ee00cd..000000000 --- a/framework/tools/hdi-gen/test/unittest/07_extended_struct_idl/target/foo/v1_0/types.h.txt +++ /dev/null @@ -1,32 +0,0 @@ -namespace OHOS { -class MessageParcel; -} - -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); \ 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 deleted file mode 100644 index 301e8791e..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,24 +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. - */ - -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 deleted file mode 100644 index ff3783f02..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/foo/v1_1/IFoo.idl +++ /dev/null @@ -1,24 +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. - */ - -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.cpp.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.cpp.txt deleted file mode 100644 index 9e9b296d8..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_proxy.cpp.txt +++ /dev/null @@ -1,74 +0,0 @@ -#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_service.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt deleted file mode 100644 index de316e01d..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_service.h.txt +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef OHOS_HDI_FOO_V1_1_FOOSERVICE_H -#define OHOS_HDI_FOO_V1_1_FOOSERVICE_H - -#include "v1_1/ifoo.h" - -class FooService : public OHOS::HDI::Foo::V1_1::IFoo { - 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; -}; \ 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 deleted file mode 100644 index 8d8989fb6..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/foo_stub.cpp.txt +++ /dev/null @@ -1,99 +0,0 @@ -#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/ifoo.h.txt b/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt deleted file mode 100644 index dd3f2f23a..000000000 --- a/framework/tools/hdi-gen/test/unittest/08_overload_method_idl/target/foo/v1_1/ifoo.h.txt +++ /dev/null @@ -1,12 +0,0 @@ -enum { - CMD_FOO_PING_4 = 4, - CMD_FOO_GET_DATA_5 = 5, -}; - -class IFoo : public OHOS::HDI::Foo::V1_0::IFoo { - 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; -}; \ No newline at end of file diff --git a/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/IFoo.idl b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/IFoo.idl deleted file mode 100644 index 6ed1975b3..000000000 --- a/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/IFoo.idl +++ /dev/null @@ -1,26 +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. - */ - -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/09_enum_nesting_idl/foo/v1_0/Types.idl b/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/Types.idl deleted file mode 100644 index b554fedb8..000000000 --- a/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/foo/v1_0/Types.idl +++ /dev/null @@ -1,28 +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. - */ - -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), -}; - -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 deleted file mode 100644 index 3b51b25f5..000000000 --- a/framework/tools/hdi-gen/test/unittest/09_enum_nesting_idl/target/foo/v1_0/types.h.txt +++ /dev/null @@ -1,23 +0,0 @@ -#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 deleted file mode 100644 index c72c251ac..000000000 --- a/framework/tools/hdi-gen/test/unittest/unit_test.py +++ /dev/null @@ -1,258 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# 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. -# 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 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: - return is_subsequence(first_file, second_file) - - -def compare_target_files(first_file_path, 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_list]) - second_files = set([file[len(second_file_path):-4] for file in second_files_list]) - - common_files = first_files & second_files - - for files in common_files: - if not compare_file(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 - - -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)) - - -def clean_binary_file(file_path): - return exec_command("make --directory={} clean".format(file_path)) - - -def get_all_files(path): - file_list = [] - 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 += get_all_files(item_path) - 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 - 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 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)) - 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 run(self): - return self.run_fail() - - -# standard interface idl file -class UnitTest02(Test): - def run(self): - return self.run_success() - - -# standard callback idl file -class UnitTest03(Test): - def run(self): - return self.run_success() - - -# extended interface idl file -class UnitTest04(Test): - def run(self): - return self.run_success() - - -# interface with types idl file -class UnitTest05(Test): - def run(self): - return self.run_success() - - -# extended enum idl file -class UnitTest06(Test): - def run(self): - return self.run_success() - - -# extended struct idl file -class UnitTest07(Test): - def run(self): - return self.run_success() - - -# overload method idl file -class UnitTest08(Test): - def run(self): - 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"), - 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"), - UnitTest07("UnitTestStructExtension", "07_extended_struct_idl"), - UnitTest08("UnitTestOverloadMethod", "08_overload_method_idl"), - UnitTest09("UnitTestEnumNesting", "09_enum_nesting_idl"), - ] - - @staticmethod - def set_up_test_case(): - hdi_gen_file = "../../hdi-gen" - ret = file_exists(hdi_gen_file) - if not ret: - 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 - - @staticmethod - 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(): - 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 48e27759faeb49d01402f2fe16023891dd670501 Mon Sep 17 00:00:00 2001 From: fan-jingle Date: Mon, 26 Feb 2024 16:01:50 +0800 Subject: [PATCH 17/17] Modify the key Signed-off-by: fan-jingle --- framework/README_zh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/README_zh.md b/framework/README_zh.md index 1b9a80849..9adac731b 100644 --- a/framework/README_zh.md +++ b/framework/README_zh.md @@ -136,7 +136,7 @@ Sensor驱动模型主要由以下两部分组成: ### Display框架模型说明 -基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。 +基于OpenHarmony驱动框架的Display驱动模型,对下屏蔽了芯片平台差异,方便操作系统跨平台迁移;向上抽象了外设驱动公共业务逻辑,通过配置或差异化适配接口,实现了一套驱动模型兼容不同的外设器件,使得三方厂商可以高效、便捷的切入OpenHarmony驱动生态。 Display驱动模型主要由以下两部分组成: -- Gitee