Skip to content

Commit 08c0aaf

Browse files
committed
Rule 5.4: add conditional test cases
1 parent 34abb42 commit 08c0aaf

File tree

8 files changed

+53
-0
lines changed

8 files changed

+53
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
| header3.h:7:1:7:24 | #define MULTIPLE_INCLUDE | Macro identifer MULTIPLE_INCLUDE is nondistinct in first 63 characters, compared to $@. | header4.h:1:1:1:24 | #define MULTIPLE_INCLUDE | MULTIPLE_INCLUDE |
2+
| header3.h:14:1:14:21 | #define NOT_PROTECTED | Macro identifer NOT_PROTECTED is nondistinct in first 63 characters, compared to $@. | header4.h:12:1:12:23 | #define NOT_PROTECTED 1 | NOT_PROTECTED |
13
| test.c:2:1:2:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB | Macro identifer iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyB is nondistinct in first 63 characters, compared to $@. | test.c:1:1:1:72 | #define iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA | iltiqzxgfqsgigwfuyntzghvzltueatcxqnqofnnvjyszmcsylyohvqaosjbqyyA |
24
| test.c:8:1:8:31 | #define FUNCTION_MACRO(X) X + 1 | Macro identifer FUNCTION_MACRO is nondistinct in first 63 characters, compared to $@. | test.c:7:1:7:57 | #define FUNCTION_MACRO(FUNCTION_MACRO) FUNCTION_MACRO + 1 | FUNCTION_MACRO |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifdef FOO
2+
#include "header1.h"
3+
#else
4+
#include "header2.h"
5+
#endif
6+
7+
#ifdef FOO
8+
#define A_MACRO 1 // COMPLIANT
9+
#else
10+
#define A_MACRO 2 // COMPLIANT
11+
#endif

c/misra/test/rules/RULE-5-4/header1.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define REPEATED 11 // COMPLIANT

c/misra/test/rules/RULE-5-4/header2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define REPEATED 1 // COMPLIANT

c/misra/test/rules/RULE-5-4/header3.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef HEADER3_H
2+
#define HEADER3_H
3+
4+
// We should ignore the header guards in this file
5+
6+
// This is defined unconditionally by both header3.h and header4.h
7+
#define MULTIPLE_INCLUDE // NON_COMPLIANT
8+
9+
// This is redefined in header3.h, but only if it isn't already defined
10+
#define PROTECTED // COMPLIANT
11+
12+
// This is redefined in header3.h, but is conditional on some other condition,
13+
// so this is redefined
14+
#define NOT_PROTECTED // NON_COMPLIANT
15+
16+
#endif

c/misra/test/rules/RULE-5-4/header4.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define MULTIPLE_INCLUDE // NON_COMPLIANT
2+
3+
// This case is triggered from root2.c
4+
// because PROTECTED isn't defined in
5+
// that case
6+
#ifndef PROTECTED
7+
#define PROTECTED // COMPLIANT - checked by guard
8+
#endif
9+
10+
// Always enabled, so conflicts in root1.c case
11+
#ifdef MULTIPLE_INCLUDE
12+
#define NOT_PROTECTED 1 // NON_COMPLIANT
13+
#endif

c/misra/test/rules/RULE-5-4/root1.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#define FOO 1
2+
#include "conditional.h"
3+
4+
// Both headers define MULTIPLE_INCLUDE
5+
#include "header3.h"
6+
#include "header4.h"

c/misra/test/rules/RULE-5-4/root2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "conditional.h"
2+
3+
#include "header4.h"

0 commit comments

Comments
 (0)