source: rtems-central/rtemsspec/tests/test_interfacedoc.py @ e49c759

Last change on this file since e49c759 was e49c759, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 15, 2020 at 8:04:25 AM

Rename "rtemsqual" in "rtemsspec"

  • Property mode set to 100644
File size: 6.2 KB
Line 
1# SPDX-License-Identifier: BSD-2-Clause
2""" Unit tests for the rtemsspec.interfacedoc module. """
3
4# Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26
27import os
28import pytest
29
30from rtemsspec.interfacedoc import generate
31from rtemsspec.items import EmptyItemCache, ItemCache
32from rtemsspec.tests.util import create_item_cache_config_and_copy_spec
33
34
35def test_interfacedoc(tmpdir):
36    doc_config = {}
37    doc_config["group"] = "/gb"
38    introduction_rst = os.path.join(tmpdir, "introduction.rst")
39    doc_config["introduction-target"] = introduction_rst
40    directives_rst = os.path.join(tmpdir, "directives.rst")
41    doc_config["directives-target"] = directives_rst
42
43    doc_config_2 = {}
44    doc_config_2["group"] = "/ga"
45    introduction_2_rst = os.path.join(tmpdir, "introduction-2.rst")
46    doc_config_2["introduction-target"] = introduction_2_rst
47    directives_2_rst = os.path.join(tmpdir, "directives-2.rst")
48    doc_config_2["directives-target"] = directives_2_rst
49
50    item_cache_config = create_item_cache_config_and_copy_spec(
51        tmpdir, "spec-interface", with_spec_types=True)
52    generate([doc_config, doc_config_2], ItemCache(item_cache_config))
53
54    with open(introduction_rst, "r") as src:
55        content = """.. SPDX-License-Identifier: CC-BY-SA-4.0
56
57.. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
58
59.. _GroupBIntroduction:
60
61Introduction
62============
63
64The directives provided by the Group B are:
65
66* :ref:`VeryLongFunction() <InterfaceVeryLongFunction>` - Very long function
67  brief description.
68
69* :ref:`VeryLongTypeFunction() <InterfaceVeryLongTypeFunction>` - Function
70  brief description with very long return type.
71
72* :ref:`VoidFunction() <InterfaceVoidFunction>`
73"""
74        assert content == src.read()
75
76    with open(directives_rst, "r") as src:
77        content = """.. SPDX-License-Identifier: CC-BY-SA-4.0
78
79.. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
80
81.. _GroupBDirectives:
82
83Directives
84==========
85
86.. _InterfaceVeryLongFunction:
87
88VeryLongFunction()
89------------------
90
91Very long function brief description.
92
93CALLING SEQUENCE:
94    .. code-block:: c
95
96        int VeryLongFunction(
97          int                  VeryLongParam0,
98          const struct Struct *VeryLongParam1,
99          struct Struct    *( *VeryLongParam2 )( void ),
100          struct Struct       *VeryLongParam3
101        );
102
103DIRECTIVE PARAMETERS:
104    VeryLongParam0
105        This parameter is very long parameter 0 with some super important and
106        extra very long description which makes a lot of sense.
107
108    VeryLongParam1
109        This parameter is very long parameter 1.
110
111    VeryLongParam2
112        This parameter is very long parameter 2.
113
114    VeryLongParam3
115        This parameter is very long parameter 3.
116
117DIRECTIVE RETURN VALUES:
118    1
119        is returned, in case A.
120
121    2
122        is returned, in case B.
123
124    Sometimes some value.  See :ref:`Function() <InterfaceFunction>`.
125
126DESCRIPTION:
127    VeryLongFunction description.
128
129NOTES:
130    VeryLongFunction notes.
131
132.. _InterfaceVeryLongTypeFunction:
133
134VeryLongTypeFunction()
135----------------------
136
137Function brief description with very long return type.
138
139CALLING SEQUENCE:
140    .. code-block:: c
141
142        #if 1
143          NotSoVeryLongType VeryLongTypeFunction( void );
144        #else
145          VeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongType
146          VeryLongTypeFunction( void );
147        #endif
148
149DIRECTIVE RETURN VALUES:
150    This function returns an object with a very long type.
151
152.. _InterfaceVoidFunction:
153
154VoidFunction()
155--------------
156
157CALLING SEQUENCE:
158    .. code-block:: c
159
160        #if 1
161          void VoidFunction( void );
162        #endif
163"""
164        assert content == src.read()
165
166    with open(introduction_2_rst, "r") as src:
167        content = """.. SPDX-License-Identifier: CC-BY-SA-4.0
168
169.. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
170
171.. _GroupAIntroduction:
172
173Introduction
174============
175
176Group A brief description.
177
178Group A description. The directives provided by the Group A are:
179
180* :ref:`Function() <InterfaceFunction>` - Function brief description.
181"""
182        assert content == src.read()
183
184    with open(directives_2_rst, "r") as src:
185        content = """.. SPDX-License-Identifier: CC-BY-SA-4.0
186
187.. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
188
189.. _GroupADirectives:
190
191Directives
192==========
193
194.. _InterfaceFunction:
195
196Function()
197----------
198
199Function brief description.
200
201CALLING SEQUENCE:
202    .. code-block:: c
203
204        void Function( int Param0, const int *Param1, int *Param2, int *Param3 );
205
206DIRECTIVE PARAMETERS:
207    Param0
208        This parameter is parameter 0.
209
210    Param1
211        This parameter is parameter 1.
212
213    Param2
214        This parameter is parameter 2.
215
216    Param3
217        This parameter is parameter 3.
218
219DESCRIPTION:
220    Function description.  References to :ref:`VeryLongFunction()
221    <InterfaceVeryLongFunction>`, Integer, Enum, DEFINE, VERY_LONG_MACRO,
222    Variable, ENUMERATOR_0, Struct, :ref:`a`, and interface.
223"""
224        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.