Skip to content

Commit aed7d28

Browse files
committed
tests
1 parent 89b88da commit aed7d28

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/scl/test_protocol.cc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* SCL --- Secure Computation Library
2+
* Copyright (C) 2025 Anders Dalskov
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include <catch2/catch_test_macros.hpp>
19+
20+
#include "scl/coro/runtime.h"
21+
#include "scl/coro/task.h"
22+
#include "scl/protocol.h"
23+
24+
using namespace scl;
25+
26+
namespace {
27+
28+
class CountdownProtocol final : public Protocol {
29+
public:
30+
CountdownProtocol(std::size_t n) : m_n(n) {}
31+
32+
Task<Result> run(Env& /* ignored */) const override {
33+
if (m_n > 0) {
34+
co_return Result::nextStep(std::make_unique<CountdownProtocol>(m_n - 1),
35+
m_n);
36+
} else {
37+
co_return Result::done();
38+
}
39+
}
40+
41+
private:
42+
std::size_t m_n;
43+
};
44+
45+
} // namespace
46+
47+
TEST_CASE("Protocol eval") {
48+
std::unique_ptr<Protocol> p = std::make_unique<CountdownProtocol>(10);
49+
50+
auto rt = DefaultRuntime::create();
51+
52+
Env env;
53+
54+
std::size_t cd = 10;
55+
56+
rt->run(runProtocol(std::move(p), env, [&cd](std::any& x) {
57+
REQUIRE(cd == std::any_cast<std::size_t>(x));
58+
cd--;
59+
}));
60+
}

0 commit comments

Comments
 (0)