From: David Steele Date: Fri, 17 Feb 2017 10:56:19 +0000 (+0000) Subject: Test harness: Moved CompareType<> templates to own header X-Git-Tag: dali_1.2.28~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F39%2F115339%2F2;p=platform%2Fcore%2Fuifw%2Fdali-core.git Test harness: Moved CompareType<> templates to own header Change-Id: I367a21562a7c6362a15a13bfcc6fc8fffeb37c3b --- diff --git a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h index 79d422b..03c788c 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h +++ b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h @@ -20,10 +20,13 @@ // EXTERNAL INCLUDES #include +#include #include +#include // INTERNAL INCLUDES #include +#include void tet_infoline(const char*str); void tet_printf(const char *format, ...); @@ -73,176 +76,6 @@ else throw("TET_FAIL"); \ } -template -inline bool CompareType(Type value1, Type value2, float epsilon); - -/** - * A helper for fuzzy-comparing Vector2 objects - * @param[in] vector1 the first object - * @param[in] vector2 the second object - * @param[in] epsilon difference threshold - * @returns true if difference is smaller than epsilon threshold, false otherwise - */ -template <> -inline bool CompareType(float value1, float value2, float epsilon) -{ - return fabsf(value1 - value2) < epsilon; -} - -/** - * A helper for fuzzy-comparing Vector2 objects - * @param[in] vector1 the first object - * @param[in] vector2 the second object - * @param[in] epsilon difference threshold - * @returns true if difference is smaller than epsilon threshold, false otherwise - */ -template <> -inline bool CompareType(Vector2 vector1, Vector2 vector2, float epsilon) -{ - return fabsf(vector1.x - vector2.x) -inline bool CompareType(Vector3 vector1, Vector3 vector2, float epsilon) -{ - return fabsf(vector1.x - vector2.x) -inline bool CompareType(Vector4 vector1, Vector4 vector2, float epsilon) -{ - return fabsf(vector1.x - vector2.x) -inline bool CompareType(Quaternion q1, Quaternion q2, float epsilon) -{ - Quaternion q2N = -q2; // These quaternions represent the same rotation - return CompareType(q1.mVector, q2.mVector, epsilon) || CompareType(q1.mVector, q2N.mVector, epsilon); -} - -template <> -inline bool CompareType(Radian q1, Radian q2, float epsilon) -{ - return CompareType(q1.radian, q2.radian, epsilon); -} - -template <> -inline bool CompareType(Degree q1, Degree q2, float epsilon) -{ - return CompareType(q1.degree, q2.degree, epsilon); -} - -template <> -inline bool CompareType(Property::Value q1, Property::Value q2, float epsilon) -{ - Property::Type type = q1.GetType(); - if( type != q2.GetType() ) - { - return false; - } - - bool result = false; - switch(type) - { - case Property::BOOLEAN: - { - bool a, b; - q1.Get(a); - q2.Get(b); - result = a == b; - break; - } - case Property::INTEGER: - { - int a, b; - q1.Get(a); - q2.Get(b); - result = a == b; - break; - } - case Property::FLOAT: - { - float a, b; - q1.Get(a); - q2.Get(b); - result = CompareType(a, b, epsilon); - break; - } - case Property::VECTOR2: - { - Vector2 a, b; - q1.Get(a); - q2.Get(b); - result = CompareType(a, b, epsilon); - break; - } - case Property::VECTOR3: - { - Vector3 a, b; - q1.Get(a); - q2.Get(b); - result = CompareType(a, b, epsilon); - break; - } - case Property::RECTANGLE: - case Property::VECTOR4: - { - Vector4 a, b; - q1.Get(a); - q2.Get(b); - result = CompareType(a, b, epsilon); - break; - } - case Property::ROTATION: - { - Quaternion a, b; - q1.Get(a); - q2.Get(b); - result = CompareType(a, b, epsilon); - break; - } - case Property::MATRIX: - case Property::MATRIX3: - case Property::STRING: - case Property::ARRAY: - case Property::MAP: - { - //TODO: Implement this? - DALI_ASSERT_ALWAYS( 0 && "Not implemented"); - result = false; - break; - } - case Property::NONE: - { - result = false; - break; - } - } - - return result; -} - bool operator==(TimePeriod a, TimePeriod b); std::ostream& operator<<( std::ostream& ostream, TimePeriod value ); @@ -258,7 +91,7 @@ std::ostream& operator<<( std::ostream& ostream, Degree angle ); template inline void DALI_TEST_EQUALS(Type value1, Type value2, const char* location) { - if (!(value1 == value2)) + if( !CompareType(value1, value2, 0.01f) ) { std::ostringstream o; o << value1 << " == " << value2 << std::endl; @@ -514,6 +347,7 @@ struct DefaultFunctionCoverage BufferImage CreateBufferImage(); BufferImage CreateBufferImage(int width, int height, const Vector4& color); + // Prepare a resource image to be loaded. Should be called before creating the ResourceImage void PrepareResourceImage( TestApplication& application, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat ); diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-compare-types.h b/automated-tests/src/dali/dali-test-suite-utils/test-compare-types.h new file mode 100644 index 0000000..248276e --- /dev/null +++ b/automated-tests/src/dali/dali-test-suite-utils/test-compare-types.h @@ -0,0 +1,199 @@ +#ifndef DALI_TEST_COMPARE_TYPES_H +#define DALI_TEST_COMPARE_TYPES_H + +/* + * Copyright (c) 2017 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 +using namespace Dali; + + +template +inline bool CompareType(Type value1, Type value2, float epsilon) +{ + return value1 == value2; +} + +/** + * A helper for fuzzy-comparing Vector2 objects + * @param[in] vector1 the first object + * @param[in] vector2 the second object + * @param[in] epsilon difference threshold + * @returns true if difference is smaller than epsilon threshold, false otherwise + */ +template <> +inline bool CompareType(float value1, float value2, float epsilon) +{ + return fabsf(value1 - value2) < epsilon; +} + +/** + * A helper for fuzzy-comparing Vector2 objects + * @param[in] vector1 the first object + * @param[in] vector2 the second object + * @param[in] epsilon difference threshold + * @returns true if difference is smaller than epsilon threshold, false otherwise + */ +template <> +inline bool CompareType(Vector2 vector1, Vector2 vector2, float epsilon) +{ + return fabsf(vector1.x - vector2.x) +inline bool CompareType(Vector3 vector1, Vector3 vector2, float epsilon) +{ + return fabsf(vector1.x - vector2.x) +inline bool CompareType(Vector4 vector1, Vector4 vector2, float epsilon) +{ + return fabsf(vector1.x - vector2.x) +inline bool CompareType(Quaternion q1, Quaternion q2, float epsilon) +{ + Quaternion q2N = -q2; // These quaternions represent the same rotation + return CompareType(q1.mVector, q2.mVector, epsilon) || CompareType(q1.mVector, q2N.mVector, epsilon); +} + +template <> +inline bool CompareType(Radian q1, Radian q2, float epsilon) +{ + return CompareType(q1.radian, q2.radian, epsilon); +} + +template <> +inline bool CompareType(Degree q1, Degree q2, float epsilon) +{ + return CompareType(q1.degree, q2.degree, epsilon); +} + +template <> +inline bool CompareType(Property::Value q1, Property::Value q2, float epsilon) +{ + Property::Type type = q1.GetType(); + if( type != q2.GetType() ) + { + return false; + } + + bool result = false; + switch(type) + { + case Property::BOOLEAN: + { + bool a, b; + q1.Get(a); + q2.Get(b); + result = a == b; + break; + } + case Property::INTEGER: + { + int a, b; + q1.Get(a); + q2.Get(b); + result = a == b; + break; + } + case Property::FLOAT: + { + float a, b; + q1.Get(a); + q2.Get(b); + result = CompareType(a, b, epsilon); + break; + } + case Property::VECTOR2: + { + Vector2 a, b; + q1.Get(a); + q2.Get(b); + result = CompareType(a, b, epsilon); + break; + } + case Property::VECTOR3: + { + Vector3 a, b; + q1.Get(a); + q2.Get(b); + result = CompareType(a, b, epsilon); + break; + } + case Property::RECTANGLE: + case Property::VECTOR4: + { + Vector4 a, b; + q1.Get(a); + q2.Get(b); + result = CompareType(a, b, epsilon); + break; + } + case Property::ROTATION: + { + Quaternion a, b; + q1.Get(a); + q2.Get(b); + result = CompareType(a, b, epsilon); + break; + } + case Property::MATRIX: + case Property::MATRIX3: + case Property::STRING: + case Property::ARRAY: + case Property::MAP: + { + //TODO: Implement this? + DALI_ASSERT_ALWAYS( 0 && "Not implemented"); + result = false; + break; + } + case Property::NONE: + { + result = false; + break; + } + } + + return result; +} + + + +#endif diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index 9bed832..1613bb5 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -25,13 +25,15 @@ #include #include #include // for strcmp +#include // INTERNAL INCLUDES #include #include #include #include -#include "test-trace-call-stack.h" +#include +#include namespace Dali { @@ -2132,7 +2134,7 @@ private: T uniformValue; if ( GetUniformValue( program, uniform, uniformValue ) ) { - return value == uniformValue; + return CompareType(value, uniformValue, Math::MACHINE_EPSILON_10); } return false; @@ -2176,6 +2178,9 @@ private: ProgramUniformValue mProgramUniformsMat4; ProgramUniformValue mProgramUniformsMat3; + + + inline const ProgramUniformValue& GetProgramUniformsForType( const int ) const { return mProgramUniforms1i;