diff --git a/test/gtest/smith_for_in_loop_test.cpp b/test/gtest/smith_for_in_loop_test.cpp new file mode 100644 index 00000000000..918129c4663 --- /dev/null +++ b/test/gtest/smith_for_in_loop_test.cpp @@ -0,0 +1,69 @@ +#include "gtest/gtest.h" +#include "backends/p4tools/modules/smith/smith.h" +#include "backends/p4tools/modules/smith/common/declarations.h" +#include "backends/p4tools/modules/smith/common/expressions.h" +#include "backends/p4tools/modules/smith/common/generator.h" +#include "backends/p4tools/modules/smith/common/parser.h" +#include "backends/p4tools/modules/smith/common/probabilities.h" +#include "backends/p4tools/modules/smith/common/scope.h" +#include "backends/p4tools/modules/smith/common/statements.h" +#include "backends/p4tools/modules/smith/common/table.h" +#include "backends/p4tools/modules/smith/core/target.h" +#include "ir/ir.h" +#include "ir/ir-generated.h" + +namespace Test { + +class P4SmithForInLoopTest : public ::testing::Test { +protected: + P4Tools::P4Smith::StatementGenerator* generator; + + // TODO(zzmic): Figure out how to properly initialize and clean up the test object. + P4SmithForInLoopTest() {} + ~P4SmithForInLoopTest() override {} +}; + +/// @brief Test the generation of a for-in-loop statement. +TEST_F(P4SmithForInLoopTest, ForLoopGeneration) { + auto forInLoopStmt = generator->genForInLoopStatement(false); + ASSERT_NE(forInLoopStmt, nullptr); + EXPECT_TRUE(forInLoopStmt->is()); +} + +/// @brief Test the for-in-loop's declaration variable. +TEST_F(P4SmithForInLoopTest, CheckForLoopDeclarationVariable) { + auto forInLoopStmt = generator->genForInLoopStatement(false); + ASSERT_NE(forInLoopStmt, nullptr); + EXPECT_TRUE(forInLoopStmt->is()); + + // TODO(zzmic): Figure out whether this "static_cast" is necessary. + auto forInStmt = forInLoopStmt->to(); + ASSERT_NE(forInStmt->decl, nullptr); + EXPECT_TRUE(forInStmt->decl->is()); +} + +/// @brief Test the for-in-loop's collection. +TEST_F(P4SmithForInLoopTest, CheckForLoopCollection) { + auto forInLoopStmt = generator->genForInLoopStatement(false); + ASSERT_NE(forInLoopStmt, nullptr); + EXPECT_TRUE(forInLoopStmt->is()); + + // TODO(zzmic): Figure out whether this "static_cast" is necessary. + auto forInStmt = forInLoopStmt->to(); + ASSERT_NE(forInStmt, nullptr); + EXPECT_TRUE(forInStmt->collection->is()); +} + +/// @brief Test the for-in-loop's body. +TEST_F(P4SmithForInLoopTest, CheckForLoopBody) { + auto forInLoopStmt = generator->genForInLoopStatement(false); + ASSERT_NE(forInLoopStmt, nullptr); + EXPECT_TRUE(forInLoopStmt->is()); + + // TODO(zzmic): Figure out whether this "static_cast" is necessary. + auto forInStmt = forInLoopStmt->to(); + ASSERT_NE(forInStmt->body, nullptr); + EXPECT_FALSE(forInStmt->body->is()); +} + +} // namespace Test \ No newline at end of file diff --git a/test/gtest/for_loop_test.cpp b/test/gtest/smith_for_loop_test.cpp similarity index 80% rename from test/gtest/for_loop_test.cpp rename to test/gtest/smith_for_loop_test.cpp index 33457f76868..1d20b80f78f 100644 --- a/test/gtest/for_loop_test.cpp +++ b/test/gtest/smith_for_loop_test.cpp @@ -18,32 +18,32 @@ class P4SmithForLoopTest : public ::testing::Test { protected: P4Tools::P4Smith::StatementGenerator* generator; - // TODO(zzmic): Figure out how to initialize and clean up the test object. + // TODO(zzmic): Figure out how to properly initialize and clean up the test object. P4SmithForLoopTest() {} ~P4SmithForLoopTest() override {} }; -/// @brief Test the generation of a for loop statement. +/// @brief Test the generation of a for-loop statement. TEST_F(P4SmithForLoopTest, ForLoopGeneration) { auto forLoopStmt = generator->genForLoopStatement(false); ASSERT_NE(forLoopStmt, nullptr); EXPECT_TRUE(forLoopStmt->is()); } -/// @brief Test whether the for loop contains an initialization. -TEST_F(P4SmithForLoopTest, ForLoopContainsInitialization) { +/// @brief Test the for-loop's initialization. +TEST_F(P4SmithForLoopTest, CheckForLoopContainsInitialization) { auto forLoopStmt = generator->genForLoopStatement(false); ASSERT_NE(forLoopStmt, nullptr); EXPECT_TRUE(forLoopStmt->is()); // TODO(zzmic): Figure out whether this "static_cast" is necessary. auto forStmt = forLoopStmt->to(); - ASSERT_NE(forStmt->init, nullptr); + ASSERT_NE(forStmt->init, nullptr); EXPECT_FALSE(forStmt->init.empty()); } -/// @brief Test whether the for loop contains a condition. -TEST_F(P4SmithForLoopTest, ForLoopContainsCondition) { +/// @brief Test the for-loop's condition. +TEST_F(P4SmithForLoopTest, CheckForLoopContainsCondition) { auto forLoopStmt = generator->genForLoopStatement(false); ASSERT_NE(forLoopStmt, nullptr); EXPECT_TRUE(forLoopStmt->is()); @@ -54,8 +54,8 @@ TEST_F(P4SmithForLoopTest, ForLoopContainsCondition) { EXPECT_TRUE(forStmt->condition->is()); } -/// @brief Test whether the for loop contains an update. -TEST_F(P4SmithForLoopTest, ForLoopContainsUpdate) { +/// @brief Test the for-loop's update. +TEST_F(P4SmithForLoopTest, CheckForLoopContainsUpdate) { auto forLoopStmt = generator->genForLoopStatement(false); ASSERT_NE(forLoopStmt, nullptr); EXPECT_TRUE(forLoopStmt->is()); @@ -66,8 +66,8 @@ TEST_F(P4SmithForLoopTest, ForLoopContainsUpdate) { EXPECT_FALSE(forStmt->updates.empty()); } -/// @brief Test whether the for loop contains a body. -TEST_F(P4SmithForLoopTest, ForLoopContainsBody) { +/// @brief Test the for-loop' body. +TEST_F(P4SmithForLoopTest, CheckForLoopContainsBody) { auto forLoopStmt = generator->genForLoopStatement(false); ASSERT_NE(forLoopStmt, nullptr); EXPECT_TRUE(forLoopStmt->is());