From 73a6c28e22991f2f6dc0ab303c1c5274f083de77 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Tue, 29 Apr 2014 13:32:37 +0200 Subject: First cut at adding DB support. Including half crazy rewrite of most of the data structures. --- src/test/plop_test.erl | 52 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'src/test/plop_test.erl') diff --git a/src/test/plop_test.erl b/src/test/plop_test.erl index 87329c6..8a308c0 100644 --- a/src/test/plop_test.erl +++ b/src/test/plop_test.erl @@ -7,12 +7,13 @@ start_stop_test_() -> {setup, fun start/0, fun stop/1, fun is_registered/1}}. %% "Entries can be added and the STH changes." +%% FIXME: This way, if a test fails, we don't stop plop. The tests +%% must run and be validated in strict order though. adding_verifying_test() -> Pid = start(), - add(), - sth(), - %% TODO: add one more and verify that the STH changes - %% add(), + add(0), + sth(0), + add(1), %% sth(), stop(Pid). @@ -30,7 +31,7 @@ is_registered(Pid) -> ?_assertEqual(Pid, whereis(plop))]. %%% Helpers. -add() -> +add(0) -> TestVector = <<1,247,141,118,3,148,171,128,29,143,106,97,200,179,204,166,242,98,70,185,231, 78,193,39,12,245,82,254,230,136,69,69,0,0,0,0,0,0,0,18,103,69,73,8,105,107, @@ -46,11 +47,42 @@ add() -> 90,254,167,119,10,136,211,20,178,251,244,124,87,223,61,102,244,143,98,213,59, 217,84,80,64,22,209,1,63,64,185,63,13,115,43,36,143,93,19,206,234,100,181, 203,214,189,144,145,21,247,165,125,192,43,94,247,209,81,50,100>>, - Entry = #plop_entry{type = test, data = <<"some data">>}, - SPT = #spt{signature_type = test, timestamp = 4711, entry = Entry}, - ?assertEqual(TestVector, plop:add(SPT)). + Entry = #timestamped_entry{timestamp = 4711, + entry_type = test, + entry = <<"some data">>}, + SPT = plop:add(Entry), + ?assertEqual(TestVector, SPT); +add(1) -> + TestVector = + <<1,247,141,118,3,148,171,128,29,143,106,97,200,179,204,166,242,98,70,185,231, + 78,193,39,12,245,82,254,230,136,69,69,0,0,0,0,0,0,0,18,104,141,82,14,84,52, + 131,244,51,145,16,7,238,168,117,8,184,95,165,94,116,234,87,145,43,39,223,243, + 33,159,238,239,195,203,246,232,147,125,234,34,147,83,254,253,248,133,49,81, + 80,7,104,23,24,147,24,116,147,183,20,58,165,53,147,196,226,250,135,18,115, + 182,139,194,190,60,97,103,240,188,86,184,194,21,75,79,136,84,62,53,123,44, + 236,244,24,190,207,193,42,156,230,135,174,90,195,89,174,185,228,129,148,78, + 255,168,104,73,142,85,11,239,222,227,213,208,99,31,12,177,223,187,11,216,119, + 29,231,67,82,140,103,181,173,71,246,112,57,121,153,204,1,249,251,172,26,77, + 96,223,129,102,14,160,115,10,87,105,234,21,99,65,125,198,35,104,160,43,25,74, + 159,64,236,226,126,208,88,199,60,12,88,36,214,174,110,147,215,142,1,205,77, + 116,119,47,222,87,84,99,78,131,212,247,138,156,190,211,244,184,140,46,202,13, + 217,28,20,109,8,129,62,226,37,51,123,94,151,151,47,96,111,122,118,178,242,14, + 213,35,184,204,165,157,199,1,210,74,243,180,36,85,163,69,166,79,136>>, + Entry = #timestamped_entry{timestamp = 4712, + entry_type = test, + entry = <<"some more data">>}, + SPT = plop:add(Entry), + %%io:format(element(2, file:open("foo", write)), "~p", [SPT]), + ?assertEqual(TestVector, SPT). +%% add(2) -> +%% TestVector = <<>>, +%% %% Same data as in 0, should not result in new database entry. +%% Entry = #timestamped_entry{timestamp = 4713, entry_type = test, entry = <<"some data">>}, +%% SPT = plop:add(#spt{signature_type = test, entry = Entry}), +%% ?assertEqual(TestVector, SPT), +%% ?assertEqual(fixme, fixme). -sth() -> +sth(0) -> TestVector = <<0,0,0,0,0,0,0,1,0,0,0,0,0,0,18,103,93,90,159,157,211,129,96,54,161,145,226, 218,28,127,43,87,221,243,153,101,255,249,156,114,234,50,84,163,183,64,215, @@ -68,5 +100,5 @@ sth() -> 187,221,242,23,254,196,182,98,110,150,95,126,53,42,243,123,198,30,247,79,17, 172,129>>, STH = plop:sth(#sth{timestamp = 4711}), - %%io:format(element(2, file:open("foo", write)), "~p", [STH]), + io:format(element(2, file:open("testdata", write)), "~p", [STH]), ?assertEqual(TestVector, STH). -- cgit v1.1