Added comparison ops for Graphics::Viewport and Rect2D 30/319130/5
authorDavid Steele <david.steele@samsung.com>
Tue, 15 Oct 2024 16:34:36 +0000 (17:34 +0100)
committerDavid Steele <david.steele@samsung.com>
Fri, 25 Oct 2024 10:20:31 +0000 (11:20 +0100)
Change-Id: Iebcd2ba4792cd4e6fad6423033fb4f592d32f2fc

automated-tests/src/dali-internal/CMakeLists.txt
automated-tests/src/dali-internal/utc-Dali-Internal-GraphicsAPI.cpp [new file with mode: 0644]
dali/graphics-api/graphics-types.h

index fa4bff7acd90522b4bf2bca813c40bead4f8f26c..9578d2f0a64f8c7a516f4eb79ec285cc1afa040b 100644 (file)
@@ -15,6 +15,7 @@ SET(TC_SOURCES
   utc-Dali-Internal-FixedSizeMemoryPool.cpp
   utc-Dali-Internal-FrustumCulling.cpp
   utc-Dali-Internal-Gesture.cpp
+  utc-Dali-Internal-GraphicsAPI.cpp
   utc-Dali-Internal-GpuBuffer.cpp
   utc-Dali-Internal-Handles.cpp
   utc-Dali-Internal-IndexedConstStringMap.cpp
diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-GraphicsAPI.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-GraphicsAPI.cpp
new file mode 100644 (file)
index 0000000..9f045d2
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ *
+ * 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 <dali-test-suite-utils.h>
+#include <dali/graphics-api/graphics-types.h>
+#include <stdlib.h>
+
+#include <iostream>
+
+using namespace Dali;
+
+void utc_dali_graphicsApi_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void utc_dali_graphicsApi_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliGraphicsApiRect2DOpEq(void)
+{
+  TestApplication application;
+
+  Graphics::Rect2D rect1, rect2;
+  Graphics::Rect2D zeroRect;
+  zeroRect.x      = 0;
+  zeroRect.y      = 0;
+  zeroRect.width  = 0;
+  zeroRect.height = 0;
+
+  DALI_TEST_CHECK(rect1 == zeroRect);
+
+  rect1.x      = 10;
+  rect1.y      = 20;
+  rect1.width  = 30;
+  rect1.height = 40;
+
+  rect2.x      = 10;
+  rect2.y      = 20;
+  rect2.width  = 30;
+  rect2.height = 40;
+
+  DALI_TEST_CHECK(rect1 == rect2);
+
+  END_TEST;
+}
+
+int UtcDaliGraphicsApiRect2DOpNotEq(void)
+{
+  TestApplication application;
+
+  Graphics::Rect2D rect1, rect2;
+  Graphics::Rect2D zeroRect;
+  zeroRect.x      = 0;
+  zeroRect.y      = 0;
+  zeroRect.width  = 0;
+  zeroRect.height = 0;
+
+  rect1.x      = 10;
+  rect1.y      = 20;
+  rect1.width  = 30;
+  rect1.height = 40;
+
+  DALI_TEST_CHECK(rect1 != zeroRect);
+  END_TEST;
+}
+
+int UtcDaliGraphicsApiViewportOpEq(void)
+{
+  TestApplication application;
+
+  Graphics::Viewport viewport1, viewport2, zeroViewport;
+
+  zeroViewport.x        = 0.f;
+  zeroViewport.y        = 0.f;
+  zeroViewport.width    = 0.f;
+  zeroViewport.height   = 0.f;
+  zeroViewport.minDepth = 0.f;
+  zeroViewport.maxDepth = 1.f;
+
+  DALI_TEST_CHECK(viewport1 == zeroViewport);
+
+  viewport1.x        = 10.f;
+  viewport1.y        = 20.f;
+  viewport1.width    = 30.f;
+  viewport1.height   = 40.f;
+  viewport1.minDepth = 0.0f;
+  viewport1.maxDepth = 1.0f;
+
+  viewport2.x        = 10.f;
+  viewport2.y        = 20.f;
+  viewport2.width    = 30.f;
+  viewport2.height   = 40.f;
+  viewport2.minDepth = 0.0f;
+  viewport2.maxDepth = 1.0f;
+
+  DALI_TEST_CHECK(viewport1 == viewport2);
+
+  END_TEST;
+}
+
+int UtcDaliGraphicsApiViewportOpNotEq(void)
+{
+  TestApplication application;
+
+  Graphics::Viewport zeroViewport, viewport1, viewport2;
+
+  zeroViewport.x        = 0.f;
+  zeroViewport.y        = 0.f;
+  zeroViewport.width    = 0.f;
+  zeroViewport.height   = 0.f;
+  zeroViewport.minDepth = 0.f;
+  zeroViewport.maxDepth = 1.f;
+
+  viewport1.x        = 10.f;
+  viewport1.y        = 20.f;
+  viewport1.width    = 30.f;
+  viewport1.height   = 40.f;
+  viewport1.minDepth = 0.0f;
+  viewport1.maxDepth = 1.0f;
+
+  DALI_TEST_CHECK(viewport1 != zeroViewport);
+
+  viewport2.x        = 10.f;
+  viewport2.y        = 20.f;
+  viewport2.width    = 30.f;
+  viewport2.height   = 40.f;
+  viewport2.minDepth = 0.0f;
+  viewport2.maxDepth = 1.0f;
+
+  DALI_TEST_CHECK(viewport1 == viewport2);
+
+  END_TEST;
+}
index 49f4101564776798b5fdfdc985ff027a337ef17c..4c749ea692a3dd8af13d1d9ee5da6eab31566b06 100644 (file)
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include <dali/public-api/images/pixel-data.h>
+#include <dali/public-api/math/math-utils.h>
 #include <dali/public-api/signals/callback.h>
 
 namespace Dali
@@ -70,6 +71,33 @@ struct Rect2D
   uint32_t height = 0;
 };
 
+/**
+ * @brief Equality operator.
+ *
+ * @param[in] lhs The first rectangle
+ * @param[in] rhs The second rectangle
+ * @return True if rectangles are not identical
+ */
+inline bool operator==(const Rect2D& lhs, const Rect2D& rhs)
+{
+  return (lhs.x == rhs.x) &&
+         (lhs.y == rhs.y) &&
+         (lhs.width == rhs.width) &&
+         (lhs.height == rhs.height);
+}
+
+/**
+ * @brief Inequality operator.
+ *
+ * @param[in] lhs The first rectangle
+ * @param[in] rhs The second rectangle
+ * @return True if rectangles are not identical
+ */
+inline bool operator!=(const Rect2D& lhs, const Rect2D& rhs)
+{
+  return !(lhs == rhs);
+}
+
 /**
  * @brief Structure represents area of viewport
  */
@@ -83,6 +111,35 @@ struct Viewport
   float maxDepth = 1.0f;
 };
 
+/**
+ * @brief Equality operator.
+ *
+ * @param[in] lhs The first rectangle
+ * @param[in] rhs The second rectangle
+ * @return True if rectangles are not identical
+ */
+inline bool operator==(const Viewport& lhs, const Viewport& rhs)
+{
+  return Equals(lhs.x, rhs.x) &&
+         Equals(lhs.y, rhs.y) &&
+         Equals(lhs.width, rhs.width) &&
+         Equals(lhs.height, rhs.height) &&
+         Equals(lhs.minDepth, rhs.minDepth) &&
+         Equals(lhs.maxDepth, rhs.maxDepth);
+}
+
+/**
+ * @brief Inequality operator.
+ *
+ * @param[in] lhs The first rectangle
+ * @param[in] rhs The second rectangle
+ * @return True if rectangles are not identical
+ */
+inline bool operator!=(const Viewport& lhs, const Viewport& rhs)
+{
+  return !(lhs == rhs);
+}
+
 /**
  * @brief Describes vertex attribute input rate
  */