Exemplo n.º 1
0
	def test_settings_defaults(self):
		settings = Settings()
		assert settings.contains("analysis.linearSweep.autorun"), "test_settings_defaults failed"
		assert settings.contains("analysis.unicode.blocks"), "test_settings_defaults failed"
		assert settings.contains("downloadClient.providerName"), "test_settings_defaults failed"
		assert settings.get_bool_with_scope("analysis.linearSweep.autorun", scope=SettingsScope.SettingsDefaultScope)[0], "test_settings_defaults failed"
		assert settings.get_bool_with_scope("analysis.linearSweep.autorun", scope=SettingsScope.SettingsDefaultScope)[1] == SettingsScope.SettingsDefaultScope, "test_settings_defaults failed"
Exemplo n.º 2
0
 def test_settings_registration(self):
     settings = Settings("test")
     assert not settings.contains(
         "testGroup.testSetting"), "test_settings_registration failed"
     assert settings.register_group(
         "testGroup", "Title"), "test_settings_registration failed"
     assert settings.register_setting(
         "testGroup.testSetting",
         '{"description" : "Test description.", "title" : "Test Title", "default" : true, "type" : "boolean", "id" : "testSetting"}'
     ), "test_settings_registration failed"
     assert settings.contains(
         "testGroup.testSetting"), "test_settings_registration failed"
Exemplo n.º 3
0
    def test_settings_usage(self):
        settings = Settings("test")
        assert not settings.contains(
            "testGroup.testSetting"), "test_settings_types failed"
        assert settings.register_group("testGroup",
                                       "Title"), "test_settings_types failed"
        assert not settings.register_setting(
            "testGroup.boolSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : 500, "type" : "boolean", "id" : "boolSetting"}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.boolSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : true, "type" : "boolean", "id" : "boolSetting"}'
        ), "test_settings_types failed"
        assert not settings.register_setting(
            "testGroup.doubleSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : true, "type" : "number", "id" : "doubleSetting"}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.doubleSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : 500, "type" : "number", "id" : "doubleSetting"}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.integerSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : 500, "type" : "number", "id" : "integerSetting"}'
        ), "test_settings_types failed"
        assert not settings.register_setting(
            "testGroup.stringSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : 500, "type" : "string", "id" : "stringSetting"}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.stringSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : "value", "type" : "string", "id" : "stringSetting"}'
        ), "test_settings_types failed"
        assert not settings.register_setting(
            "testGroup.stringListSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : true, "type" : "array", "id" : "stringListSetting"}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.stringListSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : ["value1", "value2"], "type" : "array", "id" : "stringListSetting"}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.ignoreResourceBoolSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : true, "type" : "boolean", "id" : "boolSetting", "ignore" : ["SettingsResourceScope"]}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.ignoreUserBoolSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : true, "type" : "boolean", "id" : "boolSetting", "ignore" : ["SettingsUserScope"]}'
        ), "test_settings_types failed"
        assert settings.register_setting(
            "testGroup.readOnlyBoolSetting",
            '{"description" : "Test description.", "title" : "Test Title", "default" : true, "type" : "boolean", "id" : "boolSetting", "ignore" : ["SettingsResourceScope", "SettingsUserScope"]}'
        ), "test_settings_types failed"

        assert settings.contains(
            "testGroup.boolSetting"), "test_settings_types failed"
        assert settings.contains(
            "testGroup.doubleSetting"), "test_settings_types failed"
        assert settings.contains(
            "testGroup.integerSetting"), "test_settings_types failed"
        assert settings.contains(
            "testGroup.stringSetting"), "test_settings_types failed"
        assert settings.contains(
            "testGroup.stringListSetting"), "test_settings_types failed"

        assert settings.get_bool(
            "testGroup.boolSetting") == True, "test_settings_types failed"
        assert settings.get_double(
            "testGroup.doubleSetting") == 500, "test_settings_types failed"
        assert settings.get_integer(
            "testGroup.integerSetting") == 500, "test_settings_types failed"
        assert settings.get_string(
            "testGroup.stringSetting") == "value", "test_settings_types failed"
        assert settings.get_string_list("testGroup.stringListSetting") == [
            "value1", "value2"
        ], "test_settings_types failed"

        assert settings.set_bool("testGroup.boolSetting",
                                 False), "test_settings_types failed"
        assert settings.set_double("testGroup.doubleSetting",
                                   700), "test_settings_types failed"
        assert settings.set_integer("testGroup.integerSetting",
                                    700), "test_settings_types failed"
        assert settings.set_string("testGroup.stringSetting",
                                   "value_user"), "test_settings_types failed"
        assert settings.set_string_list(
            "testGroup.stringListSetting",
            ["value3", "value4"]), "test_settings_types failed"

        assert settings.get_bool(
            "testGroup.boolSetting") == False, "test_settings_types failed"
        assert settings.get_double(
            "testGroup.doubleSetting") == 700, "test_settings_types failed"
        assert settings.get_integer(
            "testGroup.integerSetting") == 700, "test_settings_types failed"
        assert settings.get_string(
            "testGroup.stringSetting"
        ) == "value_user", "test_settings_types failed"
        assert settings.get_string_list("testGroup.stringListSetting") == [
            "value3", "value4"
        ], "test_settings_types failed"

        assert settings.get_bool_with_scope(
            "testGroup.boolSetting", scope=SettingsScope.SettingsDefaultScope
        )[0] == True, "test_settings_types failed"
        assert settings.get_double_with_scope(
            "testGroup.doubleSetting",
            scope=SettingsScope.SettingsDefaultScope
        )[0] == 500, "test_settings_types failed"
        assert settings.get_integer_with_scope(
            "testGroup.integerSetting",
            scope=SettingsScope.SettingsDefaultScope
        )[0] == 500, "test_settings_types failed"
        assert settings.get_string_with_scope(
            "testGroup.stringSetting",
            scope=SettingsScope.SettingsDefaultScope
        )[0] == "value", "test_settings_types failed"
        assert settings.get_string_list_with_scope(
            "testGroup.stringListSetting",
            scope=SettingsScope.SettingsDefaultScope)[0] == [
                "value1", "value2"
            ], "test_settings_types failed"

        assert settings.get_bool_with_scope(
            "testGroup.boolSetting", scope=SettingsScope.SettingsUserScope
        )[0] == False, "test_settings_types failed"
        assert settings.get_double_with_scope(
            "testGroup.doubleSetting", scope=SettingsScope.SettingsUserScope
        )[0] == 700, "test_settings_types failed"
        assert settings.get_integer_with_scope(
            "testGroup.integerSetting", scope=SettingsScope.SettingsUserScope
        )[0] == 700, "test_settings_types failed"
        assert settings.get_string_with_scope(
            "testGroup.stringSetting", scope=SettingsScope.SettingsUserScope
        )[0] == "value_user", "test_settings_types failed"
        assert settings.get_string_list_with_scope(
            "testGroup.stringListSetting",
            scope=SettingsScope.SettingsUserScope)[0] == [
                "value3", "value4"
            ], "test_settings_types failed"

        raw_view = BinaryView.new(b'0x55')
        assert not settings.set_bool("testGroup.ignoreResourceBoolSetting",
                                     False,
                                     scope=SettingsScope.SettingsDefaultScope
                                     ), "test_settings_types failed"
        assert not settings.set_bool("testGroup.ignoreResourceBoolSetting",
                                     False,
                                     scope=SettingsScope.SettingsResourceScope
                                     ), "test_settings_types failed"
        assert not settings.set_bool("testGroup.ignoreResourceBoolSetting",
                                     False,
                                     raw_view,
                                     scope=SettingsScope.SettingsResourceScope
                                     ), "test_settings_types failed"
        assert settings.set_bool("testGroup.ignoreResourceBoolSetting",
                                 False,
                                 scope=SettingsScope.SettingsUserScope
                                 ), "test_settings_types failed"
        assert not settings.set_bool("testGroup.ignoreUserBoolSetting",
                                     False), "test_settings_types failed"
        assert settings.set_bool("testGroup.ignoreUserBoolSetting", False,
                                 raw_view), "test_settings_types failed"
        assert settings.set_bool("testGroup.ignoreUserBoolSetting",
                                 False,
                                 raw_view,
                                 scope=SettingsScope.SettingsResourceScope
                                 ), "test_settings_types failed"
        assert not settings.set_bool("testGroup.readOnlyBoolSetting",
                                     False), "test_settings_types failed"
        assert not settings.set_bool("testGroup.readOnlyBoolSetting",
                                     False,
                                     scope=SettingsScope.SettingsResourceScope
                                     ), "test_settings_types failed"
        assert not settings.set_bool("testGroup.readOnlyBoolSetting",
                                     False,
                                     scope=SettingsScope.SettingsUserScope
                                     ), "test_settings_types failed"

        s2 = Settings("test2")
        assert s2.serialize_schema() == "", "test_settings_types failed"
        test_schema = settings.serialize_schema()
        assert test_schema != "", "test_settings_types failed"
        assert s2.deserialize_schema(test_schema), "test_settings_types failed"

        assert s2.get_bool(
            "testGroup.boolSetting") == True, "test_settings_types failed"
        assert s2.get_double(
            "testGroup.doubleSetting") == 500, "test_settings_types failed"
        assert s2.get_integer(
            "testGroup.integerSetting") == 500, "test_settings_types failed"
        assert s2.get_string(
            "testGroup.stringSetting") == "value", "test_settings_types failed"
        assert s2.get_string_list("testGroup.stringListSetting") == [
            "value1", "value2"
        ], "test_settings_types failed"

        assert s2.deserialize_settings(
            settings.serialize_settings(scope=SettingsScope.SettingsUserScope),
            raw_view,
            SettingsScope.SettingsResourceScope), "test_settings_types failed"
        assert s2.get_bool("testGroup.boolSetting",
                           raw_view) == False, "test_settings_types failed"
        assert s2.get_double("testGroup.doubleSetting",
                             raw_view) == 700, "test_settings_types failed"
        assert s2.get_integer("testGroup.integerSetting",
                              raw_view) == 700, "test_settings_types failed"
        assert s2.get_string(
            "testGroup.stringSetting",
            raw_view) == "value_user", "test_settings_types failed"
        assert s2.get_string_list("testGroup.stringListSetting",
                                  raw_view) == ["value3", "value4"
                                                ], "test_settings_types failed"

        assert s2.reset_all(), "test_settings_types failed"
        assert s2.get_bool(
            "testGroup.boolSetting") == True, "test_settings_types failed"
        assert s2.get_double(
            "testGroup.doubleSetting") == 500, "test_settings_types failed"
        assert s2.get_integer(
            "testGroup.integerSetting") == 500, "test_settings_types failed"
        assert s2.get_string(
            "testGroup.stringSetting") == "value", "test_settings_types failed"
        assert s2.get_string_list("testGroup.stringListSetting") == [
            "value1", "value2"
        ], "test_settings_types failed"

        s3 = Settings("test3")
        assert s3.deserialize_schema(test_schema,
                                     SettingsScope.SettingsResourceScope)
        assert not s3.contains("testGroup.ignoreResourceBoolSetting"
                               ), "test_settings_types failed"
        assert s3.contains(
            "testGroup.ignoreUserBoolSetting"), "test_settings_types failed"
        assert not s3.contains(
            "testGroup.readOnlyBoolSetting"), "test_settings_types failed"

        assert s3.deserialize_schema(test_schema,
                                     SettingsScope.SettingsUserScope, False)
        assert s3.contains("testGroup.ignoreResourceBoolSetting"
                           ), "test_settings_types failed"
        assert not s3.contains(
            "testGroup.ignoreUserBoolSetting"), "test_settings_types failed"
        assert not s3.contains(
            "testGroup.readOnlyBoolSetting"), "test_settings_types failed"

        assert s3.deserialize_schema(test_schema,
                                     SettingsScope.SettingsUserScope, False)
        assert s3.deserialize_schema(s3.serialize_schema(),
                                     SettingsScope.SettingsResourceScope,
                                     False)
        assert not s3.contains("testGroup.ignoreResourceBoolSetting"
                               ), "test_settings_types failed"
        assert not s3.contains(
            "testGroup.ignoreUserBoolSetting"), "test_settings_types failed"
        assert not s3.contains(
            "testGroup.readOnlyBoolSetting"), "test_settings_types failed"