github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/internal/util/mem_test.go (about) 1 package util 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/tetratelabs/wazero/experimental/wazerotest" 8 ) 9 10 func TestView_nil(t *testing.T) { 11 defer func() { _ = recover() }() 12 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 13 View(mock, 0, 8) 14 t.Error("want panic") 15 } 16 17 func TestView_range(t *testing.T) { 18 defer func() { _ = recover() }() 19 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 20 View(mock, wazerotest.PageSize-2, 8) 21 t.Error("want panic") 22 } 23 24 func TestView_overflow(t *testing.T) { 25 defer func() { _ = recover() }() 26 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 27 View(mock, 1, math.MaxInt64) 28 t.Error("want panic") 29 } 30 31 func TestReadUint8_nil(t *testing.T) { 32 defer func() { _ = recover() }() 33 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 34 ReadUint8(mock, 0) 35 t.Error("want panic") 36 } 37 38 func TestReadUint8_range(t *testing.T) { 39 defer func() { _ = recover() }() 40 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 41 ReadUint8(mock, wazerotest.PageSize) 42 t.Error("want panic") 43 } 44 45 func TestReadUint32_nil(t *testing.T) { 46 defer func() { _ = recover() }() 47 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 48 ReadUint32(mock, 0) 49 t.Error("want panic") 50 } 51 52 func TestReadUint32_range(t *testing.T) { 53 defer func() { _ = recover() }() 54 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 55 ReadUint32(mock, wazerotest.PageSize-2) 56 t.Error("want panic") 57 } 58 59 func TestReadUint64_nil(t *testing.T) { 60 defer func() { _ = recover() }() 61 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 62 ReadUint64(mock, 0) 63 t.Error("want panic") 64 } 65 66 func TestReadUint64_range(t *testing.T) { 67 defer func() { _ = recover() }() 68 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 69 ReadUint64(mock, wazerotest.PageSize-2) 70 t.Error("want panic") 71 } 72 73 func TestWriteUint8_nil(t *testing.T) { 74 defer func() { _ = recover() }() 75 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 76 WriteUint8(mock, 0, 1) 77 t.Error("want panic") 78 } 79 80 func TestWriteUint8_range(t *testing.T) { 81 defer func() { _ = recover() }() 82 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 83 WriteUint8(mock, wazerotest.PageSize, 1) 84 t.Error("want panic") 85 } 86 87 func TestWriteUint32_nil(t *testing.T) { 88 defer func() { _ = recover() }() 89 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 90 WriteUint32(mock, 0, 1) 91 t.Error("want panic") 92 } 93 94 func TestWriteUint32_range(t *testing.T) { 95 defer func() { _ = recover() }() 96 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 97 WriteUint32(mock, wazerotest.PageSize-2, 1) 98 t.Error("want panic") 99 } 100 101 func TestWriteUint64_nil(t *testing.T) { 102 defer func() { _ = recover() }() 103 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 104 WriteUint64(mock, 0, 1) 105 t.Error("want panic") 106 } 107 108 func TestWriteUint64_range(t *testing.T) { 109 defer func() { _ = recover() }() 110 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 111 WriteUint64(mock, wazerotest.PageSize-2, 1) 112 t.Error("want panic") 113 } 114 115 func TestReadString_range(t *testing.T) { 116 defer func() { _ = recover() }() 117 mock := wazerotest.NewModule(wazerotest.NewFixedMemory(wazerotest.PageSize)) 118 ReadString(mock, wazerotest.PageSize+2, math.MaxUint32) 119 t.Error("want panic") 120 }