From 8f4f053a0af055a52308fb9e418e9416a44aa207 Mon Sep 17 00:00:00 2001 From: yanxuejun12 Date: Mon, 7 Jul 2025 18:33:04 +0800 Subject: [PATCH] fix: improve UT coverage Signed-off-by: yanxuejun12 --- idl_tool_2/test/unittest/BUILD.gn | 48 -- .../unittest/include/sa_type_emitter_test.h | 29 -- .../unittest/sa_type_emitter_test/BUILD.gn | 51 +++ .../sa_cstring_type_emitter_test.cpp | 166 +++++++ .../sa_fd_type_emitter_test.cpp | 172 ++++++++ .../sa_fdsan_type_emitter_test.cpp} | 299 +++++++------ test/unittest/BUILD.gn | 1 - test/unittest/cacheable2_test/BUILD.gn | 409 ------------------ .../cacheable2_test/cacheable2_test.cpp | 303 ------------- .../cacheable2_test/cacheable_common.h | 91 ---- test/unittest/cacheable2_test/cacheable_idl.h | 119 ----- 11 files changed, 563 insertions(+), 1125 deletions(-) delete mode 100644 idl_tool_2/test/unittest/include/sa_type_emitter_test.h create mode 100644 idl_tool_2/test/unittest/sa_type_emitter_test/sa_cstring_type_emitter_test.cpp create mode 100644 idl_tool_2/test/unittest/sa_type_emitter_test/sa_fd_type_emitter_test.cpp rename idl_tool_2/test/unittest/{src/sa_type_emitter_test.cpp => sa_type_emitter_test/sa_fdsan_type_emitter_test.cpp} (33%) delete mode 100644 test/unittest/cacheable2_test/BUILD.gn delete mode 100644 test/unittest/cacheable2_test/cacheable2_test.cpp delete mode 100644 test/unittest/cacheable2_test/cacheable_common.h delete mode 100644 test/unittest/cacheable2_test/cacheable_idl.h diff --git a/idl_tool_2/test/unittest/BUILD.gn b/idl_tool_2/test/unittest/BUILD.gn index 914d842..28dc133 100644 --- a/idl_tool_2/test/unittest/BUILD.gn +++ b/idl_tool_2/test/unittest/BUILD.gn @@ -25,37 +25,6 @@ config("idl_tool_2_test_config") { } common_sources = [ - "${IDL_DIR}/codegen/SA/sa_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_array_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_boolean_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_byte_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_char_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_cstring_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_double_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_enum_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_fd_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_fdsan_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_float_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_int_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_interface_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_long_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_map_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_orderedmap_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_ptr_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_rawdata_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_seq_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_set_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_short_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_string_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_struct_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_u16string_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_uchar_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_uint_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_ulong_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_union_type_emitter.cpp", - "${IDL_DIR}/codegen/SA/type/sa_ushort_type_emitter.cpp", - "${IDL_DIR}/lexer/lexer.cpp", - "${IDL_DIR}/lexer/token.cpp", "${IDL_DIR}/util/file.cpp", "${IDL_DIR}/util/light_refcount_base.cpp", "${IDL_DIR}/util/logger.cpp", @@ -65,22 +34,6 @@ common_sources = [ "${IDL_DIR}/util/string_pool.cpp", ] -ohos_unittest("SaTypeEmitterTest") { - module_out_path = module_output_path - include_dirs = [ "${IDL_DIR}" ] - - configs = [ ":idl_tool_2_test_config" ] - sources = [ "./src/sa_type_emitter_test.cpp" ] - sources += common_sources - - deps = [] - - external_deps = [ "c_utils:utils" ] - - part_name = "idl_tool" - subsystem_name = "ability" -} - ohos_unittest("IdlTool2UtilOptionsTest") { module_out_path = module_output_path include_dirs = [ "${IDL_DIR}" ] @@ -116,7 +69,6 @@ ohos_unittest("IdlTool2UtilStringTest") { group("unittest") { testonly = true deps = [ - ":SaTypeEmitterTest", ":IdlTool2UtilOptionsTest", ":IdlTool2UtilStringTest", "sa_type_emitter_test:unittest", diff --git a/idl_tool_2/test/unittest/include/sa_type_emitter_test.h b/idl_tool_2/test/unittest/include/sa_type_emitter_test.h deleted file mode 100644 index ff28e99..0000000 --- a/idl_tool_2/test/unittest/include/sa_type_emitter_test.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2025 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 IDL_TOOL_TEST_UNITTEST_SA_TYPE_EMITTER_TEST_H -#define IDL_TOOL_TEST_UNITTEST_SA_TYPE_EMITTER_TEST_H - -#include "gtest/gtest.h" - -namespace OHOS { -class SaTypeEmitterTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; -} // OHOS -#endif /* IDL_TOOL_TEST_UNITTEST_SA_TYPE_EMITTER_TEST_H */ \ No newline at end of file diff --git a/idl_tool_2/test/unittest/sa_type_emitter_test/BUILD.gn b/idl_tool_2/test/unittest/sa_type_emitter_test/BUILD.gn index 3467f70..736cc59 100644 --- a/idl_tool_2/test/unittest/sa_type_emitter_test/BUILD.gn +++ b/idl_tool_2/test/unittest/sa_type_emitter_test/BUILD.gn @@ -66,6 +66,54 @@ common_sources = [ "${IDL_DIR}/util/string_pool.cpp", ] +ohos_unittest("SaCStringTypeEmitterTest") { + module_out_path = module_output_path + include_dirs = [ "${IDL_DIR}" ] + + configs = [ ":idl_tool_2_test_config" ] + sources = [ "./sa_cstring_type_emitter_test.cpp" ] + sources += common_sources + + deps = [] + + external_deps = [ "c_utils:utils" ] + + part_name = "idl_tool" + subsystem_name = "ability" +} + +ohos_unittest("SaFdTypeEmitterTest") { + module_out_path = module_output_path + include_dirs = [ "${IDL_DIR}" ] + + configs = [ ":idl_tool_2_test_config" ] + sources = [ "./sa_fd_type_emitter_test.cpp" ] + sources += common_sources + + deps = [] + + external_deps = [ "c_utils:utils" ] + + part_name = "idl_tool" + subsystem_name = "ability" +} + +ohos_unittest("SaFdSanTypeEmitterTest") { + module_out_path = module_output_path + include_dirs = [ "${IDL_DIR}" ] + + configs = [ ":idl_tool_2_test_config" ] + sources = [ "./sa_fdsan_type_emitter_test.cpp" ] + sources += common_sources + + deps = [] + + external_deps = [ "c_utils:utils" ] + + part_name = "idl_tool" + subsystem_name = "ability" +} + ohos_unittest("SaUshortTypeEmitterTest") { module_out_path = module_output_path include_dirs = [ "${IDL_DIR}" ] @@ -230,6 +278,9 @@ ohos_unittest("SaSetTypeEmitterTest") { group("unittest") { testonly = true deps = [ + ":SaCStringTypeEmitterTest", + ":SaFdTypeEmitterTest", + ":SaFdSanTypeEmitterTest", ":SaUshortTypeEmitterTest", ":SaSetTypeEmitterTest", ":SaStructTypeEmitterTest", diff --git a/idl_tool_2/test/unittest/sa_type_emitter_test/sa_cstring_type_emitter_test.cpp b/idl_tool_2/test/unittest/sa_type_emitter_test/sa_cstring_type_emitter_test.cpp new file mode 100644 index 0000000..d2535ce --- /dev/null +++ b/idl_tool_2/test/unittest/sa_type_emitter_test/sa_cstring_type_emitter_test.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2025 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 "gtest/gtest.h" +#include "test_log.h" + +#include "codegen/SA/type/sa_cstring_type_emitter.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl; + +namespace OHOS::Idl { +class SaCStringTypeEmitterTest : public testing::Test { +public: + SaCStringTypeEmitterTest() {} + virtual ~SaCStringTypeEmitterTest() {} + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void SaCStringTypeEmitterTest::SetUpTestCase() +{ + DTEST_LOG << "SetUpTestCase" << std::endl; +} + +void SaCStringTypeEmitterTest::TearDownTestCase() +{ + DTEST_LOG << "TearDownTestCase" << std::endl; +} + +void SaCStringTypeEmitterTest::SetUp() +{ + DTEST_LOG << "SetUp" << std::endl; +} + +void SaCStringTypeEmitterTest::TearDown() +{ + DTEST_LOG << "TearDown" << std::endl; +} + +/* + * @tc.name: GetTypeKind_001 + * @tc.desc: test SaCStringTypeEmitter GetTypeKind + * @tc.type: FUNC + */ +HWTEST_F(SaCStringTypeEmitterTest, GetTypeKind_001, Level1) +{ + DTEST_LOG << "GetTypeKind_001 begin" << std::endl; + SaCStringTypeEmitter emitter; + auto ret = emitter.GetTypeKind(); + EXPECT_EQ(ret, TypeKind::TYPE_CSTRING); + DTEST_LOG << "GetTypeKind_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppType_001 + * @tc.desc: test SaCStringTypeEmitter EmitCppType + * @tc.type: FUNC + */ +HWTEST_F(SaCStringTypeEmitterTest, EmitCppType_001, Level1) +{ + DTEST_LOG << "EmitCppType_001 begin" << std::endl; + SaCStringTypeEmitter emitter; + std::string type = emitter.EmitCppType(TypeMode::NO_MODE); + EXPECT_EQ(type, "const char *"); + type = emitter.EmitCppType(TypeMode::LOCAL_VAR); + EXPECT_EQ(type, "const char *"); + type = emitter.EmitCppType(TypeMode::PARAM_IN); + EXPECT_EQ(type, "const char *"); + type = emitter.EmitCppType(TypeMode::PARAM_INOUT); + EXPECT_EQ(type, "const char *"); + type = emitter.EmitCppType(TypeMode::PARAM_OUT); + EXPECT_EQ(type, "const char *"); + type = emitter.EmitCppType(static_cast(9)); + EXPECT_EQ(type, "unknown type"); + DTEST_LOG << "EmitCppType_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppWriteVar_001 + * @tc.desc: test SaCStringTypeEmitter EmitCppWriteVar with log + * @tc.type: FUNC + */ +HWTEST_F(SaCStringTypeEmitterTest, EmitCppWriteVar_001, Level1) +{ + DTEST_LOG << "EmitCppWriteVar_001 begin" << std::endl; + SaCStringTypeEmitter emitter; + emitter.logOn_ = true; + std::string expectedCode = + "if (!parcel.WriteCString(value)) {\n" + " HiLog::Error(LABEL, \"Write [value] failed!\");\n" + " return ERR_INVALID_DATA;\n" + "}\n"; + StringBuilder sb; + emitter.EmitCppWriteVar("parcel.", "value", sb, ""); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppWriteVar_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppWriteVar_002 + * @tc.desc: test SaCStringTypeEmitter EmitCppWriteVar without log + * @tc.type: FUNC + */ +HWTEST_F(SaCStringTypeEmitterTest, EmitCppWriteVar_002, Level1) +{ + DTEST_LOG << "EmitCppWriteVar_002 begin" << std::endl; + SaCStringTypeEmitter emitter; + emitter.logOn_ = false; + std::string expectedCode = + "if (!parcel.WriteCString(value)) {\n" + " return ERR_INVALID_DATA;\n" + "}\n"; + StringBuilder sb; + emitter.EmitCppWriteVar("parcel.", "value", sb, ""); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppWriteVar_002 end" << std::endl; +} + +/* + * @tc.name: EmitCppReadVar_001 + * @tc.desc: test SaCStringTypeEmitter EmitCppReadVar with type + * @tc.type: FUNC + */ +HWTEST_F(SaCStringTypeEmitterTest, EmitCppReadVar_001, Level1) +{ + DTEST_LOG << "EmitCppReadVar_001 begin" << std::endl; + SaCStringTypeEmitter emitter; + std::string expectedCode = "const char * value = data.ReadCString();\n"; + StringBuilder sb; + emitter.EmitCppReadVar("data.", "value", sb, "", true); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppReadVar_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppReadVar_002 + * @tc.desc: test SaCStringTypeEmitter EmitCppReadVar without type + * @tc.type: FUNC + */ +HWTEST_F(SaCStringTypeEmitterTest, EmitCppReadVar_002, Level1) +{ + DTEST_LOG << "EmitCppReadVar_002 begin" << std::endl; + SaCStringTypeEmitter emitter; + std::string expectedCode = "value = data.ReadCString();\n"; + StringBuilder sb; + emitter.EmitCppReadVar("data.", "value", sb, "", false); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppReadVar_002 end" << std::endl; +} +} // namespace OHOS::idl \ No newline at end of file diff --git a/idl_tool_2/test/unittest/sa_type_emitter_test/sa_fd_type_emitter_test.cpp b/idl_tool_2/test/unittest/sa_type_emitter_test/sa_fd_type_emitter_test.cpp new file mode 100644 index 0000000..0ffc5d3 --- /dev/null +++ b/idl_tool_2/test/unittest/sa_type_emitter_test/sa_fd_type_emitter_test.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2025 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 "gtest/gtest.h" +#include "test_log.h" + +#include "codegen/SA/type/sa_fd_type_emitter.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl; + +namespace OHOS::Idl { +class SaFdTypeEmitterTest : public testing::Test { +public: + SaFdTypeEmitterTest() {} + virtual ~SaFdTypeEmitterTest() {} + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void SaFdTypeEmitterTest::SetUpTestCase() +{ + DTEST_LOG << "SetUpTestCase" << std::endl; +} + +void SaFdTypeEmitterTest::TearDownTestCase() +{ + DTEST_LOG << "TearDownTestCase" << std::endl; +} + +void SaFdTypeEmitterTest::SetUp() +{ + DTEST_LOG << "SetUp" << std::endl; +} + +void SaFdTypeEmitterTest::TearDown() +{ + DTEST_LOG << "TearDown" << std::endl; +} + +/* + * @tc.name: GetTypeKind_001 + * @tc.desc: test SaFdTypeEmitter GetTypeKind + * @tc.type: FUNC + */ +HWTEST_F(SaFdTypeEmitterTest, GetTypeKind_001, Level1) +{ + DTEST_LOG << "GetTypeKind_001 begin" << std::endl; + SaFdTypeEmitter emitter; + auto ret = emitter.GetTypeKind(); + EXPECT_EQ(ret, TypeKind::TYPE_FILEDESCRIPTOR); + DTEST_LOG << "GetTypeKind_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppType_001 + * @tc.desc: test SaFdTypeEmitter EmitCppType + * @tc.type: FUNC + */ +HWTEST_F(SaFdTypeEmitterTest, EmitCppType_001, Level1) +{ + DTEST_LOG << "EmitCppType_001 begin" << std::endl; + SaFdTypeEmitter emitter; + std::string type = emitter.EmitCppType(TypeMode::NO_MODE); + EXPECT_EQ(type, "int"); + type = emitter.EmitCppType(TypeMode::PARAM_IN); + EXPECT_EQ(type, "int"); + type = emitter.EmitCppType(TypeMode::LOCAL_VAR); + EXPECT_EQ(type, "int"); + type = emitter.EmitCppType(TypeMode::PARAM_INOUT); + EXPECT_EQ(type, "int&"); + type = emitter.EmitCppType(TypeMode::PARAM_OUT); + EXPECT_EQ(type, "int&"); + type = emitter.EmitCppType(static_cast(9)); + EXPECT_EQ(type, "unknown type"); + DTEST_LOG << "EmitCppType_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppWriteVar_001 + * @tc.desc: test SaFdTypeEmitter EmitCppWriteVar with log + * @tc.type: FUNC + */ +HWTEST_F(SaFdTypeEmitterTest, EmitCppWriteVar_001, Level1) +{ + DTEST_LOG << "EmitCppWriteVar_001 begin" << std::endl; + SaFdTypeEmitter emitter; + emitter.logOn_ = true; + emitter.isProxy = false; + std::string expectedCode = + "if (!parcel.WriteFileDescriptor(fd)) {\n" + " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" + " if (fd >= 0) {\n" + " close(fd);\n" + " }\n" + " return ERR_INVALID_DATA;\n" + "}\n"; + StringBuilder sb; + emitter.EmitCppWriteVar("parcel.", "fd", sb, ""); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppWriteVar_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppWriteVar_002 + * @tc.desc: test SaFdTypeEmitter EmitCppWriteVar without log + * @tc.type: FUNC + */ +HWTEST_F(SaFdTypeEmitterTest, EmitCppWriteVar_002, Level1) +{ + DTEST_LOG << "EmitCppWriteVar_002 begin" << std::endl; + SaFdTypeEmitter emitter; + emitter.logOn_ = true; + emitter.isProxy = true; + std::string expectedCode = + "if (!parcel.WriteFileDescriptor(fd)) {\n" + " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" + " return ERR_INVALID_DATA;\n" + "}\n"; + StringBuilder sb; + emitter.EmitCppWriteVar("parcel.", "fd", sb, ""); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppWriteVar_002 end" << std::endl; +} + +/* + * @tc.name: EmitCppReadVar_001 + * @tc.desc: test SaFdTypeEmitter EmitCppReadVar with type + * @tc.type: FUNC + */ +HWTEST_F(SaFdTypeEmitterTest, EmitCppReadVar_001, Level1) +{ + DTEST_LOG << "EmitCppReadVar_001 begin" << std::endl; + SaFdTypeEmitter emitter; + std::string expectedCode = "int fd = parcel.ReadFileDescriptor();\n"; + StringBuilder sb; + emitter.EmitCppReadVar("parcel.", "fd", sb, "", true); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppReadVar_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppReadVar_002 + * @tc.desc: test SaFdTypeEmitter EmitCppReadVar without type + * @tc.type: FUNC + */ +HWTEST_F(SaFdTypeEmitterTest, EmitCppReadVar_002, Level1) +{ + DTEST_LOG << "EmitCppReadVar_002 begin" << std::endl; + SaFdTypeEmitter emitter; + std::string expectedCode = "int fd = parcel.ReadFileDescriptor();\n"; + StringBuilder sb; + emitter.EmitCppReadVar("parcel.", "fd", sb, "", false); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppReadVar_002 end" << std::endl; +} +} // namespace OHOS::idl \ No newline at end of file diff --git a/idl_tool_2/test/unittest/src/sa_type_emitter_test.cpp b/idl_tool_2/test/unittest/sa_type_emitter_test/sa_fdsan_type_emitter_test.cpp similarity index 33% rename from idl_tool_2/test/unittest/src/sa_type_emitter_test.cpp rename to idl_tool_2/test/unittest/sa_type_emitter_test/sa_fdsan_type_emitter_test.cpp index 7d4bda3..94f7bbb 100644 --- a/idl_tool_2/test/unittest/src/sa_type_emitter_test.cpp +++ b/idl_tool_2/test/unittest/sa_type_emitter_test/sa_fdsan_type_emitter_test.cpp @@ -1,125 +1,174 @@ -/* - * Copyright (c) 2025 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 "sa_type_emitter_test.h" -#include "codegen/SA/type/sa_fd_type_emitter.h" -#include "codegen/SA/type/sa_fdsan_type_emitter.h" - -using namespace testing; -using namespace testing::ext; -using namespace OHOS::Idl; - -namespace OHOS { - -void SaTypeEmitterTest::SetUpTestCase() {} - -void SaTypeEmitterTest::TearDownTestCase() {} - -void SaTypeEmitterTest::SetUp() {} - -void SaTypeEmitterTest::TearDown() {} - -/* - * @tc.name: SaFdTypeEmitterTest_001 - * @tc.desc: test SaFdTypeEmitter EmitCppWriteVar stub - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(SaTypeEmitterTest, SaFdTypeEmitterTest_001, Level1) -{ - SaFdTypeEmitter emitter; - emitter.logOn_ = true; - emitter.isProxy = false; - std::string expectedCode = - "if (!parcelWriteFileDescriptor(fd)) {\n" - " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" - " if (fd >= 0) {\n" - " close(fd);\n" - " }\n" - " return ERR_INVALID_DATA;\n" - "}\n"; - StringBuilder sb; - emitter.EmitCppWriteVar("parcel", "fd", sb, ""); - EXPECT_EQ(sb.ToString(), expectedCode); -} - -/* - * @tc.name: SaFdTypeEmitterTest_002 - * @tc.desc: test SaFdTypeEmitter EmitCppWriteVar proxy - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(SaTypeEmitterTest, SaFdTypeEmitterTest_002, Level1) -{ - SaFdTypeEmitter emitter; - emitter.logOn_ = true; - emitter.isProxy = true; - std::string expectedCode = - "if (!parcelWriteFileDescriptor(fd)) {\n" - " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" - " return ERR_INVALID_DATA;\n" - "}\n"; - StringBuilder sb; - emitter.EmitCppWriteVar("parcel", "fd", sb, ""); - EXPECT_EQ(sb.ToString(), expectedCode); -} - -/* - * @tc.name: SaFdSanTypeEmitterTest_001 - * @tc.desc: test SaFdSanTypeEmitter EmitCppWriteVar stub - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(SaTypeEmitterTest, SaFdSanTypeEmitterTest_001, Level1) -{ - SaFdSanTypeEmitter emitter; - emitter.logOn_ = true; - emitter.isProxy = false; - emitter.domainId_ = "testDomainId"; - std::string expectedCode = - "if (!parcelWriteFileDescriptor(fd)) {\n" - " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" - " if (fd >= 0) {\n" - " fdsan_close_with_tag(fd, testDomainId);\n" - " }\n" - " return ERR_INVALID_DATA;\n" - "}\n"; - StringBuilder sb; - emitter.EmitCppWriteVar("parcel", "fd", sb, ""); - EXPECT_EQ(sb.ToString(), expectedCode); -} - -/* - * @tc.name: SaFdSanTypeEmitterTest_002 - * @tc.desc: test SaFdSanTypeEmitter EmitCppWriteVar - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(SaTypeEmitterTest, SaFdSanTypeEmitterTest_002, Level1) -{ - SaFdSanTypeEmitter emitter; - emitter.logOn_ = true; - emitter.isProxy = true; - emitter.domainId_ = "testDomainId"; - std::string expectedCode = - "if (!parcelWriteFileDescriptor(fd)) {\n" - " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" - " return ERR_INVALID_DATA;\n" - "}\n"; - StringBuilder sb; - emitter.EmitCppWriteVar("parcel", "fd", sb, ""); - EXPECT_EQ(sb.ToString(), expectedCode); -} -} // namespace OHOS \ No newline at end of file +/* + * Copyright (c) 2025 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 "gtest/gtest.h" +#include "test_log.h" + +#include "codegen/SA/type/sa_fdsan_type_emitter.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Idl; + +namespace OHOS::Idl { +class SaFdSanTypeEmitterTest : public testing::Test { +public: + SaFdSanTypeEmitterTest() {} + virtual ~SaFdSanTypeEmitterTest() {} + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void SaFdSanTypeEmitterTest::SetUpTestCase() +{ + DTEST_LOG << "SetUpTestCase" << std::endl; +} + +void SaFdSanTypeEmitterTest::TearDownTestCase() +{ + DTEST_LOG << "TearDownTestCase" << std::endl; +} + +void SaFdSanTypeEmitterTest::SetUp() +{ + DTEST_LOG << "SetUp" << std::endl; +} + +void SaFdSanTypeEmitterTest::TearDown() +{ + DTEST_LOG << "TearDown" << std::endl; +} + +/* + * @tc.name: GetTypeKind_001 + * @tc.desc: test SaFdSanTypeEmitter GetTypeKind + * @tc.type: FUNC + */ +HWTEST_F(SaFdSanTypeEmitterTest, GetTypeKind_001, Level1) +{ + DTEST_LOG << "GetTypeKind_001 begin" << std::endl; + SaFdSanTypeEmitter emitter; + auto ret = emitter.GetTypeKind(); + EXPECT_EQ(ret, TypeKind::TYPE_FILEDESCRIPTORSAN); + DTEST_LOG << "GetTypeKind_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppType_001 + * @tc.desc: test SaFdSanTypeEmitter EmitCppType + * @tc.type: FUNC + */ +HWTEST_F(SaFdSanTypeEmitterTest, EmitCppType_001, Level1) +{ + DTEST_LOG << "EmitCppType_001 begin" << std::endl; + SaFdSanTypeEmitter emitter; + std::string type = emitter.EmitCppType(TypeMode::NO_MODE); + EXPECT_EQ(type, "int"); + type = emitter.EmitCppType(TypeMode::PARAM_IN); + EXPECT_EQ(type, "int"); + type = emitter.EmitCppType(TypeMode::LOCAL_VAR); + EXPECT_EQ(type, "int"); + type = emitter.EmitCppType(TypeMode::PARAM_INOUT); + EXPECT_EQ(type, "int&"); + type = emitter.EmitCppType(TypeMode::PARAM_OUT); + EXPECT_EQ(type, "int&"); + type = emitter.EmitCppType(static_cast(9)); + EXPECT_EQ(type, "unknown type"); + DTEST_LOG << "EmitCppType_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppWriteVar_001 + * @tc.desc: test SaFdSanTypeEmitter EmitCppWriteVar with log + * @tc.type: FUNC + */ +HWTEST_F(SaFdSanTypeEmitterTest, EmitCppWriteVar_001, Level1) +{ + DTEST_LOG << "EmitCppWriteVar_001 begin" << std::endl; + SaFdSanTypeEmitter emitter; + emitter.logOn_ = true; + emitter.isProxy = false; + emitter.domainId_ = "testDomainId"; + std::string expectedCode = + "if (!parcel.WriteFileDescriptor(fd)) {\n" + " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" + " if (fd >= 0) {\n" + " fdsan_close_with_tag(fd, testDomainId);\n" + " }\n" + " return ERR_INVALID_DATA;\n" + "}\n"; + StringBuilder sb; + emitter.EmitCppWriteVar("parcel.", "fd", sb, ""); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppWriteVar_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppWriteVar_002 + * @tc.desc: test SaFdSanTypeEmitter EmitCppWriteVar without log + * @tc.type: FUNC + */ +HWTEST_F(SaFdSanTypeEmitterTest, EmitCppWriteVar_002, Level1) +{ + DTEST_LOG << "EmitCppWriteVar_002 begin" << std::endl; + SaFdSanTypeEmitter emitter; + emitter.logOn_ = true; + emitter.isProxy = true; + emitter.domainId_ = "testDomainId"; + std::string expectedCode = + "if (!parcel.WriteFileDescriptor(fd)) {\n" + " HiLog::Error(LABEL, \"Write [fd] failed!\");\n" + " return ERR_INVALID_DATA;\n" + "}\n"; + StringBuilder sb; + emitter.EmitCppWriteVar("parcel.", "fd", sb, ""); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppWriteVar_002 end" << std::endl; +} + +/* + * @tc.name: EmitCppReadVar_001 + * @tc.desc: test SaFdSanTypeEmitter EmitCppReadVar with type + * @tc.type: FUNC + */ +HWTEST_F(SaFdSanTypeEmitterTest, EmitCppReadVar_001, Level1) +{ + DTEST_LOG << "EmitCppReadVar_001 begin" << std::endl; + SaFdSanTypeEmitter emitter; + std::string expectedCode = "int fd = parcel.ReadFileDescriptor();\n"; + StringBuilder sb; + emitter.EmitCppReadVar("parcel.", "fd", sb, "", true); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppReadVar_001 end" << std::endl; +} + +/* + * @tc.name: EmitCppReadVar_002 + * @tc.desc: test SaFdSanTypeEmitter EmitCppReadVar without type + * @tc.type: FUNC + */ +HWTEST_F(SaFdSanTypeEmitterTest, EmitCppReadVar_002, Level1) +{ + DTEST_LOG << "EmitCppReadVar_002 begin" << std::endl; + SaFdSanTypeEmitter emitter; + std::string expectedCode = "fd = parcel.ReadFileDescriptor();\n"; + StringBuilder sb; + emitter.EmitCppReadVar("parcel.", "fd", sb, "", false); + EXPECT_EQ(sb.ToString(), expectedCode); + DTEST_LOG << "EmitCppReadVar_002 end" << std::endl; +} +} // namespace OHOS::idl \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 2f1eb2b..2ca1771 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -26,7 +26,6 @@ group("unittest") { "ast_sequenceable_type_test:unittest", "ast_type_test:unittest", "cacheable_test:unittest", - "cacheable2_test:unittest", "codegen_code_generator_test:unittest", "cpp_code_emitter_test:unittest", "lexer_test:unittest", diff --git a/test/unittest/cacheable2_test/BUILD.gn b/test/unittest/cacheable2_test/BUILD.gn deleted file mode 100644 index 87b1e0f..0000000 --- a/test/unittest/cacheable2_test/BUILD.gn +++ /dev/null @@ -1,409 +0,0 @@ -# Copyright (c) 2025 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") -import("//build/test.gni") -import("//foundation/ability/idl_tool/idl_tool.gni") - -module_output_path = "idl_tool/idl_tool" - -IDL_DIR = "../../.." - -common_sources = [ - "${IDL_DIR}/idl_tool_2/ast/base/ast_boolean_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_boolean_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_byte_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_byte_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_char_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_char_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_cstring_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_cstring_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_double_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_double_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_float_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_float_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_integer_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_integer_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_long_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_long_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_short_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_short_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_string16_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_string16_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_string_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_string_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_u16string_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_u16string_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_uchar_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_uchar_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_uint_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_uint_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_ulong_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_ulong_type.h", - "${IDL_DIR}/idl_tool_2/ast/base/ast_ushort_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/base/ast_ushort_type.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/ast/ast.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast.h", - "${IDL_DIR}/idl_tool_2/ast/ast_array_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_array_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_attribute.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_attribute.h", - "${IDL_DIR}/idl_tool_2/ast/ast_enum_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_enum_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_expr.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_expr.h", - "${IDL_DIR}/idl_tool_2/ast/ast_fd_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_fd_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_fdsan_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_fdsan_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_interface_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_interface_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_map_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_map_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_method.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_method.h", - "${IDL_DIR}/idl_tool_2/ast/ast_namespace.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_namespace.h", - "${IDL_DIR}/idl_tool_2/ast/ast_native_buffer_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_native_buffer_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_node.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_node.h", - "${IDL_DIR}/idl_tool_2/ast/ast_orderedmap_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_orderedmap_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_parameter.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_parameter.h", - "${IDL_DIR}/idl_tool_2/ast/ast_pointer_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_pointer_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_ptr_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_rawdata_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_rawdata_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_sequenceable_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_sequenceable_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_set_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_set_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_smq_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_smq_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_struct_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_struct_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_union_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_union_type.h", - "${IDL_DIR}/idl_tool_2/ast/ast_void_type.cpp", - "${IDL_DIR}/idl_tool_2/ast/ast_void_type.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_client_proxy_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_client_proxy_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_custom_types_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_custom_types_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_interface_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_interface_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_service_driver_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_service_driver_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_service_impl_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_service_impl_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_service_stub_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/c_service_stub_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/hdi_c_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/c/hdi_c_code_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_client_proxy_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_client_proxy_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_custom_types_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_custom_types_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_interface_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_interface_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_service_driver_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_service_driver_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_service_impl_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_service_impl_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_service_stub_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/cpp_service_stub_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/hdi_cpp_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/cpp/hdi_cpp_code_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/HDI/java/hdi_java_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/java/hdi_java_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/java/java_client_interface_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/java/java_client_interface_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/java/java_client_proxy_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/java/java_client_proxy_code_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_array_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_array_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_boolean_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_boolean_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_byte_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_byte_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_double_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_double_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_enum_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_enum_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_fd_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_fd_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_float_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_float_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_int_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_int_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_interface_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_interface_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_long_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_long_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_map_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_map_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_native_buffer_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_native_buffer_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_pointer_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_pointer_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_seq_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_seq_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_short_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_short_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_smq_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_smq_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_string_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_string_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_struct_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_struct_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_uchar_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_uchar_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_uint_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_uint_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_ulong_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_ulong_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_union_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_union_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_ushort_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/type/hdi_ushort_type_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/HDI/hdi_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/hdi_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/hdi_code_generator.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/hdi_code_generator.h", - "${IDL_DIR}/idl_tool_2/codegen/HDI/hdi_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/HDI/hdi_type_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_client_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_client_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_client_proxy_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_custom_types_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_custom_types_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_interface_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/SA/rust/sa_rust_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/rust/sa_rust_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/rust/sa_rust_interface_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/rust/sa_rust_interface_code_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_client_proxy_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_client_proxy_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_interface_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_interface_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_service_stub_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/ts/sa_ts_service_stub_code_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_array_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_array_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_boolean_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_boolean_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_byte_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_byte_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_char_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_char_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_cstring_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_cstring_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_double_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_double_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_enum_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_enum_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_fdsan_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_fdsan_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_float_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_float_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_int_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_int_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_interface_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_interface_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_long_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_long_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_map_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_map_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_orderedmap_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_orderedmap_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_ptr_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_rawdata_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_rawdata_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_seq_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_set_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_set_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_short_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_short_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_string_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_string_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_struct_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_struct_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_u16string_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_u16string_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_union_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_union_type_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/SA/sa_code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/sa_code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/sa_code_generator.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/sa_code_generator.h", - "${IDL_DIR}/idl_tool_2/codegen/SA/sa_type_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/SA/sa_type_emitter.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/codegen/code_emitter.cpp", - "${IDL_DIR}/idl_tool_2/codegen/code_emitter.h", - "${IDL_DIR}/idl_tool_2/codegen/code_generator.cpp", - "${IDL_DIR}/idl_tool_2/codegen/code_generator.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/hash/hash.cpp", - "${IDL_DIR}/idl_tool_2/hash/hash.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/lexer/lexer.cpp", - "${IDL_DIR}/idl_tool_2/lexer/lexer.h", - "${IDL_DIR}/idl_tool_2/lexer/token.cpp", - "${IDL_DIR}/idl_tool_2/lexer/token.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/metadata/meta_component.h", - "${IDL_DIR}/idl_tool_2/metadata/meta_interface.h", - "${IDL_DIR}/idl_tool_2/metadata/meta_method.h", - "${IDL_DIR}/idl_tool_2/metadata/meta_namespace.h", - "${IDL_DIR}/idl_tool_2/metadata/meta_patameter.h", - "${IDL_DIR}/idl_tool_2/metadata/meta_rawdata.h", - "${IDL_DIR}/idl_tool_2/metadata/meta_sequenceable.h", - "${IDL_DIR}/idl_tool_2/metadata/meta_type.h", - "${IDL_DIR}/idl_tool_2/metadata/metadata_builder.cpp", - "${IDL_DIR}/idl_tool_2/metadata/metadata_builder.h", - "${IDL_DIR}/idl_tool_2/metadata/metadata_dumper.cpp", - "${IDL_DIR}/idl_tool_2/metadata/metadata_dumper.h", - "${IDL_DIR}/idl_tool_2/metadata/metadata_reader.cpp", - "${IDL_DIR}/idl_tool_2/metadata/metadata_reader.h", - "${IDL_DIR}/idl_tool_2/metadata/metadata_serializer.cpp", - "${IDL_DIR}/idl_tool_2/metadata/metadata_serializer.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/parser/intf_type_check.cpp", - "${IDL_DIR}/idl_tool_2/parser/intf_type_check.h", - "${IDL_DIR}/idl_tool_2/parser/parser.cpp", - "${IDL_DIR}/idl_tool_2/parser/parser.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/preprocessor/preprocessor.cpp", - "${IDL_DIR}/idl_tool_2/preprocessor/preprocessor.h", -] - -common_sources += [ - "${IDL_DIR}/idl_tool_2/util/autoptr.h", - "${IDL_DIR}/idl_tool_2/util/common.h", - "${IDL_DIR}/idl_tool_2/util/file.cpp", - "${IDL_DIR}/idl_tool_2/util/file.h", - "${IDL_DIR}/idl_tool_2/util/light_refcount_base.cpp", - "${IDL_DIR}/idl_tool_2/util/light_refcount_base.h", - "${IDL_DIR}/idl_tool_2/util/logger.cpp", - "${IDL_DIR}/idl_tool_2/util/logger.h", - "${IDL_DIR}/idl_tool_2/util/options.cpp", - "${IDL_DIR}/idl_tool_2/util/options.h", - "${IDL_DIR}/idl_tool_2/util/string_builder.cpp", - "${IDL_DIR}/idl_tool_2/util/string_builder.h", - "${IDL_DIR}/idl_tool_2/util/string_helper.cpp", - "${IDL_DIR}/idl_tool_2/util/string_helper.h", - "${IDL_DIR}/idl_tool_2/util/string_pool.cpp", - "${IDL_DIR}/idl_tool_2/util/string_pool.h", -] - -ohos_unittest("cacheable2_test") { - module_out_path = module_output_path - use_exceptions = true - include_dirs = [ "${IDL_TOOL_DIR}/idl_tool_2" ] - - sources = [ "cacheable2_test.cpp" ] - - sources += common_sources - - defines = [ "IDLTOOL_GTEST" ] - - deps = [] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "bounds_checking_function:libsec_static" - ] - - if (is_arkui_x) { - deps += [ "//third_party/bounds_checking_function:libsec_static" ] - } - - part_name = "idl_tool" - subsystem_name = "ability" -} - -group("unittest") { - testonly = true - deps = [ ":cacheable2_test" ] -} diff --git a/test/unittest/cacheable2_test/cacheable2_test.cpp b/test/unittest/cacheable2_test/cacheable2_test.cpp deleted file mode 100644 index 953a5e7..0000000 --- a/test/unittest/cacheable2_test/cacheable2_test.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2025 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 "cacheable_idl.h" -#include "cacheable_common.h" - -#ifdef IDLTOOL_GTEST -#define private public -#define protected public -#endif -#include "util/options.h" -#include "parser/parser.h" - -using namespace testing; -using namespace testing::ext; -namespace OHOS { -namespace Idl { -using namespace TestCommon; - -class Cacheable2Test : public testing::Test { -public: - Cacheable2Test() {} - - virtual ~Cacheable2Test() {} - - static void SetUpTestCase(); - - static void TearDownTestCase(); - - void SetUp(); - - void TearDown(); -}; - -void Cacheable2Test::SetUpTestCase() {} - -void Cacheable2Test::TearDownTestCase() {} - -void Cacheable2Test::SetUp() {} - -void Cacheable2Test::TearDown() {} - -/* - * @tc.name: Cacheable2Test001 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test001, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test001, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_001_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST001_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_001_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, true); -} - -/* - * @tc.name: Cacheable2Test002 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test002, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test002, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_002_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST002_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_002_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, false); -} - -/* - * @tc.name: Cacheable2Test003 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test003, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test003, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_003_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST003_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_003_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, true); -} - -/* - * @tc.name: Cacheable2Test004 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test004, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test004, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_004_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST004_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_004_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, true); -} - -/* - * @tc.name: Cacheable2Test005 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test005, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test005, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_005_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST005_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_005_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, false); -} - -/* - * @tc.name: Cacheable2Test006 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test006, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test006, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_006_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST006_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_006_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - Parser parser; - auto mode = parser.lexer_.mode_; - parser.lexer_.mode_ = Lexer::ParseMode::EXPR_MODE; - std::string path = "Cache.h"; - parser.lexer_.Reset(path); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, false); - parser.lexer_.mode_ = mode; -} - -/* - * @tc.name: Cacheable2Test007 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test007, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test007, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_007_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST007_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_007_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, false); -} - -/* - * @tc.name: Cacheable2Test008 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test008, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test008, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_008_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST008_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_008_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - ret = parser.Parse(fileDetails); - EXPECT_EQ(ret, true); -} - -/* - * @tc.name: Cacheable2Test009 - * @tc.desc: test Idltool2 Lexer - * @tc.type: FUNC - * @tc.require: issueICIIF8 - */ -HWTEST_F(Cacheable2Test, Cacheable2Test009, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) << "Cacheable2Test, Cacheable2Test009, TestSize.Level1"; - PrepareIdlFile(CACHE_TIME_009_IDL_NAME.c_str(), - CACHEABLE_TIME_TEST009_IDL_CONTENT.c_str()); - const char* argvArray[] = {"./idl", "-gen-cpp", "-c", CACHE_TIME_009_IDL_NAME.c_str()}; - int argc = 4; - ParameterArgv parameters(argvArray, argc); - Options &options = Options::GetInstance(); - options.sourceFiles.clear(); - bool ret = options.Parse(parameters.argc_, parameters.argv_); - EXPECT_EQ(ret, true); - std::vector fileDetails; - ret = Preprocessor::Preprocess(fileDetails); - EXPECT_EQ(ret, true); - Parser parser; - parser.lexer_.Reset(fileDetails[0].filePath_); - parser.lexer_.SkipCurrentLine(); - ret = parser.lexer_.SkipCurrentLine('h'); - EXPECT_EQ(ret, true); - ret = parser.lexer_.SkipCurrentLine('f'); - EXPECT_EQ(ret, false); - parser.lexer_.Skip('b'); - parser.lexer_.SkipToken(TokenType::LONG); - parser.lexer_.SkipUntilToken(TokenType::END_OF_FILE); - parser.lexer_.SkipEof(); -} -} // namespace idl -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cacheable2_test/cacheable_common.h b/test/unittest/cacheable2_test/cacheable_common.h deleted file mode 100644 index d5bc942..0000000 --- a/test/unittest/cacheable2_test/cacheable_common.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2025 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_CACHEABLE_COMMON_H -#define OHOS_CACHEABLE_COMMON_H -#include "securec.h" -#include "util/string_helper.h" -#include "util/string_builder.h" -#include "util/file.h" - -namespace OHOS { -namespace Idl { -namespace TestCommon { -const int ERR_FAIL = -1; -const int ERR_OK = 0; - -class ParameterArgv { -public: - ParameterArgv(const char** args, const int argc) : argc_(argc) - { - argv_ = new char* [argc_] {nullptr}; - for (int i = 0; i < argc_; ++i) { - const int itemSize = strlen(args[i]); - argv_[i] = new char[itemSize + 1] {0}; - if (strcpy_s(argv_[i], itemSize + 1, args[i]) != ERR_OK) { - GTEST_LOG_(ERROR) << "strcpy_s error [!EOK]"; - return; - } - } - }; - ~ParameterArgv() - { - if (argv_ == nullptr) { - return; - } - - for (int i = 0; i < argc_; ++i) { - if (argv_[i] == nullptr) { - continue; - } - delete[] argv_[i]; - argv_[i] = nullptr; - } - delete[] argv_; - argv_ = nullptr; - }; - - char** GetArgv() - { - return argv_; - }; - - char** argv_; - const int argc_; -}; - -int PrepareIdlFile(const std::string &fileName, const std::string &fileContent) -{ - std::string filePath = StringHelper::Format("%s/%s", "./", fileName.c_str()); - File file(filePath, File::WRITE); - if (!file.IsValid()) { - GTEST_LOG_(INFO) << "OPEN FILE FAIL"; - return ERR_FAIL; - } - - StringBuilder stringBuilder; - stringBuilder.Append(fileContent.c_str()); - - std::string data = stringBuilder.ToString(); - file.WriteData(data.c_str(), data.size()); - file.Flush(); - file.Close(); - return ERR_OK; -} -} // namespace TestCommon -} // namespace Idl -} // namespace OHOS - -#endif // OHOS_CACHEABLE_COMMON_H \ No newline at end of file diff --git a/test/unittest/cacheable2_test/cacheable_idl.h b/test/unittest/cacheable2_test/cacheable_idl.h deleted file mode 100644 index e76cc55..0000000 --- a/test/unittest/cacheable2_test/cacheable_idl.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2025 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_CACHEABLE_IDL_FILE_H -#define OHOS_CACHEABLE_IDL_FILE_H - -#include - -namespace OHOS { -namespace Idl { -namespace TestCommon { - -const std::string CACHE_TIME_001_IDL_NAME = "CacheTimeTest001.idl"; - -const std::string CACHEABLE_TIME_TEST001_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest001 {\n" -" [cacheable 100]void test001([in] short param1);\n" -" [cacheable 0]void test002([in] short param1);\n" -" [cacheable 00200]void test003([in] short param1);\n" -" [cacheable 2147483647]void test004([in] short param1);\n" -"}"; - -const std::string CACHE_TIME_002_IDL_NAME = "CacheTimeTest002.idl"; - -const std::string CACHEABLE_TIME_TEST002_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest002 {\n" -" [cacheable 2147483648]void test001([in] short param1);\n" -"}"; - -const std::string CACHE_TIME_003_IDL_NAME = "CacheTimeTest003.idl"; - -const std::string CACHEABLE_TIME_TEST003_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest003 {\n" -" [cacheable 100]void test001([in] short param1);\n" -" [cacheable 00200]void test002([in] short param1);\n" -" [cacheable 200, ipccode 0X823]void test003([in] short param1);\n" -" [cacheable 200, ipccode 0x90]void test004([in] short param1);\n" -"}"; - -const std::string CACHE_TIME_004_IDL_NAME = "CacheTimeTest004.idl"; - -const std::string CACHEABLE_TIME_TEST004_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest004 {\n" -" [cacheable 200]void test001([in] short param1, [in] List param2);\n" -"}"; - -const std::string CACHE_TIME_005_IDL_NAME = "CacheTimeTest005.idl"; - -const std::string CACHEABLE_TIME_TEST005_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest005 {\n" -" [cacheable -900]void test001([in] short param1);\n" -" [cacheable +900]void test002([in] short param1);\n" -" [cacheable 100, ipccode 0B110]void test003([in] short param1);\n" -" [cacheable 100, ipccode 0b10]void test004([in] short param1);\n" -"}"; - -const std::string CACHE_TIME_006_IDL_NAME = "CacheTimeTest006.idl"; - -const std::string CACHEABLE_TIME_TEST006_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest006 {\n" -" [cacheable --900]void test001([in] short param1);\n" -" [cacheable ++900]void test002([in] short param1);\n" -" [cacheable 9<<1]void test003([in] short param1);\n" -" [cacheable 9>>1]void test004([in] short param1);\n" -" [cacheable 2 100]void test005([in] short param1);\n" -" [cacheable 200 void test006([in] short param1);\n" -" [cacheable 0823]void test007([in] short param1);\n" -" [cacheable 0h82]void test008([in] short param1);\n" -" /comment test009\n" -"}"; - -const std::string CACHE_TIME_007_IDL_NAME = "CacheTimeTest007.idl"; - -const std::string CACHEABLE_TIME_TEST007_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest007 {\n" -" [cacheable"; - -const std::string CACHE_TIME_008_IDL_NAME = "CacheTimeTest008.idl"; - -const std::string CACHEABLE_TIME_TEST008_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest008 {\n" -" //comment test001\n" -" [cacheable 200]void test001([in] short param1);\n" -" /*comment test002*/\n" -" [cacheable 200]void test002([in] short param1);\n" -" /**\n" -" * @brief comment test003\n" -" *\n" -" * @param [in] param1 short\n" -" */\n" -" [cacheable 200]void test003([in] short param1);\n" -"}"; - -const std::string CACHE_TIME_009_IDL_NAME = "CacheTimeTest009.idl"; - -const std::string CACHEABLE_TIME_TEST009_IDL_CONTENT = -"interface idl.OHOS.CacheTimeTest009 {\n" -" [cacheable 100]void test001([in] short param1);\n" -" [cacheable 100]void test002([in] short param1);\n" -" [cacheable 200]void test003([in] long param1);\n" -" [cacheable 200]void test004([in] short param1);\n" -"}"; - -} // namespace TestCommon -} // namespace Idl -} // namespace OHOS - -#endif // OHOS_CACHEABLE_IDL_FILE_H \ No newline at end of file -- Gitee