diff options
| author | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-07-12 19:29:23 +0200 | 
|---|---|---|
| committer | Harald Welte <laforge@gnumonks.org> | 2018-07-16 17:56:25 +0000 | 
| commit | b885ef88c11b5d67f96827abac30a8db75beb5ad (patch) | |
| tree | 23d021b53eb0acec119adca5b86a06389354056e | |
| parent | 59e605944755d5b2af52aebf53b070e0ec110c54 (diff) | |
tests: ctrl: Test received ERROR messages are handled correctly
Change-Id: I3c8e95aaa1ca222d4cd1395e548f8461bf9d4cd6
| -rw-r--r-- | tests/ctrl/ctrl_test.c | 22 | ||||
| -rw-r--r-- | tests/ctrl/ctrl_test.ok | 35 | 
2 files changed, 55 insertions, 2 deletions
| diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c index 8bb917b9..cffb8039 100644 --- a/tests/ctrl/ctrl_test.c +++ b/tests/ctrl/ctrl_test.c @@ -70,18 +70,23 @@ void assert_same_str(const char *label, const char *expect, const char *got)  static void assert_test(struct ctrl_handle *ctrl, struct ctrl_connection *ccon, const struct one_test *t)  {  	struct ctrl_cmd *cmd; +	bool parse_failed;  	struct msgb *msg = msgb_from_string(t->cmd_str);  	int ctx_size_was;  	printf("test: '%s'\n", osmo_escape_str(t->cmd_str, -1));  	printf("parsing:\n"); -	cmd = ctrl_cmd_parse2(ctx, msg); +	cmd = ctrl_cmd_parse3(ctx, msg, &parse_failed);  	OSMO_ASSERT(cmd);  	if (t->expect_parsed.type != cmd->type) {  		printf("type mismatch: got %s\n", get_value_string(ctrl_type_vals, cmd->type));  		OSMO_ASSERT(t->expect_parsed.type == cmd->type); +	} else { +		printf("type = '%s'%s\n", get_value_string(ctrl_type_vals, cmd->type), +		       cmd->type != CTRL_TYPE_ERROR ? "" : +		       (parse_failed ? " (parse failure)" : " (error received)"));  	}  #define ASSERT_SAME_STR(field) \ @@ -310,7 +315,20 @@ static const struct one_test test_messages_list[] = {  			.reply = "OK",  		},  	}, - +	{ "ERROR 1 some error message", +		{ +			.type = CTRL_TYPE_ERROR, +			.id = "1", +			.reply = "some error message", +		}, +	}, +	{ "ERROR err some error message", +		{ +			.type = CTRL_TYPE_ERROR, +			.id = "err", +			.reply = "some error message", +		}, +	},  };  static void test_messages() diff --git a/tests/ctrl/ctrl_test.ok b/tests/ctrl/ctrl_test.ok index 07f4aac5..0705d69c 100644 --- a/tests/ctrl/ctrl_test.ok +++ b/tests/ctrl/ctrl_test.ok @@ -9,6 +9,7 @@ ctrl type 6 is ERROR -> 6 OK  ctrl type 64 is unknown 0x40 [PARSE FAILED]  test: 'GET 1 variable'  parsing: +type = 'GET'  id = '1'  variable = 'variable'  value = '(null)' @@ -18,6 +19,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'GET 1 variable\n'  parsing: +type = 'GET'  id = '1'  variable = 'variable'  value = '(null)' @@ -27,6 +29,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'GET 1 var\ni\nable'  parsing: +type = 'ERROR' (parse failure)  id = '1'  reply = 'GET with trailing characters'  handling: @@ -34,6 +37,7 @@ replied: 'ERROR 1 GET with trailing characters'  ok  test: 'GET 1 var\ti\table'  parsing: +type = 'ERROR' (parse failure)  id = '1'  reply = 'GET variable contains invalid characters'  handling: @@ -41,6 +45,7 @@ replied: 'ERROR 1 GET variable contains invalid characters'  ok  test: 'GET 1 var\ri\rable'  parsing: +type = 'ERROR' (parse failure)  id = '1'  reply = 'GET variable contains invalid characters'  handling: @@ -48,6 +53,7 @@ replied: 'ERROR 1 GET variable contains invalid characters'  ok  test: 'GET 1 variable value'  parsing: +type = 'ERROR' (parse failure)  id = '1'  reply = 'GET with trailing characters'  handling: @@ -55,6 +61,7 @@ replied: 'ERROR 1 GET with trailing characters'  ok  test: 'GET 1 variable value\n'  parsing: +type = 'ERROR' (parse failure)  id = '1'  reply = 'GET with trailing characters'  handling: @@ -62,6 +69,7 @@ replied: 'ERROR 1 GET with trailing characters'  ok  test: 'GET 1 variable multiple value tokens'  parsing: +type = 'ERROR' (parse failure)  id = '1'  reply = 'GET with trailing characters'  handling: @@ -69,6 +77,7 @@ replied: 'ERROR 1 GET with trailing characters'  ok  test: 'GET 1 variable multiple value tokens\n'  parsing: +type = 'ERROR' (parse failure)  id = '1'  reply = 'GET with trailing characters'  handling: @@ -76,6 +85,7 @@ replied: 'ERROR 1 GET with trailing characters'  ok  test: 'SET 1 variable value'  parsing: +type = 'SET'  id = '1'  variable = 'variable'  value = 'value' @@ -85,6 +95,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'SET 1 variable value\n'  parsing: +type = 'SET'  id = '1'  variable = 'variable'  value = 'value' @@ -94,6 +105,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'SET weird_id variable value'  parsing: +type = 'ERROR' (parse failure)  id = 'err'  reply = 'Invalid message ID number'  handling: @@ -101,6 +113,7 @@ replied: 'ERROR err Invalid message ID number'  ok  test: 'SET weird_id variable value\n'  parsing: +type = 'ERROR' (parse failure)  id = 'err'  reply = 'Invalid message ID number'  handling: @@ -108,6 +121,7 @@ replied: 'ERROR err Invalid message ID number'  ok  test: 'SET 1 variable multiple value tokens'  parsing: +type = 'SET'  id = '1'  variable = 'variable'  value = 'multiple value tokens' @@ -117,6 +131,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'SET 1 variable multiple value tokens\n'  parsing: +type = 'SET'  id = '1'  variable = 'variable'  value = 'multiple value tokens' @@ -126,6 +141,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'SET 1 variable value_with_trailing_spaces  '  parsing: +type = 'SET'  id = '1'  variable = 'variable'  value = 'value_with_trailing_spaces  ' @@ -135,6 +151,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'SET 1 variable value_with_trailing_spaces  \n'  parsing: +type = 'SET'  id = '1'  variable = 'variable'  value = 'value_with_trailing_spaces  ' @@ -144,6 +161,7 @@ replied: 'ERROR 1 Command not found'  ok  test: 'SET \n special_char_id value'  parsing: +type = 'ERROR' (parse failure)  id = 'err'  reply = 'Invalid message ID number'  handling: @@ -151,6 +169,7 @@ replied: 'ERROR err Invalid message ID number'  ok  test: 'SET \t special_char_id value'  parsing: +type = 'ERROR' (parse failure)  id = 'err'  reply = 'Invalid message ID number'  handling: @@ -158,6 +177,7 @@ replied: 'ERROR err Invalid message ID number'  ok  test: 'GET_REPLY 1 variable OK'  parsing: +type = 'GET_REPLY'  id = '1'  variable = 'variable'  value = '(null)' @@ -166,12 +186,27 @@ handling:  ok  test: 'SET_REPLY 1 variable OK'  parsing: +type = 'SET_REPLY'  id = '1'  variable = 'variable'  value = '(null)'  reply = 'OK'  handling:  ok +test: 'ERROR 1 some error message' +parsing: +type = 'ERROR' (error received) +id = '1' +reply = 'some error message' +handling: +ok +test: 'ERROR err some error message' +parsing: +type = 'ERROR' (error received) +id = 'err' +reply = 'some error message' +handling: +ok  test_deferred_cmd  get_test_defer called | 
