diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/core/test-core-config-file.cpp | 248 |
1 files changed, 176 insertions, 72 deletions
diff --git a/tests/unit/core/test-core-config-file.cpp b/tests/unit/core/test-core-config-file.cpp index b58498029..d55aeebb3 100644 --- a/tests/unit/core/test-core-config-file.cpp +++ b/tests/unit/core/test-core-config-file.cpp @@ -83,7 +83,7 @@ TEST_GROUP(CoreConfigFileWithNewOptions) /* auto-created as enum with WeeChat >= 4.1.0 */ ptr_option_int_str = config_file_new_option ( weechat_config_file, weechat_config_section_look, - "test_integer_values", "integer", "", "v1|v2|v3", 0, 0, "v1", NULL, 0, + "test_integer_values", "integer", "", "v1|v2|v3", 0, 0, "v2", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -101,7 +101,7 @@ TEST_GROUP(CoreConfigFileWithNewOptions) NULL, NULL, NULL); ptr_option_enum = config_file_new_option ( weechat_config_file, weechat_config_section_look, - "test_enum", "enum", "", "v1|v2|v3", 0, 0, "v1", NULL, 0, + "test_enum", "enum", "", "v1|v2|v3", 0, 0, "v2", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); @@ -121,7 +121,6 @@ TEST_GROUP(CoreConfigFileWithNewOptions) ptr_option_col = NULL; config_file_option_free (ptr_option_enum, 0); ptr_option_enum = NULL; - } }; @@ -627,15 +626,15 @@ TEST(CoreConfigFileWithNewOptions, OptionSetReset) LONGS_EQUAL(100, CONFIG_INTEGER(ptr_option_int)); /* integer with string values (enum with WeeChat >= 4.1.0) */ - LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_int_str)); + LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_set (ptr_option_int_str, "zzz", 1)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, - config_file_option_set (ptr_option_int_str, "v2", 1)); - LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_int_str)); + config_file_option_set (ptr_option_int_str, "v3", 1)); + LONGS_EQUAL(2, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_reset (ptr_option_int_str, 1)); - LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_int_str)); + LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_int_str)); /* string */ STRCMP_EQUAL("value", CONFIG_STRING(ptr_option_str)); @@ -698,15 +697,15 @@ TEST(CoreConfigFileWithNewOptions, OptionSetReset) LONGS_EQUAL(9, CONFIG_COLOR(ptr_option_col)); /* enum */ - LONGS_EQUAL(0, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_set (ptr_option_enum, "zzz", 1)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, - config_file_option_set (ptr_option_enum, "v2", 1)); - LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); + config_file_option_set (ptr_option_enum, "v3", 1)); + LONGS_EQUAL(2, CONFIG_ENUM(ptr_option_enum)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_reset (ptr_option_enum, 1)); - LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_enum)); + LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_enum)); } /* @@ -722,8 +721,8 @@ TEST(CoreConfigFileWithNewOptions, OptionToggle) const char *value_integer_ok[] = { "50", NULL }; const char *values_integer_ok[] = { "75", "92", NULL }; const char *values_integer_error[] = { "-500", "99999999", NULL }; - const char *value_integer_str_ok[] = { "v2", NULL }; - const char *values_integer_str_ok[] = { "v2", "v3", NULL }; + const char *value_integer_str_ok[] = { "v3", NULL }; + const char *values_integer_str_ok[] = { "v1", "v3", NULL }; const char *values_integer_str_error[] = { "xxx", "zzz", NULL }; const char *value_string_ok[] = { "+", NULL }; const char *values_string_ok[] = { "$", "*", NULL }; @@ -793,7 +792,7 @@ TEST(CoreConfigFileWithNewOptions, OptionToggle) LONGS_EQUAL(100, CONFIG_INTEGER(ptr_option_int)); /* integer with string values (enum with WeeChat >= 4.1.0) */ - LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_int_str)); + LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_toggle (ptr_option_int_str, values_integer_str_error, 2, 1)); @@ -803,18 +802,18 @@ TEST(CoreConfigFileWithNewOptions, OptionToggle) LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_toggle (ptr_option_int_str, value_integer_str_ok, 1, 1)); - LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_int_str)); + LONGS_EQUAL(2, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_toggle (ptr_option_int_str, values_integer_str_ok, 2, 1)); - LONGS_EQUAL(2, CONFIG_INTEGER(ptr_option_int_str)); + LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_toggle (ptr_option_int_str, values_integer_str_ok, 2, 1)); - LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_int_str)); + LONGS_EQUAL(2, CONFIG_INTEGER(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_reset (ptr_option_int_str, 1)); - LONGS_EQUAL(0, CONFIG_INTEGER(ptr_option_int_str)); + LONGS_EQUAL(1, CONFIG_INTEGER(ptr_option_int_str)); /* string */ STRCMP_EQUAL("value", CONFIG_STRING(ptr_option_str)); @@ -869,7 +868,7 @@ TEST(CoreConfigFileWithNewOptions, OptionToggle) LONGS_EQUAL(9, CONFIG_COLOR(ptr_option_col)); /* enum */ - LONGS_EQUAL(0, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_toggle (ptr_option_enum, values_integer_str_error, 2, 1)); @@ -879,18 +878,18 @@ TEST(CoreConfigFileWithNewOptions, OptionToggle) LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_toggle (ptr_option_enum, value_integer_str_ok, 1, 1)); - LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(2, CONFIG_ENUM(ptr_option_enum)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_toggle (ptr_option_enum, values_integer_str_ok, 2, 1)); - LONGS_EQUAL(2, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(0, CONFIG_ENUM(ptr_option_enum)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_toggle (ptr_option_enum, values_integer_str_ok, 2, 1)); - LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(2, CONFIG_ENUM(ptr_option_enum)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, config_file_option_reset (ptr_option_enum, 1)); - LONGS_EQUAL(0, CONFIG_ENUM(ptr_option_enum)); + LONGS_EQUAL(1, CONFIG_ENUM(ptr_option_enum)); } /* @@ -950,14 +949,14 @@ TEST(CoreConfigFileWithNewOptions, OptionSetDefault) LONGS_EQUAL(62, CONFIG_INTEGER_DEFAULT(ptr_option_int)); /* integer with string values (enum with WeeChat >= 4.1.0) */ - LONGS_EQUAL(0, CONFIG_INTEGER_DEFAULT(ptr_option_int_str)); + LONGS_EQUAL(1, CONFIG_INTEGER_DEFAULT(ptr_option_int_str)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE, config_file_option_set_default (ptr_option_int_str, NULL, 1)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_set_default (ptr_option_int_str, "zzz", 1)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, - config_file_option_set_default (ptr_option_int_str, "v2", 1)); - LONGS_EQUAL(1, CONFIG_INTEGER_DEFAULT(ptr_option_int_str)); + config_file_option_set_default (ptr_option_int_str, "v3", 1)); + LONGS_EQUAL(2, CONFIG_INTEGER_DEFAULT(ptr_option_int_str)); /* string */ STRCMP_EQUAL("value", CONFIG_STRING_DEFAULT(ptr_option_str)); @@ -1014,14 +1013,14 @@ TEST(CoreConfigFileWithNewOptions, OptionSetDefault) CONFIG_COLOR_DEFAULT(ptr_option_col)); /* enum */ - LONGS_EQUAL(0, CONFIG_ENUM_DEFAULT(ptr_option_enum)); + LONGS_EQUAL(1, CONFIG_ENUM_DEFAULT(ptr_option_enum)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE, config_file_option_set_default (ptr_option_enum, NULL, 1)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_ERROR, config_file_option_set_default (ptr_option_enum, "zzz", 1)); LONGS_EQUAL(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED, - config_file_option_set_default (ptr_option_enum, "v2", 1)); - LONGS_EQUAL(1, CONFIG_INTEGER_DEFAULT(ptr_option_enum)); + config_file_option_set_default (ptr_option_enum, "v3", 1)); + LONGS_EQUAL(2, CONFIG_INTEGER_DEFAULT(ptr_option_enum)); } /* @@ -1117,81 +1116,186 @@ TEST(CoreConfigFile, OptionSetWithString) /* * Tests functions: * config_file_option_boolean - */ - -TEST(CoreConfigFile, OptionBoolean) -{ - /* TODO: write tests */ -} - -/* - * Tests functions: * config_file_option_boolean_default */ -TEST(CoreConfigFile, OptionBooleanDefault) -{ - /* TODO: write tests */ +TEST(CoreConfigFileWithNewOptions, OptionBoolean) +{ + LONGS_EQUAL(0, config_file_option_boolean (NULL)); + LONGS_EQUAL(0, config_file_option_boolean_default (NULL)); + + LONGS_EQUAL(0, config_file_option_boolean (ptr_option_bool)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_bool)); + + config_file_option_set (ptr_option_bool, "on", 1); + LONGS_EQUAL(1, config_file_option_boolean (ptr_option_bool)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_bool)); + config_file_option_reset (ptr_option_bool, 1); + LONGS_EQUAL(0, config_file_option_boolean (ptr_option_bool)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_bool)); + + LONGS_EQUAL(0, config_file_option_boolean (ptr_option_int)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_int)); + LONGS_EQUAL(0, config_file_option_boolean (ptr_option_int_str)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_int_str)); + LONGS_EQUAL(0, config_file_option_boolean (ptr_option_str)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_str)); + LONGS_EQUAL(0, config_file_option_boolean (ptr_option_col)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_col)); + LONGS_EQUAL(0, config_file_option_boolean (ptr_option_enum)); + LONGS_EQUAL(0, config_file_option_boolean_default (ptr_option_enum)); } /* * Tests functions: * config_file_option_integer - */ - -TEST(CoreConfigFile, OptionInteger) -{ - /* TODO: write tests */ -} - -/* - * Tests functions: * config_file_option_integer_default */ -TEST(CoreConfigFile, OptionIntegerDefault) -{ - /* TODO: write tests */ +TEST(CoreConfigFileWithNewOptions, OptionInteger) +{ + LONGS_EQUAL(0, config_file_option_integer (NULL)); + LONGS_EQUAL(0, config_file_option_integer_default (NULL)); + + LONGS_EQUAL(100, config_file_option_integer (ptr_option_int)); + LONGS_EQUAL(100, config_file_option_integer_default (ptr_option_int)); + + config_file_option_set (ptr_option_int, "123", 1); + LONGS_EQUAL(123, config_file_option_integer (ptr_option_int)); + LONGS_EQUAL(100, config_file_option_integer_default (ptr_option_int)); + config_file_option_reset (ptr_option_int, 1); + LONGS_EQUAL(100, config_file_option_integer (ptr_option_int)); + LONGS_EQUAL(100, config_file_option_integer_default (ptr_option_int)); + + LONGS_EQUAL(0, config_file_option_integer (ptr_option_bool)); + LONGS_EQUAL(0, config_file_option_integer_default (ptr_option_bool)); + config_file_option_set (ptr_option_bool, "on", 1); + LONGS_EQUAL(1, config_file_option_integer (ptr_option_bool)); + LONGS_EQUAL(0, config_file_option_integer_default (ptr_option_bool)); + config_file_option_reset (ptr_option_bool, 1); + LONGS_EQUAL(1, config_file_option_integer (ptr_option_int_str)); + LONGS_EQUAL(1, config_file_option_integer_default (ptr_option_int_str)); + LONGS_EQUAL(0, config_file_option_integer (ptr_option_str)); + LONGS_EQUAL(0, config_file_option_integer_default (ptr_option_str)); + LONGS_EQUAL(9, config_file_option_integer (ptr_option_col)); + LONGS_EQUAL(9, config_file_option_integer_default (ptr_option_col)); + LONGS_EQUAL(1, config_file_option_integer (ptr_option_enum)); + LONGS_EQUAL(1, config_file_option_integer_default (ptr_option_enum)); } /* * Tests functions: * config_file_option_string - */ - -TEST(CoreConfigFile, OptionString) -{ - /* TODO: write tests */ -} - -/* - * Tests functions: * config_file_option_string_default */ -TEST(CoreConfigFile, OptionStringDefault) -{ - /* TODO: write tests */ +TEST(CoreConfigFileWithNewOptions, OptionString) +{ + POINTERS_EQUAL(0, config_file_option_string (NULL)); + POINTERS_EQUAL(0, config_file_option_string_default (NULL)); + + STRCMP_EQUAL("v2", config_file_option_string (ptr_option_int_str)); + STRCMP_EQUAL("v2", config_file_option_string_default (ptr_option_int_str)); + + STRCMP_EQUAL("value", config_file_option_string (ptr_option_str)); + STRCMP_EQUAL("value", config_file_option_string_default (ptr_option_str)); + + config_file_option_set (ptr_option_int_str, "v3", 1); + STRCMP_EQUAL("v3", config_file_option_string (ptr_option_int_str)); + STRCMP_EQUAL("v2", config_file_option_string_default (ptr_option_int_str)); + config_file_option_reset (ptr_option_int_str, 1); + STRCMP_EQUAL("v2", config_file_option_string (ptr_option_int_str)); + STRCMP_EQUAL("v2", config_file_option_string_default (ptr_option_int_str)); + + config_file_option_set (ptr_option_str, "test", 1); + STRCMP_EQUAL("test", config_file_option_string (ptr_option_str)); + STRCMP_EQUAL("value", config_file_option_string_default (ptr_option_str)); + config_file_option_reset (ptr_option_str, 1); + STRCMP_EQUAL("value", config_file_option_string (ptr_option_str)); + STRCMP_EQUAL("value", config_file_option_string_default (ptr_option_str)); + + STRCMP_EQUAL("off", config_file_option_string (ptr_option_bool)); + STRCMP_EQUAL("off", config_file_option_string_default (ptr_option_bool)); + POINTERS_EQUAL(NULL, config_file_option_string (ptr_option_int)); + POINTERS_EQUAL(NULL, config_file_option_string_default (ptr_option_int)); + STRCMP_EQUAL("v2", config_file_option_string (ptr_option_int_str)); + STRCMP_EQUAL("v2", config_file_option_string_default (ptr_option_int_str)); + STRCMP_EQUAL("blue", config_file_option_string (ptr_option_col)); + STRCMP_EQUAL("blue", config_file_option_string_default (ptr_option_col)); + STRCMP_EQUAL("v2", config_file_option_string (ptr_option_enum)); + STRCMP_EQUAL("v2", config_file_option_string_default (ptr_option_enum)); } /* * Tests functions: * config_file_option_color + * config_file_option_color_default */ -TEST(CoreConfigFile, OptionColor) -{ - /* TODO: write tests */ +TEST(CoreConfigFileWithNewOptions, OptionColor) +{ + POINTERS_EQUAL(0, config_file_option_color (NULL)); + POINTERS_EQUAL(0, config_file_option_color_default (NULL)); + + STRCMP_EQUAL("blue", config_file_option_color (ptr_option_col)); + STRCMP_EQUAL("blue", config_file_option_color_default (ptr_option_col)); + + config_file_option_set (ptr_option_col, "red", 1); + STRCMP_EQUAL("red", config_file_option_color (ptr_option_col)); + STRCMP_EQUAL("blue", config_file_option_color_default (ptr_option_col)); + config_file_option_reset (ptr_option_col, 1); + STRCMP_EQUAL("blue", config_file_option_color (ptr_option_col)); + STRCMP_EQUAL("blue", config_file_option_color_default (ptr_option_col)); + + POINTERS_EQUAL(NULL, config_file_option_color (ptr_option_bool)); + POINTERS_EQUAL(NULL, config_file_option_color_default (ptr_option_bool)); + POINTERS_EQUAL(NULL, config_file_option_color (ptr_option_int)); + POINTERS_EQUAL(NULL, config_file_option_color_default (ptr_option_int)); + POINTERS_EQUAL(NULL, config_file_option_color (ptr_option_int_str)); + POINTERS_EQUAL(NULL, config_file_option_color_default (ptr_option_int_str)); + POINTERS_EQUAL(NULL, config_file_option_color (ptr_option_str)); + POINTERS_EQUAL(NULL, config_file_option_color_default (ptr_option_str)); + POINTERS_EQUAL(NULL, config_file_option_color (ptr_option_enum)); + POINTERS_EQUAL(NULL, config_file_option_color_default (ptr_option_enum)); } /* * Tests functions: - * config_file_option_color_default + * config_file_option_enum + * config_file_option_enum_default */ -TEST(CoreConfigFile, OptionColorDefault) -{ - /* TODO: write tests */ +TEST(CoreConfigFileWithNewOptions, OptionEnum) +{ + LONGS_EQUAL(0, config_file_option_enum (NULL)); + LONGS_EQUAL(0, config_file_option_enum_default (NULL)); + + LONGS_EQUAL(1, config_file_option_enum (ptr_option_enum)); + LONGS_EQUAL(1, config_file_option_enum_default (ptr_option_enum)); + + config_file_option_set (ptr_option_enum, "v3", 1); + LONGS_EQUAL(2, config_file_option_enum (ptr_option_enum)); + LONGS_EQUAL(1, config_file_option_enum_default (ptr_option_enum)); + config_file_option_reset (ptr_option_enum, 1); + LONGS_EQUAL(1, config_file_option_enum (ptr_option_enum)); + LONGS_EQUAL(1, config_file_option_enum_default (ptr_option_enum)); + + LONGS_EQUAL(0, config_file_option_enum (ptr_option_bool)); + LONGS_EQUAL(0, config_file_option_enum_default (ptr_option_bool)); + config_file_option_set (ptr_option_bool, "on", 1); + LONGS_EQUAL(1, config_file_option_enum (ptr_option_bool)); + LONGS_EQUAL(0, config_file_option_enum_default (ptr_option_bool)); + config_file_option_reset (ptr_option_bool, 1); + LONGS_EQUAL(100, config_file_option_enum (ptr_option_int)); + LONGS_EQUAL(100, config_file_option_enum_default (ptr_option_int)); + LONGS_EQUAL(1, config_file_option_enum (ptr_option_int_str)); + LONGS_EQUAL(1, config_file_option_enum_default (ptr_option_int_str)); + LONGS_EQUAL(0, config_file_option_enum (ptr_option_str)); + LONGS_EQUAL(0, config_file_option_enum_default (ptr_option_str)); + LONGS_EQUAL(9, config_file_option_enum (ptr_option_col)); + LONGS_EQUAL(9, config_file_option_enum_default (ptr_option_col)); + LONGS_EQUAL(1, config_file_option_enum (ptr_option_enum)); + LONGS_EQUAL(1, config_file_option_enum_default (ptr_option_enum)); } /* |