Add UTCs for GetMatches* 80/318380/2
authorYoungsun Suh <youngsun.suh@samsung.com>
Fri, 27 Sep 2024 08:21:11 +0000 (17:21 +0900)
committerYoungsun Suh <youngsun.suh@samsung.com>
Fri, 27 Sep 2024 08:26:42 +0000 (17:26 +0900)
Change-Id: Ib0eb330a970e94b54a1addec2a444a4c761c76a0

automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls-BridgeUp.cpp

index d717b2aeb4125ba24e2d4a06d9ce5934efdb1190..0e2fa6181fffa29eb0398cca5a2f8565ff7939c8 100644 (file)
@@ -2089,3 +2089,185 @@ int UtcDaliIncludeHidden(void)
 
   END_TEST;
 }
+
+enum class MatchType : int32_t
+{
+  INVALID,
+  ALL,
+  ANY,
+  NONE,
+  EMPTY
+};
+
+enum class SortOrder : uint32_t
+{
+  INVALID,
+  CANONICAL,
+  FLOW,
+  TAB,
+  REVERSE_CANONICAL,
+  REVERSE_FLOW,
+  REVERSE_TAB,
+  LAST_DEFINED
+};
+
+static bool TestTouchCallback(Actor, const TouchEvent&)
+{
+  return true;
+}
+
+class TestMatcheableView
+{
+private:
+  Actor MakeClickableActor()
+  {
+    auto actor = Control::New();
+    actor.SetProperty(Actor::Property::SENSITIVE, true);
+    actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, true);
+    actor.TouchedSignal().Connect(TestTouchCallback);
+    return actor;
+  }
+
+  Actor MakeNonClickableActor()
+  {
+    auto actor = Control::New();
+    actor.SetProperty(Actor::Property::SENSITIVE, false);
+    return actor;
+  }
+
+  Actor MakeContainer(bool isClickable, std::string label)
+  {
+    Actor   container = isClickable ? MakeClickableActor() : MakeNonClickableActor();
+    Vector4 color(0.5f, 0.6f, 0.5f, 1.0f);
+    container.SetProperty(Actor::Property::COLOR, color);
+    container.SetProperty(Actor::Property::VISIBLE, true);
+
+    // button
+    auto button = PushButton::New();
+    button.SetProperty(Actor::Property::POSITION, Vector2(0.f, 0.f));
+    button.SetProperty(Actor::Property::SIZE, Vector2(10.f, 10.f));
+    button.SetProperty(Actor::Property::VISIBLE, true);
+    container.Add(button);
+
+    // text label
+    auto text = TextLabel::New(label);
+    text.SetProperty(Actor::Property::VISIBLE, true);
+    container.Add(text);
+
+    return container;
+  };
+
+public:
+  TestMatcheableView()
+  {
+    view = TableView::New(N, N);                                      // N by N grid.
+    view.SetProperty(Actor::Property::SIZE, Vector2(480.0f, 800.0f)); // full screen
+
+    for(int i = 0; i < N; ++i)
+    {
+      for(int j = 0; j < N; ++j)
+      {
+        bool        isClickable = (i * N + j) % 2;
+        std::string label       = "test_" + std::to_string(i) + "_" + std::to_string(j);
+        view.AddChild(MakeContainer(isClickable, std::move(label)), TableView::CellPosition(i, j));
+      }
+    }
+  }
+
+  TableView        view;
+  static const int N{48};
+};
+
+static Accessibility::Collection::MatchRule GetMatchRule(std::vector<Accessibility::State> states, std::vector<Accessibility::Role> roles)
+{
+  Accessibility::States  statesRule;
+  MatchType              stateMatchType = MatchType::INVALID;
+  std::array<int32_t, 2> statesConverted{0, 0};
+  if(!states.empty())
+  {
+    for(auto state : states)
+    {
+      statesRule[state] = true;
+    }
+    const auto statesRaw = statesRule.GetRawData();
+    statesConverted      = {static_cast<int32_t>(statesRaw[0]), static_cast<int32_t>(statesRaw[1])};
+    stateMatchType       = MatchType::ALL;
+  }
+
+  Accessibility::EnumBitSet<Accessibility::Role, Accessibility::Role::MAX_COUNT> rolesRule;
+  MatchType                                                                      roleMatchType = MatchType::INVALID;
+  std::array<int32_t, 4>                                                         rolesConverted{0, 0, 0, 0};
+  if(!roles.empty())
+  {
+    for(auto role : roles)
+    {
+      rolesRule[role] = true;
+    }
+    const auto rolesRaw = rolesRule.GetRawData();
+    rolesConverted      = {static_cast<int32_t>(rolesRaw[0]), static_cast<int32_t>(rolesRaw[1]), static_cast<int32_t>(rolesRaw[2]), static_cast<int32_t>(rolesRaw[3])};
+    roleMatchType       = MatchType::ALL;
+  }
+
+  return {
+    std::move(statesConverted),
+    static_cast<int32_t>(stateMatchType),
+    {},
+    static_cast<int32_t>(MatchType::INVALID),
+    std::move(rolesConverted),
+    static_cast<int32_t>(roleMatchType),
+    {},
+    static_cast<int32_t>(MatchType::INVALID),
+    false};
+}
+
+int UtcDaliGetMatches(void)
+{
+  ToolkitTestApplication application;
+
+  Dali::Accessibility::TestEnableSC(true);
+
+  application.GetScene().Add(TestMatcheableView().view);
+  application.SendNotification();
+  application.Render();
+
+  auto appAccessible = Accessibility::Bridge::GetCurrentBridge()->GetApplication();
+  DALI_TEST_CHECK(appAccessible);
+  auto collection = dynamic_cast<Accessibility::Collection*>(appAccessible);
+  DALI_TEST_CHECK(collection);
+
+  auto       rule          = GetMatchRule({Accessibility::State::SENSITIVE, Accessibility::State::SHOWING}, {});
+  auto       results       = collection->GetMatches(std::move(rule), static_cast<uint32_t>(SortOrder::CANONICAL), 0);
+  const auto numContainers = TestMatcheableView::N * TestMatcheableView::N;
+  DALI_TEST_CHECK(results.size() == 1 + numContainers / 2 + numContainers); // 1 (root) + num(half of containers) + num(buttons);
+
+  Dali::Accessibility::TestEnableSC(false);
+
+  END_TEST;
+}
+
+int UtcDaliGetMatchesInMatches(void)
+{
+  ToolkitTestApplication application;
+
+  Dali::Accessibility::TestEnableSC(true);
+
+  application.GetScene().Add(TestMatcheableView().view);
+  application.SendNotification();
+  application.Render();
+
+  auto appAccessible = Accessibility::Bridge::GetCurrentBridge()->GetApplication();
+  DALI_TEST_CHECK(appAccessible);
+  auto collection = dynamic_cast<Accessibility::Collection*>(appAccessible);
+  DALI_TEST_CHECK(collection);
+
+  auto rule1   = GetMatchRule({Accessibility::State::SENSITIVE, Accessibility::State::SHOWING}, {});
+  auto rule2   = GetMatchRule({Accessibility::State::SHOWING}, {Accessibility::Role::LABEL});
+  auto results = collection->GetMatchesInMatches(std::move(rule1), std::move(rule2), static_cast<uint32_t>(SortOrder::CANONICAL), 0, 0);
+
+  const auto numLabels = TestMatcheableView::N * TestMatcheableView::N;
+  DALI_TEST_CHECK(results.size() == numLabels); // text labels
+
+  Dali::Accessibility::TestEnableSC(false);
+
+  END_TEST;
+}