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