2015-10-14 11:28:01 +00:00
|
|
|
-module(machi_csum_table_test).
|
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
smoke_test() ->
|
|
|
|
Filename = "./temp-checksum-dumb-file",
|
2015-10-16 00:33:16 +00:00
|
|
|
_ = file:delete(Filename),
|
|
|
|
{ok, MC} = machi_csum_table:open(Filename, []),
|
2015-10-14 11:28:01 +00:00
|
|
|
{Offset, Size, Checksum} = {64, 34, <<"deadbeef">>},
|
2015-10-16 00:33:16 +00:00
|
|
|
{error, unknown_chunk} = machi_csum_table:find(MC, Offset, Size),
|
|
|
|
ok = machi_csum_table:write(MC, Offset, Size, Checksum),
|
|
|
|
{ok, Checksum} = machi_csum_table:find(MC, Offset, Size),
|
|
|
|
ok = machi_csum_table:trim(MC, Offset, Size),
|
|
|
|
{error, trimmed} = machi_csum_table:find(MC, Offset, Size),
|
|
|
|
ok = machi_csum_table:close(MC),
|
|
|
|
ok = machi_csum_table:delete(MC).
|
2015-10-14 11:28:01 +00:00
|
|
|
|
|
|
|
close_test() ->
|
|
|
|
Filename = "./temp-checksum-dumb-file-2",
|
2015-10-16 00:33:16 +00:00
|
|
|
_ = file:delete(Filename),
|
|
|
|
{ok, MC} = machi_csum_table:open(Filename, []),
|
2015-10-14 11:28:01 +00:00
|
|
|
{Offset, Size, Checksum} = {64, 34, <<"deadbeef">>},
|
2015-10-16 00:33:16 +00:00
|
|
|
{error, unknown_chunk} = machi_csum_table:find(MC, Offset, Size),
|
|
|
|
ok = machi_csum_table:write(MC, Offset, Size, Checksum),
|
|
|
|
{ok, Checksum} = machi_csum_table:find(MC, Offset, Size),
|
|
|
|
ok = machi_csum_table:close(MC),
|
2015-10-14 11:28:01 +00:00
|
|
|
|
2015-10-16 00:33:16 +00:00
|
|
|
{ok, MC2} = machi_csum_table:open(Filename, []),
|
|
|
|
{ok, Checksum} = machi_csum_table:find(MC2, Offset, Size),
|
|
|
|
ok = machi_csum_table:trim(MC2, Offset, Size),
|
|
|
|
{error, trimmed} = machi_csum_table:find(MC2, Offset, Size),
|
|
|
|
ok = machi_csum_table:delete(MC2).
|