Skip to content

Commit

Permalink
[CI] feature subscription test
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Nov 7, 2024
1 parent 0f2b7cf commit 0df63f0
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ if($ENV{ROS_VERSION} STREQUAL "1")
target_include_directories(onto_feature_multi_test PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(onto_feature_multi_test ontologenius_lib ${catkin_LIBRARIES})

add_rostest_gtest(onto_feature_subscription_test test/feature_subscription.test src/tests/CI/feature_subscription_test.cpp)
target_include_directories(onto_feature_subscription_test PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(onto_feature_subscription_test ontologenius_lib ${catkin_LIBRARIES})

add_rostest_gtest(onto_reasoning_anonymous_class_test test/reasoning_anonymous_class.test src/tests/CI/reasoning_anonymous_class_test.cpp)
set_target_properties(onto_reasoning_anonymous_class_test PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED ON)
target_include_directories(onto_reasoning_anonymous_class_test PRIVATE ${catkin_INCLUDE_DIRS})
Expand Down
24 changes: 24 additions & 0 deletions files/test_individuals.owl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@



<!-- test_individuals#cube2 -->

<owl:NamedIndividual rdf:about="test_individuals#cube1">
<rdf:type rdf:resource="objects#Cube"/>
</owl:NamedIndividual>



<!-- test_individuals#table1 -->

<owl:NamedIndividual rdf:about="test_individuals#table1">
<rdf:type rdf:resource="objects#Table"/>
</owl:NamedIndividual>



<!-- test_individuals#table2 -->

<owl:NamedIndividual rdf:about="test_individuals#table2">
<rdf:type rdf:resource="objects#Table"/>
</owl:NamedIndividual>



<!-- test_individuals#green_cube -->

<owl:NamedIndividual rdf:about="test_individuals#green_cube">
Expand Down
183 changes: 183 additions & 0 deletions src/tests/CI/feature_subscription_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#include <algorithm>
#include <cstddef>
#include <gtest/gtest.h>
#include <ros/ros.h>
#include <sstream>
#include <string>
#include <vector>

#include "ontologenius/API/ontologenius/OntologyManipulator.h"

onto::OntologyManipulator* onto_ptr;
std::atomic<int> done_add;
std::atomic<int> done_del;
std::atomic<int> done_any;

#define NB_TIME 20 // 2s

void callbackAdd(const std::string& fact)
{
done_add++;
}

void callbackDel(const std::string& fact)
{
done_del++;
}

void callbackAny(const std::string& fact)
{
done_any++;
}

TEST(feature_subscription, exact_one_pattern)
{
done_add = 0;
done_del = 0;
onto_ptr->subscriber.subscribe("[add]cube1|isOn|table1", &callbackAdd, 1);

usleep(1000);

for(size_t i = 0; i < 2; i++)
{
onto_ptr->feeder.addProperty("cube1", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table1");
}

usleep(1000);

EXPECT_EQ(done_add, 1);
EXPECT_EQ(done_del, 0);
}

TEST(feature_subscription, exact_invert_pattern)
{
done_add = 0;
done_del = 0;
onto_ptr->subscriber.subscribe("[add]table1|isUnder|cube1", &callbackAdd, 2);

usleep(1000);

for(size_t i = 0; i < 2; i++)
{
onto_ptr->feeder.addProperty("cube1", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table1");
}

usleep(1000);

EXPECT_EQ(done_add, 2);
EXPECT_EQ(done_del, 0);
}

TEST(feature_subscription, exact_two_pattern)
{
done_add = 0;
done_del = 0;
onto_ptr->subscriber.subscribe("[add]cube1|isOn|table1", &callbackAdd, 1);
onto_ptr->subscriber.subscribe("[del]cube1|isOn|table1", &callbackDel, 1);

usleep(1000);

for(size_t i = 0; i < 2; i++)
{
onto_ptr->feeder.addProperty("cube1", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table1");
}
onto_ptr->feeder.waitUpdate(500);
for(size_t i = 0; i < 2; i++)
{
onto_ptr->feeder.removeProperty("cube1", "isOn", "table1");
onto_ptr->feeder.removeProperty("cube2", "isOn", "table1");
}

usleep(1000);

EXPECT_EQ(done_add, 1);
EXPECT_EQ(done_del, 1);
}

TEST(feature_subscription, abstract_pattern)
{
done_add = 0;
done_del = 0;
onto_ptr->subscriber.subscribe("[add]Cube|isOn|table1", &callbackAdd, 2);

usleep(1000);

onto_ptr->feeder.addProperty("cube1", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table1");

usleep(1000);

EXPECT_EQ(done_add, 2);
EXPECT_EQ(done_del, 0);
}

TEST(feature_subscription, variable_pattern)
{
done_add = 0;
done_del = 0;
onto_ptr->subscriber.subscribe("[add]?|isOn|table1", &callbackAdd, 3);

usleep(1000);

onto_ptr->feeder.addProperty("cube1", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table2");

usleep(1000);

EXPECT_EQ(done_add, 2);
EXPECT_EQ(done_del, 0);
}

TEST(feature_subscription, variable_abstract_pattern)
{
done_add = 0;
done_del = 0;
onto_ptr->subscriber.subscribe("[add]?|isOn|Table", &callbackAdd, 3);

usleep(1000);

onto_ptr->feeder.addProperty("cube1", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table1");
onto_ptr->feeder.addProperty("cube2", "isOn", "table2");

usleep(1000);

EXPECT_EQ(done_add, 3);
EXPECT_EQ(done_del, 0);
}

TEST(feature_subscription, any_pattern)
{
done_any = 0;

onto_ptr->subscriber.subscribe("[?]cube1|isOn|table1", &callbackAny, 1);

usleep(1000);

onto_ptr->feeder.addProperty("cube1", "isOn", "table1");

onto_ptr->feeder.waitUpdate(500);

onto_ptr->feeder.removeProperty("cube1", "isOn", "table1");

usleep(1000);

EXPECT_EQ(done_any, 1);
}

int main(int argc, char** argv)
{
ros::init(argc, argv, "ontologenius_feature_subscription_test");

onto::OntologyManipulator onto;
onto_ptr = &onto;

onto.close();

testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Empty file removed src/tests/CI/subscription.cpp
Empty file.
8 changes: 8 additions & 0 deletions test/feature_subscription.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<launch>
<include file="$(find ontologenius)/launch/ontologenius.launch">
<arg name="intern_file" default="none"/>
<arg name="display" default="false"/>
</include>
<arg name='TESTDURATION' value='60' />
<test pkg="ontologenius" type="onto_feature_subscription_test" test-name="feature_subscription_test" time-limit="$(arg TESTDURATION)" retry="0" />
</launch>

0 comments on commit 0df63f0

Please sign in to comment.