Skip to content

Commit

Permalink
[Ci] update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Jun 26, 2024
1 parent 94795cb commit 5771603
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 76 deletions.
76 changes: 42 additions & 34 deletions src/test/CI/action_pub_sub.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include <ros/ros.h>

#include <gtest/gtest.h>

#include <atomic>
#include <gtest/gtest.h>
#include <ros/ros.h>

#include "ontologenius/OntologyManipulator.h"
#include "mementar/API/mementar/TimelineManipulator.h"
#include "mementar/API/mementar/OccasionsSubscriber.h"
#include "mementar/API/mementar/ActionsSubscriber.h"
#include "mementar/API/mementar/OccasionsSubscriber.h"
#include "mementar/API/mementar/TimelineManipulator.h"
#include "ontologenius/OntologyManipulator.h"

mementar::TimelineManipulator* time_ptr;

Expand Down Expand Up @@ -47,17 +45,18 @@ TEST(action_pub_sub_tests, TimelineManipulator_fact_start_subscriber)
r.sleep();
for(size_t i = 0; i < 2; i++)
{
time_ptr->action_feeder.insert("act_" + std::to_string(i));
time_ptr->action_feeder.insert("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insert("act_" + std::to_string(i));
time_ptr->action_feeder_.insert("other_act_" + std::to_string(i));
}
for(size_t i = 0; i < 2; i++)
{
time_ptr->action_feeder.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder.insertEnd("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("other_act_" + std::to_string(i));
}
r.sleep();

EXPECT_TRUE((cpt_fact_start == 1) && (cpt_fact_end == 0));
EXPECT_EQ(cpt_fact_start, 1);
EXPECT_EQ(cpt_fact_end, 0);
}

TEST(action_pub_sub_tests, TimelineManipulator_fact_end_subscriber)
Expand All @@ -71,17 +70,18 @@ TEST(action_pub_sub_tests, TimelineManipulator_fact_end_subscriber)
r.sleep();
for(size_t i = 10; i < 12; i++)
{
time_ptr->action_feeder.insert("act_" + std::to_string(i));
time_ptr->action_feeder.insert("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insert("act_" + std::to_string(i));
time_ptr->action_feeder_.insert("other_act_" + std::to_string(i));
}
for(size_t i = 10; i < 12; i++)
{
time_ptr->action_feeder.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder.insertEnd("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("other_act_" + std::to_string(i));
}
r.sleep();

EXPECT_TRUE((cpt_fact_start == 0) && (cpt_fact_end == 1));
EXPECT_EQ(cpt_fact_start, 0);
EXPECT_EQ(cpt_fact_end, 1);
}

TEST(action_pub_sub_tests, TimelineManipulator_action_start_subscriber)
Expand All @@ -95,17 +95,18 @@ TEST(action_pub_sub_tests, TimelineManipulator_action_start_subscriber)
r.sleep();
for(size_t i = 20; i < 22; i++)
{
time_ptr->action_feeder.insert("act_" + std::to_string(i));
time_ptr->action_feeder.insert("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insert("act_" + std::to_string(i));
time_ptr->action_feeder_.insert("other_act_" + std::to_string(i));
}
for(size_t i = 20; i < 22; i++)
{
time_ptr->action_feeder.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder.insertEnd("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("other_act_" + std::to_string(i));
}
r.sleep();

EXPECT_TRUE((cpt_act_start == 1) && (cpt_act_end == 0));
EXPECT_EQ(cpt_act_start, 1);
EXPECT_EQ(cpt_act_end, 0);
}

TEST(action_pub_sub_tests, TimelineManipulator_action_end_subscriber)
Expand All @@ -119,17 +120,18 @@ TEST(action_pub_sub_tests, TimelineManipulator_action_end_subscriber)
r.sleep();
for(size_t i = 30; i < 32; i++)
{
time_ptr->action_feeder.insert("act_" + std::to_string(i));
time_ptr->action_feeder.insert("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insert("act_" + std::to_string(i));
time_ptr->action_feeder_.insert("other_act_" + std::to_string(i));
}
for(size_t i = 30; i < 32; i++)
{
time_ptr->action_feeder.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder.insertEnd("other_act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("act_" + std::to_string(i));
time_ptr->action_feeder_.insertEnd("other_act_" + std::to_string(i));
}
r.sleep();

EXPECT_TRUE((cpt_act_start == 0) && (cpt_act_end == 1));
EXPECT_EQ(cpt_act_start, 0);
EXPECT_EQ(cpt_act_end, 1);
}

TEST(action_pub_sub_tests, TimelineManipulator_action_start_end_subscriber)
Expand All @@ -145,27 +147,33 @@ TEST(action_pub_sub_tests, TimelineManipulator_action_start_end_subscriber)
r.sleep();
for(size_t i = 40; i < 42; i++)
{
time_ptr->action_feeder.insert("act_" + std::to_string(i), time(0), time(0) + 2);
time_ptr->action_feeder.insert("other_act_" + std::to_string(i), time(0), time(0) + 2);
time_ptr->action_feeder_.insert("act_" + std::to_string(i), time(0), time(0) + 2);
time_ptr->action_feeder_.insert("other_act_" + std::to_string(i), time(0), time(0) + 2);
}
r.sleep();

EXPECT_TRUE((cpt_act_start == 1) && (cpt_act_end == 1));
EXPECT_EQ(cpt_act_start, 1);
EXPECT_EQ(cpt_act_end, 1);
}

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

ros::NodeHandle n;
// std::thread th([]() { mementar::compat::mem_ros::Node::get().spin(); });
std::thread th([]() { ros::spin(); });

onto::OntologyManipulator onto;
mementar::TimelineManipulator timeline(&n);
mementar::TimelineManipulator timeline;
timeline.waitInit();
time_ptr = &timeline;

onto.close();

testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();

return 0;
// mementar::compat::mem_ros::Node::shutdown();
// th.join();

return RUN_ALL_TESTS();
}
58 changes: 34 additions & 24 deletions src/test/CI/fact_pub_sub.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include <ros/ros.h>

#include <gtest/gtest.h>

#include <atomic>
#include <gtest/gtest.h>
#include <ros/ros.h>

#include "ontologenius/OntologyManipulator.h"
#include "include/mementar/API/mementar/TimelineManipulator.h"
#include "include/mementar/API/mementar/OccasionsSubscriber.h"
#include "include/mementar/API/mementar/TimelineManipulator.h"
#include "ontologenius/OntologyManipulator.h"

onto::OntologyManipulator* onto_ptr;
mementar::TimelineManipulator* time_ptr;
Expand Down Expand Up @@ -42,12 +40,13 @@ TEST(fact_pub_sub_tests, TimelineManipulator_one_subscriber)
r.sleep();
for(size_t i = 0; i < 5; i++)
{
time_ptr->fact_feeder.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder.insert(mementar::Fact("d", "e", "f"));
time_ptr->fact_feeder_.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder_.insert(mementar::Fact("d", "e", "f"));
}
r.sleep();

EXPECT_TRUE((cpt_abc == 3) && (cpt_def == 0));
EXPECT_EQ(cpt_abc, 3);
EXPECT_EQ(cpt_def, 0);
}

TEST(fact_pub_sub_tests, TimelineManipulator_two_subscriber)
Expand All @@ -63,12 +62,13 @@ TEST(fact_pub_sub_tests, TimelineManipulator_two_subscriber)
r.sleep();
for(size_t i = 0; i < 5; i++)
{
time_ptr->fact_feeder.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder.insert(mementar::Fact("d", "e", "f"));
time_ptr->fact_feeder_.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder_.insert(mementar::Fact("d", "e", "f"));
}
r.sleep();

EXPECT_TRUE((cpt_abc == 4) && (cpt_def == 1));
EXPECT_EQ(cpt_abc, 4);
EXPECT_EQ(cpt_def, 1);
}

TEST(fact_pub_sub_tests, TimelineManipulator_three_subscriber)
Expand All @@ -85,12 +85,13 @@ TEST(fact_pub_sub_tests, TimelineManipulator_three_subscriber)
r.sleep();
for(size_t i = 0; i < 5; i++)
{
time_ptr->fact_feeder.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder.insert(mementar::Fact("d", "e", "f"));
time_ptr->fact_feeder_.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder_.insert(mementar::Fact("d", "e", "f"));
}
r.sleep();

EXPECT_TRUE((cpt_abc == 6) && (cpt_def == 1));
EXPECT_EQ(cpt_abc, 6);
EXPECT_EQ(cpt_def, 1);
}

TEST(fact_pub_sub_tests, TimelineManipulator_pattern_subscriber)
Expand All @@ -104,19 +105,21 @@ TEST(fact_pub_sub_tests, TimelineManipulator_pattern_subscriber)
r.sleep();
for(size_t i = 0; i < 5; i++)
{
time_ptr->fact_feeder.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder.insert(mementar::Fact("a", "b", "d"));
time_ptr->fact_feeder_.insert(mementar::Fact("a", "b", "c"));
time_ptr->fact_feeder_.insert(mementar::Fact("a", "b", "d"));
}
r.sleep();

EXPECT_TRUE((cpt_abc == 10) && (cpt_def == 0));
EXPECT_EQ(cpt_abc, 10);
EXPECT_EQ(cpt_def, 0);
}

TEST(fact_pub_sub_tests, OntologyManipulator_one_subscriber)
{
ros::Rate r(0.9);
onto_ptr->feeder.addInheritage("a", "cube");
onto_ptr->feeder.removeProperty("a", "b", "c");
onto_ptr->feeder.waitUpdate(1500);

mementar::OccasionsSubscriber sub1(&factCallbackABC);
sub1.subscribe(mementar::Fact("a", "b", "c"), 1);
Expand All @@ -127,14 +130,16 @@ TEST(fact_pub_sub_tests, OntologyManipulator_one_subscriber)
onto_ptr->feeder.addProperty("a", "b", "c");
r.sleep();

EXPECT_TRUE((cpt_abc == 1) && (cpt_def == 0));
EXPECT_EQ(cpt_abc, 1);
EXPECT_EQ(cpt_def, 0);
}

TEST(fact_pub_sub_tests, OntologyManipulator_inv_subscriber)
{
ros::Rate r(0.9);
onto_ptr->feeder.addInheritage("a", "cube");
onto_ptr->feeder.removeProperty("a", "isOn", "c");
onto_ptr->feeder.waitUpdate(1500);

mementar::OccasionsSubscriber sub1(&factCallbackCisUnderA);
sub1.subscribe(mementar::Fact("c", "isUnder", "a"), 1);
Expand All @@ -144,23 +149,28 @@ TEST(fact_pub_sub_tests, OntologyManipulator_inv_subscriber)
onto_ptr->feeder.addProperty("a", "isOn", "c");
r.sleep();

EXPECT_TRUE(cpt_cIsUndera == 1);
EXPECT_EQ(cpt_cIsUndera, 1);
}

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

ros::NodeHandle n;
// std::thread th([]() { mementar::compat::mem_ros::Node::get().spin(); });
std::thread th([]() { ros::spin(); });

onto::OntologyManipulator onto;
onto_ptr = &onto;
mementar::TimelineManipulator timeline(&n);
mementar::TimelineManipulator timeline;
timeline.waitInit();
time_ptr = &timeline;

onto.close();

testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();

return 0;
// mementar::compat::mem_ros::Node::shutdown();
// th.join();

return RUN_ALL_TESTS();
}
Loading

0 comments on commit 5771603

Please sign in to comment.