EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {"bacon", "lettuce", "tomato", "mayonnaise"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_FALSE(RD->hasAttr<RandomizeLayoutAttr>());
EXPECT_FALSE(RD->isRandomized());
}
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {"bacon", "lettuce", "tomato", "mayonnaise"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->hasAttr<NoRandomizeLayoutAttr>());
EXPECT_FALSE(RD->isRandomized());
}
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {"lettuce", "bacon", "mayonnaise", "tomato"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->hasAttr<RandomizeLayoutAttr>());
EXPECT_TRUE(RD->isRandomized());
}
long long tomato;
float mayonnaise;
} __attribute__((no_randomize_layout));
- )c", true);
+ )c",
+ true);
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
long long tomato;
float mayonnaise;
} __attribute__((randomize_layout)) __attribute__((no_randomize_layout));
- )c", true);
+ )c",
+ true);
EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
long long tomato;
float mayonnaise;
} __attribute__((no_randomize_layout)) __attribute__((randomize_layout));
- )c", true);
+ )c",
+ true);
EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {
- "a", "b", "c", "x", "y", "z" // x, y, z needs to be a subsequnce.
- };
+ const field_names Actual = getFieldNamesFromRecord(RD);
+ const field_names Subseq = {"x", "y", "z"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->isRandomized());
+ EXPECT_TRUE(isSubsequence(Actual, Subseq));
}
-// FIXME: Enable when fix for flexible arrays is submitted.
-TEST(RANDSTRUCT_TEST, DISABLED_CheckVariableLengthArrayMemberRemainsAtEndOfStructure) {
+TEST(RANDSTRUCT_TEST, CheckVariableLengthArrayMemberRemainsAtEndOfStructure) {
std::unique_ptr<ASTUnit> AST = makeAST(R"c(
struct test {
int a;
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {"c", "a", "b", "name"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->isRandomized());
}
long long b;
int c[];
} __attribute__((packed, randomize_layout));
- )c", false, field_names({"test_struct", "another_struct", "last_struct"}));
+ )c",
+ false,
+ std::vector<std::string>(
+ {"test_struct", "another_struct", "last_struct"}));
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
getRecordDeclFromAST(AST->getASTContext(), "test_struct");
const ASTRecordLayout *Layout =
&AST->getASTContext().getASTRecordLayout(RD);
- const field_names Expected = {"b", "a", "c", "d"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->isRandomized());
EXPECT_EQ(19, Layout->getSize().getQuantity());
}
getRecordDeclFromAST(AST->getASTContext(), "another_struct");
const ASTRecordLayout *Layout =
&AST->getASTContext().getASTRecordLayout(RD);
- const field_names Expected = {"c", "b", "a"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->isRandomized());
EXPECT_EQ(10, Layout->getSize().getQuantity());
}
getRecordDeclFromAST(AST->getASTContext(), "last_struct");
const ASTRecordLayout *Layout =
&AST->getASTContext().getASTRecordLayout(RD);
- const field_names Expected = {"a", "c", "b"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->isRandomized());
EXPECT_EQ(9, Layout->getSize().getQuantity());
}
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {"a", "b", ""};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->isRandomized());
}
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
- const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {"a", "b", "c", "d", "e", "f"};
+ const RecordDecl *RD =
+ getRecordDeclFromAST(AST->getASTContext(), "test");
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_FALSE(RD->isRandomized());
}
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
const RecordDecl *RD = getRecordDeclFromAST(AST->getASTContext(), "test");
- const field_names Expected = {"", "l", "", "r", "s", "a", "f"};
- EXPECT_EQ(Expected, getFieldNamesFromRecord(RD));
EXPECT_TRUE(RD->isRandomized());
bool AnonStructTested = false;