shithub: openh264

Download patch

ref: abaf3a4104d424088ed42008ca00230b543cd000
parent: eb9f56584fae81eab9be6ab999040ed5e4a7cfcd
author: Sindre Aamås <saamas@cisco.com>
date: Wed Apr 13 04:39:05 EDT 2016

[UT] Reduce duplication in quantization tests

--- a/test/encoder/EncUT_EncoderMbAux.cpp
+++ b/test/encoder/EncUT_EncoderMbAux.cpp
@@ -292,6 +292,7 @@
 #define WELS_ABS_LC(a) ((sign ^ (int32_t)(a)) - sign)
 #define NEW_QUANT(pDct, ff, mf) (((ff)+ WELS_ABS_LC(pDct))*(mf)) >>16
 #define WELS_NEW_QUANT(pDct,ff,mf) WELS_ABS_LC(NEW_QUANT(pDct, ff, mf))
+namespace {
 void WelsQuantFour4x4MaxAnchor (int16_t* pDct, int16_t* ff,  int16_t* mf, int16_t* max) {
   int32_t i, j, k, sign;
   int16_t max_abs;
@@ -308,25 +309,7 @@
     max[k] = max_abs;
   }
 }
-TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_c) {
-  int16_t ff[8], mf[8];
-  int16_t iDctA[64], iMaxA[16];
-  int16_t iDctC[64], iMaxC[16];
-  for (int i = 0; i < 8; i++) {
-    ff[i] = rand() & 32767;
-    mf[i] = rand() & 32767;
-  }
-  for (int i = 0; i < 64; i++)
-    iDctA[i] = iDctC[i] = (rand() & 65535) - 32767;
-  WelsQuantFour4x4MaxAnchor (iDctA, ff, mf, iMaxA);
-  WelsQuantFour4x4Max_c (iDctC, ff, mf, iMaxC);
-  for (int i = 0; i < 64; i++)
-    EXPECT_EQ (iDctA[i], iDctC[i]);
-  for (int i = 0; i < 4; i++)
-    EXPECT_EQ (iMaxA[i], iMaxC[i]);
-}
-#ifdef X86_ASM
-TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_sse2) {
+void TestWelsQuantFour4x4Max (PQuantizationMaxFunc func) {
   CMemoryAlign cMemoryAlign (0);
   ALLOC_MEMORY (int16_t, ff, 8);
   ALLOC_MEMORY (int16_t, mf, 8);
@@ -340,8 +323,8 @@
   }
   for (int i = 0; i < 64; i++)
     iDctC[i] = iDctS[i] = (rand() & 65535) - 32767;
-  WelsQuantFour4x4Max_c (iDctC, ff, mf, iMaxC);
-  WelsQuantFour4x4Max_sse2 (iDctS, ff, mf, iMaxS);
+  WelsQuantFour4x4MaxAnchor (iDctC, ff, mf, iMaxC);
+  func (iDctS, ff, mf, iMaxS);
   for (int i = 0; i < 64; i++)
     EXPECT_EQ (iDctC[i], iDctS[i]);
   for (int i = 0; i < 4; i++)
@@ -352,6 +335,14 @@
   FREE_MEMORY (iDctS);
   FREE_MEMORY (iMaxC);
   FREE_MEMORY (iMaxS);
+}
+} // anon ns
+TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_c) {
+  TestWelsQuantFour4x4Max (WelsQuantFour4x4Max_c);
+}
+#ifdef X86_ASM
+TEST (EncodeMbAuxTest, WelsQuantFour4x4Max_sse2) {
+  TestWelsQuantFour4x4Max (WelsQuantFour4x4Max_sse2);
 }
 #endif
 int32_t WelsHadamardQuant2x2SkipAnchor (int16_t* rs, int16_t ff,  int16_t mf) {