diff --git a/common_components/heap/collector/tests/BUILD.gn b/common_components/heap/collector/tests/BUILD.gn index 20a34d4289709824629fe2663dcf71b8349d9011..6490c79d2276706e5d44ce4214202d4c9ce0d4b0 100755 --- a/common_components/heap/collector/tests/BUILD.gn +++ b/common_components/heap/collector/tests/BUILD.gn @@ -39,6 +39,29 @@ host_unittest_action("Collector_Test") { ] } +host_unittest_action("Collector_Proxy_Test") { + module_out_path = module_output_path + + sources = [ + # test file + "collector_proxy_test.cpp", + ] + + configs = [ + "//arkcompiler/ets_runtime/common_components:common_components_test_config", + "//arkcompiler/ets_runtime:icu_path_test_config", + ] + + deps = [ "//arkcompiler/ets_runtime/common_components:libark_common_components_test" ] + + # hiviewdfx libraries + external_deps = [ + "icu:shared_icui18n", + "icu:shared_icuuc", + "zlib:libz", + ] +} + host_unittest_action("Trace_Collector_Test") { module_out_path = module_output_path @@ -114,6 +137,7 @@ group("unittest") { # deps file deps = [ ":Collector_Test", + ":Collector_Proxy_Test", ":Trace_Collector_Test", ":Task_Queue_Test", ":Gc_Request_Test", @@ -126,6 +150,7 @@ group("host_unittest") { # deps file deps = [ ":Collector_TestAction", + ":Collector_Proxy_TestAction", ":Trace_Collector_TestAction", ":Task_Queue_TestAction", ":Gc_Request_TestAction", diff --git a/common_components/heap/collector/tests/collector_proxy_test.cpp b/common_components/heap/collector/tests/collector_proxy_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2baca36eb1519c6ea39bd6eb5f2cbff4e4b2fac8 --- /dev/null +++ b/common_components/heap/collector/tests/collector_proxy_test.cpp @@ -0,0 +1,44 @@ +/* +* 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 "common_components/heap/collector/collector_proxy.h" +#include "common_components/tests/test_helper.h" + +using namespace common; +namespace common::test { +class CollectorProxyTest : public common::test::BaseTestWithScope { +protected: + static void SetUpTestCase() + { + BaseRuntime::GetInstance()->Init(); + } + + static void TearDownTestCase() + { + BaseRuntime::GetInstance()->Fini(); + } + + void SetUp() override {} + void TearDown() override {} +}; + +HWTEST_F_L0(CollectorProxyTest, RunGarbageCollection) +{ + CollectorProxy collectorProxy(Heap::GetHeap().GetAllocator(), Heap::GetHeap().GetCollectorResources()); + Heap::GetHeap().SetGCReason(GCReason::GC_REASON_OOM); + collectorProxy.RunGarbageCollection(0, GCReason::GC_REASON_OOM, GCType::GC_TYPE_BEGIN); + ASSERT_TRUE(Heap::GetHeap().GetGCReason() == GCReason::GC_REASON_OOM); +} +} // namespace common::test \ No newline at end of file diff --git a/common_components/log/tests/log_test.cpp b/common_components/log/tests/log_test.cpp index e41af1f5b83c3bd9835e8f400704bbf209fcdc0d..269e1fe2e1a65d5a788b9550e3f2005a2c49bbb6 100644 --- a/common_components/log/tests/log_test.cpp +++ b/common_components/log/tests/log_test.cpp @@ -55,6 +55,11 @@ HWTEST_F_L0(LogTest, ConvertFromRuntime_Default_ReturnsDebug) { Level result = Log::ConvertFromRuntime(static_cast(999)); EXPECT_EQ(result, Level::DEBUG); } + +HWTEST_F_L0(LogTest, PrettyOrderMathNano) { + std::string result = PrettyOrderMathNano(1000000000000, "s"); + EXPECT_EQ(result, "1000s"); +} } namespace common { diff --git a/common_components/mutator/tests/mutator_manager_test.cpp b/common_components/mutator/tests/mutator_manager_test.cpp index d6a6f79fc2f0f753a093559f256b085ff2ab88c4..b1dc236bf31e7f6b2b87a5d5959f59f921a34560 100755 --- a/common_components/mutator/tests/mutator_manager_test.cpp +++ b/common_components/mutator/tests/mutator_manager_test.cpp @@ -27,6 +27,16 @@ protected: void TearDown() override {} }; +HWTEST_F_L0(MutatorManagerTest, BindMutatorOnly_Test1) +{ + MutatorManager *managerPtr = new MutatorManager(); + Mutator mutator; + managerPtr->UnbindMutatorOnly(); + bool res = managerPtr->BindMutatorOnly(&mutator); + ASSERT_TRUE(res); + delete managerPtr; +} + HWTEST_F_L0(MutatorManagerTest, IsRuntimeThread_Test1) { ThreadLocalData* localData = ThreadLocal::GetThreadLocalData(); diff --git a/common_components/objects/tests/base_string_test.cpp b/common_components/objects/tests/base_string_test.cpp index ae004c97c0017e4b38137c093070a14ab71618d5..5a7f68d229c90c0e6cd049fbbb90f32f57b64dd4 100755 --- a/common_components/objects/tests/base_string_test.cpp +++ b/common_components/objects/tests/base_string_test.cpp @@ -22,6 +22,105 @@ namespace common::test { class BaseStringTest : public common::test::BaseTestWithScope { }; +HWTEST_F_L0(BaseStringTest, IndexOf_TEST5) +{ + const uint8_t lhs[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs[] = {'a', 'b', 'c'}; + Span lhsSp(lhs, 5); + Span rhsSp(rhs, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp, rhsSp, 0, 4), 0); + + const uint8_t lhs1[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs1[] = {'c', 'd'}; + Span lhsSp1(lhs1, 5); + Span rhsSp1(rhs1, 2); + EXPECT_EQ(BaseString::IndexOf(lhsSp1, rhsSp1, 0, 4), 2); + + const uint8_t lhs2[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs2[] = {'x', 'y', 'z'}; + Span lhsSp2(lhs2, 5); + Span rhsSp2(rhs2, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp2, rhsSp2, 0, 4), -1); + + const uint8_t lhs3[] = {'a', 'b', 'a', 'b', 'c'}; + const uint16_t rhs3[] = {'a', 'b', 'c'}; + Span lhsSp3(lhs3, 5); + Span rhsSp3(rhs3, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp3, rhsSp3, 0, 4), 2); + + const uint8_t lhs4[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs4[] = {'a', 'b', 'x'}; + Span lhsSp4(lhs4, 5); + Span rhsSp4(rhs4, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp4, rhsSp4, 0, 4), -1); +} + +HWTEST_F_L0(BaseStringTest, IndexOf_TEST6) +{ + const uint16_t lhs[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs[] = {'a', 'b', 'c'}; + Span lhsSp(lhs, 5); + Span rhsSp(rhs, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp, rhsSp, 0, 4), 0); + + const uint16_t lhs1[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs1[] = {'c', 'd'}; + Span lhsSp1(lhs1, 5); + Span rhsSp1(rhs1, 2); + EXPECT_EQ(BaseString::IndexOf(lhsSp1, rhsSp1, 0, 4), 2); + + const uint16_t lhs2[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs2[] = {'x', 'y', 'z'}; + Span lhsSp2(lhs2, 5); + Span rhsSp2(rhs2, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp2, rhsSp2, 0, 4), -1); + + const uint16_t lhs3[] = {'a', 'b', 'a', 'b', 'c'}; + const uint16_t rhs3[] = {'a', 'b', 'c'}; + Span lhsSp3(lhs3, 5); + Span rhsSp3(rhs3, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp3, rhsSp3, 0, 4), 2); + + const uint16_t lhs4[] = {'a', 'b', 'c', 'd', 'e'}; + const uint16_t rhs4[] = {'a', 'b', 'x'}; + Span lhsSp4(lhs4, 5); + Span rhsSp4(rhs4, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp4, rhsSp4, 0, 4), -1); +} + +HWTEST_F_L0(BaseStringTest, IndexOf_TEST7) +{ + const uint16_t lhs[] = {'a', 'b', 'c', 'd', 'e'}; + const uint8_t rhs[] = {'a', 'b', 'c'}; + Span lhsSp(lhs, 5); + Span rhsSp(rhs, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp, rhsSp, 0, 4), 0); + + const uint16_t lhs1[] = {'a', 'b', 'c', 'd', 'e'}; + const uint8_t rhs1[] = {'c', 'd'}; + Span lhsSp1(lhs1, 5); + Span rhsSp1(rhs1, 2); + EXPECT_EQ(BaseString::IndexOf(lhsSp1, rhsSp1, 0, 4), 2); + + const uint16_t lhs2[] = {'a', 'b', 'c', 'd', 'e'}; + const uint8_t rhs2[] = {'x', 'y', 'z'}; + Span lhsSp2(lhs2, 5); + Span rhsSp2(rhs2, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp2, rhsSp2, 0, 4), -1); + + const uint16_t lhs3[] = {'a', 'b', 'a', 'b', 'c'}; + const uint8_t rhs3[] = {'a', 'b', 'c'}; + Span lhsSp3(lhs3, 5); + Span rhsSp3(rhs3, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp3, rhsSp3, 0, 4), 2); + + const uint16_t lhs4[] = {'a', 'b', 'c', 'd', 'e'}; + const uint8_t rhs4[] = {'a', 'b', 'x'}; + Span lhsSp4(lhs4, 5); + Span rhsSp4(rhs4, 3); + EXPECT_EQ(BaseString::IndexOf(lhsSp4, rhsSp4, 0, 4), -1); +} + HWTEST_F_L0(BaseStringTest, IsUtf8EqualsUtf16_TEST0) { const uint8_t utf8_01[] = {0xF0, 0xE0, 0xC0}; diff --git a/common_components/tests/ohos_test.xml b/common_components/tests/ohos_test.xml index a9332b249edfadefb88244a85a60ce144a938823..7b7e1b878fb4d62bfe5431dc8a12f12f6715341a 100644 --- a/common_components/tests/ohos_test.xml +++ b/common_components/tests/ohos_test.xml @@ -43,6 +43,11 @@