Skip to content

Commit c4d6453

Browse files
committed
test(extract): an anonymous C typedef aggregate is one definition
Regression test for the merge with DeusData#2458: with its extract_class_def case restored, typedef struct { int count; } Tally; yields two Class defs named Tally (count_defs_named == 2, RED at test_extraction.c:1129); with the case removed it is one Class, one count field, one Shade enum, and no variants list (extraction 432 passed). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent d64f7e5 commit c4d6453

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎tests/test_extraction.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,29 @@ TEST(extract_c_anonymous_typedef_aggregate_is_named_by_its_typedef) {
11161116
PASS();
11171117
}
11181118

1119+
/* The anonymous aggregate of a typedef is ONE definition. extract_c_typedef names
1120+
* it from the type_definition; a second naming from the anonymous specifier gave
1121+
* Tally two Class defs under one QN, every member twice, and a variants list. */
1122+
TEST(extract_c_anonymous_typedef_aggregate_is_one_def) {
1123+
CBMFileResult *r = extract("typedef struct {\n"
1124+
" int count;\n"
1125+
"} Tally;\n"
1126+
"typedef enum { SHADE_RED, SHADE_GREEN } Shade;\n",
1127+
CBM_LANG_C, "t", "tally.h");
1128+
ASSERT_NOT_NULL(r);
1129+
ASSERT_EQ(count_defs_named(r, "Class", "Tally"), 1);
1130+
ASSERT_EQ(count_defs_named(r, "Field", "count"), 1);
1131+
ASSERT_EQ(count_defs_named(r, "Enum", "Shade"), 1);
1132+
for (int i = 0; i < r->defs.count; i++) {
1133+
const CBMDefinition *d = &r->defs.items[i];
1134+
if (d->name && strcmp(d->name, "Tally") == 0) {
1135+
ASSERT_NULL(d->variants);
1136+
}
1137+
}
1138+
cbm_free_result(r);
1139+
PASS();
1140+
}
1141+
11191142
/* A pointer-to-function member (`void (*open)(int);`, the shape of every
11201143
* kernel ops table) is a field of its struct. It shares the
11211144
* field_declaration + function_declarator shape with a C++ member FUNCTION
@@ -10405,6 +10428,7 @@ SUITE(extraction) {
1040510428
RUN_TEST(c_function_return_type_plain_unchanged);
1040610429
RUN_TEST(c_struct);
1040710430
RUN_TEST(extract_c_anonymous_typedef_aggregate_is_named_by_its_typedef);
10431+
RUN_TEST(extract_c_anonymous_typedef_aggregate_is_one_def);
1040810432
RUN_TEST(extract_c_function_pointer_member_is_a_field);
1040910433
RUN_TEST(extract_c_member_declarators_name_and_type);
1041010434
RUN_TEST(cpp_class);

0 commit comments

Comments
 (0)