Skip to content

Commit

Permalink
Add more tests for filter parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Dec 8, 2023
1 parent 27fe84a commit 4b1e844
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions libs/utils/gtest/src/FilterErrorInjectionTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 18 additions & 2 deletions libs/utils/gtest/src/FilterTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TEST_F(FilterTestSuite, CreateDestroyTest) {
ASSERT_TRUE(filter != nullptr);

celix_filter_destroy(filter);
celix_filter_destroy(nullptr);
}

TEST_F(FilterTestSuite, MissingOpenBracketsCreateTest) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4b1e844

Please sign in to comment.