Commits

Matt Oswald committed 50267e8

Assert.Empty tests added

Comments (0)

Files changed (5)

xUnit++/Tests/Assert.Empty.cpp

+#include <vector>
+#include "../xUnit++.h"
+
+using xUnitpp::xUnitAssert;
+using xUnitpp::Assert;
+
+namespace
+{
+    struct
+    {
+        bool empty() const
+        {
+            return true;
+        }
+    } hasConstEmpty;
+
+    namespace Local
+    {
+        struct Container
+        {
+        };
+
+        int begin(const Container &)
+        {
+            return 0;
+        }
+
+        int end(const Container &)
+        {
+            return 0;
+        }
+    }
+}
+
+SUITE(AssertEqual)
+{
+
+FACT(EmptyCallsEmptyForContainerWithConstEmptyMember)
+{
+    Assert.Empty(hasConstEmpty);
+}
+
+FACT(EmptyFindsLocalBeginEnd)
+{
+    Assert.Empty(Local::Container());
+}
+
+FACT(EmptyFindsStdBeginEnd)
+{
+    int array[10];
+    Assert.Throws<xUnitAssert>([&]() { Assert.Empty(array); });
+}
+
+FACT(EmptyFindsMemberBeginEnd)
+{
+    struct
+    {
+        int begin() const
+        {
+            return 0;
+        }
+
+        int end() const
+        {
+            return 0;
+        }
+    } hasMembers;
+
+    Assert.Empty(hasMembers);
+}
+
+FACT(EmptyAssertsOnFailure)
+{
+    std::vector<int> v;
+    v.push_back(0);
+    v.push_back(1);
+
+    Assert.Throws<xUnitAssert>([&]() { Assert.Empty(v); });
+}
+
+FACT(EmptyAppendsUserMessage)
+{
+    static const std::string msg = "xUnit++";
+
+    std::vector<int> v;
+    v.push_back(0);
+    v.push_back(1);
+
+    auto assert = Assert.Throws<xUnitAssert>([&]() { Assert.Empty(v, msg); });
+
+    Assert.Contains(assert.what(), msg.c_str());
+}
+
+}

xUnit++/Tests/Assert.Equal.cpp

 
 FACT(AssertEqualWithDefaultComparerWithSuccess)
 {
-	Assert.Equal(0, 0);
+    Assert.Equal(0, 0);
 }
 
 FACT(AssertEqualWithDefaultComparerAssertsOnFailure)

xUnit++/xUnit++.vcxproj

     <ClCompile Include="TestCollection.cpp" />
     <ClCompile Include="TestDetails.cpp" />
     <ClCompile Include="Tests\Assert.DoesNotThrow.cpp" />
+    <ClCompile Include="Tests\Assert.Empty.cpp" />
     <ClCompile Include="Tests\Assert.Equal.cpp" />
     <ClCompile Include="Tests\Assert.Fail.cpp" />
     <ClCompile Include="Tests\Assert.False.cpp" />

xUnit++/xUnit++.vcxproj.filters

     <ClCompile Include="Tests\Assert.True.cpp">
       <Filter>Tests</Filter>
     </ClCompile>
+    <ClCompile Include="Tests\Assert.Empty.cpp">
+      <Filter>Tests</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Fact.h" />

xUnit++/xUnitAssert.cpp

 {
     if (actualString.find(value) == std::string::npos)
     {
-        throw xUnitAssert("Contains", msg, "", "", "");
+        throw xUnitAssert("Contains", msg, "", actualString, value);
     }
 }