|
| 1 | +using FluentAssertions; |
| 2 | +using System.IO; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace Wasmtime.Tests |
| 6 | +{ |
| 7 | + public class StoreTests |
| 8 | + : StoreFixture |
| 9 | + { |
| 10 | + [Fact] |
| 11 | + public void ItSetsLimits() |
| 12 | + { |
| 13 | + Store.SetLimits(1, 2, 3, 4, 5); |
| 14 | + } |
| 15 | + |
| 16 | + [Fact] |
| 17 | + public void ItSetsDefaultLimits() |
| 18 | + { |
| 19 | + Store.SetLimits(null, null, null, null, null); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void ItLimitsMemorySize() |
| 24 | + { |
| 25 | + Store.SetLimits(memorySize: Memory.PageSize); |
| 26 | + |
| 27 | + var memory = new Memory(Store, 0, 1024); |
| 28 | + memory.GetSize().Should().Be(0); |
| 29 | + |
| 30 | + |
| 31 | + memory.Grow(1).Should().Be(0); |
| 32 | + |
| 33 | + var act = () => { memory.Grow(1); }; |
| 34 | + act.Should().Throw<WasmtimeException>(); |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public void ItLimitsTableElements() |
| 39 | + { |
| 40 | + Store.SetLimits(tableElements: 5); |
| 41 | + |
| 42 | + var table = new Table(Store, ValueKind.ExternRef, null, 0); |
| 43 | + table.GetSize().Should().Be(0); |
| 44 | + |
| 45 | + table.Grow(5, null); |
| 46 | + |
| 47 | + var act = () => { table.Grow(1, null); }; |
| 48 | + act.Should().Throw<WasmtimeException>(); |
| 49 | + } |
| 50 | + |
| 51 | + [Fact] |
| 52 | + public void ItLimitsInstances() |
| 53 | + { |
| 54 | + Store.SetLimits(instances: 3); |
| 55 | + |
| 56 | + using var module = Module.FromTextFile(Engine, Path.Combine("Modules", "Trap.wat")); |
| 57 | + |
| 58 | + var inst1 = new Instance(Store, module); |
| 59 | + var inst2 = new Instance(Store, module); |
| 60 | + var inst3 = new Instance(Store, module); |
| 61 | + |
| 62 | + var act = () => { new Instance(Store, module); }; |
| 63 | + act.Should().Throw<WasmtimeException>(); |
| 64 | + } |
| 65 | + |
| 66 | + [Fact] |
| 67 | + public void ItLimitsTables() |
| 68 | + { |
| 69 | + Store.SetLimits(tables: 3); |
| 70 | + |
| 71 | + // This module exports exactly 3 tables |
| 72 | + using var module = Module.FromTextFile(Engine, Path.Combine("Modules", "TableExports.wat")); |
| 73 | + |
| 74 | + var inst1 = new Instance(Store, module); |
| 75 | + |
| 76 | + var act = () => { new Instance(Store, module); }; |
| 77 | + act.Should().Throw<WasmtimeException>(); |
| 78 | + } |
| 79 | + |
| 80 | + [Fact] |
| 81 | + public void ItLimitsMemories() |
| 82 | + { |
| 83 | + Store.SetLimits(memories: 2); |
| 84 | + |
| 85 | + // This module exports 1 memory |
| 86 | + using var module = Module.FromTextFile(Engine, Path.Combine("Modules", "MemoryExports.wat")); |
| 87 | + |
| 88 | + var inst1 = new Instance(Store, module); |
| 89 | + var inst2 = new Instance(Store, module); |
| 90 | + |
| 91 | + var act = () => { new Instance(Store, module); }; |
| 92 | + act.Should().Throw<WasmtimeException>(); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments