Test macros print just filename and not full path, all tests throw and harness catche... 01/150201/2
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 14 Sep 2017 17:08:35 +0000 (18:08 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 14 Sep 2017 17:15:39 +0000 (18:15 +0100)
Change-Id: Id701d19543d3b08da66e769a88cacafa57da45f5

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/dali-test-suite-utils.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp

index 8877a50..b38428b 100644 (file)
@@ -117,6 +117,7 @@ void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, const cha
                m1[6],  m1[7], m1[8],   m2[6],  m2[7], m2[8]);
 
     tet_result(TET_FAIL);
                m1[6],  m1[7], m1[8],   m2[6],  m2[7], m2[8]);
 
     tet_result(TET_FAIL);
+    throw("TET_FAIL");
   }
   else
   {
   }
   else
   {
@@ -147,6 +148,7 @@ void DALI_TEST_EQUALS( const Matrix3& matrix1, const Matrix3& matrix2, float eps
                m1[6],  m1[7], m1[8],   m2[6],  m2[7], m2[8]);
 
     tet_result(TET_FAIL);
                m1[6],  m1[7], m1[8],   m2[6],  m2[7], m2[8]);
 
     tet_result(TET_FAIL);
+    throw("TET_FAIL");
   }
   else
   {
   }
   else
   {
@@ -183,6 +185,7 @@ void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, const char*
               m1[12], m1[13], m1[14], m1[15],  m2[12], m2[13], m2[14], m2[15]);
 
     tet_result(TET_FAIL);
               m1[12], m1[13], m1[14], m1[15],  m2[12], m2[13], m2[14], m2[15]);
 
     tet_result(TET_FAIL);
+    throw("TET_FAIL");
   }
   else
   {
   }
   else
   {
@@ -214,6 +217,7 @@ void DALI_TEST_EQUALS( const Matrix& matrix1, const Matrix& matrix2, float epsil
               m1[12], m1[13], m1[14], m1[15],  m2[12], m2[13], m2[14], m2[15]);
 
     tet_result(TET_FAIL);
               m1[12], m1[13], m1[14], m1[15],  m2[12], m2[13], m2[14], m2[15]);
 
     tet_result(TET_FAIL);
+    throw("TET_FAIL");
   }
   else
   {
   }
   else
   {
@@ -251,6 +255,7 @@ void DALI_TEST_EQUALS( Property::Value& str1, const char* str2, const char* loca
   else
   {
     tet_result(TET_FAIL);
   else
   {
     tet_result(TET_FAIL);
+    throw("TET_FAIL");
   }
 }
 
   }
 }
 
@@ -265,6 +270,7 @@ void DALI_TEST_ASSERT( DaliException& e, std::string conditionSubString, const c
   {
     fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location );
     tet_result(TET_FAIL);
   {
     fprintf(stderr, "Expected substring '%s' : actual exception string '%s' : location %s\n", conditionSubString.c_str(), e.condition, location );
     tet_result(TET_FAIL);
+    throw("TET_FAIL");
   }
   else
   {
   }
   else
   {
@@ -294,6 +300,7 @@ void ConstraintAppliedCheck::CheckSignalReceived()
   {
     fprintf(stderr,  "Expected Applied signal was not received\n" );
     tet_result( TET_FAIL );
   {
     fprintf(stderr,  "Expected Applied signal was not received\n" );
     tet_result( TET_FAIL );
+    throw("TET_FAIL");
   }
   else
   {
   }
   else
   {
@@ -307,6 +314,7 @@ void ConstraintAppliedCheck::CheckSignalNotReceived()
   {
     fprintf(stderr,  "Unexpected Applied signal was received\n" );
     tet_result( TET_FAIL );
   {
     fprintf(stderr,  "Unexpected Applied signal was received\n" );
     tet_result( TET_FAIL );
+    throw("TET_FAIL");
   }
   else
   {
   }
   else
   {
index 2b84d39..4f71920 100644 (file)
@@ -40,11 +40,24 @@ using namespace Dali;
 #define STRINGIZE_I(text) #text
 #define STRINGIZE(text) STRINGIZE_I(text)
 
 #define STRINGIZE_I(text) #text
 #define STRINGIZE(text) STRINGIZE_I(text)
 
-// the following is the other compilers way of token pasting, gcc seems to just concatenate strings automatically
-//#define TOKENPASTE(x,y) x ## y
-#define TOKENPASTE(x,y) x y
-#define TOKENPASTE2(x,y) TOKENPASTE( x, y )
-#define TEST_LOCATION TOKENPASTE2( "Test failed in ", TOKENPASTE2( __FILE__, TOKENPASTE2( ", line ", STRINGIZE(__LINE__) ) ) )
+/**
+ * Inspired by https://stackoverflow.com/questions/1706346/file-macro-manipulation-handling-at-compile-time
+ * answer by Chetan Reddy
+ */
+constexpr int32_t basenameIndex( const char * const path, const int32_t index = 0, const int32_t slashIndex = -1 )
+{
+   return path[ index ]
+       ? ( path[ index ] == '/'
+           ? basenameIndex( path, index + 1, index )
+           : basenameIndex( path, index + 1, slashIndex ) )
+       : ( slashIndex + 1 );
+}
+
+#define __FILELINE__ ( { static const int32_t basenameIdx = basenameIndex( __FILE__ ); \
+                         static_assert (basenameIdx >= 0, "compile-time basename" );   \
+                         __FILE__ ":" STRINGIZE(__LINE__) + basenameIdx ; } )
+
+#define TEST_LOCATION __FILELINE__
 #define TEST_INNER_LOCATION(x) ( std::string(x) + " (" + STRINGIZE(__LINE__) + ")" ).c_str()
 
 #define TET_UNDEF 2
 #define TEST_INNER_LOCATION(x) ( std::string(x) + " (" + STRINGIZE(__LINE__) + ")" ).c_str()
 
 #define TET_UNDEF 2
@@ -73,7 +86,7 @@ if ( (condition) )
 }                                                                                         \
 else                                                                                      \
 {                                                                                         \
 }                                                                                         \
 else                                                                                      \
 {                                                                                         \
-  fprintf(stderr, "%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__);    \
+  fprintf(stderr, "Test failed in %s, condition: %s\n", __FILELINE__, #condition );       \
   tet_result(TET_FAIL);                                                                   \
   throw("TET_FAIL");                                                                      \
 }
   tet_result(TET_FAIL);                                                                   \
   throw("TET_FAIL");                                                                      \
 }
@@ -97,8 +110,9 @@ inline void DALI_TEST_EQUALS(Type value1, Type value2, const char* location)
   {
     std::ostringstream o;
     o << value1 << " == " << value2 << std::endl;
   {
     std::ostringstream o;
     o << value1 << " == " << value2 << std::endl;
-    fprintf(stderr, "%s, checking %s", location, o.str().c_str());
+    fprintf(stderr, "Test failed in %s, checking %s", location, o.str().c_str());
     tet_result(TET_FAIL);
     tet_result(TET_FAIL);
+    throw("TET_FAIL");                                                                      \
   }
   else
   {
   }
   else
   {
@@ -106,6 +120,13 @@ inline void DALI_TEST_EQUALS(Type value1, Type value2, const char* location)
   }
 }
 
   }
 }
 
+/**
+ * Test whether two values are equal.
+ * @param[in] value1 The first value
+ * @param[in] value2 The second value
+ */
+#define DALI_TEST_EQUAL( v1, v2 ) DALI_TEST_EQUALS( v1, v2, __FILELINE__ )
+
 template<typename Type>
 inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char* location)
 {
 template<typename Type>
 inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char* location)
 {
@@ -113,8 +134,9 @@ inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char
   {
     std::ostringstream o;
     o << value1 << " == " << value2 << std::endl;
   {
     std::ostringstream o;
     o << value1 << " == " << value2 << std::endl;
-    fprintf(stderr, "%s, checking %s", location, o.str().c_str());
+    fprintf(stderr, "Test failed in %s, checking %s", location, o.str().c_str());
     tet_result(TET_FAIL);
     tet_result(TET_FAIL);
+    throw("TET_FAIL");                                                                      \
   }
   else
   {
   }
   else
   {
@@ -129,8 +151,9 @@ inline void DALI_TEST_NOT_EQUALS(Type value1, Type value2, float epsilon, const
   {
     std::ostringstream o;
     o << value1 << " !=  " << value2 << std::endl;
   {
     std::ostringstream o;
     o << value1 << " !=  " << value2 << std::endl;
-    fprintf(stderr, "%s, checking %s", location, o.str().c_str());
+    fprintf(stderr, "Test failed in %s, checking %s", location, o.str().c_str());
     tet_result(TET_FAIL);
     tet_result(TET_FAIL);
+    throw("TET_FAIL");                                                                      \
   }
   else
   {
   }
   else
   {
@@ -151,13 +174,15 @@ inline void DALI_TEST_EQUALS<TimePeriod>( TimePeriod value1, TimePeriod value2,
 {
   if ((fabs(value1.durationSeconds - value2.durationSeconds) > epsilon))
   {
 {
   if ((fabs(value1.durationSeconds - value2.durationSeconds) > epsilon))
   {
-    fprintf(stderr, "%s, checking durations %f == %f, epsilon %f\n", location, value1.durationSeconds, value2.durationSeconds, epsilon);
+    fprintf(stderr, "Test failed in %s, checking durations %f == %f, epsilon %f\n", location, value1.durationSeconds, value2.durationSeconds, epsilon);
     tet_result(TET_FAIL);
     tet_result(TET_FAIL);
+    throw("TET_FAIL");                                                                      \
   }
   else if ((fabs(value1.delaySeconds - value2.delaySeconds) > epsilon))
   {
   }
   else if ((fabs(value1.delaySeconds - value2.delaySeconds) > epsilon))
   {
-    fprintf(stderr, "%s, checking delays %f == %f, epsilon %f\n", location, value1.delaySeconds, value2.delaySeconds, epsilon);
+    fprintf(stderr, "Test failed in %s, checking delays %f == %f, epsilon %f\n", location, value1.delaySeconds, value2.delaySeconds, epsilon);
     tet_result(TET_FAIL);
     tet_result(TET_FAIL);
+    throw("TET_FAIL");                                                                      \
   }
   else
   {
   }
   else
   {
@@ -232,8 +257,9 @@ inline void DALI_TEST_EQUALS<const char*>( const char* str1, const char* str2, c
 {
   if (strcmp(str1, str2))
   {
 {
   if (strcmp(str1, str2))
   {
-    fprintf(stderr, "%s, checking '%s' == '%s'\n", location, str1, str2);
+    fprintf(stderr, "Test failed in %s, checking '%s' == '%s'\n", location, str1, str2);
     tet_result(TET_FAIL);
     tet_result(TET_FAIL);
+    throw("TET_FAIL");                                                                      \
   }
   else
   {
   }
   else
   {
@@ -289,8 +315,9 @@ void DALI_TEST_GREATER( T value1, T value2, const char* location)
 {
   if (!(value1 > value2))
   {
 {
   if (!(value1 > value2))
   {
-    std::cerr << location << ", checking " << value1 <<" > " << value2 << "\n";
+    std::cerr << "Test failed in " << location << ", checking " << value1 <<" > " << value2 << "\n";
     tet_result(TET_FAIL);
     tet_result(TET_FAIL);
+    throw("TET_FAIL");                                                                      \
   }
   else
   {
   }
   else
   {
index 840ef0d..645d74b 100644 (file)
@@ -52,7 +52,14 @@ int RunTestCase( struct ::testcase_s& testCase )
   {
     testCase.startup();
   }
   {
     testCase.startup();
   }
-  result = testCase.function();
+  try
+  {
+    result = testCase.function();
+  }
+  catch( const char* )
+  {
+    // just catch test fail exception, return is already set to EXIT_STATUS_TESTCASE_FAILED
+  }
   if( testCase.cleanup )
   {
     testCase.cleanup();
   if( testCase.cleanup )
   {
     testCase.cleanup();