#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Config; using namespace Config::Lua; namespace { class CUnsupportedValue : public Values::IValue { public: CUnsupportedValue() : Values::IValue(0) { m_name = "unsupported"; m_description = "unsupported"; } const std::type_info* underlying() const override { return &typeid(void); } void commence() override { ; } }; } TEST(ConfigLuaUtils, fromGenericValueMapsSupportedTypes) { { auto out = fromGenericValue(makeShared("a", "", 1)); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", 1.F)); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", true)); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", "x")); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", 0xFF000000)); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", VEC2{1, 2})); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", 5)); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", 500)); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } { auto out = fromGenericValue(makeShared("a", "", CHyprColor(0xFF112233))); ASSERT_NE(out.get(), nullptr); EXPECT_NE(dynamic_cast(out.get()), nullptr); } } TEST(ConfigLuaUtils, fromGenericValueReturnsNullForUnsupportedType) { auto out = fromGenericValue(makeShared()); EXPECT_EQ(out.get(), nullptr); } TEST(ConfigLuaUtils, fromGenericValueCopiesRefreshBits) { const auto REFRESH = Config::Supplementary::REFRESH_LAYOUTS | Config::Supplementary::REFRESH_WINDOW_STATES; auto out = fromGenericValue(makeShared("a", "", 1, Values::SIntValueOptions{.refresh = REFRESH})); ASSERT_NE(out.get(), nullptr); EXPECT_EQ(out->refreshBits(), REFRESH); } TEST(ConfigLuaUtils, typedAccessorsReadStoredValues) { CLuaConfigBool boolFalse(false); CLuaConfigBool boolTrue(true); CLuaConfigInt intValue(2); CLuaConfigFloat floatValue(1.25F); CLuaConfigVec2 vecValue({3, 4}); CLuaConfigString stringValue("value"); EXPECT_EQ(boolFalse.asInt(), 0); EXPECT_EQ(boolTrue.asInt(), 1); EXPECT_EQ(intValue.asInt(), 2); EXPECT_FLOAT_EQ(floatValue.asFloat(), 1.25F); const auto vec = vecValue.asVec2(); EXPECT_EQ(vec.x, 3); EXPECT_EQ(vec.y, 4); EXPECT_EQ(stringValue.asString(), "value"); }