Add a test for a combination of LOGICAL_NOT and brackets.

Redmine: refs #2382.
Fix a bug that a query '!(X)' causes an error.

Redmine: fixes #2382.