diff --git a/userspace/libsinsp/test/CMakeLists.txt b/userspace/libsinsp/test/CMakeLists.txt index 1b96c79d2e..1d5342aa8a 100644 --- a/userspace/libsinsp/test/CMakeLists.txt +++ b/userspace/libsinsp/test/CMakeLists.txt @@ -17,13 +17,15 @@ # include_directories("${GTEST_INCLUDE_DIR}") +include_directories("..") add_executable(unit-test-libsinsp - testy_test_face.ut.cpp + cgroup_list_counter.ut.cpp ) target_link_libraries(unit-test-libsinsp "${GTEST_MAIN_LIB}" + sinsp ) add_custom_target(run-unit-test-libsinsp diff --git a/userspace/libsinsp/test/cgroup_list_counter.ut.cpp b/userspace/libsinsp/test/cgroup_list_counter.ut.cpp new file mode 100644 index 0000000000..bd6322d7c5 --- /dev/null +++ b/userspace/libsinsp/test/cgroup_list_counter.ut.cpp @@ -0,0 +1,65 @@ +/* +Copyright (C) 2019 Sysdig Inc. + +This file is part of sysdig. + +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 + +TEST(cgroup_list_counter_test, basic) +{ + libsinsp::cgroup_list_counter counter; + ASSERT_EQ(8, counter("0-5,8,14")); + ASSERT_EQ(1, counter("5")); + ASSERT_EQ(6, counter("9-14")); +} + +TEST(cgroup_list_counter_test, invalid_value) +{ + libsinsp::cgroup_list_counter counter; + ASSERT_EQ(-1, counter("")); + ASSERT_EQ(-1, counter(",1")); +} + +TEST(cgroup_list_counter_test, invalid_range_missing_number) +{ + libsinsp::cgroup_list_counter counter; + ASSERT_EQ(-1, counter("-5,8,14")); + ASSERT_EQ(-1, counter("1,-5,8,14")); + ASSERT_EQ(-1, counter("1,4-,14")); + ASSERT_EQ(-1, counter("1,4-")); +} + +TEST(cgroup_list_counter_test, invalid_range_double_dash) +{ + libsinsp::cgroup_list_counter counter; + ASSERT_EQ(-1, counter("1,4-5-6,14")); +} + +TEST(cgroup_list_counter_test, invalid_range_wrong_order) +{ + libsinsp::cgroup_list_counter counter; + ASSERT_EQ(-1, counter("1,6-5,14")); +} + +TEST(cgroup_list_counter_test, not_a_number) +{ + libsinsp::cgroup_list_counter counter; + ASSERT_EQ(-1, counter("1,5-a,14")); +} + + diff --git a/userspace/libsinsp/test/testy_test_face.ut.cpp b/userspace/libsinsp/test/testy_test_face.ut.cpp deleted file mode 100644 index b8c3912df8..0000000000 --- a/userspace/libsinsp/test/testy_test_face.ut.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* -Copyright (C) 2019 Sysdig Inc. - -This file is part of sysdig. - -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 - -/** - * Ensure that tests are being tested - */ -TEST(testy_test_face_test, basic) -{ - ASSERT_TRUE(true); -}