void test_compare_basic()
{
  using namespace fs;
  for (auto const & TC : CompareTestCases) {
    const path p1(TC.LHS);
    const path p2(TC.RHS);
    const std::string R(TC.RHS);
    const std::string_view RV(TC.RHS);
    const int E = TC.expect;
    { // compare(...) functions
      DisableAllocationGuard g; // none of these operations should allocate

      // check runtime results
      int ret1 = normalize_ret(p1.compare(p2));
      int ret2 = normalize_ret(p1.compare(R));
      int ret3 = normalize_ret(p1.compare(TC.RHS));
      int ret4 = normalize_ret(p1.compare(RV));

      g.release();
      ASSERT_EQ(ret1, ret2);
      ASSERT_EQ(ret1, ret3);
      ASSERT_EQ(ret1, ret4);
      ASSERT_EQ(ret1, E)
          << DISPLAY(TC.LHS) << DISPLAY(TC.RHS);

      // check signatures
      ASSERT_NOEXCEPT(p1.compare(p2));
    }
    { // comparison operators
      DisableAllocationGuard g; // none of these operations should allocate

      // Check runtime result
      assert((p1 == p2) == (E == 0));
      assert((p1 != p2) == (E != 0));
      assert((p1 <  p2) == (E <  0));
      assert((p1 <= p2) == (E <= 0));
      assert((p1 >  p2) == (E >  0));
      assert((p1 >= p2) == (E >= 0));

      // Check signatures
      ASSERT_NOEXCEPT(p1 == p2);
      ASSERT_NOEXCEPT(p1 != p2);
      ASSERT_NOEXCEPT(p1 <  p2);
      ASSERT_NOEXCEPT(p1 <= p2);
      ASSERT_NOEXCEPT(p1 >  p2);
      ASSERT_NOEXCEPT(p1 >= p2);
    }
    { // check hash values
      auto h1 = hash_value(p1);
      auto h2 = hash_value(p2);
      assert((h1 == h2) == (p1 == p2));
      // check signature
      ASSERT_SAME_TYPE(size_t, decltype(hash_value(p1)));
      ASSERT_NOEXCEPT(hash_value(p1));
    }
  }
}
Beispiel #2
0
int main()
{
  using namespace fs;
  for (auto const & TC : CompareTestCases) {
    const path p1(TC.LHS);
    const path p2(TC.RHS);
    const std::string R(TC.RHS);
    const std::string_view RV(TC.RHS);
    const int E = TC.expect;
    { // compare(...) functions
      DisableAllocationGuard g; // none of these operations should allocate

      // check runtime results
      int ret1 = p1.compare(p2);
      int ret2 = p1.compare(R);
      int ret3 = p1.compare(TC.RHS);
      int ret4 = p1.compare(RV);
      assert(ret1 == ret2 && ret1 == ret3 && ret1 == ret4);
      int normalized_ret = ret1 < 0 ? -1 : (ret1 > 0 ? 1 : 0);
      assert(normalized_ret == E);

      // check signatures
      ASSERT_NOEXCEPT(p1.compare(p2));
    }
    { // comparison operators
      DisableAllocationGuard g; // none of these operations should allocate

      // Check runtime result
      assert((p1 == p2) == (E == 0));
      assert((p1 != p2) == (E != 0));
      assert((p1 <  p2) == (E <  0));
      assert((p1 <= p2) == (E <= 0));
      assert((p1 >  p2) == (E >  0));
      assert((p1 >= p2) == (E >= 0));

      // Check signatures
      ASSERT_NOEXCEPT(p1 == p2);
      ASSERT_NOEXCEPT(p1 != p2);
      ASSERT_NOEXCEPT(p1 <  p2);
      ASSERT_NOEXCEPT(p1 <= p2);
      ASSERT_NOEXCEPT(p1 >  p2);
      ASSERT_NOEXCEPT(p1 >= p2);
    }
    { // check hash values
      auto h1 = hash_value(p1);
      auto h2 = hash_value(p2);
      assert((h1 == h2) == (p1 == p2));
      // check signature
      ASSERT_SAME_TYPE(size_t, decltype(hash_value(p1)));
      ASSERT_NOEXCEPT(hash_value(p1));
    }
  }
}
Beispiel #3
0
 bool operator<(const path& lhs, const path& rhs) noexcept
 {
   return lhs.compare(rhs) < 0;
 }