<reponame>sebhub/rtems-qual
# SPDX-License-Identifier: BSD-2-Clause
""" Unit tests for the rtemsqual.applconfig module. """

# Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import os
import shutil

from rtemsqual.applconfig import generate
from rtemsqual.items import ItemCache


def test_applconfig(tmpdir):
    item_cache_config = {}
    item_cache_config["cache-directory"] = "cache"
    spec_src = os.path.join(os.path.dirname(__file__), "spec-applconfig")
    spec_dst = os.path.join(tmpdir, "spec")
    shutil.copytree(spec_src, spec_dst)
    item_cache_config["paths"] = [os.path.normpath(spec_dst)]
    ic = ItemCache(item_cache_config)

    applconfig_config = {}
    g_rst = os.path.join(tmpdir, "g.rst")
    applconfig_config["groups"] = [{"uid": "g", "target": g_rst}]
    generate(applconfig_config, ic)

    with open(g_rst, "r") as src:
        content = (
            ".. SPDX-License-Identifier: CC-BY-SA-4.0\n"
            "\n"
            ".. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)\n"
            "\n"
            "group name\n"
            "==========\n"
            "\n"
            "description\n"
            "\n"
            ".. index:: a\n"
            ".. index:: index a\n"
            "\n"
            ".. _a:\n"
            "\n"
            "a\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``a``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is a boolean feature define.\n"
            "\n"
            "DEFAULT CONFIGURATION:\n"
            "    default a\n"
            "\n"
            "DESCRIPTION:\n"
            "    description a\n"
            "\n"
            "NOTES:\n"
            "    notes a\n"
            "\n"
            ".. index:: b\n"
            "\n"
            ".. _b:\n"
            "\n"
            "b\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``b``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is a boolean feature define.\n"
            "\n"
            "DEFAULT CONFIGURATION:\n"
            "    If this configuration option is undefined, then the described feature is not\n"
            "    enabled.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description b\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: c\n"
            "\n"
            ".. _c:\n"
            "\n"
            "c\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``c``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 13.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall satisfy all of the following\n"
            "    constraints:\n"
            "\n"
            "    * It shall be greater than or equal to -1.\n"
            "\n"
            "    * It shall be less than or equal to 99.\n"
            "\n"
            "    * custom c 1\n"
            "\n"
            "    * custom c 2\n"
            "\n"
            "    * constraint d\n"
            "\n"
            "DESCRIPTION:\n"
            "    description c\n"
            "\n"
            "NOTES:\n"
            "    notes c\n"
            "\n"
            ".. index:: e\n"
            "\n"
            ".. _e:\n"
            "\n"
            "e\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``e``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 7.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be greater than or equal to -2.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description e\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: f\n"
            "\n"
            ".. _f:\n"
            "\n"
            "f\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``f``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be less than or equal to 2.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description f\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: h\n"
            "\n"
            ".. _h:\n"
            "\n"
            "h\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``h``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    custom h\n"
            "\n"
            "DESCRIPTION:\n"
            "    description h\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: i\n"
            "\n"
            ".. _i:\n"
            "\n"
            "i\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``i``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be\n"
            "    an element of {1, 2, 3}.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description i\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: j\n"
            "\n"
            ".. _j:\n"
            "\n"
            "j\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``j``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall satisfy all of the following\n"
            "    constraints:\n"
            "\n"
            "    * It shall be an element of [1, 2].\n"
            "\n"
            "    * constraint d\n"
            "\n"
            "DESCRIPTION:\n"
            "    description j\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: k\n"
            "\n"
            ".. _k:\n"
            "\n"
            "k\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``k``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall satisfy all of the following\n"
            "    constraints:\n"
            "\n"
            "    * custom k 1\n"
            "\n"
            "    * custom k 2\n"
            "\n"
            "DESCRIPTION:\n"
            "    description k\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: l\n"
            "\n"
            ".. _l:\n"
            "\n"
            "l\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``l``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an initializer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be greater than or equal to 0\n"
            "    and less than or equal to 2.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description l\n"
            "\n"
            "NOTES:\n"
            "    None.\n")
        assert content == src.read()

# SPDX-License-Identifier: BSD-2-Clause
""" Unit tests for the rtemsqual.applconfig module. """

# Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import os
import shutil

from rtemsqual.applconfig import generate
from rtemsqual.items import ItemCache


def test_applconfig(tmpdir):
    item_cache_config = {}
    item_cache_config["cache-directory"] = "cache"
    spec_src = os.path.join(os.path.dirname(__file__), "spec-applconfig")
    spec_dst = os.path.join(tmpdir, "spec")
    shutil.copytree(spec_src, spec_dst)
    item_cache_config["paths"] = [os.path.normpath(spec_dst)]
    ic = ItemCache(item_cache_config)

    applconfig_config = {}
    g_rst = os.path.join(tmpdir, "g.rst")
    applconfig_config["groups"] = [{"uid": "g", "target": g_rst}]
    generate(applconfig_config, ic)

    with open(g_rst, "r") as src:
        content = (
            ".. SPDX-License-Identifier: CC-BY-SA-4.0\n"
            "\n"
            ".. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)\n"
            "\n"
            "group name\n"
            "==========\n"
            "\n"
            "description\n"
            "\n"
            ".. index:: a\n"
            ".. index:: index a\n"
            "\n"
            ".. _a:\n"
            "\n"
            "a\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``a``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is a boolean feature define.\n"
            "\n"
            "DEFAULT CONFIGURATION:\n"
            "    default a\n"
            "\n"
            "DESCRIPTION:\n"
            "    description a\n"
            "\n"
            "NOTES:\n"
            "    notes a\n"
            "\n"
            ".. index:: b\n"
            "\n"
            ".. _b:\n"
            "\n"
            "b\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``b``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is a boolean feature define.\n"
            "\n"
            "DEFAULT CONFIGURATION:\n"
            "    If this configuration option is undefined, then the described feature is not\n"
            "    enabled.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description b\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: c\n"
            "\n"
            ".. _c:\n"
            "\n"
            "c\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``c``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 13.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall satisfy all of the following\n"
            "    constraints:\n"
            "\n"
            "    * It shall be greater than or equal to -1.\n"
            "\n"
            "    * It shall be less than or equal to 99.\n"
            "\n"
            "    * custom c 1\n"
            "\n"
            "    * custom c 2\n"
            "\n"
            "    * constraint d\n"
            "\n"
            "DESCRIPTION:\n"
            "    description c\n"
            "\n"
            "NOTES:\n"
            "    notes c\n"
            "\n"
            ".. index:: e\n"
            "\n"
            ".. _e:\n"
            "\n"
            "e\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``e``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 7.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be greater than or equal to -2.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description e\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: f\n"
            "\n"
            ".. _f:\n"
            "\n"
            "f\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``f``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be less than or equal to 2.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description f\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: h\n"
            "\n"
            ".. _h:\n"
            "\n"
            "h\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``h``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    custom h\n"
            "\n"
            "DESCRIPTION:\n"
            "    description h\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: i\n"
            "\n"
            ".. _i:\n"
            "\n"
            "i\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``i``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be\n"
            "    an element of {1, 2, 3}.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description i\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: j\n"
            "\n"
            ".. _j:\n"
            "\n"
            "j\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``j``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall satisfy all of the following\n"
            "    constraints:\n"
            "\n"
            "    * It shall be an element of [1, 2].\n"
            "\n"
            "    * constraint d\n"
            "\n"
            "DESCRIPTION:\n"
            "    description j\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: k\n"
            "\n"
            ".. _k:\n"
            "\n"
            "k\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``k``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an integer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall satisfy all of the following\n"
            "    constraints:\n"
            "\n"
            "    * custom k 1\n"
            "\n"
            "    * custom k 2\n"
            "\n"
            "DESCRIPTION:\n"
            "    description k\n"
            "\n"
            "NOTES:\n"
            "    None.\n"
            "\n"
            ".. index:: l\n"
            "\n"
            ".. _l:\n"
            "\n"
            "l\n"
            "-\n"
            "\n"
            "CONSTANT:\n"
            "    ``l``\n"
            "\n"
            "OPTION TYPE:\n"
            "    This configuration option is an initializer define.\n"
            "\n"
            "DEFAULT VALUE:\n"
            "    The default value is 1.\n"
            "\n"
            "VALUE CONSTRAINTS:\n"
            "    The value of this configuration option shall be greater than or equal to 0\n"
            "    and less than or equal to 2.\n"
            "\n"
            "DESCRIPTION:\n"
            "    description l\n"
            "\n"
            "NOTES:\n"
            "    None.\n")
        assert content == src.read()
# SPDX-License-Identifier: BSD-2-Clause Unit tests for the rtemsqual.applconfig module. # Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright #    notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright #    notice, this list of conditions and the following disclaimer in the #    documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE.