anchor.diff:      ok = diameter:stop_service(?SERVER),
       ok = diameter:stop_service(?CLIENT).
   
  +%% send_unknown_application/1
  +%%
  +%% Send an unknown application that a callback (which shouldn't take
  +%% place) fails on.
  +
  +%% diameter answers.
  +send_unknown_application([_,_]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 3007,
  +                                                 %% UNSUPPORTED_APPLICATION
  +                                    'Failed-AVP' = [],
  +                                    'AVP' = []}
  +        = call();
  +
  +send_unknown_application(Config) ->
  +    send_unknown_application(?group(Config)).
  +
   %% send_unknown_command/1
   %%
  -%% Send a unknown command and expect a different result depending on
  -%% whether or not the server gets a handle_request callback.
  -
  -%% Server handle_request discards the request.
  -send_unknown_command(callback) ->
  +%% Send a unknown command that a callback discards.
  +
  +%% handle_request discards the request.
  +send_unknown_command([callback, _]) ->
       {error, timeout} = call();
   
  -%% No handle_request, diameter answers.
  -send_unknown_command(answer_3xxx) ->
  -    #'diameter_base_answer-message'{'Result-Code' = ?UNSUPPORTED_COMMAND}
  +%% diameter answers.
  +send_unknown_command([_,_]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 3001,
  +                                                 %% UNSUPPORTED_COMMAND
  +                                    'Failed-AVP' = [],
  +                                    'AVP' = []}
           = call();
   
   send_unknown_command(Config) ->
  -    ?testcase(Config),
       send_unknown_command(?group(Config)).
   
  -%% send_ok_override/1
  -%%
  -%% Send a correct STA and expect the same answer from handle_request
  -%% in both cases.
  -
  -send_ok_override(A)
  -  when is_atom(A) ->
  -    #diameter_base_STA{'Result-Code' = ?UNKNOWN_SESSION_ID}
  -        = call();
  -
  -send_ok_override(Config) ->
  -    ?testcase(Config),
  -    send_ok_override(?group(Config)).
  +%% send_ok/1
  +%%
  +%% Send a correct STR that a callback answers with 5002.
  +
  +%% Callback answers.
  +send_ok([_,_]) ->
  +    #diameter_base_STA{'Result-Code' = 5002,  %% UNKNOWN_SESSION_ID
  +                       'Failed-AVP' = [],
  +                       'AVP' = []}
  +        = call();
  +
  +send_ok(Config) ->
  +    send_ok(?group(Config)).
   
   %% send_invalid_avp_bits/1
   %%
   %% Send a request with an incorrect length on the optional
  -%% Origin-State-Id and expect a callback to ignore the error.
  -
  -send_invalid_avp_bits(callback) ->
  -    #diameter_base_STA{'Result-Code' = ?SUCCESS,
  -                       'Failed-AVP' = []}
  -        = call();
  -
  -send_invalid_avp_bits(answer_3xxx) ->
  -    #'diameter_base_answer-message'{'Result-Code' = ?INVALID_AVP_BITS,
  -                                    'Failed-AVP' = []}
  +%% Origin-State-Id that a callback ignores.
  +
  +%% Callback answers.
  +send_invalid_avp_bits([callback, _]) ->
  +    #diameter_base_STA{'Result-Code' = 2001,  %% SUCCESS
  +                       'Failed-AVP' = [],
  +                       'AVP' = []}
  +        = call();
  +
  +%% diameter answers.
  +send_invalid_avp_bits([_,_]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 3009, %% INVALID_AVP_BITS
  +                                    'Failed-AVP' = [],
  +                                    'AVP' = []}
           = call();
   
   send_invalid_avp_bits(Config) ->
  -    ?testcase(Config),
       send_invalid_avp_bits(?group(Config)).
   
  +%% send_missing_avp/1
  +%%
  +%% Send a request with a missing AVP that a callback answers.
  +
  +%% diameter answers.
  +send_missing_avp([answer, rfc6733]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 5005,  %% MISSING_AVP
  +                                    'Failed-AVP' = [_],
  +                                    'AVP' = []}
  +        = call();
  +
  +%% Callback answers.
  +send_missing_avp([_,_]) ->
  +    #diameter_base_STA{'Result-Code' = 5005,  %% MISSING_AVP
  +                       'Failed-AVP' = [_],
  +                       'AVP' = []}
  +        = call();
  +
  +send_missing_avp(Config) ->
  +    send_missing_avp(?group(Config)).
  +
  +%% send_ignore_missing_avp/1
  +%%
  +%% Send a request with a missing AVP that a callback ignores.
  +
  +%% diameter answers.
  +send_ignore_missing_avp([answer, rfc6733]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 5005,  %% MISSING_AVP
  +                                    'Failed-AVP' = [_],
  +                                    'AVP' = []}
  +        = call();
  +
  +%% Callback answers, ignores the error
  +send_ignore_missing_avp([_,_]) ->
  +    #diameter_base_STA{'Result-Code' = 2001,  %% SUCCESS
  +                       'Failed-AVP' = [],
  +                       'AVP' = []}
  +        = call();
  +
  +send_ignore_missing_avp(Config) ->
  +    send_ignore_missing_avp(?group(Config)).
  +
   %% send_double_error/1
   %%
   %% Send a request with both an incorrect length on the optional
  -%% Origin-State-Id and a missing AVP and see that it's answered
  -%% differently.
  -
  -%% diameter answers with the 3xxx error.
  -send_double_error(answer_3xxx) ->
  -    #'diameter_base_answer-message'{'Result-Code' = ?INVALID_AVP_BITS,
  -                                    'Failed-AVP' = [_]}
  -        = call();
  -
  -%% handle_request answers with STA and diameter resets Result-Code.
  -send_double_error(callback) ->
  -    #diameter_base_STA{'Result-Code' = ?MISSING_AVP,
  -                       'Failed-AVP' = [_]}
  +%% Origin-State-Id and a missing AVP.
  +
  +%% Callback answers with STA.
  +send_double_error([callback, _]) ->
  +    #diameter_base_STA{'Result-Code' = 5005,  %% MISSING_AVP
  +                       'Failed-AVP' = [_],
  +                       'AVP' = []}
  +        = call();
  +
  +%% diameter answers with answer-message.
  +send_double_error([_,_]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 3009, %% INVALID_AVP_BITS
  +                                    'Failed-AVP' = [_],
  +                                    'AVP' = []}
           = call();
   
   send_double_error(Config) ->
  -    ?testcase(Config),
       send_double_error(?group(Config)).
  +
  +%% send_3xxx/1
  +%%
  +%% Send a request that's answered with a 3xxx result code.
  +
  +%% Callback answers.
  +send_3xxx([_,_]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 3999,
  +                                    'Failed-AVP' = [],
  +                                    'AVP' = []}
  +        = call();
  +
  +send_3xxx(Config) ->
  +    send_3xxx(?group(Config)).
  +
  +%% send_5xxx/1
  +%%
  +%% Send a request that's answered with a 5xxx result code.
  +
  +%% Callback answers but fails since 5xxx isn't allowed in an RFC 3588
  +%% answer-message.
  +send_5xxx([_, rfc3588]) ->
  +    {error, timeout} = call();
  +
  +%% Callback answers.
  +send_5xxx([_,_]) ->
  +    #'diameter_base_answer-message'{'Result-Code' = 5999,
  +                                    'Failed-AVP' = [],
  +                                    'AVP' = []}
  +        = call();
  +
  +send_5xxx(Config) ->
  +    send_5xxx(?group(Config)).
   
   %% ===========================================================================
   
  
positive.code: 
  %% handle_request/3
  
  %% send_unknown_command
  handle_request(#diameter_packet{msg = undefined}, ?SERVER, _) ->
      discard;
  
  handle_request(#diameter_packet{msg = Req}, ?SERVER, {_, Caps}) ->
      #diameter_base_STR{'Class' = [Name]}
          = Req,
      {reply, request(?A(Name), Req, Caps)}.
  
  request(send_ok_override, Req, Caps) ->
      #diameter_packet{msg = answer(Req, Caps),
                       errors = [?UNKNOWN_SESSION_ID]};  %% override
  
  request(send_invalid_avp_bits, Req, Caps) ->
      #diameter_base_STR{'Origin-State-Id' = []}
  
negative.code: 
  %% testcases
  -export([start/1,
           send_unknown_application/1,
           send_unknown_command/1,
           send_ok/1,
           send_invalid_avp_bits/1,
           send_missing_avp/1,
           send_ignore_missing_avp/1,
           send_double_error/1,
           send_3xxx/1,
           send_5xxx/1,
           stop/1]).
  
  %% diameter callbacks
  