diff --git a/zidl/BUILD.gn b/idl/BUILD.gn similarity index 93% rename from zidl/BUILD.gn rename to idl/BUILD.gn index 3ff94170fd..97e1d7bc28 100644 --- a/zidl/BUILD.gn +++ b/idl/BUILD.gn @@ -2,7 +2,7 @@ import("//build/ohos.gni") -config("zidl_config") { +config("idl_config") { include_dirs = [ "./", "//utils/native/base/include/", @@ -63,14 +63,14 @@ common_sources += [ "util/string_pool.cpp", ] -ohos_executable("zidl") { +ohos_executable("idl") { sources = [ "main.cpp" ] sources += common_sources - configs = [ ":zidl_config" ] + configs = [ ":idl_config" ] deps = [ "//utils/native/base:utilsecurec" ] - part_name = "zidl" + part_name = "idl" subsystem_name = "aafwk" } diff --git a/zidl/ast/ast_array_type.cpp b/idl/ast/ast_array_type.cpp similarity index 93% rename from zidl/ast/ast_array_type.cpp rename to idl/ast/ast_array_type.cpp index 01c08bfcbd..438a525b38 100644 --- a/zidl/ast/ast_array_type.cpp +++ b/idl/ast/ast_array_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_array_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTArrayType::GetSignature() { diff --git a/zidl/ast/ast_array_type.h b/idl/ast/ast_array_type.h similarity index 90% rename from zidl/ast/ast_array_type.h rename to idl/ast/ast_array_type.h index 8dc4541a83..3714cdbf87 100644 --- a/zidl/ast/ast_array_type.h +++ b/idl/ast/ast_array_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTARRAYTYPE_H -#define OHOS_ZIDL_ASTARRAYTYPE_H +#ifndef OHOS_IDL_ASTARRAYTYPE_H +#define OHOS_IDL_ASTARRAYTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTArrayType : public ASTType { public: @@ -47,4 +47,4 @@ private: } } -#endif // OHOS_ZIDL_ASTARRAYTYPE_H \ No newline at end of file +#endif // OHOS_IDL_ASTARRAYTYPE_H \ No newline at end of file diff --git a/zidl/ast/ast_boolean_type.cpp b/idl/ast/ast_boolean_type.cpp similarity index 92% rename from zidl/ast/ast_boolean_type.cpp rename to idl/ast/ast_boolean_type.cpp index 011e51dc48..aa78332127 100644 --- a/zidl/ast/ast_boolean_type.cpp +++ b/idl/ast/ast_boolean_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_boolean_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTBooleanType::GetSignature() { diff --git a/zidl/ast/ast_boolean_type.h b/idl/ast/ast_boolean_type.h similarity index 86% rename from zidl/ast/ast_boolean_type.h rename to idl/ast/ast_boolean_type.h index bc41173758..cbeda01e1c 100644 --- a/zidl/ast/ast_boolean_type.h +++ b/idl/ast/ast_boolean_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTBOOLEANTYPE_H -#define OHOS_ZIDL_ASTBOOLEANTYPE_H +#ifndef OHOS_IDL_ASTBOOLEANTYPE_H +#define OHOS_IDL_ASTBOOLEANTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTBooleanType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTBOOLEANTYPE_H +#endif // OHOS_IDL_ASTBOOLEANTYPE_H diff --git a/zidl/ast/ast_byte_type.cpp b/idl/ast/ast_byte_type.cpp similarity index 92% rename from zidl/ast/ast_byte_type.cpp rename to idl/ast/ast_byte_type.cpp index be3e84298b..e3a2c0a9a1 100644 --- a/zidl/ast/ast_byte_type.cpp +++ b/idl/ast/ast_byte_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_byte_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTByteType::GetSignature() { diff --git a/zidl/ast/ast_byte_type.h b/idl/ast/ast_byte_type.h similarity index 87% rename from zidl/ast/ast_byte_type.h rename to idl/ast/ast_byte_type.h index 561fe580f8..1cd5ff65fc 100644 --- a/zidl/ast/ast_byte_type.h +++ b/idl/ast/ast_byte_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTBYTETYPE_H -#define OHOS_ZIDL_ASTBYTETYPE_H +#ifndef OHOS_IDL_ASTBYTETYPE_H +#define OHOS_IDL_ASTBYTETYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTByteType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTBYTETYPE_H +#endif // OHOS_IDL_ASTBYTETYPE_H diff --git a/zidl/ast/ast_char_type.cpp b/idl/ast/ast_char_type.cpp similarity index 92% rename from zidl/ast/ast_char_type.cpp rename to idl/ast/ast_char_type.cpp index 6a8682dc98..6fc1865c76 100644 --- a/zidl/ast/ast_char_type.cpp +++ b/idl/ast/ast_char_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_char_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTCharType::GetSignature() { diff --git a/zidl/ast/ast_char_type.h b/idl/ast/ast_char_type.h similarity index 87% rename from zidl/ast/ast_char_type.h rename to idl/ast/ast_char_type.h index a2d2487a6f..44daf44e8c 100644 --- a/zidl/ast/ast_char_type.h +++ b/idl/ast/ast_char_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTCHARTYPE_H -#define OHOS_ZIDL_ASTCHARTYPE_H +#ifndef OHOS_IDL_ASTCHARTYPE_H +#define OHOS_IDL_ASTCHARTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTCharType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTCHARTYPE_H +#endif // OHOS_IDL_ASTCHARTYPE_H diff --git a/zidl/ast/ast_double_type.cpp b/idl/ast/ast_double_type.cpp similarity index 92% rename from zidl/ast/ast_double_type.cpp rename to idl/ast/ast_double_type.cpp index 7e6b773553..f03548bc7e 100644 --- a/zidl/ast/ast_double_type.cpp +++ b/idl/ast/ast_double_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_double_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTDoubleType::GetSignature() { diff --git a/zidl/ast/ast_double_type.h b/idl/ast/ast_double_type.h similarity index 87% rename from zidl/ast/ast_double_type.h rename to idl/ast/ast_double_type.h index 625111bbf8..67aef9d57e 100644 --- a/zidl/ast/ast_double_type.h +++ b/idl/ast/ast_double_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTDOUBLETYPE_H -#define OHOS_ZIDL_ASTDOUBLETYPE_H +#ifndef OHOS_IDL_ASTDOUBLETYPE_H +#define OHOS_IDL_ASTDOUBLETYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTDoubleType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTDOUBLETYPE_H \ No newline at end of file +#endif // OHOS_IDL_ASTDOUBLETYPE_H \ No newline at end of file diff --git a/zidl/ast/ast_float_type.cpp b/idl/ast/ast_float_type.cpp similarity index 92% rename from zidl/ast/ast_float_type.cpp rename to idl/ast/ast_float_type.cpp index df699bba83..1361476a0f 100644 --- a/zidl/ast/ast_float_type.cpp +++ b/idl/ast/ast_float_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_float_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTFloatType::GetSignature() { diff --git a/zidl/ast/ast_float_type.h b/idl/ast/ast_float_type.h similarity index 87% rename from zidl/ast/ast_float_type.h rename to idl/ast/ast_float_type.h index 44ef0103c5..7b030cd025 100644 --- a/zidl/ast/ast_float_type.h +++ b/idl/ast/ast_float_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTFLOATTYPE_H -#define OHOS_ZIDL_ASTFLOATTYPE_H +#ifndef OHOS_IDL_ASTFLOATTYPE_H +#define OHOS_IDL_ASTFLOATTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTFloatType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTFLOATTYPE_H +#endif // OHOS_IDL_ASTFLOATTYPE_H diff --git a/zidl/ast/ast_integer_type.cpp b/idl/ast/ast_integer_type.cpp similarity index 92% rename from zidl/ast/ast_integer_type.cpp rename to idl/ast/ast_integer_type.cpp index 16918c9a6e..bdcfa80ffa 100644 --- a/zidl/ast/ast_integer_type.cpp +++ b/idl/ast/ast_integer_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_integer_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTIntegerType::GetSignature() { diff --git a/zidl/ast/ast_integer_type.h b/idl/ast/ast_integer_type.h similarity index 86% rename from zidl/ast/ast_integer_type.h rename to idl/ast/ast_integer_type.h index cc30c15b4d..d6e5c3f6c6 100644 --- a/zidl/ast/ast_integer_type.h +++ b/idl/ast/ast_integer_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTINTEGERTYPE_H -#define OHOS_ZIDL_ASTINTEGERTYPE_H +#ifndef OHOS_IDL_ASTINTEGERTYPE_H +#define OHOS_IDL_ASTINTEGERTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTIntegerType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTINTEGERTYPE_H +#endif // OHOS_IDL_ASTINTEGERTYPE_H diff --git a/zidl/ast/ast_interface_type.cpp b/idl/ast/ast_interface_type.cpp similarity index 97% rename from zidl/ast/ast_interface_type.cpp rename to idl/ast/ast_interface_type.cpp index b92003f681..5d814f9b45 100644 --- a/zidl/ast/ast_interface_type.cpp +++ b/idl/ast/ast_interface_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -17,7 +17,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { void ASTInterfaceType::SetNamespace( /* [in] */ ASTNamespace* nspace) diff --git a/zidl/ast/ast_interface_type.h b/idl/ast/ast_interface_type.h similarity index 93% rename from zidl/ast/ast_interface_type.h rename to idl/ast/ast_interface_type.h index ff858591e0..85e4fc123f 100644 --- a/zidl/ast/ast_interface_type.h +++ b/idl/ast/ast_interface_type.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTINTERFACETYPE_H -#define OHOS_ZIDL_ASTINTERFACETYPE_H +#ifndef OHOS_IDL_ASTINTERFACETYPE_H +#define OHOS_IDL_ASTINTERFACETYPE_H #include #include "ast/ast_method.h" @@ -22,7 +22,7 @@ #include "util/autoptr.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTInterfaceType : public ASTType { public: @@ -92,4 +92,4 @@ private: } } -#endif // OHOS_ZIDL_ASTINTERFACETYPE_H +#endif // OHOS_IDL_ASTINTERFACETYPE_H diff --git a/zidl/ast/ast_list_type.cpp b/idl/ast/ast_list_type.cpp similarity index 93% rename from zidl/ast/ast_list_type.cpp rename to idl/ast/ast_list_type.cpp index 5c31c6f4cf..17507cf82f 100644 --- a/zidl/ast/ast_list_type.cpp +++ b/idl/ast/ast_list_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_list_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTListType::GetSignature() { diff --git a/zidl/ast/ast_list_type.h b/idl/ast/ast_list_type.h similarity index 90% rename from zidl/ast/ast_list_type.h rename to idl/ast/ast_list_type.h index d6c80a6833..f26f5681ab 100644 --- a/zidl/ast/ast_list_type.h +++ b/idl/ast/ast_list_type.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTLISTTYPE_H -#define OHOS_ZIDL_ASTLISTTYPE_H +#ifndef OHOS_IDL_ASTLISTTYPE_H +#define OHOS_IDL_ASTLISTTYPE_H #include "ast/ast_type.h" #include "util/autoptr.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTListType : public ASTType { public: @@ -48,4 +48,4 @@ private: } } -#endif // OHOS_ZIDL_ASTLISTTYPE_H +#endif // OHOS_IDL_ASTLISTTYPE_H diff --git a/zidl/ast/ast_long_type.cpp b/idl/ast/ast_long_type.cpp similarity index 92% rename from zidl/ast/ast_long_type.cpp rename to idl/ast/ast_long_type.cpp index 29c7bdd01f..f7bac1352b 100644 --- a/zidl/ast/ast_long_type.cpp +++ b/idl/ast/ast_long_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_long_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTLongType::GetSignature() { diff --git a/zidl/ast/ast_long_type.h b/idl/ast/ast_long_type.h similarity index 87% rename from zidl/ast/ast_long_type.h rename to idl/ast/ast_long_type.h index eec1873fc3..5f37022946 100644 --- a/zidl/ast/ast_long_type.h +++ b/idl/ast/ast_long_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTLONGTYPE_H -#define OHOS_ZIDL_ASTLONGTYPE_H +#ifndef OHOS_IDL_ASTLONGTYPE_H +#define OHOS_IDL_ASTLONGTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTLongType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTLONGTYPE_H +#endif // OHOS_IDL_ASTLONGTYPE_H diff --git a/zidl/ast/ast_map_type.cpp b/idl/ast/ast_map_type.cpp similarity index 93% rename from zidl/ast/ast_map_type.cpp rename to idl/ast/ast_map_type.cpp index 2f41e6b4a2..78181a7b39 100644 --- a/zidl/ast/ast_map_type.cpp +++ b/idl/ast/ast_map_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_map_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTMapType::GetSignature() { diff --git a/zidl/ast/ast_map_type.h b/idl/ast/ast_map_type.h similarity index 92% rename from zidl/ast/ast_map_type.h rename to idl/ast/ast_map_type.h index 3fcddce540..f883ad3ac6 100644 --- a/zidl/ast/ast_map_type.h +++ b/idl/ast/ast_map_type.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTMAPTYPE_H -#define OHOS_ZIDL_ASTMAPTYPE_H +#ifndef OHOS_IDL_ASTMAPTYPE_H +#define OHOS_IDL_ASTMAPTYPE_H #include "ast/ast_type.h" #include "util/autoptr.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTMapType : public ASTType { public: @@ -60,4 +60,4 @@ private: } } -#endif // OHOS_ZIDL_ASTMAPTYPE_H \ No newline at end of file +#endif // OHOS_IDL_ASTMAPTYPE_H \ No newline at end of file diff --git a/zidl/ast/ast_method.cpp b/idl/ast/ast_method.cpp similarity index 96% rename from zidl/ast/ast_method.cpp rename to idl/ast/ast_method.cpp index a9aff6b6d8..8339e80b6b 100644 --- a/zidl/ast/ast_method.cpp +++ b/idl/ast/ast_method.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -17,7 +17,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTMethod::GetSignature() { diff --git a/zidl/ast/ast_method.h b/idl/ast/ast_method.h similarity index 80% rename from zidl/ast/ast_method.h rename to idl/ast/ast_method.h index 638b4a4584..36645ddbbb 100644 --- a/zidl/ast/ast_method.h +++ b/idl/ast/ast_method.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTMETHOD_H -#define OHOS_ZIDL_ASTMETHOD_H +#ifndef OHOS_IDL_ASTMETHOD_H +#define OHOS_IDL_ASTMETHOD_H #include #include "ast/ast_node.h" @@ -23,41 +23,41 @@ #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTMethod : public ASTNode { public: - inline void SetName( + void SetName( /* [in] */ const String& name) { name_ = name; } - inline String GetName() + String GetName() { return name_; } String GetSignature(); - inline void SetOneway( + void SetOneway( /* [in] */ bool oneway) { oneway_ = oneway; } - inline bool IsOneway() + bool IsOneway() { return oneway_; } - inline void SetReturnType( + void SetReturnType( /* [in] */ ASTType* type) { returnType_ = type; } - inline AutoPtr GetReturnType() + AutoPtr GetReturnType() { return returnType_; } @@ -68,7 +68,7 @@ public: AutoPtr GetParameter( /* [in] */ size_t index); - inline size_t GetParameterNumber() + size_t GetParameterNumber() { return parameters_.size(); } @@ -89,4 +89,4 @@ private: } } -#endif // OHOS_ZIDL_ASTMETHOD_H +#endif // OHOS_IDL_ASTMETHOD_H diff --git a/zidl/ast/ast_module.cpp b/idl/ast/ast_module.cpp similarity index 91% rename from zidl/ast/ast_module.cpp rename to idl/ast/ast_module.cpp index 39d949fad6..70491001b7 100644 --- a/zidl/ast/ast_module.cpp +++ b/idl/ast/ast_module.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -17,7 +17,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { ASTModule::ASTModule() { @@ -44,18 +44,18 @@ ASTModule::ASTModule() types_["void"] = voidType_.Get(); } -void ASTModule::SetZidlFile( - /* [in] */ const String& zidlFile) +void ASTModule::SetIdlFile( + /* [in] */ const String& idlFile) { - zidlFilePath_ = zidlFile; + idlFilePath_ = idlFile; #ifdef __MINGW32__ - int index = zidlFilePath_.LastIndexOf('\\'); + int index = idlFilePath_.LastIndexOf('\\'); #else - int index = zidlFilePath_.LastIndexOf('/'); + int index = idlFilePath_.LastIndexOf('/'); #endif - int end = zidlFilePath_.LastIndexOf(".zidl") == -1 ? - zidlFilePath_.LastIndexOf(".idl") : zidlFilePath_.LastIndexOf(".zidl"); - name_ = zidlFilePath_.Substring((index == -1) ? 0 : (index + 1), end); + int end = idlFilePath_.LastIndexOf(".idl") == -1 ? + idlFilePath_.LastIndexOf(".idl") : idlFilePath_.LastIndexOf(".idl"); + name_ = idlFilePath_.Substring((index == -1) ? 0 : (index + 1), end); } AutoPtr ASTModule::ParseNamespace( @@ -230,7 +230,7 @@ String ASTModule::Dump( sb.Append(prefix); sb.Append("Module["); sb.Append("name: ").Append(name_).Append(" "); - sb.Append("file: ").Append(zidlFilePath_); + sb.Append("file: ").Append(idlFilePath_); sb.Append("]\n"); for (auto sequenceable : sequenceables_) { diff --git a/zidl/ast/ast_module.h b/idl/ast/ast_module.h similarity index 94% rename from zidl/ast/ast_module.h rename to idl/ast/ast_module.h index 6256e15b3e..a82078f6e1 100644 --- a/zidl/ast/ast_module.h +++ b/idl/ast/ast_module.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTMODULE_H -#define OHOS_ZIDL_ASTMODULE_H +#ifndef OHOS_IDL_ASTMODULE_H +#define OHOS_IDL_ASTMODULE_H #include #include @@ -35,14 +35,14 @@ #include "util/autoptr.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTModule : public ASTNode { public: ASTModule(); - void SetZidlFile( - /* [in] */ const String& zidlFile); + void SetIdlFile( + /* [in] */ const String& idlFile); inline String GetName() { @@ -150,10 +150,10 @@ private: AutoPtr stringType_; AutoPtr voidType_; - String zidlFilePath_; + String idlFilePath_; }; } } -#endif // OHOS_ZIDL_ASTMODULE_H +#endif // OHOS_IDL_ASTMODULE_H diff --git a/zidl/ast/ast_namespace.cpp b/idl/ast/ast_namespace.cpp similarity index 97% rename from zidl/ast/ast_namespace.cpp rename to idl/ast/ast_namespace.cpp index 66b502a41f..68258aedca 100644 --- a/zidl/ast/ast_namespace.cpp +++ b/idl/ast/ast_namespace.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -18,7 +18,7 @@ #include "ast/ast_sequenceable_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { ASTNamespace:: ASTNamespace( /* [in] */ const String& nspaceStr) diff --git a/zidl/ast/ast_namespace.h b/idl/ast/ast_namespace.h similarity index 94% rename from zidl/ast/ast_namespace.h rename to idl/ast/ast_namespace.h index d78d171de1..8f612beb3c 100644 --- a/zidl/ast/ast_namespace.h +++ b/idl/ast/ast_namespace.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTNAMESPACE_H -#define OHOS_ZIDL_ASTNAMESPACE_H +#ifndef OHOS_IDL_ASTNAMESPACE_H +#define OHOS_IDL_ASTNAMESPACE_H #include #include "ast/ast_node.h" #include "util/autoptr.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTInterfaceType; class ASTSequenceableType; @@ -90,4 +90,4 @@ private: } } -#endif // OHOS_ZIDL_ASTNAMESPACE_H +#endif // OHOS_IDL_ASTNAMESPACE_H diff --git a/zidl/ast/ast_node.cpp b/idl/ast/ast_node.cpp similarity index 92% rename from zidl/ast/ast_node.cpp rename to idl/ast/ast_node.cpp index f16e2d6ef0..3b852b59fd 100644 --- a/zidl/ast/ast_node.cpp +++ b/idl/ast/ast_node.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_node.h" namespace OHOS { -namespace Zidl { +namespace Idl { ASTNode::~ASTNode() {} diff --git a/zidl/ast/ast_node.h b/idl/ast/ast_node.h similarity index 89% rename from zidl/ast/ast_node.h rename to idl/ast/ast_node.h index abe435e652..366706cfc2 100644 --- a/zidl/ast/ast_node.h +++ b/idl/ast/ast_node.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTNODE_H -#define OHOS_ZIDL_ASTNODE_H +#ifndef OHOS_IDL_ASTNODE_H +#define OHOS_IDL_ASTNODE_H #include "util/light_refcount_base.h" #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTNode : public LightRefCountBase { public: @@ -35,4 +35,4 @@ public: } } -#endif // OHOS_ZIDL_ASTNODE_H +#endif // OHOS_IDL_ASTNODE_H diff --git a/zidl/ast/ast_parameter.cpp b/idl/ast/ast_parameter.cpp similarity index 94% rename from zidl/ast/ast_parameter.cpp rename to idl/ast/ast_parameter.cpp index c62da3aeee..d119cf476e 100644 --- a/zidl/ast/ast_parameter.cpp +++ b/idl/ast/ast_parameter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -17,7 +17,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTParameter::Dump( /* [in] */ const String& prefix) diff --git a/zidl/ast/ast_parameter.h b/idl/ast/ast_parameter.h similarity index 93% rename from zidl/ast/ast_parameter.h rename to idl/ast/ast_parameter.h index 84418edd8c..06e6a9ed6c 100644 --- a/zidl/ast/ast_parameter.h +++ b/idl/ast/ast_parameter.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTPARAMETER_H -#define OHOS_ZIDL_ASTPARAMETER_H +#ifndef OHOS_IDL_ASTPARAMETER_H +#define OHOS_IDL_ASTPARAMETER_H #include "ast/ast_node.h" #include "ast/ast_type.h" @@ -22,7 +22,7 @@ #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTParameter : public ASTNode { public: @@ -83,4 +83,4 @@ private: } } -#endif // OHOS_ZIDL_ASTPARAMETER_H +#endif // OHOS_IDL_ASTPARAMETER_H diff --git a/zidl/ast/ast_sequenceable_type.cpp b/idl/ast/ast_sequenceable_type.cpp similarity index 95% rename from zidl/ast/ast_sequenceable_type.cpp rename to idl/ast/ast_sequenceable_type.cpp index 680606733e..6c7e50aebe 100644 --- a/zidl/ast/ast_sequenceable_type.cpp +++ b/idl/ast/ast_sequenceable_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -17,7 +17,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { void ASTSequenceableType::SetNamespace( /* [in] */ ASTNamespace* nspace) diff --git a/zidl/ast/ast_sequenceable_type.h b/idl/ast/ast_sequenceable_type.h similarity index 87% rename from zidl/ast/ast_sequenceable_type.h rename to idl/ast/ast_sequenceable_type.h index d22b50d625..99462ae663 100644 --- a/zidl/ast/ast_sequenceable_type.h +++ b/idl/ast/ast_sequenceable_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTSEQUENCEABLETYPE_H -#define OHOS_ZIDL_ASTSEQUENCEABLETYPE_H +#ifndef OHOS_IDL_ASTSEQUENCEABLETYPE_H +#define OHOS_IDL_ASTSEQUENCEABLETYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTSequenceableType : public ASTType { public: @@ -39,4 +39,4 @@ public: } } -#endif // OHOS_ZIDL_ASTSEQUENCEABLETYPE_H +#endif // OHOS_IDL_ASTSEQUENCEABLETYPE_H diff --git a/zidl/ast/ast_short_type.cpp b/idl/ast/ast_short_type.cpp similarity index 92% rename from zidl/ast/ast_short_type.cpp rename to idl/ast/ast_short_type.cpp index 2891aed192..d02f6946c5 100644 --- a/zidl/ast/ast_short_type.cpp +++ b/idl/ast/ast_short_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_short_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTShortType::GetSignature() { diff --git a/zidl/ast/ast_short_type.h b/idl/ast/ast_short_type.h similarity index 87% rename from zidl/ast/ast_short_type.h rename to idl/ast/ast_short_type.h index da8766f207..4917825768 100644 --- a/zidl/ast/ast_short_type.h +++ b/idl/ast/ast_short_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTSHORTTYPE_H -#define OHOS_ZIDL_ASTSHORTTYPE_H +#ifndef OHOS_IDL_ASTSHORTTYPE_H +#define OHOS_IDL_ASTSHORTTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTShortType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTSHORTTYPE_H +#endif // OHOS_IDL_ASTSHORTTYPE_H diff --git a/zidl/ast/ast_string_type.cpp b/idl/ast/ast_string_type.cpp similarity index 92% rename from zidl/ast/ast_string_type.cpp rename to idl/ast/ast_string_type.cpp index 3144aee55e..ad33f40491 100644 --- a/zidl/ast/ast_string_type.cpp +++ b/idl/ast/ast_string_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_string_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTStringType::GetSignature() { diff --git a/zidl/ast/ast_string_type.h b/idl/ast/ast_string_type.h similarity index 87% rename from zidl/ast/ast_string_type.h rename to idl/ast/ast_string_type.h index e7eab0a443..f7499b5974 100644 --- a/zidl/ast/ast_string_type.h +++ b/idl/ast/ast_string_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTSTRINGTYPE_H -#define OHOS_ZIDL_ASTSTRINGTYPE_H +#ifndef OHOS_IDL_ASTSTRINGTYPE_H +#define OHOS_IDL_ASTSTRINGTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTStringType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTSTRINGTYPE_H +#endif // OHOS_IDL_ASTSTRINGTYPE_H diff --git a/zidl/ast/ast_type.cpp b/idl/ast/ast_type.cpp similarity index 96% rename from zidl/ast/ast_type.cpp rename to idl/ast/ast_type.cpp index 1c31469907..b47d015af0 100644 --- a/zidl/ast/ast_type.cpp +++ b/idl/ast/ast_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { void ASTType::SetName( /* [in] */ const String& name) diff --git a/zidl/ast/ast_type.h b/idl/ast/ast_type.h similarity index 94% rename from zidl/ast/ast_type.h rename to idl/ast/ast_type.h index 1ecacde4d7..83cfb27244 100644 --- a/zidl/ast/ast_type.h +++ b/idl/ast/ast_type.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTTYPE_H -#define OHOS_ZIDL_ASTTYPE_H +#ifndef OHOS_IDL_ASTTYPE_H +#define OHOS_IDL_ASTTYPE_H #include "ast/ast_namespace.h" #include "ast/ast_node.h" @@ -22,7 +22,7 @@ #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTType : public ASTNode { public: @@ -80,4 +80,4 @@ protected: } } -#endif // OHOS_ZIDL_ASTTYPE_H +#endif // OHOS_IDL_ASTTYPE_H diff --git a/zidl/ast/ast_void_type.cpp b/idl/ast/ast_void_type.cpp similarity index 92% rename from zidl/ast/ast_void_type.cpp rename to idl/ast/ast_void_type.cpp index 2cce08c685..09ce72cef3 100644 --- a/zidl/ast/ast_void_type.cpp +++ b/idl/ast/ast_void_type.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "ast/ast_void_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { String ASTVoidType::GetSignature() { diff --git a/zidl/ast/ast_void_type.h b/idl/ast/ast_void_type.h similarity index 87% rename from zidl/ast/ast_void_type.h rename to idl/ast/ast_void_type.h index 9a66b6f840..d103330ea7 100644 --- a/zidl/ast/ast_void_type.h +++ b/idl/ast/ast_void_type.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_ASTVOIDTYPE_H -#define OHOS_ZIDL_ASTVOIDTYPE_H +#ifndef OHOS_IDL_ASTVOIDTYPE_H +#define OHOS_IDL_ASTVOIDTYPE_H #include "ast/ast_type.h" namespace OHOS { -namespace Zidl { +namespace Idl { class ASTVoidType : public ASTType { public: @@ -33,4 +33,4 @@ public: } } -#endif // OHOS_ZIDL_ASTBOOLEANTYPE_H \ No newline at end of file +#endif // OHOS_IDL_ASTBOOLEANTYPE_H \ No newline at end of file diff --git a/zidl/bundle.json b/idl/bundle.json similarity index 77% rename from zidl/bundle.json rename to idl/bundle.json index a0281732a2..3559d73e7f 100644 --- a/zidl/bundle.json +++ b/idl/bundle.json @@ -1,16 +1,16 @@ { - "name": "@ohos/zidl", + "name": "@ohos/idl", "description": "提供自动生成Extension 服务端及客户端接口文件的能力", "version": "3.1", "license": "Apache License 2.0", "publishAs": "code-segment", "segment": { - "destPath": "foundation/aafwk/standard/zidl" + "destPath": "foundation/aafwk/standard/idl" }, "dirs": {}, "scripts": {}, "component": { - "name": "zidl", + "name": "idl", "subsystem": "aafwk", "syscap": [], "features": [], @@ -31,9 +31,7 @@ "build": { "sub_component": [], "inner_kits": [], - "test": [ - "//foundation/aafwk/standard/zidl/test/ts/moduletest:moduletest" - ] + "test": [] } } } \ No newline at end of file diff --git a/zidl/codegen/code_emitter.cpp b/idl/codegen/code_emitter.cpp similarity index 96% rename from zidl/codegen/code_emitter.cpp rename to idl/codegen/code_emitter.cpp index 5dfda23272..adeed14736 100644 --- a/zidl/codegen/code_emitter.cpp +++ b/idl/codegen/code_emitter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "codegen/code_emitter.h" namespace OHOS { -namespace Zidl { +namespace Idl { const char* CodeEmitter::TAB = " "; diff --git a/zidl/codegen/code_emitter.h b/idl/codegen/code_emitter.h similarity index 92% rename from zidl/codegen/code_emitter.h rename to idl/codegen/code_emitter.h index 4fd84ffd8b..4d0e4f5caf 100644 --- a/zidl/codegen/code_emitter.h +++ b/idl/codegen/code_emitter.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_CODEEMITTER_H -#define OHOS_ZIDL_CODEEMITTER_H +#ifndef OHOS_IDL_CODEEMITTER_H +#define OHOS_IDL_CODEEMITTER_H #include "metadata/metadata.h" #include "util/light_refcount_base.h" #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class CodeEmitter : public LightRefCountBase { public: @@ -57,4 +57,4 @@ protected: } } -#endif // OHOS_ZIDL_CODEEMITTER_H +#endif // OHOS_IDL_CODEEMITTER_H diff --git a/zidl/codegen/code_generator.cpp b/idl/codegen/code_generator.cpp similarity index 97% rename from zidl/codegen/code_generator.cpp rename to idl/codegen/code_generator.cpp index 3cbdba45fc..d822bdd79d 100644 --- a/zidl/codegen/code_generator.cpp +++ b/idl/codegen/code_generator.cpp @@ -23,7 +23,7 @@ #include "util/logger.h" namespace OHOS { -namespace Zidl { +namespace Idl { const char* CodeGenerator::TAG = "CodeGenerator"; @@ -39,7 +39,7 @@ CodeGenerator::CodeGenerator( emitter_ = new CppCodeEmitter(metaComponent_); } else if (language.Equals("java")) { emitter_ = new JavaCodeEmitter(metaComponent_); - } else if (language.Equals("js")) { + } else if (language.Equals("ts")) { emitter_ = new JsCodeEmitter(metaComponent_); } } diff --git a/zidl/codegen/code_generator.h b/idl/codegen/code_generator.h similarity index 90% rename from zidl/codegen/code_generator.h rename to idl/codegen/code_generator.h index 43eca9157f..c8e96d7031 100644 --- a/zidl/codegen/code_generator.h +++ b/idl/codegen/code_generator.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_CODEGENERATOR_H -#define OHOS_ZIDL_CODEGENERATOR_H +#ifndef OHOS_IDL_CODEGENERATOR_H +#define OHOS_IDL_CODEGENERATOR_H #include "codegen/code_emitter.h" #include "metadata/metadata.h" @@ -22,7 +22,7 @@ #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class CodeGenerator { public: @@ -49,4 +49,4 @@ private: } } -#endif // OHOS_ZIDL_CODEGENERATOR_H +#endif // OHOS_IDL_CODEGENERATOR_H diff --git a/zidl/codegen/cpp_code_emitter.cpp b/idl/codegen/cpp_code_emitter.cpp similarity index 99% rename from zidl/codegen/cpp_code_emitter.cpp rename to idl/codegen/cpp_code_emitter.cpp index 8e23b8989c..6beca4b1d4 100644 --- a/zidl/codegen/cpp_code_emitter.cpp +++ b/idl/codegen/cpp_code_emitter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -22,7 +22,7 @@ #include "util/file.h" namespace OHOS { -namespace Zidl { +namespace Idl { void CppCodeEmitter::EmitInterface() { diff --git a/zidl/codegen/cpp_code_emitter.h b/idl/codegen/cpp_code_emitter.h similarity index 98% rename from zidl/codegen/cpp_code_emitter.h rename to idl/codegen/cpp_code_emitter.h index f130be83af..dc183a3989 100644 --- a/zidl/codegen/cpp_code_emitter.h +++ b/idl/codegen/cpp_code_emitter.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_CPPCODEEMITTER_H -#define OHOS_ZIDL_CPPCODEEMITTER_H +#ifndef OHOS_IDL_CPPCODEEMITTER_H +#define OHOS_IDL_CPPCODEEMITTER_H #include @@ -22,7 +22,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { class CppCodeEmitter : public CodeEmitter { public: @@ -234,4 +234,4 @@ private: } } -#endif // OHOS_ZIDL_CPPCODEEMITTER_H +#endif // OHOS_IDL_CPPCODEEMITTER_H diff --git a/zidl/codegen/java_code_emitter.cpp b/idl/codegen/java_code_emitter.cpp similarity index 99% rename from zidl/codegen/java_code_emitter.cpp rename to idl/codegen/java_code_emitter.cpp index e12fa8b2bd..594f6662da 100644 --- a/zidl/codegen/java_code_emitter.cpp +++ b/idl/codegen/java_code_emitter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -21,7 +21,7 @@ #include "util/file.h" namespace OHOS { -namespace Zidl { +namespace Idl { void JavaCodeEmitter::EmitInterface() { diff --git a/zidl/codegen/java_code_emitter.h b/idl/codegen/java_code_emitter.h similarity index 98% rename from zidl/codegen/java_code_emitter.h rename to idl/codegen/java_code_emitter.h index 777f74c310..9db7a80dbc 100644 --- a/zidl/codegen/java_code_emitter.h +++ b/idl/codegen/java_code_emitter.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_JAVACODEEMITTER_H -#define OHOS_ZIDL_JAVACODEEMITTER_H +#ifndef OHOS_IDL_JAVACODEEMITTER_H +#define OHOS_IDL_JAVACODEEMITTER_H #include @@ -22,7 +22,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { class JavaCodeEmitter : public CodeEmitter { public: @@ -238,4 +238,4 @@ private: } } -#endif // OHOS_ZIDL_JAVACODEEMITTER_H +#endif // OHOS_IDL_JAVACODEEMITTER_H diff --git a/zidl/codegen/js_code_emitter.cpp b/idl/codegen/js_code_emitter.cpp similarity index 88% rename from zidl/codegen/js_code_emitter.cpp rename to idl/codegen/js_code_emitter.cpp index 617e978722..ee2efe9387 100644 --- a/zidl/codegen/js_code_emitter.cpp +++ b/idl/codegen/js_code_emitter.cpp @@ -24,7 +24,7 @@ #include "util/logger.h" namespace OHOS { -namespace Zidl { +namespace Idl { namespace { const std::string PROXY = "proxy"; const std::string THIS_PROXY = "this.proxy"; @@ -32,6 +32,8 @@ static const char* TAG = "JsCodeEmitter"; const std::string UNKNOWN_TYPE = "unknown type"; const String NEWLINE = "\n"; const String RETURN_VALUE = "returnValue"; +const std::string ERR_CODE_TYPE = "errCode: number"; +const String ERR_CODE = "errCode"; } void JsCodeEmitter::EmitInterface() @@ -62,7 +64,7 @@ void JsCodeEmitter::EmitInterfaceImports( { for (const auto &item : methods_) { if (item.callbackName_.size() > 0) { - stringBuilder.AppendFormat("import {%s} from \"./%s\"\n", + stringBuilder.AppendFormat("import {%s} from \"./%s\";\n", item.callbackName_.c_str(), FileName(interfaceName_).string()); } } @@ -123,21 +125,18 @@ void JsCodeEmitter::EmitInterfaceMethods(StringBuilder& stringBuilder, const Str void JsCodeEmitter::EmitInterfaceMethod(MetaMethod* metaMethod, StringBuilder& stringBuilder, const String& prefix) { MetaType* returnType = metaComponent_->types_[metaMethod->returnTypeIndex_]; - Method method; method.properties_ = metaMethod->properties_; - bool haveCallback = false; + StringBuilder callbackName; + callbackName.AppendFormat("%sCallback", MethodName(metaMethod->name_).string()); + method.callbackName_ = callbackName.ToString(); + method.exportFunction_ = "export type " + callbackName.ToString() + " = (" + ERR_CODE_TYPE.c_str(); + bool haveOutPara = false; StringBuilder methodStr; if (returnType->kind_ != TypeKind::Void) { - haveCallback = true; - StringBuilder callbackName; - callbackName.AppendFormat("%sCallback", MethodName(metaMethod->name_).string()); method.retParameter_.name_ = RETURN_VALUE.string(); method.retParameter_.type_ = EmitType(returnType).string(); - method.callbackName_ = callbackName.ToString(); - method.exportFunction_ = "export type " + callbackName.ToString() + " = ("; - } methodStr.Append(prefix).AppendFormat("%s(", MethodName(metaMethod->name_).string()); method.name_ = MethodName(metaMethod->name_).string(); @@ -151,14 +150,6 @@ void JsCodeEmitter::EmitInterfaceMethod(MetaMethod* metaMethod, StringBuilder& s para.type_ = EmitType(paraType).string(); if ((mp->attributes_ & ATTR_OUT) != 0) { haveOutPara = true; - if (!haveCallback) { - haveCallback = true; - StringBuilder callbackName; - callbackName.AppendFormat("%sCallback", MethodName(metaMethod->name_).string()); - method.callbackName_ = callbackName.ToString(); - method.exportFunction_ = "export type " + callbackName.ToString() + " = ("; - } - } method.parameters_.emplace_back(para); } @@ -185,9 +176,16 @@ void JsCodeEmitter::EmitInterfaceMethod(MetaMethod* metaMethod, StringBuilder& s if (method.retParameter_.name_.size() > 0) { if (!haveOutPara) { method.exportFunction_ += - (method.retParameter_.name_ + ": " + method.retParameter_.type_ + ") => void;"); + (", " + method.retParameter_.name_ + ": " + method.retParameter_.type_ + ") => void;"); } else { - method.exportFunction_ += (method.retParameter_.name_ + ": " + method.retParameter_.type_ + ", "); + method.exportFunction_ += + (", " + method.retParameter_.name_ + ": " + method.retParameter_.type_ + ", "); + } + } else { + if (!haveOutPara) { + method.exportFunction_ += ") => void;"; + } else { + method.exportFunction_ += ", "; } } for (size_t index = 0; index < method.parameters_.size(); index++) { @@ -311,7 +309,6 @@ void JsCodeEmitter::EmitInterfaceProxyMethodImpl(MetaMethod* metaMethod, int met void JsCodeEmitter::EmitInterfaceProxyMethodBody(MetaMethod* metaMethod, int methodIndex, StringBuilder& stringBuilder, const String& prefix) { - bool haveCallback = (methods_[methodIndex].callbackName_.size() > 0) ? true : false; bool haveOutPara = false; stringBuilder.Append(prefix).Append("{\n"); stringBuilder.Append(prefix).Append(TAB).AppendFormat("let _option = new rpc.MessageOption(%s);\n", @@ -329,35 +326,43 @@ void JsCodeEmitter::EmitInterfaceProxyMethodBody(MetaMethod* metaMethod, int met haveOutPara = true; } } + stringBuilder.Append(prefix).Append(TAB).AppendFormat( + "%s.sendRequest(%s.COMMAND_%s, _data, _reply, _option).then(function(result) {\n", THIS_PROXY.c_str(), + proxyName_.string(), ConstantName(metaMethod->name_).string()); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).AppendFormat("if (result.errCode === 0) {\n"); + MetaType* returnType = metaComponent_->types_[metaMethod->returnTypeIndex_]; + // emit errCode + MetaType errCode; + errCode.kind_ = TypeKind::Integer; + EmitReadOutVariable("result.reply", UnderlineAdded(ERR_CODE).c_str(), &errCode, stringBuilder, + prefix + TAB + TAB + TAB); + + if (returnType->kind_ != TypeKind::Void || haveOutPara) { + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).AppendFormat( + "if (%s != 0) {\n", UnderlineAdded(ERR_CODE).c_str()); - if (!haveCallback) { - stringBuilder.Append(prefix).Append(TAB).AppendFormat( - "%s.sendRequest(%s.COMMAND_%s, _data, _reply, _option);\n", THIS_PROXY.c_str(), proxyName_.string(), - ConstantName(metaMethod->name_).string()); - } else { - stringBuilder.Append(prefix).Append(TAB).AppendFormat( - "%s.sendRequest(%s.COMMAND_%s, _data, _reply, _option).then(function(result) {\n", THIS_PROXY.c_str(), - proxyName_.string(), ConstantName(metaMethod->name_).string()); - stringBuilder.Append(prefix).Append(TAB).Append(TAB).AppendFormat("if (result.errCode === 0) {\n"); - MetaType* returnType = metaComponent_->types_[metaMethod->returnTypeIndex_]; - // emit return if (returnType->kind_ != TypeKind::Void) { - String parcelName = "result.reply"; - EmitReadOutVariable(parcelName, UnderlineAdded(RETURN_VALUE), returnType, stringBuilder, - prefix + TAB + TAB + TAB); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).Append(TAB).AppendFormat( + "let %s = undefined;\n", UnderlineAdded(RETURN_VALUE).c_str()); } - for (int index = 0; index < metaMethod->parameterNumber_; index++) { - MetaParameter* mp = metaMethod->parameters_[index]; - if ((mp->attributes_ & ATTR_OUT) != 0) { - EmitReadMethodParameter(mp, "result.reply", stringBuilder, prefix + TAB + TAB + TAB); + for (size_t index = 0; index < methods_[methodIndex].parameters_.size(); index++) { + if ((methods_[methodIndex].parameters_[index].attr_ & ATTR_OUT) != 0) { + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).Append(TAB).AppendFormat( + "let %s = undefined;\n", UnderlineAdded( + methods_[methodIndex].parameters_[index].name_.c_str()).c_str()); } } - stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).AppendFormat("callback("); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).Append(TAB).AppendFormat("callback("); + stringBuilder.AppendFormat("%s", UnderlineAdded(ERR_CODE).c_str()); if (methods_[methodIndex].retParameter_.name_.size() > 0) { if (haveOutPara) { - stringBuilder.AppendFormat("%s, ", UnderlineAdded(RETURN_VALUE).c_str()); + stringBuilder.AppendFormat(", %s, ", UnderlineAdded(RETURN_VALUE).c_str()); } else { - stringBuilder.AppendFormat("%s", UnderlineAdded(RETURN_VALUE).c_str()); + stringBuilder.AppendFormat(", %s", UnderlineAdded(RETURN_VALUE).c_str()); + } + } else { + if (haveOutPara) { + stringBuilder.Append(","); } } for (size_t index = 0; index < methods_[methodIndex].parameters_.size(); index++) { @@ -370,12 +375,49 @@ void JsCodeEmitter::EmitInterfaceProxyMethodBody(MetaMethod* metaMethod, int met } } stringBuilder.Append(");\n"); - stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append("} else {\n"); - stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).Append( - "console.log(\"sendRequest failed, errCode: \" + result.errCode);\n"); - stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append("}\n"); - stringBuilder.Append(prefix).Append(TAB).Append("})\n"); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).Append(TAB).Append("return;\n"); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).Append("}\n"); } + // emit return + if (returnType->kind_ != TypeKind::Void) { + String parcelName = "result.reply"; + EmitReadOutVariable(parcelName, UnderlineAdded(RETURN_VALUE), returnType, stringBuilder, + prefix + TAB + TAB + TAB); + } + for (int index = 0; index < metaMethod->parameterNumber_; index++) { + MetaParameter* mp = metaMethod->parameters_[index]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + EmitReadMethodParameter(mp, "result.reply", stringBuilder, prefix + TAB + TAB + TAB); + } + } + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).AppendFormat("callback("); + stringBuilder.AppendFormat("%s", UnderlineAdded(ERR_CODE).c_str()); + if (methods_[methodIndex].retParameter_.name_.size() > 0) { + if (haveOutPara) { + stringBuilder.AppendFormat(", %s, ", UnderlineAdded(RETURN_VALUE).c_str()); + } else { + stringBuilder.AppendFormat(", %s", UnderlineAdded(RETURN_VALUE).c_str()); + } + } else { + if (haveOutPara) { + stringBuilder.Append(","); + } + } + for (size_t index = 0; index < methods_[methodIndex].parameters_.size(); index++) { + if ((methods_[methodIndex].parameters_[index].attr_ & ATTR_OUT) != 0) { + stringBuilder.AppendFormat("%s", + UnderlineAdded(methods_[methodIndex].parameters_[index].name_.c_str()).c_str()); + if (index != methods_[methodIndex].parameters_.size() - 1) { + stringBuilder.Append(", "); + } + } + } + stringBuilder.Append(");\n"); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append("} else {\n"); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append(TAB).Append( + "console.log(\"sendRequest failed, errCode: \" + result.errCode);\n"); + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append("}\n"); + stringBuilder.Append(prefix).Append(TAB).Append("})\n"); stringBuilder.Append(prefix).Append("}\n"); } @@ -475,12 +517,10 @@ void JsCodeEmitter::EmitInterfaceStubMethodImpls( } } } - if (methods_[index].callbackName_.size() > 0) { - if (!isLastParaTypeIn) { - stringBuilder.AppendFormat("callback: %s", methods_[index].callbackName_.c_str()); - } else { - stringBuilder.AppendFormat(", callback: %s", methods_[index].callbackName_.c_str()); - } + if (!isLastParaTypeIn) { + stringBuilder.AppendFormat("callback: %s", methods_[index].callbackName_.c_str()); + } else { + stringBuilder.AppendFormat(", callback: %s", methods_[index].callbackName_.c_str()); } stringBuilder.Append("): void{}\n"); } @@ -490,7 +530,8 @@ void JsCodeEmitter::EmitInterfaceStubMethodImpl(MetaMethod* metaMethod, int meth const String& prefix) { bool haveOutPara = false; - stringBuilder.Append(prefix).AppendFormat("case %s.COMMAND_%s: {\n", stubName_.string(), ConstantName(metaMethod->name_).string()); + stringBuilder.Append(prefix).AppendFormat("case %s.COMMAND_%s: {\n", stubName_.string(), + ConstantName(metaMethod->name_).string()); for (int index = 0; index < metaMethod->parameterNumber_; index++) { MetaParameter* mp = metaMethod->parameters_[index]; if ((mp->attributes_ & ATTR_IN) != 0) { @@ -514,18 +555,21 @@ void JsCodeEmitter::EmitInterfaceStubMethodImpl(MetaMethod* metaMethod, int meth } } } - if (methods_[methodIndex].callbackName_.size() > 0) { - if (!isLastParaTypeIn) { - stringBuilder.Append("("); - } else { - stringBuilder.Append(", ("); - } + if (!isLastParaTypeIn) { + stringBuilder.Append("("); + } else { + stringBuilder.Append(", ("); } + stringBuilder.Append(ERR_CODE); if (methods_[methodIndex].retParameter_.name_.size() > 0) { if (!haveOutPara) { - stringBuilder.Append(RETURN_VALUE.string()); + stringBuilder.AppendFormat(", %s", RETURN_VALUE.string()); } else { - stringBuilder.Append(RETURN_VALUE.string()).Append(", "); + stringBuilder.AppendFormat(", %s", RETURN_VALUE.string()).Append(", "); + } + } else { + if (haveOutPara) { + stringBuilder.Append(", "); } } for (size_t index = 0; index < methods_[methodIndex].parameters_.size(); index++) { @@ -536,22 +580,27 @@ void JsCodeEmitter::EmitInterfaceStubMethodImpl(MetaMethod* metaMethod, int meth } } } - if (methods_[methodIndex].callbackName_.size() > 0) { - stringBuilder.Append(") => {\n"); - MetaType* returnType = metaComponent_->types_[metaMethod->returnTypeIndex_]; + + stringBuilder.Append(") => {\n"); + MetaType errCode; + errCode.kind_ = TypeKind::Integer; + EmitWriteVariable("reply", ERR_CODE.string(), &errCode, stringBuilder, prefix + TAB + TAB); + MetaType* returnType = metaComponent_->types_[metaMethod->returnTypeIndex_]; + + if (returnType->kind_ != TypeKind::Void || haveOutPara) { + stringBuilder.Append(prefix).Append(TAB).Append(TAB).AppendFormat("if (%s == 0) {\n", ERR_CODE.string()); if (returnType->kind_ != TypeKind::Void) { - EmitWriteVariable("reply", RETURN_VALUE.string(), returnType, stringBuilder, prefix + TAB + TAB); + EmitWriteVariable("reply", RETURN_VALUE.string(), returnType, stringBuilder, prefix + TAB + TAB + TAB); } - } - for (int index = 0; index < metaMethod->parameterNumber_; index++) { - MetaParameter* mp = metaMethod->parameters_[index]; - if ((mp->attributes_ & ATTR_OUT) != 0) { - EmitWriteMethodParameter(mp, "reply", stringBuilder, prefix + TAB + TAB); + for (int index = 0; index < metaMethod->parameterNumber_; index++) { + MetaParameter* mp = metaMethod->parameters_[index]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + EmitWriteMethodParameter(mp, "reply", stringBuilder, prefix + TAB + TAB + TAB); + } } + stringBuilder.Append(prefix).Append(TAB).Append(TAB).Append("}\n"); } - if (methods_[methodIndex].callbackName_.size() > 0) { - stringBuilder.Append(prefix).Append(TAB).Append("}"); - } + stringBuilder.Append(prefix).Append(TAB).Append("}"); stringBuilder.Append(");\n"); stringBuilder.Append(prefix).Append(TAB).Append("return true;\n"); stringBuilder.Append(prefix).Append("}\n"); @@ -603,7 +652,8 @@ void JsCodeEmitter::EmitWriteVariable(const String& parcelName, const std::strin name.c_str()); break; } - stringBuilder.Append(prefix).AppendFormat("%s.writeSequenceable(%s);\n", parcelName.string(), name.c_str()); + stringBuilder.Append(prefix).AppendFormat("%s.writeSequenceable(%s);\n", parcelName.string(), + name.c_str()); break; case TypeKind::Interface: stringBuilder.Append(prefix).AppendFormat("%s.writeRemoteObject(%s as %s);\n", parcelName.string(), @@ -644,13 +694,15 @@ void JsCodeEmitter::EmitWriteArrayVariable(const String& parcelName, const std:: { switch (mt->kind_) { case TypeKind::Boolean: - stringBuilder.Append(prefix).AppendFormat("%s.writeBooleanArray(%s);\n", parcelName.string(), name.c_str()); + stringBuilder.Append(prefix).AppendFormat("%s.writeBooleanArray(%s);\n", parcelName.string(), + name.c_str()); break; case TypeKind::Char: stringBuilder.Append(prefix).AppendFormat("%s.writeCharArray(%s);\n", parcelName.string(), name.c_str()); break; case TypeKind::Byte: - stringBuilder.Append(prefix).AppendFormat("let %sArray = new Int8Array(%s);\n", name.c_str(), name.c_str()); + stringBuilder.Append(prefix).AppendFormat("let %sArray = new Int8Array(%s);\n", name.c_str(), + name.c_str()); stringBuilder.Append(prefix).AppendFormat("%s.writeByteArray(%sArray);\n", parcelName.string(), name.c_str()); break; @@ -1078,7 +1130,7 @@ bool JsCodeEmitter::CheckInterfaceType() MetaType* returnType = metaComponent_->types_[metaMethod->returnTypeIndex_]; std::string returnTypeStr = EmitType(returnType).string(); if (returnTypeStr == UNKNOWN_TYPE) { - Logger::E(TAG, "unsupported type in .zidl file"); + Logger::E(TAG, "unsupported type in .idl file"); return false; } for (int index = 0; index < metaMethod->parameterNumber_; index++) { @@ -1086,7 +1138,7 @@ bool JsCodeEmitter::CheckInterfaceType() MetaType* paraType = metaComponent_->types_[mp->typeIndex_]; std::string paraTypeStr = EmitType(paraType).string(); if (paraTypeStr == UNKNOWN_TYPE) { - Logger::E(TAG, "unsupported type in .zidl file"); + Logger::E(TAG, "unsupported type in .idl file"); return false; } } diff --git a/zidl/codegen/js_code_emitter.h b/idl/codegen/js_code_emitter.h similarity index 97% rename from zidl/codegen/js_code_emitter.h rename to idl/codegen/js_code_emitter.h index e8a630c563..a72268ffb7 100644 --- a/zidl/codegen/js_code_emitter.h +++ b/idl/codegen/js_code_emitter.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_JSCODEEMITTER_H -#define OHOS_ZIDL_JSCODEEMITTER_H +#ifndef OHOS_IDL_JSCODEEMITTER_H +#define OHOS_IDL_JSCODEEMITTER_H #include #include @@ -23,7 +23,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { class JsCodeEmitter : public CodeEmitter { public: JsCodeEmitter(MetaComponent* mc) @@ -150,4 +150,4 @@ private: } } -#endif // OHOS_ZIDL_JSCODEEMITTER_H +#endif // OHOS_IDL_JSCODEEMITTER_H diff --git a/zidl/main.cpp b/idl/main.cpp similarity index 94% rename from zidl/main.cpp rename to idl/main.cpp index c0e314a6ce..ab8ac6b4dd 100644 --- a/zidl/main.cpp +++ b/idl/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -22,9 +22,9 @@ #include "util/logger.h" #include "util/options.h" -using namespace OHOS::Zidl; +using namespace OHOS::Idl; -static const char* TAG = "zidl"; +static const char* TAG = "idl"; int main(int argc, char** argv) { @@ -50,7 +50,7 @@ int main(int argc, char** argv) if (options.DoCompile()) { Parser parser(options); if (!parser.Parse(options.GetSourceFile())) { - Logger::E(TAG, "Parsing .zidl failed."); + Logger::E(TAG, "Parsing .idl failed."); return -1; } diff --git a/zidl/metadata/metadata.h b/idl/metadata/metadata.h similarity index 96% rename from zidl/metadata/metadata.h rename to idl/metadata/metadata.h index 0b405f06e4..d901da36fa 100644 --- a/zidl/metadata/metadata.h +++ b/idl/metadata/metadata.h @@ -13,11 +13,11 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_METADATA_H -#define OHOS_ZIDL_METADATA_H +#ifndef OHOS_IDL_METADATA_H +#define OHOS_IDL_METADATA_H namespace OHOS { -namespace Zidl { +namespace Idl { static constexpr int METADATA_MAGIC_NUMBER = 0x1DF02ED1; @@ -121,4 +121,4 @@ struct MetaType { } } -#endif // OHOS_ZIDL_METADATA_H +#endif // OHOS_IDL_METADATA_H diff --git a/zidl/metadata/metadata_builder.cpp b/idl/metadata/metadata_builder.cpp similarity index 99% rename from zidl/metadata/metadata_builder.cpp rename to idl/metadata/metadata_builder.cpp index 946bb999af..036cdf807e 100644 --- a/zidl/metadata/metadata_builder.cpp +++ b/idl/metadata/metadata_builder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -24,7 +24,7 @@ #define ALIGN8(v) (((v) + 7) & ~7) namespace OHOS { -namespace Zidl { +namespace Idl { const char* MetadataBuilder::TAG = "MetadataBuilder"; diff --git a/zidl/metadata/metadata_builder.h b/idl/metadata/metadata_builder.h similarity index 95% rename from zidl/metadata/metadata_builder.h rename to idl/metadata/metadata_builder.h index 1d0801fbef..78a57ea1aa 100644 --- a/zidl/metadata/metadata_builder.h +++ b/idl/metadata/metadata_builder.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_METADATABUILDER_H -#define OHOS_ZIDL_METADATABUILDER_H +#ifndef OHOS_IDL_METADATABUILDER_H +#define OHOS_IDL_METADATABUILDER_H #include #include "ast/ast_module.h" @@ -24,7 +24,7 @@ #include "util/string_pool.h" namespace OHOS { -namespace Zidl { +namespace Idl { class MetadataBuilder { public: @@ -104,4 +104,4 @@ private: } } -#endif // OHOS_ZIDL_METADATABUILDER_H +#endif // OHOS_IDL_METADATABUILDER_H diff --git a/zidl/metadata/metadata_dumper.cpp b/idl/metadata/metadata_dumper.cpp similarity index 99% rename from zidl/metadata/metadata_dumper.cpp rename to idl/metadata/metadata_dumper.cpp index cba7aec699..4f18306ea5 100644 --- a/zidl/metadata/metadata_dumper.cpp +++ b/idl/metadata/metadata_dumper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -18,7 +18,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { const char* MetadataDumper::TAB = " "; diff --git a/zidl/metadata/metadata_dumper.h b/idl/metadata/metadata_dumper.h similarity index 93% rename from zidl/metadata/metadata_dumper.h rename to idl/metadata/metadata_dumper.h index ec30a2b653..c688d4e063 100644 --- a/zidl/metadata/metadata_dumper.h +++ b/idl/metadata/metadata_dumper.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_METADATADUMPER_H -#define OHOS_ZIDL_METADATADUMPER_H +#ifndef OHOS_IDL_METADATADUMPER_H +#define OHOS_IDL_METADATADUMPER_H #include "metadata/metadata.h" #include "util/string.h" #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { class MetadataDumper { public: @@ -75,4 +75,4 @@ private: } } -#endif // OHOS_ZIDL_METADATADUMPER_H +#endif // OHOS_IDL_METADATADUMPER_H diff --git a/zidl/metadata/metadata_reader.cpp b/idl/metadata/metadata_reader.cpp similarity index 97% rename from zidl/metadata/metadata_reader.cpp rename to idl/metadata/metadata_reader.cpp index fcd1250bae..bff2d9c524 100644 --- a/zidl/metadata/metadata_reader.cpp +++ b/idl/metadata/metadata_reader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -19,7 +19,7 @@ #include "util/logger.h" namespace OHOS { -namespace Zidl { +namespace Idl { const char* MetadataReader::TAG = "MetadataReader"; diff --git a/zidl/metadata/metadata_reader.h b/idl/metadata/metadata_reader.h similarity index 87% rename from zidl/metadata/metadata_reader.h rename to idl/metadata/metadata_reader.h index 1d7054b67d..3d3ab79428 100644 --- a/zidl/metadata/metadata_reader.h +++ b/idl/metadata/metadata_reader.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_METADATAREADER_H -#define OHOS_ZIDL_METADATAREADER_H +#ifndef OHOS_IDL_METADATAREADER_H +#define OHOS_IDL_METADATAREADER_H #include #include "metadata/metadata.h" #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class MetadataReader { public: @@ -35,4 +35,4 @@ private: } } -#endif // OHOS_ZIDL_METADATAREADER_H +#endif // OHOS_IDL_METADATAREADER_H diff --git a/zidl/metadata/metadata_serializer.cpp b/idl/metadata/metadata_serializer.cpp similarity index 99% rename from zidl/metadata/metadata_serializer.cpp rename to idl/metadata/metadata_serializer.cpp index 8ee9031e5b..66efde1b95 100644 --- a/zidl/metadata/metadata_serializer.cpp +++ b/idl/metadata/metadata_serializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "metadata/metadata_serializer.h" namespace OHOS { -namespace Zidl { +namespace Idl { void MetadataSerializer::Serialize() { diff --git a/zidl/metadata/metadata_serializer.h b/idl/metadata/metadata_serializer.h similarity index 94% rename from zidl/metadata/metadata_serializer.h rename to idl/metadata/metadata_serializer.h index 7a5e3a5189..9bc903589e 100644 --- a/zidl/metadata/metadata_serializer.h +++ b/idl/metadata/metadata_serializer.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_METADATASERIALIZER_H -#define OHOS_ZIDL_METADATASERIALIZER_H +#ifndef OHOS_IDL_METADATASERIALIZER_H +#define OHOS_IDL_METADATASERIALIZER_H #include #include #include "metadata/metadata.h" namespace OHOS { -namespace Zidl { +namespace Idl { class MetadataSerializer { public: @@ -109,4 +109,4 @@ private: } } -#endif // OHOS_ZIDL_METADATASERIALIZER_H +#endif // OHOS_IDL_METADATASERIALIZER_H diff --git a/zidl/parser/lexer.cpp b/idl/parser/lexer.cpp similarity index 99% rename from zidl/parser/lexer.cpp rename to idl/parser/lexer.cpp index c8680d4a6d..dd96351134 100644 --- a/zidl/parser/lexer.cpp +++ b/idl/parser/lexer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -19,7 +19,7 @@ #include "util/string_builder.h" namespace OHOS { -namespace Zidl { +namespace Idl { static struct Keywords { String key_; diff --git a/zidl/parser/lexer.h b/idl/parser/lexer.h similarity index 96% rename from zidl/parser/lexer.h rename to idl/parser/lexer.h index d43c7050ce..1aef59879c 100644 --- a/zidl/parser/lexer.h +++ b/idl/parser/lexer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_LEXER_H -#define OHOS_ZIDL_LEXER_H +#ifndef OHOS_IDL_LEXER_H +#define OHOS_IDL_LEXER_H #include #include @@ -25,7 +25,7 @@ #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class Lexer { public: @@ -124,4 +124,4 @@ private: } } -#endif // OHOS_ZIDL_LEXER_H +#endif // OHOS_IDL_LEXER_H diff --git a/zidl/parser/parser.cpp b/idl/parser/parser.cpp similarity index 96% rename from zidl/parser/parser.cpp rename to idl/parser/parser.cpp index 969e1a2a56..e81b1ede96 100644 --- a/zidl/parser/parser.cpp +++ b/idl/parser/parser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -24,7 +24,7 @@ #include namespace OHOS { -namespace Zidl { +namespace Idl { const char* Parser::TAG = "Parser"; @@ -63,7 +63,7 @@ bool Parser::ParseFile() bool ret = true; module_ = new ASTModule(); - module_->SetZidlFile(lexer_.GetSourceFile()->GetPath()); + module_->SetIdlFile(lexer_.GetSourceFile()->GetPath()); ParseLicense(); @@ -174,9 +174,11 @@ bool Parser::ParseInterface() LogError(Token::IDENTIFIER, String::Format("Interface name \"%s\" is illegal.", interfaceFullName.string())); return false; } else if (interfaceFullName.IndexOf(".") == -1) { - LogError(Token::IDENTIFIER, String::Format("Interface name \"%s\" does not have namespace.", + if (!(options_.GetTargetLanguage().Equals("ts"))) { + LogError(Token::IDENTIFIER, String::Format("Interface name \"%s\" does not have namespace.", interfaceFullName.string())); - return false; + return false; + } } AutoPtr interface = new ASTInterfaceType(); @@ -187,6 +189,7 @@ bool Parser::ParseInterface() interface->SetNamespace(module_->ParseNamespace(interfaceFullName.Substring(0, index + 1))); } else { interface->SetName(interfaceFullName); + interface->SetNamespace(NameSpaceEmpty()); } // read ';' @@ -631,6 +634,7 @@ bool Parser::ParseSequenceable() sequenceable->SetNamespace(module_->ParseNamespace(classFullName.Substring(0, index + 1))); } else { sequenceable->SetName(classFullName); + sequenceable->SetNamespace(NameSpaceEmpty()); } module_->AddSequenceable(sequenceable); @@ -706,5 +710,14 @@ void Parser::ShowError() } } +AutoPtr Parser::NameSpaceEmpty() { + AutoPtr currNspace = nullptr; + currNspace = module_->FindNamespace(""); + if (currNspace == nullptr) { + currNspace = new ASTNamespace(""); + module_->AddNamespace(currNspace); + } + return currNspace; +} } } diff --git a/zidl/parser/parser.h b/idl/parser/parser.h similarity index 94% rename from zidl/parser/parser.h rename to idl/parser/parser.h index b0e4f5ec3b..493ce44b3d 100644 --- a/zidl/parser/parser.h +++ b/idl/parser/parser.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_PARSER_H -#define OHOS_ZIDL_PARSER_H +#ifndef OHOS_IDL_PARSER_H +#define OHOS_IDL_PARSER_H #include "ast/ast_interface_type.h" #include "ast/ast_method.h" @@ -28,7 +28,7 @@ #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class Parser { public: @@ -68,6 +68,8 @@ private: bool ParseParameter( /* [in] */ ASTMethod* method); + AutoPtr NameSpaceEmpty(); + AutoPtr ParseType(); AutoPtr ParseList(); @@ -105,4 +107,4 @@ private: } } -#endif // OHOS_ZIDL_PARSER_H +#endif // OHOS_IDL_PARSER_H diff --git a/zidl/parser/token.h b/idl/parser/token.h similarity index 93% rename from zidl/parser/token.h rename to idl/parser/token.h index a121f147ef..11a649537d 100644 --- a/zidl/parser/token.h +++ b/idl/parser/token.h @@ -13,11 +13,11 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_TOKEN_H -#define OHOS_ZIDL_TOKEN_H +#ifndef OHOS_IDL_TOKEN_H +#define OHOS_IDL_TOKEN_H namespace OHOS { -namespace Zidl { +namespace Idl { enum class Token { UNKNOWN = 0, @@ -62,4 +62,4 @@ enum class Token { } } -#endif // OHOS_ZIDL_TOKEN_H +#endif // OHOS_IDL_TOKEN_H diff --git a/zidl/test/native/BUILD.gn b/idl/test/native/BUILD.gn similarity index 80% rename from zidl/test/native/BUILD.gn rename to idl/test/native/BUILD.gn index 509f964109..5f62a460f7 100644 --- a/zidl/test/native/BUILD.gn +++ b/idl/test/native/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -14,22 +14,22 @@ import("//build/ohos.gni") IPC_SUBSYSTEM_DIR = "//foundation/communication/ipc" -ZIDL_TEST_DIR = "//foundation/aafwk/standard/zidl/test/native" +IDL_TEST_DIR = "//foundation/aafwk/standard/idl/test/native" config("ipc_test_config") { include_dirs = [ "//utils/native/base/include", - "$ZIDL_TEST_DIR/include", + "$IDL_TEST_DIR/include", "$IPC_SUBSYSTEM_DIR/utils/include", "$IPC_SUBSYSTEM_DIR/ipc/native/src/mock/include", ] } -ohos_executable("zidl_server_test") { +ohos_executable("idl_server_test") { sources = [ "./src/main_server.cpp", "./src/test_service.cpp", - "./src/zidl_test_service_stub.cpp", + "./src/idl_test_service_stub.cpp", ] configs = [ ":ipc_test_config" ] @@ -43,14 +43,14 @@ ohos_executable("zidl_server_test") { ] subsystem_name = "aafwk" - part_name = "zidl" + part_name = "idl" } -ohos_executable("zidl_client_test") { +ohos_executable("idl_client_test") { sources = [ "./src/main_client.cpp", "./src/test_client.cpp", - "./src/zidl_test_service_proxy.cpp", + "./src/idl_test_service_proxy.cpp", ] configs = [ ":ipc_test_config" ] @@ -64,5 +64,5 @@ ohos_executable("zidl_client_test") { ] subsystem_name = "aafwk" - part_name = "zidl" + part_name = "idl" } diff --git a/zidl/test/native/IZidlTestService.zidl b/idl/test/native/IIdlTestService.idl similarity index 86% rename from zidl/test/native/IZidlTestService.zidl rename to idl/test/native/IIdlTestService.idl index c90dd9fec0..c711167c88 100644 --- a/zidl/test/native/IZidlTestService.zidl +++ b/idl/test/native/IIdlTestService.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,7 +13,7 @@ * limitations under the License. */ -interface OHOS.IZidlTestService { +interface OHOS.IIdlTestService { int TestIntTransaction([in] int data); void TestStringTransaction([in] String data); } diff --git a/zidl/test/native/include/zidl_test_service_proxy.h b/idl/test/native/include/idl_test_service_proxy.h similarity index 73% rename from zidl/test/native/include/zidl_test_service_proxy.h rename to idl/test/native/include/idl_test_service_proxy.h index 222376ca11..d8133bccc9 100644 --- a/zidl/test/native/include/zidl_test_service_proxy.h +++ b/idl/test/native/include/idl_test_service_proxy.h @@ -13,22 +13,22 @@ * limitations under the License. */ -#ifndef OHOS_ZIDLTESTSERVICEPROXY_H -#define OHOS_ZIDLTESTSERVICEPROXY_H +#ifndef OHOS_IDLTESTSERVICEPROXY_H +#define OHOS_IDLTESTSERVICEPROXY_H #include -#include "izidl_test_service.h" +#include "iidl_test_service.h" namespace OHOS { -class ZidlTestServiceProxy : public IRemoteProxy { +class IdlTestServiceProxy : public IRemoteProxy { public: - explicit ZidlTestServiceProxy( + explicit IdlTestServiceProxy( /* [in] */ const sptr& remote) - : IRemoteProxy(remote) + : IRemoteProxy(remote) {} - virtual ~ZidlTestServiceProxy() + virtual ~IdlTestServiceProxy() {} ErrCode TestIntTransaction( @@ -42,8 +42,8 @@ private: static constexpr int COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0; static constexpr int COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; - static inline BrokerDelegator delegator_; + static inline BrokerDelegator delegator_; }; } // namespace OHOS -#endif // OHOS_ZIDLTESTSERVICEPROXY_H +#endif // OHOS_IDLTESTSERVICEPROXY_H diff --git a/zidl/test/native/include/zidl_test_service_stub.h b/idl/test/native/include/idl_test_service_stub.h similarity index 83% rename from zidl/test/native/include/zidl_test_service_stub.h rename to idl/test/native/include/idl_test_service_stub.h index f8318660c9..8657388c23 100644 --- a/zidl/test/native/include/zidl_test_service_stub.h +++ b/idl/test/native/include/idl_test_service_stub.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef OHOS_ZIDLTESTSERVICESTUB_H -#define OHOS_ZIDLTESTSERVICESTUB_H +#ifndef OHOS_IDLTESTSERVICESTUB_H +#define OHOS_IDLTESTSERVICESTUB_H #include -#include "izidl_test_service.h" +#include "iidl_test_service.h" namespace OHOS { -class ZidlTestServiceStub : public IRemoteStub { +class IdlTestServiceStub : public IRemoteStub { public: int OnRemoteRequest( /* [in] */ uint32_t code, @@ -34,5 +34,5 @@ private: static constexpr int COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1; }; } // namespace OHOS -#endif // OHOS_ZIDLTESTSERVICESTUB_H +#endif // OHOS_IDLTESTSERVICESTUB_H diff --git a/zidl/test/native/include/izidl_test_service.h b/idl/test/native/include/iidl_test_service.h similarity index 81% rename from zidl/test/native/include/izidl_test_service.h rename to idl/test/native/include/iidl_test_service.h index b14dc80847..52b4abcbd4 100644 --- a/zidl/test/native/include/izidl_test_service.h +++ b/idl/test/native/include/iidl_test_service.h @@ -13,16 +13,16 @@ * limitations under the License. */ -#ifndef OHOS_IZIDLTESTSERVICE_H -#define OHOS_IZIDLTESTSERVICE_H +#ifndef OHOS_IIDLTESTSERVICE_H +#define OHOS_IIDLTESTSERVICE_H #include #include namespace OHOS { -class IZidlTestService : public IRemoteBroker { +class IIdlTestService : public IRemoteBroker { public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IZidlTestService"); + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IIdlTestService"); virtual ErrCode TestIntTransaction( /* [in] */ int _data, @@ -32,5 +32,5 @@ public: /* [in] */ const std::string& _data) = 0; }; } // namespace OHOS -#endif // OHOS_IZIDLTESTSERVICE_H +#endif // OHOS_IIDLTESTSERVICE_H diff --git a/zidl/test/native/include/test_client.h b/idl/test/native/include/test_client.h similarity index 92% rename from zidl/test/native/include/test_client.h rename to idl/test/native/include/test_client.h index cd73b69be1..3ab38aa7e9 100644 --- a/zidl/test/native/include/test_client.h +++ b/idl/test/native/include/test_client.h @@ -18,7 +18,7 @@ #include "ipc_debug.h" #include "log_tags.h" -#include "zidl_test_service_proxy.h" +#include "idl_test_service_proxy.h" namespace OHOS { class TestClient { @@ -28,7 +28,7 @@ public: void StartStringTransaction(); private: static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestClient" }; - sptr testService_; + sptr testService_; }; } // namespace OHOS #endif // OHOS_IPC_TEST_SERVICE_CLIENT_H diff --git a/zidl/test/native/include/test_service.h b/idl/test/native/include/test_service.h similarity index 92% rename from zidl/test/native/include/test_service.h rename to idl/test/native/include/test_service.h index 33c59f855a..d88cee6a05 100644 --- a/zidl/test/native/include/test_service.h +++ b/idl/test/native/include/test_service.h @@ -18,10 +18,10 @@ #include "hilog/log.h" #include "log_tags.h" -#include "zidl_test_service_stub.h" +#include "idl_test_service_stub.h" namespace OHOS { -class TestService : public ZidlTestServiceStub { +class TestService : public IdlTestServiceStub { public: TestService(); ~TestService(); diff --git a/zidl/test/native/src/zidl_test_service_proxy.cpp b/idl/test/native/src/idl_test_service_proxy.cpp similarity index 90% rename from zidl/test/native/src/zidl_test_service_proxy.cpp rename to idl/test/native/src/idl_test_service_proxy.cpp index 8ad62051da..0130ba76a9 100644 --- a/zidl/test/native/src/zidl_test_service_proxy.cpp +++ b/idl/test/native/src/idl_test_service_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "zidl_test_service_proxy.h" +#include "idl_test_service_proxy.h" namespace OHOS { -ErrCode ZidlTestServiceProxy::TestIntTransaction( +ErrCode IdlTestServiceProxy::TestIntTransaction( /* [in] */ int _data, /* [out] */ int& result) { @@ -47,7 +47,7 @@ ErrCode ZidlTestServiceProxy::TestIntTransaction( return ERR_OK; } -ErrCode ZidlTestServiceProxy::TestStringTransaction( +ErrCode IdlTestServiceProxy::TestStringTransaction( /* [in] */ const std::string& _data) { MessageParcel data; diff --git a/zidl/test/native/src/zidl_test_service_stub.cpp b/idl/test/native/src/idl_test_service_stub.cpp similarity index 92% rename from zidl/test/native/src/zidl_test_service_stub.cpp rename to idl/test/native/src/idl_test_service_stub.cpp index 8e69a0903c..0ba8f1ed06 100644 --- a/zidl/test/native/src/zidl_test_service_stub.cpp +++ b/idl/test/native/src/idl_test_service_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "zidl_test_service_stub.h" +#include "idl_test_service_stub.h" namespace OHOS { -int ZidlTestServiceStub::OnRemoteRequest( +int IdlTestServiceStub::OnRemoteRequest( /* [in] */ uint32_t code, /* [in] */ MessageParcel& data, /* [out] */ MessageParcel& reply, diff --git a/zidl/test/native/src/main_client.cpp b/idl/test/native/src/main_client.cpp similarity index 97% rename from zidl/test/native/src/main_client.cpp rename to idl/test/native/src/main_client.cpp index 7238b197b7..2d2ee26af2 100644 --- a/zidl/test/native/src/main_client.cpp +++ b/idl/test/native/src/main_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 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/zidl/test/native/src/main_server.cpp b/idl/test/native/src/main_server.cpp similarity index 95% rename from zidl/test/native/src/main_server.cpp rename to idl/test/native/src/main_server.cpp index 91611c64b0..ba87fa6da8 100644 --- a/zidl/test/native/src/main_server.cpp +++ b/idl/test/native/src/main_server.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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/zidl/test/native/src/test_client.cpp b/idl/test/native/src/test_client.cpp similarity index 90% rename from zidl/test/native/src/test_client.cpp rename to idl/test/native/src/test_client.cpp index d2670709a2..f5592ee1bc 100644 --- a/zidl/test/native/src/test_client.cpp +++ b/idl/test/native/src/test_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -33,7 +33,7 @@ int TestClient::ConnectService() sptr object = saMgr->GetSystemAbility(IPC_TEST_SERVICE); if (object != nullptr) { ZLOGE(LABEL, "Got test Service object"); - testService_ = (new (std::nothrow) ZidlTestServiceProxy(object)); + testService_ = (new (std::nothrow) IdlTestServiceProxy(object)); } if (testService_ == nullptr) { @@ -58,7 +58,7 @@ void TestClient::StartStringTransaction() { if (testService_ != nullptr) { ZLOGI(LABEL, "StartIntTransaction"); - testService_->TestStringTransaction("ZIDL Test"); + testService_->TestStringTransaction("IDL Test"); } } } // namespace OHOS diff --git a/zidl/test/native/src/test_service.cpp b/idl/test/native/src/test_service.cpp similarity index 97% rename from zidl/test/native/src/test_service.cpp rename to idl/test/native/src/test_service.cpp index a8698b4f46..b935f562cc 100644 --- a/zidl/test/native/src/test_service.cpp +++ b/idl/test/native/src/test_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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/zidl/test/ts/moduletest/common/zidl_common.h b/idl/test/ts/common/idl_common.h similarity index 85% rename from zidl/test/ts/moduletest/common/zidl_common.h rename to idl/test/ts/common/idl_common.h index b2bbcdcbd5..970dae0158 100644 --- a/zidl/test/ts/moduletest/common/zidl_common.h +++ b/idl/test/ts/common/idl_common.h @@ -13,13 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_MODULE_TEST_ZIDL_COMMON_H -#define OHOS_ZIDL_MODULE_TEST_ZIDL_COMMON_H +#ifndef OHOS_IDL_MODULE_TEST_IDL_COMMON_H +#define OHOS_IDL_MODULE_TEST_IDL_COMMON_H #include #include #define private public #define protected public +#include "codegen/code_emitter.h" #include "codegen/code_generator.h" #include "codegen/js_code_emitter.h" #undef private @@ -34,18 +35,18 @@ #include "util/options.h" #include "util/string.h" #include "util/string_builder.h" -#include "zidl_file.h" +#include "idl_file.h" namespace OHOS { -namespace Zidl { -namespace ModuleTest { +namespace Idl { +namespace TestCommon { const int ERR_FAIL = -1; const int ERR_OK = 0; -class ZidlCommon { +class IdlCommon { public: - ZidlCommon() = default; - ~ZidlCommon() = default; + IdlCommon() = default; + ~IdlCommon() = default; int Ready(int argc, char** argv) { @@ -94,7 +95,7 @@ public: return ERR_FAIL; } } - if (options.GetTargetLanguage().Equals("js")) { + if (options.GetTargetLanguage().Equals("ts")) { this->jsCodeGen_ = std::make_shared(metadata.get()); this->jsCodeGen_->SetDirectory(options.GetGenerationDirectory()); } @@ -102,7 +103,7 @@ public: return 0; } - int PrepareZidlFile(const std::string &fileName, const std::string &fileContent) + int PrepareIdlFile(const std::string &fileName, const std::string &fileContent, const std::string &fileLicense = LICENSE_CONTENT) { String filePath = String::Format("%s/%s", "./", fileName.c_str()); File file(filePath, File::WRITE); @@ -112,7 +113,8 @@ public: } StringBuilder stringBuilder; - stringBuilder.Append(LICENSE_CONTENT.c_str()); + // stringBuilder.Append(LICENSE_CONTENT.c_str()); + stringBuilder.Append(fileLicense.c_str()); stringBuilder.Append(fileContent.c_str()); String data = stringBuilder.ToString(); @@ -127,4 +129,4 @@ public: } } } -#endif // OHOS_ZIDL_MODULE_TEST_ZIDL_COMMON_H \ No newline at end of file +#endif // OHOS_IDL_MODULE_TEST_IDL_COMMON_H \ No newline at end of file diff --git a/idl/test/ts/common/idl_file.h b/idl/test/ts/common/idl_file.h new file mode 100644 index 0000000000..163b945dd7 --- /dev/null +++ b/idl/test/ts/common/idl_file.h @@ -0,0 +1,441 @@ +/* + * Copyright (c) 2022 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_IDL_MODULE_TEST_IDL_FILE_H +#define OHOS_IDL_MODULE_TEST_IDL_FILE_H + +#include + +namespace OHOS { +namespace Idl { +namespace TestCommon { +const std::string LICENSE_CONTENT = +"/*\n" +" * Copyright (C) 2021 Huawei Device Co., Ltd.\n" +" * Licensed under the Apache License, Version 2.0 (the \"License\");\n" +" * you may not use this file except in compliance with the License.\n" +" * You may obtain a copy of the License at\n" +" *\n" +" * http://www.apache.org/licenses/LICENSE-2.0\n" +" *\n" +" * Unless required by applicable law or agreed to in writing, software\n" +" * distributed under the License is distributed on an \"AS IS\" BASIS,\n" +" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +" * See the License for the specific language governing permissions and\n" +" * limitations under the License.\n" +" */\n" +"\n"; +const std::string UNKNOW_TYPE_IDL_NAME = "IIdlTest.idl"; + +const std::string UNKNOW_TYPE_CASE1_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" void voidOrderOutChar([in] char param1, [out] char param2);\n" +"}"; + +const std::string UNKNOW_TYPE_CASE2_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" void voidOrderOutList([in] List param1, [out] List param2);\n" +"}"; + +const std::string UNKNOW_TYPE_CASE3_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" void voidOrderOutMapChar([in] Map param1, [out] Map param2);\n" +"}"; + +const std::string UNKNOW_TYPE_CASE4_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" void voidOrderOutMapList([in] Map> param1, [out] Map> param2);\n" +"}"; + +const std::string UNKNOW_TYPE_CASE5_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" char voidOrderReturnChar();\n" +"}"; + +const std::string UNKNOW_TYPE_CASE6_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" List voidOrderReturnList();\n" +"}"; + +const std::string UNKNOW_TYPE_CASE7_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" Map voidOrderReturnMapChar();\n" +"}"; + +const std::string UNKNOW_TYPE_CASE8_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" Map> voidOrderReturnMapList();\n" +"}"; + +const std::string NORMAL_TYPE_IDL_CONTENT = +"interface idl.systemtest.IInterfaceDeclare;\n" +"sequenceable idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.IIdlTest {\n" +" int voidOrderOutInt([in] int param1, [out] int param2);\n" +"}"; + +const std::string NO_RETURN_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" voidOrderNoReturn();\n" +"}"; + +const std::string NO_FUNCTION_NAME_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" int ([in] int param1, [out] int param2);\n" +"}"; + +const std::string SAME_FUNCTION_NAME_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" int voidOrderOutInt([in] int param1, [out] int param2);\n" +" int voidOrderOutInt([in] int param1);\n" +"}"; + +const std::string UNSIGNED_CHAR_TYPE_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" unsigned char voidOrderOutUnsignedChar([in] unsigned char param1, [out] unsigned char param2);\n" +"}"; + +const std::string UNSIGNED_SHORT_TYPE_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" unsigned short voidOrderOutUnsignedShort([in] unsigned short param1, [out] unsigned short param2);\n" +"}"; + +const std::string UNSIGNED_INT_TYPE_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" unsigned int voidOrderOutUnsignedInt([in] unsigned int param1, [out] unsigned int param2);\n" +"}"; + +const std::string MULTIPLE_NAMESPACES_IDL_CONTENT = +"interface idl.systemtest.namespace3.namespace4.IIdlTest {\n" +" void voidParameterTypeVoid([in] int param1);\n" +"}"; + +const std::string ERROR_INTERFACE_KEYWORD_IDL_CONTENT = +"lnterfaces idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid([in] int param1);\n" +"}"; + +const std::string INOUT_SEPARATE_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid([in, out] int param1);\n" +"}"; + +const std::string INTERFACE_NO_CONTENT_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +"}"; + +const std::string PARAM_NO_INOUT_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid(int param1);\n" +"}"; + +const std::string INOUT_NO_BIGPARANTHESES_IDL_CONTENT = +"interface idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid(in int param1);\n" +"}"; + +const std::string NORMAL_TYPE_IN_IDL_CONTENT = +"interface idl.systemtest.IInterfaceDeclare;\n" +"sequenceable idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid([in] void param1);\n" +" void voidParameterTypeShort([in] short param1);\n" +" void voidParameterTypeByte([in] byte param2);\n" +" void voidParameterTypeInt([in] int param1);\n" +" void voidParameterTypeLong([in] long param1);\n" +" void voidParameterTypeFloat([in] float param1);\n" +" void voidParameterTypeString([in] String param1);\n" +" void voidParameterTypeDouble([in] double param1);\n" +" void voidParameterTypeBoolean([in] boolean param1);\n" +" void voidParameterTypeShortArray([in] short[] param1);\n" +" void voidParameterTypeByteArray([in] byte[] param2);\n" +" void voidParameterTypeIntArray([in] int[] param1);\n" +" void voidParameterTypeLongArray([in] long[] param1);\n" +" void voidParameterTypeFloatArray([in] float[] param1);\n" +" void voidParameterTypeStringArray([in] String[] param1);\n" +" void voidParameterTypeDoubleArray([in] double[] param1);\n" +" void voidParameterTypeBooleanArray([in] boolean[] param1);\n" +" void voidParameterTypeMySequenceable([in] MySequenceable mysequenceable);\n" +" void voidParameterTypeMySequenceableArray([in] MySequenceable[] mysequenceable);\n" +" void voidParameterTypeInterface([in] IInterfaceDeclare myInterface);\n" +" void voidMap([in] Map data);\n" +"}"; + +const std::string NORMAL_TYPE_OUT_IDL_CONTENT = +"interface idl.systemtest.IInterfaceDeclare;\n" +"sequenceable idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid([out] void param2);\n" +" void voidParameterTypeShort([out] short param2);\n" +" void voidParameterTypeByte([out] byte param2);\n" +" void voidParameterTypeInt([out] int param2);\n" +" void voidParameterTypeLong([out] long param2);\n" +" void voidParameterTypeFloat([out] float param2);\n" +" void voidParameterTypeString([out] String param2);\n" +" void voidParameterTypeDouble([out] double param2);\n" +" void voidParameterTypeBoolean([out] boolean param2);\n" +" void voidParameterTypeShortArray([out] short[] param2);\n" +" void voidParameterTypeByteArray([out] byte[] param2);\n" +" void voidParameterTypeIntArray([out] int[] param2);\n" +" void voidParameterTypeLongArray([out] long[] param2);\n" +" void voidParameterTypeFloatArray([out] float[] param2);\n" +" void voidParameterTypeStringArray([out] String[] param2);\n" +" void voidParameterTypeDoubleArray([out] double[] param2);\n" +" void voidParameterTypeBooleanArray([out] boolean[] param2);\n" +" void voidParameterTypeMySequenceable([out] MySequenceable mysequenceable);\n" +" void voidParameterTypeMySequenceableArray([out] MySequenceable[] mysequenceable);\n" +" void voidParameterTypeInterface([out] IInterfaceDeclare myInterface);\n" +" void voidMap([out] Map data);\n" +"}"; + +const std::string NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT = +"interface idl.systemtest.IInterfaceDeclare;\n" +"sequenceable idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid([inout] void param2);\n" +" void voidParameterTypeShort([inout] short param2);\n" +" void voidParameterTypeByte([inout] byte param2);\n" +" void voidParameterTypeInt([inout] int param2);\n" +" void voidParameterTypeLong([inout] long param2);\n" +" void voidParameterTypeFloat([inout] float param2);\n" +" void voidParameterTypeString([inout] String param2);\n" +" void voidParameterTypeDouble([inout] double param2);\n" +" void voidParameterTypeBoolean([inout] boolean param2);\n" +" void voidParameterTypeShortArray([inout] short[] param2);\n" +" void voidParameterTypeByteArray([inout] byte[] param2);\n" +" void voidParameterTypeIntArray([inout] int[] param2);\n" +" void voidParameterTypeLongArray([inout] long[] param2);\n" +" void voidParameterTypeFloatArray([inout] float[] param2);\n" +" void voidParameterTypeStringArray([inout] String[] param2);\n" +" void voidParameterTypeDoubleArray([inout] double[] param2);\n" +" void voidParameterTypeBooleanArray([inout] boolean[] param2);\n" +" void voidParameterTypeMySequenceable([inout] MySequenceable mysequenceable);\n" +" void voidParameterTypeMySequenceableArray([inout] MySequenceable[] mysequenceable);\n" +" void voidParameterTypeInterface([inout] IInterfaceDeclare myInterface);\n" +" void voidMap([inout] Map data);\n" +"}"; + +const std::string NORMAL_TYPE_RETURN_IDL_CONTENT = +"interface idl.systemtest.IInterfaceDeclare;\n" +"sequenceable idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.IIdlTest {\n" +" void voidParameterTypeVoid();\n" +" short voidParameterTypeShort();\n" +" byte voidParameterTypeByte();\n" +" int voidParameterTypeInt();\n" +" long voidParameterTypeLong();\n" +" float voidParameterTypeFloat();\n" +" String voidParameterTypeString();\n" +" double voidParameterTypeDouble();\n" +" boolean voidParameterTypeBoolean();\n" +" short[] voidParameterTypeShortArray();\n" +" byte[] voidParameterTypeByteArray();\n" +" int[] voidParameterTypeIntArray();\n" +" long[] voidParameterTypeLongArray();\n" +" float[] voidParameterTypeFloatArray();\n" +" String[] voidParameterTypeStringArray();\n" +" double[] voidParameterTypeDoubleArray();\n" +" boolean[] voidParameterTypeBooleanArray();\n" +" MySequenceable voidParameterTypeMySequenceable();\n" +" MySequenceable[] voidParameterTypeMySequenceableArray();\n" +" Map voidMap();\n" +"}"; + +const std::string NORMAL_TYPE_COMBINATION_IDL_CONTENT = +"interface idl.systemtest.IInterfaceDeclare;\n" +"sequenceable idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.IIdlTest {\n" +" short voidParameterTypeShort([in] short param1, [out] short param2, [inout] short param3);\n" +" byte voidParameterTypeByte([in] byte param1, [out] byte param2, [inout] byte param3);\n" +" short[] voidParameterTypeShortArray([in] short[] param1, [out] short[] param2, [inout] short[] param3);\n" +" int[] voidParameterTypeIntArray([in] int[] param1, [inout] int[] param2 , [out] int[] param3);\n" +" long[] voidParameterTypeLongArray([in] long[] param1, [inout] long[] param2, [out] long[] param3);\n" +" float[] voidParameterTypeFloatArray([in] float[] param1, [inout] float[] param2, [out] float[] param3);\n" +" String[] voidParameterTypeStringArray([in] String[] param1, [inout] String[] param2, [out] String[] param3);\n" +" double[] voidParameterTypeDoubleArray([in] double[] param1, [inout] double[] param2, [out] double[] param3);\n" +" boolean[] voidParameterTypeBooleanArray([in] boolean[] param1," +"[inout] boolean[] param2, [out] boolean[] param3);\n" +" byte[] voidParameterTypeByteArray([in] byte[] param1, [out] byte[] param2, [inout] byte[] param3);\n" +" MySequenceable TestIntTransaction([in] MySequenceable mysequenceable1," +"[in, out] MySequenceable mysequenceable2, [out] MySequenceable mysequenceable3);\n" +" MySequenceable[] voidParameterTypeMySequenceableArray([in] MySequenceable[] mysequenceable1," +"[inout] MySequenceable[] mysequenceable2, [out] MySequenceable[] mysequenceable3);\n" +" void InOutMap([inout] Map data);\n" +" void InOutMapArray([inout] Map data);\n" +"}"; + +const std::string CAPITALIZATION_ZIDL_NAME = "CapitalizationIdlTest.idl"; + +const std::string CAPITALIZATION_VOID_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" VOID voidOrderReturnVoid();\n" +"}"; + +const std::string CAPITALIZATION_BOOL_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" BOOLEAN voidOrderReturnBOOLEAN();\n" +"}"; + +const std::string CAPITALIZATION_INT_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" INT voidOrderReturnINT();\n" +"}"; + +const std::string CAPITALIZATION_STRING_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" STRING voidOrderReturnSTRING();\n" +"}"; + +const std::string CAPITALIZATION_INTERFACE_TYPE_ZIDL_CONTENT = +"INTERFACE idl.systemtest.CapitalizationIdlTest {\n" +" int voidOrderReturnInt();\n" +"}"; + +const std::string CAPITALIZATION_IN_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" int voidOrderReturnInt([IN] int param1);\n" +"}"; + +const std::string CAPITALIZATION_OUT_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" void voidOrderReturnVoid([OUT] int param1);\n" +"}"; + +const std::string CAPITALIZATION_ONEWAY_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" [ONEWAY] void voidOrderReturnVoid();\n" +"}"; + +const std::string CAPITALIZATION_SEQUENCEABLE_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.IInterfaceDeclare;\n" +"SEQUENCEABLE idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.CapitalizationIdlTest {\n" +" void voidOrderReturnVoid([in] MySequenceable mysequenceable);\n" +"}"; + +const std::string CAPITALIZATION_MAP_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.CapitalizationIdlTest {\n" +" MAP voidOrderReturnMap();\n" +"}"; + +const std::string NO_LICENSE_ZIDL_NAME = "NoLicenseIdlTest.idl"; + +const std::string NO_LICENSE_VOID_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" void voidOrderReturnVoid();\n" +"}"; + +const std::string NO_LICENSE_BOOL_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" boolean voidOrderReturnBOOLEAN();\n" +"}"; + +const std::string NO_LICENSE_INT_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" int voidOrderReturnINT();\n" +"}"; + +const std::string NO_LICENSE_STRING_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" string voidOrderReturnSTRING();\n" +"}"; + +const std::string NO_LICENSE_INTERFACE_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" int voidOrderReturnInt();\n" +"}"; + +const std::string NO_LICENSE_IN_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" int voidOrderReturnInt([in] int param1);\n" +"}"; + +const std::string NO_LICENSE_OUT_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" void voidOrderReturnVoid([out] int param1);\n" +"}"; + +const std::string NO_LICENSE_ONEWAY_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" [oneway] void voidOrderReturnVoid();\n" +"}"; + +const std::string NO_LICENSE_SEQUENCEABLE_TYPE_ZIDL_CONTENT = +"sequenceable idl.systemtest.MySequenceable;\n" +"interface idl.systemtest.NoLicenseIdlTest {\n" +" void voidOrderReturnVoid([in] MySequenceable mysequenceable);\n" +"}"; + +const std::string NO_LICENSE_MAP_TYPE_ZIDL_CONTENT = +"interface idl.systemtest.NoLicenseIdlTest {\n" +" Map voidOrderReturnMap();\n" +"}"; + +const std::string NO_INTERFACE_ZIDL_NAME = "NoInterfaceIdlTest.idl"; + +const std::string NO_INTERFACE_VOID_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" void voidOrderReturnVoid();\n" +"}"; + +const std::string NO_INTERFACE_BOOL_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" boolean voidOrderReturnBOOLEAN();\n" +"}"; + +const std::string NO_INTERFACE_INT_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" int voidOrderReturnINT();\n" +"}"; + +const std::string NO_INTERFACE_STRING_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" string voidOrderReturnSTRING();\n" +"}"; + +const std::string NO_INTERFACE_INTERFACE_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" int voidOrderReturnInt();\n" +"}"; + +const std::string NO_INTERFACE_IN_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" int voidOrderReturnInt([in] int param1);\n" +"}"; + +const std::string NO_INTERFACE_OUT_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" void voidOrderReturnVoid([out] int param1);\n" +"}"; + +const std::string NO_INTERFACE_ONEWAY_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" [oneway] void voidOrderReturnVoid();\n" +"}"; + +const std::string NO_INTERFACE_SEQUENCEABLE_TYPE_ZIDL_CONTENT = +"sequenceable idl.systemtest.MySequenceable;\n" +"idl.systemtest.NoInterfaceIdlTest {\n" +" void voidOrderReturnVoid([in] MySequenceable mysequenceable);\n" +"}"; + +const std::string NO_INTERFACE_MAP_TYPE_ZIDL_CONTENT = +"idl.systemtest.NoInterfaceIdlTest {\n" +" Map voidOrderReturnMap();\n" +"}"; +} +} +} +#endif // OHOS_AAFWK_ABILITY_CONFIG_H \ No newline at end of file diff --git a/idl/test/ts/moduletest/BUILD.gn b/idl/test/ts/moduletest/BUILD.gn new file mode 100644 index 0000000000..04dba875e5 --- /dev/null +++ b/idl/test/ts/moduletest/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 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. + +import("//build/ohos.gni") +group("moduletest") { + testonly = true + + deps = [ + "js_code_emitter_test:moduletest", + "js_code_emitter_capitalization_issues_test:moduletest", + "js_code_emitter_no_license_test:moduletest", + "js_code_emitter_no_interface_test:moduletest", + ] +} diff --git a/zidl/test/ts/moduletest/js_code_emitter_proxy_test/BUILD.gn b/idl/test/ts/moduletest/js_code_emitter_capitalization_issues_test/BUILD.gn similarity index 82% rename from zidl/test/ts/moduletest/js_code_emitter_proxy_test/BUILD.gn rename to idl/test/ts/moduletest/js_code_emitter_capitalization_issues_test/BUILD.gn index 21c03a50e9..3a8ac87998 100644 --- a/zidl/test/ts/moduletest/js_code_emitter_proxy_test/BUILD.gn +++ b/idl/test/ts/moduletest/js_code_emitter_capitalization_issues_test/BUILD.gn @@ -17,14 +17,13 @@ ZIDL_DIR = "../../../.." config("zidl_module_test_config") { include_dirs = [ - "../common", + "../../common", "${ZIDL_DIR}/", - "${ZIDL_DIR}/codegen/", "//utils/native/base/include/", ] } -zidl_common_sources = [ +common_sources = [ "${ZIDL_DIR}/ast/ast_array_type.cpp", "${ZIDL_DIR}/ast/ast_boolean_type.cpp", "${ZIDL_DIR}/ast/ast_byte_type.cpp", @@ -48,7 +47,7 @@ zidl_common_sources = [ "${ZIDL_DIR}/ast/ast_void_type.cpp", ] -zidl_common_sources += [ +common_sources += [ "${ZIDL_DIR}/codegen/code_emitter.cpp", "${ZIDL_DIR}/codegen/code_generator.cpp", "${ZIDL_DIR}/codegen/cpp_code_emitter.cpp", @@ -56,19 +55,19 @@ zidl_common_sources += [ "${ZIDL_DIR}/codegen/js_code_emitter.cpp", ] -zidl_common_sources += [ +common_sources += [ "${ZIDL_DIR}/metadata/metadata_builder.cpp", "${ZIDL_DIR}/metadata/metadata_dumper.cpp", "${ZIDL_DIR}/metadata/metadata_reader.cpp", "${ZIDL_DIR}/metadata/metadata_serializer.cpp", ] -zidl_common_sources += [ +common_sources += [ "${ZIDL_DIR}/parser/lexer.cpp", "${ZIDL_DIR}/parser/parser.cpp", ] -zidl_common_sources += [ +common_sources += [ "${ZIDL_DIR}/util/file.cpp", "${ZIDL_DIR}/util/light_refcount_base.cpp", "${ZIDL_DIR}/util/logger.cpp", @@ -77,24 +76,17 @@ zidl_common_sources += [ "${ZIDL_DIR}/util/string_builder.cpp", "${ZIDL_DIR}/util/string_pool.cpp", ] +module_output_path = "zidl/ts_moduletest" -module_output_path = "zidl/zidl_moduletest" -ohos_moduletest("js_code_emitter_proxy_test") { +ohos_moduletest("js_code_emitter_capitalization_issues_test") { module_out_path = module_output_path - configs = [ ":zidl_module_test_config" ] - - sources = [ "js_code_emitter_proxy_test.cpp" ] - sources += zidl_common_sources - - deps = [ - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - "//utils/native/base:utilsecurec", - ] + sources = [ "js_code_emitter_capitalization_issues_test.cpp" ] + sources += common_sources + deps = [ "//utils/native/base:utilsecurec" ] } group("moduletest") { testonly = true - deps = [ ":js_code_emitter_proxy_test" ] + deps = [ ":js_code_emitter_capitalization_issues_test" ] } diff --git a/idl/test/ts/moduletest/js_code_emitter_capitalization_issues_test/js_code_emitter_capitalization_issues_test.cpp b/idl/test/ts/moduletest/js_code_emitter_capitalization_issues_test/js_code_emitter_capitalization_issues_test.cpp new file mode 100644 index 0000000000..03ee880fc8 --- /dev/null +++ b/idl/test/ts/moduletest/js_code_emitter_capitalization_issues_test/js_code_emitter_capitalization_issues_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2021 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 +#include "idl_common.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl::TestCommon; + +namespace OHOS { +namespace Idl { +namespace ModuleTest { +class JsCodeEmitterTest : public testing::Test, public IdlCommon { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void JsCodeEmitterTest::SetUpTestCase() +{} + +void JsCodeEmitterTest::TearDownTestCase() +{} + +void JsCodeEmitterTest::SetUp() +{} + +void JsCodeEmitterTest::TearDown() +{} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_VOID_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_BOOL_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_INT_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_STRING_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_INTERFACE_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_006, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_IN_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_007, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_OUT_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_008, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_ONEWAY_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_009, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_SEQUENCEABLE_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: Detect keyword capitalization issues test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_010, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_ZIDL_NAME.c_str(), CAPITALIZATION_MAP_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", CAPITALIZATION_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +} // namespace ModuleTest +} // namespace Idl +} // namespace OHOS diff --git a/idl/test/ts/moduletest/js_code_emitter_no_interface_test/BUILD.gn b/idl/test/ts/moduletest/js_code_emitter_no_interface_test/BUILD.gn new file mode 100644 index 0000000000..cc26206d36 --- /dev/null +++ b/idl/test/ts/moduletest/js_code_emitter_no_interface_test/BUILD.gn @@ -0,0 +1,92 @@ +# Copyright (c) 2022 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. + +import("//build/test.gni") + +ZIDL_DIR = "../../../.." + +config("zidl_module_test_config") { + include_dirs = [ + "../../common", + "${ZIDL_DIR}/", + "//utils/native/base/include/", + ] +} + +common_sources = [ + "${ZIDL_DIR}/ast/ast_array_type.cpp", + "${ZIDL_DIR}/ast/ast_boolean_type.cpp", + "${ZIDL_DIR}/ast/ast_byte_type.cpp", + "${ZIDL_DIR}/ast/ast_char_type.cpp", + "${ZIDL_DIR}/ast/ast_double_type.cpp", + "${ZIDL_DIR}/ast/ast_float_type.cpp", + "${ZIDL_DIR}/ast/ast_integer_type.cpp", + "${ZIDL_DIR}/ast/ast_interface_type.cpp", + "${ZIDL_DIR}/ast/ast_list_type.cpp", + "${ZIDL_DIR}/ast/ast_long_type.cpp", + "${ZIDL_DIR}/ast/ast_map_type.cpp", + "${ZIDL_DIR}/ast/ast_method.cpp", + "${ZIDL_DIR}/ast/ast_module.cpp", + "${ZIDL_DIR}/ast/ast_namespace.cpp", + "${ZIDL_DIR}/ast/ast_node.cpp", + "${ZIDL_DIR}/ast/ast_parameter.cpp", + "${ZIDL_DIR}/ast/ast_sequenceable_type.cpp", + "${ZIDL_DIR}/ast/ast_short_type.cpp", + "${ZIDL_DIR}/ast/ast_string_type.cpp", + "${ZIDL_DIR}/ast/ast_type.cpp", + "${ZIDL_DIR}/ast/ast_void_type.cpp", +] + +common_sources += [ + "${ZIDL_DIR}/codegen/code_emitter.cpp", + "${ZIDL_DIR}/codegen/code_generator.cpp", + "${ZIDL_DIR}/codegen/cpp_code_emitter.cpp", + "${ZIDL_DIR}/codegen/java_code_emitter.cpp", + "${ZIDL_DIR}/codegen/js_code_emitter.cpp", +] + +common_sources += [ + "${ZIDL_DIR}/metadata/metadata_builder.cpp", + "${ZIDL_DIR}/metadata/metadata_dumper.cpp", + "${ZIDL_DIR}/metadata/metadata_reader.cpp", + "${ZIDL_DIR}/metadata/metadata_serializer.cpp", +] + +common_sources += [ + "${ZIDL_DIR}/parser/lexer.cpp", + "${ZIDL_DIR}/parser/parser.cpp", +] + +common_sources += [ + "${ZIDL_DIR}/util/file.cpp", + "${ZIDL_DIR}/util/light_refcount_base.cpp", + "${ZIDL_DIR}/util/logger.cpp", + "${ZIDL_DIR}/util/options.cpp", + "${ZIDL_DIR}/util/string.cpp", + "${ZIDL_DIR}/util/string_builder.cpp", + "${ZIDL_DIR}/util/string_pool.cpp", +] +module_output_path = "zidl/ts_moduletest" + +ohos_moduletest("js_code_emitter_no_interface_test") { + module_out_path = module_output_path + configs = [ ":zidl_module_test_config" ] + sources = [ "js_code_emitter_no_interface_test.cpp" ] + sources += common_sources + deps = [ "//utils/native/base:utilsecurec" ] +} + +group("moduletest") { + testonly = true + deps = [ ":js_code_emitter_no_interface_test" ] +} diff --git a/idl/test/ts/moduletest/js_code_emitter_no_interface_test/js_code_emitter_no_interface_test.cpp b/idl/test/ts/moduletest/js_code_emitter_no_interface_test/js_code_emitter_no_interface_test.cpp new file mode 100644 index 0000000000..58f03e9bfc --- /dev/null +++ b/idl/test/ts/moduletest/js_code_emitter_no_interface_test/js_code_emitter_no_interface_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2021 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 +#include "idl_common.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl::TestCommon; + +namespace OHOS { +namespace Idl { +namespace ModuleTest { +class JsCodeEmitterTest : public testing::Test, public IdlCommon { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void JsCodeEmitterTest::SetUpTestCase() +{} + +void JsCodeEmitterTest::TearDownTestCase() +{} + +void JsCodeEmitterTest::SetUp() +{} + +void JsCodeEmitterTest::TearDown() +{} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_VOID_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_BOOL_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_INT_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_STRING_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_INTERFACE_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_006, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_IN_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_007, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_OUT_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_008, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_ONEWAY_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_009, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_SEQUENCEABLE_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no interface test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_010, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_ZIDL_NAME.c_str(), NO_INTERFACE_MAP_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_INTERFACE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +} // namespace ModuleTest +} // namespace Idl +} // namespace OHOS diff --git a/zidl/test/ts/moduletest/js_coe_emitter_interface_test/BUILD.gn b/idl/test/ts/moduletest/js_code_emitter_no_license_test/BUILD.gn similarity index 92% rename from zidl/test/ts/moduletest/js_coe_emitter_interface_test/BUILD.gn rename to idl/test/ts/moduletest/js_code_emitter_no_license_test/BUILD.gn index dc362e66b7..eae3842990 100644 --- a/zidl/test/ts/moduletest/js_coe_emitter_interface_test/BUILD.gn +++ b/idl/test/ts/moduletest/js_code_emitter_no_license_test/BUILD.gn @@ -17,7 +17,7 @@ ZIDL_DIR = "../../../.." config("zidl_module_test_config") { include_dirs = [ - "../common", + "../../common", "${ZIDL_DIR}/", "//utils/native/base/include/", ] @@ -76,17 +76,17 @@ common_sources += [ "${ZIDL_DIR}/util/string_builder.cpp", "${ZIDL_DIR}/util/string_pool.cpp", ] -module_output_path = "zidl/zidl_moduletest" +module_output_path = "zidl/ts_moduletest" -ohos_moduletest("js_code_emitter_interface") { +ohos_moduletest("js_code_emitter_no_license_test") { module_out_path = module_output_path configs = [ ":zidl_module_test_config" ] - sources = [ "js_code_emitter_interface.cpp" ] + sources = [ "js_code_emitter_no_license_test.cpp" ] sources += common_sources deps = [ "//utils/native/base:utilsecurec" ] } group("moduletest") { testonly = true - deps = [ ":js_code_emitter_interface" ] + deps = [ ":js_code_emitter_no_license_test" ] } diff --git a/idl/test/ts/moduletest/js_code_emitter_no_license_test/js_code_emitter_no_license_test.cpp b/idl/test/ts/moduletest/js_code_emitter_no_license_test/js_code_emitter_no_license_test.cpp new file mode 100644 index 0000000000..4c211f9e3a --- /dev/null +++ b/idl/test/ts/moduletest/js_code_emitter_no_license_test/js_code_emitter_no_license_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2021 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 +#include "idl_common.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl::TestCommon; + +namespace OHOS { +namespace Idl { +namespace ModuleTest { +class JsCodeEmitterTest : public testing::Test, public IdlCommon { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void JsCodeEmitterTest::SetUpTestCase() +{} + +void JsCodeEmitterTest::TearDownTestCase() +{} + +void JsCodeEmitterTest::SetUp() +{} + +void JsCodeEmitterTest::TearDown() +{} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_VOID_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_BOOL_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_INT_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_STRING_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_INTERFACE_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_006, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_IN_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_007, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_OUT_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_008, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_ONEWAY_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_009, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_SEQUENCEABLE_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +/* + * Feature: zidl + * Function: Ready + * SubFunction: NA + * FunctionPoints: no license test + * EnvConditions: NA + * CaseDescription: char type exists in .zidl(value type). + */ +HWTEST_F(JsCodeEmitterTest, Ready_010, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(NO_LICENSE_ZIDL_NAME.c_str(), NO_LICENSE_MAP_TYPE_ZIDL_CONTENT.c_str(), ""), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", NO_LICENSE_ZIDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); +} + +} // namespace ModuleTest +} // namespace Idl +} // namespace OHOS diff --git a/idl/test/ts/moduletest/js_code_emitter_test/BUILD.gn b/idl/test/ts/moduletest/js_code_emitter_test/BUILD.gn new file mode 100644 index 0000000000..9d8f385dc4 --- /dev/null +++ b/idl/test/ts/moduletest/js_code_emitter_test/BUILD.gn @@ -0,0 +1,92 @@ +# Copyright (c) 2022 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. + +import("//build/test.gni") + +IDL_DIR = "../../../.." + +config("idl_module_test_config") { + include_dirs = [ + "../../common", + "${IDL_DIR}/", + "//utils/native/base/include/", + ] +} + +common_sources = [ + "${IDL_DIR}/ast/ast_array_type.cpp", + "${IDL_DIR}/ast/ast_boolean_type.cpp", + "${IDL_DIR}/ast/ast_byte_type.cpp", + "${IDL_DIR}/ast/ast_char_type.cpp", + "${IDL_DIR}/ast/ast_double_type.cpp", + "${IDL_DIR}/ast/ast_float_type.cpp", + "${IDL_DIR}/ast/ast_integer_type.cpp", + "${IDL_DIR}/ast/ast_interface_type.cpp", + "${IDL_DIR}/ast/ast_list_type.cpp", + "${IDL_DIR}/ast/ast_long_type.cpp", + "${IDL_DIR}/ast/ast_map_type.cpp", + "${IDL_DIR}/ast/ast_method.cpp", + "${IDL_DIR}/ast/ast_module.cpp", + "${IDL_DIR}/ast/ast_namespace.cpp", + "${IDL_DIR}/ast/ast_node.cpp", + "${IDL_DIR}/ast/ast_parameter.cpp", + "${IDL_DIR}/ast/ast_sequenceable_type.cpp", + "${IDL_DIR}/ast/ast_short_type.cpp", + "${IDL_DIR}/ast/ast_string_type.cpp", + "${IDL_DIR}/ast/ast_type.cpp", + "${IDL_DIR}/ast/ast_void_type.cpp", +] + +common_sources += [ + "${IDL_DIR}/codegen/code_emitter.cpp", + "${IDL_DIR}/codegen/code_generator.cpp", + "${IDL_DIR}/codegen/cpp_code_emitter.cpp", + "${IDL_DIR}/codegen/java_code_emitter.cpp", + "${IDL_DIR}/codegen/js_code_emitter.cpp", +] + +common_sources += [ + "${IDL_DIR}/metadata/metadata_builder.cpp", + "${IDL_DIR}/metadata/metadata_dumper.cpp", + "${IDL_DIR}/metadata/metadata_reader.cpp", + "${IDL_DIR}/metadata/metadata_serializer.cpp", +] + +common_sources += [ + "${IDL_DIR}/parser/lexer.cpp", + "${IDL_DIR}/parser/parser.cpp", +] + +common_sources += [ + "${IDL_DIR}/util/file.cpp", + "${IDL_DIR}/util/light_refcount_base.cpp", + "${IDL_DIR}/util/logger.cpp", + "${IDL_DIR}/util/options.cpp", + "${IDL_DIR}/util/string.cpp", + "${IDL_DIR}/util/string_builder.cpp", + "${IDL_DIR}/util/string_pool.cpp", +] +module_output_path = "idl/ts_moduletest" + +ohos_moduletest("js_code_emitter_test") { + module_out_path = module_output_path + configs = [ ":idl_module_test_config" ] + sources = [ "js_code_emitter_test.cpp" ] + sources += common_sources + deps = [ "//utils/native/base:utilsecurec" ] +} + +group("moduletest") { + testonly = true + deps = [ ":js_code_emitter_test" ] +} diff --git a/zidl/test/ts/moduletest/js_code_emitter_proxy_test/js_code_emitter_proxy_test.cpp b/idl/test/ts/moduletest/js_code_emitter_test/js_code_emitter_test.cpp similarity index 58% rename from zidl/test/ts/moduletest/js_code_emitter_proxy_test/js_code_emitter_proxy_test.cpp rename to idl/test/ts/moduletest/js_code_emitter_test/js_code_emitter_test.cpp index 67e3509e33..1fd436d0b5 100644 --- a/zidl/test/ts/moduletest/js_code_emitter_proxy_test/js_code_emitter_proxy_test.cpp +++ b/idl/test/ts/moduletest/js_code_emitter_test/js_code_emitter_test.cpp @@ -1,60 +1,65 @@ -/* - * Copyright (c) 2022 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 -#include "zidl_common.h" - -using namespace testing::ext; -namespace OHOS { -namespace Zidl { -namespace ModuleTest { -class JsCodeEmitterProxyTest : public testing::Test, public ZidlCommon { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void JsCodeEmitterProxyTest::SetUpTestCase(void) -{} -void JsCodeEmitterProxyTest::TearDownTestCase(void) -{} -void JsCodeEmitterProxyTest::SetUp() -{} -void JsCodeEmitterProxyTest::TearDown() -{} - -/* - * Feature: zidl - * Function: CheckInterfaceType - * SubFunction: NA - * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool - * EnvConditions: NA - * CaseDescription: char type exists in .zidl(value type). - */ -HWTEST_F(JsCodeEmitterProxyTest, CheckInterfaceType_001, TestSize.Level1) -{ - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE1_ZIDL_CONTENT.c_str()), ERR_OK); - int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; - char** argv = (char**)argvArray; - EXPECT_EQ(Ready(argc, argv), ERR_OK); - EXPECT_NE(jsCodeGen_, nullptr); - EXPECT_FALSE(jsCodeGen_->CheckInterfaceType()); -} -} -} -} +/* + * Copyright (c) 2022 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 +#include "idl_common.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl::TestCommon; + +namespace OHOS { +namespace Idl { +namespace ModuleTest { +class JsCodeEmitterTest : public testing::Test, public IdlCommon { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void JsCodeEmitterTest::SetUpTestCase() +{} + +void JsCodeEmitterTest::TearDownTestCase() +{} + +void JsCodeEmitterTest::SetUp() +{} + +void JsCodeEmitterTest::TearDown() +{} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: char type exists in .idl(value type). + */ +HWTEST_F(JsCodeEmitterTest, CheckInterfaceType_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE1_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + EXPECT_FALSE(jsCodeGen_->CheckInterfaceType()); +} +} // namespace ModuleTest +} // namespace Idl +} // namespace OHOS diff --git a/zidl/test/ts/moduletest/BUILD.gn b/idl/test/ts/unittest/BUILD.gn similarity index 81% rename from zidl/test/ts/moduletest/BUILD.gn rename to idl/test/ts/unittest/BUILD.gn index 5ee2a95d6f..2c75fa2cc3 100644 --- a/zidl/test/ts/moduletest/BUILD.gn +++ b/idl/test/ts/unittest/BUILD.gn @@ -12,11 +12,12 @@ # limitations under the License. import("//build/ohos.gni") -group("moduletest") { +group("unittest") { testonly = true deps = [ - "js_code_emitter_proxy_test:moduletest", - "js_coe_emitter_interface_test:moduletest", + "js_code_emitter_interface_test:unittest", + "js_code_emitter_proxy_test:unittest", + "js_code_emitter_stub_test:unittest", ] } diff --git a/idl/test/ts/unittest/js_code_emitter_interface_test/BUILD.gn b/idl/test/ts/unittest/js_code_emitter_interface_test/BUILD.gn new file mode 100644 index 0000000000..927e256fdc --- /dev/null +++ b/idl/test/ts/unittest/js_code_emitter_interface_test/BUILD.gn @@ -0,0 +1,92 @@ +# Copyright (c) 2022 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. + +import("//build/test.gni") + +IDL_DIR = "../../../.." + +config("idl_unittest_test_config") { + include_dirs = [ + "../../common/", + "${IDL_DIR}/", + "//utils/native/base/include/", + ] +} + +common_sources = [ + "${IDL_DIR}/ast/ast_array_type.cpp", + "${IDL_DIR}/ast/ast_boolean_type.cpp", + "${IDL_DIR}/ast/ast_byte_type.cpp", + "${IDL_DIR}/ast/ast_char_type.cpp", + "${IDL_DIR}/ast/ast_double_type.cpp", + "${IDL_DIR}/ast/ast_float_type.cpp", + "${IDL_DIR}/ast/ast_integer_type.cpp", + "${IDL_DIR}/ast/ast_interface_type.cpp", + "${IDL_DIR}/ast/ast_list_type.cpp", + "${IDL_DIR}/ast/ast_long_type.cpp", + "${IDL_DIR}/ast/ast_map_type.cpp", + "${IDL_DIR}/ast/ast_method.cpp", + "${IDL_DIR}/ast/ast_module.cpp", + "${IDL_DIR}/ast/ast_namespace.cpp", + "${IDL_DIR}/ast/ast_node.cpp", + "${IDL_DIR}/ast/ast_parameter.cpp", + "${IDL_DIR}/ast/ast_sequenceable_type.cpp", + "${IDL_DIR}/ast/ast_short_type.cpp", + "${IDL_DIR}/ast/ast_string_type.cpp", + "${IDL_DIR}/ast/ast_type.cpp", + "${IDL_DIR}/ast/ast_void_type.cpp", +] + +common_sources += [ + "${IDL_DIR}/codegen/code_emitter.cpp", + "${IDL_DIR}/codegen/code_generator.cpp", + "${IDL_DIR}/codegen/cpp_code_emitter.cpp", + "${IDL_DIR}/codegen/java_code_emitter.cpp", + "${IDL_DIR}/codegen/js_code_emitter.cpp", +] + +common_sources += [ + "${IDL_DIR}/metadata/metadata_builder.cpp", + "${IDL_DIR}/metadata/metadata_dumper.cpp", + "${IDL_DIR}/metadata/metadata_reader.cpp", + "${IDL_DIR}/metadata/metadata_serializer.cpp", +] + +common_sources += [ + "${IDL_DIR}/parser/lexer.cpp", + "${IDL_DIR}/parser/parser.cpp", +] + +common_sources += [ + "${IDL_DIR}/util/file.cpp", + "${IDL_DIR}/util/light_refcount_base.cpp", + "${IDL_DIR}/util/logger.cpp", + "${IDL_DIR}/util/options.cpp", + "${IDL_DIR}/util/string.cpp", + "${IDL_DIR}/util/string_builder.cpp", + "${IDL_DIR}/util/string_pool.cpp", +] +module_output_path = "idl/ts_unittest" + +ohos_unittest("js_code_emitter_interface_test") { + module_out_path = module_output_path + configs = [ ":idl_unittest_test_config" ] + sources = [ "js_code_emitter_interface_test.cpp" ] + sources += common_sources + deps = [ "//utils/native/base:utilsecurec" ] +} + +group("unittest") { + testonly = true + deps = [ ":js_code_emitter_interface_test" ] +} diff --git a/zidl/test/ts/moduletest/js_coe_emitter_interface_test/js_code_emitter_interface.cpp b/idl/test/ts/unittest/js_code_emitter_interface_test/js_code_emitter_interface_test.cpp similarity index 53% rename from zidl/test/ts/moduletest/js_coe_emitter_interface_test/js_code_emitter_interface.cpp rename to idl/test/ts/unittest/js_code_emitter_interface_test/js_code_emitter_interface_test.cpp index 711adc235f..b3d6e09c4e 100644 --- a/zidl/test/ts/moduletest/js_coe_emitter_interface_test/js_code_emitter_interface.cpp +++ b/idl/test/ts/unittest/js_code_emitter_interface_test/js_code_emitter_interface_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -13,15 +13,16 @@ * limitations under the License. */ #include -#include "zidl_common.h" +#include "idl_common.h" using namespace testing; using namespace testing::ext; +using namespace OHOS::Idl::TestCommon; namespace OHOS { -namespace Zidl { -namespace ModuleTest { -class JsCodeEmitterInterface : public testing::Test, public ZidlCommon { +namespace Idl { +namespace UnitTest { +class JsCodeEmitterInterfaceTest : public testing::Test, public IdlCommon { public: static void SetUpTestCase(); static void TearDownTestCase(); @@ -29,31 +30,31 @@ public: void TearDown(); }; -void JsCodeEmitterInterface::SetUpTestCase() +void JsCodeEmitterInterfaceTest::SetUpTestCase() {} -void JsCodeEmitterInterface::TearDownTestCase() +void JsCodeEmitterInterfaceTest::TearDownTestCase() {} -void JsCodeEmitterInterface::SetUp() +void JsCodeEmitterInterfaceTest::SetUp() {} -void JsCodeEmitterInterface::TearDown() +void JsCodeEmitterInterfaceTest::TearDown() {} /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: char type exists in .zidl(value type). + * CaseDescription: char type exists in .idl(value type). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_001, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_001, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE1_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE1_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -61,18 +62,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_001, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: list type exists in .zidl(value type). + * CaseDescription: list type exists in .idl(value type). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_002, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_002, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE2_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE2_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -80,18 +81,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_002, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: char type exists in .zidl(Map). + * CaseDescription: char type exists in .idl(Map). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_003, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_003, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE3_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE3_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -99,18 +100,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_003, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: list type exists in .zidl(Map>). + * CaseDescription: list type exists in .idl(Map>). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_004, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_004, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE4_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE4_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -118,18 +119,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_004, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: char type exists in .zidl(return value). + * CaseDescription: char type exists in .idl(return value). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_005, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_005, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE5_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE5_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -137,18 +138,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_005, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: list type exists in .zidl(return value). + * CaseDescription: list type exists in .idl(return value). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_006, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_006, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE6_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE6_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -156,18 +157,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_006, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: char type exists in .zidl(return Map). + * CaseDescription: char type exists in .idl(return Map). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_007, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_007, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE7_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE7_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -175,18 +176,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_007, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: char type exists in .zidl(return Map>). + * CaseDescription: char type exists in .idl(return Map>). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_008, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_008, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), UNKNOW_TYPE_CASE8_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE8_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -194,18 +195,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_008, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: CheckInterfaceType * SubFunction: NA * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool * EnvConditions: NA - * CaseDescription: normal type exists in .zidl(int). + * CaseDescription: normal type exists in .idl(int). */ -HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_009, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, CheckInterfaceType_009, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), NORMAL_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -213,18 +214,18 @@ HWTEST_F(JsCodeEmitterInterface, CheckInterfaceType_009, TestSize.Level1) } /* - * Feature: zidl + * Feature: idl * Function: EmitInterfaceImports * SubFunction: NA * FunctionPoints: For generating impotr code. * EnvConditions: NA * CaseDescription: The string in EmitInterfaceImports is not empty. */ -HWTEST_F(JsCodeEmitterInterface, EmitInterfaceImports_001, TestSize.Level1) +HWTEST_F(JsCodeEmitterInterfaceTest, EmitInterfaceImports_001, TestSize.Level1) { - EXPECT_EQ(PrepareZidlFile(UNKNOW_TYPE_ZIDL_NAME.c_str(), NORMAL_TYPE_ZIDL_CONTENT.c_str()), ERR_OK); + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IDL_CONTENT.c_str()), ERR_OK); int argc = 6; - const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_ZIDL_NAME.c_str(), "-gen-js", "-d", "."}; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; char** argv = (char**)argvArray; EXPECT_EQ(Ready(argc, argv), ERR_OK); EXPECT_NE(jsCodeGen_, nullptr); @@ -232,6 +233,9 @@ HWTEST_F(JsCodeEmitterInterface, EmitInterfaceImports_001, TestSize.Level1) jsCodeGen_->EmitInterfaceImports(stringBuilder); EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); } -} // namespace ModuleTest -} // namespace Zidl + + + +} // namespace UnitTest +} // namespace Idl } // namespace OHOS diff --git a/idl/test/ts/unittest/js_code_emitter_proxy_test/BUILD.gn b/idl/test/ts/unittest/js_code_emitter_proxy_test/BUILD.gn new file mode 100644 index 0000000000..c8d68dbed0 --- /dev/null +++ b/idl/test/ts/unittest/js_code_emitter_proxy_test/BUILD.gn @@ -0,0 +1,101 @@ +# Copyright (c) 2022 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. + +import("//build/test.gni") + +IDL_DIR = "../../../.." + +config("idl_unittest_test_config") { + include_dirs = [ + "../../common", + "${IDL_DIR}/", + "${IDL_DIR}/codegen/", + "//utils/native/base/include/", + ] +} + +idl_common_sources = [ + "${IDL_DIR}/ast/ast_array_type.cpp", + "${IDL_DIR}/ast/ast_boolean_type.cpp", + "${IDL_DIR}/ast/ast_byte_type.cpp", + "${IDL_DIR}/ast/ast_char_type.cpp", + "${IDL_DIR}/ast/ast_double_type.cpp", + "${IDL_DIR}/ast/ast_float_type.cpp", + "${IDL_DIR}/ast/ast_integer_type.cpp", + "${IDL_DIR}/ast/ast_interface_type.cpp", + "${IDL_DIR}/ast/ast_list_type.cpp", + "${IDL_DIR}/ast/ast_long_type.cpp", + "${IDL_DIR}/ast/ast_map_type.cpp", + "${IDL_DIR}/ast/ast_method.cpp", + "${IDL_DIR}/ast/ast_module.cpp", + "${IDL_DIR}/ast/ast_namespace.cpp", + "${IDL_DIR}/ast/ast_node.cpp", + "${IDL_DIR}/ast/ast_parameter.cpp", + "${IDL_DIR}/ast/ast_sequenceable_type.cpp", + "${IDL_DIR}/ast/ast_short_type.cpp", + "${IDL_DIR}/ast/ast_string_type.cpp", + "${IDL_DIR}/ast/ast_type.cpp", + "${IDL_DIR}/ast/ast_void_type.cpp", +] + +idl_common_sources += [ + "${IDL_DIR}/codegen/code_emitter.cpp", + "${IDL_DIR}/codegen/code_generator.cpp", + "${IDL_DIR}/codegen/cpp_code_emitter.cpp", + "${IDL_DIR}/codegen/java_code_emitter.cpp", + "${IDL_DIR}/codegen/js_code_emitter.cpp", +] + +idl_common_sources += [ + "${IDL_DIR}/metadata/metadata_builder.cpp", + "${IDL_DIR}/metadata/metadata_dumper.cpp", + "${IDL_DIR}/metadata/metadata_reader.cpp", + "${IDL_DIR}/metadata/metadata_serializer.cpp", +] + +idl_common_sources += [ + "${IDL_DIR}/parser/lexer.cpp", + "${IDL_DIR}/parser/parser.cpp", +] + +idl_common_sources += [ + "${IDL_DIR}/util/file.cpp", + "${IDL_DIR}/util/light_refcount_base.cpp", + "${IDL_DIR}/util/logger.cpp", + "${IDL_DIR}/util/options.cpp", + "${IDL_DIR}/util/string.cpp", + "${IDL_DIR}/util/string_builder.cpp", + "${IDL_DIR}/util/string_pool.cpp", +] + +module_output_path = "idl/ts_unittest" +ohos_unittest("js_code_emitter_proxy_test") { + + module_out_path = module_output_path + + configs = [ ":idl_unittest_test_config" ] + + sources = [ "js_code_emitter_proxy_test.cpp" ] + sources += idl_common_sources + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + "//utils/native/base:utilsecurec" + ] +} + +group("unittest") { + testonly = true + deps = [ ":js_code_emitter_proxy_test" ] +} diff --git a/idl/test/ts/unittest/js_code_emitter_proxy_test/js_code_emitter_proxy_test.cpp b/idl/test/ts/unittest/js_code_emitter_proxy_test/js_code_emitter_proxy_test.cpp new file mode 100644 index 0000000000..c029838f6b --- /dev/null +++ b/idl/test/ts/unittest/js_code_emitter_proxy_test/js_code_emitter_proxy_test.cpp @@ -0,0 +1,1146 @@ +/* + * Copyright (c) 2022 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 +#include "idl_common.h" +#include + +using namespace testing::ext; +using namespace OHOS::Idl::TestCommon; +namespace OHOS { +namespace Idl { +namespace UnitTest { +class JsCodeEmitterProxyTest : public testing::Test, public IdlCommon { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void JsCodeEmitterProxyTest::SetUpTestCase(void) +{} +void JsCodeEmitterProxyTest::TearDownTestCase(void) +{} +void JsCodeEmitterProxyTest::SetUp() +{} +void JsCodeEmitterProxyTest::TearDown() +{} + +/* + * Feature: idl + * Function: EmitWriteArrayVariable + * SubFunction: NA + * FunctionPoints: EmitWriteArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteArrayVariable_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_IN) != 0) { + MetaType* innerType = jsCodeGen_->metaComponent_->types_[mt->nestedTypeIndexes_[0]]; + jsCodeGen_->EmitWriteArrayVariable("data", mp->name_, innerType, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeBooleanArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("Int8Array"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeShortArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeIntArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeLongArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeFloatArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeDoubleArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeStringArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeSequenceableArray"), ERR_FAIL); + EXPECT_TRUE(stringBuilder.ToString().IsEmpty()); +} + +/* + * Feature: idl + * Function: EmitWriteArrayVariable + * SubFunction: NA + * FunctionPoints: EmitWriteArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteArrayVariable_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_IN) != 0) { + MetaType* innerType = jsCodeGen_->metaComponent_->types_[mt->nestedTypeIndexes_[0]]; + jsCodeGen_->EmitWriteArrayVariable("data", mp->name_, innerType, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeBooleanArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("Int8Array"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeShortArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeIntArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeLongArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeFloatArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeDoubleArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeStringArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeSequenceableArray"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitWriteArrayVariable + * SubFunction: NA + * FunctionPoints: EmitWriteArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteArrayVariable_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), + NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_IN) != 0) { + MetaType* innerType = jsCodeGen_->metaComponent_->types_[mt->nestedTypeIndexes_[0]]; + jsCodeGen_->EmitWriteArrayVariable("data", mp->name_, innerType, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeBooleanArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("Int8Array"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeShortArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeIntArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeLongArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeFloatArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeDoubleArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeStringArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeSequenceableArray"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitWriteArrayVariable + * SubFunction: NA + * FunctionPoints: EmitWriteArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteArrayVariable_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), + NORMAL_TYPE_RETURN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_IN) != 0) { + MetaType* innerType = jsCodeGen_->metaComponent_->types_[mt->nestedTypeIndexes_[0]]; + jsCodeGen_->EmitWriteArrayVariable("data", mp->name_, innerType, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeBooleanArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("Int8Array"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeShortArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeIntArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeLongArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeFloatArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeDoubleArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeStringArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("writeSequenceableArray"), ERR_FAIL); + EXPECT_TRUE(stringBuilder.ToString().IsEmpty()); +} + +/* + * Feature: idl + * Function: EmitWriteArrayVariable + * SubFunction: NA + * FunctionPoints: EmitWriteArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteArrayVariable_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), + NORMAL_TYPE_COMBINATION_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + int count = 0; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_IN) != 0) { + count++; + MetaType* innerType = jsCodeGen_->metaComponent_->types_[mt->nestedTypeIndexes_[0]]; + jsCodeGen_->EmitWriteArrayVariable("data", mp->name_, innerType, + stringBuilder, CodeEmitter::TAB); + } + } + } + const int size = 18; + EXPECT_TRUE(count == size); + EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeBooleanArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("Int8Array"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeShortArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeIntArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeLongArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeFloatArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeDoubleArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeStringArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("writeSequenceableArray"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutArrayVariable + * SubFunction: NA + * FunctionPoints: EmitReadOutArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutArrayVariable_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_MASK) == ATTR_OUT) { + jsCodeGen_->EmitReadOutArrayVariable("data", mp->name_, mt, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); + EXPECT_NE(stringBuilder.ToString().IndexOf("readBooleanArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readByteArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readShortArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readIntArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readLongArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readFloatArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readDoubleArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readStringArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readSequenceableArray"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutArrayVariable + * SubFunction: NA + * FunctionPoints: EmitReadOutArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutArrayVariable_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_MASK) == ATTR_OUT) { + jsCodeGen_->EmitReadOutArrayVariable("data", mp->name_, mt, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_EQ(stringBuilder.ToString().IndexOf("readBooleanArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readByteArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readShortArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readIntArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readLongArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readFloatArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readDoubleArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readStringArray"), ERR_FAIL); + EXPECT_EQ(stringBuilder.ToString().IndexOf("readSequenceableArray"), ERR_FAIL); + EXPECT_TRUE(stringBuilder.ToString().IsEmpty()); +} + +/* + * Feature: idl + * Function: EmitReadOutArrayVariable + * SubFunction: NA + * FunctionPoints: EmitReadOutArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutArrayVariable_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), + NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_MASK) == ATTR_OUT) { + jsCodeGen_->EmitReadOutArrayVariable("data", mp->name_, mt, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); + EXPECT_NE(stringBuilder.ToString().IndexOf("readBooleanArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readByteArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readShortArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readIntArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readLongArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readFloatArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readDoubleArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readStringArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readSequenceableArray"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutArrayVariable + * SubFunction: NA + * FunctionPoints: EmitReadOutArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutArrayVariable_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), + NORMAL_TYPE_RETURN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_MASK) == ATTR_OUT) { + jsCodeGen_->EmitReadOutArrayVariable("data", mp->name_, mt, + stringBuilder, CodeEmitter::TAB); + } + } + } + EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); + EXPECT_NE(stringBuilder.ToString().IndexOf("readBooleanArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readByteArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readShortArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readIntArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readLongArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readFloatArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readDoubleArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readStringArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readSequenceableArray"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutArrayVariable + * SubFunction: NA + * FunctionPoints: EmitReadOutArrayVariable validates the array type + * EnvConditions: NA + * CaseDescription: Array type keyword generated successfully. + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutArrayVariable_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), + NORMAL_TYPE_COMBINATION_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + int count = 0; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int j = 0; j < metaMethod->parameterNumber_; j++) { + MetaParameter* mp = metaMethod->parameters_[j]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if (mt->kind_ == TypeKind::Array && (mp->attributes_ & ATTR_MASK) == ATTR_OUT) { + count++; + jsCodeGen_->EmitReadOutArrayVariable("data", mp->name_, mt, + stringBuilder, CodeEmitter::TAB); + } + } + } + const int size = 18; + EXPECT_TRUE(count == size); + EXPECT_FALSE(stringBuilder.ToString().IsEmpty()); + EXPECT_NE(stringBuilder.ToString().IndexOf("readBooleanArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readByteArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readShortArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readIntArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readLongArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readFloatArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readDoubleArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readStringArray"), ERR_FAIL); + EXPECT_NE(stringBuilder.ToString().IndexOf("readSequenceableArray"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitWriteMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteMethodParameter_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitWriteMethodParameter(mp, "reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("writeInt"), ERR_FAIL); + EXPECT_NE(data.find("writeLong"), ERR_FAIL); + EXPECT_NE(data.find("writeFloat"), ERR_FAIL); + EXPECT_NE(data.find("writeDouble"), ERR_FAIL); + EXPECT_NE(data.find("writeString"), ERR_FAIL); + EXPECT_NE(data.find("writeSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("writeRemoteObject"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitWriteMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteMethodParameter_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitWriteMethodParameter(mp, "reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("writeInt"), ERR_FAIL); + EXPECT_NE(data.find("writeLong"), ERR_FAIL); + EXPECT_NE(data.find("writeFloat"), ERR_FAIL); + EXPECT_NE(data.find("writeDouble"), ERR_FAIL); + EXPECT_NE(data.find("writeString"), ERR_FAIL); + EXPECT_NE(data.find("writeSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("writeRemoteObject"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitWriteMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteMethodParameter_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitWriteMethodParameter(mp, "reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("writeInt"), ERR_FAIL); + EXPECT_NE(data.find("writeLong"), ERR_FAIL); + EXPECT_NE(data.find("writeFloat"), ERR_FAIL); + EXPECT_NE(data.find("writeDouble"), ERR_FAIL); + EXPECT_NE(data.find("writeString"), ERR_FAIL); + EXPECT_NE(data.find("writeSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("writeRemoteObject"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitWriteMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteMethodParameter_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_RETURN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitWriteMethodParameter(mp, "reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("writeInt"), ERR_FAIL); + EXPECT_NE(data.find("writeLong"), ERR_FAIL); + EXPECT_NE(data.find("writeFloat"), ERR_FAIL); + EXPECT_NE(data.find("writeDouble"), ERR_FAIL); + EXPECT_NE(data.find("writeString"), ERR_FAIL); + EXPECT_NE(data.find("writeSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("writeRemoteObject"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitWriteMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitWriteMethodParameter_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_COMBINATION_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitWriteMethodParameter(mp, "reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("writeInt"), ERR_FAIL); + EXPECT_NE(data.find("writeLong"), ERR_FAIL); + EXPECT_NE(data.find("writeFloat"), ERR_FAIL); + EXPECT_NE(data.find("writeDouble"), ERR_FAIL); + EXPECT_NE(data.find("writeString"), ERR_FAIL); + EXPECT_NE(data.find("writeSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("writeRemoteObject"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadMethodParameter_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadMethodParameter(mp, "result.reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadMethodParameter_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadMethodParameter(mp, "result.reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadMethodParameter_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadMethodParameter(mp, "result.reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadMethodParameter_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_RETURN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadMethodParameter(mp, "result.reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadMethodParameter + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadMethodParameter_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_COMBINATION_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadMethodParameter(mp, "result.reply", stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutVariable + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutVariable_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadOutVariable("result.reply", mp->name_, mt, stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutVariable + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutVariable_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadOutVariable("result.reply", mp->name_, mt, stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutVariable + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutVariable_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadOutVariable("result.reply", mp->name_, mt, stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutVariable + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutVariable_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_RETURN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadOutVariable("result.reply", mp->name_, mt, stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitReadOutVariable + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitReadOutVariable_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_COMBINATION_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + if ((mp->attributes_ & ATTR_OUT) != 0) { + jsCodeGen_->EmitReadOutVariable("result.reply", mp->name_, mt, stringBuilder, CodeEmitter::TAB); + } + } + } + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("readInt"), ERR_FAIL); + EXPECT_NE(data.find("readLong"), ERR_FAIL); + EXPECT_NE(data.find("readFloat"), ERR_FAIL); + EXPECT_NE(data.find("readDouble"), ERR_FAIL); + EXPECT_NE(data.find("readString"), ERR_FAIL); + EXPECT_NE(data.find("readSequenceable"), ERR_FAIL); + EXPECT_NE(data.find("readRemoteObject"), ERR_FAIL); + EXPECT_NE(data.find("new Map()"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitLicense + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitLicense_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + jsCodeGen_->EmitLicense(stringBuilder); + + std::string data(stringBuilder.ToString()); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("Ltd."), ERR_FAIL); +} + +/* + * Feature: idl + * Function: EmitLicense + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitLicense_002, TestSize.Level1) +{ + std::string fileLicense; + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str(), fileLicense), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + StringBuilder stringBuilder; + jsCodeGen_->EmitLicense(stringBuilder); + + std::string data(stringBuilder.ToString()); + EXPECT_TRUE(data.length()); +} + +/* + * Feature: idl + * Function: EmitType + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, EmitType_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + String result; + for (int index = 0; index < jsCodeGen_->metaInterface_->methodNumber_; index++) { + MetaMethod* metaMethod = jsCodeGen_->metaInterface_->methods_[index]; + for (int parameterIndex = 0; index < metaMethod->parameterNumber_; parameterIndex++) { + MetaParameter* mp = metaMethod->parameters_[parameterIndex]; + MetaType* mt = jsCodeGen_->metaComponent_->types_[mp->typeIndex_]; + result += jsCodeGen_->EmitType(mt); + result += "_"; + } + } + std::string data = result.string(); + EXPECT_FALSE(data.length()); + EXPECT_NE(data.find("void"), ERR_FAIL); + EXPECT_NE(data.find("number"), ERR_FAIL); + EXPECT_NE(data.find("string"), ERR_FAIL); + EXPECT_NE(data.find("MySequenceable"), ERR_FAIL); + EXPECT_NE(data.find("IInterfaceDeclare"), ERR_FAIL); + EXPECT_NE(data.find("Map"), ERR_FAIL); + EXPECT_NE(data.find("boolean[]"), ERR_FAIL); + EXPECT_NE(data.find("String[]"), ERR_FAIL); + EXPECT_NE(data.find("number[]"), ERR_FAIL); + EXPECT_NE(data.find("MySequenceable[]"), ERR_FAIL); +} + +/* + * Feature: idl + * Function: FileName + * SubFunction: NA + * FunctionPoints: + * EnvConditions: NA + * CaseDescription: + */ +HWTEST_F(JsCodeEmitterProxyTest, FileName_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./zidl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-js", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + String param1; + EXPECT_TRUE(jsCodeGen_->FileName(param1).Equals(param1)); + String param2("testFileName"); + EXPECT_TRUE(jsCodeGen_->FileName(param1).Equals("test_file_name")); + String param3("app.data.testFileName"); + EXPECT_TRUE(jsCodeGen_->FileName(param1).Equals("app/data/test_file_name")); + String param4("testfile"); + EXPECT_TRUE(jsCodeGen_->FileName(param1).Equals("testfile")); +} +} +} +} diff --git a/idl/test/ts/unittest/js_code_emitter_stub_test/BUILD.gn b/idl/test/ts/unittest/js_code_emitter_stub_test/BUILD.gn new file mode 100644 index 0000000000..0919c3bd6a --- /dev/null +++ b/idl/test/ts/unittest/js_code_emitter_stub_test/BUILD.gn @@ -0,0 +1,92 @@ +# Copyright (c) 2022 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. + +import("//build/test.gni") + +IDL_DIR = "../../../.." + +config("idl_unittest_test_config") { + include_dirs = [ + "../../common", + "${IDL_DIR}/", + "//utils/native/base/include/", + ] +} + +common_sources = [ + "${IDL_DIR}/ast/ast_array_type.cpp", + "${IDL_DIR}/ast/ast_boolean_type.cpp", + "${IDL_DIR}/ast/ast_byte_type.cpp", + "${IDL_DIR}/ast/ast_char_type.cpp", + "${IDL_DIR}/ast/ast_double_type.cpp", + "${IDL_DIR}/ast/ast_float_type.cpp", + "${IDL_DIR}/ast/ast_integer_type.cpp", + "${IDL_DIR}/ast/ast_interface_type.cpp", + "${IDL_DIR}/ast/ast_list_type.cpp", + "${IDL_DIR}/ast/ast_long_type.cpp", + "${IDL_DIR}/ast/ast_map_type.cpp", + "${IDL_DIR}/ast/ast_method.cpp", + "${IDL_DIR}/ast/ast_module.cpp", + "${IDL_DIR}/ast/ast_namespace.cpp", + "${IDL_DIR}/ast/ast_node.cpp", + "${IDL_DIR}/ast/ast_parameter.cpp", + "${IDL_DIR}/ast/ast_sequenceable_type.cpp", + "${IDL_DIR}/ast/ast_short_type.cpp", + "${IDL_DIR}/ast/ast_string_type.cpp", + "${IDL_DIR}/ast/ast_type.cpp", + "${IDL_DIR}/ast/ast_void_type.cpp", +] + +common_sources += [ + "${IDL_DIR}/codegen/code_emitter.cpp", + "${IDL_DIR}/codegen/code_generator.cpp", + "${IDL_DIR}/codegen/cpp_code_emitter.cpp", + "${IDL_DIR}/codegen/java_code_emitter.cpp", + "${IDL_DIR}/codegen/js_code_emitter.cpp", +] + +common_sources += [ + "${IDL_DIR}/metadata/metadata_builder.cpp", + "${IDL_DIR}/metadata/metadata_dumper.cpp", + "${IDL_DIR}/metadata/metadata_reader.cpp", + "${IDL_DIR}/metadata/metadata_serializer.cpp", +] + +common_sources += [ + "${IDL_DIR}/parser/lexer.cpp", + "${IDL_DIR}/parser/parser.cpp", +] + +common_sources += [ + "${IDL_DIR}/util/file.cpp", + "${IDL_DIR}/util/light_refcount_base.cpp", + "${IDL_DIR}/util/logger.cpp", + "${IDL_DIR}/util/options.cpp", + "${IDL_DIR}/util/string.cpp", + "${IDL_DIR}/util/string_builder.cpp", + "${IDL_DIR}/util/string_pool.cpp", +] +module_output_path = "idl/ts_unittest" + +ohos_unittest("js_code_emitter_stub_test") { + module_out_path = module_output_path + configs = [ ":idl_unittest_test_config" ] + sources = [ "js_code_emitter_stub_test.cpp" ] + sources += common_sources + deps = [ "//utils/native/base:utilsecurec" ] +} + +group("unittest") { + testonly = true + deps = [ ":js_code_emitter_stub_test" ] +} diff --git a/idl/test/ts/unittest/js_code_emitter_stub_test/js_code_emitter_stub_test.cpp b/idl/test/ts/unittest/js_code_emitter_stub_test/js_code_emitter_stub_test.cpp new file mode 100644 index 0000000000..1ad979e705 --- /dev/null +++ b/idl/test/ts/unittest/js_code_emitter_stub_test/js_code_emitter_stub_test.cpp @@ -0,0 +1,443 @@ +/* + * Copyright (c) 2022 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 + +#define private public +#define protected public +#include "idl_common.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl::TestCommon; + +namespace OHOS { +namespace Idl { +namespace UnitTest { +class JsCodeEmitterStubTest : public testing::Test, public IdlCommon { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void JsCodeEmitterStubTest::SetUpTestCase() +{} + +void JsCodeEmitterStubTest::TearDownTestCase() +{} + +void JsCodeEmitterStubTest::SetUp() +{} + +void JsCodeEmitterStubTest::TearDown() +{} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: char type exists in .idl(value type). + */ +HWTEST_F(JsCodeEmitterStubTest, CheckInterfaceType_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), UNKNOW_TYPE_CASE1_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + EXPECT_FALSE(jsCodeGen_->CheckInterfaceType()); +} + +#if 0 // baof 没有编译 + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: inout type exists in .idl(value type). + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpls_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + StringBuilder sb; + std::string str("onRemoteRequest(code: number, data, reply, option): boolean"); + + //const char* CodeEmitter::TAB = " "; + jsCodeGen_->EmitInterfaceStubMethodImpls(sb, TAB); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: inout type exists in .idl(value type). + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpls_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + StringBuilder sb; + std::string str("onRemoteRequest(code: number, data, reply, option): boolean"); + + //const char* CodeEmitter::TAB = " "; + jsCodeGen_->EmitInterfaceStubMethodImpls(sb, TAB); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: inout type exists in .idl(value type). + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpls_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + StringBuilder sb; + std::string str("onRemoteRequest(code: number, data, reply, option): boolean"); + + //const char* CodeEmitter::TAB = " "; + jsCodeGen_->EmitInterfaceStubMethodImpls(sb, TAB); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: inout type exists in .idl(value type). + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpls_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + StringBuilder sb; + std::string str("onRemoteRequest(code: number, data, reply, option): boolean"); + + //const char* CodeEmitter::TAB = " "; + jsCodeGen_->EmitInterfaceStubMethodImpls(sb, TAB); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: inout type exists in .idl(value type). + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpls_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + StringBuilder sb; + std::string str("onRemoteRequest(code: number, data, reply, option): boolean"); + + //const char* CodeEmitter::TAB = " "; + jsCodeGen_->EmitInterfaceStubMethodImpls(sb, TAB); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Interface stub method implementation + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpl_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + jsCodeGen_->EmitInterfaceStubMethodImpl(); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Interface stub method implementation + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpl_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + jsCodeGen_->EmitInterfaceStubMethodImpl(); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Interface stub method implementation + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpl_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + jsCodeGen_->EmitInterfaceStubMethodImpl(); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Interface stub method implementation + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpl_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + jsCodeGen_->EmitInterfaceStubMethodImpl(); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Interface stub method implementation + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceStubMethodImpl_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + jsCodeGen_->EmitInterfaceStubMethodImpl(); + EXPECT_FALSE(sb.ToString().find(str) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Issue interface method commands + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceMethodCommands_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + std::string keywords("readonly"); + StringBuilder sb; + jsCodeGen_->EmitInterfaceMethodCommands(sb); + EXPECT_FALSE(sb.ToString().find(keywords) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Issue interface method commands + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceMethodCommands_002, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + std::string keywords("readonly"); + StringBuilder sb; + jsCodeGen_->EmitInterfaceMethodCommands(sb); + EXPECT_FALSE(sb.ToString().find(keywords) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Issue interface method commands + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceMethodCommands_003, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + std::string keywords("readonly"); + StringBuilder sb; + jsCodeGen_->EmitInterfaceMethodCommands(sb); + EXPECT_FALSE(sb.ToString().find(keywords) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Issue interface method commands + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceMethodCommands_004, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + std::string keywords("readonly"); + StringBuilder sb; + jsCodeGen_->EmitInterfaceMethodCommands(sb); + EXPECT_FALSE(sb.ToString().find(keywords) == std::string::npos); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: Issue interface method commands + */ +HWTEST_F(JsCodeEmitterStubTest, EmitInterfaceMethodCommands_005, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + auto num = jsCodeGen_->metaInterface_->methodNumber_; + std::string keywords("readonly"); + StringBuilder sb; + jsCodeGen_->EmitInterfaceMethodCommands(sb); + EXPECT_FALSE(std::count(sb.ToString().begin(), sb.ToString().end(), keywords) == num); +} + +/* + * Feature: idl + * Function: CheckInterfaceType + * SubFunction: NA + * FunctionPoints: Check whether the interface return value type and parameter type are supported by the tool + * EnvConditions: NA + * CaseDescription: emit stub write method parameter + */ +HWTEST_F(JsCodeEmitterStubTest, EmitStubWriteMethodParameter_001, TestSize.Level1) +{ + EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT.c_str()), ERR_OK); + int argc = 6; + const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."}; + char** argv = (char**)argvArray; + EXPECT_EQ(Ready(argc, argv), ERR_OK); + EXPECT_NE(jsCodeGen_, nullptr); + + std::string keywords("readonly"); + int num = jsCodeGen_-> + StringBuilder sb; + jsCodeGen_->EmitStubWriteMethodParameter(sb); + EXPECT_FALSE(sb.ToString().find(keywords) == std::string::npos); +} +#endif +} // namespace UnitTest +} // namespace Idl +} // namespace OHOS diff --git a/zidl/util/autoptr.h b/idl/util/autoptr.h similarity index 98% rename from zidl/util/autoptr.h rename to idl/util/autoptr.h index 3574bf9f86..a776072347 100644 --- a/zidl/util/autoptr.h +++ b/idl/util/autoptr.h @@ -13,11 +13,11 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_AUTOPTR_H -#define OHOS_ZIDL_AUTOPTR_H +#ifndef OHOS_IDL_AUTOPTR_H +#define OHOS_IDL_AUTOPTR_H namespace OHOS { -namespace Zidl { +namespace Idl { template class AutoPtr { @@ -306,4 +306,4 @@ bool AutoPtr::operator>=( } } -#endif // OHOS_ZIDL_AUTOPTR_H +#endif // OHOS_IDL_AUTOPTR_H diff --git a/zidl/util/file.cpp b/idl/util/file.cpp similarity index 98% rename from zidl/util/file.cpp rename to idl/util/file.cpp index 1ba337c1f3..e3bdf7d11b 100644 --- a/zidl/util/file.cpp +++ b/idl/util/file.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -20,7 +20,7 @@ #include "securec.h" namespace OHOS { -namespace Zidl { +namespace Idl { #ifdef __MINGW32__ constexpr unsigned int File::READ; diff --git a/zidl/util/file.h b/idl/util/file.h similarity index 95% rename from zidl/util/file.h rename to idl/util/file.h index 1f5f3acc7b..b245efadf7 100644 --- a/zidl/util/file.h +++ b/idl/util/file.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_FILE_H -#define OHOS_ZIDL_FILE_H +#ifndef OHOS_IDL_FILE_H +#define OHOS_IDL_FILE_H #include #include @@ -22,7 +22,7 @@ #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class File { public: @@ -100,4 +100,4 @@ private: } } -#endif // OHOS_ZIDL_STRING_H +#endif // OHOS_IDL_STRING_H diff --git a/zidl/util/light_refcount_base.cpp b/idl/util/light_refcount_base.cpp similarity index 93% rename from zidl/util/light_refcount_base.cpp rename to idl/util/light_refcount_base.cpp index fb0bedd02a..c7414fff6b 100644 --- a/zidl/util/light_refcount_base.cpp +++ b/idl/util/light_refcount_base.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -16,7 +16,7 @@ #include "util/light_refcount_base.h" namespace OHOS { -namespace Zidl { +namespace Idl { int LightRefCountBase::AddRef() { diff --git a/zidl/util/light_refcount_base.h b/idl/util/light_refcount_base.h similarity index 88% rename from zidl/util/light_refcount_base.h rename to idl/util/light_refcount_base.h index 55df3d3ece..8e354ee4b8 100644 --- a/zidl/util/light_refcount_base.h +++ b/idl/util/light_refcount_base.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_LIGHTREFCOUNTBASE_H -#define OHOS_ZIDL_LIGHTREFCOUNTBASE_H +#ifndef OHOS_IDL_LIGHTREFCOUNTBASE_H +#define OHOS_IDL_LIGHTREFCOUNTBASE_H #include namespace OHOS { -namespace Zidl { +namespace Idl { class LightRefCountBase { public: @@ -47,4 +47,4 @@ private: } } -#endif // OHOS_ZIDL_LIGHTREFCOUNTBASE_H +#endif // OHOS_IDL_LIGHTREFCOUNTBASE_H diff --git a/zidl/util/logger.cpp b/idl/util/logger.cpp similarity index 96% rename from zidl/util/logger.cpp rename to idl/util/logger.cpp index acc50e1edb..1780266b2b 100644 --- a/zidl/util/logger.cpp +++ b/idl/util/logger.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -18,7 +18,7 @@ #include namespace OHOS { -namespace Zidl { +namespace Idl { int Logger::level_ = DEBUG; diff --git a/zidl/util/logger.h b/idl/util/logger.h similarity index 93% rename from zidl/util/logger.h rename to idl/util/logger.h index f31a20ad9a..3990c136b7 100644 --- a/zidl/util/logger.h +++ b/idl/util/logger.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_LOGGER_H -#define OHOS_ZIDL_LOGGER_H +#ifndef OHOS_IDL_LOGGER_H +#define OHOS_IDL_LOGGER_H #include namespace OHOS { -namespace Zidl { +namespace Idl { class Logger { public: @@ -67,4 +67,4 @@ private: } } -#endif // OHOS_ZIDL_LOGGER_H +#endif // OHOS_IDL_LOGGER_H diff --git a/zidl/util/options.cpp b/idl/util/options.cpp similarity index 87% rename from zidl/util/options.cpp rename to idl/util/options.cpp index 6309c07c6a..6202f22fab 100644 --- a/zidl/util/options.cpp +++ b/idl/util/options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -20,7 +20,7 @@ #include namespace OHOS { -namespace Zidl { +namespace Idl { void Options::Parse( /* [in] */ int argc, @@ -51,9 +51,9 @@ void Options::Parse( } else if (option.Equals("-gen-java")) { doGenerateCode_ = true; targetLanguage_ = "java"; - } else if (option.Equals("-gen-js")) { + } else if (option.Equals("-gen-ts")) { doGenerateCode_ = true; - targetLanguage_ = "js"; + targetLanguage_ = "ts"; } else if (option.Equals("-d")) { generationDirectory_ = argv[i++]; } else if (!option.StartsWith("-")) { @@ -82,25 +82,25 @@ void Options::ShowErrors() void Options::ShowVersion() { - printf("zidl %d.%d\n" + printf("idl %d.%d\n" "Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.\n\n", VERSION_MAJOR, VERSION_MINOR); } void Options::ShowUsage() { - printf("Compile a .zidl file and generate metadata, or generate C++, Js and Java codes from metadata.\n" - "Usage: zidl [options] file\n" + printf("Compile a .idl file and generate metadata, or generate C++, Ts and Java codes from metadata.\n" + "Usage: idl [options] file\n" "Options:\n" " --help Display command line options\n" " --version Display toolchain version information\n" " -dump-ast Display the AST of the compiled file\n" " -dump-metadata Display the metadata generated from the compiled file\n" - " -c Compile the .zidl file\n" + " -c Compile the .idl file\n" " -s Place the metadata into \n" " -gen-cpp Generate C++ codes\n" " -gen-java Generate Java codes\n" - " -gen-js Generate Js codes\n" + " -gen-ts Generate Ts codes\n" " -d Place generated codes into \n"); } diff --git a/zidl/util/options.h b/idl/util/options.h similarity index 96% rename from zidl/util/options.h rename to idl/util/options.h index 9d7895052e..97b258eee1 100644 --- a/zidl/util/options.h +++ b/idl/util/options.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_OPTIONS_H -#define OHOS_ZIDL_OPTIONS_H +#ifndef OHOS_IDL_OPTIONS_H +#define OHOS_IDL_OPTIONS_H #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class Options { public: @@ -125,4 +125,4 @@ private: } } -#endif // OHOS_ZIDL_OPTIONS_H +#endif // OHOS_IDL_OPTIONS_H diff --git a/zidl/util/string.cpp b/idl/util/string.cpp similarity index 99% rename from zidl/util/string.cpp rename to idl/util/string.cpp index d640223f14..e194f7cc58 100644 --- a/zidl/util/string.cpp +++ b/idl/util/string.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -27,7 +27,7 @@ #include "util/logger.h" namespace OHOS { -namespace Zidl { +namespace Idl { constexpr int LINE_MAX_SIZE = 1024; using SharedData = struct SharedData { diff --git a/zidl/util/string.h b/idl/util/string.h similarity index 97% rename from zidl/util/string.h rename to idl/util/string.h index d0f3250315..5896f4a979 100644 --- a/zidl/util/string.h +++ b/idl/util/string.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_STRING_H -#define OHOS_ZIDL_STRING_H +#ifndef OHOS_IDL_STRING_H +#define OHOS_IDL_STRING_H #include namespace OHOS { -namespace Zidl { +namespace Idl { class String { public: @@ -189,4 +189,4 @@ struct StringEqualFunc { } } -#endif // OHOS_ZIDL_STRING_H +#endif // OHOS_IDL_STRING_H diff --git a/zidl/util/string_builder.cpp b/idl/util/string_builder.cpp similarity index 98% rename from zidl/util/string_builder.cpp rename to idl/util/string_builder.cpp index e2caea4b58..7eec191cfb 100644 --- a/zidl/util/string_builder.cpp +++ b/idl/util/string_builder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -23,7 +23,7 @@ #include "util/logger.h" namespace OHOS { -namespace Zidl { +namespace Idl { const char* StringBuilder::TAG = "StringBuilder"; constexpr int LINE_MAX_SIZE = 1024; diff --git a/zidl/util/string_builder.h b/idl/util/string_builder.h similarity index 90% rename from zidl/util/string_builder.h rename to idl/util/string_builder.h index 54f4331d27..0249f901cf 100644 --- a/zidl/util/string_builder.h +++ b/idl/util/string_builder.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_STRINGBUILDER_H -#define OHOS_ZIDL_STRINGBUILDER_H +#ifndef OHOS_IDL_STRINGBUILDER_H +#define OHOS_IDL_STRINGBUILDER_H #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class StringBuilder { public: @@ -52,4 +52,4 @@ private: } } -#endif // OHOS_ZIDL_STRINGBUILDER_H +#endif // OHOS_IDL_STRINGBUILDER_H diff --git a/zidl/util/string_pool.cpp b/idl/util/string_pool.cpp similarity index 97% rename from zidl/util/string_pool.cpp rename to idl/util/string_pool.cpp index 026bcffdee..7883dcbb0d 100644 --- a/zidl/util/string_pool.cpp +++ b/idl/util/string_pool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -19,7 +19,7 @@ #include "util/logger.h" namespace OHOS { -namespace Zidl { +namespace Idl { const char* StringPool::TAG = "StringPool"; diff --git a/zidl/util/string_pool.h b/idl/util/string_pool.h similarity index 92% rename from zidl/util/string_pool.h rename to idl/util/string_pool.h index 7b991512c4..b712341208 100644 --- a/zidl/util/string_pool.h +++ b/idl/util/string_pool.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_ZIDL_STRINGPOOL_H -#define OHOS_ZIDL_STRINGPOOL_H +#ifndef OHOS_IDL_STRINGPOOL_H +#define OHOS_IDL_STRINGPOOL_H #include #include "util/string.h" namespace OHOS { -namespace Zidl { +namespace Idl { class StringPool { public: @@ -61,4 +61,4 @@ private: } } -#endif // OHOS_ZIDL_STRINGPOOL_H +#endif // OHOS_IDL_STRINGPOOL_H diff --git a/zidl/test/ts/moduletest/common/zidl_file.h b/zidl/test/ts/moduletest/common/zidl_file.h deleted file mode 100644 index 7c7123c0ab..0000000000 --- a/zidl/test/ts/moduletest/common/zidl_file.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2022 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_ZIDL_MODULE_TEST_ZIDL_FILE_H -#define OHOS_ZIDL_MODULE_TEST_ZIDL_FILE_H - -#include - -namespace OHOS { -namespace Zidl { -namespace ModuleTest { -const std::string LICENSE_CONTENT = -"/*\n" -" * Copyright (C) 2021 Huawei Device Co., Ltd.\n" -" * Licensed under the Apache License, Version 2.0 (the \"License\");\n" -" * you may not use this file except in compliance with the License.\n" -" * You may obtain a copy of the License at\n" -" *\n" -" * http://www.apache.org/licenses/LICENSE-2.0\n" -" *\n" -" * Unless required by applicable law or agreed to in writing, software\n" -" * distributed under the License is distributed on an \"AS IS\" BASIS,\n" -" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" -" * See the License for the specific language governing permissions and\n" -" * limitations under the License.\n" -" */\n" -"\n"; -const std::string UNKNOW_TYPE_ZIDL_NAME = "IZidlTest.zidl"; - -const std::string UNKNOW_TYPE_CASE1_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" void voidOrderOutChar([in] char param1, [out] char param2);\n" -"}"; - -const std::string UNKNOW_TYPE_CASE2_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" void voidOrderOutList([in] List param1, [out] List param2);\n" -"}"; - -const std::string UNKNOW_TYPE_CASE3_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" void voidOrderOutMapChar([in] Map param1, [out] Map param2);\n" -"}"; - -const std::string UNKNOW_TYPE_CASE4_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" void voidOrderOutMapList([in] Map> param1, [out] Map> param2);\n" -"}"; - -const std::string UNKNOW_TYPE_CASE5_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" char voidOrderReturnChar();\n" -"}"; - -const std::string UNKNOW_TYPE_CASE6_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" List voidOrderReturnList();\n" -"}"; - -const std::string UNKNOW_TYPE_CASE7_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" Map voidOrderReturnMapChar();\n" -"}"; - -const std::string UNKNOW_TYPE_CASE8_ZIDL_CONTENT = -"interface zidl.systemtest.IZidlTest {\n" -" Map> voidOrderReturnMapList();\n" -"}"; - -const std::string NORMAL_TYPE_ZIDL_CONTENT = -"interface zidl.systemtest.IInterfaceDeclare;" -"sequenceable zidl.systemtest.MySequenceable;" -"interface zidl.systemtest.IZidlTest {\n" -" int voidOrderOutInt([in] int param1, [out] int param2);\n" -"}"; -} -} -} -#endif // OHOS_AAFWK_ABILITY_CONFIG_H \ No newline at end of file