diff --git a/src/adapter/adapter.c b/src/adapter/adapter.c index 9e46a3df..efdd7038 100644 --- a/src/adapter/adapter.c +++ b/src/adapter/adapter.c @@ -1325,8 +1325,8 @@ int add_gtags(neu_adapter_t *adapter, neu_req_add_gtag_t *cmd, if (add_tag_result != 0) { for (int added_group_index = 0; added_group_index < group_index; added_group_index++) { - for (int added_tag_index = 0; added_tag_index <= - cmd->groups[added_group_index].n_tag; + for (int added_tag_index = 0; + added_tag_index < cmd->groups[added_group_index].n_tag; added_tag_index++) { neu_adapter_driver_del_tag( (neu_adapter_driver_t *) adapter, diff --git a/tests/ft/tag/test_tag.py b/tests/ft/tag/test_tag.py index ed51e64b..2add729a 100644 --- a/tests/ft/tag/test_tag.py +++ b/tests/ft/tag/test_tag.py @@ -355,4 +355,106 @@ class TestLog: assert 2 == response.json()['groups'][1]['tag_count'] assert 'group_3' == response.json()['groups'][2]['group'] assert 3000 == response.json()['groups'][2]['interval'] - assert 2 == response.json()['groups'][2]['tag_count'] \ No newline at end of file + assert 2 == response.json()['groups'][2]['tag_count'] + + @description(given="multiple groups including same name tags in the first group", when="adding", then="add failed") + def test_adding_same_name_gtags_first_group(self): + response = api.add_gtags( + node='modbus-tcp-tag-test', + groups=[ + { + "group": "group_f", + "interval": 3000, + "tags": [ + { + "name": "tag1", + "address": "1!400001", + "attribute": 3, + "type": 3, + "decimal": 0.01 + }, + { + "name": "tag1", + "address": "1!400002", + "attribute": 3, + "type": 9, + "precision": 3 + } + ] + }, + { + "group": "group_s", + "interval": 3000, + "tags": [ + { + "name": "tag1", + "address": "1!400001", + "attribute": 3, + "type": 9, + "precision": 3 + }, + { + "name": "tag2", + "address": "1!400002", + "attribute": 3, + "type": 9, + "precision": 3 + } + ] + } + ] + ) + + assert 409 == response.status_code + assert NEU_ERR_TAG_NAME_CONFLICT == response.json()['error'] + + @description(given="multiple groups including same name tags in the second group", when="adding", then="add failed") + def test_adding_same_name_gtags_second_group(self): + response = api.add_gtags( + node='modbus-tcp-tag-test', + groups=[ + { + "group": "group_f", + "interval": 3000, + "tags": [ + { + "name": "tag1", + "address": "1!400001", + "attribute": 3, + "type": 3, + "decimal": 0.01 + }, + { + "name": "tag2", + "address": "1!400002", + "attribute": 3, + "type": 9, + "precision": 3 + } + ] + }, + { + "group": "group_s", + "interval": 3000, + "tags": [ + { + "name": "tag1", + "address": "1!400001", + "attribute": 3, + "type": 9, + "precision": 3 + }, + { + "name": "tag1", + "address": "1!400002", + "attribute": 3, + "type": 9, + "precision": 3 + } + ] + } + ] + ) + + assert 409 == response.status_code + assert NEU_ERR_TAG_NAME_CONFLICT == response.json()['error'] \ No newline at end of file