1: %%
    2: %% %CopyrightBegin%
    3: %%
    4: %% Copyright Ericsson AB 2007-2011. All Rights Reserved.
    5: %%
    6: %% The contents of this file are subject to the Erlang Public License,
    7: %% Version 1.1, (the "License"); you may not use this file except in
    8: %% compliance with the License. You should have received a copy of the
    9: %% Erlang Public License along with this software. If not, it can be
   10: %% retrieved online at http://www.erlang.org/.
   11: %%
   12: %% Software distributed under the License is distributed on an "AS IS"
   13: %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
   14: %% the License for the specific language governing rights and limitations
   15: %% under the License.
   16: %%
   17: %% %CopyrightEnd%
   18: %%
   19: 
   20: %%
   21: 
   22: -module(odbc_start_SUITE).
   23: 
   24: %% Note: This directive should only be used in test suites.
   25: -compile(export_all).
   26: 
   27: -include_lib("common_test/include/ct.hrl").
   28: -include("test_server_line.hrl").
   29: -include("odbc_test.hrl").
   30: 
   31: %% Test server callback functions
   32: %%--------------------------------------------------------------------
   33: %% Function: init_per_suite(Config) -> Config
   34: %% Config - [tuple()]
   35: %%   A list of key/value pairs, holding the test case configuration.
   36: %% Description: Initialization before the whole suite
   37: %%
   38: %% Note: This function is free to add any key/value pairs to the Config
   39: %% variable, but should NOT alter/remove any existing entries.
   40: %%--------------------------------------------------------------------
   41: init_per_suite(Config) ->
   42:     case odbc_test_lib:skip() of
   43: 	true ->
   44: 	    {skip, "ODBC not supported"};
   45: 	false ->
   46: 	    case code:which(odbc) of
   47: 		non_existing ->
   48: 		    {skip, "No ODBC built"};
   49: 		_ ->
   50: 		    %% Make sure odbc is not already started
   51: 		    odbc:stop(),
   52: 		    [{tableName, odbc_test_lib:unique_table_name()} | Config]
   53: 	    end
   54:     end.
   55: 
   56: %%--------------------------------------------------------------------
   57: %% Function: end_per_suite(Config) -> _
   58: %% Config - [tuple()]
   59: %%   A list of key/value pairs, holding the test case configuration.
   60: %% Description: Cleanup after the whole suite
   61: %%--------------------------------------------------------------------
   62: end_per_suite(_Config) ->
   63:     ok.
   64: %%--------------------------------------------------------------------
   65: %% Function: init_per_testcase(TestCase, Config) -> Config
   66: %% Case - atom()
   67: %%   Name of the test case that is about to be run.
   68: %% Config - [tuple()]
   69: %%   A list of key/value pairs, holding the test case configuration.
   70: %%
   71: %% Description: Initialization before each test case
   72: %%
   73: %% Note: This function is free to add any key/value pairs to the Config
   74: %% variable, but should NOT alter/remove any existing entries.
   75: %% Description: Initialization before each test case
   76: %%--------------------------------------------------------------------
   77: init_per_testcase(_TestCase, Config0) ->
   78:     test_server:format("ODBCINI = ~p~n", [os:getenv("ODBCINI")]),
   79:     Config = lists:keydelete(watchdog, 1, Config0),
   80:     Dog = test_server:timetrap(?TIMEOUT),
   81:     [{watchdog, Dog} | Config].
   82: 
   83: %%--------------------------------------------------------------------
   84: %% Function: end_per_testcase(TestCase, Config) -> _
   85: %% Case - atom()
   86: %%   Name of the test case that is about to be run.
   87: %% Config - [tuple()]
   88: %%   A list of key/value pairs, holding the test case configuration.
   89: %% Description: Cleanup after each test case
   90: %%--------------------------------------------------------------------
   91: end_per_testcase(_TestCase, Config) ->
   92:     Dog = ?config(watchdog, Config),
   93:     case Dog of 
   94: 	undefined ->
   95: 	    ok;
   96: 	_ ->
   97: 	    test_server:timetrap_cancel(Dog)
   98:     end.
   99: 
  100: %%--------------------------------------------------------------------
  101: %% Function: all(Clause) -> TestCases
  102: %% Clause - atom() - suite | doc
  103: %% TestCases - [Case] 
  104: %% Case - atom()
  105: %%   Name of a test case.
  106: %% Description: Returns a list of all test cases in this test suite
  107: %%--------------------------------------------------------------------
  108: suite() -> [{ct_hooks,[ts_install_cth]}].
  109: 
  110: all() -> 
  111:     case odbc_test_lib:odbc_check() of
  112: 	ok -> [start];
  113: 	Other -> {skip, Other}
  114:     end.
  115: 
  116: groups() -> 
  117:     [].
  118: 
  119: init_per_group(_GroupName, Config) ->
  120:     Config.
  121: 
  122: end_per_group(_GroupName, Config) ->
  123:     Config.
  124: 
  125: 
  126: 
  127: %% Test cases starts here.
  128: %%--------------------------------------------------------------------
  129: 
  130: start(doc) -> 
  131:     ["Test start/stop of odbc"];
  132: start(suite) -> 
  133:     [];
  134: start(Config) when is_list(Config) -> 
  135:     PlatformOptions = odbc_test_lib:platform_options(),
  136: 	{error,odbc_not_started} = odbc:connect(?RDBMS:connection_string(),
  137: 					    PlatformOptions),
  138:     odbc:start(),
  139:     case odbc:connect(?RDBMS:connection_string(), PlatformOptions) of
  140: 	{ok, Ref0} ->
  141: 	    ok = odbc:disconnect(Ref0),
  142: 	    odbc:stop(),
  143: 	    {error,odbc_not_started} = 
  144: 		odbc:connect(?RDBMS:connection_string(), PlatformOptions),
  145: 	    start_odbc(transient),
  146: 	    start_odbc(permanent);
  147: 	{error, odbc_not_started} ->
  148: 	    test_server:fail(start_failed);
  149: 	Error ->
  150: 	    test_server:format("Connection failed: ~p~n", [Error]),
  151: 	    {skip, "ODBC is not properly setup"}
  152:     end.
  153:     
  154: start_odbc(Type) ->
  155:     ok = odbc:start(Type),
  156:     case odbc:connect(?RDBMS:connection_string(), odbc_test_lib:platform_options()) of
  157: 	{ok, Ref} ->
  158: 	    ok = odbc:disconnect(Ref),
  159: 	    odbc:stop();
  160: 	{error, odbc_not_started} ->
  161: 	    test_server:fail(start_failed)
  162:     end.