// Copyright Microsoft and Project Verona Contributors. // SPDX-License-Identifier: MIT #include #include #include using namespace verona::cpp; struct Account { int balance; Account(int balance) : balance(balance) {} }; void test_read_only() { size_t num_accounts = 8; std::vector> accounts; for (size_t i = 0; i < num_accounts; i++) accounts.push_back(make_cown(0)); cown_ptr common_account = make_cown(100); when(common_account) << [](acquired_cown account) { account->balance -= 10; }; for (size_t i = 0; i < num_accounts; i++) { when(accounts[i], read(common_account)) << []( acquired_cown write_account, acquired_cown ro_account) { write_account->balance = ro_account->balance; }; when(read(accounts[i])) << [](acquired_cown account) { check(account->balance == 90); }; } when(common_account) << [](acquired_cown account) { account->balance += 10; }; when(read(common_account)) << [](acquired_cown account) { check(account->balance == 100); }; } void test_read_only_fast_send() { // Test that fast sending to a read cown also reschedules the cown cown_ptr account_one = make_cown(100); cown_ptr account_two = make_cown(100); when(read(account_one), read(account_two)) << []( acquired_cown account_one, acquired_cown account_two) { check(account_one->balance == account_two->balance); }; when(read(account_one), read(account_two)) << []( acquired_cown account_one, acquired_cown account_two) { check(account_one->balance == account_two->balance); }; when(account_one, account_two) << [](acquired_cown account_one, acquired_cown account_two) { check(account_one->balance == account_two->balance); }; } int main(int argc, char** argv) { SystematicTestHarness harness(argc, argv); harness.run(test_read_only); }