88 lines
2.2 KiB
C++
88 lines
2.2 KiB
C++
|
|
#include <gtest/gtest.h>
|
||
|
|
|
||
|
|
#include <cctype>
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
#include "cases.hpp"
|
||
|
|
#include "registry.hpp"
|
||
|
|
#include "spawn.hpp"
|
||
|
|
|
||
|
|
namespace
|
||
|
|
{
|
||
|
|
|
||
|
|
class PartyFlowTest : public ::testing::TestWithParam<std::string>
|
||
|
|
{
|
||
|
|
};
|
||
|
|
|
||
|
|
TEST_P(PartyFlowTest, Trio)
|
||
|
|
{
|
||
|
|
dpf::party::register_all_flows();
|
||
|
|
const auto & name = GetParam();
|
||
|
|
const auto * f = dpf::party::find_flow(name);
|
||
|
|
ASSERT_NE(f, nullptr) << name;
|
||
|
|
// IKNP replaces the dealer. Spawning p2 makes that role call a keygen
|
||
|
|
// that refuses `role::p2` (`iknp point/comparison keygen has no dealer`).
|
||
|
|
const bool pair = dpf::party::flow_is_pair(*f);
|
||
|
|
auto r = pair ? dpf::party::spawn_pair_flow(name)
|
||
|
|
: dpf::party::spawn_trio_flow(name);
|
||
|
|
EXPECT_EQ(r.rc[0], 0) << "p0 failed for " << name;
|
||
|
|
EXPECT_EQ(r.rc[1], 0) << "p1 failed for " << name;
|
||
|
|
if (!pair)
|
||
|
|
EXPECT_EQ(r.rc[2], 0) << "p2 failed for " << name;
|
||
|
|
else
|
||
|
|
EXPECT_EQ(r.rc[2], 0) << "pair spawn must not report a dealer";
|
||
|
|
}
|
||
|
|
|
||
|
|
std::vector<std::string> all_flow_names()
|
||
|
|
{
|
||
|
|
dpf::party::register_all_flows();
|
||
|
|
std::vector<std::string> names;
|
||
|
|
for (const auto * f : dpf::party::select_flows({}))
|
||
|
|
names.emplace_back(f->name);
|
||
|
|
return names;
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(PartyFlow, PairFlowsAreTheIknpOnes)
|
||
|
|
{
|
||
|
|
dpf::party::register_all_flows();
|
||
|
|
int pairs = 0;
|
||
|
|
int trios = 0;
|
||
|
|
for (const auto * f : dpf::party::select_flows({}))
|
||
|
|
{
|
||
|
|
ASSERT_NE(f, nullptr);
|
||
|
|
ASSERT_NE(f->name, nullptr);
|
||
|
|
const std::string name = f->name;
|
||
|
|
const bool iknp = name.rfind("iknp_", 0) == 0
|
||
|
|
|| dpf::party::flow_has_tag(*f, "iknp");
|
||
|
|
EXPECT_EQ(dpf::party::flow_is_pair(*f), iknp) << name;
|
||
|
|
if (iknp)
|
||
|
|
{
|
||
|
|
++pairs;
|
||
|
|
EXPECT_EQ(name.rfind("iknp_", 0), 0u) << name;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
++trios;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
EXPECT_GE(pairs, 5);
|
||
|
|
EXPECT_GT(trios, pairs);
|
||
|
|
}
|
||
|
|
|
||
|
|
INSTANTIATE_TEST_SUITE_P(
|
||
|
|
AllFlows,
|
||
|
|
PartyFlowTest,
|
||
|
|
::testing::ValuesIn(all_flow_names()),
|
||
|
|
[](const auto & info) {
|
||
|
|
std::string n = info.param;
|
||
|
|
for (char & c : n)
|
||
|
|
{
|
||
|
|
if (!(std::isalnum(static_cast<unsigned char>(c)) || c == '_'))
|
||
|
|
c = '_';
|
||
|
|
}
|
||
|
|
return n;
|
||
|
|
});
|
||
|
|
|
||
|
|
} // namespace
|