Commits

Matt Oswald committed ad697ef

Assert.NotSame, Assert.Same tests added

Comments (0)

Files changed (5)

xUnit++/Tests/Assert.NotSame.cpp

+#include "../xUnit++.h"
+
+using xUnitpp::xUnitAssert;
+using xUnitpp::Assert;
+
+SUITE(AssertNotSame)
+{
+
+FACT(NotSameSuccess)
+{
+    int x = 2;
+    int y = 2;
+
+    Assert.NotSame(x, y);
+}
+
+FACT(NotSameForPointersSuccess)
+{
+    int x = 2;
+    int y = 2;
+
+    Assert.NotSame(&x, &y);
+}
+
+FACT(NotSameAssertsOnFailure)
+{
+    int x;
+
+    Assert.Throws<xUnitAssert>([=]() { Assert.NotSame(x, x); });
+}
+
+FACT(NotSameForPointersAssertsOnFailure)
+{
+    int x;
+
+    Assert.Throws<xUnitAssert>([=]() { Assert.NotSame(&x, &x); });
+}
+
+FACT(NotSameAppendsUserMessage)
+{
+    static const std::string msg = "xUnit++";
+
+    int x;
+
+    auto assert = Assert.Throws<xUnitAssert>([&]() { Assert.NotSame(x, x, msg); });
+
+    Assert.Contains(assert.what(), msg.c_str());
+}
+
+}

xUnit++/Tests/Assert.Same.cpp

+#include "../xUnit++.h"
+
+using xUnitpp::xUnitAssert;
+using xUnitpp::Assert;
+
+SUITE(AssertSame)
+{
+
+FACT(SameSuccess)
+{
+    int x;
+
+    Assert.Same(x, x);
+}
+
+FACT(SameForPointersSuccess)
+{
+    int x;
+
+    Assert.Same(&x, &x);
+}
+
+FACT(SameForConstPointersSuccess)
+{
+    int x;
+    const int *px = &x;
+
+    Assert.Same(px, px);
+}
+
+FACT(SameAssertsOnFailure)
+{
+    int x = 2;
+    int y = 2;
+
+    Assert.Throws<xUnitAssert>([=]() { Assert.Same(x, y); });
+}
+
+FACT(SameForPointersAssertsOnFailure)
+{
+    int x = 2;
+    int y = 2;
+
+    Assert.Throws<xUnitAssert>([=]() { Assert.Same(&x, &y); });
+}
+
+FACT(SameAppendsUserMessage)
+{
+    static const std::string msg = "xUnit++";
+
+    auto assert = Assert.Throws<xUnitAssert>([]() { Assert.Same(0, 1, msg); });
+
+    Assert.Contains(assert.what(), msg.c_str());
+}
+
+}

xUnit++/xUnit++.vcxproj

     <ClCompile Include="Tests\Assert.NotEqual.cpp" />
     <ClCompile Include="Tests\Assert.NotInRange.cpp" />
     <ClCompile Include="Tests\Assert.NotNull.cpp" />
+    <ClCompile Include="Tests\Assert.NotSame.cpp" />
     <ClCompile Include="Tests\Assert.Null.cpp" />
+    <ClCompile Include="Tests\Assert.Same.cpp" />
     <ClCompile Include="Tests\Assert.Throws.cpp" />
     <ClCompile Include="Tests\Assert.True.cpp" />
     <ClCompile Include="Theory.cpp" />

xUnit++/xUnit++.vcxproj.filters

     <ClCompile Include="Tests\Assert.Null.cpp">
       <Filter>Tests</Filter>
     </ClCompile>
+    <ClCompile Include="Tests\Assert.NotSame.cpp">
+      <Filter>Tests</Filter>
+    </ClCompile>
+    <ClCompile Include="Tests\Assert.Same.cpp">
+      <Filter>Tests</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Fact.h" />

xUnit++/xUnitAssert.h

     }
 
     template<typename T>
+    void NotSame(const T *t0, const T *t1, const std::string &msg = "") const
+    {
+        if (t0 == t1)
+        {
+            throw xUnitAssert("NotSame", msg, "", "", "");
+        }
+    }
+
+    template<typename T>
     void Same(const T &t0, const T &t1, const std::string &msg = "") const
     {
         if (&t0 != &t1)
             throw xUnitAssert("Same", msg, "", "", "");
         }
     }
+
+    template<typename T>
+    void Same(T *t0, T *t1, const std::string &msg = "") const
+    {
+        if (t0 != t1)
+        {
+            throw xUnitAssert("Same", msg, "", "", "");
+        }
+    }
+
+    template<typename T>
+    void Same(const T *t0, const T *t1, const std::string &msg = "") const
+    {
+        if (t0 != t1)
+        {
+            throw xUnitAssert("Same", msg, "", "", "");
+        }
+    }
 } Assert;
 
 }