PageRenderTime 42ms CodeModel.GetById 35ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/run Torrent client/database_test.erl~

http://github.com/anonymous-admin/anonymous
Unknown | 48 lines | 40 code | 8 blank | 0 comment | 0 complexity | 43a500cc723754055db29d3a400b0949 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
16delete_record_test_() ->
17    Record1 = create_record(1),
18   [?_assert(gen_server:cast(database, {notify, torrent_status, {Record1#torrent.id, deleted}}) =:= ok),
19    ?_assert(length(ets:tab2list(database_table)) =:= 1)].
20
21update_record_test_() ->
22    Record2 = create_record(2),
23   [?_assert(gen_server:cast(database, {notify, piece_length, {Record2#torrent.id, 50000}}) =:= ok)].
24
25set_default_path_test_() ->
26    [?assert(gen_server:cast(database, {notify, default_path, {-1, "c:\\"}}) =:= ok)].
27    
28
29create_record(N) ->
30    case N of
31	1 ->
32	    #torrent{id = 1, info_hash_tracker = 2, 
33	     announce = 3, creation_date = 4, comment = 5, 
34	     created_by = 6, encoding = 7, files = 8,
35	     filename = 9, piece_length = 10, 
36	     number_of_pieces = 11, file_length = 12,
37	     bitfield = 13 };
38        2->
39	    #torrent{id = 14, info_hash_tracker = 15, 
40	     announce = 16, creation_date = 18, comment = 19, 
41	     created_by = 20, encoding = 21, files = 22,
42	     filename = 23, piece_length = 24, 
43	     number_of_pieces = 25, file_length = 26,
44	     bitfield = 27 }
45    end.
46
47display_table() ->
48    ets:tab2list(database_table).