[Libva] [PATCH intel-driver 05/11] test: jpeg/enc: move input creators to data file

U. Artie Eoff ullysses.a.eoff at intel.com
Wed Sep 28 20:36:05 UTC 2016


Move the ::JPEG::Encode::TestInputCreator's to the
i965_jpeg_test_data[.h|.cpp] files.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff at intel.com>
---
 test/i965_jpeg_encode_test.cpp | 81 +-----------------------------------------
 test/i965_jpeg_test_data.cpp   | 64 +++++++++++++++++++++++++++++++++
 test/i965_jpeg_test_data.h     | 45 +++++++++++++++++++++++
 3 files changed, 110 insertions(+), 80 deletions(-)

diff --git a/test/i965_jpeg_encode_test.cpp b/test/i965_jpeg_encode_test.cpp
index c587643e1f32..c794bf935ebf 100644
--- a/test/i965_jpeg_encode_test.cpp
+++ b/test/i965_jpeg_encode_test.cpp
@@ -25,9 +25,8 @@
 #include "i965_jpeg_test_data.h"
 #include "i965_streamable.h"
 #include "i965_test_fixture.h"
-#include "test_utils.h"
 
-#include <algorithm>
+#include <numeric>
 #include <cstring>
 #include <memory>
 #include <tuple>
@@ -83,51 +82,6 @@ TEST_F(JPEGEncodeTest, Entrypoint)
     }
 }
 
-class TestInputCreator
-{
-public:
-    typedef std::shared_ptr<TestInputCreator> Shared;
-    typedef std::shared_ptr<const TestInputCreator> SharedConst;
-
-    TestInput::Shared create(const unsigned fourcc) const
-    {
-        const std::array<unsigned, 2> res = getResolution();
-
-        TestInput::Shared input(new TestInput(fourcc, res[0], res[1]));
-        ByteData& bytes = input->bytes;
-
-        RandomValueGenerator<uint8_t> rg(0x00, 0xff);
-        for (size_t i(0); i < input->planes; ++i)
-            std::generate_n(
-                std::back_inserter(bytes), input->sizes[i],
-                [&rg]{ return rg(); });
-        return input;
-    }
-
-    friend ::std::ostream& operator<<(
-        ::std::ostream& os, const TestInputCreator& t)
-    {
-        t.repr(os);
-        return os;
-    }
-
-    friend ::std::ostream& operator<<(
-        ::std::ostream& os, const TestInputCreator::Shared& t)
-    {
-        return os << *t;
-    }
-
-    friend ::std::ostream& operator<<(
-        ::std::ostream& os, const TestInputCreator::SharedConst& t)
-    {
-        return os << *t;
-    }
-
-protected:
-    virtual std::array<unsigned, 2> getResolution() const = 0;
-    virtual void repr(std::ostream& os) const = 0;
-};
-
 const TestInput::Shared NV12toI420(const TestInput::SharedConst& nv12)
 {
     TestInput::Shared i420(
@@ -541,18 +495,6 @@ TEST_P(JPEGEncodeInputTest, Full)
     VerifyOutput();
 }
 
-class RandomSizeCreator
-    : public TestInputCreator
-{
-protected:
-    std::array<unsigned, 2> getResolution() const
-    {
-        static RandomValueGenerator<unsigned> rg(1, 769);
-        return {rg(), rg()};
-    }
-    void repr(std::ostream& os) const { os << "Random Size"; }
-};
-
 INSTANTIATE_TEST_CASE_P(
     Random, JPEGEncodeInputTest,
     ::testing::Combine(
@@ -563,27 +505,6 @@ INSTANTIATE_TEST_CASE_P(
     )
 );
 
-class FixedSizeCreator
-    : public TestInputCreator
-{
-public:
-    FixedSizeCreator(const std::array<unsigned, 2>& resolution)
-        : res(resolution)
-    { }
-
-protected:
-    std::array<unsigned, 2> getResolution() const { return res; }
-    void repr(std::ostream& os) const
-    {
-        os << "Fixed Size " << res[0] << "x" << res[1];
-    }
-
-private:
-    const std::array<unsigned, 2> res;
-};
-
-typedef std::vector<TestInputCreator::SharedConst> InputCreators;
-
 InputCreators generateCommonInputs()
 {
     return {
diff --git a/test/i965_jpeg_test_data.cpp b/test/i965_jpeg_test_data.cpp
index 84316a8355c9..0c1f0d3eebed 100644
--- a/test/i965_jpeg_test_data.cpp
+++ b/test/i965_jpeg_test_data.cpp
@@ -25,6 +25,9 @@
 #include "i965_jpeg_test_data.h"
 #include "i965_drv_video.h"
 #include "i965_streamable.h"
+#include "test_utils.h"
+
+#include <algorithm>
 
 namespace JPEG {
 namespace Decode {
@@ -851,5 +854,66 @@ namespace Encode {
         return os << *t;
     }
 
+    TestInput::Shared TestInputCreator::create(const unsigned fourcc) const
+    {
+        const std::array<unsigned, 2> res = getResolution();
+
+        TestInput::Shared input(new TestInput(fourcc, res[0], res[1]));
+        ByteData& bytes = input->bytes;
+
+        RandomValueGenerator<uint8_t> rg(0x00, 0xff);
+        for (size_t i(0); i < input->planes; ++i)
+            std::generate_n(
+                std::back_inserter(bytes), input->sizes[i],
+                [&rg]{ return rg(); });
+        return input;
+    }
+
+    ::std::ostream& operator<<(::std::ostream& os, const TestInputCreator& t)
+    {
+        t.repr(os);
+        return os;
+    }
+
+    ::std::ostream& operator<<(
+        ::std::ostream& os, const TestInputCreator::Shared& t)
+    {
+        return os << *t;
+    }
+
+    ::std::ostream& operator<<(
+        ::std::ostream& os, const TestInputCreator::SharedConst& t)
+    {
+        return os << *t;
+    }
+
+    std::array<unsigned, 2> RandomSizeCreator::getResolution() const
+    {
+        static RandomValueGenerator<unsigned> rg(1, 769);
+        return {rg(), rg()};
+    }
+
+    void RandomSizeCreator::repr(::std::ostream& os) const
+    {
+        os << "Random Size";
+    }
+
+    FixedSizeCreator::FixedSizeCreator(
+        const std::array<unsigned, 2>& resolution)
+        : res(resolution)
+    {
+        return;
+    }
+
+    std::array<unsigned, 2> FixedSizeCreator::getResolution() const
+    {
+        return res;
+    }
+
+    void FixedSizeCreator::repr(::std::ostream& os) const
+    {
+        os << "Fixed Size " << res[0] << "x" << res[1];
+    }
+
 } // namespace Encode
 } // namespace JPEG
diff --git a/test/i965_jpeg_test_data.h b/test/i965_jpeg_test_data.h
index 5f4802e7dd93..cde0cfe8258e 100644
--- a/test/i965_jpeg_test_data.h
+++ b/test/i965_jpeg_test_data.h
@@ -421,6 +421,51 @@ namespace Encode {
         std::array<size_t, 3> offsets;
         std::array<size_t, 3> sizes;
     };
+
+    class TestInputCreator
+    {
+    public:
+        typedef std::shared_ptr<TestInputCreator> Shared;
+        typedef std::shared_ptr<const TestInputCreator> SharedConst;
+
+        TestInput::Shared create(const unsigned) const;
+
+        friend ::std::ostream& operator<<(
+            ::std::ostream&, const TestInputCreator&);
+        friend ::std::ostream& operator<<(
+            ::std::ostream&, const TestInputCreator::Shared&);
+        friend ::std::ostream& operator<<(
+            ::std::ostream&, const TestInputCreator::SharedConst&);
+
+    protected:
+        virtual std::array<unsigned, 2> getResolution() const = 0;
+        virtual void repr(::std::ostream& os) const = 0;
+    };
+
+    class RandomSizeCreator
+        : public TestInputCreator
+    {
+    protected:
+        std::array<unsigned, 2> getResolution() const;
+        void repr(::std::ostream&) const;
+    };
+
+    class FixedSizeCreator
+        : public TestInputCreator
+    {
+    public:
+        FixedSizeCreator(const std::array<unsigned, 2>&);
+
+    protected:
+        std::array<unsigned, 2> getResolution() const;
+        void repr(::std::ostream& os) const;
+
+    private:
+        const std::array<unsigned, 2> res;
+    };
+
+    typedef std::vector<TestInputCreator::SharedConst> InputCreators;
+
 } // namespace Encode
 } // namespace JPEG
 
-- 
2.4.11



More information about the Libva mailing list