Commits

Matt Oswald  committed b53834b

added test that proves anything that supports begin/end pairs will work as a theory data provider

  • Participants
  • Parent commits d6200f9

Comments (0)

Files changed (1)

File Tests/UnitTests/Theory.cpp

 #include <algorithm>
+#include <array>
 #include <mutex>
 #include <string>
 #include <tuple>
     template<typename TTheoryData>
     void Register(std::string &&name, std::string &&params, TTheoryData &&theoryData)
     {
-        xUnitpp::TestCollection::Register reg(collection, &TheoryUnderTest, std::forward<TTheoryData>(theoryData),
-            std::move(name), "Theory", std::move(params), attributes, -1, __FILE__, __LINE__, localEventRecorders);
+        xUnitpp::TestCollection::Register reg(
+            collection,
+            &TheoryUnderTest,
+            std::forward<TTheoryData>(theoryData),
+            std::move(name),
+            "Theory",
+            std::move(params),
+            attributes,
+            -1,
+            __FILE__, __LINE__,
+            localEventRecorders);
         (void)reg;
     }
 
     Assert.DoesNotThrow(fn);
 }
 
+struct ArrayProvider
+{
+    const std::array<std::tuple<int>, 1> &operator ()() const
+    {
+        static std::array<std::tuple<int>, 1> tuples;
+        tuples[0] = std::make_tuple(0);
+        return tuples;
+    }
+};
+
+struct CustomProvider
+{
+    CustomProvider()
+    {
+        tuples[0] = std::make_tuple(0);
+    }
+
+    const CustomProvider &operator ()() const
+    {
+        return *this;
+    }
+
+    friend const std::tuple<int> *begin(const CustomProvider &cp)
+    {
+        return &cp.tuples[0];
+    }
+
+    friend const std::tuple<int> *end(const CustomProvider &cp)
+    {
+        return &cp.tuples[1];
+    }
+
+    std::tuple<int> tuples[1];
+};
+
+FACT_FIXTURE("DATA_THEORY accepts anything that has begin/end", TheoryFixture)
+{
+    Register("Array", "(int)", ArrayProvider());
+    Register("Custom", "(int)", CustomProvider());
+
+    Run();
 }
+
+}