Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions casbin/model/policy_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ PoliciesValues::iterator PoliciesValues::iterator::operator++() {
return *this;
}

bool PoliciesValues::iterator::operator==(const PoliciesValues::iterator& other) const {
return !(*this != other);
}

bool PoliciesValues::iterator::operator!=(const PoliciesValues::iterator& other) const {
return opt_vector_iterator != other.opt_vector_iterator || opt_hashset_iterator != other.opt_hashset_iterator;
}
Expand Down Expand Up @@ -146,6 +150,10 @@ PoliciesValues::const_iterator PoliciesValues::const_iterator::operator++() {
return *this;
}

bool PoliciesValues::const_iterator::operator==(const const_iterator& other) const {
return !(*this != other);
}

bool PoliciesValues::const_iterator::operator!=(const const_iterator& other) const {
return opt_vector_iterator != other.opt_vector_iterator || opt_hashset_iterator != other.opt_hashset_iterator;
}
Expand Down
2 changes: 2 additions & 0 deletions include/casbin/model/policy_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ using PoliciesHashset = std::unordered_set<PolicyValues>;
using reference = value_type&;
PolicyValues& operator*() const;
iterator operator++();
bool operator==(const iterator& other) const;
bool operator!=(const iterator& other) const;
};

Expand All @@ -95,6 +96,7 @@ using PoliciesHashset = std::unordered_set<PolicyValues>;
using reference = value_type&;
const PolicyValues& operator*() const;
const_iterator operator++();
bool operator==(const const_iterator& other) const;
bool operator!=(const const_iterator& other) const;
};

Expand Down
12 changes: 12 additions & 0 deletions tests/management_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ TEST(TestManagementAPI, TestGetList) {
ASSERT_TRUE(casbin::ArrayEquals({"data2_admin"}, e.GetAllRoles()));
}

TEST(TestManagementAPI, TestPolicyIteratorEquality) {
const PolicyValues policy = {"alice", "data1", "read"};
for (auto policies : {PoliciesValues::createWithVector({policy}), PoliciesValues::createWithHashset({policy})}) {
const auto& const_policies = policies;

ASSERT_NE(policies.begin(), policies.end());
ASSERT_EQ(++policies.begin(), policies.end());
ASSERT_NE(const_policies.begin(), const_policies.end());
ASSERT_EQ(++const_policies.begin(), const_policies.end());
}
}

void TestGetPolicy(casbin::Enforcer& e, const PoliciesValues& res) {
PoliciesValues my_res;
my_res = e.GetPolicy();
Expand Down
Loading