PageRenderTime 25ms CodeModel.GetById 23ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/Testenviro/#database_test.erl#

http://github.com/anonymous-admin/anonymous
Unknown | 50 lines | 42 code | 8 blank | 0 comment | 0 complexity | 4b7917d58744994bf90ad4ea059596b7 MD5 | raw file
 1-module(database_test).
 2-include_lib("eunit/include/eunit.hrl").
 3-include("defs.hrl").
 4-export([create_record/1, display_table/0]).
 5
 6start_test_() ->
 7    [?_assert(database:start_link() =:= ok)].
 8
 9insert_record_test_() ->
10    Record1 = create_record(1),
11    Record2 = create_record(2),
12   [?_assert(gen_server:cast(database, {notify, torrent_info, {Record1#torrent.id, Record1}}) =:= ok),
13    ?_assert(gen_server:cast(database, {notify, torrent_info, {Record2#torrent.id, Record2}}) =:= ok),
14    ?_assert(length(ets:tab2list(database_table)) =:= 2)].
15
16   [?_assert(torrent_info:alltorrent_info(f.torrent) =:= ok),
17    ?_assert(torrent_info:start_link() =:= {ok, Pid}),
18    ?_assert(tracker:start_link() =:= {ok, Pid}),
19    ?_assert(gen_server:cast(parser, )
20
21delete_record_test_() ->
22    Record1 = create_record(1),
23   [?_assert(gen_server:cast(database, {notify, torrent_status, {Record1#torrent.id, deleted}}) =:= ok),
24    ?_assert(length(ets:tab2list(database_table)) =:= 1)].
25
26update_record_test_() ->
27    Record2 = create_record(2),
28   [?_assert(gen_server:cast(database, {notify, piece_length, {Record2#torrent.id, 50000}}) =:= ok)].
29    
30
31create_record(N) ->
32    case N of
33	1 ->
34	    #torrent{id = 1, info_hash_tracker = 2, 
35	     announce = 3, creation_date = 4, comment = 5, 
36	     created_by = 6, encoding = 7, files = 8,
37	     filename = 9, piece_length = 10, 
38	     number_of_pieces = 11, file_length = 12,
39	     bitfield = 13 };
40        2->
41	    #torrent{id = 14, info_hash_tracker = 15, 
42	     announce = 16, creation_date = 18, comment = 19, 
43	     created_by = 20, encoding = 21, files = 22,
44	     filename = 23, piece_length = 24, 
45	     number_of_pieces = 25, file_length = 26,
46	     bitfield = 27 }
47    end.
48
49display_table() ->
50    ets:tab2list(database_table).