Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 118 lines (102 sloc) 4.764 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
-module(app_test).
-include("../include/tftest.hrl").
-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).


%% Way to invoke just one test
start([F]) ->
    ?line {ok, _} = ibrowse:start_link(),
    apply(app_test, F, []),
    ibrowse:stop().

start() ->
    io:format("\n ==== MIME-TYPES TESTS ==== \n\n", []),
    ?line {ok, _} = ibrowse:start_link(),
    test_generated_module(),
    test_default_type(),
    test_yaws_type(),
    test_erlang_type(),
    ibrowse:stop().


test_generated_module() ->
    io:format("generated_module_test\n", []),
    {ok, Host} = inet:gethostname(),
    Node = list_to_atom("test@" ++ Host),
    Vhost1 = {"localhost:8000", 8000},
    Vhost2 = {"localhost:8001", 8001},

    ?line CInfo = rpc:call(Node,mime_types,module_info,[compile]),
    ?line IdDir = rpc:call(Node,yaws,id_dir,[testid]),
    ?line IdDir = filename:dirname(proplists:get_value(source, CInfo)),

    ?line "text/html" = rpc:call(Node,mime_types,default_type,[]),
    ?line "text/html" = rpc:call(Node,mime_types,default_type,[global]),
    ?line "text/html" = rpc:call(Node,mime_types,default_type,[Vhost1]),
    ?line "text/plain; charset=UTF-8" =
        rpc:call(Node,mime_types,default_type,[Vhost2]),

    ?line {yaws, "text/html"} = rpc:call(Node,mime_types,t,["yaws"]),
    ?line {yaws, "text/html"} = rpc:call(Node,mime_types,t,[global,"yaws"]),
    ?line {yaws, "text/html"} = rpc:call(Node,mime_types,t,[Vhost1,"yaws"]),
    ?line {yaws, "text/xhtml; charset=ISO-8859-1"} =
        rpc:call(Node,mime_types,t,[Vhost2,"yaws"]),

    ?line {regular, "text/plain; charset=UTF-8"} =
        rpc:call(Node,mime_types,t,["tst"]),
    ?line {regular, "text/plain; charset=UTF-8"} =
        rpc:call(Node,mime_types,t,[global,"tst"]),
    ?line {regular, "text/plain; charset=UTF-8"} =
        rpc:call(Node,mime_types,t,[Vhost1,"tst"]),
    ?line {regular, "application/x-test; charset=US-ASCII"} =
        rpc:call(Node,mime_types,t,[Vhost2,"tst"]),

    ?line {regular, "text/html"} =
        rpc:call(Node,mime_types,t,["test"]),
    ?line {regular, "text/html"} =
        rpc:call(Node,mime_types,t,[global,"test"]),
    ?line {regular, "text/html"} =
        rpc:call(Node,mime_types,t,[Vhost1,"test"]),
    ?line {regular, "application/x-test; charset=UTF-8"} =
        rpc:call(Node,mime_types,t,[Vhost2,"test"]),

    ?line {php, "text/html"} =
        rpc:call(Node,mime_types,t,["php"]),
    ?line {php, "text/html"} =
        rpc:call(Node,mime_types,t,[global, "php"]),
    ?line {php, "text/html"} =
        rpc:call(Node,mime_types,t,[Vhost1, "php"]),
    ?line {php, "application/x-httpd-php"} =
        rpc:call(Node,mime_types,t,[Vhost2,"php"]),
    ?line {php, "application/x-httpd-php"} =
        rpc:call(Node,mime_types,t,[Vhost2,"PHP"]),
    ?line {regular, "php5", "application/x-httpd-php5"} =
        rpc:call(Node,mime_types,revt,[Vhost2,"5php"]),
    ?line {regular, "PHP5", "application/x-httpd-php5"} =
        rpc:call(Node,mime_types,revt,[Vhost2,"5PHP"]),

    ?line {regular, "text/plain"} =
        rpc:call(Node,mime_types,t,["html"]),
    ?line {regular, "text/plain"} =
        rpc:call(Node,mime_types,t,[global,"html"]),
    ?line {regular, "text/plain"} =
        rpc:call(Node,mime_types,t,[Vhost1,"html"]),
    ?line {regular, "text/plain; charset=UTF-8"} =
        rpc:call(Node,mime_types,t,[Vhost2,"html"]),

    ok.

test_default_type() ->
    io:format("default_type_test\n", []),
    Uri1 = "http://localhost:8000/news",
    Uri2 = "http://localhost:8001/news",
    ?line {ok, "200", Hdrs1, _} = ibrowse:send_req(Uri1, [], get),
    ?line {ok, "200", Hdrs2, _} = ibrowse:send_req(Uri2, [], get),
    ?line "text/html" = proplists:get_value("Content-Type", Hdrs1),
    ?line "text/plain; charset=UTF-8" = proplists:get_value("Content-Type", Hdrs2),
    ok.

test_yaws_type() ->
    io:format("yaws_type_test\n", []),
    Uri1 = "http://localhost:8000/index.yaws",
    Uri2 = "http://localhost:8001/index.yaws",
    ?line {ok, "200", Hdrs1, _} = ibrowse:send_req(Uri1, [], get),
    ?line {ok, "200", Hdrs2, _} = ibrowse:send_req(Uri2, [], get),
    ?line "text/html" = proplists:get_value("Content-Type", Hdrs1),
    ?line "text/xhtml; charset=ISO-8859-1" = proplists:get_value("Content-Type", Hdrs2),
    ok.

test_erlang_type() ->
    io:format("erlang_type_test\n", []),
    Uri1 = "http://localhost:8000/code/myappmod.erl",
    Uri2 = "http://localhost:8001/code/myappmod.erl",
    ?line {ok, "200", Hdrs1, _} = ibrowse:send_req(Uri1, [], get),
    ?line {ok, "200", Hdrs2, _} = ibrowse:send_req(Uri2, [], get),
    ?line "text/html" = proplists:get_value("Content-Type", Hdrs1),
    ?line "text/x-erlang; charset=UTF-8" = proplists:get_value("Content-Type", Hdrs2),
    ok.
Something went wrong with that request. Please try again.