Subversion Repositories SE.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12 7u83 1
-module(mochiweb_base64url_tests).
2
-include_lib("eunit/include/eunit.hrl").
3
 
4
id(X) ->
5
    ?assertEqual(
6
       X,
7
       mochiweb_base64url:decode(mochiweb_base64url:encode(X))),
8
    ?assertEqual(
9
       X,
10
       mochiweb_base64url:decode(
11
         binary_to_list(mochiweb_base64url:encode(binary_to_list(X))))).
12
-ifdef(rand_mod_unavailable).
13
random_binary(Short,Long) ->
14
    << <<(random:uniform(256) - 1)>>
15
     || _ <- lists:seq(1, Short + random:uniform(1 + Long - Short) - 1) >>.
16
-else.
17
random_binary(Short,Long) ->
18
    << <<(rand:uniform(256) - 1)>>
19
     || _ <- lists:seq(1, Short + rand:uniform(1 + Long - Short) - 1) >>.
20
-endif.
21
 
22
empty_test() ->
23
    id(<<>>).
24
 
25
onechar_test() ->
26
    [id(<<C>>) || C <- lists:seq(0,255)],
27
    ok.
28
 
29
nchar_test() ->
30
    %% 1000 tests of 2-6 char strings
31
    [id(B) || _ <- lists:seq(1,1000), B <- [random_binary(2, 6)]],
32
    ok.