Merge "Fix to do not update state of render task in case of uploadOnly" into devel...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Rect.cpp
index 028d183..349989c 100644 (file)
@@ -1,24 +1,25 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2020 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 <iostream>
-
-#include <stdlib.h>
-#include <dali/dali.h>
 #include <dali-test-suite-utils.h>
+#include <dali/public-api/dali-core.h>
+#include <stdlib.h>
+
+#include <iostream>
 
 using namespace Dali;
 
@@ -32,7 +33,6 @@ void utc_dali_rect_cleanup(void)
   test_return_value = TET_PASS;
 }
 
-
 // Positive test case for a method
 int UtcDaliRectCons01(void)
 {
@@ -64,7 +64,7 @@ int UtcDaliRectCons03(void)
 
   Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
 
-  Rect<float> r2 = rect;
+  Rect<float> r2(rect);
 
   DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
   DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
@@ -77,9 +77,40 @@ int UtcDaliRectCons04(void)
 {
   TestApplication application;
 
+  Vector4 vec4(10.0f, 20.0f, 400.0f, 200.0f);
+
+  Rect<float> rect(vec4);
+
+  DALI_TEST_EQUALS(rect.x, 10.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.y, 20.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.width, 400.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.height, 200.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliRectMoveConstructor(void)
+{
+  TestApplication application;
+
   Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
 
-  Rect<float> r2(rect);
+  Rect<float> r2 = std::move(rect);
+
+  DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(r2.width, 400.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(r2.height, 200.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliRectMoveAssignmentOperator(void)
+{
+  TestApplication application;
+
+  Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
+
+  Rect<float> r2;
+  r2 = std::move(rect);
 
   DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
   DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
@@ -88,6 +119,38 @@ int UtcDaliRectCons04(void)
   END_TEST;
 }
 
+int UtcDaliRectAssignmentOperatorRect(void)
+{
+  TestApplication application;
+
+  Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
+
+  Rect<float> r2;
+  r2 = rect;
+
+  DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(r2.width, 400.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(r2.height, 200.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliRectAssignmentOperatorVector4(void)
+{
+  TestApplication application;
+
+  Vector4 vec4(10.0f, 20.0f, 400.0f, 200.0f);
+
+  Rect<float> rect;
+  rect = vec4;
+
+  DALI_TEST_EQUALS(rect.x, 10.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.y, 20.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.width, 400.0f, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(rect.height, 200.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
 int UtcDaliRectSet(void)
 {
   TestApplication application;
@@ -107,12 +170,12 @@ int UtcDaliRectIsEmpty(void)
 {
   TestApplication application;
 
-  Rect<int>   ri;
-  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
-  Rect<float> rf2;
-  Rect<float> rf3(10.0f, 20.0f, 0.0f, 200.0f);
-  Rect<float> rf4(10.0f, 20.0f, 400.0f, 0.0f);
-  Rect<double> rd(10.0, 20.0, 0.0, 200.0);
+  Rect<int>          ri;
+  Rect<float>        rf(10.0f, 20.0f, 400.0f, 200.0f);
+  Rect<float>        rf2;
+  Rect<float>        rf3(10.0f, 20.0f, 0.0f, 200.0f);
+  Rect<float>        rf4(10.0f, 20.0f, 400.0f, 0.0f);
+  Rect<double>       rd(10.0, 20.0, 0.0, 200.0);
   Rect<unsigned int> ru(0u, 0u, 4u, 0u);
 
   DALI_TEST_CHECK(!rf.IsEmpty());
@@ -125,6 +188,16 @@ int UtcDaliRectIsEmpty(void)
   END_TEST;
 }
 
+int UtcDaliRectLeft(void)
+{
+  TestApplication application;
+
+  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
+
+  DALI_TEST_EQUALS(rf.Left(), 10.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
 int UtcDaliRectRight(void)
 {
   TestApplication application;
@@ -135,6 +208,15 @@ int UtcDaliRectRight(void)
   END_TEST;
 }
 
+int UtcDaliRectTop(void)
+{
+  TestApplication application;
+
+  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
+
+  DALI_TEST_EQUALS(rf.Top(), 20.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
 
 int UtcDaliRectBottom(void)
 {
@@ -146,7 +228,6 @@ int UtcDaliRectBottom(void)
   END_TEST;
 }
 
-
 int UtcDaliRectArea(void)
 {
   TestApplication application;
@@ -157,16 +238,15 @@ int UtcDaliRectArea(void)
   END_TEST;
 }
 
-
 int UtcDaliRectIntersects(void)
 {
   TestApplication application;
 
-  Rect<float> rf1( 10.0f,  20.0f, 200.0f, 200.0f);
-  Rect<float> rf2( 10.0f, 120.0f, 200.0f, 200.0f);
-  Rect<float> rf3( 10.0f, -80.0f, 200.0f, 200.0f);
-  Rect<float> rf4(110.0f,  20.0f, 200.0f, 200.0f);
-  Rect<float> rf5(-90.0f,  20.0f, 200.0f, 200.0f);
+  Rect<float> rf1(10.0f, 20.0f, 200.0f, 200.0f);
+  Rect<float> rf2(10.0f, 120.0f, 200.0f, 200.0f);
+  Rect<float> rf3(10.0f, -80.0f, 200.0f, 200.0f);
+  Rect<float> rf4(110.0f, 20.0f, 200.0f, 200.0f);
+  Rect<float> rf5(-90.0f, 20.0f, 200.0f, 200.0f);
   Rect<float> rf6(1000.0f, 1200.0f, 10.0f, 10.0f);
 
   DALI_TEST_CHECK(rf1.Intersects(rf2));
@@ -177,26 +257,24 @@ int UtcDaliRectIntersects(void)
   END_TEST;
 }
 
-
-
 int UtcDaliRectContains(void)
 {
   TestApplication application;
 
-  Rect<float> rf1( 10.0f,  20.0f, 200.0f, 200.0f);
+  Rect<float> rf1(10.0f, 20.0f, 200.0f, 200.0f);
 
-  Rect<float> rf2( 10.0f, 120.0f, 200.0f, 200.0f);
-  Rect<float> rf3( 10.0f, -80.0f, 200.0f, 200.0f);
-  Rect<float> rf4(110.0f,  20.0f, 200.0f, 200.0f);
-  Rect<float> rf5(-90.0f,  20.0f, 200.0f, 200.0f);
+  Rect<float> rf2(10.0f, 120.0f, 200.0f, 200.0f);
+  Rect<float> rf3(10.0f, -80.0f, 200.0f, 200.0f);
+  Rect<float> rf4(110.0f, 20.0f, 200.0f, 200.0f);
+  Rect<float> rf5(-90.0f, 20.0f, 200.0f, 200.0f);
   Rect<float> rf6(1000.0f, 1200.0f, 10.0f, 10.0f);
 
-  Rect<float> rf7( 50.0f,  70.0f, 50.0f,   50.0f);
+  Rect<float> rf7(50.0f, 70.0f, 50.0f, 50.0f);
 
-  Rect<float> rf8(  10.0f,  20.0f, 100.0f, 100.0f);
-  Rect<float> rf9( 110.0f,  20.0f, 100.0f, 100.0f);
-  Rect<float> rf10( 110.0f, 120.0f, 100.0f, 100.0f);
-  Rect<float> rf11(  10.0f, 120.0f, 100.0f, 100.0f);
+  Rect<float> rf8(10.0f, 20.0f, 100.0f, 100.0f);
+  Rect<float> rf9(110.0f, 20.0f, 100.0f, 100.0f);
+  Rect<float> rf10(110.0f, 120.0f, 100.0f, 100.0f);
+  Rect<float> rf11(10.0f, 120.0f, 100.0f, 100.0f);
 
   DALI_TEST_CHECK(rf1.Contains(rf1));
   DALI_TEST_CHECK(!rf1.Contains(rf2));
@@ -214,22 +292,21 @@ int UtcDaliRectContains(void)
   END_TEST;
 }
 
-
 int UtcDaliRectOperatorNotEquals(void)
 {
   TestApplication application;
 
-  Rect<float> rf1( 10.0f,  20.0f, 200.0f, 200.0f);
-  Rect<float> rf2( 10.0f, 120.0f, 200.0f, 200.0f);
-  Rect<float> rf3( 10.0f, -80.0f, 200.0f, 200.0f);
-  Rect<float> rf4(110.0f,  20.0f, 200.0f, 200.0f);
-  Rect<float> rf5(-90.0f,  20.0f, 200.0f, 200.0f);
+  Rect<float> rf1(10.0f, 20.0f, 200.0f, 200.0f);
+  Rect<float> rf2(10.0f, 120.0f, 200.0f, 200.0f);
+  Rect<float> rf3(10.0f, -80.0f, 200.0f, 200.0f);
+  Rect<float> rf4(110.0f, 20.0f, 200.0f, 200.0f);
+  Rect<float> rf5(-90.0f, 20.0f, 200.0f, 200.0f);
   Rect<float> rf6(1000.0f, 1200.0f, 10.0f, 10.0f);
-  Rect<float> rf7( 50.0f,  70.0f, 50.0f,   50.0f);
-  Rect<float> rf8(  10.0f,  20.0f, 100.0f, 100.0f);
-  Rect<float> rf9( 110.0f,  20.0f, 100.0f, 100.0f);
-  Rect<float> rf10( 110.0f, 120.0f, 100.0f, 100.0f);
-  Rect<float> rf11(  10.0f, 120.0f, 100.0f, 100.0f);
+  Rect<float> rf7(50.0f, 70.0f, 50.0f, 50.0f);
+  Rect<float> rf8(10.0f, 20.0f, 100.0f, 100.0f);
+  Rect<float> rf9(110.0f, 20.0f, 100.0f, 100.0f);
+  Rect<float> rf10(110.0f, 120.0f, 100.0f, 100.0f);
+  Rect<float> rf11(10.0f, 120.0f, 100.0f, 100.0f);
 
   DALI_TEST_CHECK(rf1 != rf2);
   DALI_TEST_CHECK(rf1 != rf3);
@@ -244,20 +321,19 @@ int UtcDaliRectOperatorNotEquals(void)
   END_TEST;
 }
 
-
 int UtcDaliRectOperatorEquals(void)
 {
   TestApplication application;
 
-  Rect<float> rf1( 10.0f,  20.0f, 200.0f, 200.0f);
-  Rect<float> rf1p( 10.0f,  20.0f, 200.0f, 200.0f);
+  Rect<float> rf1(10.0f, 20.0f, 200.0f, 200.0f);
+  Rect<float> rf1p(10.0f, 20.0f, 200.0f, 200.0f);
 
-  Rect<float> rf2(110.0f,  20.0f, 200.0f, 200.0f);
-  Rect<float> rf3( 10.0f, 120.0f, 200.0f, 200.0f);
-  Rect<float> rf4( 10.0f,  20.0f, 300.0f, 200.0f);
-  Rect<float> rf5( 10.0f,  20.0f, 200.0f, 500.0f);
+  Rect<float> rf2(110.0f, 20.0f, 200.0f, 200.0f);
+  Rect<float> rf3(10.0f, 120.0f, 200.0f, 200.0f);
+  Rect<float> rf4(10.0f, 20.0f, 300.0f, 200.0f);
+  Rect<float> rf5(10.0f, 20.0f, 200.0f, 500.0f);
 
-  Rect<float> rf6( 0.0f,  0.0f, 9.0f, 10.0f);
+  Rect<float> rf6(0.0f, 0.0f, 9.0f, 10.0f);
 
   DALI_TEST_CHECK(rf1 == rf1p);
   DALI_TEST_CHECK(rf1 == rf1);
@@ -267,11 +343,25 @@ int UtcDaliRectOperatorEquals(void)
   DALI_TEST_CHECK(!(rf1 == rf5));
   DALI_TEST_CHECK(!(rf1 == rf6));
 
-
   // integers
-  Rect<int> ri1( 10,  20, 200, 200 );
-  Rect<int> ri1p( 10,  20, 200, 200 );
+  Rect<int> ri1(10, 20, 200, 200);
+  Rect<int> ri1p(10, 20, 200, 200);
 
   DALI_TEST_CHECK(ri1 == ri1p);
   END_TEST;
 }
+
+int UtcDaliRectOStreamOperatorP(void)
+{
+  TestApplication    application;
+  std::ostringstream oss;
+
+  Rect<int> rect(1, 2, 10, 10);
+
+  oss << rect;
+
+  std::string expectedOutput = "[1, 2, 10, 10]";
+
+  DALI_TEST_EQUALS(oss.str(), expectedOutput, TEST_LOCATION);
+  END_TEST;
+}