1 | # SPDX-License-Identifier: BSD-2-Clause |
---|
2 | """ Unit tests for the rtemsqual.content 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 | |
---|
27 | from rtemsqual.content import CContent |
---|
28 | |
---|
29 | |
---|
30 | def test_add_have_config(): |
---|
31 | content = CContent() |
---|
32 | content.add_have_config() |
---|
33 | assert str(content) == """#ifdef HAVE_CONFIG_H |
---|
34 | #include "config.h" |
---|
35 | #endif |
---|
36 | """ |
---|
37 | content.add_have_config() |
---|
38 | assert str(content) == """#ifdef HAVE_CONFIG_H |
---|
39 | #include "config.h" |
---|
40 | #endif |
---|
41 | |
---|
42 | #ifdef HAVE_CONFIG_H |
---|
43 | #include "config.h" |
---|
44 | #endif |
---|
45 | """ |
---|
46 | |
---|
47 | |
---|
48 | def test_add_includes(): |
---|
49 | content = CContent() |
---|
50 | content.add_includes([]) |
---|
51 | assert str(content) == "" |
---|
52 | content = CContent() |
---|
53 | content.add_includes(["a", "a"]) |
---|
54 | assert str(content) == """#include <a> |
---|
55 | """ |
---|
56 | content.add_includes(["b"]) |
---|
57 | assert str(content) == """#include <a> |
---|
58 | |
---|
59 | #include <b> |
---|
60 | """ |
---|
61 | content = CContent() |
---|
62 | content.add_includes(["c", "b"], local=True) |
---|
63 | assert str(content) == """#include "b" |
---|
64 | #include "c" |
---|
65 | """ |
---|
66 | content = CContent() |
---|
67 | content.add_includes(["d/f", "d/e"]) |
---|
68 | assert str(content) == """#include <d/e> |
---|
69 | #include <d/f> |
---|
70 | """ |
---|
71 | content = CContent() |
---|
72 | content.add_includes(["h", "g/h"]) |
---|
73 | assert str(content) == """#include <h> |
---|
74 | #include <g/h> |
---|
75 | """ |
---|
76 | content = CContent() |
---|
77 | content.add_includes(["i/l/k", "i/j/k"]) |
---|
78 | assert str(content) == """#include <i/j/k> |
---|
79 | #include <i/l/k> |
---|
80 | """ |
---|
81 | |
---|
82 | |
---|
83 | def test_comment_block(): |
---|
84 | content = CContent() |
---|
85 | with content.comment_block(): |
---|
86 | assert not content.gap |
---|
87 | content.add(content.wrap("")) |
---|
88 | assert not content.gap |
---|
89 | assert str(content) == """/* |
---|
90 | """ |
---|
91 | content.add(content.wrap("a")) |
---|
92 | assert content.gap |
---|
93 | assert str(content) == """/* |
---|
94 | * a |
---|
95 | """ |
---|
96 | content.add(content.wrap("b")) |
---|
97 | assert content.gap |
---|
98 | assert str(content) == """/* |
---|
99 | * a |
---|
100 | * |
---|
101 | * b |
---|
102 | """ |
---|
103 | content.gap = False |
---|
104 | content.add(content.wrap("c")) |
---|
105 | assert content.gap |
---|
106 | assert str(content) == """/* |
---|
107 | * a |
---|
108 | * |
---|
109 | * b |
---|
110 | * c |
---|
111 | """ |
---|
112 | |
---|
113 | |
---|
114 | def test_add_brief_description(): |
---|
115 | content = CContent() |
---|
116 | content.add_brief_description("") |
---|
117 | assert str(content) == "" |
---|
118 | content.gap = True |
---|
119 | content.add_brief_description( |
---|
120 | "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT " |
---|
121 | "HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED " |
---|
122 | "WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES " |
---|
123 | "OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE " |
---|
124 | "DISCLAIMED.") |
---|
125 | assert str(content) == """ |
---|
126 | @brief THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
---|
127 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
---|
128 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
---|
129 | PARTICULAR PURPOSE ARE DISCLAIMED. |
---|
130 | """ |
---|