#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY #include #include #include #include #include #include namespace test_enum_namespace { namespace first { enum class IdenticallyNamed { VALUE0, VALUE1, VALUE2 }; } namespace second { enum class IdenticallyNamed { VALUE3, VALUE4, VALUE5 }; } struct MultiStruct { sqlgen::PrimaryKey id; first::IdenticallyNamed enum_one; second::IdenticallyNamed enum_two; }; TEST(postgres, test_enum_namespace) { using namespace sqlgen; using namespace sqlgen::literals; auto objects = std::vector({ MultiStruct{.enum_one = first::IdenticallyNamed::VALUE0, .enum_two = second::IdenticallyNamed::VALUE3}, MultiStruct{.enum_one = first::IdenticallyNamed::VALUE1, .enum_two = second::IdenticallyNamed::VALUE4}, MultiStruct{.enum_one = first::IdenticallyNamed::VALUE2, .enum_two = second::IdenticallyNamed::VALUE5}, }); const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", .password = "password", .host = "localhost", .dbname = "postgres"}; const auto conn = postgres::connect(credentials); conn.and_then(drop | if_exists); write(conn, objects); const auto read_objects = sqlgen::read>(conn).value(); std::vector actual_ids; for (const auto& obj : read_objects) { if (obj.enum_one == first::IdenticallyNamed::VALUE0) { EXPECT_EQ(obj.enum_two, second::IdenticallyNamed::VALUE3); } else if (obj.enum_one == first::IdenticallyNamed::VALUE1) { EXPECT_EQ(obj.enum_two, second::IdenticallyNamed::VALUE4); } else if (obj.enum_one == first::IdenticallyNamed::VALUE2) { EXPECT_EQ(obj.enum_two, second::IdenticallyNamed::VALUE5); } else { FAIL() << "Unexpected enum value"; } } } } // namespace test_enum_namespace #endif