From 4b1e8446b78f324a24b2ea9005857c7d5a14b899 Mon Sep 17 00:00:00 2001 From: PengZheng Date: Fri, 8 Dec 2023 17:52:38 +0800 Subject: [PATCH] Add more tests for filter parsing. --- .../src/FilterErrorInjectionTestSuite.cc | 8 ++++++++ libs/utils/gtest/src/FilterTestSuite.cc | 20 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libs/utils/gtest/src/FilterErrorInjectionTestSuite.cc b/libs/utils/gtest/src/FilterErrorInjectionTestSuite.cc index fc22c898c..add870087 100644 --- a/libs/utils/gtest/src/FilterErrorInjectionTestSuite.cc +++ b/libs/utils/gtest/src/FilterErrorInjectionTestSuite.cc @@ -132,6 +132,14 @@ TEST_F(FilterErrorInjectionTestSuite, ErrorWithCallocTest) { //Then the filter creation should fail, because it cannot calloc mem for an internal struct (converted types) filter = celix_filter_create(filterStr); EXPECT_EQ(nullptr, filter); + + //Given an error injection for calloc + celix_ei_expect_calloc((void*)celix_filter_create, 2, nullptr); + //When creating a filter withAND filter node + filterStr = "(&(key1=value1)(key2=value2))"; + //Then the filter creation should fail, cecause it cannot calloc mem for an internal struct (converted types) + filter = celix_filter_create(filterStr); + EXPECT_EQ(nullptr, filter); } TEST_F(FilterErrorInjectionTestSuite, ErrorMemStreamTest) { diff --git a/libs/utils/gtest/src/FilterTestSuite.cc b/libs/utils/gtest/src/FilterTestSuite.cc index abbc6a20f..a6bad97ed 100644 --- a/libs/utils/gtest/src/FilterTestSuite.cc +++ b/libs/utils/gtest/src/FilterTestSuite.cc @@ -42,6 +42,7 @@ TEST_F(FilterTestSuite, CreateDestroyTest) { ASSERT_TRUE(filter != nullptr); celix_filter_destroy(filter); + celix_filter_destroy(nullptr); } TEST_F(FilterTestSuite, MissingOpenBracketsCreateTest) { @@ -144,15 +145,30 @@ TEST_F(FilterTestSuite, MiscInvalidCreateTest) { ASSERT_STREQ("strWith)inIt", (char*)filter->value); celix_filter_destroy(filter); - // test incomplete substring operator + // test parsing incomplete substring operator const char* str8 = "(test_attr3=*attr3\\"; filter = celix_filter_create(str8); ASSERT_TRUE(filter == nullptr); - // test incomplete substring operator + // test parsing incomplete substring operator const char* str9 = "(test_attr3=*attr3"; filter = celix_filter_create(str9); ASSERT_TRUE(filter == nullptr); + + // test parsing fiter missing ) + const char* str10 = "(|(a=b)"; + filter = celix_filter_create(str10); + ASSERT_TRUE(filter == nullptr); + + // test parsing APPROX operator missing value + const char* str11 = "(a~=)"; + filter = celix_filter_create(str11); + ASSERT_TRUE(filter == nullptr); + + // test parsing LESS operator missing value + const char* str12 = "(a<)"; + filter = celix_filter_create(str12); + ASSERT_TRUE(filter == nullptr); } TEST_F(FilterTestSuite, MatchEqualTest) {