From: Richard Russon Date: Tue, 24 Jul 2018 15:09:10 +0000 (+0100) Subject: config tests X-Git-Tag: 2019-10-25~735 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0628a66bc9f3a115894d125d1de0627278c6aec3;p=neomutt config tests --- diff --git a/.gitignore b/.gitignore index 8e0b57eac..6cc68da58 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ Makefile doc/makedoc neomutt pgpewrap +test/config-test test/neomutt-test # Build products diff --git a/Makefile.autosetup b/Makefile.autosetup index 4cfb62b74..b7daccc78 100644 --- a/Makefile.autosetup +++ b/Makefile.autosetup @@ -364,7 +364,6 @@ $(PWD)/hcache: $(PGPEWRAP): $(PGPEWRAPOBJS) $(CC) $(LDFLAGS) -o $@ $(PGPEWRAPOBJS) - # generated git_ver.h: $(ALL_FILES) version=`git describe --dirty --abbrev=6 --match "neomutt-*" 2> /dev/null | \ @@ -424,6 +423,9 @@ distclean: clean conststrings.c contrib/Makefile doc/Makefile doc/neomutt.1 \ html Makefile po/Makefile test/Makefile +# Tests for the config code +config-test: libmutt.a libemail.a libconfig.a + ############################################################################## # include generated dependency files -include $(DEPFILES) diff --git a/config/dump.c b/config/dump.c index 6a24223e8..d1c6d45ca 100644 --- a/config/dump.c +++ b/config/dump.c @@ -276,8 +276,8 @@ bool dump_config(struct ConfigSet *cs, int style, int flags) mutt_buffer_addstr(value, "***"); } - if (type == DT_PATH) - mutt_pretty_mailbox(value->data, value->dsize); + // if (type == DT_PATH) + // mutt_pretty_mailbox(value->data, value->dsize); if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING)) @@ -298,8 +298,8 @@ bool dump_config(struct ConfigSet *cs, int style, int flags) break; } - if (type == DT_PATH) - mutt_pretty_mailbox(value->data, value->dsize); + // if (type == DT_PATH) + // mutt_pretty_mailbox(value->data, value->dsize); if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING)) diff --git a/config/regex.c b/config/regex.c index 8523f869f..8d539a319 100644 --- a/config/regex.c +++ b/config/regex.c @@ -194,7 +194,8 @@ static int regex_native_set(const struct ConfigSet *cs, void *var, if (orig && orig->pattern) { - r = regex_create(orig->pattern, cdef->type, err); + const int flags = orig->not ? DT_REGEX_ALLOW_NOT : 0; + r = regex_create(orig->pattern, flags, err); if (!r) rc = CSR_ERR_INVALID; } diff --git a/test/Makefile.autosetup b/test/Makefile.autosetup index 94d835bf3..98deccb5a 100644 --- a/test/Makefile.autosetup +++ b/test/Makefile.autosetup @@ -4,16 +4,44 @@ TEST_OBJS = test/main.o \ test/rfc2047.o \ test/string.o + +CONFIG_OBJS = test/config/main.o test/config/account.o \ + test/config/address.o test/config/bool.o \ + test/config/command.o test/config/common.o \ + test/config/dump/data.o test/config/dump/dump.o \ + test/config/dump/vars.o test/config/initial.o \ + test/config/long.o test/config/magic.o \ + test/config/mbtable.o test/config/number.o \ + test/config/path.o test/config/quad.o test/config/regex.o \ + test/config/set.o test/config/sort.o test/config/string.o \ + test/config/synonym.o + +CFLAGS += -Itest + TEST_BINARY = test/neomutt-test$(EXEEXT) +TEST_CONFIG = test/config-test$(EXEEXT) + .PHONY: test -test: $(TEST_BINARY) +test: $(TEST_BINARY) $(TEST_CONFIG) $(TEST_BINARY) + @for i in set account initial synonym address bool command long magic mbtable number path quad regex sort string; do \ + $(TEST_CONFIG) $$i > test/config/$$i.txt.tmp; \ + if cmp -s test/config/$$i.txt test/config/$$i.txt.tmp; then \ + echo "Config test: '$$i' passed"; \ + rm -f test/config/$$i.txt.tmp; \ + else \ + echo "Config test: '$$i' failed"; \ + fi; \ + done $(TEST_BINARY): $(TEST_OBJS) $(MUTTLIBS) $(CC) -o $@ $(TEST_OBJS) $(MUTTLIBS) $(LDFLAGS) $(LIBS) -all-test: $(TEST_BINARY) +$(TEST_CONFIG): $(CONFIG_OBJS) $(MUTT_LIBS) + $(CC) -o $@ $(CONFIG_OBJS) $(MUTTLIBS) $(LDFLAGS) $(LIBS) libemail.a libmutt.a + +all-test: $(TEST_BINARY) $(TEST_CONFIG) clean-test: $(RM) $(TEST_BINARY) $(TEST_OBJS) $(TEST_OBJS:.o=.Po) @@ -24,4 +52,7 @@ uninstall-test: TEST_DEPFILES = $(TEST_OBJS:.o=.Po) -include $(TEST_DEPFILES) +CONFIG_DEPFILES = $(CONFIG_OBJS:.o=.Po) +-include $(CONFIG_DEPFILES) + # vim: set ts=8 noexpandtab: diff --git a/test/config/account.c b/test/config/account.c new file mode 100644 index 000000000..b08afb7b0 --- /dev/null +++ b/test/config/account.c @@ -0,0 +1,370 @@ +/** + * @file + * Test code for the Account object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include "mutt/buffer.h" +#include "mutt/hash.h" +#include "mutt/logging.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/common.h" +#include "config/number.h" +#include "config/set.h" +#include "config/types.h" +#include "config/inheritance.h" + +static short VarApple; +static short VarBanana; +static short VarCherry; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_NUMBER, 0, &VarApple, 0, NULL }, + { "Banana", DT_NUMBER, 0, &VarBanana, 0, NULL }, + { "Cherry", DT_NUMBER, 0, &VarCherry, 0, NULL }, + { NULL }, +}; +// clang-format on + +bool account_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + number_init(cs); + if (!cs_register_variables(cs, Vars, 0)) + return false; + + set_list(cs); + + cs_add_listener(cs, log_listener); + + const char *account = "damaged"; + const char *BrokenVarStr[] = { + "Pineapple", NULL, + }; + + struct Account *ac = ac_create(cs, account, BrokenVarStr); + if (!ac) + { + printf("Expected error:\n"); + } + else + { + ac_free(cs, &ac); + printf("This test should have failed\n"); + return false; + } + + const char *AccountVarStr2[] = { + "Apple", "Apple", NULL, + }; + + printf("Expect error for next test\n"); + ac = ac_create(cs, account, AccountVarStr2); + if (ac) + { + ac_free(cs, &ac); + printf("This test should have failed\n"); + return false; + } + + account = "fruit"; + const char *AccountVarStr[] = { + "Apple", "Cherry", NULL, + }; + + ac = ac_create(cs, account, AccountVarStr); + if (!ac) + return false; + + unsigned int index = 0; + mutt_buffer_reset(&err); + int rc = ac_set_value(ac, index, 33, &err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err.data); + } + + mutt_buffer_reset(&err); + rc = ac_set_value(ac, 99, 42, &err); + if (CSR_RESULT(rc) == CSR_ERR_UNKNOWN) + { + printf("Expected error: %s\n", err.data); + } + else + { + printf("This test should have failed\n"); + return false; + } + + mutt_buffer_reset(&err); + rc = ac_get_value(ac, index, &err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err.data); + } + else + { + printf("%s = %s\n", AccountVarStr[index], err.data); + } + + index++; + mutt_buffer_reset(&err); + rc = ac_get_value(ac, index, &err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err.data); + } + else + { + printf("%s = %s\n", AccountVarStr[index], err.data); + } + + mutt_buffer_reset(&err); + rc = ac_get_value(ac, 99, &err); + if (CSR_RESULT(rc) == CSR_ERR_UNKNOWN) + { + printf("Expected error\n"); + } + else + { + printf("This test should have failed\n"); + return false; + } + + const char *name = "fruit:Apple"; + mutt_buffer_reset(&err); + int result = cs_str_string_get(cs, name, &err); + if (CSR_RESULT(result) == CSR_SUCCESS) + { + printf("%s = '%s'\n", name, err.data); + } + else + { + printf("%s\n", err.data); + return false; + } + + mutt_buffer_reset(&err); + result = cs_str_native_set(cs, name, 42, &err); + if (CSR_RESULT(result) == CSR_SUCCESS) + { + printf("Set %s\n", name); + } + else + { + printf("%s\n", err.data); + return false; + } + + struct HashElem *he = cs_get_elem(cs, name); + if (!he) + return false; + + mutt_buffer_reset(&err); + result = cs_str_initial_set(cs, name, "42", &err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error\n"); + } + else + { + printf("This test should have failed\n"); + return false; + } + + mutt_buffer_reset(&err); + result = cs_str_initial_get(cs, name, &err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error\n"); + } + else + { + printf("This test should have failed\n"); + return false; + } + + name = "Apple"; + he = cs_get_elem(cs, name); + if (!he) + return false; + + mutt_buffer_reset(&err); + result = cs_he_native_set(cs, he, 42, &err); + if (CSR_RESULT(result) == CSR_SUCCESS) + { + printf("Set %s\n", name); + } + else + { + printf("%s\n", err.data); + return false; + } + + ac_free(cs, &ac); + cs_free(&cs); + FREE(&err.data); + + return true; +} + +/** + * ac_create - Create an Account + * @param cs Config items + * @param name Name of Account + * @param var_names List of config items (NULL terminated) + * @retval ptr New Account object + */ +struct Account *ac_create(const struct ConfigSet *cs, const char *name, + const char *var_names[]) +{ + if (!cs || !name || !var_names) + return NULL; /* LCOV_EXCL_LINE */ + + int count = 0; + for (; var_names[count]; count++) + ; + + struct Account *ac = mutt_mem_calloc(1, sizeof(*ac)); + ac->name = mutt_str_strdup(name); + ac->cs = cs; + ac->var_names = var_names; + ac->vars = mutt_mem_calloc(count, sizeof(struct HashElem *)); + ac->num_vars = count; + + bool success = true; + char acname[64]; + + for (size_t i = 0; i < ac->num_vars; i++) + { + struct HashElem *parent = cs_get_elem(cs, ac->var_names[i]); + if (!parent) + { + mutt_debug(1, "%s doesn't exist\n", ac->var_names[i]); + success = false; + break; + } + + snprintf(acname, sizeof(acname), "%s:%s", name, ac->var_names[i]); + ac->vars[i] = cs_inherit_variable(cs, parent, acname); + if (!ac->vars[i]) + { + mutt_debug(1, "failed to create %s\n", acname); + success = false; + break; + } + } + + if (success) + return ac; + + ac_free(cs, &ac); + return NULL; +} + +/** + * ac_free - Free an Account object + * @param cs Config items + * @param ac Account to free + */ +void ac_free(const struct ConfigSet *cs, struct Account **ac) +{ + if (!cs || !ac || !*ac) + return; /* LCOV_EXCL_LINE */ + + char child[128]; + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + + for (size_t i = 0; i < (*ac)->num_vars; i++) + { + snprintf(child, sizeof(child), "%s:%s", (*ac)->name, (*ac)->var_names[i]); + mutt_buffer_reset(&err); + int result = cs_str_reset(cs, child, &err); + if (CSR_RESULT(result) != CSR_SUCCESS) + mutt_debug(1, "reset failed for %s: %s\n", child, err.data); + mutt_hash_delete(cs->hash, child, NULL); + } + + FREE(&err.data); + FREE(&(*ac)->name); + FREE(&(*ac)->vars); + FREE(ac); +} + +/** + * ac_set_value - Set an Account-specific config item + * @param ac Account-specific config items + * @param vid Value ID (index into Account's HashElem's) + * @param value Native pointer/value to set + * @param err Buffer for error messages + * @retval int Result, e.g. #CSR_SUCCESS + */ +int ac_set_value(const struct Account *ac, unsigned int vid, intptr_t value, struct Buffer *err) +{ + if (!ac) + return CSR_ERR_CODE; /* LCOV_EXCL_LINE */ + if (vid >= ac->num_vars) + return CSR_ERR_UNKNOWN; + + struct HashElem *he = ac->vars[vid]; + return cs_he_native_set(ac->cs, he, value, err); +} + +/** + * ac_get_value - Get an Account-specific config item + * @param ac Account-specific config items + * @param vid Value ID (index into Account's HashElem's) + * @param result Buffer for results or error messages + * @retval int Result, e.g. #CSR_SUCCESS + */ +int ac_get_value(const struct Account *ac, unsigned int vid, struct Buffer *result) +{ + if (!ac) + return CSR_ERR_CODE; /* LCOV_EXCL_LINE */ + if (vid >= ac->num_vars) + return CSR_ERR_UNKNOWN; + + struct HashElem *he = ac->vars[vid]; + + if ((he->type & DT_INHERITED) && (DTYPE(he->type) == 0)) + { + struct Inheritance *i = he->data; + he = i->parent; + } + + return cs_he_string_get(ac->cs, he, result); +} diff --git a/test/config/account.h b/test/config/account.h new file mode 100644 index 000000000..5236d03ad --- /dev/null +++ b/test/config/account.h @@ -0,0 +1,49 @@ +/** + * @file + * A collection of account-specific config items + * + * @authors + * Copyright (C) 2017-2018 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _CONFIG_ACCOUNT_H +#define _CONFIG_ACCOUNT_H + +#include + +struct Buffer; +struct ConfigSet; + +/** + * struct Account - Account-local config items + */ +struct Account +{ + char *name; /**< Name of Account */ + const struct ConfigSet *cs; /**< Parent ConfigSet */ + const char **var_names; /**< Array of the names of local config items */ + int num_vars; /**< Number of local config items */ + struct HashElem **vars; /**< Array of the HashElems of local config items */ +}; + +struct Account *ac_create(const struct ConfigSet *cs, const char *name, const char *var_names[]); +void ac_free(const struct ConfigSet *cs, struct Account **ac); + +int ac_set_value(const struct Account *ac, unsigned int vid, intptr_t value, struct Buffer *err); +int ac_get_value(const struct Account *ac, unsigned int vid, struct Buffer *err); + +#endif /* _CONFIG_ACCOUNT_H */ diff --git a/test/config/account.txt b/test/config/account.txt new file mode 100644 index 000000000..16db75144 --- /dev/null +++ b/test/config/account.txt @@ -0,0 +1,25 @@ +---- account_test ------------------------------------------ +---- set_list ---------------------------------------------- +number Apple = 0 +number Banana = 0 +number Cherry = 0 +Pineapple doesn't exist +reset failed for damaged:Pineapple: Unknown var 'damaged:Pineapple' +Expected error: +Expect error for next test +failed to create damaged:Apple +reset failed for damaged:Apple: Unknown var 'damaged:Apple' +Event: Apple has been set to '33' +Expected error: +Apple = 33 +Cherry = 0 +Expected error +fruit:Apple = '33' +Event: Apple has been set to '42' +Set fruit:Apple +Variable 'Apple' is inherited type. +Expected error +Expected error +Event: Apple has been set to '42' +Set Apple +Event: fruit:Apple has been reset to '42' diff --git a/test/config/account2.h b/test/config/account2.h new file mode 100644 index 000000000..a673f0ce4 --- /dev/null +++ b/test/config/account2.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Account object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_ACCOUNT_H +#define _TEST_ACCOUNT_H + +#include + +bool account_test(void); + +#endif /* _TEST_ACCOUNT_H */ diff --git a/test/config/address.c b/test/config/address.c new file mode 100644 index 000000000..c47f5d92d --- /dev/null +++ b/test/config/address.c @@ -0,0 +1,631 @@ +/** + * @file + * Test code for the Address object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/address.h" +#include "config/set.h" +#include "config/types.h" +#include "email/address.h" +#include "config/common.h" + +static struct Address *VarApple; +static struct Address *VarBanana; +static struct Address *VarCherry; +static struct Address *VarDamson; +static struct Address *VarElderberry; +static struct Address *VarFig; +static struct Address *VarGuava; +static struct Address *VarHawthorn; +static struct Address *VarIlama; +static struct Address *VarJackfruit; +static struct Address *VarKumquat; +static struct Address *VarLemon; +static struct Address *VarMango; +static struct Address *VarNectarine; +static struct Address *VarOlive; +static struct Address *VarPapaya; +static struct Address *VarQuince; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_ADDRESS, 0, &VarApple, IP "apple@example.com", NULL }, /* test_initial_values */ + { "Banana", DT_ADDRESS, 0, &VarBanana, IP "banana@example.com", NULL }, + { "Cherry", DT_ADDRESS, 0, &VarCherry, IP "cherry@example.com", NULL }, + { "Damson", DT_ADDRESS, 0, &VarDamson, 0, NULL }, /* test_address_set */ + { "Elderberry", DT_ADDRESS, 0, &VarElderberry, IP "elderberry@example.com", NULL }, + { "Fig", DT_ADDRESS, 0, &VarFig, 0, NULL }, /* test_address_get */ + { "Guava", DT_ADDRESS, 0, &VarGuava, IP "guava@example.com", NULL }, + { "Hawthorn", DT_ADDRESS, 0, &VarHawthorn, 0, NULL }, + { "Ilama", DT_ADDRESS, 0, &VarIlama, 0, NULL }, /* test_native_set */ + { "Jackfruit", DT_ADDRESS, 0, &VarJackfruit, IP "jackfruit@example.com", NULL }, + { "Kumquat", DT_ADDRESS, 0, &VarKumquat, 0, NULL }, /* test_native_get */ + { "Lemon", DT_ADDRESS, 0, &VarLemon, IP "lemon@example.com", NULL }, /* test_reset */ + { "Mango", DT_ADDRESS, 0, &VarMango, IP "mango@example.com", validator_fail }, + { "Nectarine", DT_ADDRESS, 0, &VarNectarine, IP "nectarine@example.com", validator_succeed }, /* test_validator */ + { "Olive", DT_ADDRESS, 0, &VarOlive, IP "olive@example.com", validator_warn }, + { "Papaya", DT_ADDRESS, 0, &VarPapaya, IP "papaya@example.com", validator_fail }, + { "Quince", DT_ADDRESS, 0, &VarQuince, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = '%s'\n", VarApple->mailbox); + printf("Banana = '%s'\n", VarBanana->mailbox); + + const char *apple_orig = "apple@example.com"; + const char *banana_orig = "banana@example.com"; + + if ((mutt_str_strcmp(VarApple->mailbox, apple_orig) != 0) || + (mutt_str_strcmp(VarBanana->mailbox, banana_orig) != 0)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "granny@smith.com", err); + cs_str_string_set(cs, "Banana", NULL, err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, apple_orig) != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = '%s'\n", VarApple->mailbox); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, banana_orig) != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = '%s'\n", VarBanana ? VarBanana->mailbox : ""); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "john@doe.com", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "jane@doe.com", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry ? VarCherry->mailbox : ""); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello@example.com", "world@example.com", NULL }; + char *name = "Damson"; + char *addr = NULL; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + addr = VarDamson ? VarDamson->mailbox : NULL; + if (mutt_str_strcmp(addr, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(addr), NONULL(valid[i])); + } + + name = "Elderberry"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + addr = VarElderberry ? VarElderberry->mailbox : NULL; + if (mutt_str_strcmp(addr, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(addr), NONULL(valid[i])); + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Fig"; + char *addr = NULL; + + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + addr = VarFig ? VarFig->mailbox : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(addr), err->data); + + name = "Guava"; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + addr = VarGuava ? VarGuava->mailbox : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(addr), err->data); + + name = "Hawthorn"; + rc = cs_str_string_set(cs, name, "hawthorn", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + addr = VarHawthorn ? VarHawthorn->mailbox : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(addr), err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + struct Address *a = address_create("hello@example.com"); + char *name = "Ilama"; + char *addr = NULL; + bool result = false; + + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, (intptr_t) a, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + goto tbns_out; + } + + addr = VarIlama ? VarIlama->mailbox : NULL; + if (mutt_str_strcmp(addr, a->mailbox) != 0) + { + printf("Value of %s wasn't changed\n", name); + goto tbns_out; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(addr), a->mailbox); + + name = "Jackfruit"; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 0, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + goto tbns_out; + } + + if (VarJackfruit != NULL) + { + printf("Value of %s wasn't changed\n", name); + goto tbns_out; + } + addr = VarJackfruit ? VarJackfruit->mailbox : NULL; + printf("%s = '%s', set by NULL\n", name, NONULL(addr)); + + result = true; +tbns_out: + address_free(&a); + return result; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Kumquat"; + + if (cs_str_string_set(cs, name, "kumquat@example.com", err) == INT_MIN) + return false; + + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + struct Address *a = (struct Address *) value; + + if (VarKumquat != a) + { + printf("Get failed: %s\n", err->data); + return false; + } + char *addr1 = VarKumquat ? VarKumquat->mailbox : NULL; + char *addr2 = a ? a->mailbox : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(addr1), NONULL(addr2)); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Lemon"; + char *addr = NULL; + + mutt_buffer_reset(err); + + addr = VarLemon ? VarLemon->mailbox : NULL; + printf("Initial: %s = '%s'\n", name, NONULL(addr)); + int rc = cs_str_string_set(cs, name, "hello@example.com", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + addr = VarLemon ? VarLemon->mailbox : NULL; + printf("Set: %s = '%s'\n", name, NONULL(addr)); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + addr = VarLemon ? VarLemon->mailbox : NULL; + if (mutt_str_strcmp(addr, "lemon@example.com") != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, NONULL(addr)); + + name = "Mango"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarMango->mailbox); + dont_fail = true; + rc = cs_str_string_set(cs, name, "john@example.com", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarMango->mailbox); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarMango->mailbox, "john@example.com") != 0) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarMango->mailbox); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *addr = NULL; + struct Address *a = address_create("world@example.com"); + bool result = false; + + char *name = "Nectarine"; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "hello@example.com", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + addr = VarNectarine ? VarNectarine->mailbox : NULL; + printf("Address: %s = %s\n", name, NONULL(addr)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP a, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + addr = VarNectarine ? VarNectarine->mailbox : NULL; + printf("Native: %s = %s\n", name, NONULL(addr)); + + name = "Olive"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello@example.com", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + addr = VarOlive ? VarOlive->mailbox : NULL; + printf("Address: %s = %s\n", name, NONULL(addr)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP a, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + addr = VarOlive ? VarOlive->mailbox : NULL; + printf("Native: %s = %s\n", name, NONULL(addr)); + + name = "Papaya"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello@example.com", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + addr = VarPapaya ? VarPapaya->mailbox : NULL; + printf("Address: %s = %s\n", name, NONULL(addr)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP a, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + addr = VarPapaya ? VarPapaya->mailbox : NULL; + printf("Native: %s = %s\n", name, NONULL(addr)); + + result = true; +tv_out: + address_free(&a); + return result; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + struct Address *pa = (struct Address *) pval; + struct Address *ca = (struct Address *) cval; + + char *pstr = pa ? pa->mailbox : NULL; + char *cstr = ca ? ca->mailbox : NULL; + + printf("%15s = %s\n", parent, NONULL(pstr)); + printf("%15s = %s\n", child, NONULL(cstr)); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Quince"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarAddr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarAddr); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "hello@example.com", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "world@example.com", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool address_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + address_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/address.h b/test/config/address.h new file mode 100644 index 000000000..46a3000a1 --- /dev/null +++ b/test/config/address.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Address object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_ADDRESS_H +#define _TEST_ADDRESS_H + +#include + +bool address_test(void); + +#endif /* _TEST_ADDRESS_H */ diff --git a/test/config/address.txt b/test/config/address.txt new file mode 100644 index 000000000..bee50da5b --- /dev/null +++ b/test/config/address.txt @@ -0,0 +1,99 @@ +---- address_test ------------------------------------------ +---- set_list ---------------------------------------------- +address Apple = apple@example.com +address Banana = banana@example.com +address Cherry = cherry@example.com +address Damson = +address Elderberry = elderberry@example.com +address Fig = +address Guava = guava@example.com +address Hawthorn = +address Ilama = +address Jackfruit = jackfruit@example.com +address Kumquat = +address Lemon = lemon@example.com +address Mango = mango@example.com +address Nectarine = nectarine@example.com +address Olive = olive@example.com +address Papaya = papaya@example.com +address Quince = +---- test_initial_values ----------------------------------- +Apple = 'apple@example.com' +Banana = 'banana@example.com' +Event: Apple has been set to 'granny@smith.com' +Event: Banana has been set to '' +Apple = 'granny@smith.com' +Apple's initial value is 'apple@example.com' +Banana = '' +Banana's initial value is 'banana@example.com' +Event: Cherry has been initial-set to 'john@doe.com' +Event: Cherry has been initial-set to 'jane@doe.com' +Cherry = 'cherry@example.com' +Cherry's initial value is 'jane@doe.com' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'hello@example.com' +Damson = 'hello@example.com', set by 'hello@example.com' +Event: Damson has been set to 'world@example.com' +Damson = 'world@example.com', set by 'world@example.com' +Event: Damson has been set to '' +Damson = '', set by '' +Event: Elderberry has been set to 'hello@example.com' +Elderberry = 'hello@example.com', set by 'hello@example.com' +Event: Elderberry has been set to 'world@example.com' +Elderberry = 'world@example.com', set by 'world@example.com' +Event: Elderberry has been set to '' +Elderberry = '', set by '' +---- test_string_get --------------------------------------- +Fig = '', '' +Guava = 'guava@example.com', 'guava@example.com' +Event: Hawthorn has been set to 'hawthorn' +Hawthorn = 'hawthorn', 'hawthorn' +---- test_native_set --------------------------------------- +Event: Ilama has been set to 'hello@example.com' +Ilama = 'hello@example.com', set by 'hello@example.com' +Event: Jackfruit has been set to '' +Jackfruit = '', set by NULL +---- test_native_get --------------------------------------- +Event: Kumquat has been set to 'kumquat@example.com' +Kumquat = 'kumquat@example.com', 'kumquat@example.com' +---- test_reset -------------------------------------------- +Initial: Lemon = 'lemon@example.com' +Event: Lemon has been set to 'hello@example.com' +Set: Lemon = 'hello@example.com' +Event: Lemon has been reset to 'lemon@example.com' +Reset: Lemon = 'lemon@example.com' +Initial: Mango = 'mango@example.com' +Event: Mango has been set to 'john@example.com' +Set: Mango = 'john@example.com' +Expected error: validator_fail: Mango, (ptr) +Reset: Mango = 'john@example.com' +---- test_validator ---------------------------------------- +Event: Nectarine has been set to 'hello@example.com' +validator_succeed: Nectarine, (ptr) +Address: Nectarine = hello@example.com +Event: Nectarine has been set to 'world@example.com' +validator_succeed: Nectarine, (ptr) +Native: Nectarine = world@example.com +Event: Olive has been set to 'hello@example.com' +validator_warn: Olive, (ptr) +Address: Olive = hello@example.com +Event: Olive has been set to 'world@example.com' +validator_warn: Olive, (ptr) +Native: Olive = world@example.com +Expected error: validator_fail: Papaya, (ptr) +Address: Papaya = papaya@example.com +Expected error: validator_fail: Papaya, (ptr) +Native: Papaya = papaya@example.com +---- test_inherit ------------------------------------------ +Event: Quince has been set to 'hello@example.com' + Quince = hello@example.com + fruit:Quince = hello@example.com +Event: fruit:Quince has been set to 'world@example.com' + Quince = hello@example.com + fruit:Quince = world@example.com +Event: fruit:Quince has been reset to 'hello@example.com' + Quince = hello@example.com + fruit:Quince = hello@example.com +Event: Quince has been reset to '' + Quince = + fruit:Quince = diff --git a/test/config/bool.c b/test/config/bool.c new file mode 100644 index 000000000..4bbeb8f60 --- /dev/null +++ b/test/config/bool.c @@ -0,0 +1,735 @@ +/** + * @file + * Test code for the Bool object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/bool.h" +#include "config/quad.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static bool VarApple; +static bool VarBanana; +static bool VarCherry; +static bool VarDamson; +static bool VarFig; +static bool VarGuava; +static bool VarHawthorn; +static bool VarJackfruit; +static bool VarKumquat; +static bool VarLemon; +static bool VarMango; +static char VarElderberry; +static char VarIlama; +static char VarNectarine; +static char VarOlive; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_BOOL, 0, &VarApple, 0, NULL }, /* test_initial_values */ + { "Banana", DT_BOOL, 0, &VarBanana, 1, NULL }, + { "Cherry", DT_BOOL, 0, &VarCherry, 0, NULL }, + { "Damson", DT_BOOL, 0, &VarDamson, 0, NULL }, /* test_string_set */ + { "Elderberry", DT_BOOL, 0, &VarElderberry, 0, NULL }, /* test_string_get */ + { "Fig", DT_BOOL, 0, &VarFig, 0, NULL }, /* test_native_set */ + { "Guava", DT_BOOL, 0, &VarGuava, 0, NULL }, /* test_native_get */ + { "Hawthorn", DT_BOOL, 0, &VarHawthorn, 0, NULL }, /* test_reset */ + { "Ilama", DT_BOOL, 0, &VarIlama, 0, validator_fail }, + { "Jackfruit", DT_BOOL, 0, &VarJackfruit, 0, validator_succeed }, /* test_validator */ + { "Kumquat", DT_BOOL, 0, &VarKumquat, 0, validator_warn }, + { "Lemon", DT_BOOL, 0, &VarLemon, 0, validator_fail }, + { "Mango", DT_BOOL, 0, &VarMango, 0, NULL }, /* test_inherit */ + { "Nectarine", DT_BOOL, 0, &VarNectarine, 0, NULL }, /* test_toggle */ + { "Olive", DT_QUAD, 0, &VarOlive, 0, NULL }, + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %d\n", VarApple); + printf("Banana = %d\n", VarBanana); + + if ((VarApple != false) || (VarBanana != true)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "true", err); + cs_str_string_set(cs, "Banana", "false", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "no") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = '%s'\n", VarApple ? "yes" : "no"); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "yes") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = '%s'\n", VarBanana ? "yes" : "no"); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "yes", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry ? "yes" : "no"); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { + "no", "yes", "n", "y", "false", "true", "0", "1", "off", "on", + }; + const char *invalid[] = { + "nope", "ye", "", NULL, + }; + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + VarDamson = ((i + 1) % 2); + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarDamson != (i % 2)) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = %d, set by '%s'\n", name, VarDamson, valid[i]); + } + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "yes", err); + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + } + else + { + printf("This test should have failed\n"); + return false; + } + + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%s'\n", name, VarDamson, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Elderberry"; + int rc; + + VarElderberry = false; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarElderberry, err->data); + + VarElderberry = true; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarElderberry, err->data); + + VarElderberry = 3; + mutt_buffer_reset(err); + printf("Expect error for next test\n"); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + // return false; + } + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Fig"; + bool value = true; + int rc; + + VarFig = false; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarFig != value) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("%s = %d, set to '%d'\n", name, VarFig, value); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + } + + int invalid[] = { -1, 2 }; + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + VarFig = false; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%d'\n", name, VarFig, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Guava"; + + VarGuava = true; + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %ld\n", name, value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Hawthorn"; + VarHawthorn = true; + mutt_buffer_reset(err); + + int rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarHawthorn == true) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarHawthorn); + + name = "Ilama"; + mutt_buffer_reset(err); + + printf("Initial: %s = %d\n", name, VarIlama); + dont_fail = true; + rc = cs_str_string_set(cs, name, "yes", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = %d\n", name, VarIlama); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (!VarIlama) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarIlama); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Jackfruit"; + VarJackfruit = false; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "yes", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarJackfruit); + + VarJackfruit = false; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 1, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarJackfruit); + + name = "Kumquat"; + VarKumquat = false; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "yes", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarKumquat); + + VarKumquat = false; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 1, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarKumquat); + + name = "Lemon"; + VarLemon = false; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "yes", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarLemon); + + VarLemon = false; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 1, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarLemon); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %ld\n", parent, pval); + printf("%15s = %ld\n", child, cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Mango"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + VarMango = false; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "1", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "0", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", parent); + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +static bool test_toggle(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + struct ToggleTest + { + bool before; + bool after; + }; + + struct ToggleTest tests[] = { { false, true }, { true, false } }; + + char *name = "Nectarine"; + int rc; + + struct HashElem *he = cs_get_elem(cs, name); + if (!he) + return false; + + for (size_t i = 0; i < mutt_array_size(tests); i++) + { + bool before = tests[i].before; + bool after = tests[i].after; + printf("test %zd\n", i); + + VarNectarine = before; + mutt_buffer_reset(err); + intptr_t value = cs_he_native_get(cs, he, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + + bool copy = value; + if (copy != before) + { + printf("Initial value is wrong: %s\n", err->data); + return false; + } + + rc = bool_he_toggle(cs, he, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Toggle failed: %s\n", err->data); + return false; + } + + if (VarNectarine != after) + { + printf("Toggle value is wrong: %s\n", err->data); + return false; + } + } + + for (size_t i = 0; i < mutt_array_size(tests); i++) + { + bool before = tests[i].before; + bool after = tests[i].after; + printf("test %zd\n", i); + + VarNectarine = before; + mutt_buffer_reset(err); + intptr_t value = cs_he_native_get(cs, he, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + + bool copy = value; + if (copy != before) + { + printf("Initial value is wrong: %s\n", err->data); + return false; + } + + rc = bool_str_toggle(cs, "Nectarine", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Toggle failed: %s\n", err->data); + return false; + } + + if (VarNectarine != after) + { + printf("Toggle value is wrong: %s\n", err->data); + return false; + } + } + + VarNectarine = 8; + mutt_buffer_reset(err); + rc = bool_he_toggle(cs, he, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + + name = "Olive"; + he = cs_get_elem(cs, name); + if (!he) + return false; + + mutt_buffer_reset(err); + rc = bool_he_toggle(cs, he, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + + mutt_buffer_reset(err); + rc = bool_str_toggle(cs, "unknown", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("This test should have failed\n"); + return false; + } + + return true; +} + +bool bool_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + bool_init(cs); + quad_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + if (!test_toggle(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/bool.h b/test/config/bool.h new file mode 100644 index 000000000..0215eeefd --- /dev/null +++ b/test/config/bool.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Bool object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_BOOL_H +#define _TEST_BOOL_H + +#include + +bool bool_test(void); + +#endif /* _TEST_BOOL_H */ diff --git a/test/config/bool.txt b/test/config/bool.txt new file mode 100644 index 000000000..5c62a7a10 --- /dev/null +++ b/test/config/bool.txt @@ -0,0 +1,118 @@ +---- bool_test --------------------------------------------- +---- set_list ---------------------------------------------- +boolean Apple = no +boolean Banana = yes +boolean Cherry = no +boolean Damson = no +boolean Elderberry = no +boolean Fig = no +boolean Guava = no +boolean Hawthorn = no +boolean Ilama = no +boolean Jackfruit = no +boolean Kumquat = no +boolean Lemon = no +boolean Mango = no +boolean Nectarine = no +quad Olive = no +---- test_initial_values ----------------------------------- +Apple = 0 +Banana = 1 +Event: Apple has been set to 'yes' +Event: Banana has been set to 'no' +Apple = 'yes' +Apple's initial value is 'no' +Banana = 'no' +Banana's initial value is 'yes' +Event: Cherry has been initial-set to 'yes' +Cherry = 'no' +Cherry's initial value is 'yes' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'no' +Damson = 0, set by 'no' +Event: Damson has been set to 'yes' +Damson = 1, set by 'yes' +Event: Damson has been set to 'no' +Damson = 0, set by 'n' +Event: Damson has been set to 'yes' +Damson = 1, set by 'y' +Event: Damson has been set to 'no' +Damson = 0, set by 'false' +Event: Damson has been set to 'yes' +Damson = 1, set by 'true' +Event: Damson has been set to 'no' +Damson = 0, set by '0' +Event: Damson has been set to 'yes' +Damson = 1, set by '1' +Event: Damson has been set to 'no' +Damson = 0, set by 'off' +Event: Damson has been set to 'yes' +Damson = 1, set by 'on' +Value of Damson wasn't changed +Expected error: Invalid boolean value: nope +Expected error: Invalid boolean value: ye +Expected error: Invalid boolean value: +Expected error: +---- test_string_get --------------------------------------- +Elderberry = 0, no +Elderberry = 1, yes +Expect error for next test +Variable has an invalid value: 3 +---- test_native_set --------------------------------------- +Event: Fig has been set to 'yes' +Fig = 1, set to '1' +Value of Fig wasn't changed +Expected error: Invalid boolean value: -1 +Expected error: Invalid boolean value: 2 +---- test_native_get --------------------------------------- +Guava = 1 +---- test_reset -------------------------------------------- +Event: Hawthorn has been reset to 'no' +Reset: Hawthorn = 0 +Initial: Ilama = 0 +Event: Ilama has been set to 'yes' +Set: Ilama = 1 +Expected error: validator_fail: Ilama, 0 +Reset: Ilama = 1 +---- test_validator ---------------------------------------- +Event: Jackfruit has been set to 'yes' +validator_succeed: Jackfruit, 1 +String: Jackfruit = 1 +Event: Jackfruit has been set to 'yes' +validator_succeed: Jackfruit, 1 +Native: Jackfruit = 1 +Event: Kumquat has been set to 'yes' +validator_warn: Kumquat, 1 +String: Kumquat = 1 +Event: Kumquat has been set to 'yes' +validator_warn: Kumquat, 1 +Native: Kumquat = 1 +Expected error: validator_fail: Lemon, 1 +String: Lemon = 0 +Expected error: validator_fail: Lemon, 1 +Native: Lemon = 0 +---- test_inherit ------------------------------------------ +Event: Mango has been set to 'yes' + Mango = 1 + fruit:Mango = 1 +Value of Mango wasn't changed + Mango = 1 + fruit:Mango = 0 +Event: fruit:Mango has been reset to 'yes' + Mango = 1 + fruit:Mango = 1 +Event: Mango has been reset to 'no' + Mango = 0 + fruit:Mango = 0 +---- test_toggle ------------------------------------------- +test 0 +Event: Nectarine has been set to 'yes' +test 1 +Event: Nectarine has been set to 'no' +test 0 +Event: Nectarine has been set to 'yes' +test 1 +Event: Nectarine has been set to 'no' +Expected error: Invalid boolean value: 8 +Expected error: +Expected error: Unknown var 'unknown' diff --git a/test/config/command.c b/test/config/command.c new file mode 100644 index 000000000..a16d94b37 --- /dev/null +++ b/test/config/command.c @@ -0,0 +1,653 @@ +/** + * @file + * Test code for the Command object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/command.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static char *VarApple; +static char *VarBanana; +static char *VarCherry; +static char *VarDamson; +static char *VarElderberry; +static char *VarFig; +static char *VarGuava; +static char *VarHawthorn; +static char *VarIlama; +static char *VarJackfruit; +static char *VarKumquat; +static char *VarLemon; +static char *VarMango; +static char *VarNectarine; +static char *VarOlive; +static char *VarPapaya; +static char *VarQuince; +static char *VarRaspberry; +static char *VarStrawberry; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_COMMAND, 0, &VarApple, IP "/apple", NULL }, /* test_initial_values */ + { "Banana", DT_COMMAND, 0, &VarBanana, IP "/banana", NULL }, + { "Cherry", DT_COMMAND, 0, &VarCherry, IP "/cherry", NULL }, + { "Damson", DT_COMMAND, 0, &VarDamson, 0, NULL }, /* test_string_set */ + { "Elderberry", DT_COMMAND, 0, &VarElderberry, IP "/elderberry", NULL }, + { "Fig", DT_COMMAND|DT_NOT_EMPTY, 0, &VarFig, IP "fig", NULL }, + { "Guava", DT_COMMAND, 0, &VarGuava, 0, NULL }, /* test_string_get */ + { "Hawthorn", DT_COMMAND, 0, &VarHawthorn, IP "/hawthorn", NULL }, + { "Ilama", DT_COMMAND, 0, &VarIlama, 0, NULL }, + { "Jackfruit", DT_COMMAND, 0, &VarJackfruit, 0, NULL }, /* test_native_set */ + { "Kumquat", DT_COMMAND, 0, &VarKumquat, IP "/kumquat", NULL }, + { "Lemon", DT_COMMAND|DT_NOT_EMPTY, 0, &VarLemon, IP "lemon", NULL }, + { "Mango", DT_COMMAND, 0, &VarMango, 0, NULL }, /* test_native_get */ + { "Nectarine", DT_COMMAND, 0, &VarNectarine, IP "/nectarine", NULL }, /* test_reset */ + { "Olive", DT_COMMAND, 0, &VarOlive, IP "/olive", validator_fail }, + { "Papaya", DT_COMMAND, 0, &VarPapaya, IP "/papaya", validator_succeed }, /* test_validator */ + { "Quince", DT_COMMAND, 0, &VarQuince, IP "/quince", validator_warn }, + { "Raspberry", DT_COMMAND, 0, &VarRaspberry, IP "/raspberry", validator_fail }, + { "Strawberry", DT_COMMAND, 0, &VarStrawberry, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %s\n", VarApple); + printf("Banana = %s\n", VarBanana); + + if ((mutt_str_strcmp(VarApple, "/apple") != 0) || + (mutt_str_strcmp(VarBanana, "/banana") != 0)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "/etc", err); + cs_str_string_set(cs, "Banana", NULL, err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "/apple") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = '%s'\n", VarApple); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "/banana") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = '%s'\n", VarBanana); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "/tmp", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "/usr", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello", "world", "world", "", NULL }; + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarDamson, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarDamson), NONULL(valid[i])); + } + + name = "Fig"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + name = "Elderberry"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarElderberry, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarElderberry), NONULL(valid[i])); + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Guava"; + + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarGuava), err->data); + + name = "Hawthorn"; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarHawthorn), err->data); + + name = "Ilama"; + rc = cs_str_string_set(cs, name, "ilama", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarIlama), err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello", "world", "world", "", NULL }; + char *name = "Jackfruit"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarJackfruit, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarJackfruit), NONULL(valid[i])); + } + + name = "Lemon"; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) "", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + name = "Kumquat"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarKumquat, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarKumquat), NONULL(valid[i])); + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Mango"; + + int rc = cs_str_string_set(cs, name, "mango", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (mutt_str_strcmp(VarMango, (char *) value) != 0) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, VarMango, (char *) value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Nectarine"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarNectarine); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarNectarine); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarNectarine, "/nectarine") != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarNectarine); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + name = "Olive"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarOlive); + dont_fail = true; + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarOlive); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarOlive, "hello") != 0) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarOlive); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Papaya"; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Command: %s = %s\n", name, VarPapaya); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarPapaya); + + name = "Quince"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Command: %s = %s\n", name, VarQuince); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarQuince); + + name = "Raspberry"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Command: %s = %s\n", name, VarRaspberry); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarRaspberry); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %s\n", parent, (char *) pval); + printf("%15s = %s\n", child, (char *) cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Strawberry"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "world", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool command_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + command_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/command.h b/test/config/command.h new file mode 100644 index 000000000..a1925fa0b --- /dev/null +++ b/test/config/command.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Command object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_COMMAND_H +#define _TEST_COMMAND_H + +#include + +bool command_test(void); + +#endif /* _TEST_COMMAND_H */ diff --git a/test/config/command.txt b/test/config/command.txt new file mode 100644 index 000000000..8d01cbb98 --- /dev/null +++ b/test/config/command.txt @@ -0,0 +1,119 @@ +---- command_test ------------------------------------------ +---- set_list ---------------------------------------------- +command Apple = /apple +command Banana = /banana +command Cherry = /cherry +command Damson = +command Elderberry = /elderberry +command Fig = fig +command Guava = +command Hawthorn = /hawthorn +command Ilama = +command Jackfruit = +command Kumquat = /kumquat +command Lemon = lemon +command Mango = +command Nectarine = /nectarine +command Olive = /olive +command Papaya = /papaya +command Quince = /quince +command Raspberry = /raspberry +command Strawberry = +---- test_initial_values ----------------------------------- +Apple = /apple +Banana = /banana +Event: Apple has been set to '/etc' +Event: Banana has been set to '' +Apple = '/etc' +Apple's initial value is '/apple' +Banana = '(null)' +Banana's initial value is '/banana' +Event: Cherry has been initial-set to '/tmp' +Event: Cherry has been initial-set to '/usr' +Cherry = '/cherry' +Cherry's initial value is '/usr' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'hello' +Damson = 'hello', set by 'hello' +Event: Damson has been set to 'world' +Damson = 'world', set by 'world' +Value of Damson wasn't changed +Event: Damson has been set to '' +Damson = '', set by '' +Value of Damson wasn't changed +Expected error: Option Fig may not be empty +Event: Elderberry has been set to 'hello' +Elderberry = 'hello', set by 'hello' +Event: Elderberry has been set to 'world' +Elderberry = 'world', set by 'world' +Value of Elderberry wasn't changed +Event: Elderberry has been set to '' +Elderberry = '', set by '' +Value of Elderberry wasn't changed +---- test_string_get --------------------------------------- +Guava = '', '' +Hawthorn = '/hawthorn', '/hawthorn' +Event: Ilama has been set to 'ilama' +Ilama = 'ilama', 'ilama' +---- test_native_set --------------------------------------- +Event: Jackfruit has been set to 'hello' +Jackfruit = 'hello', set by 'hello' +Event: Jackfruit has been set to 'world' +Jackfruit = 'world', set by 'world' +Value of Jackfruit wasn't changed +Event: Jackfruit has been set to '' +Jackfruit = '', set by '' +Value of Jackfruit wasn't changed +Expected error: Option Lemon may not be empty +Event: Kumquat has been set to 'hello' +Kumquat = 'hello', set by 'hello' +Event: Kumquat has been set to 'world' +Kumquat = 'world', set by 'world' +Value of Kumquat wasn't changed +Event: Kumquat has been set to '' +Kumquat = '', set by '' +Value of Kumquat wasn't changed +---- test_native_get --------------------------------------- +Event: Mango has been set to 'mango' +Mango = 'mango', 'mango' +---- test_reset -------------------------------------------- +Initial: Nectarine = '/nectarine' +Event: Nectarine has been set to 'hello' +Set: Nectarine = 'hello' +Event: Nectarine has been reset to '/nectarine' +Reset: Nectarine = '/nectarine' +Initial: Olive = '/olive' +Event: Olive has been set to 'hello' +Set: Olive = 'hello' +Expected error: validator_fail: Olive, (ptr) +Reset: Olive = 'hello' +---- test_validator ---------------------------------------- +Event: Papaya has been set to 'hello' +validator_succeed: Papaya, (ptr) +Command: Papaya = hello +Event: Papaya has been set to 'world' +validator_succeed: Papaya, (ptr) +Native: Papaya = world +Event: Quince has been set to 'hello' +validator_warn: Quince, (ptr) +Command: Quince = hello +Event: Quince has been set to 'world' +validator_warn: Quince, (ptr) +Native: Quince = world +Expected error: validator_fail: Raspberry, (ptr) +Command: Raspberry = /raspberry +Expected error: validator_fail: Raspberry, (ptr) +Native: Raspberry = /raspberry +---- test_inherit ------------------------------------------ +Event: Strawberry has been set to 'hello' + Strawberry = hello +fruit:Strawberry = hello +Event: fruit:Strawberry has been set to 'world' + Strawberry = hello +fruit:Strawberry = world +Event: fruit:Strawberry has been reset to 'hello' + Strawberry = hello +fruit:Strawberry = hello +Event: Strawberry has been reset to '' + Strawberry = (null) +fruit:Strawberry = (null) diff --git a/test/config/common.c b/test/config/common.c new file mode 100644 index 000000000..5ac788363 --- /dev/null +++ b/test/config/common.c @@ -0,0 +1,218 @@ +/** + * @file + * Shared Testing Code + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/hash.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/inheritance.h" +#include "config/set.h" +#include "config/types.h" +#include "common.h" + +const char *line = "----------------------------------------" + "----------------------------------------"; + +bool dont_fail = false; + +int validator_fail(const struct ConfigSet *cs, const struct ConfigDef *cdef, + intptr_t value, struct Buffer *result) +{ + if (dont_fail) + return CSR_SUCCESS; + + if (value > 1000000) + mutt_buffer_printf(result, "%s: %s, (ptr)", __func__, cdef->name); + else + mutt_buffer_printf(result, "%s: %s, %ld", __func__, cdef->name, value); + return CSR_ERR_INVALID; +} + +int validator_warn(const struct ConfigSet *cs, const struct ConfigDef *cdef, + intptr_t value, struct Buffer *result) +{ + if (value > 1000000) + mutt_buffer_printf(result, "%s: %s, (ptr)", __func__, cdef->name); + else + mutt_buffer_printf(result, "%s: %s, %ld", __func__, cdef->name, value); + return CSR_SUCCESS | CSR_SUC_WARNING; +} + +int validator_succeed(const struct ConfigSet *cs, const struct ConfigDef *cdef, + intptr_t value, struct Buffer *result) +{ + if (value > 1000000) + mutt_buffer_printf(result, "%s: %s, (ptr)", __func__, cdef->name); + else + mutt_buffer_printf(result, "%s: %s, %ld", __func__, cdef->name, value); + return CSR_SUCCESS; +} + +void log_line(const char *fn) +{ + int len = 54 - mutt_str_strlen(fn); + printf("---- %s %.*s\n", fn, len, line); +} + +bool log_listener(const struct ConfigSet *cs, struct HashElem *he, + const char *name, enum ConfigEvent ev) +{ + struct Buffer result; + mutt_buffer_init(&result); + result.data = mutt_mem_calloc(1, STRING); + result.dsize = STRING; + + const char *events[] = { "set", "reset", "initial-set" }; + + mutt_buffer_reset(&result); + + if (ev != CE_INITIAL_SET) + cs_he_string_get(cs, he, &result); + else + cs_he_initial_get(cs, he, &result); + + printf("Event: %s has been %s to '%s'\n", name, events[ev - 1], result.data); + + FREE(&result.data); + return true; +} + +void set_list(const struct ConfigSet *cs) +{ + log_line(__func__); + cs_dump_set(cs); + // hash_dump(cs->hash); +} + +void hash_dump(struct Hash *table) +{ + if (!table) + return; + + struct HashElem *he = NULL; + + for (int i = 0; i < table->nelem; i++) + { + he = table->table[i]; + if (!he) + continue; + + if (he->type == DT_SYNONYM) + continue; + + printf("%03d ", i); + for (; he; he = he->next) + { + if (he->type & DT_INHERITED) + { + struct Inheritance *inh = he->data; + printf("\033[1;32m[%s]\033[m ", inh->name); + } + else + { + printf("%s ", *(char **) he->data); + } + } + printf("\n"); + } +} + +int sort_list_cb(const void *a, const void *b) +{ + const char *stra = *(char **) a; + const char *strb = *(char **) b; + return strcmp(stra, strb); +} + +void cs_dump_set(const struct ConfigSet *cs) +{ + if (!cs) + return; + + struct HashElem *he = NULL; + struct HashWalkState state; + memset(&state, 0, sizeof(state)); + + struct Buffer result; + mutt_buffer_init(&result); + result.data = mutt_mem_calloc(1, STRING); + result.dsize = STRING; + + char tmp[128]; + char *list[26] = { 0 }; + size_t index = 0; + size_t i = 0; + + for (i = 0; (he = mutt_hash_walk(cs->hash, &state)); i++) + { + if (he->type == DT_SYNONYM) + continue; + + const char *name = NULL; + + if (he->type & DT_INHERITED) + { + struct Inheritance *inh = he->data; + he = inh->parent; + name = inh->name; + } + else + { + name = he->key.strkey; + } + + const struct ConfigSetType *cst = cs_get_type_def(cs, he->type); + if (!cst) + { + snprintf(tmp, sizeof(tmp), "Unknown type: %d", he->type); + list[index] = mutt_str_strdup(tmp); + index++; + continue; + } + + mutt_buffer_reset(&result); + const struct ConfigDef *cdef = he->data; + + int rc = cst->string_get(cs, cdef->var, cdef, &result); + if (CSR_RESULT(rc) == CSR_SUCCESS) + snprintf(tmp, sizeof(tmp), "%s %s = %s", cst->name, name, result.data); + else + snprintf(tmp, sizeof(tmp), "%s %s: ERROR: %s", cst->name, name, result.data); + list[index] = mutt_str_strdup(tmp); + index++; + } + + qsort(list, index, sizeof(list[0]), sort_list_cb); + for (i = 0; list[i]; i++) + { + puts(list[i]); + FREE(&list[i]); + } + + FREE(&result.data); +} diff --git a/test/config/common.h b/test/config/common.h new file mode 100644 index 000000000..4549719d1 --- /dev/null +++ b/test/config/common.h @@ -0,0 +1,52 @@ +/** + * @file + * Shared Testing Code + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_COMMON_H +#define _TEST_COMMON_H + +#include +#include +#include "config/set.h" + +struct Buffer; +struct Hash; +struct HashElem; + +extern const char *line; +extern bool dont_fail; + +int validator_succeed(const struct ConfigSet *cs, const struct ConfigDef *cdef, + intptr_t value, struct Buffer *result); +int validator_warn(const struct ConfigSet *cs, const struct ConfigDef *cdef, + intptr_t value, struct Buffer *result); +int validator_fail(const struct ConfigSet *cs, const struct ConfigDef *cdef, + intptr_t value, struct Buffer *result); + +void log_line(const char *fn); +bool log_listener(const struct ConfigSet *cs, struct HashElem *he, + const char *name, enum ConfigEvent ev); +void set_list(const struct ConfigSet *cs); + +void hash_dump(struct Hash *table); +void cs_dump_set(const struct ConfigSet *cs); + +#endif /* _TEST_COMMON_H */ diff --git a/test/config/dump/data.c b/test/config/dump/data.c new file mode 100644 index 000000000..d7632eaba --- /dev/null +++ b/test/config/dump/data.c @@ -0,0 +1,4289 @@ +/** + * @file + * Test Data for config dumping + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include "mutt/regex3.h" +#include "config/magic.h" +#include "config/quad.h" +#include "config/regex2.h" +#include "config/set.h" +#include "config/sort.h" +#include "config/types.h" +#include "data.h" +#include "vars.h" + +#define ISPELL "ispell" +#define MIXMASTER "mixmaster" + +// clang-format off +struct ConfigDef MuttVars[] = { + /*++*/ + + { "abort_noattach", DT_QUAD, R_NONE, &AbortNoattach, MUTT_NO }, + /* + ** .pp + ** If set to \fIyes\fP, when composing messages containing the regular expression + ** specified by $attach_keyword and no attachments ** are given, composition + ** will be aborted. If set to \fIno\fP, composing ** messages as such will never + ** be aborted. + ** .pp + ** Example: + ** .ts + ** set attach_keyword = "\\" + ** .te + */ + { "abort_nosubject", DT_QUAD, R_NONE, &AbortNosubject, MUTT_ASKYES }, + /* + ** .pp + ** If set to \fIyes\fP, when composing messages and no subject is given + ** at the subject prompt, composition will be aborted. If set to + ** \fIno\fP, composing messages with no subject given at the subject + ** prompt will never be aborted. + */ + { "abort_unmodified", DT_QUAD, R_NONE, &AbortUnmodified, MUTT_YES }, + /* + ** .pp + ** If set to \fIyes\fP, composition will automatically abort after + ** editing the message body if no changes are made to the file (this + ** check only happens after the \fIfirst\fP edit of the file). When set + ** to \fIno\fP, composition will never be aborted. + */ + { "alias_file", DT_PATH, R_NONE, &AliasFile, IP "~/.neomuttrc" }, + /* + ** .pp + ** The default file in which to save aliases created by the + ** \fC$\fP function. Entries added to this file are + ** encoded in the character set specified by $$config_charset if it + ** is \fIset\fP or the current character set otherwise. + ** .pp + ** \fBNote:\fP NeoMutt will not automatically source this file; you must + ** explicitly use the ``$source'' command for it to be executed in case + ** this option points to a dedicated alias file. + ** .pp + ** The default for this option is the currently used neomuttrc file, or + ** ``~/.neomuttrc'' if no user neomuttrc was found. + */ + { "alias_format", DT_STRING, R_NONE, &AliasFormat, IP "%4n %2f %t %-10a %r" }, + /* + ** .pp + ** Specifies the format of the data displayed for the ``$alias'' menu. The + ** following \fCprintf(3)\fP-style sequences are available: + ** .dl + ** .dt %a .dd Alias name + ** .dt %f .dd Flags - currently, a ``d'' for an alias marked for deletion + ** .dt %n .dd Index number + ** .dt %r .dd Address which alias expands to + ** .dt %t .dd Character which indicates if the alias is tagged for inclusion + ** .de + */ + { "allow_8bit", DT_BOOL, R_NONE, &Allow8bit, 1 }, + /* + ** .pp + ** Controls whether 8-bit data is converted to 7-bit using either Quoted- + ** Printable or Base64 encoding when sending mail. + */ + { "allow_ansi", DT_BOOL, R_NONE, &AllowAnsi, 0 }, + /* + ** .pp + ** Controls whether ANSI color codes in messages (and color tags in + ** rich text messages) are to be interpreted. + ** Messages containing these codes are rare, but if this option is \fIset\fP, + ** their text will be colored accordingly. Note that this may override + ** your color choices, and even present a security problem, since a + ** message could include a line like + ** .ts + ** [-- PGP output follows ... + ** .te + ** .pp + ** and give it the same color as your attachment color (see also + ** $$crypt_timestamp). + */ + { "arrow_cursor", DT_BOOL, R_MENU, &ArrowCursor, 0 }, + /* + ** .pp + ** When \fIset\fP, an arrow (``->'') will be used to indicate the current entry + ** in menus instead of highlighting the whole line. On slow network or modem + ** links this will make response faster because there is less that has to + ** be redrawn on the screen when moving to the next or previous entries + ** in the menu. + */ + { "ascii_chars", DT_BOOL, R_BOTH, &AsciiChars, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will use plain ASCII characters when displaying thread + ** and attachment trees, instead of the default \fIACS\fP characters. + */ + { "askbcc", DT_BOOL, R_NONE, &Askbcc, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will prompt you for blind-carbon-copy (Bcc) recipients + ** before editing an outgoing message. + */ + { "askcc", DT_BOOL, R_NONE, &Askcc, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will prompt you for carbon-copy (Cc) recipients before + ** editing the body of an outgoing message. + */ + { "ask_follow_up", DT_BOOL, R_NONE, &AskFollowUp, 0 }, + /* + ** .pp + ** If set, NeoMutt will prompt you for follow-up groups before editing + ** the body of an outgoing message. + */ + { "ask_x_comment_to", DT_BOOL, R_NONE, &AskXCommentTo, 0 }, + /* + ** .pp + ** If set, NeoMutt will prompt you for x-comment-to field before editing + ** the body of an outgoing message. + */ + { "assumed_charset", DT_STRING, R_NONE, &AssumedCharset, 0 }, + /* + ** .pp + ** This variable is a colon-separated list of character encoding + ** schemes for messages without character encoding indication. + ** Header field values and message body content without character encoding + ** indication would be assumed that they are written in one of this list. + ** By default, all the header fields and message body without any charset + ** indication are assumed to be in ``us-ascii''. + ** .pp + ** For example, Japanese users might prefer this: + ** .ts + ** set assumed_charset="iso-2022-jp:euc-jp:shift_jis:utf-8" + ** .te + ** .pp + ** However, only the first content is valid for the message body. + */ + { "attach_charset", DT_STRING, R_NONE, &AttachCharset, 0 }, + /* + ** .pp + ** This variable is a colon-separated list of character encoding + ** schemes for text file attachments. NeoMutt uses this setting to guess + ** which encoding files being attached are encoded in to convert them to + ** a proper character set given in $$send_charset. + ** .pp + ** If \fIunset\fP, the value of $$charset will be used instead. + ** For example, the following configuration would work for Japanese + ** text handling: + ** .ts + ** set attach_charset="iso-2022-jp:euc-jp:shift_jis:utf-8" + ** .te + ** .pp + ** Note: for Japanese users, ``iso-2022-*'' must be put at the head + ** of the value as shown above if included. + */ + { "attach_format", DT_STRING, R_NONE, &AttachFormat, IP "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " }, + /* + ** .pp + ** This variable describes the format of the ``attachment'' menu. The + ** following \fCprintf(3)\fP-style sequences are understood: + ** .dl + ** .dt %C .dd Charset + ** .dt %c .dd Requires charset conversion (``n'' or ``c'') + ** .dt %D .dd Deleted flag + ** .dt %d .dd Description (if none, falls back to %F) + ** .dt %e .dd MIME content-transfer-encoding + ** .dt %f .dd Filename + ** .dt %F .dd Filename in content-disposition header (if none, falls back to %f) + ** .dt %I .dd Disposition (``I'' for inline, ``A'' for attachment) + ** .dt %m .dd Major MIME type + ** .dt %M .dd MIME subtype + ** .dt %n .dd Attachment number + ** .dt %Q .dd ``Q'', if MIME part qualifies for attachment counting + ** .dt %s .dd Size + ** .dt %T .dd Graphic tree characters + ** .dt %t .dd Tagged flag + ** .dt %u .dd Unlink (=to delete) flag + ** .dt %X .dd Number of qualifying MIME parts in this part and its children + ** (please see the ``$attachments'' section for possible speed effects) + ** .dt %>X .dd Right justify the rest of the string and pad with character ``X'' + ** .dt %|X .dd Pad to the end of the line with character ``X'' + ** .dt %*X .dd Soft-fill with character ``X'' as pad + ** .de + ** .pp + ** For an explanation of ``soft-fill'', see the $$index_format documentation. + */ + { "attach_keyword", DT_REGEX, R_NONE, &AttachKeyword, IP "\\<(attach|attached|attachments?)\\>" }, + /* + ** .pp + ** If $abort_noattach is not set to no, then the body of the message + ** will be scanned for this regular expression, and if found, you will + ** be prompted if there are no attachments. + */ + { "attach_sep", DT_STRING, R_NONE, &AttachSep, IP "\n" }, + /* + ** .pp + ** The separator to add between attachments when operating (saving, + ** printing, piping, etc) on a list of tagged attachments. + */ + { "attach_split", DT_BOOL, R_NONE, &AttachSplit, 1 }, + /* + ** .pp + ** If this variable is \fIunset\fP, when operating (saving, printing, piping, + ** etc) on a list of tagged attachments, NeoMutt will concatenate the + ** attachments and will operate on them as a single attachment. The + ** $$attach_sep separator is added after each attachment. When \fIset\fP, + ** NeoMutt will operate on the attachments one by one. + */ + { "attribution", DT_STRING, R_NONE, &Attribution, IP "On %d, %n wrote:" }, + /* + ** .pp + ** This is the string that will precede a message which has been included + ** in a reply. For a full listing of defined \fCprintf(3)\fP-like sequences see + ** the section on $$index_format. + */ + { "attribution_locale", DT_STRING, R_NONE, &AttributionLocale, IP "" }, + /* + ** .pp + ** The locale used by \fCstrftime(3)\fP to format dates in the + ** $attribution string. Legal values are the strings your system + ** accepts for the locale environment variable \fC$$$LC_TIME\fP. + ** .pp + ** This variable is to allow the attribution date format to be + ** customized by recipient or folder using hooks. By default, NeoMutt + ** will use your locale environment, so there is no need to set + ** this except to override that default. + */ + { "auto_tag", DT_BOOL, R_NONE, &AutoTag, 0 }, + /* + ** .pp + ** When \fIset\fP, functions in the \fIindex\fP menu which affect a message + ** will be applied to all tagged messages (if there are any). When + ** unset, you must first use the \fC\fP function (bound to ``;'' + ** by default) to make the next function apply to all tagged messages. + */ + { "autoedit", DT_BOOL, R_NONE, &Autoedit, 0 }, + /* + ** .pp + ** When \fIset\fP along with $$edit_headers, NeoMutt will skip the initial + ** send-menu (prompting for subject and recipients) and allow you to + ** immediately begin editing the body of your + ** message. The send-menu may still be accessed once you have finished + ** editing the body of your message. + ** .pp + ** \fBNote:\fP when this option is \fIset\fP, you cannot use send-hooks that depend + ** on the recipients when composing a new (non-reply) message, as the initial + ** list of recipients is empty. + ** .pp + ** Also see $$fast_reply. + */ + { "beep", DT_BOOL, R_NONE, &Beep, 1 }, + /* + ** .pp + ** When this variable is \fIset\fP, NeoMutt will beep when an error occurs. + */ + { "beep_new", DT_BOOL, R_NONE, &BeepNew, 0 }, + /* + ** .pp + ** When this variable is \fIset\fP, NeoMutt will beep whenever it prints a message + ** notifying you of new mail. This is independent of the setting of the + ** $$beep variable. + */ + { "bounce", DT_QUAD, R_NONE, &Bounce, MUTT_ASKYES }, + /* + ** .pp + ** Controls whether you will be asked to confirm bouncing messages. + ** If set to \fIyes\fP you don't get asked if you want to bounce a + ** message. Setting this variable to \fIno\fP is not generally useful, + ** and thus not recommended, because you are unable to bounce messages. + */ + { "bounce_delivered", DT_BOOL, R_NONE, &BounceDelivered, 1 }, + /* + ** .pp + ** When this variable is \fIset\fP, NeoMutt will include Delivered-To headers when + ** bouncing messages. Postfix users may wish to \fIunset\fP this variable. + */ + { "braille_friendly", DT_BOOL, R_NONE, &BrailleFriendly, 0 }, + /* + ** .pp + ** When this variable is \fIset\fP, NeoMutt will place the cursor at the beginning + ** of the current line in menus, even when the $$arrow_cursor variable + ** is \fIunset\fP, making it easier for blind persons using Braille displays to + ** follow these menus. The option is \fIunset\fP by default because many + ** visual terminals don't permit making the cursor invisible. + */ + { "catchup_newsgroup", DT_QUAD, R_NONE, &CatchupNewsgroup, MUTT_ASKYES }, + /* + ** .pp + ** If this variable is \fIset\fP, NeoMutt will mark all articles in newsgroup + ** as read when you quit the newsgroup (catchup newsgroup). + */ + { "certificate_file", DT_PATH, R_NONE, &CertificateFile, IP "~/.mutt_certificates" }, + /* + ** .pp + ** This variable specifies the file where the certificates you trust + ** are saved. When an unknown certificate is encountered, you are asked + ** if you accept it or not. If you accept it, the certificate can also + ** be saved in this file and further connections are automatically + ** accepted. + ** .pp + ** You can also manually add CA certificates in this file. Any server + ** certificate that is signed with one of these CA certificates is + ** also automatically accepted. + ** .pp + ** Example: + ** .ts + ** set certificate_file=~/.neomutt/certificates + ** .te + ** + */ + { "change_folder_next", DT_BOOL, R_NONE, &ChangeFolderNext, 0 }, + /* + ** .pp + ** When this variable is \fIset\fP, the \fC\fP function + ** mailbox suggestion will start at the next folder in your ``$mailboxes'' + ** list, instead of starting at the first folder in the list. + */ + { "charset", DT_STRING, R_NONE, &Charset, 0 }, + /* + ** .pp + ** Character set your terminal uses to display and enter textual data. + ** It is also the fallback for $$send_charset. + ** .pp + ** Upon startup NeoMutt tries to derive this value from environment variables + ** such as \fC$$$LC_CTYPE\fP or \fC$$$LANG\fP. + ** .pp + ** \fBNote:\fP It should only be set in case NeoMutt isn't able to determine the + ** character set used correctly. + */ + { "check_mbox_size", DT_BOOL, R_NONE, &CheckMboxSize, 0 }, + /* + ** .pp + ** When this variable is \fIset\fP, NeoMutt will use file size attribute instead of + ** access time when checking for new mail in mbox and mmdf folders. + ** .pp + ** This variable is \fIunset\fP by default and should only be enabled when + ** new mail detection for these folder types is unreliable or doesn't work. + ** .pp + ** Note that enabling this variable should happen before any ``$mailboxes'' + ** directives occur in configuration files regarding mbox or mmdf folders + ** because NeoMutt needs to determine the initial new mail status of such a + ** mailbox by performing a fast mailbox scan when it is defined. + ** Afterwards the new mail status is tracked by file size changes. + */ + { "check_new", DT_BOOL, R_NONE, &CheckNew, 1 }, + /* + ** .pp + ** \fBNote:\fP this option only affects \fImaildir\fP and \fIMH\fP style + ** mailboxes. + ** .pp + ** When \fIset\fP, NeoMutt will check for new mail delivered while the + ** mailbox is open. Especially with MH mailboxes, this operation can + ** take quite some time since it involves scanning the directory and + ** checking each file to see if it has already been looked at. If + ** this variable is \fIunset\fP, no check for new mail is performed + ** while the mailbox is open. + */ + { "collapse_unread", DT_BOOL, R_NONE, &CollapseUnread, 1 }, + /* + ** .pp + ** When \fIunset\fP, NeoMutt will not collapse a thread if it contains any + ** unread messages. + */ + { "collapse_flagged", DT_BOOL, R_NONE, &CollapseFlagged, 1 }, + /* + ** .pp + ** When \fIunset\fP, NeoMutt will not collapse a thread if it contains any + ** flagged messages. + */ + { "compose_format", DT_STRING, R_MENU, &ComposeFormat, IP "-- NeoMutt: Compose [Approx. msg size: %l Atts: %a]%>-" }, + /* + ** .pp + ** Controls the format of the status line displayed in the ``compose'' + ** menu. This string is similar to $$status_format, but has its own + ** set of \fCprintf(3)\fP-like sequences: + ** .dl + ** .dt %a .dd Total number of attachments + ** .dt %h .dd Local hostname + ** .dt %l .dd Approximate size (in bytes) of the current message + ** .dt %v .dd NeoMutt version string + ** .de + ** .pp + ** See the text describing the $$status_format option for more + ** information on how to set $$compose_format. + */ + { "config_charset", DT_STRING, R_NONE, &ConfigCharset, 0 }, + /* + ** .pp + ** When defined, NeoMutt will recode commands in rc files from this + ** encoding to the current character set as specified by $$charset + ** and aliases written to $$alias_file from the current character set. + ** .pp + ** Please note that if setting $$charset it must be done before + ** setting $$config_charset. + ** .pp + ** Recoding should be avoided as it may render unconvertable + ** characters as question marks which can lead to undesired + ** side effects (for example in regular expressions). + */ + { "confirmappend", DT_BOOL, R_NONE, &Confirmappend, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will prompt for confirmation when appending messages to + ** an existing mailbox. + */ + { "confirmcreate", DT_BOOL, R_NONE, &Confirmcreate, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will prompt for confirmation when saving messages to a + ** mailbox which does not yet exist before creating it. + */ + { "connect_timeout", DT_NUMBER, R_NONE, &ConnectTimeout, 30 }, + /* + ** .pp + ** Causes NeoMutt to timeout a network connection (for IMAP, POP or SMTP) after this + ** many seconds if the connection is not able to be established. A negative + ** value causes NeoMutt to wait indefinitely for the connection attempt to succeed. + */ + { "content_type", DT_STRING, R_NONE, &ContentType, IP "text/plain" }, + /* + ** .pp + ** Sets the default Content-Type for the body of newly composed messages. + */ + { "copy", DT_QUAD, R_NONE, &Copy, MUTT_YES }, + /* + ** .pp + ** This variable controls whether or not copies of your outgoing messages + ** will be saved for later references. Also see $$record, + ** $$save_name, $$force_name and ``$fcc-hook''. + */ + { "crypt_autoencrypt", DT_BOOL, R_NONE, &CryptAutoencrypt, 0 }, + /* + ** .pp + ** Setting this variable will cause NeoMutt to always attempt to PGP + ** encrypt outgoing messages. This is probably only useful in + ** connection to the ``$send-hook'' command. It can be overridden + ** by use of the pgp menu, when encryption is not required or + ** signing is requested as well. If $$smime_is_default is \fIset\fP, + ** then OpenSSL is used instead to create S/MIME messages and + ** settings can be overridden by use of the smime menu instead. + ** (Crypto only) + */ + { "crypt_autopgp", DT_BOOL, R_NONE, &CryptAutopgp, 1 }, + /* + ** .pp + ** This variable controls whether or not NeoMutt may automatically enable + ** PGP encryption/signing for messages. See also $$crypt_autoencrypt, + ** $$crypt_replyencrypt, + ** $$crypt_autosign, $$crypt_replysign and $$smime_is_default. + */ + { "crypt_autosign", DT_BOOL, R_NONE, &CryptAutosign, 0 }, + /* + ** .pp + ** Setting this variable will cause NeoMutt to always attempt to + ** cryptographically sign outgoing messages. This can be overridden + ** by use of the pgp menu, when signing is not required or + ** encryption is requested as well. If $$smime_is_default is \fIset\fP, + ** then OpenSSL is used instead to create S/MIME messages and settings can + ** be overridden by use of the smime menu instead of the pgp menu. + ** (Crypto only) + */ + { "crypt_autosmime", DT_BOOL, R_NONE, &CryptAutosmime, 1 }, + /* + ** .pp + ** This variable controls whether or not NeoMutt may automatically enable + ** S/MIME encryption/signing for messages. See also $$crypt_autoencrypt, + ** $$crypt_replyencrypt, + ** $$crypt_autosign, $$crypt_replysign and $$smime_is_default. + */ + { "crypt_confirmhook", DT_BOOL, R_NONE, &CryptConfirmhook, 1 }, + /* + ** .pp + ** If set, then you will be prompted for confirmation of keys when using + ** the \fIcrypt-hook\fP command. If unset, no such confirmation prompt will + ** be presented. This is generally considered unsafe, especially where + ** typos are concerned. + */ + { "crypt_opportunistic_encrypt", DT_BOOL, R_NONE, &CryptOpportunisticEncrypt, 0 }, + /* + ** .pp + ** Setting this variable will cause NeoMutt to automatically enable and + ** disable encryption, based on whether all message recipient keys + ** can be located by NeoMutt. + ** .pp + ** When this option is enabled, NeoMutt will enable/disable encryption + ** each time the TO, CC, and BCC lists are edited. If + ** $$edit_headers is set, NeoMutt will also do so each time the message + ** is edited. + ** .pp + ** While this is set, encryption can't be manually enabled/disabled. + ** The pgp or smime menus provide a selection to temporarily disable + ** this option for the current message. + ** .pp + ** If $$crypt_autoencrypt or $$crypt_replyencrypt enable encryption for + ** a message, this option will be disabled for that message. It can + ** be manually re-enabled in the pgp or smime menus. + ** (Crypto only) + */ + { "crypt_replyencrypt", DT_BOOL, R_NONE, &CryptReplyencrypt, 1 }, + /* + ** .pp + ** If \fIset\fP, automatically PGP or OpenSSL encrypt replies to messages which are + ** encrypted. + ** (Crypto only) + */ + { "crypt_replysign", DT_BOOL, R_NONE, &CryptReplysign, 0 }, + /* + ** .pp + ** If \fIset\fP, automatically PGP or OpenSSL sign replies to messages which are + ** signed. + ** .pp + ** \fBNote:\fP this does not work on messages that are encrypted + ** \fIand\fP signed! + ** (Crypto only) + */ + { "crypt_replysignencrypted", DT_BOOL, R_NONE, &CryptReplysignencrypted, 0 }, + /* + ** .pp + ** If \fIset\fP, automatically PGP or OpenSSL sign replies to messages + ** which are encrypted. This makes sense in combination with + ** $$crypt_replyencrypt, because it allows you to sign all + ** messages which are automatically encrypted. This works around + ** the problem noted in $$crypt_replysign, that NeoMutt is not able + ** to find out whether an encrypted message is also signed. + ** (Crypto only) + */ + { "crypt_timestamp", DT_BOOL, R_NONE, &CryptTimestamp, 1 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will include a time stamp in the lines surrounding + ** PGP or S/MIME output, so spoofing such lines is more difficult. + ** If you are using colors to mark these lines, and rely on these, + ** you may \fIunset\fP this setting. + ** (Crypto only) + */ + { "crypt_use_gpgme", DT_BOOL, R_NONE, &CryptUseGpgme, 0 }, + /* + ** .pp + ** This variable controls the use of the GPGME-enabled crypto backends. + ** If it is \fIset\fP and NeoMutt was built with gpgme support, the gpgme code for + ** S/MIME and PGP will be used instead of the classic code. Note that + ** you need to set this option in .neomuttrc; it won't have any effect when + ** used interactively. + ** .pp + ** Note that the GPGME backend does not support creating old-style inline + ** (traditional) PGP encrypted or signed messages (see $$pgp_autoinline). + */ + { "crypt_use_pka", DT_BOOL, R_NONE, &CryptUsePka, 0 }, + /* + ** .pp + ** Controls whether NeoMutt uses PKA + ** (see http://www.g10code.de/docs/pka-intro.de.pdf) during signature + ** verification (only supported by the GPGME backend). + */ + { "crypt_verify_sig", DT_QUAD, R_NONE, &CryptVerifySig, MUTT_YES }, + /* + ** .pp + ** If \fI``yes''\fP, always attempt to verify PGP or S/MIME signatures. + ** If \fI``ask-*''\fP, ask whether or not to verify the signature. + ** If \fI``no''\fP, never attempt to verify cryptographic signatures. + ** (Crypto only) + */ + { "date_format", DT_STRING, R_MENU, &DateFormat, IP "!%a, %b %d, %Y at %I:%M:%S%p %Z" }, + /* + ** .pp + ** This variable controls the format of the date printed by the ``%d'' + ** sequence in $$index_format. This is passed to the \fCstrftime(3)\fP + ** function to process the date, see the man page for the proper syntax. + ** .pp + ** Unless the first character in the string is a bang (``!''), the month + ** and week day names are expanded according to the locale. + ** If the first character in the string is a + ** bang, the bang is discarded, and the month and week day names in the + ** rest of the string are expanded in the \fIC\fP locale (that is in US + ** English). + */ + { "debug_level", DT_NUMBER, R_NONE, &DebugLevel, 0 }, + /* + ** .pp + ** The debug level. Note: to debug the early startup process (before the + ** configuration is loaded), ``-d'' neomutt argument must be used. + ** debug_level/debug_file are ignored until it's read from the configuration + ** file. + */ + { "debug_file", DT_PATH, R_NONE, &DebugFile, IP "~/.neomuttdebug" }, + /* + ** .pp + ** The location prefix of the debug file, 0 is append to the debug file + ** Old debug files are renamed with the prefix 1, 2, 3 and 4. + ** See ``debug_level'' for more detail. + */ + { "default_hook", DT_STRING, R_NONE, &DefaultHook, IP "~f %s !~P | (~P ~C %s)" }, + /* + ** .pp + ** This variable controls how ``$message-hook'', ``$reply-hook'', ``$send-hook'', + ** ``$send2-hook'', ``$save-hook'', and ``$fcc-hook'' will + ** be interpreted if they are specified with only a simple regex, + ** instead of a matching pattern. The hooks are expanded when they are + ** declared, so a hook will be interpreted according to the value of this + ** variable at the time the hook is declared. + ** .pp + ** The default value matches + ** if the message is either from a user matching the regular expression + ** given, or if it is from you (if the from address matches + ** ``$alternates'') and is to or cc'ed to a user matching the given + ** regular expression. + */ + { "delete", DT_QUAD, R_NONE, &Delete, MUTT_ASKYES }, + /* + ** .pp + ** Controls whether or not messages are really deleted when closing or + ** synchronizing a mailbox. If set to \fIyes\fP, messages marked for + ** deleting will automatically be purged without prompting. If set to + ** \fIno\fP, messages marked for deletion will be kept in the mailbox. + */ + { "delete_untag", DT_BOOL, R_NONE, &DeleteUntag, 1 }, + /* + ** .pp + ** If this option is \fIset\fP, NeoMutt will untag messages when marking them + ** for deletion. This applies when you either explicitly delete a message, + ** or when you save it to another folder. + */ + { "digest_collapse", DT_BOOL, R_NONE, &DigestCollapse, 1 }, + /* + ** .pp + ** If this option is \fIset\fP, NeoMutt's received-attachments menu will not show the subparts of + ** individual messages in a multipart/digest. To see these subparts, press ``v'' on that menu. + */ + { "display_filter", DT_PATH, R_PAGER, &DisplayFilter, IP "" }, + /* + ** .pp + ** When set, specifies a command used to filter messages. When a message + ** is viewed it is passed as standard input to $$display_filter, and the + ** filtered message is read from the standard output. + ** .pp + ** When preparing the message, NeoMutt inserts some escape sequences into the + ** text. They are of the form: \fC]9;XXX\fP where "XXX" is a random + ** 64-bit number. + ** .pp + ** If these escape sequences interfere with your filter, they can be removed + ** using a tool like \fCansifilter\fP or \fCsed 's/^\x1b]9;[0-9]\+\x7//'\fP + ** .pp + ** If they are removed, then PGP and MIME headers will no longer be coloured. + ** This can be fixed by adding this to your config: + ** \fCcolor body magenta default '^\[-- .* --\]$$'\fP. + */ + { "dsn_notify", DT_STRING, R_NONE, &DsnNotify, IP "" }, + /* + ** .pp + ** This variable sets the request for when notification is returned. The + ** string consists of a comma separated list (no spaces!) of one or more + ** of the following: \fInever\fP, to never request notification, + ** \fIfailure\fP, to request notification on transmission failure, + ** \fIdelay\fP, to be notified of message delays, \fIsuccess\fP, to be + ** notified of successful transmission. + ** .pp + ** Example: + ** .ts + ** set dsn_notify="failure,delay" + ** .te + ** .pp + ** \fBNote:\fP when using $$sendmail for delivery, you should not enable + ** this unless you are either using Sendmail 8.8.x or greater or a MTA + ** providing a \fCsendmail(1)\fP-compatible interface supporting the \fC-N\fP option + ** for DSN. For SMTP delivery, DSN support is auto-detected so that it + ** depends on the server whether DSN will be used or not. + */ + { "dsn_return", DT_STRING, R_NONE, &DsnReturn, IP "" }, + /* + ** .pp + ** This variable controls how much of your message is returned in DSN + ** messages. It may be set to either \fIhdrs\fP to return just the + ** message header, or \fIfull\fP to return the full message. + ** .pp + ** Example: + ** .ts + ** set dsn_return=hdrs + ** .te + ** .pp + ** \fBNote:\fP when using $$sendmail for delivery, you should not enable + ** this unless you are either using Sendmail 8.8.x or greater or a MTA + ** providing a \fCsendmail(1)\fP-compatible interface supporting the \fC-R\fP option + ** for DSN. For SMTP delivery, DSN support is auto-detected so that it + ** depends on the server whether DSN will be used or not. + */ + { "duplicate_threads", DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, &DuplicateThreads, 1 }, + /* + ** .pp + ** This variable controls whether NeoMutt, when $$sort is set to \fIthreads\fP, threads + ** messages with the same Message-Id together. If it is \fIset\fP, it will indicate + ** that it thinks they are duplicates of each other with an equals sign + ** in the thread tree. + */ + { "edit_headers", DT_BOOL, R_NONE, &EditHeaders, 0 }, + /* + ** .pp + ** This option allows you to edit the header of your outgoing messages + ** along with the body of your message. + ** .pp + ** Although the compose menu may have localized header labels, the + ** labels passed to your editor will be standard RFC2822 headers, + ** (e.g. To:, Cc:, Subject:). Headers added in your editor must + ** also be RFC2822 headers, or one of the pseudo headers listed in + ** ``$edit-header''. NeoMutt will not understand localized header + ** labels, just as it would not when parsing an actual email. + ** .pp + ** \fBNote\fP that changes made to the References: and Date: headers are + ** ignored for interoperability reasons. + */ + { "editor", DT_PATH, R_NONE, &Editor, 0 }, + /* + ** .pp + ** This variable specifies which editor is used by NeoMutt. + ** It defaults to the value of the \fC$$$VISUAL\fP, or \fC$$$EDITOR\fP, environment + ** variable, or to the string ``vi'' if neither of those are set. + ** .pp + ** The \fC$$editor\fP string may contain a \fI%s\fP escape, which will be replaced by the name + ** of the file to be edited. If the \fI%s\fP escape does not appear in \fC$$editor\fP, a + ** space and the name to be edited are appended. + ** .pp + ** The resulting string is then executed by running + ** .ts + ** sh -c 'string' + ** .te + ** .pp + ** where \fIstring\fP is the expansion of \fC$$editor\fP described above. + */ + { "empty_subject", DT_STRING, R_NONE, &EmptySubject, IP "Re: your mail" }, + /* + ** .pp + ** This variable specifies the subject to be used when replying to an email + ** with an empty subject. It defaults to "Re: your mail". + */ + { "encode_from", DT_BOOL, R_NONE, &EncodeFrom, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will quoted-printable encode messages when + ** they contain the string ``From '' (note the trailing space) in the beginning of a line. + ** This is useful to avoid the tampering certain mail delivery and transport + ** agents tend to do with messages (in order to prevent tools from + ** misinterpreting the line as a mbox message separator). + */ + { "entropy_file", DT_PATH, R_NONE, &EntropyFile, 0 }, + /* + ** .pp + ** The file which includes random data that is used to initialize SSL + ** library functions. + */ + { "envelope_from_address", DT_ADDRESS, R_NONE, &EnvelopeFromAddress, 0 }, + /* + ** .pp + ** Manually sets the \fIenvelope\fP sender for outgoing messages. + ** This value is ignored if $$use_envelope_from is \fIunset\fP. + */ + { "escape", DT_STRING, R_NONE, &Escape, IP "~" }, + /* + ** .pp + ** Escape character to use for functions in the built-in editor. + */ + { "fast_reply", DT_BOOL, R_NONE, &FastReply, 0 }, + /* + ** .pp + ** When \fIset\fP, the initial prompt for recipients and subject are skipped + ** when replying to messages, and the initial prompt for subject is + ** skipped when forwarding messages. + ** .pp + ** \fBNote:\fP this variable has no effect when the $$autoedit + ** variable is \fIset\fP. + */ + { "fcc_attach", DT_QUAD, R_NONE, &FccAttach, MUTT_YES }, + /* + ** .pp + ** This variable controls whether or not attachments on outgoing messages + ** are saved along with the main body of your message. + */ + { "fcc_clear", DT_BOOL, R_NONE, &FccClear, 0 }, + /* + ** .pp + ** When this variable is \fIset\fP, FCCs will be stored unencrypted and + ** unsigned, even when the actual message is encrypted and/or + ** signed. + ** (PGP only) + */ + { "flag_safe", DT_BOOL, R_NONE, &FlagSafe, 0 }, + /* + ** .pp + ** If set, flagged messages cannot be deleted. + */ + { "folder", DT_PATH, R_NONE, &Folder, IP "~/Mail" }, + /* + ** .pp + ** Specifies the default location of your mailboxes. A ``+'' or ``='' at the + ** beginning of a pathname will be expanded to the value of this + ** variable. Note that if you change this variable (from the default) + ** value you need to make sure that the assignment occurs \fIbefore\fP + ** you use ``+'' or ``='' for any other variables since expansion takes place + ** when handling the ``$mailboxes'' command. + */ + { "folder_format", DT_STRING, R_MENU, &FolderFormat, IP "%2C %t %N %F %2l %-8.8u %-8.8g %8s %d %f" }, + /* + ** .pp + ** This variable allows you to customize the file browser display to your + ** personal taste. This string is similar to $$index_format, but has + ** its own set of \fCprintf(3)\fP-like sequences: + ** .dl + ** .dt %C .dd Current file number + ** .dt %d .dd Date/time folder was last modified + ** .dt %D .dd Date/time folder was last modified using $$date_format. + ** .dt %f .dd Filename (``/'' is appended to directory names, + ** ``@'' to symbolic links and ``*'' to executable files) + ** .dt %F .dd File permissions + ** .dt %g .dd Group name (or numeric gid, if missing) + ** .dt %l .dd Number of hard links + ** .dt %m .dd Number of messages in the mailbox * + ** .dt %n .dd Number of unread messages in the mailbox * + ** .dt %N .dd ``N'' if mailbox has new mail, blank otherwise + ** .dt %s .dd Size in bytes + ** .dt %t .dd ``*'' if the file is tagged, blank otherwise + ** .dt %u .dd Owner name (or numeric uid, if missing) + ** .dt %>X .dd Right justify the rest of the string and pad with character ``X'' + ** .dt %|X .dd Pad to the end of the line with character ``X'' + ** .dt %*X .dd Soft-fill with character ``X'' as pad + ** .de + ** .pp + ** For an explanation of ``soft-fill'', see the $$index_format documentation. + ** .pp + ** * = can be optionally printed if nonzero + ** .pp + ** %m, %n, and %N only work for monitored mailboxes. + ** %m requires $$mail_check_stats to be set. + ** %n requires $$mail_check_stats to be set (except for IMAP mailboxes). + */ + { "followup_to", DT_BOOL, R_NONE, &FollowupTo, 1 }, + /* + ** .pp + ** Controls whether or not the ``Mail-Followup-To:'' header field is + ** generated when sending mail. When \fIset\fP, NeoMutt will generate this + ** field when you are replying to a known mailing list, specified with + ** the ``$subscribe'' or ``$lists'' commands. + ** .pp + ** This field has two purposes. First, preventing you from + ** receiving duplicate copies of replies to messages which you send + ** to mailing lists, and second, ensuring that you do get a reply + ** separately for any messages sent to known lists to which you are + ** not subscribed. + ** .pp + ** The header will contain only the list's address + ** for subscribed lists, and both the list address and your own + ** email address for unsubscribed lists. Without this header, a + ** group reply to your message sent to a subscribed list will be + ** sent to both the list and your address, resulting in two copies + ** of the same email for you. + */ + { "followup_to_poster", DT_QUAD, R_NONE, &FollowupToPoster, MUTT_ASKYES }, + /* + ** .pp + ** If this variable is \fIset\fP and the keyword "poster" is present in + ** \fIFollowup-To\fP header, follow-up to newsgroup function is not + ** permitted. The message will be mailed to the submitter of the + ** message via mail. + */ + { "force_name", DT_BOOL, R_NONE, &ForceName, 0 }, + /* + ** .pp + ** This variable is similar to $$save_name, except that NeoMutt will + ** store a copy of your outgoing message by the username of the address + ** you are sending to even if that mailbox does not exist. + ** .pp + ** Also see the $$record variable. + */ + { "forward_attribution_intro", DT_STRING, R_NONE, &ForwardAttributionIntro, IP "----- Forwarded message from %f -----" }, + /* + ** .pp + ** This is the string that will precede a message which has been forwarded + ** in the main body of a message (when $$mime_forward is unset). + ** For a full listing of defined \fCprintf(3)\fP-like sequences see + ** the section on $$index_format. See also $$attribution_locale. + */ + { "forward_attribution_trailer", DT_STRING, R_NONE, &ForwardAttributionTrailer, IP "----- End forwarded message -----" }, + /* + ** .pp + ** This is the string that will follow a message which has been forwarded + ** in the main body of a message (when $$mime_forward is unset). + ** For a full listing of defined \fCprintf(3)\fP-like sequences see + ** the section on $$index_format. See also $$attribution_locale. + */ + { "forward_decode", DT_BOOL, R_NONE, &ForwardDecode, 1 }, + /* + ** .pp + ** Controls the decoding of complex MIME messages into \fCtext/plain\fP when + ** forwarding a message. The message header is also RFC2047 decoded. + ** This variable is only used, if $$mime_forward is \fIunset\fP, + ** otherwise $$mime_forward_decode is used instead. + */ + { "forward_decrypt", DT_BOOL, R_NONE, &ForwardDecrypt, 1 }, + /* + ** .pp + ** Controls the handling of encrypted messages when forwarding a message. + ** When \fIset\fP, the outer layer of encryption is stripped off. This + ** variable is only used if $$mime_forward is \fIset\fP and + ** $$mime_forward_decode is \fIunset\fP. + ** (PGP only) + */ + { "forward_edit", DT_QUAD, R_NONE, &ForwardEdit, MUTT_YES }, + /* + ** .pp + ** This quadoption controls whether or not the user is automatically + ** placed in the editor when forwarding messages. For those who always want + ** to forward with no modification, use a setting of ``no''. + */ + { "forward_format", DT_STRING, R_NONE, &ForwardFormat, IP "[%a: %s]" }, + /* + ** .pp + ** This variable controls the default subject when forwarding a message. + ** It uses the same format sequences as the $$index_format variable. + */ + { "forward_quote", DT_BOOL, R_NONE, &ForwardQuote, 0 }, + /* + ** .pp + ** When \fIset\fP, forwarded messages included in the main body of the + ** message (when $$mime_forward is \fIunset\fP) will be quoted using + ** $$indent_string. + */ + { "forward_references", DT_BOOL, R_NONE, &ForwardReferences, 0 }, + /* + ** .pp + ** When \fIset\fP, forwarded messages set the ``In-Reply-To:'' and + ** ``References:'' headers in the same way as normal replies would. Hence the + ** forwarded message becomes part of the original thread instead of starting + ** a new one. + */ + { "from", DT_ADDRESS, R_NONE, &From, 0 }, + /* + ** .pp + ** When \fIset\fP, this variable contains a default from address. It + ** can be overridden using ``$my_hdr'' (including from a ``$send-hook'') and + ** $$reverse_name. This variable is ignored if $$use_from is \fIunset\fP. + ** .pp + ** This setting defaults to the contents of the environment variable \fC$$$EMAIL\fP. + */ + { "from_chars", DT_MBTABLE, R_BOTH, &FromChars, 0 }, + /* + ** .pp + ** Controls the character used to prefix the %F and %L fields in the + ** index. + ** .dl + ** .dt \fBCharacter\fP .dd \fBDescription\fP + ** .dt 1 .dd Mail is written by you and has a To address, or has a known mailing list in the To address. + ** .dt 2 .dd Mail is written by you and has a Cc address, or has a known mailing list in the Cc address. + ** .dt 3 .dd Mail is written by you and has a Bcc address. + ** .dt 4 .dd All remaining cases. + ** .de + ** .pp + ** If this is empty or unset (default), the traditional long "To ", + ** "Cc " and "Bcc " prefixes are used. If set but too short to + ** include a character for a particular case, a single space will be + ** prepended to the field. To prevent any prefix at all from being + ** added in a particular case, use the special value CR (aka ^M) + ** for the corresponding character. + ** .pp + ** This slightly odd interface is necessitated by NeoMutt's handling of + ** string variables; one cannot tell a variable that is unset from one + ** that is set to the empty string. + */ + { "gecos_mask", DT_REGEX, R_NONE, &GecosMask, IP "^[^,]*" }, + /* + ** .pp + ** A regular expression used by NeoMutt to parse the GECOS field of a password + ** entry when expanding the alias. The default value + ** will return the string up to the first ``,'' encountered. + ** If the GECOS field contains a string like ``lastname, firstname'' then you + ** should set it to ``\fC.*\fP''. + ** .pp + ** This can be useful if you see the following behavior: you address an e-mail + ** to user ID ``stevef'' whose full name is ``Steve Franklin''. If NeoMutt expands + ** ``stevef'' to ``"Franklin" stevef@foo.bar'' then you should set the $$gecos_mask to + ** a regular expression that will match the whole name so NeoMutt will expand + ** ``Franklin'' to ``Franklin, Steve''. + */ + { "group_index_format", DT_STRING, R_BOTH, &GroupIndexFormat, IP "%4C %M%N %5s %-45.45f %d" }, + /* + ** .pp + ** This variable allows you to customize the newsgroup browser display to + ** your personal taste. This string is similar to ``$index_format'', but + ** has its own set of printf()-like sequences: + ** .dl + ** .dt %C .dd Current newsgroup number + ** .dt %d .dd Description of newsgroup (becomes from server) + ** .dt %f .dd Newsgroup name + ** .dt %M .dd - if newsgroup not allowed for direct post (moderated for example) + ** .dt %N .dd N if newsgroup is new, u if unsubscribed, blank otherwise + ** .dt %n .dd Number of new articles in newsgroup + ** .dt %s .dd Number of unread articles in newsgroup + ** .dt %>X .dd Right justify the rest of the string and pad with character "X" + ** .dt %|X .dd Pad to the end of the line with character "X" + ** .de + */ + { "hdrs", DT_BOOL, R_NONE, &Hdrs, 1 }, + /* + ** .pp + ** When \fIunset\fP, the header fields normally added by the ``$my_hdr'' + ** command are not created. This variable \fImust\fP be unset before + ** composing a new message or replying in order to take effect. If \fIset\fP, + ** the user defined header fields are added to every new message. + */ + { "header", DT_BOOL, R_NONE, &Header, 0 }, + /* + ** .pp + ** When \fIset\fP, this variable causes NeoMutt to include the header + ** of the message you are replying to into the edit buffer. + ** The $$weed setting applies. + */ + { "header_cache", DT_PATH, R_NONE, &HeaderCache, 0 }, + /* + ** .pp + ** This variable points to the header cache database. + ** If pointing to a directory NeoMutt will contain a header cache + ** database file per folder, if pointing to a file that file will + ** be a single global header cache. By default it is \fIunset\fP so no header + ** caching will be used. + ** .pp + ** Header caching can greatly improve speed when opening POP, IMAP + ** MH or Maildir folders, see ``$caching'' for details. + */ + { "header_cache_backend", DT_STRING, R_NONE, &HeaderCacheBackend, 0 }, + /* + ** .pp + ** This variable specifies the header cache backend. + */ + { "header_cache_compress", DT_BOOL, R_NONE, &HeaderCacheCompress, 1 }, + /* + ** .pp + ** When NeoMutt is compiled with qdbm, tokyocabinet or kyotocabinet + ** as header cache backend, this option determines whether the + ** database will be compressed. Compression results in database + ** files roughly being one fifth of the usual diskspace, but the + ** decompression can result in a slower opening of cached folder(s) + ** which in general is still much faster than opening non header + ** cached folders. + */ + { "header_cache_pagesize", DT_STRING, R_NONE, &HeaderCachePageSize, IP "16384" }, + /* + ** .pp + ** When NeoMutt is compiled with either gdbm or bdb4 as the header cache backend, + ** this option changes the database page size. Too large or too small + ** values can waste space, memory, or CPU time. The default should be more + ** or less optimal for most use cases. + */ + { "header_color_partial", DT_BOOL, R_PAGER_FLOW, &HeaderColorPartial, 0 }, + /* + ** .pp + ** When \fIset\fP, color header regexes behave like color body regexes: + ** color is applied to the exact text matched by the regex. When + ** \fIunset\fP, color is applied to the entire header. + ** .pp + ** One use of this option might be to apply color to just the header labels. + ** .pp + ** See ``$color'' for more details. + */ + { "help", DT_BOOL, R_REFLOW, &Help, 1 }, + /* + ** .pp + ** When \fIset\fP, help lines describing the bindings for the major functions + ** provided by each menu are displayed on the first line of the screen. + ** .pp + ** \fBNote:\fP The binding will not be displayed correctly if the + ** function is bound to a sequence rather than a single keystroke. Also, + ** the help line may not be updated if a binding is changed while NeoMutt is + ** running. Since this variable is primarily aimed at new users, neither + ** of these should present a major problem. + */ + { "hidden_host", DT_BOOL, R_NONE, &HiddenHost, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will skip the host name part of $$hostname variable + ** when adding the domain part to addresses. This variable does not + ** affect the generation of Message-IDs, and it will not lead to the + ** cut-off of first-level domains. + */ + { "hide_limited", DT_BOOL, R_TREE|R_INDEX, &HideLimited, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will not show the presence of messages that are hidden + ** by limiting, in the thread tree. + */ + { "hide_missing", DT_BOOL, R_TREE|R_INDEX, &HideMissing, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will not show the presence of missing messages in the + ** thread tree. + */ + { "hide_thread_subject", DT_BOOL, R_TREE|R_INDEX, &HideThreadSubject, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will not show the subject of messages in the thread + ** tree that have the same subject as their parent or closest previously + ** displayed sibling. + */ + { "hide_top_limited", DT_BOOL, R_TREE|R_INDEX, &HideTopLimited, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will not show the presence of messages that are hidden + ** by limiting, at the top of threads in the thread tree. Note that when + ** $$hide_limited is \fIset\fP, this option will have no effect. + */ + { "hide_top_missing", DT_BOOL, R_TREE|R_INDEX, &HideTopMissing, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will not show the presence of missing messages at the + ** top of threads in the thread tree. Note that when $$hide_missing is + ** \fIset\fP, this option will have no effect. + */ + { "history", DT_NUMBER, R_NONE, &History, 10 }, + /* + ** .pp + ** This variable controls the size (in number of strings remembered) of + ** the string history buffer per category. The buffer is cleared each time the + ** variable is set. + */ + { "history_file", DT_PATH, R_NONE, &HistoryFile, IP "~/.mutthistory" }, + /* + ** .pp + ** The file in which NeoMutt will save its history. + ** .pp + ** Also see $$save_history. + */ + { "history_remove_dups", DT_BOOL, R_NONE, &HistoryRemoveDups, 0 }, + /* + ** .pp + ** When \fIset\fP, all of the string history will be scanned for duplicates + ** when a new entry is added. Duplicate entries in the $$history_file will + ** also be removed when it is periodically compacted. + */ + { "honor_disposition", DT_BOOL, R_NONE, &HonorDisposition, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will not display attachments with a + ** disposition of ``attachment'' inline even if it could + ** render the part to plain text. These MIME parts can only + ** be viewed from the attachment menu. + ** .pp + ** If \fIunset\fP, NeoMutt will render all MIME parts it can + ** properly transform to plain text. + */ + { "honor_followup_to", DT_QUAD, R_NONE, &HonorFollowupTo, MUTT_YES }, + /* + ** .pp + ** This variable controls whether or not a Mail-Followup-To header is + ** honored when group-replying to a message. + */ + { "hostname", DT_STRING, R_NONE, &Hostname, 0 }, + /* + ** .pp + ** Specifies the fully-qualified hostname of the system NeoMutt is running on + ** containing the host's name and the DNS domain it belongs to. It is used + ** as the domain part (after ``@'') for local email addresses as well as + ** Message-Id headers. + ** .pp + ** Its value is determined at startup as follows: the node's + ** hostname is first determined by the \fCuname(3)\fP function. The + ** domain is then looked up using the \fCgethostname(2)\fP and + ** \fCgetaddrinfo(3)\fP functions. If those calls are unable to + ** determine the domain, the full value returned by uname is used. + ** Optionally, NeoMutt can be compiled with a fixed domain name in + ** which case a detected one is not used. + ** .pp + ** Also see $$use_domain and $$hidden_host. + */ + { "idn_decode", DT_BOOL, R_MENU, &IdnDecode, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will show you international domain names decoded. + ** Note: You can use IDNs for addresses even if this is \fIunset\fP. + ** This variable only affects decoding. (IDN only) + */ + { "idn_encode", DT_BOOL, R_MENU, &IdnEncode, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will encode international domain names using + ** IDN. Unset this if your SMTP server can handle newer (RFC6531) + ** UTF-8 encoded domains. (IDN only) + */ + { "ignore_linear_white_space", DT_BOOL, R_NONE, &IgnoreLinearWhiteSpace, 0 }, + /* + ** .pp + ** This option replaces linear-white-space between encoded-word + ** and text to a single space to prevent the display of MIME-encoded + ** ``Subject:'' field from being divided into multiple lines. + */ + { "ignore_list_reply_to", DT_BOOL, R_NONE, &IgnoreListReplyTo, 0 }, + /* + ** .pp + ** Affects the behavior of the \fC\fP function when replying to + ** messages from mailing lists (as defined by the ``$subscribe'' or + ** ``$lists'' commands). When \fIset\fP, if the ``Reply-To:'' field is + ** set to the same value as the ``To:'' field, NeoMutt assumes that the + ** ``Reply-To:'' field was set by the mailing list to automate responses + ** to the list, and will ignore this field. To direct a response to the + ** mailing list when this option is \fIset\fP, use the \fC$\fP + ** function; \fC\fP will reply to both the sender and the + ** list. + */ + { "show_multipart_alternative", DT_STRING, R_NONE, &ShowMultipartAlternative, 0 }, + /* + ** .pp + ** When \fIset\fP to \fCinfo\fP, the multipart/alternative information is shown. + ** When \fIset\fP to \fCinline\fP, all of the alternatives are displayed. + ** When not set, the default behavior is to show only the chosen alternative. + ** .pp + */ + { "imap_authenticators", DT_STRING, R_NONE, &ImapAuthenticators, 0 }, + /* + ** .pp + ** This is a colon-delimited list of authentication methods NeoMutt may + ** attempt to use to log in to an IMAP server, in the order NeoMutt should + ** try them. Authentication methods are either ``login'' or the right + ** side of an IMAP ``AUTH=xxx'' capability string, e.g. ``digest-md5'', ``gssapi'' + ** or ``cram-md5''. This option is case-insensitive. If it's + ** \fIunset\fP (the default) NeoMutt will try all available methods, + ** in order from most-secure to least-secure. + ** .pp + ** Example: + ** .ts + ** set imap_authenticators="gssapi:cram-md5:login" + ** .te + ** .pp + ** \fBNote:\fP NeoMutt will only fall back to other authentication methods if + ** the previous methods are unavailable. If a method is available but + ** authentication fails, NeoMutt will not connect to the IMAP server. + */ + { "imap_check_subscribed", DT_BOOL, R_NONE, &ImapCheckSubscribed, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will fetch the set of subscribed folders from + ** your server on connection, and add them to the set of mailboxes + ** it polls for new mail just as if you had issued individual ``$mailboxes'' + ** commands. + */ + { "imap_delim_chars", DT_STRING, R_NONE, &ImapDelimChars, IP "/." }, + /* + ** .pp + ** This contains the list of characters which you would like to treat + ** as folder separators for displaying IMAP paths. In particular it + ** helps in using the ``='' shortcut for your \fIfolder\fP variable. + */ + { "imap_headers", DT_STRING, R_INDEX, &ImapHeaders, 0 }, + /* + ** .pp + ** NeoMutt requests these header fields in addition to the default headers + ** (``Date:'', ``From:'', ``Subject:'', ``To:'', ``Cc:'', ``Message-Id:'', + ** ``References:'', ``Content-Type:'', ``Content-Description:'', ``In-Reply-To:'', + ** ``Reply-To:'', ``Lines:'', ``List-Post:'', ``X-Label:'') from IMAP + ** servers before displaying the index menu. You may want to add more + ** headers for spam detection. + ** .pp + ** \fBNote:\fP This is a space separated list, items should be uppercase + ** and not contain the colon, e.g. ``X-BOGOSITY X-SPAM-STATUS'' for the + ** ``X-Bogosity:'' and ``X-Spam-Status:'' header fields. + */ + { "imap_idle", DT_BOOL, R_NONE, &ImapIdle, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will attempt to use the IMAP IDLE extension + ** to check for new mail in the current mailbox. Some servers + ** (dovecot was the inspiration for this option) react badly + ** to NeoMutt's implementation. If your connection seems to freeze + ** up periodically, try unsetting this. + */ + { "imap_keepalive", DT_NUMBER, R_NONE, &ImapKeepalive, 300 }, + /* + ** .pp + ** This variable specifies the maximum amount of time in seconds that NeoMutt + ** will wait before polling open IMAP connections, to prevent the server + ** from closing them before NeoMutt has finished with them. The default is + ** well within the RFC-specified minimum amount of time (30 minutes) before + ** a server is allowed to do this, but in practice the RFC does get + ** violated every now and then. Reduce this number if you find yourself + ** getting disconnected from your IMAP server due to inactivity. + */ + { "imap_list_subscribed", DT_BOOL, R_NONE, &ImapListSubscribed, 0 }, + /* + ** .pp + ** This variable configures whether IMAP folder browsing will look for + ** only subscribed folders or all folders. This can be toggled in the + ** IMAP browser with the \fC\fP function. + */ + { "imap_login", DT_STRING, R_NONE|F_SENSITIVE, &ImapLogin, 0 }, + /* + ** .pp + ** Your login name on the IMAP server. + ** .pp + ** This variable defaults to the value of $$imap_user. + */ + { "imap_pass", DT_STRING, R_NONE|F_SENSITIVE, &ImapPass, 0 }, + /* + ** .pp + ** Specifies the password for your IMAP account. If \fIunset\fP, NeoMutt will + ** prompt you for your password when you invoke the \fC\fP function + ** or try to open an IMAP folder. + ** .pp + ** \fBWarning\fP: you should only use this option when you are on a + ** fairly secure machine, because the superuser can read your neomuttrc even + ** if you are the only one who can read the file. + */ + { "imap_passive", DT_BOOL, R_NONE, &ImapPassive, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will not open new IMAP connections to check for new + ** mail. NeoMutt will only check for new mail over existing IMAP + ** connections. This is useful if you don't want to be prompted to + ** user/password pairs on NeoMutt invocation, or if opening the connection + ** is slow. + */ + { "imap_peek", DT_BOOL, R_NONE, &ImapPeek, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will avoid implicitly marking your mail as read whenever + ** you fetch a message from the server. This is generally a good thing, + ** but can make closing an IMAP folder somewhat slower. This option + ** exists to appease speed freaks. + */ + { "imap_pipeline_depth", DT_NUMBER, R_NONE, &ImapPipelineDepth, 15 }, + /* + ** .pp + ** Controls the number of IMAP commands that may be queued up before they + ** are sent to the server. A deeper pipeline reduces the amount of time + ** NeoMutt must wait for the server, and can make IMAP servers feel much + ** more responsive. But not all servers correctly handle pipelined commands, + ** so if you have problems you might want to try setting this variable to 0. + ** .pp + ** \fBNote:\fP Changes to this variable have no effect on open connections. + */ + { "imap_poll_timeout", DT_NUMBER, R_NONE, &ImapPollTimeout, 15 }, + /* + ** .pp + ** This variable specifies the maximum amount of time in seconds + ** that NeoMutt will wait for a response when polling IMAP connections + ** for new mail, before timing out and closing the connection. Set + ** to 0 to disable timing out. + */ + { "imap_servernoise", DT_BOOL, R_NONE, &ImapServernoise, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will display warning messages from the IMAP + ** server as error messages. Since these messages are often + ** harmless, or generated due to configuration problems on the + ** server which are out of the users' hands, you may wish to suppress + ** them at some point. + */ + { "imap_user", DT_STRING, R_NONE|F_SENSITIVE, &ImapUser, 0 }, + /* + ** .pp + ** The name of the user whose mail you intend to access on the IMAP + ** server. + ** .pp + ** This variable defaults to your user name on the local machine. + */ + { "implicit_autoview", DT_BOOL,R_NONE, &ImplicitAutoview, 0 }, + /* + ** .pp + ** If set to ``yes'', NeoMutt will look for a mailcap entry with the + ** ``\fCcopiousoutput\fP'' flag set for \fIevery\fP MIME attachment it doesn't have + ** an internal viewer defined for. If such an entry is found, NeoMutt will + ** use the viewer defined in that entry to convert the body part to text + ** form. + */ + { "include", DT_QUAD, R_NONE, &Include, MUTT_ASKYES }, + /* + ** .pp + ** Controls whether or not a copy of the message(s) you are replying to + ** is included in your reply. + */ + { "include_onlyfirst", DT_BOOL, R_NONE, &IncludeOnlyfirst, 0 }, + /* + ** .pp + ** Controls whether or not NeoMutt includes only the first attachment + ** of the message you are replying. + */ + { "indent_string", DT_STRING, R_NONE, &IndentString, IP "> " }, + /* + ** .pp + ** Specifies the string to prepend to each line of text quoted in a + ** message to which you are replying. You are strongly encouraged not to + ** change this value, as it tends to agitate the more fanatical netizens. + ** .pp + ** The value of this option is ignored if $$text_flowed is set, because + ** the quoting mechanism is strictly defined for format=flowed. + ** .pp + ** This option is a format string, please see the description of + ** $$index_format for supported \fCprintf(3)\fP-style sequences. + */ + { "index_format", DT_STRING, R_BOTH, &IndexFormat, IP "%4C %Z %{%b %d} %-15.15L (%?l?%4l&%4c?) %s" }, + /* + ** .pp + ** This variable allows you to customize the message index display to + ** your personal taste. + ** .pp + ** ``Format strings'' are similar to the strings used in the C + ** function \fCprintf(3)\fP to format output (see the man page for more details). + ** For an explanation of the %? construct, see the $status_format description. + ** The following sequences are defined in NeoMutt: + ** .dl + ** .dt %a .dd Address of the author + ** .dt %A .dd Reply-to address (if present; otherwise: address of author) + ** .dt %b .dd Filename of the original message folder (think mailbox) + ** .dt %B .dd The list to which the letter was sent, or else the folder name (%b). + ** .dt %c .dd Number of characters (bytes) in the message + ** .dt %C .dd Current message number + ** .dt %d .dd Date and time of the message in the format specified by + ** $$date_format converted to sender's time zone + ** .dt %D .dd Date and time of the message in the format specified by + ** $$date_format converted to the local time zone + ** .dt %e .dd Current message number in thread + ** .dt %E .dd Number of messages in current thread + ** .dt %f .dd Sender (address + real name), either From: or Return-Path: + ** .dt %F .dd Author name, or recipient name if the message is from you + ** .dt %g .dd Newsgroup name (if compiled with NNTP support) + ** .dt %g .dd Message labels (e.g. notmuch tags) + ** .dt %H .dd Spam attribute(s) of this message + ** .dt %I .dd Initials of author + ** .dt %i .dd Message-id of the current message + ** .dt %K .dd The list to which the letter was sent (if any; otherwise: empty) + ** .dt %l .dd Number of lines in the message (does not work with maildir, + ** Mh, and possibly IMAP folders) + ** .dt %L .dd If an address in the ``To:'' or ``Cc:'' header field matches an address + ** Defined by the users ``$subscribe'' command, this displays + ** "To ", otherwise the same as %F + ** .dt %m .dd Total number of message in the mailbox + ** .dt %M .dd Number of hidden messages if the thread is collapsed + ** .dt %N .dd Message score + ** .dt %n .dd Author's real name (or address if missing) + ** .dt %O .dd Original save folder where NeoMutt would formerly have + ** Stashed the message: list name or recipient name + ** If not sent to a list + ** .dt %P .dd Progress indicator for the built-in pager (how much of the file has been displayed) + ** .dt %q .dd Newsgroup name (if compiled with NNTP support) + ** .dt %r .dd Comma separated list of ``To:'' recipients + ** .dt %R .dd Comma separated list of ``Cc:'' recipients + ** .dt %s .dd Subject of the message + ** .dt %S .dd Single character status of the message (``N''/``O''/``D''/``d''/``!''/``r''/``\(as'') + ** .dt %t .dd ``To:'' field (recipients) + ** .dt %T .dd The appropriate character from the $$to_chars string + ** .dt %u .dd User (login) name of the author + ** .dt %v .dd First name of the author, or the recipient if the message is from you + ** .dt %W .dd Name of organization of author (``Organization:'' field) + ** .dt %x .dd ``X-Comment-To:'' field (if present and compiled with NNTP support) + ** .dt %X .dd Number of attachments + ** (please see the ``$attachments'' section for possible speed effects) + ** .dt %y .dd ``X-Label:'' field, if present + ** .dt %Y .dd ``X-Label:'' field, if present, and \fI(1)\fP not at part of a thread tree, + ** \fI(2)\fP at the top of a thread, or \fI(3)\fP ``X-Label:'' is different from + ** Preceding message's ``X-Label:'' + ** .dt %Z .dd A three character set of message status flags. + ** The first character is new/read/replied flags (``n''/``o''/``r''/``O''/``N''). + ** The second is deleted or encryption flags (``D''/``d''/``S''/``P''/``s''/``K''). + ** The third is either tagged/flagged (``\(as''/``!''), or one of the characters + ** Listed in $$to_chars. + ** .dt %zs .dd Message status flags + ** .dt %zc .dd Message crypto flags + ** .dt %zt .dd Message tag flags + ** .dt %{fmt} .dd the date and time of the message is converted to sender's + ** time zone, and ``fmt'' is expanded by the library function + ** \fCstrftime(3)\fP; a leading bang disables locales + ** .dt %[fmt] .dd the date and time of the message is converted to the local + ** time zone, and ``fmt'' is expanded by the library function + ** \fCstrftime(3)\fP; a leading bang disables locales + ** .dt %(fmt) .dd the local date and time when the message was received. + ** ``fmt'' is expanded by the library function \fCstrftime(3)\fP; + ** a leading bang disables locales + ** .dt %>X .dd right justify the rest of the string and pad with character ``X'' + ** .dt %|X .dd pad to the end of the line with character ``X'' + ** .dt %*X .dd soft-fill with character ``X'' as pad + ** .de + ** .pp + ** Date format expressions can be constructed based on relative dates. Using + ** the date formatting operators along with nested conditionals, the date + ** format can be modified based on how old a message is. See the section on + ** ``Conditional Dates'' for an explanation and examples + ** ``Soft-fill'' deserves some explanation: Normal right-justification + ** will print everything to the left of the ``%>'', displaying padding and + ** whatever lies to the right only if there's room. By contrast, + ** soft-fill gives priority to the right-hand side, guaranteeing space + ** to display it and showing padding only if there's still room. If + ** necessary, soft-fill will eat text leftwards to make room for + ** rightward text. + ** .pp + ** Note that these expandos are supported in + ** ``$save-hook'', ``$fcc-hook'' and ``$fcc-save-hook'', too. + */ + { "inews", DT_PATH, R_NONE, &Inews, IP "" }, + /* + ** .pp + ** If set, specifies the program and arguments used to deliver news posted + ** by NeoMutt. Otherwise, NeoMutt posts article using current connection to + ** news server. The following printf-style sequence is understood: + ** .dl + ** .dt %a .dd account url + ** .dt %p .dd port + ** .dt %P .dd port if specified + ** .dt %s .dd news server name + ** .dt %S .dd url schema + ** .dt %u .dd username + ** .de + ** .pp + ** Example: + ** .ts + ** set inews="/usr/local/bin/inews -hS" + ** .te + */ + { "ispell", DT_PATH, R_NONE, &Ispell, IP ISPELL }, + /* + ** .pp + ** How to invoke ispell (GNU's spell-checking software). + */ + { "keep_flagged", DT_BOOL, R_NONE, &KeepFlagged, 0 }, + /* + ** .pp + ** If \fIset\fP, read messages marked as flagged will not be moved + ** from your spool mailbox to your $$mbox mailbox, or as a result of + ** a ``$mbox-hook'' command. + */ + { "mail_check", DT_NUMBER, R_NONE, &MailCheck, 5 }, + /* + ** .pp + ** This variable configures how often (in seconds) NeoMutt should look for + ** new mail. Also see the $$timeout variable. + */ + { "mail_check_recent",DT_BOOL, R_NONE, &MailCheckRecent, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will only notify you about new mail that has been received + ** since the last time you opened the mailbox. When \fIunset\fP, NeoMutt will notify you + ** if any new mail exists in the mailbox, regardless of whether you have visited it + ** recently. + ** .pp + ** When \fI$$mark_old\fP is set, NeoMutt does not consider the mailbox to contain new + ** mail if only old messages exist. + */ + { "mail_check_stats", DT_BOOL, R_NONE, &MailCheckStats, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will periodically calculate message + ** statistics of a mailbox while polling for new mail. It will + ** check for unread, flagged, and total message counts. Because + ** this operation is more performance intensive, it defaults to + ** \fIunset\fP, and has a separate option, $$mail_check_stats_interval, to + ** control how often to update these counts. + */ + { "mail_check_stats_interval", DT_NUMBER, R_NONE, &MailCheckStatsInterval, 60 }, + /* + ** .pp + ** When $$mail_check_stats is \fIset\fP, this variable configures + ** how often (in seconds) NeoMutt will update message counts. + */ + { "mailcap_path", DT_STRING, R_NONE, &MailcapPath, 0 }, + /* + ** .pp + ** This variable specifies which files to consult when attempting to + ** display MIME bodies not directly supported by NeoMutt. + */ + { "mailcap_sanitize", DT_BOOL, R_NONE, &MailcapSanitize, 1 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will restrict possible characters in mailcap % expandos + ** to a well-defined set of safe characters. This is the safe setting, + ** but we are not sure it doesn't break some more advanced MIME stuff. + ** .pp + ** \fBDON'T CHANGE THIS SETTING UNLESS YOU ARE REALLY SURE WHAT YOU ARE + ** DOING!\fP + */ + { "maildir_header_cache_verify", DT_BOOL, R_NONE, &MaildirHeaderCacheVerify, 1 }, + /* + ** .pp + ** Check for Maildir unaware programs other than NeoMutt having modified maildir + ** files when the header cache is in use. This incurs one \fCstat(2)\fP per + ** message every time the folder is opened (which can be very slow for NFS + ** folders). + */ + { "maildir_trash", DT_BOOL, R_NONE, &MaildirTrash, 0 }, + /* + ** .pp + ** If \fIset\fP, messages marked as deleted will be saved with the maildir + ** trashed flag instead of unlinked. \fBNote:\fP this only applies + ** to maildir-style mailboxes. Setting it will have no effect on other + ** mailbox types. + */ + { "maildir_check_cur", DT_BOOL, R_NONE, &MaildirCheckCur, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will poll both the new and cur directories of + ** a maildir folder for new messages. This might be useful if other + ** programs interacting with the folder (e.g. dovecot) are moving new + ** messages to the cur directory. Note that setting this option may + ** slow down polling for new messages in large folders, since NeoMutt has + ** to scan all cur messages. + */ + { "mark_macro_prefix",DT_STRING, R_NONE, &MarkMacroPrefix, IP "'" }, + /* + ** .pp + ** Prefix for macros created using mark-message. A new macro + ** automatically generated with \fIa\fP will be composed + ** from this prefix and the letter \fIa\fP. + */ + { "mark_old", DT_BOOL, R_BOTH, &MarkOld, 1 }, + /* + ** .pp + ** Controls whether or not NeoMutt marks \fInew\fP \fBunread\fP + ** messages as \fIold\fP if you exit a mailbox without reading them. + ** With this option \fIset\fP, the next time you start NeoMutt, the messages + ** will show up with an ``O'' next to them in the index menu, + ** indicating that they are old. + */ + { "markers", DT_BOOL, R_PAGER_FLOW, &Markers, 1 }, + /* + ** .pp + ** Controls the display of wrapped lines in the internal pager. If set, a + ** ``+'' marker is displayed at the beginning of wrapped lines. + ** .pp + ** Also see the $$smart_wrap variable. + */ + { "mask", DT_REGEX | DT_REGEX_MATCH_CASE | DT_REGEX_ALLOW_NOT, R_NONE, &Mask, IP "!^\\.[^.]" }, + /* + ** .pp + ** A regular expression used in the file browser, optionally preceded by + ** the \fInot\fP operator ``!''. Only files whose names match this mask + ** will be shown. The match is always case-sensitive. + */ + { "mbox", DT_PATH, R_BOTH, &Mbox, IP "~/mbox" }, + /* + ** .pp + ** This specifies the folder into which read mail in your $$spoolfile + ** folder will be appended. + ** .pp + ** Also see the $$move variable. + */ + { "mbox_type", DT_MAGIC,R_NONE, &MboxType, MUTT_MBOX }, + /* + ** .pp + ** The default mailbox type used when creating new folders. May be any of + ** ``mbox'', ``MMDF'', ``MH'' and ``Maildir''. This is overridden by the + ** \fC-m\fP command-line option. + */ + { "menu_context", DT_NUMBER, R_NONE, &MenuContext, 0 }, + /* + ** .pp + ** This variable controls the number of lines of context that are given + ** when scrolling through menus. (Similar to $$pager_context.) + */ + { "menu_move_off", DT_BOOL, R_NONE, &MenuMoveOff, 1 }, + /* + ** .pp + ** When \fIunset\fP, the bottom entry of menus will never scroll up past + ** the bottom of the screen, unless there are less entries than lines. + ** When \fIset\fP, the bottom entry may move off the bottom. + */ + { "menu_scroll", DT_BOOL, R_NONE, &MenuScroll, 0 }, + /* + ** .pp + ** When \fIset\fP, menus will be scrolled up or down one line when you + ** attempt to move across a screen boundary. If \fIunset\fP, the screen + ** is cleared and the next or previous page of the menu is displayed + ** (useful for slow links to avoid many redraws). + */ + { "message_cache_clean", DT_BOOL, R_NONE, &MessageCacheClean, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will clean out obsolete entries from the message cache when + ** the mailbox is synchronized. You probably only want to set it + ** every once in a while, since it can be a little slow + ** (especially for large folders). + */ + { "message_cachedir", DT_PATH, R_NONE, &MessageCachedir, 0 }, + /* + ** .pp + ** Set this to a directory and NeoMutt will cache copies of messages from + ** your IMAP and POP servers here. You are free to remove entries at any + ** time. + ** .pp + ** When setting this variable to a directory, NeoMutt needs to fetch every + ** remote message only once and can perform regular expression searches + ** as fast as for local folders. + ** .pp + ** Also see the $$message_cache_clean variable. + */ + { "message_format", DT_STRING, R_NONE, &MessageFormat, IP "%s" }, + /* + ** .pp + ** This is the string displayed in the ``attachment'' menu for + ** attachments of type \fCmessage/rfc822\fP. For a full listing of defined + ** \fCprintf(3)\fP-like sequences see the section on $$index_format. + */ + { "meta_key", DT_BOOL, R_NONE, &MetaKey, 0 }, + /* + ** .pp + ** If \fIset\fP, forces NeoMutt to interpret keystrokes with the high bit (bit 8) + ** set as if the user had pressed the Esc key and whatever key remains + ** after having the high bit removed. For example, if the key pressed + ** has an ASCII value of \fC0xf8\fP, then this is treated as if the user had + ** pressed Esc then ``x''. This is because the result of removing the + ** high bit from \fC0xf8\fP is \fC0x78\fP, which is the ASCII character + ** ``x''. + */ + { "metoo", DT_BOOL, R_NONE, &Metoo, 0 }, + /* + ** .pp + ** If \fIunset\fP, NeoMutt will remove your address (see the ``$alternates'' + ** command) from the list of recipients when replying to a message. + */ + { "mh_purge", DT_BOOL, R_NONE, &MhPurge, 0 }, + /* + ** .pp + ** When \fIunset\fP, NeoMutt will mimic mh's behavior and rename deleted messages + ** to \fI,\fP in mh folders instead of really deleting + ** them. This leaves the message on disk but makes programs reading the folder + ** ignore it. If the variable is \fIset\fP, the message files will simply be + ** deleted. + ** .pp + ** This option is similar to $$maildir_trash for Maildir folders. + */ + { "mh_seq_flagged", DT_STRING, R_NONE, &MhSeqFlagged, IP "flagged" }, + /* + ** .pp + ** The name of the MH sequence used for flagged messages. + */ + { "mh_seq_replied", DT_STRING, R_NONE, &MhSeqReplied, IP "replied" }, + /* + ** .pp + ** The name of the MH sequence used to tag replied messages. + */ + { "mh_seq_unseen", DT_STRING, R_NONE, &MhSeqUnseen, IP "unseen" }, + /* + ** .pp + ** The name of the MH sequence used for unseen messages. + */ + { "mime_forward", DT_QUAD, R_NONE, &MimeForward, MUTT_NO }, + /* + ** .pp + ** When \fIset\fP, the message you are forwarding will be attached as a + ** separate \fCmessage/rfc822\fP MIME part instead of included in the main body of the + ** message. This is useful for forwarding MIME messages so the receiver + ** can properly view the message as it was delivered to you. If you like + ** to switch between MIME and not MIME from mail to mail, set this + ** variable to ``ask-no'' or ``ask-yes''. + ** .pp + ** Also see $$forward_decode and $$mime_forward_decode. + */ + { "mime_forward_decode", DT_BOOL, R_NONE, &MimeForwardDecode, 0 }, + /* + ** .pp + ** Controls the decoding of complex MIME messages into \fCtext/plain\fP when + ** forwarding a message while $$mime_forward is \fIset\fP. Otherwise + ** $$forward_decode is used instead. + */ + { "mime_forward_rest", DT_QUAD, R_NONE, &MimeForwardRest, MUTT_YES }, + /* + ** .pp + ** When forwarding multiple attachments of a MIME message from the attachment + ** menu, attachments which cannot be decoded in a reasonable manner will + ** be attached to the newly composed message if this option is \fIset\fP. + */ + { "mime_subject", DT_BOOL, R_NONE, &MimeSubject, 1 }, + /* + ** .pp + ** If \fIunset\fP, 8-bit ``subject:'' line in article header will not be + ** encoded according to RFC2047 to base64. This is useful when message + ** is Usenet article, because MIME for news is nonstandard feature. + */ + { "mime_type_query_command", DT_STRING, R_NONE, &MimeTypeQueryCommand, IP "" }, + /* + ** .pp + ** This specifies a command to run, to determine the mime type of a + ** new attachment when composing a message. Unless + ** $$mime_type_query_first is set, this will only be run if the + ** attachment's extension is not found in the mime.types file. + ** .pp + ** The string may contain a ``%s'', which will be substituted with the + ** attachment filename. NeoMutt will add quotes around the string substituted + ** for ``%s'' automatically according to shell quoting rules, so you should + ** avoid adding your own. If no ``%s'' is found in the string, NeoMutt will + ** append the attachment filename to the end of the string. + ** .pp + ** The command should output a single line containing the + ** attachment's mime type. + ** .pp + ** Suggested values are ``xdg-mime query filetype'' or + ** ``file -bi''. + */ + { "mime_type_query_first", DT_BOOL, R_NONE, &MimeTypeQueryFirst, 0 }, + /* + ** .pp + ** When \fIset\fP, the $$mime_type_query_command will be run before the + ** mime.types lookup. + */ + { "mix_entry_format", DT_STRING, R_NONE, &MixEntryFormat, IP "%4n %c %-16s %a" }, + /* + ** .pp + ** This variable describes the format of a remailer line on the mixmaster + ** chain selection screen. The following \fCprintf(3)\fP-like sequences are + ** supported: + ** .dl + ** .dt %a .dd The remailer's e-mail address + ** .dt %c .dd Remailer capabilities + ** .dt %n .dd The running number on the menu + ** .dt %s .dd The remailer's short name + ** .de + */ + { "mixmaster", DT_PATH, R_NONE, &Mixmaster, IP MIXMASTER }, + /* + ** .pp + ** This variable contains the path to the Mixmaster binary on your + ** system. It is used with various sets of parameters to gather the + ** list of known remailers, and to finally send a message through the + ** mixmaster chain. + */ + { "move", DT_QUAD, R_NONE, &Move, MUTT_NO }, + /* + ** .pp + ** Controls whether or not NeoMutt will move read messages + ** from your spool mailbox to your $$mbox mailbox, or as a result of + ** a ``$mbox-hook'' command. + */ + { "narrow_tree", DT_BOOL, R_TREE|R_INDEX, &NarrowTree, 0 }, + /* + ** .pp + ** This variable, when \fIset\fP, makes the thread tree narrower, allowing + ** deeper threads to fit on the screen. + */ + { "net_inc", DT_NUMBER, R_NONE, &NetInc, 10 }, + /* + ** .pp + ** Operations that expect to transfer a large amount of data over the + ** network will update their progress every $$net_inc kilobytes. + ** If set to 0, no progress messages will be displayed. + ** .pp + ** See also $$read_inc, $$write_inc and $$net_inc. + */ + { "new_mail_command", DT_PATH, R_NONE, &NewMailCommand, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will call this command after a new message is received. + ** See the $$status_format documentation for the values that can be formatted + ** into this command. + */ + { "news_cache_dir", DT_PATH, R_NONE, &NewsCacheDir, IP "~/.neomutt" }, + /* + ** .pp + ** This variable pointing to directory where NeoMutt will save cached news + ** articles and headers in. If \fIunset\fP, articles and headers will not be + ** saved at all and will be reloaded from the server each time. + */ + { "news_server", DT_STRING, R_NONE, &NewsServer, 0 }, + /* + ** .pp + ** This variable specifies domain name or address of NNTP server. It + ** defaults to the news server specified in the environment variable + ** $$$NNTPSERVER or contained in the file /etc/nntpserver. You can also + ** specify username and an alternative port for each news server, ie: + ** .pp + ** [[s]news://][username[:password]@]server[:port] + */ + { "newsgroups_charset", DT_STRING, R_NONE, &NewsgroupsCharset, IP "utf-8" }, + /* + ** .pp + ** Character set of newsgroups descriptions. + */ + { "newsrc", DT_PATH, R_NONE, &NewsRc, IP "~/.newsrc" }, + /* + ** .pp + ** The file, containing info about subscribed newsgroups - names and + ** indexes of read articles. The following printf-style sequence + ** is understood: + ** .dl + ** .dt %a .dd Account url + ** .dt %p .dd Port + ** .dt %P .dd Port if specified + ** .dt %s .dd News server name + ** .dt %S .dd Url schema + ** .dt %u .dd Username + ** .de + */ + { "nntp_authenticators", DT_STRING, R_NONE, &NntpAuthenticators, 0 }, + /* + ** .pp + ** This is a colon-delimited list of authentication methods NeoMutt may + ** attempt to use to log in to a news server, in the order NeoMutt should + ** try them. Authentication methods are either ``user'' or any + ** SASL mechanism, e.g. ``digest-md5'', ``gssapi'' or ``cram-md5''. + ** This option is case-insensitive. If it's \fIunset\fP (the default) + ** NeoMutt will try all available methods, in order from most-secure to + ** least-secure. + ** .pp + ** Example: + ** .ts + ** set nntp_authenticators="digest-md5:user" + ** .te + ** .pp + ** \fBNote:\fP NeoMutt will only fall back to other authentication methods if + ** the previous methods are unavailable. If a method is available but + ** authentication fails, NeoMutt will not connect to the IMAP server. + */ + { "nntp_context", DT_NUMBER, R_NONE, &NntpContext, 1000 }, + /* + ** .pp + ** This variable defines number of articles which will be in index when + ** newsgroup entered. If active newsgroup have more articles than this + ** number, oldest articles will be ignored. Also controls how many + ** articles headers will be saved in cache when you quit newsgroup. + */ + { "nntp_listgroup", DT_BOOL, R_NONE, &NntpListgroup, 1 }, + /* + ** .pp + ** This variable controls whether or not existence of each article is + ** checked when newsgroup is entered. + */ + { "nntp_load_description", DT_BOOL, R_NONE, &NntpLoadDescription, 1 }, + /* + ** .pp + ** This variable controls whether or not descriptions for each newsgroup + ** must be loaded when newsgroup is added to list (first time list + ** loading or new newsgroup adding). + */ + { "nntp_user", DT_STRING, R_NONE|F_SENSITIVE, &NntpUser, IP "" }, + /* + ** .pp + ** Your login name on the NNTP server. If \fIunset\fP and NNTP server requires + ** authentication, NeoMutt will prompt you for your account name when you + ** connect to news server. + */ + { "nntp_pass", DT_STRING, R_NONE|F_SENSITIVE, &NntpPass, IP "" }, + /* + ** .pp + ** Your password for NNTP account. + */ + { "nntp_poll", DT_NUMBER, R_NONE, &NntpPoll, 60 }, + /* + ** .pp + ** The time in seconds until any operations on newsgroup except post new + ** article will cause recheck for new news. If set to 0, NeoMutt will + ** recheck newsgroup on each operation in index (stepping, read article, + ** etc.). + */ + { "nm_open_timeout", DT_NUMBER, R_NONE, &NmOpenTimeout, 5 }, + /* + ** .pp + ** This variable specifies the timeout for database open in seconds. + */ + { "nm_default_uri", DT_STRING, R_NONE, &NmDefaultUri, 0 }, + /* + ** .pp + ** This variable specifies the default Notmuch database in format + ** notmuch://. + */ + { "nm_exclude_tags", DT_STRING, R_NONE, &NmExcludeTags, 0 }, + /* + ** .pp + ** The messages tagged with these tags are excluded and not loaded + ** from notmuch DB to NeoMutt unless specified explicitly. + */ + { "nm_unread_tag", DT_STRING, R_NONE, &NmUnreadTag, IP "unread" }, + /* + ** .pp + ** This variable specifies notmuch tag which is used for unread messages. The + ** variable is used to count unread messages in DB only. All other NeoMutt commands + ** use standard (e.g. maildir) flags. + */ + { "nm_db_limit", DT_NUMBER, R_NONE, &NmDbLimit, 0 }, + /* + ** .pp + ** This variable specifies the default limit used in notmuch queries. + */ + { "nm_query_type", DT_STRING, R_NONE, &NmQueryType, IP "messages" }, + /* + ** .pp + ** This variable specifies the default query type (threads or messages) used in notmuch queries. + */ + { "nm_record", DT_BOOL, R_NONE, &NmRecord, 0 }, + /* + ** .pp + ** This variable specifies if the NeoMutt record should indexed by notmuch. + */ + { "nm_record_tags", DT_STRING, R_NONE, &NmRecordTags, 0 }, + /* + ** .pp + ** This variable specifies the default tags applied to messages stored to the NeoMutt record. + ** When set to 0 this variable disable the window feature. + */ + { "nm_query_window_duration", DT_NUMBER, R_NONE, &NmQueryWindowDuration, 0 }, + /* + ** .pp + ** This variable sets the time base of a windowed notmuch query. + ** Accepted values are 'minute', 'hour', 'day', 'week', 'month', 'year' + */ + { "nm_query_window_timebase", DT_STRING, R_NONE, &NmQueryWindowTimebase, IP "week" }, + /* + ** .pp + ** This variable sets the time duration of a windowed notmuch query. + ** Accepted values all non negative integers. A value of 0 disables the feature. + */ + { "nm_query_window_current_search", DT_STRING, R_NONE, &NmQueryWindowCurrentSearch, IP "" }, + /* + ** .pp + ** This variable sets the time duration of a windowed notmuch query. + ** Accepted values all non negative integers. A value of 0 disables the feature. + */ + { "nm_query_window_current_position", DT_NUMBER, R_NONE, &NmQueryWindowCurrentPosition, 0 }, + /* + ** .pp + ** This variable contains the currently setup notmuch search for window based vfolder. + */ + { "pager", DT_PATH, R_NONE, &Pager, IP "builtin" }, + /* + ** .pp + ** This variable specifies which pager you would like to use to view + ** messages. The value ``builtin'' means to use the built-in pager, otherwise this + ** variable should specify the pathname of the external pager you would + ** like to use. + ** .pp + ** Using an external pager may have some disadvantages: Additional + ** keystrokes are necessary because you can't call NeoMutt functions + ** directly from the pager, and screen resizes cause lines longer than + ** the screen width to be badly formatted in the help menu. + */ + { "hidden_tags", DT_STRING, R_NONE, &HiddenTags, IP "unread,draft,flagged,passed,replied,attachment,signed,encrypted" }, + /* + ** .pp + ** This variable specifies private notmuch/imap tags which should not be printed + ** on screen. + */ + { "pager_context", DT_NUMBER, R_NONE, &PagerContext, 0 }, + /* + ** .pp + ** This variable controls the number of lines of context that are given + ** when displaying the next or previous page in the internal pager. By + ** default, NeoMutt will display the line after the last one on the screen + ** at the top of the next page (0 lines of context). + ** .pp + ** This variable also specifies the amount of context given for search + ** results. If positive, this many lines will be given before a match, + ** if 0, the match will be top-aligned. + */ + { "pager_format", DT_STRING, R_PAGER, &PagerFormat, IP "-%Z- %C/%m: %-20.20n %s%* -- (%P)" }, + /* + ** .pp + ** This variable controls the format of the one-line message ``status'' + ** displayed before each message in either the internal or an external + ** pager. The valid sequences are listed in the $$index_format + ** section. + */ + { "pager_index_lines",DT_NUMBER, R_PAGER, &PagerIndexLines, 0 }, + /* + ** .pp + ** Determines the number of lines of a mini-index which is shown when in + ** the pager. The current message, unless near the top or bottom of the + ** folder, will be roughly one third of the way down this mini-index, + ** giving the reader the context of a few messages before and after the + ** message. This is useful, for example, to determine how many messages + ** remain to be read in the current thread. One of the lines is reserved + ** for the status bar from the index, so a setting of 6 + ** will only show 5 lines of the actual index. A value of 0 results in + ** no index being shown. If the number of messages in the current folder + ** is less than $$pager_index_lines, then the index will only use as + ** many lines as it needs. + */ + { "pager_stop", DT_BOOL, R_NONE, &PagerStop, 0 }, + /* + ** .pp + ** When \fIset\fP, the internal-pager will \fBnot\fP move to the next message + ** when you are at the end of a message and invoke the \fC\fP + ** function. + */ + { "pgp_auto_decode", DT_BOOL, R_NONE, &PgpAutoDecode, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will automatically attempt to decrypt traditional PGP + ** messages whenever the user performs an operation which ordinarily would + ** result in the contents of the message being operated on. For example, + ** if the user displays a pgp-traditional message which has not been manually + ** checked with the \fC$\fP function, NeoMutt will automatically + ** check the message for traditional pgp. + */ + { "pgp_autoinline", DT_BOOL, R_NONE, &PgpAutoinline, 0 }, + /* + ** .pp + ** This option controls whether NeoMutt generates old-style inline + ** (traditional) PGP encrypted or signed messages under certain + ** circumstances. This can be overridden by use of the pgp menu, + ** when inline is not required. The GPGME backend does not support + ** this option. + ** .pp + ** Note that NeoMutt might automatically use PGP/MIME for messages + ** which consist of more than a single MIME part. NeoMutt can be + ** configured to ask before sending PGP/MIME messages when inline + ** (traditional) would not work. + ** .pp + ** Also see the $$pgp_mime_auto variable. + ** .pp + ** Also note that using the old-style PGP message format is \fBstrongly\fP + ** \fBdeprecated\fP. + ** (PGP only) + */ + { "pgp_check_exit", DT_BOOL, R_NONE, &PgpCheckExit, 1 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will check the exit code of the PGP subprocess when + ** signing or encrypting. A non-zero exit code means that the + ** subprocess failed. + ** (PGP only) + */ + { "pgp_clearsign_command", DT_STRING, R_NONE, &PgpClearSignCommand, 0 }, + /* + ** .pp + ** This format is used to create an old-style ``clearsigned'' PGP + ** message. Note that the use of this format is \fBstrongly\fP + ** \fBdeprecated\fP. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_decode_command", DT_STRING, R_NONE, &PgpDecodeCommand, 0 }, + /* + ** .pp + ** This format strings specifies a command which is used to decode + ** application/pgp attachments. + ** .pp + ** The PGP command formats have their own set of \fCprintf(3)\fP-like sequences: + ** .dl + ** .dt %p .dd Expands to PGPPASSFD=0 when a pass phrase is needed, to an empty + ** string otherwise. Note: This may be used with a %? construct. + ** .dt %f .dd Expands to the name of a file containing a message. + ** .dt %s .dd Expands to the name of a file containing the signature part + ** . of a \fCmultipart/signed\fP attachment when verifying it. + ** .dt %a .dd The value of $$pgp_sign_as. + ** .dt %r .dd One or more key IDs (or fingerprints if available). + ** .de + ** .pp + ** For examples on how to configure these formats for the various versions + ** of PGP which are floating around, see the pgp and gpg sample configuration files in + ** the \fCsamples/\fP subdirectory which has been installed on your system + ** alongside the documentation. + ** (PGP only) + */ + { "pgp_decrypt_command", DT_STRING, R_NONE, &PgpDecryptCommand, 0 }, + /* + ** .pp + ** This command is used to decrypt a PGP encrypted message. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_decryption_okay", DT_REGEX, R_NONE, &PgpDecryptionOkay, 0 }, + /* + ** .pp + ** If you assign text to this variable, then an encrypted PGP + ** message is only considered successfully decrypted if the output + ** from $$pgp_decrypt_command contains the text. This is used to + ** protect against a spoofed encrypted message, with multipart/encrypted + ** headers but containing a block that is not actually encrypted. + ** (e.g. simply signed and ascii armored text). + ** (PGP only) + */ + { "pgp_encrypt_only_command", DT_STRING, R_NONE, &PgpEncryptOnlyCommand, 0 }, + /* + ** .pp + ** This command is used to encrypt a body part without signing it. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_encrypt_sign_command", DT_STRING, R_NONE, &PgpEncryptSignCommand, 0 }, + /* + ** .pp + ** This command is used to both sign and encrypt a body part. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_entry_format", DT_STRING, R_NONE, &PgpEntryFormat, IP "%4n %t%f %4l/0x%k %-4a %2c %u" }, + /* + ** .pp + ** This variable allows you to customize the PGP key selection menu to + ** your personal taste. This string is similar to $$index_format, but + ** has its own set of \fCprintf(3)\fP-like sequences: + ** .dl + ** .dt %a .dd Algorithm + ** .dt %c .dd Capabilities + ** .dt %f .dd Flags + ** .dt %k .dd Key id + ** .dt %l .dd Key length + ** .dt %n .dd Number + ** .dt %p .dd Protocol + ** .dt %t .dd Trust/validity of the key-uid association + ** .dt %u .dd User id + ** .dt %[] .dd Date of the key where is an \fCstrftime(3)\fP expression + ** .de + ** .pp + ** (PGP only) + */ + { "pgp_export_command", DT_STRING, R_NONE, &PgpExportCommand, 0 }, + /* + ** .pp + ** This command is used to export a public key from the user's + ** key ring. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_getkeys_command", DT_STRING, R_NONE, &PgpGetkeysCommand, 0 }, + /* + ** .pp + ** This command is invoked whenever NeoMutt needs to fetch the public key associated with + ** an email address. Of the sequences supported by $$pgp_decode_command, %r is + ** the only \fCprintf(3)\fP-like sequence used with this format. Note that + ** in this case, %r expands to the email address, not the public key ID (the key ID is + ** unknown, which is why NeoMutt is invoking this command). + ** (PGP only) + */ + { "pgp_good_sign", DT_REGEX, R_NONE, &PgpGoodSign, 0 }, + /* + ** .pp + ** If you assign a text to this variable, then a PGP signature is only + ** considered verified if the output from $$pgp_verify_command contains + ** the text. Use this variable if the exit code from the command is 0 + ** even for bad signatures. + ** (PGP only) + */ + { "pgp_ignore_subkeys", DT_BOOL, R_NONE, &PgpIgnoreSubkeys, 1 }, + /* + ** .pp + ** Setting this variable will cause NeoMutt to ignore OpenPGP subkeys. Instead, + ** the principal key will inherit the subkeys' capabilities. \fIUnset\fP this + ** if you want to play interesting key selection games. + ** (PGP only) + */ + { "pgp_import_command", DT_STRING, R_NONE, &PgpImportCommand, 0 }, + /* + ** .pp + ** This command is used to import a key from a message into + ** the user's public key ring. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_list_pubring_command", DT_STRING, R_NONE, &PgpListPubringCommand, 0 }, + /* + ** .pp + ** This command is used to list the public key ring's contents. The + ** output format must be analogous to the one used by + ** .ts + ** gpg --list-keys --with-colons --with-fingerprint + ** .te + ** .pp + ** This format is also generated by the \fCpgpring\fP utility which comes + ** with NeoMutt. + ** .pp + ** Note: gpg's \fCfixed-list-mode\fP option should not be used. It + ** produces a different date format which may result in NeoMutt showing + ** incorrect key generation dates. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_list_secring_command", DT_STRING, R_NONE, &PgpListSecringCommand, 0 }, + /* + ** .pp + ** This command is used to list the secret key ring's contents. The + ** output format must be analogous to the one used by: + ** .ts + ** gpg --list-keys --with-colons --with-fingerprint + ** .te + ** .pp + ** This format is also generated by the \fCpgpring\fP utility which comes + ** with NeoMutt. + ** .pp + ** Note: gpg's \fCfixed-list-mode\fP option should not be used. It + ** produces a different date format which may result in NeoMutt showing + ** incorrect key generation dates. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_long_ids", DT_BOOL, R_NONE, &PgpLongIds, 1 }, + /* + ** .pp + ** If \fIset\fP, use 64 bit PGP key IDs, if \fIunset\fP use the normal 32 bit key IDs. + ** NOTE: Internally, NeoMutt has transitioned to using fingerprints (or long key IDs + ** as a fallback). This option now only controls the display of key IDs + ** in the key selection menu and a few other places. + ** (PGP only) + */ + { "pgp_mime_auto", DT_QUAD, R_NONE, &PgpMimeAuto, MUTT_ASKYES }, + /* + ** .pp + ** This option controls whether NeoMutt will prompt you for + ** automatically sending a (signed/encrypted) message using + ** PGP/MIME when inline (traditional) fails (for any reason). + ** .pp + ** Also note that using the old-style PGP message format is \fBstrongly\fP + ** \fBdeprecated\fP. + ** (PGP only) + */ + { "pgp_replyinline", DT_BOOL, R_NONE, &PgpReplyinline, 0 }, + /* + ** .pp + ** Setting this variable will cause NeoMutt to always attempt to + ** create an inline (traditional) message when replying to a + ** message which is PGP encrypted/signed inline. This can be + ** overridden by use of the pgp menu, when inline is not + ** required. This option does not automatically detect if the + ** (replied-to) message is inline; instead it relies on NeoMutt + ** internals for previously checked/flagged messages. + ** .pp + ** Note that NeoMutt might automatically use PGP/MIME for messages + ** which consist of more than a single MIME part. NeoMutt can be + ** configured to ask before sending PGP/MIME messages when inline + ** (traditional) would not work. + ** .pp + ** Also see the $$pgp_mime_auto variable. + ** .pp + ** Also note that using the old-style PGP message format is \fBstrongly\fP + ** \fBdeprecated\fP. + ** (PGP only) + ** + */ + { "pgp_retainable_sigs", DT_BOOL, R_NONE, &PgpRetainableSigs, 0 }, + /* + ** .pp + ** If \fIset\fP, signed and encrypted messages will consist of nested + ** \fCmultipart/signed\fP and \fCmultipart/encrypted\fP body parts. + ** .pp + ** This is useful for applications like encrypted and signed mailing + ** lists, where the outer layer (\fCmultipart/encrypted\fP) can be easily + ** removed, while the inner \fCmultipart/signed\fP part is retained. + ** (PGP only) + */ + { "pgp_self_encrypt", DT_BOOL, R_NONE, &PgpSelfEncrypt, 0 }, + /* + ** .pp + ** When \fIset\fP, PGP encrypted messages will also be encrypted + ** using the key in $$pgp_self_encrypt_as. + ** (PGP only) + */ + { "pgp_self_encrypt_as", DT_STRING, R_NONE, &PgpSelfEncryptAs, 0 }, + /* + ** .pp + ** This is an additional key used to encrypt messages when $$pgp_self_encrypt + ** is \fIset\fP. It is also used to specify the key for $$postpone_encrypt. + ** It should be in keyid or fingerprint form (e.g. 0x00112233). + ** (PGP only) + */ + { "pgp_show_unusable", DT_BOOL, R_NONE, &PgpShowUnusable, 1 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will display non-usable keys on the PGP key selection + ** menu. This includes keys which have been revoked, have expired, or + ** have been marked as ``disabled'' by the user. + ** (PGP only) + */ + { "pgp_sign_as", DT_STRING, R_NONE, &PgpSignAs, 0 }, + /* + ** .pp + ** If you have more than one key pair, this option allows you to specify + ** which of your private keys to use. It is recommended that you use the + ** keyid form to specify your key (e.g. \fC0x00112233\fP). + ** (PGP only) + */ + { "pgp_sign_command", DT_STRING, R_NONE, &PgpSignCommand, 0 }, + /* + ** .pp + ** This command is used to create the detached PGP signature for a + ** \fCmultipart/signed\fP PGP/MIME body part. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_sort_keys", DT_SORT|DT_SORT_KEYS, R_NONE, &PgpSortKeys, SORT_ADDRESS }, + /* + ** .pp + ** Specifies how the entries in the pgp menu are sorted. The + ** following are legal values: + ** .dl + ** .dt address .dd sort alphabetically by user id + ** .dt keyid .dd sort alphabetically by key id + ** .dt date .dd sort by key creation date + ** .dt trust .dd sort by the trust of the key + ** .de + ** .pp + ** If you prefer reverse order of the above values, prefix it with + ** ``reverse-''. + ** (PGP only) + */ + { "pgp_strict_enc", DT_BOOL, R_NONE, &PgpStrictEnc, 1 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will automatically encode PGP/MIME signed messages as + ** quoted-printable. Please note that unsetting this variable may + ** lead to problems with non-verifyable PGP signatures, so only change + ** this if you know what you are doing. + ** (PGP only) + */ + { "pgp_timeout", DT_NUMBER, R_NONE, &PgpTimeout, 300 }, + /* + ** .pp + ** The number of seconds after which a cached passphrase will expire if + ** not used. + ** (PGP only) + */ + { "pgp_use_gpg_agent", DT_BOOL, R_NONE, &PgpUseGpgAgent, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will use a possibly-running \fCgpg-agent(1)\fP process. + ** Note that as of version 2.1, GnuPG no longer exports GPG_AGENT_INFO, so + ** NeoMutt no longer verifies if the agent is running. + ** (PGP only) + */ + { "pgp_verify_command", DT_STRING, R_NONE, &PgpVerifyCommand, 0 }, + /* + ** .pp + ** This command is used to verify PGP signatures. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pgp_verify_key_command", DT_STRING, R_NONE, &PgpVerifyKeyCommand, 0 }, + /* + ** .pp + ** This command is used to verify key information from the key selection + ** menu. + ** .pp + ** This is a format string, see the $$pgp_decode_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (PGP only) + */ + { "pipe_decode", DT_BOOL, R_NONE, &PipeDecode, 0 }, + /* + ** .pp + ** Used in connection with the \fC\fP command. When \fIunset\fP, + ** NeoMutt will pipe the messages without any preprocessing. When \fIset\fP, NeoMutt + ** will weed headers and will attempt to decode the messages + ** first. + */ + { "pipe_sep", DT_STRING, R_NONE, &PipeSep, IP "\n" }, + /* + ** .pp + ** The separator to add between messages when piping a list of tagged + ** messages to an external Unix command. + */ + { "pipe_split", DT_BOOL, R_NONE, &PipeSplit, 0 }, + /* + ** .pp + ** Used in connection with the \fC\fP function following + ** \fC\fP. If this variable is \fIunset\fP, when piping a list of + ** tagged messages NeoMutt will concatenate the messages and will pipe them + ** all concatenated. When \fIset\fP, NeoMutt will pipe the messages one by one. + ** In both cases the messages are piped in the current sorted order, + ** and the $$pipe_sep separator is added after each message. + */ + { "pop_auth_try_all", DT_BOOL, R_NONE, &PopAuthTryAll, 1 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will try all available authentication methods. + ** When \fIunset\fP, NeoMutt will only fall back to other authentication + ** methods if the previous methods are unavailable. If a method is + ** available but authentication fails, NeoMutt will not connect to the POP server. + */ + { "pop_authenticators", DT_STRING, R_NONE, &PopAuthenticators, 0 }, + /* + ** .pp + ** This is a colon-delimited list of authentication methods NeoMutt may + ** attempt to use to log in to an POP server, in the order NeoMutt should + ** try them. Authentication methods are either ``user'', ``apop'' or any + ** SASL mechanism, e.g. ``digest-md5'', ``gssapi'' or ``cram-md5''. + ** This option is case-insensitive. If this option is \fIunset\fP + ** (the default) NeoMutt will try all available methods, in order from + ** most-secure to least-secure. + ** .pp + ** Example: + ** .ts + ** set pop_authenticators="digest-md5:apop:user" + ** .te + */ + { "pop_checkinterval", DT_NUMBER, R_NONE, &PopCheckinterval, 60 }, + /* + ** .pp + ** This variable configures how often (in seconds) NeoMutt should look for + ** new mail in the currently selected mailbox if it is a POP mailbox. + */ + { "pop_delete", DT_QUAD, R_NONE, &PopDelete, MUTT_ASKNO }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will delete successfully downloaded messages from the POP + ** server when using the \fC$\fP function. When \fIunset\fP, NeoMutt will + ** download messages but also leave them on the POP server. + */ + { "pop_host", DT_STRING, R_NONE, &PopHost, IP "" }, + /* + ** .pp + ** The name of your POP server for the \fC$\fP function. You + ** can also specify an alternative port, username and password, i.e.: + ** .ts + ** [pop[s]://][username[:password]@]popserver[:port] + ** .te + ** .pp + ** where ``[...]'' denotes an optional part. + */ + { "pop_last", DT_BOOL, R_NONE, &PopLast, 0 }, + /* + ** .pp + ** If this variable is \fIset\fP, NeoMutt will try to use the ``\fCLAST\fP'' POP command + ** for retrieving only unread messages from the POP server when using + ** the \fC$\fP function. + */ + { "pop_pass", DT_STRING, R_NONE|F_SENSITIVE, &PopPass, IP "" }, + /* + ** .pp + ** Specifies the password for your POP account. If \fIunset\fP, NeoMutt will + ** prompt you for your password when you open a POP mailbox. + ** .pp + ** \fBWarning\fP: you should only use this option when you are on a + ** fairly secure machine, because the superuser can read your neomuttrc + ** even if you are the only one who can read the file. + */ + { "pop_reconnect", DT_QUAD, R_NONE, &PopReconnect, MUTT_ASKYES }, + /* + ** .pp + ** Controls whether or not NeoMutt will try to reconnect to the POP server if + ** the connection is lost. + */ + { "pop_user", DT_STRING, R_NONE|F_SENSITIVE, &PopUser, 0 }, + /* + ** .pp + ** Your login name on the POP server. + ** .pp + ** This variable defaults to your user name on the local machine. + */ + { "post_indent_string",DT_STRING, R_NONE, &PostIndentString, IP "" }, + /* + ** .pp + ** Similar to the $$attribution variable, NeoMutt will append this + ** string after the inclusion of a message which is being replied to. + */ + { "post_moderated", DT_QUAD, R_NONE, &PostModerated, MUTT_ASKYES }, + /* + ** .pp + ** If set to \fIyes\fP, NeoMutt will post article to newsgroup that have + ** not permissions to posting (e.g. moderated). \fBNote:\fP if news server + ** does not support posting to that newsgroup or totally read-only, that + ** posting will not have an effect. + */ + { "postpone", DT_QUAD, R_NONE, &Postpone, MUTT_ASKYES }, + /* + ** .pp + ** Controls whether or not messages are saved in the $$postponed + ** mailbox when you elect not to send immediately. + ** .pp + ** Also see the $$recall variable. + */ + { "postponed", DT_PATH, R_INDEX, &Postponed, IP "~/postponed" }, + /* + ** .pp + ** NeoMutt allows you to indefinitely ``$postpone sending a message'' which + ** you are editing. When you choose to postpone a message, NeoMutt saves it + ** in the mailbox specified by this variable. + ** .pp + ** Also see the $$postpone variable. + */ + { "postpone_encrypt", DT_BOOL, R_NONE, &PostponeEncrypt, 0 }, + /* + ** .pp + ** When \fIset\fP, postponed messages that are marked for encryption will be + ** self-encrypted. NeoMutt will first try to encrypt using the value specified + ** in $$pgp_self_encrypt_as or $$smime_self_encrypt_as. If those are not + ** set, it will try the deprecated $$postpone_encrypt_as. + ** (Crypto only) + */ + { "postpone_encrypt_as", DT_STRING, R_NONE, &PostponeEncryptAs, 0 }, + /* + ** .pp + ** This is a deprecated fall-back variable for $$postpone_encrypt. + ** Please use $$pgp_self_encrypt_as or $$smime_self_encrypt_as. + ** (Crypto only) + */ + { "preconnect", DT_STRING, R_NONE, &Preconnect, 0 }, + /* + ** .pp + ** If \fIset\fP, a shell command to be executed if NeoMutt fails to establish + ** a connection to the server. This is useful for setting up secure + ** connections, e.g. with \fCssh(1)\fP. If the command returns a nonzero + ** status, NeoMutt gives up opening the server. Example: + ** .ts + ** set preconnect="ssh -f -q -L 1234:mailhost.net:143 mailhost.net \(rs + ** sleep 20 < /dev/null > /dev/null" + ** .te + ** .pp + ** Mailbox ``foo'' on ``mailhost.net'' can now be reached + ** as ``{localhost:1234}foo''. + ** .pp + ** Note: For this example to work, you must be able to log in to the + ** remote machine without having to enter a password. + */ + { "print", DT_QUAD, R_NONE, &Print, MUTT_ASKNO }, + /* + ** .pp + ** Controls whether or not NeoMutt really prints messages. + ** This is set to ``ask-no'' by default, because some people + ** accidentally hit ``p'' often. + */ + { "print_command", DT_PATH, R_NONE, &PrintCommand, IP "lpr" }, + /* + ** .pp + ** This specifies the command pipe that should be used to print messages. + */ + { "print_decode", DT_BOOL, R_NONE, &PrintDecode, 1 }, + /* + ** .pp + ** Used in connection with the \fC\fP command. If this + ** option is \fIset\fP, the message is decoded before it is passed to the + ** external command specified by $$print_command. If this option + ** is \fIunset\fP, no processing will be applied to the message when + ** printing it. The latter setting may be useful if you are using + ** some advanced printer filter which is able to properly format + ** e-mail messages for printing. + */ + { "print_split", DT_BOOL, R_NONE, &PrintSplit, 0 }, + /* + ** .pp + ** Used in connection with the \fC\fP command. If this option + ** is \fIset\fP, the command specified by $$print_command is executed once for + ** each message which is to be printed. If this option is \fIunset\fP, + ** the command specified by $$print_command is executed only once, and + ** all the messages are concatenated, with a form feed as the message + ** separator. + ** .pp + ** Those who use the \fCenscript\fP(1) program's mail-printing mode will + ** most likely want to \fIset\fP this option. + */ + { "prompt_after", DT_BOOL, R_NONE, &PromptAfter, 1 }, + /* + ** .pp + ** If you use an \fIexternal\fP $$pager, setting this variable will + ** cause NeoMutt to prompt you for a command when the pager exits rather + ** than returning to the index menu. If \fIunset\fP, NeoMutt will return to the + ** index menu when the external pager exits. + */ + { "query_command", DT_PATH, R_NONE, &QueryCommand, IP "" }, + /* + ** .pp + ** This specifies the command NeoMutt will use to make external address + ** queries. The string may contain a ``%s'', which will be substituted + ** with the query string the user types. NeoMutt will add quotes around the + ** string substituted for ``%s'' automatically according to shell quoting + ** rules, so you should avoid adding your own. If no ``%s'' is found in + ** the string, NeoMutt will append the user's query to the end of the string. + ** See ``$query'' for more information. + */ + { "query_format", DT_STRING, R_NONE, &QueryFormat, IP "%4c %t %-25.25a %-25.25n %?e?(%e)?" }, + /* + ** .pp + ** This variable describes the format of the ``query'' menu. The + ** following \fCprintf(3)\fP-style sequences are understood: + ** .dl + ** .dt %a .dd Destination address + ** .dt %c .dd Current entry number + ** .dt %e .dd Extra information * + ** .dt %n .dd Destination name + ** .dt %t .dd ``*'' if current entry is tagged, a space otherwise + ** .dt %>X .dd Right justify the rest of the string and pad with ``X'' + ** .dt %|X .dd Pad to the end of the line with ``X'' + ** .dt %*X .dd Soft-fill with character ``X'' as pad + ** .de + ** .pp + ** For an explanation of ``soft-fill'', see the $$index_format documentation. + ** .pp + ** * = can be optionally printed if nonzero, see the $$status_format documentation. + */ + { "quit", DT_QUAD, R_NONE, &Quit, MUTT_YES }, + /* + ** .pp + ** This variable controls whether ``quit'' and ``exit'' actually quit + ** from NeoMutt. If this option is \fIset\fP, they do quit, if it is \fIunset\fP, they + ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are + ** prompted for confirmation when you try to quit. + */ + { "quote_regexp", DT_REGEX, R_PAGER, &QuoteRegexp, IP "^([ \t]*[|>:}#])+" }, + /* + ** .pp + ** A regular expression used in the internal pager to determine quoted + ** sections of text in the body of a message. Quoted text may be filtered + ** out using the \fC\fP command, or colored according to the + ** ``color quoted'' family of directives. + ** .pp + ** Higher levels of quoting may be colored differently (``color quoted1'', + ** ``color quoted2'', etc.). The quoting level is determined by removing + ** the last character from the matched text and recursively reapplying + ** the regular expression until it fails to produce a match. + ** .pp + ** Match detection may be overridden by the $$smileys regular expression. + */ + { "read_inc", DT_NUMBER, R_NONE, &ReadInc, 10 }, + /* + ** .pp + ** If set to a value greater than 0, NeoMutt will display which message it + ** is currently on when reading a mailbox or when performing search actions + ** such as search and limit. The message is printed after + ** this many messages have been read or searched (e.g., if set to 25, NeoMutt will + ** print a message when it is at message 25, and then again when it gets + ** to message 50). This variable is meant to indicate progress when + ** reading or searching large mailboxes which may take some time. + ** When set to 0, only a single message will appear before the reading + ** the mailbox. + ** .pp + ** Also see the $$write_inc, $$net_inc and $$time_inc variables and the + ** ``$tuning'' section of the manual for performance considerations. + */ + { "read_only", DT_BOOL, R_NONE, &ReadOnly, 0 }, + /* + ** .pp + ** If \fIset\fP, all folders are opened in read-only mode. + */ + { "realname", DT_STRING, R_BOTH, &RealName, 0 }, + /* + ** .pp + ** This variable specifies what ``real'' or ``personal'' name should be used + ** when sending messages. + ** .pp + ** By default, this is the GECOS field from \fC/etc/passwd\fP. Note that this + ** variable will \fInot\fP be used when the user has set a real name + ** in the $$from variable. + */ + { "recall", DT_QUAD, R_NONE, &Recall, MUTT_ASKYES }, + /* + ** .pp + ** Controls whether or not NeoMutt recalls postponed messages + ** when composing a new message. + ** .pp + ** Setting this variable to \fIyes\fP is not generally useful, and thus not + ** recommended. Note that the \fC\fP function can be used + ** to manually recall postponed messages. + ** .pp + ** Also see $$postponed variable. + */ + { "record", DT_PATH, R_NONE, &Record, IP "~/sent" }, + /* + ** .pp + ** This specifies the file into which your outgoing messages should be + ** appended. (This is meant as the primary method for saving a copy of + ** your messages, but another way to do this is using the ``$my_hdr'' + ** command to create a ``Bcc:'' field with your email address in it.) + ** .pp + ** The value of \fI$$record\fP is overridden by the $$force_name and + ** $$save_name variables, and the ``$fcc-hook'' command. + */ + { "reflow_space_quotes", DT_BOOL, R_NONE, &ReflowSpaceQuotes, 1 }, + /* + ** .pp + ** This option controls how quotes from format=flowed messages are displayed + ** in the pager and when replying (with $$text_flowed \fIunset\fP). + ** When set, this option adds spaces after each level of quote marks, turning + ** ">>>foo" into "> > > foo". + ** .pp + ** \fBNote:\fP If $$reflow_text is \fIunset\fP, this option has no effect. + ** Also, this option does not affect replies when $$text_flowed is \fIset\fP. + */ + { "reflow_text", DT_BOOL, R_NONE, &ReflowText, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will reformat paragraphs in text/plain + ** parts marked format=flowed. If \fIunset\fP, NeoMutt will display paragraphs + ** unaltered from how they appear in the message body. See RFC3676 for + ** details on the \fIformat=flowed\fP format. + ** .pp + ** Also see $$reflow_wrap, and $$wrap. + */ + { "reflow_wrap", DT_NUMBER, R_NONE, &ReflowWrap, 78 }, + /* + ** .pp + ** This variable controls the maximum paragraph width when reformatting text/plain + ** parts when $$reflow_text is \fIset\fP. When the value is 0, paragraphs will + ** be wrapped at the terminal's right margin. A positive value sets the + ** paragraph width relative to the left margin. A negative value set the + ** paragraph width relative to the right margin. + ** .pp + ** Also see $$wrap. + */ + { "reply_regexp", DT_REGEX, R_INDEX|R_RESORT, &ReplyRegexp, IP "^(re([\\[0-9\\]+])*|aw):[ \t]*" }, + /* + ** .pp + ** A regular expression used to recognize reply messages when threading + ** and replying. The default value corresponds to the English "Re:" and + ** the German "Aw:". + */ + { "reply_self", DT_BOOL, R_NONE, &ReplySelf, 0 }, + /* + ** .pp + ** If \fIunset\fP and you are replying to a message sent by you, NeoMutt will + ** assume that you want to reply to the recipients of that message rather + ** than to yourself. + ** .pp + ** Also see the ``$alternates'' command. + */ + { "reply_to", DT_QUAD, R_NONE, &ReplyTo, MUTT_ASKYES }, + /* + ** .pp + ** If \fIset\fP, when replying to a message, NeoMutt will use the address listed + ** in the Reply-to: header as the recipient of the reply. If \fIunset\fP, + ** it will use the address in the From: header field instead. This + ** option is useful for reading a mailing list that sets the Reply-To: + ** header field to the list address and you want to send a private + ** message to the author of a message. + */ + { "reply_with_xorig", DT_BOOL, R_NONE, &ReplyWithXorig, 0 }, + /* + ** .pp + ** This variable provides a toggle. When active, the From: header will be + ** extracted from the current mail's `X-Original-To:' header. This setting + ** does not have precedence over ``$reverse_realname''. + ** .pp + ** Assuming `fast_reply' is disabled, this option will prompt the user with a + ** prefilled From: header. + */ + { "resolve", DT_BOOL, R_NONE, &Resolve, 1 }, + /* + ** .pp + ** When \fIset\fP, the cursor will be automatically advanced to the next + ** (possibly undeleted) message whenever a command that modifies the + ** current message is executed. + */ + { "resume_draft_files", DT_BOOL, R_NONE, &ResumeDraftFiles, 0 }, + /* + ** .pp + ** If \fIset\fP, draft files (specified by \fC-H\fP on the command + ** line) are processed similarly to when resuming a postponed + ** message. Recipients are not prompted for; send-hooks are not + ** evaluated; no alias expansion takes place; user-defined headers + ** and signatures are not added to the message. + */ + { "resume_edited_draft_files", DT_BOOL, R_NONE, &ResumeEditedDraftFiles, 1 }, + /* + ** .pp + ** If \fIset\fP, draft files previously edited (via \fC-E -H\fP on + ** the command line) will have $$resume_draft_files automatically + ** set when they are used as a draft file again. + ** .pp + ** The first time a draft file is saved, NeoMutt will add a header, + ** X-Mutt-Resume-Draft to the saved file. The next time the draft + ** file is read in, if NeoMutt sees the header, it will set + ** $$resume_draft_files. + ** .pp + ** This option is designed to prevent multiple signatures, + ** user-defined headers, and other processing effects from being + ** made multiple times to the draft file. + */ + { "reverse_alias", DT_BOOL, R_BOTH, &ReverseAlias, 0 }, + /* + ** .pp + ** This variable controls whether or not NeoMutt will display the ``personal'' + ** name from your aliases in the index menu if it finds an alias that + ** matches the message's sender. For example, if you have the following + ** alias: + ** .ts + ** alias juser abd30425@somewhere.net (Joe User) + ** .te + ** .pp + ** and then you receive mail which contains the following header: + ** .ts + ** From: abd30425@somewhere.net + ** .te + ** .pp + ** It would be displayed in the index menu as ``Joe User'' instead of + ** ``abd30425@somewhere.net.'' This is useful when the person's e-mail + ** address is not human friendly. + */ + { "reverse_name", DT_BOOL, R_BOTH, &ReverseName, 0 }, + /* + ** .pp + ** It may sometimes arrive that you receive mail to a certain machine, + ** move the messages to another machine, and reply to some the messages + ** from there. If this variable is \fIset\fP, the default \fIFrom:\fP line of + ** the reply messages is built using the address where you received the + ** messages you are replying to \fBif\fP that address matches your + ** ``$alternates''. If the variable is \fIunset\fP, or the address that would be + ** used doesn't match your ``$alternates'', the \fIFrom:\fP line will use + ** your address on the current machine. + ** .pp + ** Also see the ``$alternates'' command. + */ + { "reverse_realname", DT_BOOL, R_BOTH, &ReverseRealname, 1 }, + /* + ** .pp + ** This variable fine-tunes the behavior of the $$reverse_name feature. + ** When it is \fIset\fP, NeoMutt will use the address from incoming messages as-is, + ** possibly including eventual real names. When it is \fIunset\fP, NeoMutt will + ** override any such real names with the setting of the $$realname variable. + */ + { "rfc2047_parameters", DT_BOOL, R_NONE, &Rfc2047Parameters, 0 }, + /* + ** .pp + ** When this variable is \fIset\fP, NeoMutt will decode RFC2047-encoded MIME + ** parameters. You want to set this variable when NeoMutt suggests you + ** to save attachments to files named like: + ** .ts + ** =?iso-8859-1?Q?file=5F=E4=5F991116=2Ezip?= + ** .te + ** .pp + ** When this variable is \fIset\fP interactively, the change won't be + ** active until you change folders. + ** .pp + ** Note that this use of RFC2047's encoding is explicitly + ** prohibited by the standard, but nevertheless encountered in the + ** wild. + ** .pp + ** Also note that setting this parameter will \fInot\fP have the effect + ** that NeoMutt \fIgenerates\fP this kind of encoding. Instead, NeoMutt will + ** unconditionally use the encoding specified in RFC2231. + */ + { "save_address", DT_BOOL, R_NONE, &SaveAddress, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will take the sender's full address when choosing a + ** default folder for saving a mail. If $$save_name or $$force_name + ** is \fIset\fP too, the selection of the Fcc folder will be changed as well. + */ + { "save_empty", DT_BOOL, R_NONE, &SaveEmpty, 1 }, + /* + ** .pp + ** When \fIunset\fP, mailboxes which contain no saved messages will be removed + ** when closed (the exception is $$spoolfile which is never removed). + ** If \fIset\fP, mailboxes are never removed. + ** .pp + ** \fBNote:\fP This only applies to mbox and MMDF folders, NeoMutt does not + ** delete MH and Maildir directories. + */ + { "save_history", DT_NUMBER, R_NONE, &SaveHistory, 0 }, + /* + ** .pp + ** This variable controls the size of the history (per category) saved in the + ** $$history_file file. + */ + { "save_name", DT_BOOL, R_NONE, &SaveName, 0 }, + /* + ** .pp + ** This variable controls how copies of outgoing messages are saved. + ** When \fIset\fP, a check is made to see if a mailbox specified by the + ** recipient address exists (this is done by searching for a mailbox in + ** the $$folder directory with the \fIusername\fP part of the + ** recipient address). If the mailbox exists, the outgoing message will + ** be saved to that mailbox, otherwise the message is saved to the + ** $$record mailbox. + ** .pp + ** Also see the $$force_name variable. + */ + { "score", DT_BOOL, R_NONE, &Score, 1 }, + /* + ** .pp + ** When this variable is \fIunset\fP, scoring is turned off. This can + ** be useful to selectively disable scoring for certain folders when the + ** $$score_threshold_delete variable and related are used. + ** + */ + { "score_threshold_delete", DT_NUMBER, R_NONE, &ScoreThresholdDelete, -1 }, + /* + ** .pp + ** Messages which have been assigned a score equal to or lower than the value + ** of this variable are automatically marked for deletion by NeoMutt. Since + ** NeoMutt scores are always greater than or equal to zero, the default setting + ** of this variable will never mark a message for deletion. + */ + { "score_threshold_flag", DT_NUMBER, R_NONE, &ScoreThresholdFlag, 9999 }, + /* + ** .pp + ** Messages which have been assigned a score greater than or equal to this + ** variable's value are automatically marked "flagged". + */ + { "score_threshold_read", DT_NUMBER, R_NONE, &ScoreThresholdRead, -1 }, + /* + ** .pp + ** Messages which have been assigned a score equal to or lower than the value + ** of this variable are automatically marked as read by NeoMutt. Since + ** NeoMutt scores are always greater than or equal to zero, the default setting + ** of this variable will never mark a message read. + */ + { "search_context", DT_NUMBER, R_NONE, &SearchContext, 0 }, + /* + ** .pp + ** For the pager, this variable specifies the number of lines shown + ** before search results. By default, search results will be top-aligned. + */ + { "send_charset", DT_STRING, R_NONE, &SendCharset, IP "us-ascii:iso-8859-1:utf-8" }, + /* + ** .pp + ** A colon-delimited list of character sets for outgoing messages. NeoMutt will use the + ** first character set into which the text can be converted exactly. + ** If your $$charset is not ``iso-8859-1'' and recipients may not + ** understand ``UTF-8'', it is advisable to include in the list an + ** appropriate widely used standard character set (such as + ** ``iso-8859-2'', ``koi8-r'' or ``iso-2022-jp'') either instead of or after + ** ``iso-8859-1''. + ** .pp + ** In case the text cannot be converted into one of these exactly, + ** NeoMutt uses $$charset as a fallback. + */ + { "sendmail", DT_PATH, R_NONE, &Sendmail, IP SENDMAIL " -oem -oi" }, + /* + ** .pp + ** Specifies the program and arguments used to deliver mail sent by NeoMutt. + ** NeoMutt expects that the specified program interprets additional + ** arguments as recipient addresses. NeoMutt appends all recipients after + ** adding a \fC--\fP delimiter (if not already present). Additional + ** flags, such as for $$use_8bitmime, $$use_envelope_from, + ** $$dsn_notify, or $$dsn_return will be added before the delimiter. + */ + { "sendmail_wait", DT_NUMBER, R_NONE, &SendmailWait, 0 }, + /* + ** .pp + ** Specifies the number of seconds to wait for the $$sendmail process + ** to finish before giving up and putting delivery in the background. + ** .pp + ** NeoMutt interprets the value of this variable as follows: + ** .dl + ** .dt >0 .dd number of seconds to wait for sendmail to finish before continuing + ** .dt 0 .dd wait forever for sendmail to finish + ** .dt <0 .dd always put sendmail in the background without waiting + ** .de + ** .pp + ** Note that if you specify a value other than 0, the output of the child + ** process will be put in a temporary file. If there is some error, you + ** will be informed as to where to find the output. + */ + { "shell", DT_PATH, R_NONE, &Shell, 0 }, + /* + ** .pp + ** Command to use when spawning a subshell. By default, the user's login + ** shell from \fC/etc/passwd\fP is used. + */ + { "save_unsubscribed", DT_BOOL, R_NONE, &SaveUnsubscribed, 0 }, + /* + ** .pp + ** When \fIset\fP, info about unsubscribed newsgroups will be saved into + ** ``newsrc'' file and into cache. + */ + { "show_new_news", DT_BOOL, R_NONE, &ShowNewNews, 1 }, + /* + ** .pp + ** If \fIset\fP, news server will be asked for new newsgroups on entering + ** the browser. Otherwise, it will be done only once for a news server. + ** Also controls whether or not number of new articles of subscribed + ** newsgroups will be then checked. + */ + { "show_only_unread", DT_BOOL, R_NONE, &ShowOnlyUnread, 0 }, + /* + ** .pp + ** If \fIset\fP, only subscribed newsgroups that contain unread articles + ** will be displayed in browser. + */ + { "sidebar_delim_chars", DT_STRING, R_SIDEBAR, &SidebarDelimChars, IP "/." }, + /* + ** .pp + ** This contains the list of characters which you would like to treat + ** as folder separators for displaying paths in the sidebar. + ** .pp + ** Local mail is often arranged in directories: `dir1/dir2/mailbox'. + ** .ts + ** set sidebar_delim_chars='/' + ** .te + ** .pp + ** IMAP mailboxes are often named: `folder1.folder2.mailbox'. + ** .ts + ** set sidebar_delim_chars='.' + ** .te + ** .pp + ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_folder_indent, $$sidebar_indent_string. + */ + { "sidebar_divider_char", DT_STRING, R_SIDEBAR, &SidebarDividerChar, 0 }, + /* + ** .pp + ** This specifies the characters to be drawn between the sidebar (when + ** visible) and the other NeoMutt panels. ASCII and Unicode line-drawing + ** characters are supported. + */ + { "sidebar_folder_indent", DT_BOOL, R_SIDEBAR, &SidebarFolderIndent, 0 }, + /* + ** .pp + ** Set this to indent mailboxes in the sidebar. + ** .pp + ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_indent_string, $$sidebar_delim_chars. + */ + { "sidebar_format", DT_STRING, R_SIDEBAR, &SidebarFormat, IP "%B%* %n" }, + /* + ** .pp + ** This variable allows you to customize the sidebar display. This string is + ** similar to $$index_format, but has its own set of \fCprintf(3)\fP-like + ** sequences: + ** .dl + ** .dt %B .dd Name of the mailbox + ** .dt %S .dd * Size of mailbox (total number of messages) + ** .dt %N .dd * Number of unread messages in the mailbox + ** .dt %n .dd N if mailbox has new mail, blank otherwise + ** .dt %F .dd * Number of Flagged messages in the mailbox + ** .dt %! .dd ``!'' : one flagged message; + ** ``!!'' : two flagged messages; + ** ``n!'' : n flagged messages (for n > 2). + ** Otherwise prints nothing. + ** .dt %d .dd * @ Number of deleted messages + ** .dt %L .dd * @ Number of messages after limiting + ** .dt %t .dd * @ Number of tagged messages + ** .dt %>X .dd right justify the rest of the string and pad with ``X'' + ** .dt %|X .dd pad to the end of the line with ``X'' + ** .dt %*X .dd soft-fill with character ``X'' as pad + ** .de + ** .pp + ** * = Can be optionally printed if nonzero + ** @ = Only applicable to the current folder + ** .pp + ** In order to use %S, %N, %F, and %!, $$mail_check_stats must + ** be \fIset\fP. When thus set, a suggested value for this option is + ** "%B%?F? [%F]?%* %?N?%N/?%S". + */ + { "sidebar_indent_string", DT_STRING, R_SIDEBAR, &SidebarIndentString, IP " " }, + /* + ** .pp + ** This specifies the string that is used to indent mailboxes in the sidebar. + ** It defaults to two spaces. + ** .pp + ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_folder_indent, $$sidebar_delim_chars. + */ + { "sidebar_new_mail_only", DT_BOOL, R_SIDEBAR, &SidebarNewMailOnly, 0 }, + /* + ** .pp + ** When set, the sidebar will only display mailboxes containing new, or + ** flagged, mail. + ** .pp + ** \fBSee also:\fP $sidebar_whitelist. + */ + { "sidebar_next_new_wrap", DT_BOOL, R_NONE, &SidebarNextNewWrap, 0 }, + /* + ** .pp + ** When set, the \fC\fP command will not stop and the end of + ** the list of mailboxes, but wrap around to the beginning. The + ** \fC\fP command is similarly affected, wrapping around to + ** the end of the list. + */ + { "sidebar_on_right", DT_BOOL, R_BOTH|R_REFLOW, &SidebarOnRight, 0 }, + /* + ** .pp + ** When set, the sidebar will appear on the right-hand side of the screen. + */ + { "sidebar_short_path", DT_BOOL, R_SIDEBAR, &SidebarShortPath, 0 }, + /* + ** .pp + ** By default the sidebar will show the mailbox's path, relative to the + ** $$folder variable. Setting \fCsidebar_shortpath=yes\fP will shorten the + ** names relative to the previous name. Here's an example: + ** .dl + ** .dt \fBshortpath=no\fP .dd \fBshortpath=yes\fP .dd \fBshortpath=yes, folderindent=yes, indentstr=".."\fP + ** .dt \fCfruit\fP .dd \fCfruit\fP .dd \fCfruit\fP + ** .dt \fCfruit.apple\fP .dd \fCapple\fP .dd \fC..apple\fP + ** .dt \fCfruit.banana\fP .dd \fCbanana\fP .dd \fC..banana\fP + ** .dt \fCfruit.cherry\fP .dd \fCcherry\fP .dd \fC..cherry\fP + ** .de + ** .pp + ** \fBSee also:\fP $$sidebar_delim_chars, $$sidebar_folder_indent, + ** $$sidebar_indent_string, $$sidebar_component_depth. + */ + { "sidebar_sort_method", DT_SORT|DT_SORT_SIDEBAR, R_SIDEBAR, &SidebarSortMethod, SORT_ORDER }, + /* + ** .pp + ** Specifies how to sort entries in the file browser. By default, the + ** entries are sorted alphabetically. Valid values: + ** .il + ** .dd alpha (alphabetically) + ** .dd count (all message count) + ** .dd flagged (flagged message count) + ** .dd name (alphabetically) + ** .dd new (unread message count) + ** .dd path (alphabetically) + ** .dd unread (unread message count) + ** .dd unsorted + ** .ie + ** .pp + ** You may optionally use the ``reverse-'' prefix to specify reverse sorting + ** order (example: ``\fCset sort_browser=reverse-date\fP''). + */ + { "sidebar_component_depth", DT_NUMBER, R_SIDEBAR, &SidebarComponentDepth, 0 }, + /* + ** .pp + ** By default the sidebar will show the mailbox's path, relative to the + ** $$folder variable. This specifies the number of parent directories to hide + ** from display in the sidebar. For example: If a maildir is normally + ** displayed in the sidebar as dir1/dir2/dir3/maildir, setting + ** \fCsidebar_component_depth=2\fP will display it as dir3/maildir, having + ** truncated the 2 highest directories. + ** .pp + ** \fBSee also:\fP $$sidebar_short_path + */ + { "sidebar_visible", DT_BOOL, R_REFLOW, &SidebarVisible, 0 }, + /* + ** .pp + ** This specifies whether or not to show sidebar. The sidebar shows a list of + ** all your mailboxes. + ** .pp + ** \fBSee also:\fP $$sidebar_format, $$sidebar_width + */ + { "sidebar_width", DT_NUMBER, R_REFLOW, &SidebarWidth, 30 }, + /* + ** .pp + ** This controls the width of the sidebar. It is measured in screen columns. + ** For example: sidebar_width=20 could display 20 ASCII characters, or 10 + ** Chinese characters. + */ + { "sig_dashes", DT_BOOL, R_NONE, &SigDashes, 1 }, + /* + ** .pp + ** If \fIset\fP, a line containing ``-- '' (note the trailing space) will be inserted before your + ** $$signature. It is \fBstrongly\fP recommended that you not \fIunset\fP + ** this variable unless your signature contains just your name. The + ** reason for this is because many software packages use ``-- \n'' to + ** detect your signature. For example, NeoMutt has the ability to highlight + ** the signature in a different color in the built-in pager. + */ + { "sig_on_top", DT_BOOL, R_NONE, &SigOnTop, 0 }, + /* + ** .pp + ** If \fIset\fP, the signature will be included before any quoted or forwarded + ** text. It is \fBstrongly\fP recommended that you do not set this variable + ** unless you really know what you are doing, and are prepared to take + ** some heat from netiquette guardians. + */ + { "signature", DT_PATH, R_NONE, &Signature, IP "~/.signature" }, + /* + ** .pp + ** Specifies the filename of your signature, which is appended to all + ** outgoing messages. If the filename ends with a pipe (``|''), it is + ** assumed that filename is a shell command and input should be read from + ** its standard output. + */ + { "simple_search", DT_STRING, R_NONE, &SimpleSearch, IP "~f %s | ~s %s" }, + /* + ** .pp + ** Specifies how NeoMutt should expand a simple search into a real search + ** pattern. A simple search is one that does not contain any of the ``~'' pattern + ** operators. See ``$patterns'' for more information on search patterns. + ** .pp + ** For example, if you simply type ``joe'' at a search or limit prompt, NeoMutt + ** will automatically expand it to the value specified by this variable by + ** replacing ``%s'' with the supplied string. + ** For the default value, ``joe'' would be expanded to: ``~f joe | ~s joe''. + */ + { "skip_quoted_offset", DT_NUMBER, R_NONE, &SkipQuotedOffset, 0 }, + /* + ** .pp + ** Lines of quoted text that are displayed before the unquoted text after + ** ``skip to quoted'' command (S) + */ + { "sleep_time", DT_NUMBER, R_NONE, &SleepTime, 1 }, + /* + ** .pp + ** Specifies time, in seconds, to pause while displaying certain informational + ** messages, while moving from folder to folder and after expunging + ** messages from the current folder. The default is to pause one second, so + ** a value of zero for this option suppresses the pause. + */ + { "smart_wrap", DT_BOOL, R_PAGER_FLOW, &SmartWrap, 1 }, + /* + ** .pp + ** Controls the display of lines longer than the screen width in the + ** internal pager. If \fIset\fP, long lines are wrapped at a word boundary. If + ** \fIunset\fP, lines are simply wrapped at the screen edge. Also see the + ** $$markers variable. + */ + { "smileys", DT_REGEX, R_PAGER, &Smileys, IP "(>From )|(:[-^]?[][)(><}{|/DP])" }, + /* + ** .pp + ** The \fIpager\fP uses this variable to catch some common false + ** positives of $$quote_regexp, most notably smileys and not consider + ** a line quoted text if it also matches $$smileys. This mostly + ** happens at the beginning of a line. + */ + { "smime_ask_cert_label", DT_BOOL, R_NONE, &SmimeAskCertLabel, 1 }, + /* + ** .pp + ** This flag controls whether you want to be asked to enter a label + ** for a certificate about to be added to the database or not. It is + ** \fIset\fP by default. + ** (S/MIME only) + */ + { "smime_ca_location", DT_PATH, R_NONE, &SmimeCALocation, 0 }, + /* + ** .pp + ** This variable contains the name of either a directory, or a file which + ** contains trusted certificates for use with OpenSSL. + ** (S/MIME only) + */ + { "smime_certificates", DT_PATH, R_NONE, &SmimeCertificates, 0 }, + /* + ** .pp + ** Since for S/MIME there is no pubring/secring as with PGP, NeoMutt has to handle + ** storage and retrieval of keys by itself. This is very basic right + ** now, and keys and certificates are stored in two different + ** directories, both named as the hash-value retrieved from + ** OpenSSL. There is an index file which contains mailbox-address + ** keyid pairs, and which can be manually edited. This option points to + ** the location of the certificates. + ** (S/MIME only) + */ + { "smime_decrypt_command", DT_STRING, R_NONE, &SmimeDecryptCommand, 0 }, + /* + ** .pp + ** This format string specifies a command which is used to decrypt + ** \fCapplication/x-pkcs7-mime\fP attachments. + ** .pp + ** The OpenSSL command formats have their own set of \fCprintf(3)\fP-like sequences + ** similar to PGP's: + ** .dl + ** .dt %f .dd Expands to the name of a file containing a message. + ** .dt %s .dd Expands to the name of a file containing the signature part + ** . of a \fCmultipart/signed\fP attachment when verifying it. + ** .dt %k .dd The key-pair specified with $$smime_default_key + ** .dt %i .dd Intermediate certificates + ** .dt %c .dd One or more certificate IDs. + ** .dt %a .dd The algorithm used for encryption. + ** .dt %d .dd The message digest algorithm specified with $$smime_sign_digest_alg. + ** .dt %C .dd CA location: Depending on whether $$smime_ca_location + ** . points to a directory or file, this expands to + ** . ``-CApath $$smime_ca_location'' or ``-CAfile $$smime_ca_location''. + ** .de + ** .pp + ** For examples on how to configure these formats, see the \fCsmime.rc\fP in + ** the \fCsamples/\fP subdirectory which has been installed on your system + ** alongside the documentation. + ** (S/MIME only) + */ + { "smime_decrypt_use_default_key", DT_BOOL, R_NONE, &SmimeDecryptUseDefaultKey, 1 }, + /* + ** .pp + ** If \fIset\fP (default) this tells NeoMutt to use the default key for decryption. Otherwise, + ** if managing multiple certificate-key-pairs, NeoMutt will try to use the mailbox-address + ** to determine the key to use. It will ask you to supply a key, if it can't find one. + ** (S/MIME only) + */ + { "smime_default_key", DT_STRING, R_NONE, &SmimeDefaultKey, 0 }, + /* + ** .pp + ** This is the default key-pair to use for signing. This must be set to the + ** keyid (the hash-value that OpenSSL generates) to work properly + ** (S/MIME only) + */ + { "smime_encrypt_command", DT_STRING, R_NONE, &SmimeEncryptCommand, 0 }, + /* + ** .pp + ** This command is used to create encrypted S/MIME messages. + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + /* + ** .pp + ** Encrypt the message to $$smime_default_key too. + ** (S/MIME only) + */ + { "smime_encrypt_with", DT_STRING, R_NONE, &SmimeEncryptWith, IP "aes256" }, + /* + ** .pp + ** This sets the algorithm that should be used for encryption. + ** Valid choices are ``aes128'', ``aes192'', ``aes256'', ``des'', ``des3'', ``rc2-40'', ``rc2-64'', ``rc2-128''. + ** (S/MIME only) + */ + { "smime_get_cert_command", DT_STRING, R_NONE, &SmimeGetCertCommand, 0 }, + /* + ** .pp + ** This command is used to extract X509 certificates from a PKCS7 structure. + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smime_get_cert_email_command", DT_STRING, R_NONE, &SmimeGetCertEmailCommand, 0 }, + /* + ** .pp + ** This command is used to extract the mail address(es) used for storing + ** X509 certificates, and for verification purposes (to check whether the + ** certificate was issued for the sender's mailbox). + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smime_get_signer_cert_command", DT_STRING, R_NONE, &SmimeGetSignerCertCommand, 0 }, + /* + ** .pp + ** This command is used to extract only the signers X509 certificate from a S/MIME + ** signature, so that the certificate's owner may get compared to the + ** email's ``From:'' field. + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smime_import_cert_command", DT_STRING, R_NONE, &SmimeImportCertCommand, 0 }, + /* + ** .pp + ** This command is used to import a certificate via smime_keys. + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smime_is_default", DT_BOOL, R_NONE, &SmimeIsDefault, 0 }, + /* + ** .pp + ** The default behavior of NeoMutt is to use PGP on all auto-sign/encryption + ** operations. To override and to use OpenSSL instead this must be \fIset\fP. + ** However, this has no effect while replying, since NeoMutt will automatically + ** select the same application that was used to sign/encrypt the original + ** message. (Note that this variable can be overridden by unsetting $$crypt_autosmime.) + ** (S/MIME only) + */ + { "smime_keys", DT_PATH, R_NONE, &SmimeKeys, 0 }, + /* + ** .pp + ** Since for S/MIME there is no pubring/secring as with PGP, NeoMutt has to handle + ** storage and retrieval of keys/certs by itself. This is very basic right now, + ** and stores keys and certificates in two different directories, both + ** named as the hash-value retrieved from OpenSSL. There is an index file + ** which contains mailbox-address keyid pair, and which can be manually + ** edited. This option points to the location of the private keys. + ** (S/MIME only) + */ + { "smime_pk7out_command", DT_STRING, R_NONE, &SmimePk7outCommand, 0 }, + /* + ** .pp + ** This command is used to extract PKCS7 structures of S/MIME signatures, + ** in order to extract the public X509 certificate(s). + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smime_self_encrypt", DT_BOOL, R_NONE, &SmimeSelfEncrypt, 0 }, + /* + ** .pp + ** When \fIset\fP, S/MIME encrypted messages will also be encrypted + ** using the certificate in $$smime_self_encrypt_as. + ** (S/MIME only) + */ + { "smime_self_encrypt_as", DT_STRING, R_NONE, &SmimeSelfEncryptAs, 0 }, + /* + ** .pp + ** This is an additional certificate used to encrypt messages when + ** $$smime_self_encrypt is \fIset\fP. It is also used to specify the + ** certificate for $$postpone_encrypt. It should be the hash-value that + ** OpenSSL generates. + ** (S/MIME only) + */ + { "smime_sign_command", DT_STRING, R_NONE, &SmimeSignCommand, 0 }, + /* + ** .pp + ** This command is used to created S/MIME signatures of type + ** \fCmultipart/signed\fP, which can be read by all mail clients. + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smime_sign_digest_alg", DT_STRING, R_NONE, &SmimeSignDigestAlg, IP "sha256" }, + /* + ** .pp + ** This sets the algorithm that should be used for the signature message digest. + ** Valid choices are ``md5'', ``sha1'', ``sha224'', ``sha256'', ``sha384'', ``sha512''. + ** (S/MIME only) + */ + { "smime_timeout", DT_NUMBER, R_NONE, &SmimeTimeout, 300 }, + /* + ** .pp + ** The number of seconds after which a cached passphrase will expire if + ** not used. + ** (S/MIME only) + */ + { "smime_verify_command", DT_STRING, R_NONE, &SmimeVerifyCommand, 0 }, + /* + ** .pp + ** This command is used to verify S/MIME signatures of type \fCmultipart/signed\fP. + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smime_verify_opaque_command", DT_STRING, R_NONE, &SmimeVerifyOpaqueCommand, 0 }, + /* + ** .pp + ** This command is used to verify S/MIME signatures of type + ** \fCapplication/x-pkcs7-mime\fP. + ** .pp + ** This is a format string, see the $$smime_decrypt_command command for + ** possible \fCprintf(3)\fP-like sequences. + ** (S/MIME only) + */ + { "smtp_authenticators", DT_STRING, R_NONE, &SmtpAuthenticators, 0 }, + /* + ** .pp + ** This is a colon-delimited list of authentication methods NeoMutt may + ** attempt to use to log in to an SMTP server, in the order NeoMutt should + ** try them. Authentication methods are any SASL mechanism, e.g. ``plain'', + ** ``digest-md5'', ``gssapi'' or ``cram-md5''. + ** This option is case-insensitive. If it is ``unset'' + ** (the default) NeoMutt will try all available methods, in order from + ** most-secure to least-secure. Support for the ``plain'' mechanism is + ** bundled; other mechanisms are provided by an external SASL library (look + ** for +USE_SASL in the output of neomutt -v). + ** .pp + ** Example: + ** .ts + ** set smtp_authenticators="digest-md5:cram-md5" + ** .te + */ + { "smtp_pass", DT_STRING, R_NONE|F_SENSITIVE, &SmtpPass, 0 }, + /* + ** .pp + ** Specifies the password for your SMTP account. If \fIunset\fP, NeoMutt will + ** prompt you for your password when you first send mail via SMTP. + ** See $$smtp_url to configure NeoMutt to send mail via SMTP. + ** .pp + ** \fBWarning\fP: you should only use this option when you are on a + ** fairly secure machine, because the superuser can read your neomuttrc even + ** if you are the only one who can read the file. + */ + { "smtp_url", DT_STRING, R_NONE|F_SENSITIVE, &SmtpUrl, 0 }, + /* + ** .pp + ** Defines the SMTP smarthost where sent messages should relayed for + ** delivery. This should take the form of an SMTP URL, e.g.: + ** .ts + ** smtp[s]://[user[:pass]@]host[:port] + ** .te + ** .pp + ** where ``[...]'' denotes an optional part. + ** Setting this variable overrides the value of the $$sendmail + ** variable. + */ + { "sort", DT_SORT, R_INDEX|R_RESORT, &Sort, SORT_DATE }, + /* + ** .pp + ** Specifies how to sort messages in the ``index'' menu. Valid values + ** are: + ** .il + ** .dd date or date-sent + ** .dd date-received + ** .dd from + ** .dd mailbox-order (unsorted) + ** .dd score + ** .dd size + ** .dd spam + ** .dd subject + ** .dd threads + ** .dd to + ** .ie + ** .pp + ** You may optionally use the ``reverse-'' prefix to specify reverse sorting + ** order. + ** .pp + ** Example: + ** .ts + ** set sort=reverse-date-sent + ** .te + */ + { "sort_alias", DT_SORT|DT_SORT_ALIAS, R_NONE, &SortAlias, SORT_ALIAS }, + /* + ** .pp + ** Specifies how the entries in the ``alias'' menu are sorted. The + ** following are legal values: + ** .il + ** .dd address (sort alphabetically by email address) + ** .dd alias (sort alphabetically by alias name) + ** .dd unsorted (leave in order specified in .neomuttrc) + ** .ie + */ + { "sort_aux", DT_SORT|DT_SORT_AUX, R_INDEX|R_RESORT_BOTH, &SortAux, SORT_DATE }, + /* + ** .pp + ** When sorting by threads, this variable controls how threads are sorted + ** in relation to other threads, and how the branches of the thread trees + ** are sorted. This can be set to any value that $$sort can, except + ** ``threads'' (in that case, NeoMutt will just use ``date-sent''). You can also + ** specify the ``last-'' prefix in addition to the ``reverse-'' prefix, but ``last-'' + ** must come after ``reverse-''. The ``last-'' prefix causes messages to be + ** sorted against its siblings by which has the last descendant, using + ** the rest of $$sort_aux as an ordering. For instance, + ** .ts + ** set sort_aux=last-date-received + ** .te + ** .pp + ** would mean that if a new message is received in a + ** thread, that thread becomes the last one displayed (or the first, if + ** you have ``\fCset sort=reverse-threads\fP''.) + ** .pp + ** Note: For reversed $$sort + ** order $$sort_aux is reversed again (which is not the right thing to do, + ** but kept to not break any existing configuration setting). + */ + { "sort_browser", DT_SORT|DT_SORT_BROWSER, R_NONE, &SortBrowser, SORT_ALPHA }, + /* + ** .pp + ** Specifies how to sort entries in the file browser. By default, the + ** entries are sorted alphabetically. Valid values: + ** .il + ** .dd alpha (alphabetically) + ** .dd count (all message count) + ** .dd date + ** .dd desc (description) + ** .dd new (new message count) + ** .dd size + ** .dd unsorted + ** .ie + ** .pp + ** You may optionally use the ``reverse-'' prefix to specify reverse sorting + ** order (example: ``\fCset sort_browser=reverse-date\fP''). + */ + { "sort_re", DT_BOOL, R_INDEX|R_RESORT|R_RESORT_INIT, &SortRe, 1 }, + /* + ** .pp + ** This variable is only useful when sorting by mailboxes in sidebar. By default, + ** entries are unsorted. Valid values: + ** .il + ** .dd count (all message count) + ** .dd desc (virtual mailbox description) + ** .dd new (new message count) + ** .dd path + ** .dd unsorted + ** .ie + */ + { "spam_separator", DT_STRING, R_NONE, &SpamSeparator, IP "," }, + /* + ** .pp + ** This variable controls what happens when multiple spam headers + ** are matched: if \fIunset\fP, each successive header will overwrite any + ** previous matches value for the spam label. If \fIset\fP, each successive + ** match will append to the previous, using this variable's value as a + ** separator. + */ + { "spoolfile", DT_PATH, R_NONE, &SpoolFile, 0 }, + /* + ** .pp + ** If your spool mailbox is in a non-default place where NeoMutt cannot find + ** it, you can specify its location with this variable. NeoMutt will + ** initially set this variable to the value of the environment + ** variable \fC$$$MAIL\fP or \fC$$$MAILDIR\fP if either is defined. + */ + { "ssl_ca_certificates_file", DT_PATH, R_NONE, &SslCaCertificatesFile, 0 }, + /* + ** .pp + ** This variable specifies a file containing trusted CA certificates. + ** Any server certificate that is signed with one of these CA + ** certificates is also automatically accepted. (GnuTLS only) + ** .pp + ** Example: + ** .ts + ** set ssl_ca_certificates_file=/etc/ssl/certs/ca-certificates.crt + ** .te + */ + { "ssl_client_cert", DT_PATH, R_NONE, &SslClientCert, 0 }, + /* + ** .pp + ** The file containing a client certificate and its associated private + ** key. + */ + { "ssl_force_tls", DT_BOOL, R_NONE, &SslForceTls, 0 }, + /* + ** .pp + ** If this variable is \fIset\fP, NeoMutt will require that all connections + ** to remote servers be encrypted. Furthermore it will attempt to + ** negotiate TLS even if the server does not advertise the capability, + ** since it would otherwise have to abort the connection anyway. This + ** option supersedes $$ssl_starttls. + */ + { "ssl_min_dh_prime_bits", DT_NUMBER, R_NONE, &SslMinDhPrimeBits, 0 }, + /* + ** .pp + ** This variable specifies the minimum acceptable prime size (in bits) + ** for use in any Diffie-Hellman key exchange. A value of 0 will use + ** the default from the GNUTLS library. (GnuTLS only) + */ + { "ssl_starttls", DT_QUAD, R_NONE, &SslStarttls, MUTT_YES }, + /* + ** .pp + ** If \fIset\fP (the default), NeoMutt will attempt to use \fCSTARTTLS\fP on servers + ** advertising the capability. When \fIunset\fP, NeoMutt will not attempt to + ** use \fCSTARTTLS\fP regardless of the server's capabilities. + */ + { "ssl_use_sslv2", DT_BOOL, R_NONE, &SslUseSslv2, 0 }, + /* + ** .pp + ** This variable specifies whether to attempt to use SSLv2 in the + ** SSL authentication process. Note that SSLv2 and SSLv3 are now + ** considered fundamentally insecure and are no longer recommended. + ** (OpenSSL only) + */ + { "ssl_use_sslv3", DT_BOOL, R_NONE, &SslUseSslv3, 0 }, + /* + ** .pp + ** This variable specifies whether to attempt to use SSLv3 in the + ** SSL authentication process. Note that SSLv2 and SSLv3 are now + ** considered fundamentally insecure and are no longer recommended. + */ + { "ssl_use_tlsv1", DT_BOOL, R_NONE, &SslUseTlsv1, 1 }, + /* + ** .pp + ** This variable specifies whether to attempt to use TLSv1.0 in the + ** SSL authentication process. + */ + { "ssl_use_tlsv1_1", DT_BOOL, R_NONE, &SslUseTlsv11, 1 }, + /* + ** .pp + ** This variable specifies whether to attempt to use TLSv1.1 in the + ** SSL authentication process. + */ + { "ssl_use_tlsv1_2", DT_BOOL, R_NONE, &SslUseTlsv12, 1 }, + /* + ** .pp + ** This variable specifies whether to attempt to use TLSv1.2 in the + ** SSL authentication process. + */ + { "ssl_usesystemcerts", DT_BOOL, R_NONE, &SslUsesystemcerts, 1 }, + /* + ** .pp + ** If set to \fIyes\fP, NeoMutt will use CA certificates in the + ** system-wide certificate store when checking if a server certificate + ** is signed by a trusted CA. (OpenSSL only) + */ + { "ssl_verify_dates", DT_BOOL, R_NONE, &SslVerifyDates, 1 }, + /* + ** .pp + ** If \fIset\fP (the default), NeoMutt will not automatically accept a server + ** certificate that is either not yet valid or already expired. You should + ** only unset this for particular known hosts, using the + ** \fC$\fP function. + */ + { "ssl_verify_host", DT_BOOL, R_NONE, &SslVerifyHost, 1 }, + /* + ** .pp + ** If \fIset\fP (the default), NeoMutt will not automatically accept a server + ** certificate whose host name does not match the host used in your folder + ** URL. You should only unset this for particular known hosts, using + ** the \fC$\fP function. + */ + { "ssl_verify_partial_chains", DT_BOOL, R_NONE, &SslVerifyPartialChains, 0 }, + /* + ** .pp + ** This option should not be changed from the default unless you understand + ** what you are doing. + ** .pp + ** Setting this variable to \fIyes\fP will permit verifying partial + ** certification chains, i. e. a certificate chain where not the root, + ** but an intermediate certificate CA, or the host certificate, are + ** marked trusted (in $$certificate_file), without marking the root + ** signing CA as trusted. + ** .pp + ** (OpenSSL 1.0.2b and newer only). + */ + { "ssl_ciphers", DT_STRING, R_NONE, &SslCiphers, 0 }, + /* + ** .pp + ** Contains a colon-separated list of ciphers to use when using SSL. + ** For OpenSSL, see ciphers(1) for the syntax of the string. + ** .pp + ** For GnuTLS, this option will be used in place of "NORMAL" at the + ** start of the priority string. See gnutls_priority_init(3) for the + ** syntax and more details. (Note: GnuTLS version 2.1.7 or higher is + ** required.) + */ + { "status_chars", DT_MBTABLE, R_BOTH, &StatusChars, IP "-*%A" }, + /* + ** .pp + ** Controls the characters used by the ``%r'' indicator in $$status_format. + ** .dl + ** .dt \fBCharacter\fP .dd \fBDefault\fP .dd \fBDescription\fP + ** .dt 1 .dd - .dd Mailbox is unchanged + ** .dt 2 .dd * .dd Mailbox has been changed and needs to be resynchronized + ** .dt 3 .dd % .dd Mailbox is read-only, or will not be written when exiting. + ** (You can toggle whether to write changes to a mailbox + ** with the \fC\fP operation, bound by default + ** to ``%'') + ** .dt 4 .dd A .dd Folder opened in attach-message mode. + ** (Certain operations like composing a new mail, replying, + ** forwarding, etc. are not permitted in this mode) + ** .de + */ + { "status_format", DT_STRING, R_BOTH, &StatusFormat, IP "-%r-NeoMutt: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---" }, + /* + ** .pp + ** Controls the format of the status line displayed in the ``index'' + ** menu. This string is similar to $$index_format, but has its own + ** set of \fCprintf(3)\fP-like sequences: + ** .dl + ** .dt %b .dd Number of mailboxes with new mail * + ** .dt %d .dd Number of deleted messages * + ** .dt %f .dd The full pathname of the current mailbox + ** .dt %F .dd Number of flagged messages * + ** .dt %h .dd Local hostname + ** .dt %l .dd Size (in bytes) of the current mailbox * + ** .dt %L .dd Size (in bytes) of the messages shown + ** (i.e., which match the current limit) * + ** .dt %m .dd The number of messages in the mailbox * + ** .dt %M .dd The number of messages shown (i.e., which match the current limit) * + ** .dt %n .dd Number of new messages in the mailbox * + ** .dt %o .dd Number of old unread messages * + ** .dt %p .dd Number of postponed messages * + ** .dt %P .dd Percentage of the way through the index + ** .dt %r .dd Modified/read-only/won't-write/attach-message indicator, + ** According to $$status_chars + ** .dt %R .dd Number of read messages * + ** .dt %s .dd Current sorting mode ($$sort) + ** .dt %S .dd Current aux sorting method ($$sort_aux) + ** .dt %t .dd Number of tagged messages * + ** .dt %u .dd Number of unread messages * + ** .dt %v .dd NeoMutt version string + ** .dt %V .dd Currently active limit pattern, if any * + ** .dt %>X .dd Right justify the rest of the string and pad with ``X'' + ** .dt %|X .dd Pad to the end of the line with ``X'' + ** .dt %*X .dd Soft-fill with character ``X'' as pad + ** .de + ** .pp + ** For an explanation of ``soft-fill'', see the $$index_format documentation. + ** .pp + ** * = can be optionally printed if nonzero + ** .pp + ** Some of the above sequences can be used to optionally print a string + ** if their value is nonzero. For example, you may only want to see the + ** number of flagged messages if such messages exist, since zero is not + ** particularly meaningful. To optionally print a string based upon one + ** of the above sequences, the following construct is used: + ** .pp + ** \fC%???\fP + ** .pp + ** where \fIsequence_char\fP is a character from the table above, and + ** \fIoptional_string\fP is the string you would like printed if + ** \fIsequence_char\fP is nonzero. \fIoptional_string\fP \fBmay\fP contain + ** other sequences as well as normal text, but you may \fBnot\fP nest + ** optional strings. + ** .pp + ** Here is an example illustrating how to optionally print the number of + ** new messages in a mailbox: + ** .pp + ** \fC%?n?%n new messages.?\fP + ** .pp + ** You can also switch between two strings using the following construct: + ** .pp + ** \fC%??&?\fP + ** .pp + ** If the value of \fIsequence_char\fP is non-zero, \fIif_string\fP will + ** be expanded, otherwise \fIelse_string\fP will be expanded. + ** .pp + ** You can force the result of any \fCprintf(3)\fP-like sequence to be lowercase + ** by prefixing the sequence character with an underscore (``_'') sign. + ** For example, if you want to display the local hostname in lowercase, + ** you would use: ``\fC%_h\fP''. + ** .pp + ** If you prefix the sequence character with a colon (``:'') character, NeoMutt + ** will replace any dots in the expansion by underscores. This might be helpful + ** with IMAP folders that don't like dots in folder names. + */ + { "status_on_top", DT_BOOL, R_REFLOW, &StatusOnTop, 0 }, + /* + ** .pp + ** Setting this variable causes the ``status bar'' to be displayed on + ** the first line of the screen rather than near the bottom. If $$help + ** is \fIset\fP, too it'll be placed at the bottom. + */ + { "strict_threads", DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, &StrictThreads, 0 }, + /* + ** .pp + ** If \fIset\fP, threading will only make use of the ``In-Reply-To'' and + ** ``References:'' fields when you $$sort by message threads. By + ** default, messages with the same subject are grouped together in + ** ``pseudo threads.''. This may not always be desirable, such as in a + ** personal mailbox where you might have several unrelated messages with + ** the subjects like ``hi'' which will get grouped together. See also + ** $$sort_re for a less drastic way of controlling this + ** behavior. + */ + { "suspend", DT_BOOL, R_NONE, &Suspend, 1 }, + /* + ** .pp + ** When \fIunset\fP, NeoMutt won't stop when the user presses the terminal's + ** \fIsusp\fP key, usually ``^Z''. This is useful if you run NeoMutt + ** inside an xterm using a command like ``\fCxterm -e neomutt\fP''. + */ + { "text_flowed", DT_BOOL, R_NONE, &TextFlowed, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will generate ``format=flowed'' bodies with a content type + ** of ``\fCtext/plain; format=flowed\fP''. + ** This format is easier to handle for some mailing software, and generally + ** just looks like ordinary text. To actually make use of this format's + ** features, you'll need support in your editor. + ** .pp + ** Note that $$indent_string is ignored when this option is \fIset\fP. + */ + { "thorough_search", DT_BOOL, R_NONE, &ThoroughSearch, 1 }, + /* + ** .pp + ** Affects the \fC~b\fP and \fC~h\fP search operations described in + ** section ``$patterns''. If \fIset\fP, the headers and body/attachments of + ** messages to be searched are decoded before searching. If \fIunset\fP, + ** messages are searched as they appear in the folder. + ** .pp + ** Users searching attachments or for non-ASCII characters should \fIset\fP + ** this value because decoding also includes MIME parsing/decoding and possible + ** character set conversions. Otherwise NeoMutt will attempt to match against the + ** raw message received (for example quoted-printable encoded or with encoded + ** headers) which may lead to incorrect search results. + */ + { "thread_received", DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, &ThreadReceived, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt uses the date received rather than the date sent + ** to thread messages by subject. + */ + { "tilde", DT_BOOL, R_PAGER, &Tilde, 0 }, + /* + ** .pp + ** When \fIset\fP, the internal-pager will pad blank lines to the bottom of the + ** screen with a tilde (``~''). + */ + { "time_inc", DT_NUMBER, R_NONE, &TimeInc, 0 }, + /* + ** .pp + ** Along with $$read_inc, $$write_inc, and $$net_inc, this + ** variable controls the frequency with which progress updates are + ** displayed. It suppresses updates less than $$time_inc milliseconds + ** apart. This can improve throughput on systems with slow terminals, + ** or when running NeoMutt on a remote system. + ** .pp + ** Also see the ``$tuning'' section of the manual for performance considerations. + */ + { "timeout", DT_NUMBER, R_NONE, &Timeout, 600 }, + /* + ** .pp + ** When NeoMutt is waiting for user input either idling in menus or + ** in an interactive prompt, NeoMutt would block until input is + ** present. Depending on the context, this would prevent certain + ** operations from working, like checking for new mail or keeping + ** an IMAP connection alive. + ** .pp + ** This variable controls how many seconds NeoMutt will at most wait + ** until it aborts waiting for input, performs these operations and + ** continues to wait for input. + ** .pp + ** A value of zero or less will cause NeoMutt to never time out. + */ + { "tmpdir", DT_PATH, R_NONE, &Tmpdir, 0 }, + /* + ** .pp + ** This variable allows you to specify where NeoMutt will place its + ** temporary files needed for displaying and composing messages. If + ** this variable is not set, the environment variable \fC$$$TMPDIR\fP is + ** used. If \fC$$$TMPDIR\fP is not set then ``\fC/tmp\fP'' is used. + */ + { "to_chars", DT_MBTABLE, R_BOTH, &ToChars, IP " +TCFL" }, + /* + ** .pp + ** Controls the character used to indicate mail addressed to you. + ** .dl + ** .dt \fBCharacter\fP .dd \fBDefault\fP .dd \fBDescription\fP + ** .dt 1 .dd .dd The mail is \fInot\fP addressed to your address. + ** .dt 2 .dd + .dd You are the only recipient of the message. + ** .dt 3 .dd T .dd Your address appears in the ``To:'' header field, but you are not the only recipient of the message. + ** .dt 4 .dd C .dd Your address is specified in the ``Cc:'' header field, but you are not the only recipient. + ** .dt 5 .dd F .dd Indicates the mail that was sent by \fIyou\fP. + ** .dt 6 .dd L .dd Indicates the mail was sent to a mailing-list you subscribe to. + ** .de + */ + { "flag_chars", DT_MBTABLE, R_BOTH, &FlagChars, IP "*!DdrONon- " }, + /* + ** .pp + ** Controls the characters used in several flags. + ** .dl + ** .dt \fBCharacter\fP .dd \fBDefault\fP .dd \fBDescription\fP + ** .dt 1 .dd * .dd The mail is tagged. + ** .dt 2 .dd ! .dd The mail is flagged as important. + ** .dt 3 .dd D .dd The mail is marked for deletion. + ** .dt 4 .dd d .dd The mail has attachments marked for deletion. + ** .dt 5 .dd r .dd The mail has been replied to. + ** .dt 6 .dd O .dd The mail is Old (Unread but seen). + ** .dt 7 .dd N .dd The mail is New (Unread but not seen). + ** .dt 8 .dd o .dd The mail thread is Old (Unread but seen). + ** .dt 9 .dd n .dd The mail thread is New (Unread but not seen). + ** .dt 10 .dd - .dd The mail is read - %S expando. + ** .dt 11 .dd .dd The mail is read - %Z expando. + ** .de + */ + { "trash", DT_PATH, R_NONE, &Trash, 0 }, + /* + ** .pp + ** If set, this variable specifies the path of the trash folder where the + ** mails marked for deletion will be moved, instead of being irremediably + ** purged. + ** .pp + ** NOTE: When you delete a message in the trash folder, it is really + ** deleted, so that you have a way to clean the trash. + */ + { "ts_icon_format", DT_STRING, R_BOTH, &TSIconFormat, IP "M%?n?AIL&ail?" }, + /* + ** .pp + ** Controls the format of the icon title, as long as ``$$ts_enabled'' is set. + ** This string is identical in formatting to the one used by + ** ``$$status_format''. + */ + { "ts_enabled", DT_BOOL, R_BOTH, &TsEnabled, 0 }, + /* The default must be off to force in the validity checking. */ + /* + ** .pp + ** Controls whether NeoMutt tries to set the terminal status line and icon name. + ** Most terminal emulators emulate the status line in the window title. + */ + { "ts_status_format", DT_STRING, R_BOTH, &TSStatusFormat, IP "NeoMutt with %?m?%m messages&no messages?%?n? [%n NEW]?" }, + /* + ** .pp + ** Controls the format of the terminal status line (or window title), + ** provided that ``$$ts_enabled'' has been set. This string is identical in + ** formatting to the one used by ``$$status_format''. + */ + { "tunnel", DT_STRING, R_NONE, &Tunnel, 0 }, + /* + ** .pp + ** Setting this variable will cause NeoMutt to open a pipe to a command + ** instead of a raw socket. You may be able to use this to set up + ** preauthenticated connections to your IMAP/POP3/SMTP server. Example: + ** .ts + ** set tunnel="ssh -q mailhost.net /usr/local/libexec/imapd" + ** .te + ** .pp + ** Note: For this example to work you must be able to log in to the remote + ** machine without having to enter a password. + ** .pp + ** When set, NeoMutt uses the tunnel for all remote connections. + ** Please see ``$account-hook'' in the manual for how to use different + ** tunnel commands per connection. + */ + { "uncollapse_jump", DT_BOOL, R_NONE, &UncollapseJump, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will jump to the next unread message, if any, + ** when the current thread is \fIun\fPcollapsed. + */ + { "uncollapse_new", DT_BOOL, R_NONE, &UncollapseNew, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will automatically uncollapse any collapsed thread + ** that receives a new message. When \fIunset\fP, collapsed threads will + ** remain collapsed. the presence of the new message will still affect + ** index sorting, though. + */ + { "use_8bitmime", DT_BOOL, R_NONE, &Use8bitmime, 0 }, + /* + ** .pp + ** \fBWarning:\fP do not set this variable unless you are using a version + ** of sendmail which supports the \fC-B8BITMIME\fP flag (such as sendmail + ** 8.8.x) or you may not be able to send mail. + ** .pp + ** When \fIset\fP, NeoMutt will invoke $$sendmail with the \fC-B8BITMIME\fP + ** flag when sending 8-bit messages to enable ESMTP negotiation. + */ + { "use_domain", DT_BOOL, R_NONE, &UseDomain, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will qualify all local addresses (ones without the + ** ``@host'' portion) with the value of $$hostname. If \fIunset\fP, no + ** addresses will be qualified. + */ + { "use_envelope_from", DT_BOOL, R_NONE, &UseEnvelopeFrom, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will set the \fIenvelope\fP sender of the message. + ** If $$envelope_from_address is \fIset\fP, it will be used as the sender + ** address. If \fIunset\fP, NeoMutt will attempt to derive the sender from the + ** ``From:'' header. + ** .pp + ** Note that this information is passed to sendmail command using the + ** \fC-f\fP command line switch. Therefore setting this option is not useful + ** if the $$sendmail variable already contains \fC-f\fP or if the + ** executable pointed to by $$sendmail doesn't support the \fC-f\fP switch. + */ + { "use_from", DT_BOOL, R_NONE, &UseFrom, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will generate the ``From:'' header field when + ** sending messages. If \fIunset\fP, no ``From:'' header field will be + ** generated unless the user explicitly sets one using the ``$my_hdr'' + ** command. + */ + { "use_ipv6", DT_BOOL, R_NONE, &UseIpv6, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will look for IPv6 addresses of hosts it tries to + ** contact. If this option is \fIunset\fP, NeoMutt will restrict itself to IPv4 addresses. + ** Normally, the default should work. + */ + { "user_agent", DT_BOOL, R_NONE, &UserAgent, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will add a ``User-Agent:'' header to outgoing + ** messages, indicating which version of NeoMutt was used for composing + ** them. + */ + { "visual", DT_PATH, R_NONE, &Visual, 0 }, + /* + ** .pp + ** Specifies the visual editor to invoke when the ``\fC~v\fP'' command is + ** given in the built-in editor. + */ + { "vfolder_format", DT_STRING, R_INDEX, &VfolderFormat, IP "%2C %?n?%4n/& ?%4m %f" }, + /* + ** .pp + ** This variable allows you to customize the file browser display for virtual + ** folders to your personal taste. This string uses many of the same + ** expandos as $$folder_format. + */ + { "virtual_spoolfile", DT_BOOL, R_NONE, &VirtualSpoolfile, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will use the first defined virtual mailbox (see + ** virtual-mailboxes) as a spool file. + */ + { "wait_key", DT_BOOL, R_NONE, &WaitKey, 1 }, + /* + ** .pp + ** Controls whether NeoMutt will ask you to press a key after an external command + ** has been invoked by these functions: \fC\fP, + ** \fC\fP, \fC\fP, \fC\fP, + ** and \fC\fP commands. + ** .pp + ** It is also used when viewing attachments with ``$auto_view'', provided + ** that the corresponding mailcap entry has a \fIneedsterminal\fP flag, + ** and the external program is interactive. + ** .pp + ** When \fIset\fP, NeoMutt will always ask for a key. When \fIunset\fP, NeoMutt will wait + ** for a key only if the external command returned a non-zero status. + */ + { "weed", DT_BOOL, R_NONE, &Weed, 1 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will weed headers when displaying, forwarding, + ** printing, or replying to messages. + */ + { "wrap", DT_NUMBER, R_PAGER_FLOW, &Wrap, 0 }, + /* + ** .pp + ** When set to a positive value, NeoMutt will wrap text at $$wrap characters. + ** When set to a negative value, NeoMutt will wrap text so that there are $$wrap + ** characters of empty space on the right side of the terminal. Setting it + ** to zero makes NeoMutt wrap at the terminal width. + ** .pp + ** Also see $$reflow_wrap. + */ + { "wrap_headers", DT_NUMBER, R_PAGER, &WrapHeaders, 78 }, + /* + ** .pp + ** This option specifies the number of characters to use for wrapping + ** an outgoing message's headers. Allowed values are between 78 and 998 + ** inclusive. + ** .pp + ** \fBNote:\fP This option usually shouldn't be changed. RFC5233 + ** recommends a line length of 78 (the default), so \fBplease only change + ** this setting when you know what you're doing\fP. + */ + { "wrap_search", DT_BOOL, R_NONE, &WrapSearch, 1 }, + /* + ** .pp + ** Controls whether searches wrap around the end. + ** .pp + ** When \fIset\fP, searches will wrap around the first (or last) item. When + ** \fIunset\fP, incremental searches will not wrap. + */ + { "write_bcc", DT_BOOL, R_NONE, &WriteBcc, 1 }, + /* + ** .pp + ** Controls whether NeoMutt writes out the ``Bcc:'' header when preparing + ** messages to be sent. Exim users may wish to unset this. If NeoMutt + ** is set to deliver directly via SMTP (see $$smtp_url), this + ** option does nothing: NeoMutt will never write out the ``Bcc:'' header + ** in this case. + */ + { "write_inc", DT_NUMBER, R_NONE, &WriteInc, 10 }, + /* + ** .pp + ** When writing a mailbox, a message will be printed every + ** $$write_inc messages to indicate progress. If set to 0, only a + ** single message will be displayed before writing a mailbox. + ** .pp + ** Also see the $$read_inc, $$net_inc and $$time_inc variables and the + ** ``$tuning'' section of the manual for performance considerations. + */ + { "x_comment_to", DT_BOOL, R_NONE, &XCommentTo, 0 }, + /* + ** .pp + ** If \fIset\fP, NeoMutt will add ``X-Comment-To:'' field (that contains full + ** name of original article author) to article that followuped to newsgroup. + */ + { "collapse_all", DT_BOOL, R_NONE, &CollapseAll, 0 }, + /* + ** .pp + ** When \fIset\fP, NeoMutt will collapse all threads when entering a folder. + */ + /*--*/ + + { "pgp_encrypt_self", DT_QUAD, R_NONE, &PgpEncryptSelf, MUTT_NO }, + { "smime_encrypt_self", DT_QUAD, R_NONE, &SmimeEncryptSelf, MUTT_NO }, + { "wrapmargin", DT_NUMBER, R_PAGER, &Wrap, 0 }, + /* + ** .pp + ** (DEPRECATED) Equivalent to setting $$wrap with a negative value. + */ + + { "edit_hdrs", DT_SYNONYM, R_NONE, NULL, IP "edit_headers", }, + { "envelope_from", DT_SYNONYM, R_NONE, NULL, IP "use_envelope_from", }, + { "forw_decode", DT_SYNONYM, R_NONE, NULL, IP "forward_decode", }, + { "forw_decrypt", DT_SYNONYM, R_NONE, NULL, IP "forward_decrypt", }, + { "forw_format", DT_SYNONYM, R_NONE, NULL, IP "forward_format", }, + { "forw_quote", DT_SYNONYM, R_NONE, NULL, IP "forward_quote", }, + { "hdr_format", DT_SYNONYM, R_NONE, NULL, IP "index_format", }, + { "indent_str", DT_SYNONYM, R_NONE, NULL, IP "indent_string", }, + { "mime_fwd", DT_SYNONYM, R_NONE, NULL, IP "mime_forward", }, + { "msg_format", DT_SYNONYM, R_NONE, NULL, IP "message_format", }, + { "pgp_autoencrypt", DT_SYNONYM, R_NONE, NULL, IP "crypt_autoencrypt", }, + { "pgp_autosign", DT_SYNONYM, R_NONE, NULL, IP "crypt_autosign", }, + { "pgp_auto_traditional", DT_SYNONYM, R_NONE, NULL, IP "pgp_replyinline", }, + { "pgp_create_traditional", DT_SYNONYM, R_NONE, NULL, IP "pgp_autoinline", }, + { "pgp_replyencrypt", DT_SYNONYM, R_NONE, NULL, IP "crypt_replyencrypt", }, + { "pgp_replysign", DT_SYNONYM, R_NONE, NULL, IP "crypt_replysign", }, + { "pgp_replysignencrypted", DT_SYNONYM, R_NONE, NULL, IP "crypt_replysignencrypted", }, + { "pgp_verify_sig", DT_SYNONYM, R_NONE, NULL, IP "crypt_verify_sig", }, + { "post_indent_str", DT_SYNONYM, R_NONE, NULL, IP "post_indent_string", }, + { "print_cmd", DT_SYNONYM, R_NONE, NULL, IP "print_command", }, + { "smime_sign_as", DT_SYNONYM, R_NONE, NULL, IP "smime_default_key", }, + { "xterm_icon", DT_SYNONYM, R_NONE, NULL, IP "ts_icon_format", }, + { "xterm_set_titles", DT_SYNONYM, R_NONE, NULL, IP "ts_enabled", }, + { "xterm_title", DT_SYNONYM, R_NONE, NULL, IP "ts_status_format", }, + + { NULL, 0, 0, 0, 0 }, +}; +// clang-format on diff --git a/test/config/dump/data.h b/test/config/dump/data.h new file mode 100644 index 000000000..c1c347ae0 --- /dev/null +++ b/test/config/dump/data.h @@ -0,0 +1,28 @@ +/** + * @file + * Test Data for config dumping + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _DUMP_DATA_H +#define _DUMP_DATA_H + +extern struct ConfigDef MuttVars[]; + +#endif /* _DUMP_DATA_H */ diff --git a/test/config/dump/dump.c b/test/config/dump/dump.c new file mode 100644 index 000000000..17b42ab1e --- /dev/null +++ b/test/config/dump/dump.c @@ -0,0 +1,73 @@ +/** + * @file + * Test Code for config dumping + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/lib.h" +#include "data.h" +#include "config/common.h" + +bool dump_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(500); + + address_init(cs); + bool_init(cs); + magic_init(cs); + mbtable_init(cs); + number_init(cs); + path_init(cs); + quad_init(cs); + regex_init(cs); + sort_init(cs); + string_init(cs); + + if (!cs_register_variables(cs, MuttVars, 0)) + return false; + + cs_add_listener(cs, log_listener); + + dump_config(cs, CS_DUMP_STYLE_NEO, + CS_DUMP_HIDE_SENSITIVE | CS_DUMP_SHOW_DEFAULTS | CS_DUMP_SHOW_SYNONYMS); + printf("\n"); + + dump_config(cs, CS_DUMP_STYLE_NEO, CS_DUMP_ONLY_CHANGED); + printf("\n"); + + dump_config(cs, CS_DUMP_STYLE_MUTT, 0); + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/dump/dump.h b/test/config/dump/dump.h new file mode 100644 index 000000000..ce6ae6f13 --- /dev/null +++ b/test/config/dump/dump.h @@ -0,0 +1,28 @@ +/** + * @file + * Test Code for config dumping + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _DUMP_DUMP_H +#define _DUMP_DUMP_H + +bool dump_test(void); + +#endif /* _DUMP_DUMP_H */ diff --git a/test/config/dump/dump.txt b/test/config/dump/dump.txt new file mode 100644 index 000000000..96ff03051 --- /dev/null +++ b/test/config/dump/dump.txt @@ -0,0 +1,1442 @@ +---- dump_test --------------------------------------------- +set abort_noattach = no +# quad abort_noattach no +set abort_nosubject = ask-yes +# quad abort_nosubject ask-yes +set abort_unmodified = yes +# quad abort_unmodified yes +set alias_file = "~/.neomuttrc" +# path alias_file "~/.neomuttrc" +set alias_format = "%4n %2f %t %-10a %r" +# string alias_format "%4n %2f %t %-10a %r" +set allow_8bit = yes +# boolean allow_8bit yes +set allow_ansi = no +# boolean allow_ansi no +set arrow_cursor = no +# boolean arrow_cursor no +set ascii_chars = no +# boolean ascii_chars no +set ask_follow_up = no +# boolean ask_follow_up no +set ask_x_comment_to = no +# boolean ask_x_comment_to no +set askbcc = no +# boolean askbcc no +set askcc = no +# boolean askcc no +set assumed_charset = "" +# string assumed_charset "" +set attach_charset = "" +# string attach_charset "" +set attach_format = "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " +# string attach_format "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " +set attach_keyword = "\\<(attach|attached|attachments?)\\>" +# regex attach_keyword "\\<(attach|attached|attachments?)\\>" +set attach_sep = "\n" +# string attach_sep "\n" +set attach_split = yes +# boolean attach_split yes +set attribution = "On %d, %n wrote:" +# string attribution "On %d, %n wrote:" +set attribution_locale = "" +# string attribution_locale "" +set auto_tag = no +# boolean auto_tag no +set autoedit = no +# boolean autoedit no +set beep = yes +# boolean beep yes +set beep_new = no +# boolean beep_new no +set bounce = ask-yes +# quad bounce ask-yes +set bounce_delivered = yes +# boolean bounce_delivered yes +set braille_friendly = no +# boolean braille_friendly no +set catchup_newsgroup = ask-yes +# quad catchup_newsgroup ask-yes +set certificate_file = "~/.mutt_certificates" +# path certificate_file "~/.mutt_certificates" +set change_folder_next = no +# boolean change_folder_next no +set charset = "" +# string charset "" +set check_mbox_size = no +# boolean check_mbox_size no +set check_new = yes +# boolean check_new yes +set collapse_all = no +# boolean collapse_all no +set collapse_flagged = yes +# boolean collapse_flagged yes +set collapse_unread = yes +# boolean collapse_unread yes +set compose_format = "-- NeoMutt: Compose [Approx. msg size: %l Atts: %a]%>-" +# string compose_format "-- NeoMutt: Compose [Approx. msg size: %l Atts: %a]%>-" +set config_charset = "" +# string config_charset "" +set confirmappend = yes +# boolean confirmappend yes +set confirmcreate = yes +# boolean confirmcreate yes +set connect_timeout = 30 +# number connect_timeout 30 +set content_type = "text/plain" +# string content_type "text/plain" +set copy = yes +# quad copy yes +set crypt_autoencrypt = no +# boolean crypt_autoencrypt no +set crypt_autopgp = yes +# boolean crypt_autopgp yes +set crypt_autosign = no +# boolean crypt_autosign no +set crypt_autosmime = yes +# boolean crypt_autosmime yes +set crypt_confirmhook = yes +# boolean crypt_confirmhook yes +set crypt_opportunistic_encrypt = no +# boolean crypt_opportunistic_encrypt no +set crypt_replyencrypt = yes +# boolean crypt_replyencrypt yes +set crypt_replysign = no +# boolean crypt_replysign no +set crypt_replysignencrypted = no +# boolean crypt_replysignencrypted no +set crypt_timestamp = yes +# boolean crypt_timestamp yes +set crypt_use_gpgme = no +# boolean crypt_use_gpgme no +set crypt_use_pka = no +# boolean crypt_use_pka no +set crypt_verify_sig = yes +# quad crypt_verify_sig yes +set date_format = "!%a, %b %d, %Y at %I:%M:%S%p %Z" +# string date_format "!%a, %b %d, %Y at %I:%M:%S%p %Z" +set debug_file = "~/.neomuttdebug" +# path debug_file "~/.neomuttdebug" +set debug_level = 0 +# number debug_level 0 +set default_hook = "~f %s !~P | (~P ~C %s)" +# string default_hook "~f %s !~P | (~P ~C %s)" +set delete = ask-yes +# quad delete ask-yes +set delete_untag = yes +# boolean delete_untag yes +set digest_collapse = yes +# boolean digest_collapse yes +set display_filter = "" +# path display_filter "" +set dsn_notify = "" +# string dsn_notify "" +set dsn_return = "" +# string dsn_return "" +set duplicate_threads = yes +# boolean duplicate_threads yes +# synonym: edit_hdrs -> edit_headers +set edit_headers = no +# boolean edit_headers no +set editor = "" +# path editor "" +set empty_subject = "Re: your mail" +# string empty_subject "Re: your mail" +set encode_from = no +# boolean encode_from no +set entropy_file = "" +# path entropy_file "" +# synonym: envelope_from -> use_envelope_from +set envelope_from_address = "" +# address envelope_from_address "" +set escape = "~" +# string escape "~" +set fast_reply = no +# boolean fast_reply no +set fcc_attach = yes +# quad fcc_attach yes +set fcc_clear = no +# boolean fcc_clear no +set flag_chars = "*!DdrONon- " +# mbtable flag_chars "*!DdrONon- " +set flag_safe = no +# boolean flag_safe no +set folder = "~/Mail" +# path folder "~/Mail" +set folder_format = "%2C %t %N %F %2l %-8.8u %-8.8g %8s %d %f" +# string folder_format "%2C %t %N %F %2l %-8.8u %-8.8g %8s %d %f" +set followup_to = yes +# boolean followup_to yes +set followup_to_poster = ask-yes +# quad followup_to_poster ask-yes +set force_name = no +# boolean force_name no +# synonym: forw_decode -> forward_decode +# synonym: forw_decrypt -> forward_decrypt +# synonym: forw_format -> forward_format +# synonym: forw_quote -> forward_quote +set forward_attribution_intro = "----- Forwarded message from %f -----" +# string forward_attribution_intro "----- Forwarded message from %f -----" +set forward_attribution_trailer = "----- End forwarded message -----" +# string forward_attribution_trailer "----- End forwarded message -----" +set forward_decode = yes +# boolean forward_decode yes +set forward_decrypt = yes +# boolean forward_decrypt yes +set forward_edit = yes +# quad forward_edit yes +set forward_format = "[%a: %s]" +# string forward_format "[%a: %s]" +set forward_quote = no +# boolean forward_quote no +set forward_references = no +# boolean forward_references no +set from = "" +# address from "" +set from_chars = "" +# mbtable from_chars "" +set gecos_mask = "^[^,]*" +# regex gecos_mask "^[^,]*" +set group_index_format = "%4C %M%N %5s %-45.45f %d" +# string group_index_format "%4C %M%N %5s %-45.45f %d" +# synonym: hdr_format -> index_format +set hdrs = yes +# boolean hdrs yes +set header = no +# boolean header no +set header_cache = "" +# path header_cache "" +set header_cache_backend = "" +# string header_cache_backend "" +set header_cache_compress = yes +# boolean header_cache_compress yes +set header_cache_pagesize = "16384" +# string header_cache_pagesize "16384" +set header_color_partial = no +# boolean header_color_partial no +set help = yes +# boolean help yes +set hidden_host = no +# boolean hidden_host no +set hidden_tags = "unread,draft,flagged,passed,replied,attachment,signed,encrypted" +# string hidden_tags "unread,draft,flagged,passed,replied,attachment,signed,encrypted" +set hide_limited = no +# boolean hide_limited no +set hide_missing = yes +# boolean hide_missing yes +set hide_thread_subject = yes +# boolean hide_thread_subject yes +set hide_top_limited = no +# boolean hide_top_limited no +set hide_top_missing = yes +# boolean hide_top_missing yes +set history = 10 +# number history 10 +set history_file = "~/.mutthistory" +# path history_file "~/.mutthistory" +set history_remove_dups = no +# boolean history_remove_dups no +set honor_disposition = no +# boolean honor_disposition no +set honor_followup_to = yes +# quad honor_followup_to yes +set hostname = "" +# string hostname "" +set idn_decode = yes +# boolean idn_decode yes +set idn_encode = yes +# boolean idn_encode yes +set ignore_linear_white_space = no +# boolean ignore_linear_white_space no +set ignore_list_reply_to = no +# boolean ignore_list_reply_to no +set imap_authenticators = "" +# string imap_authenticators "" +set imap_check_subscribed = no +# boolean imap_check_subscribed no +set imap_delim_chars = "/." +# string imap_delim_chars "/." +set imap_headers = "" +# string imap_headers "" +set imap_idle = no +# boolean imap_idle no +set imap_keepalive = 300 +# number imap_keepalive 300 +set imap_list_subscribed = no +# boolean imap_list_subscribed no +set imap_login = "" +# string imap_login "" +set imap_pass = "" +# string imap_pass "" +set imap_passive = yes +# boolean imap_passive yes +set imap_peek = yes +# boolean imap_peek yes +set imap_pipeline_depth = 15 +# number imap_pipeline_depth 15 +set imap_poll_timeout = 15 +# number imap_poll_timeout 15 +set imap_servernoise = yes +# boolean imap_servernoise yes +set imap_user = "" +# string imap_user "" +set implicit_autoview = no +# boolean implicit_autoview no +set include = ask-yes +# quad include ask-yes +set include_onlyfirst = no +# boolean include_onlyfirst no +# synonym: indent_str -> indent_string +set indent_string = "> " +# string indent_string "> " +set index_format = "%4C %Z %{%b %d} %-15.15L (%?l?%4l&%4c?) %s" +# string index_format "%4C %Z %{%b %d} %-15.15L (%?l?%4l&%4c?) %s" +set inews = "" +# path inews "" +set ispell = "ispell" +# path ispell "ispell" +set keep_flagged = no +# boolean keep_flagged no +set mail_check = 5 +# number mail_check 5 +set mail_check_recent = yes +# boolean mail_check_recent yes +set mail_check_stats = no +# boolean mail_check_stats no +set mail_check_stats_interval = 60 +# number mail_check_stats_interval 60 +set mailcap_path = "" +# string mailcap_path "" +set mailcap_sanitize = yes +# boolean mailcap_sanitize yes +set maildir_check_cur = no +# boolean maildir_check_cur no +set maildir_header_cache_verify = yes +# boolean maildir_header_cache_verify yes +set maildir_trash = no +# boolean maildir_trash no +set mark_macro_prefix = "'" +# string mark_macro_prefix "'" +set mark_old = yes +# boolean mark_old yes +set markers = yes +# boolean markers yes +set mask = "!^\\.[^.]" +# regex mask "!^\\.[^.]" +set mbox = "~/mbox" +# path mbox "~/mbox" +set mbox_type = "mbox" +# magic mbox_type "mbox" +set menu_context = 0 +# number menu_context 0 +set menu_move_off = yes +# boolean menu_move_off yes +set menu_scroll = no +# boolean menu_scroll no +set message_cache_clean = no +# boolean message_cache_clean no +set message_cachedir = "" +# path message_cachedir "" +set message_format = "%s" +# string message_format "%s" +set meta_key = no +# boolean meta_key no +set metoo = no +# boolean metoo no +set mh_purge = no +# boolean mh_purge no +set mh_seq_flagged = "flagged" +# string mh_seq_flagged "flagged" +set mh_seq_replied = "replied" +# string mh_seq_replied "replied" +set mh_seq_unseen = "unseen" +# string mh_seq_unseen "unseen" +set mime_forward = no +# quad mime_forward no +set mime_forward_decode = no +# boolean mime_forward_decode no +set mime_forward_rest = yes +# quad mime_forward_rest yes +# synonym: mime_fwd -> mime_forward +set mime_subject = yes +# boolean mime_subject yes +set mime_type_query_command = "" +# string mime_type_query_command "" +set mime_type_query_first = no +# boolean mime_type_query_first no +set mix_entry_format = "%4n %c %-16s %a" +# string mix_entry_format "%4n %c %-16s %a" +set mixmaster = "mixmaster" +# path mixmaster "mixmaster" +set move = no +# quad move no +# synonym: msg_format -> message_format +set narrow_tree = no +# boolean narrow_tree no +set net_inc = 10 +# number net_inc 10 +set new_mail_command = "" +# path new_mail_command "" +set news_cache_dir = "~/.neomutt" +# path news_cache_dir "~/.neomutt" +set news_server = "" +# string news_server "" +set newsgroups_charset = "utf-8" +# string newsgroups_charset "utf-8" +set newsrc = "~/.newsrc" +# path newsrc "~/.newsrc" +set nm_db_limit = 0 +# number nm_db_limit 0 +set nm_default_uri = "" +# string nm_default_uri "" +set nm_exclude_tags = "" +# string nm_exclude_tags "" +set nm_open_timeout = 5 +# number nm_open_timeout 5 +set nm_query_type = "messages" +# string nm_query_type "messages" +set nm_query_window_current_position = 0 +# number nm_query_window_current_position 0 +set nm_query_window_current_search = "" +# string nm_query_window_current_search "" +set nm_query_window_duration = 0 +# number nm_query_window_duration 0 +set nm_query_window_timebase = "week" +# string nm_query_window_timebase "week" +set nm_record = no +# boolean nm_record no +set nm_record_tags = "" +# string nm_record_tags "" +set nm_unread_tag = "unread" +# string nm_unread_tag "unread" +set nntp_authenticators = "" +# string nntp_authenticators "" +set nntp_context = 1000 +# number nntp_context 1000 +set nntp_listgroup = yes +# boolean nntp_listgroup yes +set nntp_load_description = yes +# boolean nntp_load_description yes +set nntp_pass = "" +# string nntp_pass "" +set nntp_poll = 60 +# number nntp_poll 60 +set nntp_user = "" +# string nntp_user "" +set pager = "builtin" +# path pager "builtin" +set pager_context = 0 +# number pager_context 0 +set pager_format = "-%Z- %C/%m: %-20.20n %s%* -- (%P)" +# string pager_format "-%Z- %C/%m: %-20.20n %s%* -- (%P)" +set pager_index_lines = 0 +# number pager_index_lines 0 +set pager_stop = no +# boolean pager_stop no +set pgp_auto_decode = no +# boolean pgp_auto_decode no +# synonym: pgp_auto_traditional -> pgp_replyinline +# synonym: pgp_autoencrypt -> crypt_autoencrypt +set pgp_autoinline = no +# boolean pgp_autoinline no +# synonym: pgp_autosign -> crypt_autosign +set pgp_check_exit = yes +# boolean pgp_check_exit yes +set pgp_clearsign_command = "" +# string pgp_clearsign_command "" +# synonym: pgp_create_traditional -> pgp_autoinline +set pgp_decode_command = "" +# string pgp_decode_command "" +set pgp_decrypt_command = "" +# string pgp_decrypt_command "" +set pgp_decryption_okay = "" +# regex pgp_decryption_okay "" +set pgp_encrypt_only_command = "" +# string pgp_encrypt_only_command "" +set pgp_encrypt_self = no +# quad pgp_encrypt_self no +set pgp_encrypt_sign_command = "" +# string pgp_encrypt_sign_command "" +set pgp_entry_format = "%4n %t%f %4l/0x%k %-4a %2c %u" +# string pgp_entry_format "%4n %t%f %4l/0x%k %-4a %2c %u" +set pgp_export_command = "" +# string pgp_export_command "" +set pgp_getkeys_command = "" +# string pgp_getkeys_command "" +set pgp_good_sign = "" +# regex pgp_good_sign "" +set pgp_ignore_subkeys = yes +# boolean pgp_ignore_subkeys yes +set pgp_import_command = "" +# string pgp_import_command "" +set pgp_list_pubring_command = "" +# string pgp_list_pubring_command "" +set pgp_list_secring_command = "" +# string pgp_list_secring_command "" +set pgp_long_ids = yes +# boolean pgp_long_ids yes +set pgp_mime_auto = ask-yes +# quad pgp_mime_auto ask-yes +# synonym: pgp_replyencrypt -> crypt_replyencrypt +set pgp_replyinline = no +# boolean pgp_replyinline no +# synonym: pgp_replysign -> crypt_replysign +# synonym: pgp_replysignencrypted -> crypt_replysignencrypted +set pgp_retainable_sigs = no +# boolean pgp_retainable_sigs no +set pgp_self_encrypt = no +# boolean pgp_self_encrypt no +set pgp_self_encrypt_as = "" +# string pgp_self_encrypt_as "" +set pgp_show_unusable = yes +# boolean pgp_show_unusable yes +set pgp_sign_as = "" +# string pgp_sign_as "" +set pgp_sign_command = "" +# string pgp_sign_command "" +set pgp_sort_keys = "address" +# sort pgp_sort_keys "address" +set pgp_strict_enc = yes +# boolean pgp_strict_enc yes +set pgp_timeout = 300 +# number pgp_timeout 300 +set pgp_use_gpg_agent = no +# boolean pgp_use_gpg_agent no +set pgp_verify_command = "" +# string pgp_verify_command "" +set pgp_verify_key_command = "" +# string pgp_verify_key_command "" +# synonym: pgp_verify_sig -> crypt_verify_sig +set pipe_decode = no +# boolean pipe_decode no +set pipe_sep = "\n" +# string pipe_sep "\n" +set pipe_split = no +# boolean pipe_split no +set pop_auth_try_all = yes +# boolean pop_auth_try_all yes +set pop_authenticators = "" +# string pop_authenticators "" +set pop_checkinterval = 60 +# number pop_checkinterval 60 +set pop_delete = ask-no +# quad pop_delete ask-no +set pop_host = "" +# string pop_host "" +set pop_last = no +# boolean pop_last no +set pop_pass = "" +# string pop_pass "" +set pop_reconnect = ask-yes +# quad pop_reconnect ask-yes +set pop_user = "" +# string pop_user "" +# synonym: post_indent_str -> post_indent_string +set post_indent_string = "" +# string post_indent_string "" +set post_moderated = ask-yes +# quad post_moderated ask-yes +set postpone = ask-yes +# quad postpone ask-yes +set postpone_encrypt = no +# boolean postpone_encrypt no +set postpone_encrypt_as = "" +# string postpone_encrypt_as "" +set postponed = "~/postponed" +# path postponed "~/postponed" +set preconnect = "" +# string preconnect "" +set print = ask-no +# quad print ask-no +# synonym: print_cmd -> print_command +set print_command = "lpr" +# path print_command "lpr" +set print_decode = yes +# boolean print_decode yes +set print_split = no +# boolean print_split no +set prompt_after = yes +# boolean prompt_after yes +set query_command = "" +# path query_command "" +set query_format = "%4c %t %-25.25a %-25.25n %?e?(%e)?" +# string query_format "%4c %t %-25.25a %-25.25n %?e?(%e)?" +set quit = yes +# quad quit yes +set quote_regexp = "^([ \t]*[|>:}#])+" +# regex quote_regexp "^([ \t]*[|>:}#])+" +set read_inc = 10 +# number read_inc 10 +set read_only = no +# boolean read_only no +set realname = "" +# string realname "" +set recall = ask-yes +# quad recall ask-yes +set record = "~/sent" +# path record "~/sent" +set reflow_space_quotes = yes +# boolean reflow_space_quotes yes +set reflow_text = yes +# boolean reflow_text yes +set reflow_wrap = 78 +# number reflow_wrap 78 +set reply_regexp = "^(re([\\[0-9\\]+])*|aw):[ \t]*" +# regex reply_regexp "^(re([\\[0-9\\]+])*|aw):[ \t]*" +set reply_self = no +# boolean reply_self no +set reply_to = ask-yes +# quad reply_to ask-yes +set reply_with_xorig = no +# boolean reply_with_xorig no +set resolve = yes +# boolean resolve yes +set resume_draft_files = no +# boolean resume_draft_files no +set resume_edited_draft_files = yes +# boolean resume_edited_draft_files yes +set reverse_alias = no +# boolean reverse_alias no +set reverse_name = no +# boolean reverse_name no +set reverse_realname = yes +# boolean reverse_realname yes +set rfc2047_parameters = no +# boolean rfc2047_parameters no +set save_address = no +# boolean save_address no +set save_empty = yes +# boolean save_empty yes +set save_history = 0 +# number save_history 0 +set save_name = no +# boolean save_name no +set save_unsubscribed = no +# boolean save_unsubscribed no +set score = yes +# boolean score yes +set score_threshold_delete = -1 +# number score_threshold_delete -1 +set score_threshold_flag = 9999 +# number score_threshold_flag 9999 +set score_threshold_read = -1 +# number score_threshold_read -1 +set search_context = 0 +# number search_context 0 +set send_charset = "us-ascii:iso-8859-1:utf-8" +# string send_charset "us-ascii:iso-8859-1:utf-8" +set sendmail = "/usr/sbin/sendmail -oem -oi" +# path sendmail "/usr/sbin/sendmail -oem -oi" +set sendmail_wait = 0 +# number sendmail_wait 0 +set shell = "" +# path shell "" +set show_multipart_alternative = "" +# string show_multipart_alternative "" +set show_new_news = yes +# boolean show_new_news yes +set show_only_unread = no +# boolean show_only_unread no +set sidebar_component_depth = 0 +# number sidebar_component_depth 0 +set sidebar_delim_chars = "/." +# string sidebar_delim_chars "/." +set sidebar_divider_char = "" +# string sidebar_divider_char "" +set sidebar_folder_indent = no +# boolean sidebar_folder_indent no +set sidebar_format = "%B%* %n" +# string sidebar_format "%B%* %n" +set sidebar_indent_string = " " +# string sidebar_indent_string " " +set sidebar_new_mail_only = no +# boolean sidebar_new_mail_only no +set sidebar_next_new_wrap = no +# boolean sidebar_next_new_wrap no +set sidebar_on_right = no +# boolean sidebar_on_right no +set sidebar_short_path = no +# boolean sidebar_short_path no +set sidebar_sort_method = "mailbox-order" +# sort sidebar_sort_method "mailbox-order" +set sidebar_visible = no +# boolean sidebar_visible no +set sidebar_width = 30 +# number sidebar_width 30 +set sig_dashes = yes +# boolean sig_dashes yes +set sig_on_top = no +# boolean sig_on_top no +set signature = "~/.signature" +# path signature "~/.signature" +set simple_search = "~f %s | ~s %s" +# string simple_search "~f %s | ~s %s" +set skip_quoted_offset = 0 +# number skip_quoted_offset 0 +set sleep_time = 1 +# number sleep_time 1 +set smart_wrap = yes +# boolean smart_wrap yes +set smileys = "(>From )|(:[-^]?[][)(><}{|/DP])" +# regex smileys "(>From )|(:[-^]?[][)(><}{|/DP])" +set smime_ask_cert_label = yes +# boolean smime_ask_cert_label yes +set smime_ca_location = "" +# path smime_ca_location "" +set smime_certificates = "" +# path smime_certificates "" +set smime_decrypt_command = "" +# string smime_decrypt_command "" +set smime_decrypt_use_default_key = yes +# boolean smime_decrypt_use_default_key yes +set smime_default_key = "" +# string smime_default_key "" +set smime_encrypt_command = "" +# string smime_encrypt_command "" +set smime_encrypt_self = no +# quad smime_encrypt_self no +set smime_encrypt_with = "aes256" +# string smime_encrypt_with "aes256" +set smime_get_cert_command = "" +# string smime_get_cert_command "" +set smime_get_cert_email_command = "" +# string smime_get_cert_email_command "" +set smime_get_signer_cert_command = "" +# string smime_get_signer_cert_command "" +set smime_import_cert_command = "" +# string smime_import_cert_command "" +set smime_is_default = no +# boolean smime_is_default no +set smime_keys = "" +# path smime_keys "" +set smime_pk7out_command = "" +# string smime_pk7out_command "" +set smime_self_encrypt = no +# boolean smime_self_encrypt no +set smime_self_encrypt_as = "" +# string smime_self_encrypt_as "" +# synonym: smime_sign_as -> smime_default_key +set smime_sign_command = "" +# string smime_sign_command "" +set smime_sign_digest_alg = "sha256" +# string smime_sign_digest_alg "sha256" +set smime_timeout = 300 +# number smime_timeout 300 +set smime_verify_command = "" +# string smime_verify_command "" +set smime_verify_opaque_command = "" +# string smime_verify_opaque_command "" +set smtp_authenticators = "" +# string smtp_authenticators "" +set smtp_pass = "" +# string smtp_pass "" +set smtp_url = "" +# string smtp_url "" +set sort = "date" +# sort sort "date" +set sort_alias = "alias" +# sort sort_alias "alias" +set sort_aux = "date" +# sort sort_aux "date" +set sort_browser = "alpha" +# sort sort_browser "alpha" +set sort_re = yes +# boolean sort_re yes +set spam_separator = "," +# string spam_separator "," +set spoolfile = "" +# path spoolfile "" +set ssl_ca_certificates_file = "" +# path ssl_ca_certificates_file "" +set ssl_ciphers = "" +# string ssl_ciphers "" +set ssl_client_cert = "" +# path ssl_client_cert "" +set ssl_force_tls = no +# boolean ssl_force_tls no +set ssl_min_dh_prime_bits = 0 +# number ssl_min_dh_prime_bits 0 +set ssl_starttls = yes +# quad ssl_starttls yes +set ssl_use_sslv2 = no +# boolean ssl_use_sslv2 no +set ssl_use_sslv3 = no +# boolean ssl_use_sslv3 no +set ssl_use_tlsv1 = yes +# boolean ssl_use_tlsv1 yes +set ssl_use_tlsv1_1 = yes +# boolean ssl_use_tlsv1_1 yes +set ssl_use_tlsv1_2 = yes +# boolean ssl_use_tlsv1_2 yes +set ssl_usesystemcerts = yes +# boolean ssl_usesystemcerts yes +set ssl_verify_dates = yes +# boolean ssl_verify_dates yes +set ssl_verify_host = yes +# boolean ssl_verify_host yes +set ssl_verify_partial_chains = no +# boolean ssl_verify_partial_chains no +set status_chars = "-*%A" +# mbtable status_chars "-*%A" +set status_format = "-%r-NeoMutt: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---" +# string status_format "-%r-NeoMutt: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---" +set status_on_top = no +# boolean status_on_top no +set strict_threads = no +# boolean strict_threads no +set suspend = yes +# boolean suspend yes +set text_flowed = no +# boolean text_flowed no +set thorough_search = yes +# boolean thorough_search yes +set thread_received = no +# boolean thread_received no +set tilde = no +# boolean tilde no +set time_inc = 0 +# number time_inc 0 +set timeout = 600 +# number timeout 600 +set tmpdir = "" +# path tmpdir "" +set to_chars = " +TCFL" +# mbtable to_chars " +TCFL" +set trash = "" +# path trash "" +set ts_enabled = no +# boolean ts_enabled no +set ts_icon_format = "M%?n?AIL&ail?" +# string ts_icon_format "M%?n?AIL&ail?" +set ts_status_format = "NeoMutt with %?m?%m messages&no messages?%?n? [%n NEW]?" +# string ts_status_format "NeoMutt with %?m?%m messages&no messages?%?n? [%n NEW]?" +set tunnel = "" +# string tunnel "" +set uncollapse_jump = no +# boolean uncollapse_jump no +set uncollapse_new = yes +# boolean uncollapse_new yes +set use_8bitmime = no +# boolean use_8bitmime no +set use_domain = yes +# boolean use_domain yes +set use_envelope_from = no +# boolean use_envelope_from no +set use_from = yes +# boolean use_from yes +set use_ipv6 = yes +# boolean use_ipv6 yes +set user_agent = yes +# boolean user_agent yes +set vfolder_format = "%2C %?n?%4n/& ?%4m %f" +# string vfolder_format "%2C %?n?%4n/& ?%4m %f" +set virtual_spoolfile = no +# boolean virtual_spoolfile no +set visual = "" +# path visual "" +set wait_key = yes +# boolean wait_key yes +set weed = yes +# boolean weed yes +set wrap = 0 +# number wrap 0 +set wrap_headers = 78 +# number wrap_headers 78 +set wrap_search = yes +# boolean wrap_search yes +set wrapmargin = 0 +# number wrapmargin 0 +set write_bcc = yes +# boolean write_bcc yes +set write_inc = 10 +# number write_inc 10 +set x_comment_to = no +# boolean x_comment_to no +# synonym: xterm_icon -> ts_icon_format +# synonym: xterm_set_titles -> ts_enabled +# synonym: xterm_title -> ts_status_format + +set alias_file = "~/.neomuttrc" +set alias_format = "%4n %2f %t %-10a %r" +set assumed_charset = "" +set attach_charset = "" +set attach_format = "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " +set attach_keyword = "\\<(attach|attached|attachments?)\\>" +set attach_sep = "\n" +set attribution = "On %d, %n wrote:" +set attribution_locale = "" +set certificate_file = "~/.mutt_certificates" +set charset = "" +set compose_format = "-- NeoMutt: Compose [Approx. msg size: %l Atts: %a]%>-" +set config_charset = "" +set content_type = "text/plain" +set date_format = "!%a, %b %d, %Y at %I:%M:%S%p %Z" +set debug_file = "~/.neomuttdebug" +set default_hook = "~f %s !~P | (~P ~C %s)" +set display_filter = "" +set dsn_notify = "" +set dsn_return = "" +set editor = "" +set empty_subject = "Re: your mail" +set entropy_file = "" +set envelope_from_address = "" +set escape = "~" +set flag_chars = "*!DdrONon- " +set folder = "~/Mail" +set folder_format = "%2C %t %N %F %2l %-8.8u %-8.8g %8s %d %f" +set forward_attribution_intro = "----- Forwarded message from %f -----" +set forward_attribution_trailer = "----- End forwarded message -----" +set forward_format = "[%a: %s]" +set from = "" +set from_chars = "" +set gecos_mask = "^[^,]*" +set group_index_format = "%4C %M%N %5s %-45.45f %d" +set header_cache = "" +set header_cache_backend = "" +set header_cache_pagesize = "16384" +set hidden_tags = "unread,draft,flagged,passed,replied,attachment,signed,encrypted" +set history_file = "~/.mutthistory" +set hostname = "" +set imap_authenticators = "" +set imap_delim_chars = "/." +set imap_headers = "" +set imap_login = "" +set imap_pass = "" +set imap_user = "" +set indent_string = "> " +set index_format = "%4C %Z %{%b %d} %-15.15L (%?l?%4l&%4c?) %s" +set inews = "" +set ispell = "ispell" +set mailcap_path = "" +set mark_macro_prefix = "'" +set mask = "!^\\.[^.]" +set mbox = "~/mbox" +set mbox_type = "mbox" +set message_cachedir = "" +set message_format = "%s" +set mh_seq_flagged = "flagged" +set mh_seq_replied = "replied" +set mh_seq_unseen = "unseen" +set mime_type_query_command = "" +set mix_entry_format = "%4n %c %-16s %a" +set mixmaster = "mixmaster" +set new_mail_command = "" +set news_cache_dir = "~/.neomutt" +set news_server = "" +set newsgroups_charset = "utf-8" +set newsrc = "~/.newsrc" +set nm_default_uri = "" +set nm_exclude_tags = "" +set nm_query_type = "messages" +set nm_query_window_current_search = "" +set nm_query_window_timebase = "week" +set nm_record_tags = "" +set nm_unread_tag = "unread" +set nntp_authenticators = "" +set nntp_pass = "" +set nntp_user = "" +set pager = "builtin" +set pager_format = "-%Z- %C/%m: %-20.20n %s%* -- (%P)" +set pgp_clearsign_command = "" +set pgp_decode_command = "" +set pgp_decrypt_command = "" +set pgp_decryption_okay = "" +set pgp_encrypt_only_command = "" +set pgp_encrypt_sign_command = "" +set pgp_entry_format = "%4n %t%f %4l/0x%k %-4a %2c %u" +set pgp_export_command = "" +set pgp_getkeys_command = "" +set pgp_good_sign = "" +set pgp_import_command = "" +set pgp_list_pubring_command = "" +set pgp_list_secring_command = "" +set pgp_self_encrypt_as = "" +set pgp_sign_as = "" +set pgp_sign_command = "" +set pgp_sort_keys = "address" +set pgp_verify_command = "" +set pgp_verify_key_command = "" +set pipe_sep = "\n" +set pop_authenticators = "" +set pop_host = "" +set pop_pass = "" +set pop_user = "" +set post_indent_string = "" +set postpone_encrypt_as = "" +set postponed = "~/postponed" +set preconnect = "" +set print_command = "lpr" +set query_command = "" +set query_format = "%4c %t %-25.25a %-25.25n %?e?(%e)?" +set quote_regexp = "^([ \t]*[|>:}#])+" +set realname = "" +set record = "~/sent" +set reply_regexp = "^(re([\\[0-9\\]+])*|aw):[ \t]*" +set send_charset = "us-ascii:iso-8859-1:utf-8" +set sendmail = "/usr/sbin/sendmail -oem -oi" +set shell = "" +set show_multipart_alternative = "" +set sidebar_delim_chars = "/." +set sidebar_divider_char = "" +set sidebar_format = "%B%* %n" +set sidebar_indent_string = " " +set sidebar_sort_method = "mailbox-order" +set signature = "~/.signature" +set simple_search = "~f %s | ~s %s" +set smileys = "(>From )|(:[-^]?[][)(><}{|/DP])" +set smime_ca_location = "" +set smime_certificates = "" +set smime_decrypt_command = "" +set smime_default_key = "" +set smime_encrypt_command = "" +set smime_encrypt_with = "aes256" +set smime_get_cert_command = "" +set smime_get_cert_email_command = "" +set smime_get_signer_cert_command = "" +set smime_import_cert_command = "" +set smime_keys = "" +set smime_pk7out_command = "" +set smime_self_encrypt_as = "" +set smime_sign_command = "" +set smime_sign_digest_alg = "sha256" +set smime_verify_command = "" +set smime_verify_opaque_command = "" +set smtp_authenticators = "" +set smtp_pass = "" +set smtp_url = "" +set sort = "date" +set sort_alias = "alias" +set sort_aux = "date" +set sort_browser = "alpha" +set spam_separator = "," +set spoolfile = "" +set ssl_ca_certificates_file = "" +set ssl_ciphers = "" +set ssl_client_cert = "" +set status_chars = "-*%A" +set status_format = "-%r-NeoMutt: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---" +set tmpdir = "" +set to_chars = " +TCFL" +set trash = "" +set ts_icon_format = "M%?n?AIL&ail?" +set ts_status_format = "NeoMutt with %?m?%m messages&no messages?%?n? [%n NEW]?" +set tunnel = "" +set vfolder_format = "%2C %?n?%4n/& ?%4m %f" +set visual = "" + +abort_noattach=no +abort_nosubject=ask-yes +abort_unmodified=yes +alias_file="~/.neomuttrc" +alias_format="%4n %2f %t %-10a %r" +allow_8bit is set +allow_ansi is unset +arrow_cursor is unset +ascii_chars is unset +ask_follow_up is unset +ask_x_comment_to is unset +askbcc is unset +askcc is unset +assumed_charset="" +attach_charset="" +attach_format="%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " +attach_keyword="\\<(attach|attached|attachments?)\\>" +attach_sep="\n" +attach_split is set +attribution="On %d, %n wrote:" +attribution_locale="" +auto_tag is unset +autoedit is unset +beep is set +beep_new is unset +bounce=ask-yes +bounce_delivered is set +braille_friendly is unset +catchup_newsgroup=ask-yes +certificate_file="~/.mutt_certificates" +change_folder_next is unset +charset="" +check_mbox_size is unset +check_new is set +collapse_all is unset +collapse_flagged is set +collapse_unread is set +compose_format="-- NeoMutt: Compose [Approx. msg size: %l Atts: %a]%>-" +config_charset="" +confirmappend is set +confirmcreate is set +connect_timeout=30 +content_type="text/plain" +copy=yes +crypt_autoencrypt is unset +crypt_autopgp is set +crypt_autosign is unset +crypt_autosmime is set +crypt_confirmhook is set +crypt_opportunistic_encrypt is unset +crypt_replyencrypt is set +crypt_replysign is unset +crypt_replysignencrypted is unset +crypt_timestamp is set +crypt_use_gpgme is unset +crypt_use_pka is unset +crypt_verify_sig=yes +date_format="!%a, %b %d, %Y at %I:%M:%S%p %Z" +debug_file="~/.neomuttdebug" +debug_level=0 +default_hook="~f %s !~P | (~P ~C %s)" +delete=ask-yes +delete_untag is set +digest_collapse is set +display_filter="" +dsn_notify="" +dsn_return="" +duplicate_threads is set +edit_headers is unset +editor="" +empty_subject="Re: your mail" +encode_from is unset +entropy_file="" +envelope_from_address="" +escape="~" +fast_reply is unset +fcc_attach=yes +fcc_clear is unset +flag_chars="*!DdrONon- " +flag_safe is unset +folder="~/Mail" +folder_format="%2C %t %N %F %2l %-8.8u %-8.8g %8s %d %f" +followup_to is set +followup_to_poster=ask-yes +force_name is unset +forward_attribution_intro="----- Forwarded message from %f -----" +forward_attribution_trailer="----- End forwarded message -----" +forward_decode is set +forward_decrypt is set +forward_edit=yes +forward_format="[%a: %s]" +forward_quote is unset +forward_references is unset +from="" +from_chars="" +gecos_mask="^[^,]*" +group_index_format="%4C %M%N %5s %-45.45f %d" +hdrs is set +header is unset +header_cache="" +header_cache_backend="" +header_cache_compress is set +header_cache_pagesize="16384" +header_color_partial is unset +help is set +hidden_host is unset +hidden_tags="unread,draft,flagged,passed,replied,attachment,signed,encrypted" +hide_limited is unset +hide_missing is set +hide_thread_subject is set +hide_top_limited is unset +hide_top_missing is set +history=10 +history_file="~/.mutthistory" +history_remove_dups is unset +honor_disposition is unset +honor_followup_to=yes +hostname="" +idn_decode is set +idn_encode is set +ignore_linear_white_space is unset +ignore_list_reply_to is unset +imap_authenticators="" +imap_check_subscribed is unset +imap_delim_chars="/." +imap_headers="" +imap_idle is unset +imap_keepalive=300 +imap_list_subscribed is unset +imap_login="" +imap_pass="" +imap_passive is set +imap_peek is set +imap_pipeline_depth=15 +imap_poll_timeout=15 +imap_servernoise is set +imap_user="" +implicit_autoview is unset +include=ask-yes +include_onlyfirst is unset +indent_string="> " +index_format="%4C %Z %{%b %d} %-15.15L (%?l?%4l&%4c?) %s" +inews="" +ispell="ispell" +keep_flagged is unset +mail_check=5 +mail_check_recent is set +mail_check_stats is unset +mail_check_stats_interval=60 +mailcap_path="" +mailcap_sanitize is set +maildir_check_cur is unset +maildir_header_cache_verify is set +maildir_trash is unset +mark_macro_prefix="'" +mark_old is set +markers is set +mask="!^\\.[^.]" +mbox="~/mbox" +mbox_type="mbox" +menu_context=0 +menu_move_off is set +menu_scroll is unset +message_cache_clean is unset +message_cachedir="" +message_format="%s" +meta_key is unset +metoo is unset +mh_purge is unset +mh_seq_flagged="flagged" +mh_seq_replied="replied" +mh_seq_unseen="unseen" +mime_forward=no +mime_forward_decode is unset +mime_forward_rest=yes +mime_subject is set +mime_type_query_command="" +mime_type_query_first is unset +mix_entry_format="%4n %c %-16s %a" +mixmaster="mixmaster" +move=no +narrow_tree is unset +net_inc=10 +new_mail_command="" +news_cache_dir="~/.neomutt" +news_server="" +newsgroups_charset="utf-8" +newsrc="~/.newsrc" +nm_db_limit=0 +nm_default_uri="" +nm_exclude_tags="" +nm_open_timeout=5 +nm_query_type="messages" +nm_query_window_current_position=0 +nm_query_window_current_search="" +nm_query_window_duration=0 +nm_query_window_timebase="week" +nm_record is unset +nm_record_tags="" +nm_unread_tag="unread" +nntp_authenticators="" +nntp_context=1000 +nntp_listgroup is set +nntp_load_description is set +nntp_pass="" +nntp_poll=60 +nntp_user="" +pager="builtin" +pager_context=0 +pager_format="-%Z- %C/%m: %-20.20n %s%* -- (%P)" +pager_index_lines=0 +pager_stop is unset +pgp_auto_decode is unset +pgp_autoinline is unset +pgp_check_exit is set +pgp_clearsign_command="" +pgp_decode_command="" +pgp_decrypt_command="" +pgp_decryption_okay="" +pgp_encrypt_only_command="" +pgp_encrypt_self=no +pgp_encrypt_sign_command="" +pgp_entry_format="%4n %t%f %4l/0x%k %-4a %2c %u" +pgp_export_command="" +pgp_getkeys_command="" +pgp_good_sign="" +pgp_ignore_subkeys is set +pgp_import_command="" +pgp_list_pubring_command="" +pgp_list_secring_command="" +pgp_long_ids is set +pgp_mime_auto=ask-yes +pgp_replyinline is unset +pgp_retainable_sigs is unset +pgp_self_encrypt is unset +pgp_self_encrypt_as="" +pgp_show_unusable is set +pgp_sign_as="" +pgp_sign_command="" +pgp_sort_keys="address" +pgp_strict_enc is set +pgp_timeout=300 +pgp_use_gpg_agent is unset +pgp_verify_command="" +pgp_verify_key_command="" +pipe_decode is unset +pipe_sep="\n" +pipe_split is unset +pop_auth_try_all is set +pop_authenticators="" +pop_checkinterval=60 +pop_delete=ask-no +pop_host="" +pop_last is unset +pop_pass="" +pop_reconnect=ask-yes +pop_user="" +post_indent_string="" +post_moderated=ask-yes +postpone=ask-yes +postpone_encrypt is unset +postpone_encrypt_as="" +postponed="~/postponed" +preconnect="" +print=ask-no +print_command="lpr" +print_decode is set +print_split is unset +prompt_after is set +query_command="" +query_format="%4c %t %-25.25a %-25.25n %?e?(%e)?" +quit=yes +quote_regexp="^([ \t]*[|>:}#])+" +read_inc=10 +read_only is unset +realname="" +recall=ask-yes +record="~/sent" +reflow_space_quotes is set +reflow_text is set +reflow_wrap=78 +reply_regexp="^(re([\\[0-9\\]+])*|aw):[ \t]*" +reply_self is unset +reply_to=ask-yes +reply_with_xorig is unset +resolve is set +resume_draft_files is unset +resume_edited_draft_files is set +reverse_alias is unset +reverse_name is unset +reverse_realname is set +rfc2047_parameters is unset +save_address is unset +save_empty is set +save_history=0 +save_name is unset +save_unsubscribed is unset +score is set +score_threshold_delete=-1 +score_threshold_flag=9999 +score_threshold_read=-1 +search_context=0 +send_charset="us-ascii:iso-8859-1:utf-8" +sendmail="/usr/sbin/sendmail -oem -oi" +sendmail_wait=0 +shell="" +show_multipart_alternative="" +show_new_news is set +show_only_unread is unset +sidebar_component_depth=0 +sidebar_delim_chars="/." +sidebar_divider_char="" +sidebar_folder_indent is unset +sidebar_format="%B%* %n" +sidebar_indent_string=" " +sidebar_new_mail_only is unset +sidebar_next_new_wrap is unset +sidebar_on_right is unset +sidebar_short_path is unset +sidebar_sort_method="mailbox-order" +sidebar_visible is unset +sidebar_width=30 +sig_dashes is set +sig_on_top is unset +signature="~/.signature" +simple_search="~f %s | ~s %s" +skip_quoted_offset=0 +sleep_time=1 +smart_wrap is set +smileys="(>From )|(:[-^]?[][)(><}{|/DP])" +smime_ask_cert_label is set +smime_ca_location="" +smime_certificates="" +smime_decrypt_command="" +smime_decrypt_use_default_key is set +smime_default_key="" +smime_encrypt_command="" +smime_encrypt_self=no +smime_encrypt_with="aes256" +smime_get_cert_command="" +smime_get_cert_email_command="" +smime_get_signer_cert_command="" +smime_import_cert_command="" +smime_is_default is unset +smime_keys="" +smime_pk7out_command="" +smime_self_encrypt is unset +smime_self_encrypt_as="" +smime_sign_command="" +smime_sign_digest_alg="sha256" +smime_timeout=300 +smime_verify_command="" +smime_verify_opaque_command="" +smtp_authenticators="" +smtp_pass="" +smtp_url="" +sort="date" +sort_alias="alias" +sort_aux="date" +sort_browser="alpha" +sort_re is set +spam_separator="," +spoolfile="" +ssl_ca_certificates_file="" +ssl_ciphers="" +ssl_client_cert="" +ssl_force_tls is unset +ssl_min_dh_prime_bits=0 +ssl_starttls=yes +ssl_use_sslv2 is unset +ssl_use_sslv3 is unset +ssl_use_tlsv1 is set +ssl_use_tlsv1_1 is set +ssl_use_tlsv1_2 is set +ssl_usesystemcerts is set +ssl_verify_dates is set +ssl_verify_host is set +ssl_verify_partial_chains is unset +status_chars="-*%A" +status_format="-%r-NeoMutt: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---" +status_on_top is unset +strict_threads is unset +suspend is set +text_flowed is unset +thorough_search is set +thread_received is unset +tilde is unset +time_inc=0 +timeout=600 +tmpdir="" +to_chars=" +TCFL" +trash="" +ts_enabled is unset +ts_icon_format="M%?n?AIL&ail?" +ts_status_format="NeoMutt with %?m?%m messages&no messages?%?n? [%n NEW]?" +tunnel="" +uncollapse_jump is unset +uncollapse_new is set +use_8bitmime is unset +use_domain is set +use_envelope_from is unset +use_from is set +use_ipv6 is set +user_agent is set +vfolder_format="%2C %?n?%4n/& ?%4m %f" +virtual_spoolfile is unset +visual="" +wait_key is set +weed is set +wrap=0 +wrap_headers=78 +wrap_search is set +wrapmargin=0 +write_bcc is set +write_inc=10 +x_comment_to is unset diff --git a/test/config/dump/vars.c b/test/config/dump/vars.c new file mode 100644 index 000000000..4f8295625 --- /dev/null +++ b/test/config/dump/vars.c @@ -0,0 +1,460 @@ +/** + * @file + * Hundreds of global variables to back the user variables + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include + +struct Address *EnvelopeFromAddress; +struct Address *From; + +char *AliasFile; +char *AliasFormat; +char *AttachSep; +char *Attribution; +char *AttributionLocale; +char *AttachCharset; +char *AttachFormat; +struct Regex *AttachKeyword; +char *ComposeFormat; +char *ConfigCharset; +char *ContentType; +char *DefaultHook; +char *DateFormat; +char *DisplayFilter; +char *DsnNotify; +char *DsnReturn; +char *Editor; +char *EmptySubject; +char *Escape; +char *FolderFormat; +char *ForwardAttributionIntro; +char *ForwardAttributionTrailer; +char *ForwardFormat; +char *Hostname; +struct MbTable *FromChars; +char *IndexFormat; +char *HistoryFile; + +char *ImapAuthenticators; +char *ImapDelimChars; +char *ImapHeaders; +char *ImapLogin; +char *ImapPass; +char *ImapUser; +char *Mbox; +char *Ispell; +char *MailcapPath; +char *Folder; +char *MessageCachedir; +char *HeaderCache; +char *HeaderCacheBackend; +char *HeaderCachePageSize; +char *MarkMacroPrefix; +char *MhSeqFlagged; +char *MhSeqReplied; +char *MhSeqUnseen; +char *MimeTypeQueryCommand; +char *MessageFormat; + +short NetInc; + +char *Mixmaster; +char *MixEntryFormat; + +char *GroupIndexFormat; +char *Inews; +char *NewsCacheDir; +char *NewsServer; +char *NewsgroupsCharset; +char *NewsRc; +char *NntpAuthenticators; +char *NntpUser; +char *NntpPass; +char *Record; +char *Pager; +char *PagerFormat; +char *PipeSep; +char *PopAuthenticators; +short PopCheckinterval; +char *PopHost; +char *PopPass; +char *PopUser; +char *PostIndentString; +char *Postponed; +char *PostponeEncryptAs; +char *IndentString; +char *PrintCommand; +char *NewMailCommand; +char *QueryCommand; +char *QueryFormat; +char *RealName; +short SearchContext; +char *SendCharset; +char *Sendmail; +char *Shell; +char *ShowMultipartAlternative; +char *SidebarDelimChars; +char *SidebarDividerChar; +char *SidebarFormat; +char *SidebarIndentString; +char *Signature; +char *SimpleSearch; +char *SmtpAuthenticators; +char *SmtpPass; +char *SmtpUrl; +char *SpoolFile; +char *SpamSeparator; +struct MbTable *StatusChars; +char *StatusFormat; +char *Tmpdir; +struct MbTable *ToChars; +struct MbTable *FlagChars; +char *Trash; +char *TSStatusFormat; +char *TSIconFormat; +char *Visual; + +char *HiddenTags; + +short NntpPoll; +short NntpContext; + +short DebugLevel; +char *DebugFile; + +short History; +short MenuContext; +short PagerContext; +short PagerIndexLines; +short ReadInc; +short ReflowWrap; +short SaveHistory; +short SendmailWait; +short SleepTime; +short SkipQuotedOffset; +short TimeInc; +short Timeout; +short Wrap; +short WrapHeaders; +short WriteInc; + +short ScoreThresholdDelete; +short ScoreThresholdRead; +short ScoreThresholdFlag; + +short SidebarComponentDepth; +short SidebarWidth; +short ImapKeepalive; +short ImapPipelineDepth; +short ImapPollTimeout; + +struct Regex *PgpGoodSign; +struct Regex *PgpDecryptionOkay; +char *PgpSignAs; +short PgpTimeout; +char *PgpEntryFormat; +char *PgpClearSignCommand; +char *PgpDecodeCommand; +char *PgpVerifyCommand; +char *PgpDecryptCommand; +char *PgpSignCommand; +char *PgpEncryptSignCommand; +char *PgpEncryptOnlyCommand; +char *PgpImportCommand; +char *PgpExportCommand; +char *PgpVerifyKeyCommand; +char *PgpListSecringCommand; +char *PgpListPubringCommand; +char *PgpGetkeysCommand; +char *PgpSelfEncryptAs; + +char *SmimeDefaultKey; +short SmimeTimeout; +char *SmimeCertificates; +char *SmimeKeys; +char *SmimeEncryptWith; +char *SmimeCALocation; +char *SmimeVerifyCommand; +char *SmimeVerifyOpaqueCommand; +char *SmimeDecryptCommand; +char *SmimeSignCommand; +char *SmimeSignDigestAlg; +char *SmimeEncryptCommand; +char *SmimeGetSignerCertCommand; +char *SmimePk7outCommand; +char *SmimeGetCertCommand; +char *SmimeImportCertCommand; +char *SmimeGetCertEmailCommand; +char *SmimeSelfEncryptAs; + +int NmOpenTimeout; +char *NmDefaultUri; +char *NmExcludeTags; +char *NmUnreadTag; +char *VfolderFormat; +int NmDbLimit; +char *NmQueryType; +char *NmRecordTags; +int NmQueryWindowDuration; +char *NmQueryWindowTimebase; +int NmQueryWindowCurrentPosition; +char *NmQueryWindowCurrentSearch; + +bool Allow8bit; +bool AllowAnsi; +bool ArrowCursor; +bool AsciiChars; +bool Askbcc; +bool Askcc; +bool AskFollowUp; +bool AskXCommentTo; +bool AttachSplit; +bool Autoedit; +bool AutoTag; +bool Beep; +bool BeepNew; +bool BounceDelivered; +bool BrailleFriendly; +bool ChangeFolderNext; +bool CheckMboxSize; +bool CheckNew; +bool CollapseAll; +bool CollapseFlagged; +bool CollapseUnread; +bool Confirmappend; +bool Confirmcreate; +bool CryptAutoencrypt; +bool CryptAutopgp; +bool CryptAutosign; +bool CryptAutosmime; +bool CryptConfirmhook; +bool CryptOpportunisticEncrypt; +bool CryptReplyencrypt; +bool CryptReplysign; +bool CryptReplysignencrypted; +bool CryptTimestamp; +bool CryptUseGpgme; +bool CryptUsePka; +bool DeleteUntag; +bool DigestCollapse; +bool DuplicateThreads; +bool EditHeaders; +bool EncodeFrom; +bool FastReply; +bool FccClear; +bool FlagSafe; +bool FollowupTo; +bool ForceName; +bool ForwardDecode; +bool ForwardDecrypt; +bool ForwardQuote; +bool ForwardReferences; +bool Hdrs; +bool Header; +bool HeaderCacheCompress; +bool HeaderColorPartial; +bool Help; +bool HiddenHost; +bool HideLimited; +bool HideMissing; +bool HideThreadSubject; +bool HideTopLimited; +bool HideTopMissing; +bool HistoryRemoveDups; +bool HonorDisposition; +bool IdnDecode; +bool IdnEncode; +bool IgnoreLinearWhiteSpace; +bool IgnoreListReplyTo; +bool ImapCheckSubscribed; +bool ImapIdle; +bool ImapListSubscribed; +bool ImapPassive; +bool ImapPeek; +bool ImapServernoise; +bool ImplicitAutoview; +bool IncludeOnlyfirst; +bool KeepFlagged; +bool MailcapSanitize; +bool MailCheckRecent; +bool MailCheckStats; +bool MaildirCheckCur; +bool MaildirHeaderCacheVerify; +bool MaildirTrash; +bool Markers; +bool MarkOld; +bool MenuMoveOff; /**< allow menu to scroll past last entry */ +bool MenuScroll; /**< scroll menu instead of implicit next-page */ +bool MessageCacheClean; +bool MetaKey; /**< interpret ALT-x as ESC-x */ +bool Metoo; +bool MhPurge; +bool MimeForwardDecode; +bool MimeSubject; /**< encode subject line with RFC2047 */ +bool MimeTypeQueryFirst; +bool NarrowTree; +bool NmRecord; +bool NntpListgroup; +bool NntpLoadDescription; +bool PagerStop; +bool PgpAutoDecode; +bool PgpAutoinline; +bool PgpCheckExit; +bool PgpIgnoreSubkeys; +bool PgpLongIds; +bool PgpReplyinline; +bool PgpRetainableSigs; +bool PgpSelfEncrypt; +bool PgpShowUnusable; +bool PgpStrictEnc; +bool PgpUseGpgAgent; +bool PipeDecode; +bool PipeSplit; +bool PopAuthTryAll; +bool PopLast; +bool PostponeEncrypt; +bool PrintDecode; +bool PrintSplit; +bool PromptAfter; +bool ReadOnly; +bool ReflowSpaceQuotes; +bool ReflowText; +bool ReplySelf; +bool ReplyWithXorig; +bool Resolve; +bool ResumeDraftFiles; +bool ResumeEditedDraftFiles; +bool ReverseAlias; +bool ReverseName; +bool ReverseRealname; +bool Rfc2047Parameters; +bool SaveAddress; +bool SaveEmpty; +bool SaveName; +bool SaveUnsubscribed; +bool Score; +bool ShowNewNews; +bool ShowOnlyUnread; +bool SidebarFolderIndent; +bool SidebarNewMailOnly; +bool SidebarNextNewWrap; +bool SidebarOnRight; +bool SidebarShortPath; +bool SidebarVisible; +bool SigDashes; +bool SigOnTop; +bool SmartWrap; +bool SmimeAskCertLabel; +bool SmimeDecryptUseDefaultKey; +bool SmimeIsDefault; +bool SmimeSelfEncrypt; +bool SortRe; +bool SslForceTls; +bool SslUseSslv2; +bool SslUseSslv3; +bool SslUsesystemcerts; +bool SslUseTlsv11; +bool SslUseTlsv12; +bool SslUseTlsv1; +bool SslVerifyDates; +bool SslVerifyHost; +bool SslVerifyPartialChains; +bool StatusOnTop; +bool StrictThreads; +bool Suspend; +bool TextFlowed; +bool ThoroughSearch; +bool ThreadReceived; +bool Tilde; +bool TsEnabled; +bool UncollapseJump; +bool UncollapseNew; +bool Use8bitmime; +bool UseDomain; +bool UseEnvelopeFrom; +bool UseFrom; +bool UseIpv6; +bool UserAgent; +bool VirtualSpoolfile; +bool WaitKey; +bool Weed; +bool WrapSearch; +bool WriteBcc; +bool XCommentTo; + +unsigned char AbortNoattach; +unsigned char AbortNosubject; +unsigned char AbortUnmodified; +unsigned char Bounce; +unsigned char CatchupNewsgroup; +unsigned char Copy; +unsigned char CryptVerifySig; +unsigned char Delete; +unsigned char FccAttach; +unsigned char FollowupToPoster; +unsigned char ForwardEdit; +unsigned char HonorFollowupTo; +unsigned char Include; +unsigned char MimeForward; +unsigned char MimeForwardRest; +unsigned char Move; +unsigned char PgpEncryptSelf; +unsigned char PgpMimeAuto; +unsigned char PopDelete; +unsigned char PopReconnect; +unsigned char PostModerated; +unsigned char Postpone; +unsigned char Print; +unsigned char Quit; +unsigned char Recall; +unsigned char ReplyTo; +unsigned char SmimeEncryptSelf; +unsigned char SslStarttls; + +char *AssumedCharset; +char *Charset; + +short ConnectTimeout; +const char *CertificateFile; +const char *EntropyFile; +const char *SslCiphers; +const char *SslClientCert; +const char *SslCaCertificatesFile; +short SslMinDhPrimeBits; +const char *Preconnect; +const char *Tunnel; + +struct Regex *GecosMask; +struct Regex *Mask; +struct Regex *QuoteRegexp; +struct Regex *ReplyRegexp; +struct Regex *Smileys; + +short MailCheck; +short MailCheckStatsInterval; +short MboxType; + +short PgpSortKeys; +short SidebarSortMethod; +short Sort; +short SortAlias; +short SortAux; +short SortBrowser; diff --git a/test/config/dump/vars.h b/test/config/dump/vars.h new file mode 100644 index 000000000..2ca38c859 --- /dev/null +++ b/test/config/dump/vars.h @@ -0,0 +1,465 @@ +/** + * @file + * Hundreds of global variables to back the user variables + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _DUMP_VARS_H +#define _DUMP_VARS_H + +#include + +extern struct Address *EnvelopeFromAddress; +extern struct Address *From; + +extern char *AliasFile; +extern char *AliasFormat; +extern char *AttachSep; +extern char *Attribution; +extern char *AttributionLocale; +extern char *AttachCharset; +extern char *AttachFormat; +extern struct Regex *AttachKeyword; +extern char *ComposeFormat; +extern char *ConfigCharset; +extern char *ContentType; +extern char *DefaultHook; +extern char *DateFormat; +extern char *DisplayFilter; +extern char *DsnNotify; +extern char *DsnReturn; +extern char *Editor; +extern char *EmptySubject; +extern char *Escape; +extern char *FolderFormat; +extern char *ForwardAttributionIntro; +extern char *ForwardAttributionTrailer; +extern char *ForwardFormat; +extern char *Hostname; +extern struct MbTable *FromChars; +extern char *IndexFormat; +extern char *HistoryFile; + +extern char *ImapAuthenticators; +extern char *ImapDelimChars; +extern char *ImapHeaders; +extern char *ImapLogin; +extern char *ImapPass; +extern char *ImapUser; +extern char *Mbox; +extern char *Ispell; +extern char *MailcapPath; +extern char *Folder; +extern char *MessageCachedir; +extern char *HeaderCache; +extern char *HeaderCacheBackend; +extern char *HeaderCachePageSize; +extern char *MarkMacroPrefix; +extern char *MhSeqFlagged; +extern char *MhSeqReplied; +extern char *MhSeqUnseen; +extern char *MimeTypeQueryCommand; +extern char *MessageFormat; + +extern short NetInc; + +extern char *Mixmaster; +extern char *MixEntryFormat; + +extern char *GroupIndexFormat; +extern char *Inews; +extern char *NewsCacheDir; +extern char *NewsServer; +extern char *NewsgroupsCharset; +extern char *NewsRc; +extern char *NntpAuthenticators; +extern char *NntpUser; +extern char *NntpPass; +extern char *Record; +extern char *Pager; +extern char *PagerFormat; +extern char *PipeSep; +extern char *PopAuthenticators; +extern short PopCheckinterval; +extern char *PopHost; +extern char *PopPass; +extern char *PopUser; +extern char *PostIndentString; +extern char *Postponed; +extern char *PostponeEncryptAs; +extern char *IndentString; +extern char *PrintCommand; +extern char *NewMailCommand; +extern char *QueryCommand; +extern char *QueryFormat; +extern char *RealName; +extern short SearchContext; +extern char *SendCharset; +extern char *Sendmail; +extern char *Shell; +extern char *ShowMultipartAlternative; +extern char *SidebarDelimChars; +extern char *SidebarDividerChar; +extern char *SidebarFormat; +extern char *SidebarIndentString; +extern char *Signature; +extern char *SimpleSearch; +extern char *SmtpAuthenticators; +extern char *SmtpPass; +extern char *SmtpUrl; +extern char *SpoolFile; +extern char *SpamSeparator; +extern struct MbTable *StatusChars; +extern char *StatusFormat; +extern char *Tmpdir; +extern struct MbTable *ToChars; +extern struct MbTable *FlagChars; +extern char *Trash; +extern char *TSStatusFormat; +extern char *TSIconFormat; +extern char *Visual; + +extern char *HiddenTags; + +extern short NntpPoll; +extern short NntpContext; + +extern short DebugLevel; +extern char *DebugFile; + +extern short History; +extern short MenuContext; +extern short PagerContext; +extern short PagerIndexLines; +extern short ReadInc; +extern short ReflowWrap; +extern short SaveHistory; +extern short SendmailWait; +extern short SleepTime; +extern short SkipQuotedOffset; +extern short TimeInc; +extern short Timeout; +extern short Wrap; +extern short WrapHeaders; +extern short WriteInc; + +extern short ScoreThresholdDelete; +extern short ScoreThresholdRead; +extern short ScoreThresholdFlag; + +extern short SidebarComponentDepth; +extern short SidebarWidth; +extern short ImapKeepalive; +extern short ImapPipelineDepth; +extern short ImapPollTimeout; + +extern struct Regex *PgpGoodSign; +extern struct Regex *PgpDecryptionOkay; +extern char *PgpSignAs; +extern short PgpTimeout; +extern char *PgpEntryFormat; +extern char *PgpClearSignCommand; +extern char *PgpDecodeCommand; +extern char *PgpVerifyCommand; +extern char *PgpDecryptCommand; +extern char *PgpSignCommand; +extern char *PgpEncryptSignCommand; +extern char *PgpEncryptOnlyCommand; +extern char *PgpImportCommand; +extern char *PgpExportCommand; +extern char *PgpVerifyKeyCommand; +extern char *PgpListSecringCommand; +extern char *PgpListPubringCommand; +extern char *PgpGetkeysCommand; +extern char *PgpSelfEncryptAs; + +extern char *SmimeDefaultKey; +extern short SmimeTimeout; +extern char *SmimeCertificates; +extern char *SmimeKeys; +extern char *SmimeEncryptWith; +extern char *SmimeCALocation; +extern char *SmimeVerifyCommand; +extern char *SmimeVerifyOpaqueCommand; +extern char *SmimeDecryptCommand; +extern char *SmimeSignCommand; +extern char *SmimeSignDigestAlg; +extern char *SmimeEncryptCommand; +extern char *SmimeGetSignerCertCommand; +extern char *SmimePk7outCommand; +extern char *SmimeGetCertCommand; +extern char *SmimeImportCertCommand; +extern char *SmimeGetCertEmailCommand; +extern char *SmimeSelfEncryptAs; + +extern int NmOpenTimeout; +extern char *NmDefaultUri; +extern char *NmExcludeTags; +extern char *NmUnreadTag; +extern char *VfolderFormat; +extern int NmDbLimit; +extern char *NmQueryType; +extern char *NmRecordTags; +extern int NmQueryWindowDuration; +extern char *NmQueryWindowTimebase; +extern int NmQueryWindowCurrentPosition; +extern char *NmQueryWindowCurrentSearch; + +extern bool Allow8bit; +extern bool AllowAnsi; +extern bool ArrowCursor; +extern bool AsciiChars; +extern bool Askbcc; +extern bool Askcc; +extern bool AskFollowUp; +extern bool AskXCommentTo; +extern bool AttachSplit; +extern bool Autoedit; +extern bool AutoTag; +extern bool Beep; +extern bool BeepNew; +extern bool BounceDelivered; +extern bool BrailleFriendly; +extern bool ChangeFolderNext; +extern bool CheckMboxSize; +extern bool CheckNew; +extern bool CollapseAll; +extern bool CollapseFlagged; +extern bool CollapseUnread; +extern bool Confirmappend; +extern bool Confirmcreate; +extern bool CryptAutoencrypt; +extern bool CryptAutopgp; +extern bool CryptAutosign; +extern bool CryptAutosmime; +extern bool CryptConfirmhook; +extern bool CryptOpportunisticEncrypt; +extern bool CryptReplyencrypt; +extern bool CryptReplysign; +extern bool CryptReplysignencrypted; +extern bool CryptTimestamp; +extern bool CryptUseGpgme; +extern bool CryptUsePka; +extern bool DeleteUntag; +extern bool DigestCollapse; +extern bool DuplicateThreads; +extern bool EditHeaders; +extern bool EncodeFrom; +extern bool FastReply; +extern bool FccClear; +extern bool FlagSafe; +extern bool FollowupTo; +extern bool ForceName; +extern bool ForwardDecode; +extern bool ForwardDecrypt; +extern bool ForwardQuote; +extern bool ForwardReferences; +extern bool Hdrs; +extern bool Header; +extern bool HeaderCacheCompress; +extern bool HeaderColorPartial; +extern bool Help; +extern bool HiddenHost; +extern bool HideLimited; +extern bool HideMissing; +extern bool HideThreadSubject; +extern bool HideTopLimited; +extern bool HideTopMissing; +extern bool HistoryRemoveDups; +extern bool HonorDisposition; +extern bool IdnDecode; +extern bool IdnEncode; +extern bool IgnoreLinearWhiteSpace; +extern bool IgnoreListReplyTo; +extern bool ImapCheckSubscribed; +extern bool ImapIdle; +extern bool ImapListSubscribed; +extern bool ImapPassive; +extern bool ImapPeek; +extern bool ImapServernoise; +extern bool ImplicitAutoview; +extern bool IncludeOnlyfirst; +extern bool KeepFlagged; +extern bool MailcapSanitize; +extern bool MailCheckRecent; +extern bool MailCheckStats; +extern bool MaildirCheckCur; +extern bool MaildirHeaderCacheVerify; +extern bool MaildirTrash; +extern bool Markers; +extern bool MarkOld; +extern bool MenuMoveOff; /**< allow menu to scroll past last entry */ +extern bool MenuScroll; /**< scroll menu instead of implicit next-page */ +extern bool MessageCacheClean; +extern bool MetaKey; /**< interpret ALT-x as ESC-x */ +extern bool Metoo; +extern bool MhPurge; +extern bool MimeForwardDecode; +extern bool MimeSubject; /**< encode subject line with RFC2047 */ +extern bool MimeTypeQueryFirst; +extern bool NarrowTree; +extern bool NmRecord; +extern bool NntpListgroup; +extern bool NntpLoadDescription; +extern bool PagerStop; +extern bool PgpAutoDecode; +extern bool PgpAutoinline; +extern bool PgpCheckExit; +extern bool PgpIgnoreSubkeys; +extern bool PgpLongIds; +extern bool PgpReplyinline; +extern bool PgpRetainableSigs; +extern bool PgpSelfEncrypt; +extern bool PgpShowUnusable; +extern bool PgpStrictEnc; +extern bool PgpUseGpgAgent; +extern bool PipeDecode; +extern bool PipeSplit; +extern bool PopAuthTryAll; +extern bool PopLast; +extern bool PostponeEncrypt; +extern bool PrintDecode; +extern bool PrintSplit; +extern bool PromptAfter; +extern bool ReadOnly; +extern bool ReflowSpaceQuotes; +extern bool ReflowText; +extern bool ReplySelf; +extern bool ReplyWithXorig; +extern bool Resolve; +extern bool ResumeDraftFiles; +extern bool ResumeEditedDraftFiles; +extern bool ReverseAlias; +extern bool ReverseName; +extern bool ReverseRealname; +extern bool Rfc2047Parameters; +extern bool SaveAddress; +extern bool SaveEmpty; +extern bool SaveName; +extern bool SaveUnsubscribed; +extern bool Score; +extern bool ShowNewNews; +extern bool ShowOnlyUnread; +extern bool SidebarFolderIndent; +extern bool SidebarNewMailOnly; +extern bool SidebarNextNewWrap; +extern bool SidebarOnRight; +extern bool SidebarShortPath; +extern bool SidebarVisible; +extern bool SigDashes; +extern bool SigOnTop; +extern bool SmartWrap; +extern bool SmimeAskCertLabel; +extern bool SmimeDecryptUseDefaultKey; +extern bool SmimeIsDefault; +extern bool SmimeSelfEncrypt; +extern bool SortRe; +extern bool SslForceTls; +extern bool SslUseSslv2; +extern bool SslUseSslv3; +extern bool SslUsesystemcerts; +extern bool SslUseTlsv11; +extern bool SslUseTlsv12; +extern bool SslUseTlsv1; +extern bool SslVerifyDates; +extern bool SslVerifyHost; +extern bool SslVerifyPartialChains; +extern bool StatusOnTop; +extern bool StrictThreads; +extern bool Suspend; +extern bool TextFlowed; +extern bool ThoroughSearch; +extern bool ThreadReceived; +extern bool Tilde; +extern bool TsEnabled; +extern bool UncollapseJump; +extern bool UncollapseNew; +extern bool Use8bitmime; +extern bool UseDomain; +extern bool UseEnvelopeFrom; +extern bool UseFrom; +extern bool UseIpv6; +extern bool UserAgent; +extern bool VirtualSpoolfile; +extern bool WaitKey; +extern bool Weed; +extern bool WrapSearch; +extern bool WriteBcc; +extern bool XCommentTo; + +extern unsigned char AbortNoattach; +extern unsigned char AbortNosubject; +extern unsigned char AbortUnmodified; +extern unsigned char Bounce; +extern unsigned char CatchupNewsgroup; +extern unsigned char Copy; +extern unsigned char CryptVerifySig; +extern unsigned char Delete; +extern unsigned char FccAttach; +extern unsigned char FollowupToPoster; +extern unsigned char ForwardEdit; +extern unsigned char HonorFollowupTo; +extern unsigned char Include; +extern unsigned char MimeForward; +extern unsigned char MimeForwardRest; +extern unsigned char Move; +extern unsigned char PgpEncryptSelf; +extern unsigned char PgpMimeAuto; +extern unsigned char PopDelete; +extern unsigned char PopReconnect; +extern unsigned char PostModerated; +extern unsigned char Postpone; +extern unsigned char Print; +extern unsigned char Quit; +extern unsigned char Recall; +extern unsigned char ReplyTo; +extern unsigned char SmimeEncryptSelf; +extern unsigned char SslStarttls; + +extern char *AssumedCharset; +extern char *Charset; + +extern short ConnectTimeout; +extern const char *CertificateFile; +extern const char *EntropyFile; +extern const char *SslCiphers; +extern const char *SslClientCert; +extern const char *SslCaCertificatesFile; +extern short SslMinDhPrimeBits; +extern const char *Preconnect; +extern const char *Tunnel; + +extern struct Regex *GecosMask; +extern struct Regex *Mask; +extern struct Regex *QuoteRegexp; +extern struct Regex *ReplyRegexp; +extern struct Regex *Smileys; + +extern short MailCheck; +extern short MailCheckStatsInterval; +extern short MboxType; + +extern short PgpSortKeys; +extern short SidebarSortMethod; +extern short Sort; +extern short SortAlias; +extern short SortAux; +extern short SortBrowser; + +#endif /* _DUMP_VARS_H */ diff --git a/test/config/enum.c b/test/config/enum.c new file mode 100644 index 000000000..658b6357e --- /dev/null +++ b/test/config/enum.c @@ -0,0 +1,147 @@ +/** + * @file + * Test code for the Enum object + * + * @authors + * Copyright (C) 2018 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/mapping.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/bool.h" +#include "config/enum.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static short VarApple; + +// clang-format off +enum AnimalType +{ + ANIMAL_ANTELOPE = 1, + ANIMAL_BADGER = 2, + ANIMAL_CASSOWARY = 3, + ANIMAL_DINGO = 40, + ANIMAL_ECHIDNA = 41, + ANIMAL_FROG = 42, +}; + +static struct Mapping AnimalMap[] = { + { "Antelope", ANIMAL_ANTELOPE, }, + { "Badger", ANIMAL_BADGER, }, + { "Cassowary", ANIMAL_CASSOWARY, }, + { "Dingo", ANIMAL_DINGO, }, + { "Echidna", ANIMAL_ECHIDNA, }, + { "Frog", ANIMAL_FROG, }, + // Alternatives + { "bird", ANIMAL_CASSOWARY, }, + { "amphibian", ANIMAL_FROG, }, + { "carnivore", ANIMAL_BADGER, }, + { "herbivore", ANIMAL_ANTELOPE, }, + { NULL, 0, }, +}; + +struct EnumDef AnimalDef = { + "animal", + 5, + (struct Mapping *) &AnimalMap, +}; + +static struct ConfigDef Vars[] = { + { "Apple", DT_ENUM, IP &AnimalDef, &VarApple, ANIMAL_DINGO, NULL }, + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %d\n", VarApple); + + const char *name = "Apple"; + + int rc = cs_str_string_set(cs, name, "herbivore", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarApple, err->data); + + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + + short value = 41; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarApple != value) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("%s = %d, %s\n", name, VarApple, err->data); + return true; +} + +bool enum_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + enum_init(cs); + if (!cs_register_variables(cs, Vars, 0)) + return false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/enum.h b/test/config/enum.h new file mode 100644 index 000000000..87e49a1e0 --- /dev/null +++ b/test/config/enum.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Enum object + * + * @authors + * Copyright (C) 2018 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_ENUM_H +#define _TEST_ENUM_H + +#include + +bool enum_test(void); + +#endif /* _TEST_ENUM_H */ diff --git a/test/config/enum.txt b/test/config/enum.txt new file mode 100644 index 000000000..4ff7c406e --- /dev/null +++ b/test/config/enum.txt @@ -0,0 +1,9 @@ +---- enum_test --------------------------------------------- +---- set_list ---------------------------------------------- +enum Apple = Dingo +---- test_initial_values ----------------------------------- +Apple = 40 +Event: Apple has been set to 'Antelope' +Apple = 1, +Event: Apple has been set to 'Echidna' +Apple = 41, diff --git a/test/config/initial.c b/test/config/initial.c new file mode 100644 index 000000000..38c93da2c --- /dev/null +++ b/test/config/initial.c @@ -0,0 +1,122 @@ +/** + * @file + * Test code for pre-setting initial values + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/set.h" +#include "config/string3.h" +#include "config/types.h" +#include "config/common.h" + +static char *VarApple; +static char *VarBanana; +static char *VarCherry; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_STRING, 0, &VarApple, IP "apple", NULL }, + { "Banana", DT_STRING, 0, &VarBanana, 0, NULL }, + { "Cherry", DT_STRING, 0, &VarCherry, 0, NULL }, + { NULL }, +}; +// clang-format on + +static bool test_set_initial(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name; + + name = "Apple"; + struct HashElem *he_a = cs_get_elem(cs, name); + if (!he_a) + return false; + + const char *aval = "pie"; + int rc = cs_he_initial_set(cs, he_a, aval, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + printf("Expected error: %s\n", err->data); + + name = "Banana"; + struct HashElem *he_b = cs_get_elem(cs, name); + if (!he_b) + return false; + + const char *bval = "split"; + rc = cs_he_initial_set(cs, he_b, bval, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + name = "Cherry"; + struct HashElem *he_c = cs_get_elem(cs, name); + if (!he_c) + return false; + + const char *cval = "blossom"; + rc = cs_str_initial_set(cs, name, cval, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + printf("Apple = %s\n", VarApple); + printf("Banana = %s\n", VarBanana); + printf("Cherry = %s\n", VarCherry); + + return ((mutt_str_strcmp(VarApple, aval) != 0) && + (mutt_str_strcmp(VarBanana, bval) != 0) && + (mutt_str_strcmp(VarCherry, cval) != 0)); +} + +bool initial_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + string_init(cs); + if (!cs_register_variables(cs, Vars, 0)) + return false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_set_initial(cs, &err)) + { + cs_free(&cs); + FREE(&err.data); + return false; + } + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/initial.h b/test/config/initial.h new file mode 100644 index 000000000..3f75ffab2 --- /dev/null +++ b/test/config/initial.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for pre-setting initial values + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_INITIAL_H +#define _TEST_INITIAL_H + +#include + +bool initial_test(void); + +#endif /* _TEST_INITIAL_H */ diff --git a/test/config/initial.txt b/test/config/initial.txt new file mode 100644 index 000000000..35bc54bbf --- /dev/null +++ b/test/config/initial.txt @@ -0,0 +1,12 @@ +---- initial_test ------------------------------------------ +---- set_list ---------------------------------------------- +string Apple = apple +string Banana = +string Cherry = +---- test_set_initial -------------------------------------- +Event: Apple has been initial-set to 'pie' +Event: Banana has been initial-set to 'split' +Event: Cherry has been initial-set to 'blossom' +Apple = apple +Banana = (null) +Cherry = (null) diff --git a/test/config/long.c b/test/config/long.c new file mode 100644 index 000000000..e41a46eb4 --- /dev/null +++ b/test/config/long.c @@ -0,0 +1,606 @@ +/** + * @file + * Test code for the Long object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/long.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static short VarApple; +static short VarBanana; +static short VarCherry; +static short VarDamson; +static short VarElderberry; +static short VarFig; +static short VarGuava; +static short VarHawthorn; +static short VarIlama; +static short VarJackfruit; +static short VarKumquat; +static short VarLemon; +static short VarMango; +static short VarNectarine; +static short VarOlive; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_LONG, 0, &VarApple, -42, NULL }, /* test_initial_values */ + { "Banana", DT_LONG, 0, &VarBanana, 99, NULL }, + { "Cherry", DT_LONG, 0, &VarCherry, 33, NULL }, + { "Damson", DT_LONG, 0, &VarDamson, 0, NULL }, /* test_string_set */ + { "Elderberry", DT_LONG|DT_NOT_NEGATIVE, 0, &VarElderberry, 0, NULL }, + { "Fig", DT_LONG, 0, &VarFig, 0, NULL }, /* test_string_get */ + { "Guava", DT_LONG, 0, &VarGuava, 0, NULL }, /* test_native_set */ + { "Hawthorn", DT_LONG|DT_NOT_NEGATIVE, 0, &VarHawthorn, 0, NULL }, + { "Ilama", DT_LONG, 0, &VarIlama, 0, NULL }, /* test_native_get */ + { "Jackfruit", DT_LONG, 0, &VarJackfruit, 99, NULL }, /* test_reset */ + { "Kumquat", DT_LONG, 0, &VarKumquat, 33, validator_fail }, + { "Lemon", DT_LONG, 0, &VarLemon, 0, validator_succeed }, /* test_validator */ + { "Mango", DT_LONG, 0, &VarMango, 0, validator_warn }, + { "Nectarine", DT_LONG, 0, &VarNectarine, 0, validator_fail }, + { "Olive", DT_LONG, 0, &VarOlive, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %d\n", VarApple); + printf("Banana = %d\n", VarBanana); + + if ((VarApple != -42) || (VarBanana != 99)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "2001", err); + cs_str_string_set(cs, "Banana", "1999", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "-42") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = %d\n", VarApple); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "99") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = %d\n", VarBanana); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "123", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = %d\n", VarCherry); + printf("Cherry's initial value is %s\n", value.data); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "-123", "0", "-42", "456" }; + int longs[] = { -123, 0, -42, 456 }; + const char *invalid[] = { "-2147483648", "2147483648", "junk", "", NULL }; + + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + VarDamson = -42; + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (VarDamson != longs[i]) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = %d, set by '%s'\n", name, VarDamson, valid[i]); + } + + printf("\n"); + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%s'\n", name, VarDamson, invalid[i]); + printf("This test should have failed\n"); + // return false; + } + } + + name = "Elderberry"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "-42", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("This test should have failed\n"); + // return false; + } + else + { + printf("Expected error: %s\n", err->data); + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Fig"; + + VarFig = 123; + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarFig, err->data); + + VarFig = -789; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarFig, err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Guava"; + short value = 12345; + + VarGuava = 0; + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarGuava != value) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("%s = %d, set to '%d'\n", name, VarGuava, value); + + rc = cs_str_native_set(cs, name, value, err); + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + } + else + { + printf("This test should have failed\n"); + return false; + } + + name = "Hawthorn"; + rc = cs_str_native_set(cs, name, -42, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("This test should have failed\n"); + return false; + } + + int invalid[] = { -32769, 32768 }; + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + VarGuava = 123; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%d'\n", name, VarGuava, invalid[i]); + printf("This test should have failed\n"); + // return false; + } + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Ilama"; + + VarIlama = 3456; + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %ld\n", name, value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Jackfruit"; + VarJackfruit = 345; + mutt_buffer_reset(err); + + int rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarJackfruit == 345) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarJackfruit); + + name = "Kumquat"; + mutt_buffer_reset(err); + + printf("Initial: %s = %d\n", name, VarKumquat); + dont_fail = true; + rc = cs_str_string_set(cs, name, "99", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = %d\n", name, VarKumquat); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (VarKumquat != 99) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarKumquat); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Lemon"; + VarLemon = 123; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "456", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarLemon); + + VarLemon = 456; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 123, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarLemon); + + name = "Mango"; + VarMango = 123; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "456", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarMango); + + VarMango = 456; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 123, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarMango); + + name = "Nectarine"; + VarNectarine = 123; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "456", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarNectarine); + + VarNectarine = 456; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 123, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarNectarine); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %ld\n", parent, pval); + printf("%15s = %ld\n", child, cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Olive"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + VarOlive = 123; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "456", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "-99", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool long_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + long_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/long.h b/test/config/long.h new file mode 100644 index 000000000..3117640ee --- /dev/null +++ b/test/config/long.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Long object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_LONG_H +#define _TEST_LONG_H + +#include + +bool long_test(void); + +#endif /* _TEST_LONG_H */ diff --git a/test/config/long.txt b/test/config/long.txt new file mode 100644 index 000000000..43f5b5ce9 --- /dev/null +++ b/test/config/long.txt @@ -0,0 +1,100 @@ +---- long_test --------------------------------------------- +---- set_list ---------------------------------------------- +long Apple = -42 +long Banana = 99 +long Cherry = 33 +long Damson = 0 +long Elderberry = 0 +long Fig = 0 +long Guava = 0 +long Hawthorn = 0 +long Ilama = 0 +long Jackfruit = 99 +long Kumquat = 33 +long Lemon = 0 +long Mango = 0 +long Nectarine = 0 +long Olive = 0 +---- test_initial_values ----------------------------------- +Apple = -42 +Banana = 99 +Event: Apple has been set to '2001' +Event: Banana has been set to '1999' +Apple = 2001 +Apple's initial value is '-42' +Banana = 1999 +Banana's initial value is '99' +Event: Cherry has been initial-set to '123' +Cherry = 33 +Cherry's initial value is 123 +---- test_string_set --------------------------------------- +Event: Damson has been set to '-123' +Damson = -123, set by '-123' +Event: Damson has been set to '0' +Damson = 0, set by '0' +Value of Damson wasn't changed +Event: Damson has been set to '456' +Damson = 456, set by '456' + +Event: Damson has been set to '0' +Damson = 0, set by '-2147483648' +This test should have failed +Event: Damson has been set to '0' +Damson = 0, set by '2147483648' +This test should have failed +Expected error: Invalid long: junk +Expected error: Invalid long: +Expected error: Invalid long: (null) +Expected error: Option Elderberry may not be negative +---- test_string_get --------------------------------------- +Fig = 123, 123 +Fig = -789, -789 +---- test_native_set --------------------------------------- +Event: Guava has been set to '12345' +Guava = 12345, set to '12345' +Value of Guava wasn't changed +Expected error: Option Hawthorn may not be negative +Expected error: Option Hawthorn may not be negative +Event: Hawthorn has been set to '-32768' +Hawthorn = 123, set by '32768' +This test should have failed +---- test_native_get --------------------------------------- +Ilama = 3456 +---- test_reset -------------------------------------------- +Event: Jackfruit has been reset to '99' +Reset: Jackfruit = 99 +Initial: Kumquat = 33 +Event: Kumquat has been set to '99' +Set: Kumquat = 99 +Expected error: validator_fail: Kumquat, 33 +Reset: Kumquat = 99 +---- test_validator ---------------------------------------- +Event: Lemon has been set to '456' +validator_succeed: Lemon, 456 +String: Lemon = 456 +Event: Lemon has been set to '123' +validator_succeed: Lemon, 123 +Native: Lemon = 123 +Event: Mango has been set to '456' +validator_warn: Mango, 456 +String: Mango = 456 +Event: Mango has been set to '123' +validator_warn: Mango, 123 +Native: Mango = 123 +Expected error: validator_fail: Nectarine, 456 +String: Nectarine = 123 +Expected error: validator_fail: Nectarine, 123 +Native: Nectarine = 456 +---- test_inherit ------------------------------------------ +Event: Olive has been set to '456' + Olive = 456 + fruit:Olive = 456 +Event: fruit:Olive has been set to '-99' + Olive = 456 + fruit:Olive = -99 +Event: fruit:Olive has been reset to '456' + Olive = 456 + fruit:Olive = 456 +Event: Olive has been reset to '0' + Olive = 0 + fruit:Olive = 0 diff --git a/test/config/magic.c b/test/config/magic.c new file mode 100644 index 000000000..8f354a3f2 --- /dev/null +++ b/test/config/magic.c @@ -0,0 +1,594 @@ +/** + * @file + * Test code for the Magic object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/magic.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static short VarApple; +static short VarBanana; +static short VarCherry; +static short VarDamson; +static short VarElderberry; +static short VarFig; +static short VarGuava; +static short VarHawthorn; +static short VarIlama; +static short VarJackfruit; +static short VarKumquat; +static short VarLemon; +static short VarMango; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_MAGIC, 0, &VarApple, 1, NULL }, /* test_initial_values */ + { "Banana", DT_MAGIC, 0, &VarBanana, 3, NULL }, + { "Cherry", DT_MAGIC, 0, &VarCherry, 1, NULL }, + { "Damson", DT_MAGIC, 0, &VarDamson, 1, NULL }, /* test_string_set */ + { "Elderberry", DT_MAGIC, 0, &VarElderberry, 1, NULL }, /* test_string_get */ + { "Fig", DT_MAGIC, 0, &VarFig, 1, NULL }, /* test_native_set */ + { "Guava", DT_MAGIC, 0, &VarGuava, 1, NULL }, /* test_native_get */ + { "Hawthorn", DT_MAGIC, 0, &VarHawthorn, 1, NULL }, /* test_reset */ + { "Ilama", DT_MAGIC, 0, &VarIlama, 1, validator_fail }, + { "Jackfruit", DT_MAGIC, 0, &VarJackfruit, 1, validator_succeed }, /* test_validator */ + { "Kumquat", DT_MAGIC, 0, &VarKumquat, 1, validator_warn }, + { "Lemon", DT_MAGIC, 0, &VarLemon, 1, validator_fail }, + { "Mango", DT_MAGIC, 0, &VarMango, 1, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %d\n", VarApple); + printf("Banana = %d\n", VarBanana); + + if ((VarApple != 1) || (VarBanana != 3)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "MMDF", err); + cs_str_string_set(cs, "Banana", "Maildir", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "mbox") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = %d\n", VarApple); + printf("Apple's initial value is %s\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "MH") != 0) + { + printf("Banana's initial value is wrong: %s\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = %d\n", VarBanana); + printf("Banana's initial value is %s\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "mmdf", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = %s\n", magic_values[VarCherry]); + printf("Cherry's initial value is %s\n", value.data); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "mbox", "mmdf", "mh", "maildir" }; + const char *invalid[] = { "mbox2", "mm", "", NULL }; + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + VarDamson = ((i + 1) % 4) + 1; + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarDamson == (((i + 1) % 4) + 1)) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = %d, set by '%s'\n", name, VarDamson, valid[i]); + } + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "maildir", err); + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + } + else + { + printf("This test should have failed\n"); + return false; + } + + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%s'\n", name, VarDamson, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Elderberry"; + + int valid[] = { MUTT_MBOX, MUTT_MMDF, MUTT_MH, MUTT_MAILDIR }; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + VarElderberry = valid[i]; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarElderberry, err->data); + } + + VarElderberry = 5; + mutt_buffer_reset(err); + printf("Expect error for next test\n"); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Fig"; + short value = MUTT_MAILDIR; + + VarFig = MUTT_MBOX; + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarFig != value) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("%s = %d, set to '%d'\n", name, VarFig, value); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, MUTT_MAILDIR, err); + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + } + else + { + printf("This test should have failed\n"); + return false; + } + + int invalid[] = { 0, 5 }; + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + VarFig = MUTT_MBOX; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%d'\n", name, VarFig, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Guava"; + + VarGuava = MUTT_MAILDIR; + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %ld\n", name, value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Hawthorn"; + VarHawthorn = MUTT_MAILDIR; + mutt_buffer_reset(err); + + int rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarHawthorn == MUTT_MAILDIR) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarHawthorn); + + mutt_buffer_reset(err); + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + name = "Ilama"; + mutt_buffer_reset(err); + + printf("Initial: %s = %d\n", name, VarIlama); + dont_fail = true; + rc = cs_str_string_set(cs, name, "maildir", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = %d\n", name, VarIlama); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (VarIlama != MUTT_MAILDIR) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarIlama); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Jackfruit"; + VarJackfruit = MUTT_MBOX; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "maildir", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarJackfruit); + + VarJackfruit = MUTT_MBOX; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, MUTT_MAILDIR, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarJackfruit); + + name = "Kumquat"; + VarKumquat = MUTT_MBOX; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "maildir", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarKumquat); + + VarKumquat = MUTT_MBOX; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, MUTT_MAILDIR, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarKumquat); + + name = "Lemon"; + VarLemon = MUTT_MBOX; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "maildir", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarLemon); + + VarLemon = MUTT_MBOX; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, MUTT_MAILDIR, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarLemon); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %ld\n", parent, pval); + printf("%15s = %ld\n", child, cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Mango"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "maildir", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "mh", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool magic_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + magic_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/magic.h b/test/config/magic.h new file mode 100644 index 000000000..19aeb5386 --- /dev/null +++ b/test/config/magic.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Magic object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_MAGIC_H +#define _TEST_MAGIC_H + +#include + +bool magic_test(void); + +#endif /* _TEST_MAGIC_H */ diff --git a/test/config/magic.txt b/test/config/magic.txt new file mode 100644 index 000000000..f922d1409 --- /dev/null +++ b/test/config/magic.txt @@ -0,0 +1,94 @@ +---- magic_test -------------------------------------------- +---- set_list ---------------------------------------------- +magic Apple = mbox +magic Banana = MH +magic Cherry = mbox +magic Damson = mbox +magic Elderberry = mbox +magic Fig = mbox +magic Guava = mbox +magic Hawthorn = mbox +magic Ilama = mbox +magic Jackfruit = mbox +magic Kumquat = mbox +magic Lemon = mbox +magic Mango = mbox +---- test_initial_values ----------------------------------- +Apple = 1 +Banana = 3 +Event: Apple has been set to 'MMDF' +Event: Banana has been set to 'Maildir' +Apple = 2 +Apple's initial value is mbox +Banana = 4 +Banana's initial value is MH +Event: Cherry has been initial-set to 'MMDF' +Cherry = mbox +Cherry's initial value is MMDF +---- test_string_set --------------------------------------- +Event: Damson has been set to 'mbox' +Damson = 1, set by 'mbox' +Event: Damson has been set to 'MMDF' +Damson = 2, set by 'mmdf' +Event: Damson has been set to 'MH' +Damson = 3, set by 'mh' +Event: Damson has been set to 'Maildir' +Damson = 4, set by 'maildir' +Value of Damson wasn't changed +Expected error: Invalid magic value: mbox2 +Expected error: Invalid magic value: mm +Expected error: Option Damson may not be empty +Expected error: Option Damson may not be empty +---- test_string_get --------------------------------------- +Elderberry = 1, mbox +Elderberry = 2, MMDF +Elderberry = 3, MH +Elderberry = 4, Maildir +Expect error for next test +Variable has an invalid value: 5 +---- test_native_set --------------------------------------- +Event: Fig has been set to 'Maildir' +Fig = 4, set to '4' +Value of Fig wasn't changed +Expected error: Invalid magic value: 0 +Expected error: Invalid magic value: 5 +---- test_native_get --------------------------------------- +Guava = 4 +---- test_reset -------------------------------------------- +Event: Hawthorn has been reset to 'mbox' +Reset: Hawthorn = 1 +Initial: Ilama = 1 +Event: Ilama has been set to 'Maildir' +Set: Ilama = 4 +Expected error: validator_fail: Ilama, 1 +Reset: Ilama = 4 +---- test_validator ---------------------------------------- +Event: Jackfruit has been set to 'Maildir' +validator_succeed: Jackfruit, 4 +String: Jackfruit = 4 +Event: Jackfruit has been set to 'Maildir' +validator_succeed: Jackfruit, 4 +Native: Jackfruit = 4 +Event: Kumquat has been set to 'Maildir' +validator_warn: Kumquat, 4 +String: Kumquat = 4 +Event: Kumquat has been set to 'Maildir' +validator_warn: Kumquat, 4 +Native: Kumquat = 4 +Expected error: validator_fail: Lemon, 4 +String: Lemon = 1 +Expected error: validator_fail: Lemon, 4 +Native: Lemon = 1 +---- test_inherit ------------------------------------------ +Event: Mango has been set to 'Maildir' + Mango = 4 + fruit:Mango = 4 +Event: fruit:Mango has been set to 'MH' + Mango = 4 + fruit:Mango = 3 +Event: fruit:Mango has been reset to 'Maildir' + Mango = 4 + fruit:Mango = 4 +Event: Mango has been reset to 'mbox' + Mango = 1 + fruit:Mango = 1 diff --git a/test/config/main.c b/test/config/main.c new file mode 100644 index 000000000..2d28f531a --- /dev/null +++ b/test/config/main.c @@ -0,0 +1,115 @@ +#include "config.h" +#include +#include +#include +#include +#include +#include "mutt/logging.h" +#include "dump/dump.h" +#include "test/config/account2.h" +#include "test/config/address.h" +#include "test/config/bool.h" +#include "test/config/command.h" +#include "test/config/initial.h" +#include "test/config/long.h" +#include "test/config/magic.h" +#include "test/config/mbtable.h" +#include "test/config/number.h" +#include "test/config/path.h" +#include "test/config/quad.h" +#include "test/config/regex3.h" +#include "test/config/set.h" +#include "test/config/sort.h" +#include "test/config/string4.h" +#include "test/config/synonym.h" + +typedef bool (*test_fn)(void); + +int log_disp_stdout(time_t stamp, const char *file, int line, + const char *function, int level, ...) +{ + int err = errno; + + va_list ap; + va_start(ap, level); + const char *fmt = va_arg(ap, const char *); + int ret = vprintf(fmt, ap); + va_end(ap); + + if (level == LL_PERROR) + ret += printf("%s", strerror(err)); + + return ret; +} + +struct Test +{ + const char *name; + test_fn function; +}; + +// clang-format off +struct Test test[] = { + { "set", set_test }, + { "account", account_test }, + { "initial", initial_test }, + { "synonym", synonym_test }, + { "address", address_test }, + { "bool", bool_test }, + { "command", command_test }, + { "long", long_test }, + { "magic", magic_test }, + { "mbtable", mbtable_test }, + { "number", number_test }, + { "path", path_test }, + { "quad", quad_test }, + { "regex", regex_test }, + { "sort", sort_test }, + { "string", string_test }, + { "dump", dump_test }, + { NULL }, +}; +// clang-format on + +int main(int argc, char *argv[]) +{ + int result = 0; + + if (argc < 2) + { + printf("Usage: %s TEST ...\n", argv[0]); + for (int i = 0; test[i].name; i++) + printf(" %s\n", test[i].name); + return 1; + } + + MuttLogger = log_disp_stdout; + + for (; --argc > 0; argv++) + { + struct Test *t = NULL; + + for (int i = 0; test[i].name; i++) + { + if (strcmp(argv[1], test[i].name) == 0) + { + t = &test[i]; + break; + } + } + if (!t) + { + printf("Unknown test '%s'\n", argv[1]); + result = 1; + continue; + } + + if (!t->function()) + { + printf("%s_test() failed\n", t->name); + result = 1; + } + } + + return result; +} diff --git a/test/config/mbtable.c b/test/config/mbtable.c new file mode 100644 index 000000000..89d8ee3a8 --- /dev/null +++ b/test/config/mbtable.c @@ -0,0 +1,647 @@ +/** + * @file + * Test code for the Mbtable object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/mbtable.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static struct MbTable *VarApple; +static struct MbTable *VarBanana; +static struct MbTable *VarCherry; +static struct MbTable *VarDamson; +static struct MbTable *VarElderberry; +static struct MbTable *VarFig; +static struct MbTable *VarGuava; +static struct MbTable *VarHawthorn; +static struct MbTable *VarIlama; +static struct MbTable *VarJackfruit; +static struct MbTable *VarKumquat; +static struct MbTable *VarLemon; +static struct MbTable *VarMango; +static struct MbTable *VarNectarine; +static struct MbTable *VarOlive; +static struct MbTable *VarPapaya; +static struct MbTable *VarQuince; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_MBTABLE, 0, &VarApple, IP "apple", NULL }, /* test_initial_values */ + { "Banana", DT_MBTABLE, 0, &VarBanana, IP "banana", NULL }, + { "Cherry", DT_MBTABLE, 0, &VarCherry, IP "cherry", NULL }, + { "Damson", DT_MBTABLE, 0, &VarDamson, 0, NULL }, /* test_mbtable_set */ + { "Elderberry", DT_MBTABLE, 0, &VarElderberry, IP "elderberry", NULL }, + { "Fig", DT_MBTABLE, 0, &VarFig, 0, NULL }, /* test_mbtable_get */ + { "Guava", DT_MBTABLE, 0, &VarGuava, IP "guava", NULL }, + { "Hawthorn", DT_MBTABLE, 0, &VarHawthorn, 0, NULL }, + { "Ilama", DT_MBTABLE, 0, &VarIlama, 0, NULL }, /* test_native_set */ + { "Jackfruit", DT_MBTABLE, 0, &VarJackfruit, IP "jackfruit", NULL }, + { "Kumquat", DT_MBTABLE, 0, &VarKumquat, 0, NULL }, /* test_native_get */ + { "Lemon", DT_MBTABLE, 0, &VarLemon, IP "lemon", NULL }, /* test_reset */ + { "Mango", DT_MBTABLE, 0, &VarMango, IP "mango", validator_fail }, + { "Nectarine", DT_MBTABLE, 0, &VarNectarine, IP "nectarine", validator_succeed }, /* test_validator */ + { "Olive", DT_MBTABLE, 0, &VarOlive, IP "olive", validator_warn }, + { "Papaya", DT_MBTABLE, 0, &VarPapaya, IP "papaya", validator_fail }, + { "Quince", DT_MBTABLE, 0, &VarQuince, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %s\n", VarApple->orig_str); + printf("Banana = %s\n", VarBanana->orig_str); + + if ((mutt_str_strcmp(VarApple->orig_str, "apple") != 0) || + (mutt_str_strcmp(VarBanana->orig_str, "banana") != 0)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "car", err); + cs_str_string_set(cs, "Banana", "train", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "apple") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = '%s'\n", VarApple ? VarApple->orig_str : ""); + printf("Apple's initial value is %s\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "banana") != 0) + { + printf("Banana's initial value is wrong: %s\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = '%s'\n", VarBanana ? VarBanana->orig_str : ""); + printf("Banana's initial value is %s\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "config.*", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "file.*", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry->orig_str); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello", "world", "world", "", NULL }; + char *name = "Damson"; + char *mb = NULL; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + mb = VarDamson ? VarDamson->orig_str : NULL; + if (mutt_str_strcmp(mb, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(mb), NONULL(valid[i])); + } + + name = "Elderberry"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + const char *orig_str = VarElderberry ? VarElderberry->orig_str : NULL; + if (mutt_str_strcmp(orig_str, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(orig_str), NONULL(valid[i])); + } + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "\377", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Fig"; + char *mb = NULL; + + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + mb = VarFig ? VarFig->orig_str : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(mb), err->data); + + name = "Guava"; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + mb = VarGuava ? VarGuava->orig_str : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(mb), err->data); + + name = "Hawthorn"; + rc = cs_str_string_set(cs, name, "hawthorn", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + mb = VarHawthorn ? VarHawthorn->orig_str : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(mb), err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + struct MbTable *t = mbtable_parse("hello"); + char *name = "Ilama"; + char *mb = NULL; + bool result = false; + + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, (intptr_t) t, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + goto tns_out; + } + + mb = VarIlama ? VarIlama->orig_str : NULL; + if (mutt_str_strcmp(mb, t->orig_str) != 0) + { + printf("Value of %s wasn't changed\n", name); + goto tns_out; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(mb), t->orig_str); + + name = "Jackfruit"; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 0, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + goto tns_out; + } + + if (VarJackfruit != NULL) + { + printf("Value of %s wasn't changed\n", name); + goto tns_out; + } + mb = VarJackfruit ? VarJackfruit->orig_str : NULL; + printf("%s = '%s', set by NULL\n", name, NONULL(mb)); + + result = true; +tns_out: + mbtable_free(&t); + return result; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Kumquat"; + + int rc = cs_str_string_set(cs, name, "kumquat", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + struct MbTable *t = (struct MbTable *) value; + + if (VarKumquat != t) + { + printf("Get failed: %s\n", err->data); + return false; + } + char *mb1 = VarKumquat ? VarKumquat->orig_str : NULL; + char *mb2 = t ? t->orig_str : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(mb1), NONULL(mb2)); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Lemon"; + char *mb = NULL; + + mutt_buffer_reset(err); + + mb = VarLemon ? VarLemon->orig_str : NULL; + printf("Initial: %s = '%s'\n", name, NONULL(mb)); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + mb = VarLemon ? VarLemon->orig_str : NULL; + printf("Set: %s = '%s'\n", name, NONULL(mb)); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + mb = VarLemon ? VarLemon->orig_str : NULL; + if (mutt_str_strcmp(mb, "lemon") != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, NONULL(mb)); + + name = "Mango"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarMango->orig_str); + dont_fail = true; + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarMango->orig_str); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarMango->orig_str, "hello") != 0) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarMango->orig_str); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + struct MbTable *t = mbtable_parse("world"); + bool result = false; + + char *name = "Nectarine"; + char *mb = NULL; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + mb = VarNectarine ? VarNectarine->orig_str : NULL; + printf("MbTable: %s = %s\n", name, NONULL(mb)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP t, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + mb = VarNectarine ? VarNectarine->orig_str : NULL; + printf("Native: %s = %s\n", name, NONULL(mb)); + + name = "Olive"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + mb = VarOlive ? VarOlive->orig_str : NULL; + printf("MbTable: %s = %s\n", name, NONULL(mb)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP t, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + mb = VarOlive ? VarOlive->orig_str : NULL; + printf("Native: %s = %s\n", name, NONULL(mb)); + + name = "Papaya"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + mb = VarPapaya ? VarPapaya->orig_str : NULL; + printf("MbTable: %s = %s\n", name, NONULL(mb)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP t, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + mb = VarPapaya ? VarPapaya->orig_str : NULL; + printf("Native: %s = %s\n", name, NONULL(mb)); + + result = true; +tv_out: + mbtable_free(&t); + return result; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + struct MbTable *pa = (struct MbTable *) pval; + struct MbTable *ca = (struct MbTable *) cval; + + char *pstr = pa ? pa->orig_str : NULL; + char *cstr = ca ? ca->orig_str : NULL; + + printf("%15s = %s\n", parent, NONULL(pstr)); + printf("%15s = %s\n", child, NONULL(cstr)); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Quince"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarMb[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarMb); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "world", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool mbtable_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + mbtable_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/mbtable.h b/test/config/mbtable.h new file mode 100644 index 000000000..cd19a1b61 --- /dev/null +++ b/test/config/mbtable.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Mbtable object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_MBTABLE_H +#define _TEST_MBTABLE_H + +#include + +bool mbtable_test(void); + +#endif /* _TEST_MBTABLE_H */ diff --git a/test/config/mbtable.txt b/test/config/mbtable.txt new file mode 100644 index 000000000..a9ba9a0b2 --- /dev/null +++ b/test/config/mbtable.txt @@ -0,0 +1,107 @@ +---- mbtable_test ------------------------------------------ +---- set_list ---------------------------------------------- +mbtable Apple = apple +mbtable Banana = banana +mbtable Cherry = cherry +mbtable Damson = +mbtable Elderberry = elderberry +mbtable Fig = +mbtable Guava = guava +mbtable Hawthorn = +mbtable Ilama = +mbtable Jackfruit = jackfruit +mbtable Kumquat = +mbtable Lemon = lemon +mbtable Mango = mango +mbtable Nectarine = nectarine +mbtable Olive = olive +mbtable Papaya = papaya +mbtable Quince = +---- test_initial_values ----------------------------------- +Apple = apple +Banana = banana +Event: Apple has been set to 'car' +Event: Banana has been set to 'train' +Apple = 'car' +Apple's initial value is apple +Banana = 'train' +Banana's initial value is banana +Event: Cherry has been initial-set to 'config.*' +Event: Cherry has been initial-set to 'file.*' +Cherry = 'cherry' +Cherry's initial value is 'file.*' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'hello' +Damson = 'hello', set by 'hello' +Event: Damson has been set to 'world' +Damson = 'world', set by 'world' +Value of Damson wasn't changed +Event: Damson has been set to '' +Damson = '', set by '' +Event: Damson has been set to '' +Damson = '', set by '' +Event: Elderberry has been set to 'hello' +Elderberry = 'hello', set by 'hello' +Event: Elderberry has been set to 'world' +Elderberry = 'world', set by 'world' +Value of Elderberry wasn't changed +Event: Elderberry has been set to '' +Elderberry = '', set by '' +Event: Elderberry has been set to '' +Elderberry = '', set by '' +mbtable_parse: mbrtowc returned -1 converting ÿ in ÿ +Event: Elderberry has been set to 'ÿ' +---- test_string_get --------------------------------------- +Fig = '', '' +Guava = 'guava', 'guava' +Event: Hawthorn has been set to 'hawthorn' +Hawthorn = 'hawthorn', 'hawthorn' +---- test_native_set --------------------------------------- +Event: Ilama has been set to 'hello' +Ilama = 'hello', set by 'hello' +Event: Jackfruit has been set to '' +Jackfruit = '', set by NULL +---- test_native_get --------------------------------------- +Event: Kumquat has been set to 'kumquat' +Kumquat = 'kumquat', 'kumquat' +---- test_reset -------------------------------------------- +Initial: Lemon = 'lemon' +Event: Lemon has been set to 'hello' +Set: Lemon = 'hello' +Event: Lemon has been reset to 'lemon' +Reset: Lemon = 'lemon' +Initial: Mango = 'mango' +Event: Mango has been set to 'hello' +Set: Mango = 'hello' +Expected error: validator_fail: Mango, (ptr) +Reset: Mango = 'hello' +---- test_validator ---------------------------------------- +Event: Nectarine has been set to 'hello' +validator_succeed: Nectarine, (ptr) +MbTable: Nectarine = hello +Event: Nectarine has been set to 'world' +validator_succeed: Nectarine, (ptr) +Native: Nectarine = world +Event: Olive has been set to 'hello' +validator_warn: Olive, (ptr) +MbTable: Olive = hello +Event: Olive has been set to 'world' +validator_warn: Olive, (ptr) +Native: Olive = world +Expected error: validator_fail: Papaya, (ptr) +MbTable: Papaya = papaya +Expected error: validator_fail: Papaya, (ptr) +Native: Papaya = papaya +---- test_inherit ------------------------------------------ +Event: Quince has been set to 'hello' + Quince = hello + fruit:Quince = hello +Event: fruit:Quince has been set to 'world' + Quince = hello + fruit:Quince = world +Event: fruit:Quince has been reset to 'hello' + Quince = hello + fruit:Quince = hello +Event: Quince has been reset to '' + Quince = + fruit:Quince = diff --git a/test/config/number.c b/test/config/number.c new file mode 100644 index 000000000..bb8d22f89 --- /dev/null +++ b/test/config/number.c @@ -0,0 +1,605 @@ +/** + * @file + * Test code for the Number object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/number.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static short VarApple; +static short VarBanana; +static short VarCherry; +static short VarDamson; +static short VarElderberry; +static short VarFig; +static short VarGuava; +static short VarHawthorn; +static short VarIlama; +static short VarJackfruit; +static short VarKumquat; +static short VarLemon; +static short VarMango; +static short VarNectarine; +static short VarOlive; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_NUMBER, 0, &VarApple, -42, NULL }, /* test_initial_values */ + { "Banana", DT_NUMBER, 0, &VarBanana, 99, NULL }, + { "Cherry", DT_NUMBER, 0, &VarCherry, 33, NULL }, + { "Damson", DT_NUMBER, 0, &VarDamson, 0, NULL }, /* test_string_set */ + { "Elderberry", DT_NUMBER|DT_NOT_NEGATIVE, 0, &VarElderberry, 0, NULL }, + { "Fig", DT_NUMBER, 0, &VarFig, 0, NULL }, /* test_string_get */ + { "Guava", DT_NUMBER, 0, &VarGuava, 0, NULL }, /* test_native_set */ + { "Hawthorn", DT_NUMBER|DT_NOT_NEGATIVE, 0, &VarHawthorn, 0, NULL }, + { "Ilama", DT_NUMBER, 0, &VarIlama, 0, NULL }, /* test_native_get */ + { "Jackfruit", DT_NUMBER, 0, &VarJackfruit, 99, NULL }, /* test_reset */ + { "Kumquat", DT_NUMBER, 0, &VarKumquat, 33, validator_fail }, + { "Lemon", DT_NUMBER, 0, &VarLemon, 0, validator_succeed }, /* test_validator */ + { "Mango", DT_NUMBER, 0, &VarMango, 0, validator_warn }, + { "Nectarine", DT_NUMBER, 0, &VarNectarine, 0, validator_fail }, + { "Olive", DT_NUMBER, 0, &VarOlive, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %d\n", VarApple); + printf("Banana = %d\n", VarBanana); + + if ((VarApple != -42) || (VarBanana != 99)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "2001", err); + cs_str_string_set(cs, "Banana", "1999", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "-42") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = %d\n", VarApple); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "99") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = %d\n", VarBanana); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "123", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = %d\n", VarCherry); + printf("Cherry's initial value is %s\n", value.data); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "-123", "0", "-42", "456" }; + int numbers[] = { -123, 0, -42, 456 }; + const char *invalid[] = { "-32769", "32768", "junk", "", NULL }; + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + VarDamson = -42; + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (VarDamson != numbers[i]) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = %d, set by '%s'\n", name, VarDamson, valid[i]); + } + + printf("\n"); + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%s'\n", name, VarDamson, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + name = "Elderberry"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "-42", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("This test should have failed\n"); + return false; + } + else + { + printf("Expected error: %s\n", err->data); + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Fig"; + + VarFig = 123; + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarFig, err->data); + + VarFig = -789; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarFig, err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Guava"; + short value = 12345; + + VarGuava = 0; + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarGuava != value) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("%s = %d, set to '%d'\n", name, VarGuava, value); + + rc = cs_str_native_set(cs, name, value, err); + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + } + else + { + printf("This test should have failed\n"); + return false; + } + + name = "Hawthorn"; + rc = cs_str_native_set(cs, name, -42, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("This test should have failed\n"); + return false; + } + + int invalid[] = { -32769, 32768 }; + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + VarGuava = 123; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%d'\n", name, VarGuava, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Ilama"; + + VarIlama = 3456; + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %ld\n", name, value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Jackfruit"; + VarJackfruit = 345; + mutt_buffer_reset(err); + + int rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarJackfruit == 345) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarJackfruit); + + name = "Kumquat"; + mutt_buffer_reset(err); + + printf("Initial: %s = %d\n", name, VarKumquat); + dont_fail = true; + rc = cs_str_string_set(cs, name, "99", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = %d\n", name, VarKumquat); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (VarKumquat != 99) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarKumquat); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Lemon"; + VarLemon = 123; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "456", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarLemon); + + VarLemon = 456; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 123, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarLemon); + + name = "Mango"; + VarMango = 123; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "456", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarMango); + + VarMango = 456; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 123, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarMango); + + name = "Nectarine"; + VarNectarine = 123; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "456", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarNectarine); + + VarNectarine = 456; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 123, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarNectarine); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %ld\n", parent, pval); + printf("%15s = %ld\n", child, cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Olive"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + VarOlive = 123; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "456", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "-99", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool number_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + number_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/number.h b/test/config/number.h new file mode 100644 index 000000000..6f8b2d69c --- /dev/null +++ b/test/config/number.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Number object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_NUMBER_H +#define _TEST_NUMBER_H + +#include + +bool number_test(void); + +#endif /* _TEST_NUMBER_H */ diff --git a/test/config/number.txt b/test/config/number.txt new file mode 100644 index 000000000..f396471cf --- /dev/null +++ b/test/config/number.txt @@ -0,0 +1,94 @@ +---- number_test ------------------------------------------- +---- set_list ---------------------------------------------- +number Apple = -42 +number Banana = 99 +number Cherry = 33 +number Damson = 0 +number Elderberry = 0 +number Fig = 0 +number Guava = 0 +number Hawthorn = 0 +number Ilama = 0 +number Jackfruit = 99 +number Kumquat = 33 +number Lemon = 0 +number Mango = 0 +number Nectarine = 0 +number Olive = 0 +---- test_initial_values ----------------------------------- +Apple = -42 +Banana = 99 +Event: Apple has been set to '2001' +Event: Banana has been set to '1999' +Apple = 2001 +Apple's initial value is '-42' +Banana = 1999 +Banana's initial value is '99' +Event: Cherry has been initial-set to '123' +Cherry = 33 +Cherry's initial value is 123 +---- test_string_set --------------------------------------- +Event: Damson has been set to '-123' +Damson = -123, set by '-123' +Event: Damson has been set to '0' +Damson = 0, set by '0' +Value of Damson wasn't changed +Event: Damson has been set to '456' +Damson = 456, set by '456' + +Expected error: Number is too big: -32769 +Expected error: Number is too big: 32768 +Expected error: Invalid number: junk +Expected error: Option Damson may not be empty +Expected error: Option Damson may not be empty +Expected error: Option Elderberry may not be negative +---- test_string_get --------------------------------------- +Fig = 123, 123 +Fig = -789, -789 +---- test_native_set --------------------------------------- +Event: Guava has been set to '12345' +Guava = 12345, set to '12345' +Value of Guava wasn't changed +Expected error: Option Hawthorn may not be negative +Expected error: Invalid number: -32769 +Expected error: Invalid number: 32768 +---- test_native_get --------------------------------------- +Ilama = 3456 +---- test_reset -------------------------------------------- +Event: Jackfruit has been reset to '99' +Reset: Jackfruit = 99 +Initial: Kumquat = 33 +Event: Kumquat has been set to '99' +Set: Kumquat = 99 +Expected error: validator_fail: Kumquat, 33 +Reset: Kumquat = 99 +---- test_validator ---------------------------------------- +Event: Lemon has been set to '456' +validator_succeed: Lemon, 456 +String: Lemon = 456 +Event: Lemon has been set to '123' +validator_succeed: Lemon, 123 +Native: Lemon = 123 +Event: Mango has been set to '456' +validator_warn: Mango, 456 +String: Mango = 456 +Event: Mango has been set to '123' +validator_warn: Mango, 123 +Native: Mango = 123 +Expected error: validator_fail: Nectarine, 456 +String: Nectarine = 123 +Expected error: validator_fail: Nectarine, 123 +Native: Nectarine = 456 +---- test_inherit ------------------------------------------ +Event: Olive has been set to '456' + Olive = 456 + fruit:Olive = 456 +Event: fruit:Olive has been set to '-99' + Olive = 456 + fruit:Olive = -99 +Event: fruit:Olive has been reset to '456' + Olive = 456 + fruit:Olive = 456 +Event: Olive has been reset to '0' + Olive = 0 + fruit:Olive = 0 diff --git a/test/config/path.c b/test/config/path.c new file mode 100644 index 000000000..29193bb81 --- /dev/null +++ b/test/config/path.c @@ -0,0 +1,653 @@ +/** + * @file + * Test code for the Path object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/path.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static char *VarApple; +static char *VarBanana; +static char *VarCherry; +static char *VarDamson; +static char *VarElderberry; +static char *VarFig; +static char *VarGuava; +static char *VarHawthorn; +static char *VarIlama; +static char *VarJackfruit; +static char *VarKumquat; +static char *VarLemon; +static char *VarMango; +static char *VarNectarine; +static char *VarOlive; +static char *VarPapaya; +static char *VarQuince; +static char *VarRaspberry; +static char *VarStrawberry; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_PATH, 0, &VarApple, IP "/apple", NULL }, /* test_initial_values */ + { "Banana", DT_PATH, 0, &VarBanana, IP "/banana", NULL }, + { "Cherry", DT_PATH, 0, &VarCherry, IP "/cherry", NULL }, + { "Damson", DT_PATH, 0, &VarDamson, 0, NULL }, /* test_string_set */ + { "Elderberry", DT_PATH, 0, &VarElderberry, IP "/elderberry", NULL }, + { "Fig", DT_PATH|DT_NOT_EMPTY, 0, &VarFig, IP "fig", NULL }, + { "Guava", DT_PATH, 0, &VarGuava, 0, NULL }, /* test_string_get */ + { "Hawthorn", DT_PATH, 0, &VarHawthorn, IP "/hawthorn", NULL }, + { "Ilama", DT_PATH, 0, &VarIlama, 0, NULL }, + { "Jackfruit", DT_PATH, 0, &VarJackfruit, 0, NULL }, /* test_native_set */ + { "Kumquat", DT_PATH, 0, &VarKumquat, IP "/kumquat", NULL }, + { "Lemon", DT_PATH|DT_NOT_EMPTY, 0, &VarLemon, IP "lemon", NULL }, + { "Mango", DT_PATH, 0, &VarMango, 0, NULL }, /* test_native_get */ + { "Nectarine", DT_PATH, 0, &VarNectarine, IP "/nectarine", NULL }, /* test_reset */ + { "Olive", DT_PATH, 0, &VarOlive, IP "/olive", validator_fail }, + { "Papaya", DT_PATH, 0, &VarPapaya, IP "/papaya", validator_succeed }, /* test_validator */ + { "Quince", DT_PATH, 0, &VarQuince, IP "/quince", validator_warn }, + { "Raspberry", DT_PATH, 0, &VarRaspberry, IP "/raspberry", validator_fail }, + { "Strawberry", DT_PATH, 0, &VarStrawberry, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %s\n", VarApple); + printf("Banana = %s\n", VarBanana); + + if ((mutt_str_strcmp(VarApple, "/apple") != 0) || + (mutt_str_strcmp(VarBanana, "/banana") != 0)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "/etc", err); + cs_str_string_set(cs, "Banana", NULL, err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "/apple") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = '%s'\n", VarApple); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "/banana") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = '%s'\n", VarBanana); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "/tmp", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "/usr", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello", "world", "world", "", NULL }; + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarDamson, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarDamson), NONULL(valid[i])); + } + + name = "Fig"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + name = "Elderberry"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarElderberry, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarElderberry), NONULL(valid[i])); + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Guava"; + + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarGuava), err->data); + + name = "Hawthorn"; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarHawthorn), err->data); + + name = "Ilama"; + rc = cs_str_string_set(cs, name, "ilama", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarIlama), err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello", "world", "world", "", NULL }; + char *name = "Jackfruit"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarJackfruit, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarJackfruit), NONULL(valid[i])); + } + + name = "Lemon"; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) "", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + name = "Kumquat"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarKumquat, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarKumquat), NONULL(valid[i])); + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Mango"; + + int rc = cs_str_string_set(cs, name, "mango", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (mutt_str_strcmp(VarMango, (char *) value) != 0) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, VarMango, (char *) value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Nectarine"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarNectarine); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarNectarine); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarNectarine, "/nectarine") != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarNectarine); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + name = "Olive"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarOlive); + dont_fail = true; + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarOlive); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarOlive, "hello") != 0) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarOlive); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Papaya"; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Path: %s = %s\n", name, VarPapaya); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarPapaya); + + name = "Quince"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Path: %s = %s\n", name, VarQuince); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarQuince); + + name = "Raspberry"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Path: %s = %s\n", name, VarRaspberry); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarRaspberry); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %s\n", parent, (char *) pval); + printf("%15s = %s\n", child, (char *) cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Strawberry"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "world", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool path_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + path_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/path.h b/test/config/path.h new file mode 100644 index 000000000..2750bab7e --- /dev/null +++ b/test/config/path.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Path object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_PATH_H +#define _TEST_PATH_H + +#include + +bool path_test(void); + +#endif /* _TEST_PATH_H */ diff --git a/test/config/path.txt b/test/config/path.txt new file mode 100644 index 000000000..6c69d94a7 --- /dev/null +++ b/test/config/path.txt @@ -0,0 +1,119 @@ +---- path_test --------------------------------------------- +---- set_list ---------------------------------------------- +path Apple = /apple +path Banana = /banana +path Cherry = /cherry +path Damson = +path Elderberry = /elderberry +path Fig = fig +path Guava = +path Hawthorn = /hawthorn +path Ilama = +path Jackfruit = +path Kumquat = /kumquat +path Lemon = lemon +path Mango = +path Nectarine = /nectarine +path Olive = /olive +path Papaya = /papaya +path Quince = /quince +path Raspberry = /raspberry +path Strawberry = +---- test_initial_values ----------------------------------- +Apple = /apple +Banana = /banana +Event: Apple has been set to '/etc' +Event: Banana has been set to '' +Apple = '/etc' +Apple's initial value is '/apple' +Banana = '(null)' +Banana's initial value is '/banana' +Event: Cherry has been initial-set to '/tmp' +Event: Cherry has been initial-set to '/usr' +Cherry = '/cherry' +Cherry's initial value is '/usr' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'hello' +Damson = 'hello', set by 'hello' +Event: Damson has been set to 'world' +Damson = 'world', set by 'world' +Value of Damson wasn't changed +Event: Damson has been set to '' +Damson = '', set by '' +Value of Damson wasn't changed +Expected error: Option Fig may not be empty +Event: Elderberry has been set to 'hello' +Elderberry = 'hello', set by 'hello' +Event: Elderberry has been set to 'world' +Elderberry = 'world', set by 'world' +Value of Elderberry wasn't changed +Event: Elderberry has been set to '' +Elderberry = '', set by '' +Value of Elderberry wasn't changed +---- test_string_get --------------------------------------- +Guava = '', '' +Hawthorn = '/hawthorn', '/hawthorn' +Event: Ilama has been set to 'ilama' +Ilama = 'ilama', 'ilama' +---- test_native_set --------------------------------------- +Event: Jackfruit has been set to 'hello' +Jackfruit = 'hello', set by 'hello' +Event: Jackfruit has been set to 'world' +Jackfruit = 'world', set by 'world' +Value of Jackfruit wasn't changed +Event: Jackfruit has been set to '' +Jackfruit = '', set by '' +Value of Jackfruit wasn't changed +Expected error: Option Lemon may not be empty +Event: Kumquat has been set to 'hello' +Kumquat = 'hello', set by 'hello' +Event: Kumquat has been set to 'world' +Kumquat = 'world', set by 'world' +Value of Kumquat wasn't changed +Event: Kumquat has been set to '' +Kumquat = '', set by '' +Value of Kumquat wasn't changed +---- test_native_get --------------------------------------- +Event: Mango has been set to 'mango' +Mango = 'mango', 'mango' +---- test_reset -------------------------------------------- +Initial: Nectarine = '/nectarine' +Event: Nectarine has been set to 'hello' +Set: Nectarine = 'hello' +Event: Nectarine has been reset to '/nectarine' +Reset: Nectarine = '/nectarine' +Initial: Olive = '/olive' +Event: Olive has been set to 'hello' +Set: Olive = 'hello' +Expected error: validator_fail: Olive, (ptr) +Reset: Olive = 'hello' +---- test_validator ---------------------------------------- +Event: Papaya has been set to 'hello' +validator_succeed: Papaya, (ptr) +Path: Papaya = hello +Event: Papaya has been set to 'world' +validator_succeed: Papaya, (ptr) +Native: Papaya = world +Event: Quince has been set to 'hello' +validator_warn: Quince, (ptr) +Path: Quince = hello +Event: Quince has been set to 'world' +validator_warn: Quince, (ptr) +Native: Quince = world +Expected error: validator_fail: Raspberry, (ptr) +Path: Raspberry = /raspberry +Expected error: validator_fail: Raspberry, (ptr) +Native: Raspberry = /raspberry +---- test_inherit ------------------------------------------ +Event: Strawberry has been set to 'hello' + Strawberry = hello +fruit:Strawberry = hello +Event: fruit:Strawberry has been set to 'world' + Strawberry = hello +fruit:Strawberry = world +Event: fruit:Strawberry has been reset to 'hello' + Strawberry = hello +fruit:Strawberry = hello +Event: Strawberry has been reset to '' + Strawberry = (null) +fruit:Strawberry = (null) diff --git a/test/config/quad.c b/test/config/quad.c new file mode 100644 index 000000000..732b00a02 --- /dev/null +++ b/test/config/quad.c @@ -0,0 +1,686 @@ +/** + * @file + * Test code for the Quad object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/bool.h" +#include "config/quad.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static char VarApple; +static char VarBanana; +static char VarCherry; +static char VarDamson; +static char VarElderberry; +static char VarFig; +static char VarGuava; +static char VarHawthorn; +static char VarIlama; +static char VarJackfruit; +static char VarKumquat; +static char VarLemon; +static char VarMango; +static char VarNectarine; +static char VarOlive; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_QUAD, 0, &VarApple, 0, NULL }, /* test_initial_values */ + { "Banana", DT_QUAD, 0, &VarBanana, 3, NULL }, + { "Cherry", DT_QUAD, 0, &VarCherry, 0, NULL }, + { "Damson", DT_QUAD, 0, &VarDamson, 0, NULL }, /* test_string_set */ + { "Elderberry", DT_QUAD, 0, &VarElderberry, 0, NULL }, /* test_string_get */ + { "Fig", DT_QUAD, 0, &VarFig, 0, NULL }, /* test_native_set */ + { "Guava", DT_QUAD, 0, &VarGuava, 0, NULL }, /* test_native_get */ + { "Hawthorn", DT_QUAD, 0, &VarHawthorn, 0, NULL }, /* test_reset */ + { "Ilama", DT_QUAD, 0, &VarIlama, 0, validator_fail }, + { "Jackfruit", DT_QUAD, 0, &VarJackfruit, 0, validator_succeed }, /* test_validator */ + { "Kumquat", DT_QUAD, 0, &VarKumquat, 0, validator_warn }, + { "Lemon", DT_QUAD, 0, &VarLemon, 0, validator_fail }, + { "Mango", DT_QUAD, 0, &VarMango, 0, NULL }, /* test_inherit */ + { "Nectarine", DT_QUAD, 0, &VarNectarine, 0, NULL }, /* test_toggle */ + { "Olive", DT_BOOL, 0, &VarOlive, 0, NULL }, + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %d\n", VarApple); + printf("Banana = %d\n", VarBanana); + + if ((VarApple != 0) || (VarBanana != 3)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "ask-yes", err); + cs_str_string_set(cs, "Banana", "ask-no", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "no") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = %d\n", VarApple); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "ask-yes") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = %d\n", VarBanana); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "ask-yes", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry ? "yes" : "no"); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "no", "yes", "ask-no", "ask-yes" }; + const char *invalid[] = { + "nope", "ye", "", NULL, + }; + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + VarDamson = ((i + 1) % 4); + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarDamson == ((i + 1) % 4)) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = %d, set by '%s'\n", name, VarDamson, valid[i]); + + if (i == 2) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + } + } + + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%s'\n", name, VarDamson, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Elderberry"; + + int valid[] = { MUTT_NO, MUTT_YES, MUTT_ASKNO, MUTT_ASKYES }; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + VarElderberry = i; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarElderberry, err->data); + } + + VarElderberry = 4; + mutt_buffer_reset(err); + printf("Expect error for next test\n"); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Fig"; + char value = MUTT_YES; + + VarFig = MUTT_NO; + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarFig != value) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("%s = %d, set to '%d'\n", name, VarFig, value); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + } + + int invalid[] = { -1, 4 }; + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + VarFig = MUTT_NO; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%d'\n", name, VarFig, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Guava"; + + VarGuava = MUTT_YES; + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %ld\n", name, value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Hawthorn"; + VarHawthorn = MUTT_YES; + mutt_buffer_reset(err); + + int rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarHawthorn == MUTT_YES) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarHawthorn); + + name = "Ilama"; + mutt_buffer_reset(err); + + printf("Initial: %s = %d\n", name, VarIlama); + dont_fail = true; + rc = cs_str_string_set(cs, name, "ask-yes", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = %d\n", name, VarIlama); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (VarIlama != MUTT_ASKYES) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarIlama); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Jackfruit"; + VarJackfruit = MUTT_NO; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "yes", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarJackfruit); + + VarJackfruit = MUTT_NO; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 1, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarJackfruit); + + name = "Kumquat"; + VarKumquat = MUTT_NO; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "yes", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarKumquat); + + VarKumquat = MUTT_NO; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 1, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarKumquat); + + name = "Lemon"; + VarLemon = MUTT_NO; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "yes", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarLemon); + + VarLemon = MUTT_NO; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 1, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarLemon); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %ld\n", parent, pval); + printf("%15s = %ld\n", child, cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Mango"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "yes", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "no", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", parent); + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +static bool test_toggle(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + struct ToggleTest + { + char before; + char after; + }; + + struct ToggleTest tests[] = { + { MUTT_NO, MUTT_YES }, { MUTT_YES, MUTT_NO }, { MUTT_ASKNO, MUTT_ASKYES }, { MUTT_ASKYES, MUTT_ASKNO }, + }; + + char *name = "Nectarine"; + int rc; + + struct HashElem *he = cs_get_elem(cs, name); + if (!he) + return false; + + for (size_t i = 0; i < mutt_array_size(tests); i++) + { + char before = tests[i].before; + char after = tests[i].after; + printf("test %zd\n", i); + + VarNectarine = before; + mutt_buffer_reset(err); + intptr_t value = cs_he_native_get(cs, he, err); + if (value == INT_MIN) + { + printf("Get failed: %s\n", err->data); + return false; + } + + char copy = value; + if (copy != before) + { + printf("Initial value is wrong: %s\n", err->data); + return false; + } + + rc = quad_he_toggle(cs, he, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Toggle failed: %s\n", err->data); + return false; + } + + if (VarNectarine != after) + { + printf("Toggle value is wrong: %s\n", err->data); + return false; + } + } + + VarNectarine = 8; + mutt_buffer_reset(err); + rc = quad_he_toggle(cs, he, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + + name = "Olive"; + he = cs_get_elem(cs, name); + if (!he) + return false; + + mutt_buffer_reset(err); + rc = quad_he_toggle(cs, he, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + + return true; +} + +bool quad_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + quad_init(cs); + bool_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + if (!test_toggle(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/quad.h b/test/config/quad.h new file mode 100644 index 000000000..59d15bb1a --- /dev/null +++ b/test/config/quad.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Quad object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_QUAD_H +#define _TEST_QUAD_H + +#include + +bool quad_test(void); + +#endif /* _TEST_QUAD_H */ diff --git a/test/config/quad.txt b/test/config/quad.txt new file mode 100644 index 000000000..a7e87c5c7 --- /dev/null +++ b/test/config/quad.txt @@ -0,0 +1,107 @@ +---- quad_test --------------------------------------------- +---- set_list ---------------------------------------------- +boolean Olive = no +quad Apple = no +quad Banana = ask-yes +quad Cherry = no +quad Damson = no +quad Elderberry = no +quad Fig = no +quad Guava = no +quad Hawthorn = no +quad Ilama = no +quad Jackfruit = no +quad Kumquat = no +quad Lemon = no +quad Mango = no +quad Nectarine = no +---- test_initial_values ----------------------------------- +Apple = 0 +Banana = 3 +Event: Apple has been set to 'ask-yes' +Event: Banana has been set to 'ask-no' +Apple = 3 +Apple's initial value is 'no' +Banana = 2 +Banana's initial value is 'ask-yes' +Event: Cherry has been initial-set to 'ask-yes' +Cherry = 'no' +Cherry's initial value is 'ask-yes' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'no' +Damson = 0, set by 'no' +Event: Damson has been set to 'yes' +Damson = 1, set by 'yes' +Event: Damson has been set to 'ask-no' +Damson = 2, set by 'ask-no' +Value of Damson wasn't changed +Event: Damson has been set to 'ask-yes' +Damson = 3, set by 'ask-yes' +Expected error: Invalid quad value: nope +Expected error: Invalid quad value: ye +Expected error: Invalid quad value: +Expected error: +---- test_string_get --------------------------------------- +Elderberry = 0, no +Elderberry = 1, yes +Elderberry = 2, ask-no +Elderberry = 3, ask-yes +Expect error for next test +Variable has an invalid value: 4 +---- test_native_set --------------------------------------- +Event: Fig has been set to 'yes' +Fig = 1, set to '1' +Value of Fig wasn't changed +Expected error: Invalid quad value: -1 +Expected error: Invalid quad value: 4 +---- test_native_get --------------------------------------- +Guava = 1 +---- test_reset -------------------------------------------- +Event: Hawthorn has been reset to 'no' +Reset: Hawthorn = 0 +Initial: Ilama = 0 +Event: Ilama has been set to 'ask-yes' +Set: Ilama = 3 +Expected error: validator_fail: Ilama, 0 +Reset: Ilama = 3 +---- test_validator ---------------------------------------- +Event: Jackfruit has been set to 'yes' +validator_succeed: Jackfruit, 1 +String: Jackfruit = 1 +Event: Jackfruit has been set to 'yes' +validator_succeed: Jackfruit, 1 +Native: Jackfruit = 1 +Event: Kumquat has been set to 'yes' +validator_warn: Kumquat, 1 +String: Kumquat = 1 +Event: Kumquat has been set to 'yes' +validator_warn: Kumquat, 1 +Native: Kumquat = 1 +Expected error: validator_fail: Lemon, 1 +String: Lemon = 0 +Expected error: validator_fail: Lemon, 1 +Native: Lemon = 0 +---- test_inherit ------------------------------------------ +Event: Mango has been set to 'yes' + Mango = 1 + fruit:Mango = 1 +Value of Mango wasn't changed + Mango = 1 + fruit:Mango = 0 +Event: fruit:Mango has been reset to 'yes' + Mango = 1 + fruit:Mango = 1 +Event: Mango has been reset to 'no' + Mango = 0 + fruit:Mango = 0 +---- test_toggle ------------------------------------------- +test 0 +Event: Nectarine has been set to 'yes' +test 1 +Event: Nectarine has been set to 'no' +test 2 +Event: Nectarine has been set to 'ask-yes' +test 3 +Event: Nectarine has been set to 'ask-no' +Expected error: Invalid quad value: 8 +Expected error: diff --git a/test/config/regex.c b/test/config/regex.c new file mode 100644 index 000000000..9727c9057 --- /dev/null +++ b/test/config/regex.c @@ -0,0 +1,698 @@ +/** + * @file + * Test code for the Regex object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/regex3.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/regex2.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static struct Regex *VarApple; +static struct Regex *VarBanana; +static struct Regex *VarCherry; +static struct Regex *VarDamson; +static struct Regex *VarElderberry; +static struct Regex *VarFig; +static struct Regex *VarGuava; +static struct Regex *VarHawthorn; +static struct Regex *VarIlama; +static struct Regex *VarJackfruit; +static struct Regex *VarKumquat; +static struct Regex *VarLemon; +static struct Regex *VarMango; +static struct Regex *VarNectarine; +static struct Regex *VarOlive; +static struct Regex *VarPapaya; +static struct Regex *VarQuince; +static struct Regex *VarRaspberry; +static struct Regex *VarStrawberry; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_REGEX, 0, &VarApple, IP "apple.*", NULL }, /* test_initial_values */ + { "Banana", DT_REGEX, 0, &VarBanana, IP "banana.*", NULL }, + { "Cherry", DT_REGEX, 0, &VarCherry, IP "cherry.*", NULL }, + { "Damson", DT_REGEX, 0, &VarDamson, 0, NULL }, /* test_regex_set */ + { "Elderberry", DT_REGEX, DT_REGEX_NOSUB, &VarElderberry, IP "elderberry.*", NULL }, + { "Fig", DT_REGEX, 0, &VarFig, 0, NULL }, /* test_regex_get */ + { "Guava", DT_REGEX, 0, &VarGuava, IP "guava.*", NULL }, + { "Hawthorn", DT_REGEX, 0, &VarHawthorn, 0, NULL }, + { "Ilama", DT_REGEX, DT_REGEX_ALLOW_NOT, &VarIlama, 0, NULL }, /* test_native_set */ + { "Jackfruit", DT_REGEX, 0, &VarJackfruit, IP "jackfruit.*", NULL }, + { "Kumquat", DT_REGEX, 0, &VarKumquat, IP "kumquat.*", NULL }, + { "Lemon", DT_REGEX, 0, &VarLemon, 0, NULL }, /* test_native_get */ + { "Mango", DT_REGEX, 0, &VarMango, IP "mango.*", NULL }, /* test_reset */ + { "Nectarine", DT_REGEX, 0, &VarNectarine, IP "\\1", NULL }, + { "Olive", DT_REGEX, 0, &VarOlive, IP "olive.*", validator_fail }, + { "Papaya", DT_REGEX, 0, &VarPapaya, IP "papaya.*", validator_succeed }, /* test_validator */ + { "Quince", DT_REGEX, 0, &VarQuince, IP "quince.*", validator_warn }, + { "Raspberry", DT_REGEX, 0, &VarRaspberry, IP "raspberry.*", validator_fail }, + { "Strawberry", DT_REGEX, 0, &VarStrawberry, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %s\n", VarApple->pattern); + printf("Banana = %s\n", VarBanana->pattern); + + if ((mutt_str_strcmp(VarApple->pattern, "apple.*") != 0) || + (mutt_str_strcmp(VarBanana->pattern, "banana.*") != 0)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "car*", err); + cs_str_string_set(cs, "Banana", "train*", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "apple.*") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = '%s'\n", VarApple ? VarApple->pattern : ""); + printf("Apple's initial value is %s\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "banana.*") != 0) + { + printf("Banana's initial value is wrong: %s\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = '%s'\n", VarBanana ? VarBanana->pattern : ""); + printf("Banana's initial value is %s\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "up.*", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "down.*", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry->pattern); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello.*", "world.*", "world.*", "", NULL }; + char *name = "Damson"; + char *regex = NULL; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + regex = VarDamson ? VarDamson->pattern : NULL; + if (mutt_str_strcmp(regex, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(regex), NONULL(valid[i])); + } + + name = "Elderberry"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + regex = VarElderberry ? VarElderberry->pattern : NULL; + if (mutt_str_strcmp(regex, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(regex), NONULL(valid[i])); + } + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "\\1", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Fig"; + char *regex = NULL; + + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + regex = VarFig ? VarFig->pattern : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(regex), err->data); + + name = "Guava"; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + regex = VarGuava ? VarGuava->pattern : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(regex), err->data); + + name = "Hawthorn"; + rc = cs_str_string_set(cs, name, "hawthorn", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + regex = VarHawthorn ? VarHawthorn->pattern : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(regex), err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + struct Regex *r = regex_create("hello.*", 0, err); + char *name = "Ilama"; + char *regex = NULL; + bool result = false; + + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, (intptr_t) r, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + goto tns_out; + } + + regex = VarIlama ? VarIlama->pattern : NULL; + if (mutt_str_strcmp(regex, r->pattern) != 0) + { + printf("Value of %s wasn't changed\n", name); + goto tns_out; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(regex), r->pattern); + + regex_free(&r); + r = regex_create("!world.*", DT_REGEX_ALLOW_NOT, err); + name = "Ilama"; + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) r, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + goto tns_out; + } + printf("'%s', not flag set to %d\n", VarIlama->pattern, VarIlama->not); + + name = "Jackfruit"; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, 0, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + goto tns_out; + } + + if (VarJackfruit != NULL) + { + printf("Value of %s wasn't changed\n", name); + goto tns_out; + } + regex = VarJackfruit ? VarJackfruit->pattern : NULL; + printf("%s = '%s', set by NULL\n", name, NONULL(regex)); + + regex_free(&r); + r = regex_create("world.*", 0, err); + r->pattern[0] = '\\'; + r->pattern[1] = '1'; + name = "Kumquat"; + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) r, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tns_out; + } + + result = true; +tns_out: + regex_free(&r); + return result; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Lemon"; + + int rc = cs_str_string_set(cs, name, "lemon.*", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + struct Regex *r = (struct Regex *) value; + + if (VarLemon != r) + { + printf("Get failed: %s\n", err->data); + return false; + } + char *regex1 = VarLemon ? VarLemon->pattern : NULL; + char *regex2 = r ? r->pattern : NULL; + printf("%s = '%s', '%s'\n", name, NONULL(regex1), NONULL(regex2)); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Mango"; + char *regex = NULL; + + mutt_buffer_reset(err); + + regex = VarMango ? VarMango->pattern : NULL; + printf("Initial: %s = '%s'\n", name, NONULL(regex)); + int rc = cs_str_string_set(cs, name, "hello.*", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + regex = VarMango ? VarMango->pattern : NULL; + printf("Set: %s = '%s'\n", name, NONULL(regex)); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + regex = VarMango ? VarMango->pattern : NULL; + if (mutt_str_strcmp(regex, "mango.*") != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, NONULL(regex)); + + rc = cs_str_reset(cs, "Nectarine", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + name = "Olive"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarOlive->pattern); + dont_fail = true; + rc = cs_str_string_set(cs, name, "hel*o", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarOlive->pattern); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarOlive->pattern, "hel*o") != 0) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarOlive->pattern); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *regex = NULL; + struct Regex *r = regex_create("world.*", 0, err); + bool result = false; + + char *name = "Papaya"; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "hello.*", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + regex = VarPapaya ? VarPapaya->pattern : NULL; + printf("Regex: %s = %s\n", name, NONULL(regex)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP r, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + regex = VarPapaya ? VarPapaya->pattern : NULL; + printf("Native: %s = %s\n", name, NONULL(regex)); + + name = "Quince"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello.*", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + regex = VarQuince ? VarQuince->pattern : NULL; + printf("Regex: %s = %s\n", name, NONULL(regex)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP r, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + regex = VarQuince ? VarQuince->pattern : NULL; + printf("Native: %s = %s\n", name, NONULL(regex)); + + name = "Raspberry"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello.*", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + regex = VarRaspberry ? VarRaspberry->pattern : NULL; + printf("Regex: %s = %s\n", name, NONULL(regex)); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP r, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + goto tv_out; + } + regex = VarRaspberry ? VarRaspberry->pattern : NULL; + printf("Native: %s = %s\n", name, NONULL(regex)); + + result = true; +tv_out: + regex_free(&r); + return result; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + struct Regex *pa = (struct Regex *) pval; + struct Regex *ca = (struct Regex *) cval; + + char *pstr = pa ? pa->pattern : NULL; + char *cstr = ca ? ca->pattern : NULL; + + printf("%15s = %s\n", parent, NONULL(pstr)); + printf("%15s = %s\n", child, NONULL(cstr)); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Strawberry"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarRegex[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarRegex); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "hello.*", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "world.*", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool regex_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + regex_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/regex.txt b/test/config/regex.txt new file mode 100644 index 000000000..65e38b28c --- /dev/null +++ b/test/config/regex.txt @@ -0,0 +1,112 @@ +---- regex_test -------------------------------------------- +---- set_list ---------------------------------------------- +regex Apple = apple.* +regex Banana = banana.* +regex Cherry = cherry.* +regex Damson = +regex Elderberry = elderberry.* +regex Fig = +regex Guava = guava.* +regex Hawthorn = +regex Ilama = +regex Jackfruit = jackfruit.* +regex Kumquat = kumquat.* +regex Lemon = +regex Mango = mango.* +regex Nectarine = +regex Olive = olive.* +regex Papaya = papaya.* +regex Quince = quince.* +regex Raspberry = raspberry.* +regex Strawberry = +---- test_initial_values ----------------------------------- +Apple = apple.* +Banana = banana.* +Event: Apple has been set to 'car*' +Event: Banana has been set to 'train*' +Apple = 'car*' +Apple's initial value is apple.* +Banana = 'train*' +Banana's initial value is banana.* +Event: Cherry has been initial-set to 'up.*' +Event: Cherry has been initial-set to 'down.*' +Cherry = 'cherry.*' +Cherry's initial value is 'down.*' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'hello.*' +Damson = 'hello.*', set by 'hello.*' +Event: Damson has been set to 'world.*' +Damson = 'world.*', set by 'world.*' +Value of Damson wasn't changed +Event: Damson has been set to '' +Damson = '', set by '' +Event: Damson has been set to '' +Damson = '', set by '' +Event: Elderberry has been set to 'hello.*' +Elderberry = 'hello.*', set by 'hello.*' +Event: Elderberry has been set to 'world.*' +Elderberry = 'world.*', set by 'world.*' +Value of Elderberry wasn't changed +Event: Elderberry has been set to '' +Elderberry = '', set by '' +Event: Elderberry has been set to '' +Elderberry = '', set by '' +Expected error: Invalid back reference +---- test_string_get --------------------------------------- +Fig = '', '' +Guava = 'guava.*', 'guava.*' +Event: Hawthorn has been set to 'hawthorn' +Hawthorn = 'hawthorn', 'hawthorn' +---- test_native_set --------------------------------------- +Event: Ilama has been set to 'hello.*' +Ilama = 'hello.*', set by 'hello.*' +Event: Ilama has been set to '!world.*' +'!world.*', not flag set to 1 +Event: Jackfruit has been set to '' +Jackfruit = '', set by NULL +Expected error: Invalid back reference +---- test_native_get --------------------------------------- +Event: Lemon has been set to 'lemon.*' +Lemon = 'lemon.*', 'lemon.*' +---- test_reset -------------------------------------------- +Initial: Mango = 'mango.*' +Event: Mango has been set to 'hello.*' +Set: Mango = 'hello.*' +Event: Mango has been reset to 'mango.*' +Reset: Mango = 'mango.*' +Expected error: Invalid back reference +Initial: Olive = 'olive.*' +Event: Olive has been set to 'hel*o' +Set: Olive = 'hel*o' +Expected error: validator_fail: Olive, (ptr) +Reset: Olive = 'hel*o' +---- test_validator ---------------------------------------- +Event: Papaya has been set to 'hello.*' +validator_succeed: Papaya, (ptr) +Regex: Papaya = hello.* +Event: Papaya has been set to 'world.*' +validator_succeed: Papaya, (ptr) +Native: Papaya = world.* +Event: Quince has been set to 'hello.*' +validator_warn: Quince, (ptr) +Regex: Quince = hello.* +Event: Quince has been set to 'world.*' +validator_warn: Quince, (ptr) +Native: Quince = world.* +Expected error: validator_fail: Raspberry, (ptr) +Regex: Raspberry = raspberry.* +Expected error: validator_fail: Raspberry, (ptr) +Native: Raspberry = raspberry.* +---- test_inherit ------------------------------------------ +Event: Strawberry has been set to 'hello.*' + Strawberry = hello.* +fruit:Strawberry = hello.* +Event: fruit:Strawberry has been set to 'world.*' + Strawberry = hello.* +fruit:Strawberry = world.* +Event: fruit:Strawberry has been reset to 'hello.*' + Strawberry = hello.* +fruit:Strawberry = hello.* +Event: Strawberry has been reset to '' + Strawberry = +fruit:Strawberry = diff --git a/test/config/regex3.h b/test/config/regex3.h new file mode 100644 index 000000000..e1fd29650 --- /dev/null +++ b/test/config/regex3.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Regex object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_REGEX_H +#define _TEST_REGEX_H + +#include + +bool regex_test(void); + +#endif /* _TEST_REGEX_H */ diff --git a/test/config/set.c b/test/config/set.c new file mode 100644 index 000000000..98f5671ff --- /dev/null +++ b/test/config/set.c @@ -0,0 +1,201 @@ +/** + * @file + * Test code for the ConfigSet object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/bool.h" +#include "config/set.h" +#include "config/types.h" +#include "config/common.h" + +static short VarApple; +static bool VarBanana; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_NUMBER, 0, &VarApple, 0, NULL }, + { "Banana", DT_BOOL, 0, &VarBanana, 1, NULL }, + { NULL }, +}; +// clang-format on + +static int dummy_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, + const char *value, struct Buffer *err) +{ + return CSR_ERR_CODE; +} + +static int dummy_string_get(const struct ConfigSet *cs, void *var, + const struct ConfigDef *cdef, struct Buffer *result) +{ + return CSR_ERR_CODE; +} + +static int dummy_native_set(const struct ConfigSet *cs, void *var, + const struct ConfigDef *cdef, intptr_t value, struct Buffer *err) +{ + return CSR_ERR_CODE; +} + +static intptr_t dummy_native_get(const struct ConfigSet *cs, void *var, + const struct ConfigDef *cdef, struct Buffer *err) +{ + return INT_MIN; +} + +static int dummy_reset(const struct ConfigSet *cs, void *var, + const struct ConfigDef *cdef, struct Buffer *err) +{ + return CSR_ERR_CODE; +} + +void dummy_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef) +{ +} + +bool set_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + if (!cs) + return false; + + cs_add_listener(cs, log_listener); + cs_add_listener(cs, log_listener); /* dupe */ + cs_remove_listener(cs, log_listener); + cs_remove_listener(cs, log_listener); /* non-existant */ + + const struct ConfigSetType cst_dummy = { + "dummy", NULL, NULL, NULL, NULL, NULL, NULL, + }; + + if (!cs_register_type(cs, DT_STRING, &cst_dummy)) + { + printf("Expected error\n"); + } + else + { + printf("This test should have failed\n"); + return false; + } + + const struct ConfigSetType cst_dummy2 = { + "dummy2", dummy_string_set, dummy_string_get, dummy_native_set, + dummy_native_get, dummy_reset, dummy_destroy, + }; + + if (!cs_register_type(cs, 25, &cst_dummy2)) + { + printf("Expected error\n"); + } + else + { + printf("This test should have failed\n"); + return false; + } + + bool_init(cs); + bool_init(cs); /* second one should fail */ + + if (!cs_register_variables(cs, Vars, 0)) + { + printf("Expected error\n"); + } + else + { + printf("This test should have failed\n"); + return false; + } + + const char *name = "Unknown"; + int result = cs_str_string_set(cs, name, "hello", &err); + if (CSR_RESULT(result) == CSR_ERR_UNKNOWN) + { + printf("Expected error: Unknown var '%s'\n", name); + } + else + { + printf("This should have failed 1\n"); + return false; + } + + result = cs_str_string_get(cs, name, &err); + if (CSR_RESULT(result) == CSR_ERR_UNKNOWN) + { + printf("Expected error: Unknown var '%s'\n", name); + } + else + { + printf("This should have failed 2\n"); + return false; + } + + result = cs_str_native_set(cs, name, IP "hello", &err); + if (CSR_RESULT(result) == CSR_ERR_UNKNOWN) + { + printf("Expected error: Unknown var '%s'\n", name); + } + else + { + printf("This should have failed 3\n"); + return false; + } + + intptr_t native = cs_str_native_get(cs, name, &err); + if (native == INT_MIN) + { + printf("Expected error: Unknown var '%s'\n", name); + } + else + { + printf("This should have failed 4\n"); + return false; + } + + struct HashElem *he = cs_get_elem(cs, "Banana"); + if (!he) + return false; + + set_list(cs); + + const struct ConfigSetType *cst = cs_get_type_def(cs, 15); + if (cst) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/set.h b/test/config/set.h new file mode 100644 index 000000000..b56eef0ae --- /dev/null +++ b/test/config/set.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the ConfigSet object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_SET_H +#define _TEST_SET_H + +#include + +bool set_test(void); + +#endif /* _TEST_CONFIGSET_H */ diff --git a/test/config/set.txt b/test/config/set.txt new file mode 100644 index 000000000..96ecd30d2 --- /dev/null +++ b/test/config/set.txt @@ -0,0 +1,13 @@ +---- set_test ---------------------------------------------- +Listener was already registered +Listener wasn't registered +Expected error +Expected error +Variable 'Apple' has an invalid type 8 +Expected error +Expected error: Unknown var 'Unknown' +Expected error: Unknown var 'Unknown' +Expected error: Unknown var 'Unknown' +Expected error: Unknown var 'Unknown' +---- set_list ---------------------------------------------- +boolean Banana = yes diff --git a/test/config/slist.c b/test/config/slist.c new file mode 100644 index 000000000..2c554d38b --- /dev/null +++ b/test/config/slist.c @@ -0,0 +1,547 @@ +/** + * @file + * Test code for the Slist object + * + * @authors + * Copyright (C) 2018 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/mapping.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/bool.h" +#include "config/set.h" +#include "config/slist.h" +#include "config/types.h" +#include "config/common.h" + +static struct Slist *VarApple; +static struct Slist *VarBanana; +static struct Slist *VarCherry; +static struct Slist *VarDamson; +static struct Slist *VarElderberry; +static struct Slist *VarFig; +static struct Slist *VarGuava; +static struct Slist *VarHawthorn; +#if 0 +static struct Slist *VarIlama; +static struct Slist *VarJackfruit; +static struct Slist *VarKumquat; +static struct Slist *VarLemon; +static struct Slist *VarMango; +static struct Slist *VarNectarine; +static struct Slist *VarOlive; +static struct Slist *VarPapaya; +static struct Slist *VarQuince; +static struct Slist *VarRaspberry; +static struct Slist *VarStrawberry; +#endif + +// clang-format off +static struct ConfigDef VarsColon[] = { + { "Apple", DT_SLIST, SLIST_SEP_COLON, &VarApple, IP "apple", NULL }, /* test_initial_values */ + { "Banana", DT_SLIST, SLIST_SEP_COLON, &VarBanana, IP "apple:banana", NULL }, + { "Cherry", DT_SLIST, SLIST_SEP_COLON, &VarCherry, IP "apple:banana:cherry", NULL }, + { "Damson", DT_SLIST, SLIST_SEP_COLON, &VarDamson, IP "apple:banana", NULL }, /* test_string_set */ + { "Elderberry", DT_SLIST, SLIST_SEP_COLON, &VarElderberry, 0, NULL }, + { "Fig", DT_SLIST, SLIST_SEP_COLON, &VarFig, IP ":apple", NULL }, /* test_string_get */ + { "Guava", DT_SLIST, SLIST_SEP_COLON, &VarGuava, IP "apple::cherry", NULL }, + { "Hawthorn", DT_SLIST, SLIST_SEP_COLON, &VarHawthorn, IP "apple:", NULL }, + { NULL }, +}; + +static struct ConfigDef VarsComma[] = { + { "Apple", DT_SLIST, SLIST_SEP_COMMA, &VarApple, IP "apple", NULL }, /* test_initial_values */ + { "Banana", DT_SLIST, SLIST_SEP_COMMA, &VarBanana, IP "apple,banana", NULL }, + { "Cherry", DT_SLIST, SLIST_SEP_COMMA, &VarCherry, IP "apple,banana,cherry", NULL }, + { "Damson", DT_SLIST, SLIST_SEP_COLON, &VarDamson, IP "apple,banana", NULL }, /* test_string_set */ + { "Elderberry", DT_SLIST, SLIST_SEP_COLON, &VarElderberry, 0, NULL }, + { "Fig", DT_SLIST, SLIST_SEP_COLON, &VarFig, IP ",apple", NULL }, /* test_string_get */ + { "Guava", DT_SLIST, SLIST_SEP_COLON, &VarGuava, IP "apple,,cherry", NULL }, + { "Hawthorn", DT_SLIST, SLIST_SEP_COLON, &VarHawthorn, IP "apple,", NULL }, + { NULL }, +}; + +static struct ConfigDef VarsSpace[] = { + { "Apple", DT_SLIST, SLIST_SEP_SPACE, &VarApple, IP "apple", NULL }, /* test_initial_values */ + { "Banana", DT_SLIST, SLIST_SEP_SPACE, &VarBanana, IP "apple banana", NULL }, + { "Cherry", DT_SLIST, SLIST_SEP_SPACE, &VarCherry, IP "apple banana cherry", NULL }, + { "Damson", DT_SLIST, SLIST_SEP_COLON, &VarDamson, IP "apple banana", NULL }, /* test_string_set */ + { "Elderberry", DT_SLIST, SLIST_SEP_COLON, &VarElderberry, 0, NULL }, + { "Fig", DT_SLIST, SLIST_SEP_COLON, &VarFig, IP " apple", NULL }, /* test_string_get */ + { "Guava", DT_SLIST, SLIST_SEP_COLON, &VarGuava, IP "apple cherry", NULL }, + { "Hawthorn", DT_SLIST, SLIST_SEP_COLON, &VarHawthorn, IP "apple ", NULL }, + { NULL }, +}; +// clang-format on + +static void slist_flags(unsigned int flags) +{ + switch (flags & SLIST_SEP_MASK) + { + case SLIST_SEP_SPACE: + printf("SPACE"); + break; + case SLIST_SEP_COMMA: + printf("COMMA"); + break; + case SLIST_SEP_COLON: + printf("COLON"); + break; + default: + printf("UNKNOWN"); + return; + } + + if (flags & SLIST_ALLOW_DUPES) + printf(" | SLIST_ALLOW_DUPES"); + if (flags & SLIST_ALLOW_EMPTY) + printf(" | SLIST_ALLOW_EMPTY"); + if (flags & SLIST_CASE_SENSITIVE) + printf(" | SLIST_CASE_SENSITIVE"); +} + +static void slist_dump(const struct Slist *list) +{ + if (!list) + return; + + printf("[%ld] ", list->count); + + struct ListNode *np = NULL; + STAILQ_FOREACH(np, &list->head, entries) + { + if (np->data) + printf("'%s'", np->data); + else + printf("NULL"); + if (STAILQ_NEXT(np, entries)) + printf(","); + } + printf("\n"); +} + +static bool test_slist_parse(struct Buffer *err) +{ + mutt_buffer_reset(err); + + static const char *init[] = { + NULL, + "", + "apple", + "apple:banana", + "apple:banana:cherry", + ":apple", + "banana:", + ":", + "::", + "apple:banana:apple", + "apple::banana", + }; + + unsigned int flags = SLIST_SEP_COLON | SLIST_ALLOW_EMPTY; + slist_flags(flags); + printf("\n"); + + struct Slist *list = NULL; + for (size_t i = 0; i < mutt_array_size(init); i++) + { + printf(">>%s<<\n", init[i] ? init[i] : "NULL"); + list = slist_parse(init[i], flags); + slist_dump(list); + slist_free(&list); + } + + return true; +} + +static bool test_slist_add_string(struct Buffer *err) +{ + mutt_buffer_reset(err); + + struct Slist *list = slist_parse(NULL, SLIST_ALLOW_EMPTY); + slist_dump(list); + + slist_add_string(list, NULL); + slist_dump(list); + + slist_empty(&list); + slist_add_string(list, ""); + slist_dump(list); + + slist_empty(&list); + slist_add_string(list, "apple"); + slist_dump(list); + slist_add_string(list, "banana"); + slist_dump(list); + slist_add_string(list, "apple"); + slist_dump(list); + + slist_free(&list); + + return true; +} + +static bool test_slist_remove_string(struct Buffer *err) +{ + mutt_buffer_reset(err); + + unsigned int flags = SLIST_SEP_COLON | SLIST_ALLOW_EMPTY; + struct Slist *list = slist_parse("apple:banana::cherry", flags); + slist_dump(list); + + slist_remove_string(list, NULL); + slist_dump(list); + + slist_remove_string(list, "apple"); + slist_dump(list); + + slist_remove_string(list, "damson"); + slist_dump(list); + + slist_free(&list); + + return true; +} + +static bool test_slist_is_member(struct Buffer *err) +{ + mutt_buffer_reset(err); + + unsigned int flags = SLIST_SEP_COLON | SLIST_ALLOW_EMPTY; + struct Slist *list = slist_parse("apple:banana::cherry", flags); + slist_dump(list); + + static const char *values[] = { "apple", "", "damson", NULL }; + + for (size_t i = 0; i < mutt_array_size(values); i++) + { + printf("member '%s' : %s\n", values[i], slist_is_member(list, values[i]) ? "yes" : "no"); + } + + slist_free(&list); + return true; +} + +static bool test_slist_add_list(struct Buffer *err) +{ + mutt_buffer_reset(err); + + unsigned int flags = SLIST_SEP_COLON | SLIST_ALLOW_EMPTY; + + struct Slist *list1 = slist_parse("apple:banana::cherry", flags); + slist_dump(list1); + + struct Slist *list2 = slist_parse("damson::apple:apple", flags); + slist_dump(list2); + + list1 = slist_add_list(list1, list2); + slist_dump(list1); + + slist_free(&list1); + slist_free(&list2); + + list1 = NULL; + slist_dump(list1); + + list2 = slist_parse("damson::apple:apple", flags); + slist_dump(list2); + + list1 = slist_add_list(list1, list2); + slist_dump(list1); + + slist_free(&list1); + slist_free(&list2); + + return true; +} + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + static const char *values[] = { "apple", "banana", "cherry", NULL }; + + printf("Apple, %ld items, %u flags\n", VarApple->count, VarApple->flags); + if (VarApple->count != 1) + { + printf("Apple should have 1 item\n"); + return false; + } + + struct ListNode *np = NULL; + size_t i = 0; + STAILQ_FOREACH(np, &VarApple->head, entries) + { + if (mutt_str_strcmp(values[i], np->data) != 0) + return false; + i++; + } + + printf("Banana, %ld items, %u flags\n", VarBanana->count, VarBanana->flags); + if (VarBanana->count != 2) + { + printf("Banana should have 2 items\n"); + return false; + } + + np = NULL; + i = 0; + STAILQ_FOREACH(np, &VarBanana->head, entries) + { + if (mutt_str_strcmp(values[i], np->data) != 0) + return false; + i++; + } + + printf("Cherry, %ld items, %u flags\n", VarCherry->count, VarCherry->flags); + if (VarCherry->count != 3) + { + printf("Cherry should have 3 items\n"); + return false; + } + + np = NULL; + i = 0; + STAILQ_FOREACH(np, &VarCherry->head, entries) + { + if (mutt_str_strcmp(values[i], np->data) != 0) + return false; + i++; + } + + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + int rc; + + mutt_buffer_reset(err); + char *name = "Damson"; + rc = cs_str_string_set(cs, name, "pig:quail:rhino", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + mutt_buffer_reset(err); + name = "Elderberry"; + rc = cs_str_string_set(cs, name, "pig:quail:rhino", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + struct Buffer initial; + mutt_buffer_init(&initial); + initial.data = mutt_mem_calloc(1, STRING); + initial.dsize = STRING; + + mutt_buffer_reset(err); + mutt_buffer_reset(&initial); + char *name = "Fig"; + + int rc = cs_str_initial_get(cs, name, &initial); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(initial.data, err->data) != 0) + { + printf("Differ: %s '%s' '%s'\n", name, initial.data, err->data); + return false; + } + printf("Match: %s '%s' '%s'\n", name, initial.data, err->data); + + mutt_buffer_reset(err); + mutt_buffer_reset(&initial); + name = "Guava"; + + rc = cs_str_initial_get(cs, name, &initial); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(initial.data, err->data) != 0) + { + printf("Differ: %s '%s' '%s'\n", name, initial.data, err->data); + return false; + } + printf("Match: %s '%s' '%s'\n", name, initial.data, err->data); + + mutt_buffer_reset(err); + mutt_buffer_reset(&initial); + name = "Hawthorn"; + + rc = cs_str_initial_get(cs, name, &initial); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(initial.data, err->data) != 0) + { + printf("Differ: %s '%s' '%s'\n", name, initial.data, err->data); + return false; + } + printf("Match: %s '%s' '%s'\n", name, initial.data, err->data); + + FREE(&initial.data); + return true; +} + +#if 0 +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + return false; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + return false; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + return false; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + return false; +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + return false; +} +#endif + +bool slist_test_separator(struct ConfigDef Vars[], struct Buffer *err) +{ + log_line(__func__); + + mutt_buffer_reset(err); + struct ConfigSet *cs = cs_create(30); + + slist_init(cs); + if (!cs_register_variables(cs, Vars, 0)) + return false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, err)) + return false; + if (!test_string_set(cs, err)) + return false; + if (!test_string_get(cs, err)) + return false; + + cs_free(&cs); + return true; +} + +bool slist_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + bool result = false; + + if (!test_slist_parse(&err)) + goto st_done; + if (!test_slist_add_string(&err)) + goto st_done; + if (!test_slist_remove_string(&err)) + goto st_done; + if (!test_slist_is_member(&err)) + goto st_done; + if (!test_slist_add_list(&err)) + goto st_done; + + if (!slist_test_separator(VarsColon, &err)) + goto st_done; + if (!slist_test_separator(VarsComma, &err)) + goto st_done; + if (!slist_test_separator(VarsSpace, &err)) + goto st_done; + + result = true; +st_done: + FREE(&err.data); + return result; +} diff --git a/test/config/slist.h b/test/config/slist.h new file mode 100644 index 000000000..7e6eeb86d --- /dev/null +++ b/test/config/slist.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Slist object + * + * @authors + * Copyright (C) 2018 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_SLIST_H +#define _TEST_SLIST_H + +#include + +bool slist_test(void); + +#endif /* _TEST_SLIST_H */ diff --git a/test/config/slist.txt b/test/config/slist.txt new file mode 100644 index 000000000..8a0a9186a --- /dev/null +++ b/test/config/slist.txt @@ -0,0 +1,107 @@ +---- slist_test -------------------------------------------- +COLON | SLIST_ALLOW_EMPTY +>>NULL<< +[0] +>><< +[0] +>>apple<< +[1] 'apple' +>>apple:banana<< +[2] 'apple','banana' +>>apple:banana:cherry<< +[3] 'apple','banana','cherry' +>>:apple<< +[2] NULL,'apple' +>>banana:<< +[2] 'banana',NULL +>>:<< +[2] NULL,NULL +>>::<< +[3] NULL,NULL,NULL +>>apple:banana:apple<< +[3] 'apple','banana','apple' +>>apple::banana<< +[3] 'apple',NULL,'banana' +[0] +[1] NULL +[1] NULL +[1] 'apple' +[2] 'apple','banana' +[3] 'apple','banana','apple' +[4] 'apple','banana',NULL,'cherry' +[3] 'apple','banana','cherry' +[2] 'banana','cherry' +[2] 'banana','cherry' +[4] 'apple','banana',NULL,'cherry' +member 'apple' : yes +member '' : yes +member 'damson' : no +member '(null)' : yes +[4] 'apple','banana',NULL,'cherry' +[4] 'damson',NULL,'apple','apple' +[8] 'apple','banana',NULL,'cherry','damson',NULL,'apple','apple' +[4] 'damson',NULL,'apple','apple' +[0] 'damson',NULL,'apple','apple' +---- slist_test_separator ---------------------------------- +---- set_list ---------------------------------------------- +slist Apple = apple +slist Banana = apple:banana +slist Cherry = apple:banana:cherry +slist Damson = apple:banana +slist Elderberry = +slist Fig = :apple +slist Guava = apple::cherry +slist Hawthorn = apple: +---- test_initial_values ----------------------------------- +Apple, 1 items, 2 flags +Banana, 2 items, 2 flags +Cherry, 3 items, 2 flags +---- test_string_set --------------------------------------- +Event: Damson has been set to 'pig:quail:rhino' +Event: Elderberry has been set to 'pig:quail:rhino' +---- test_string_get --------------------------------------- +Match: Fig ':apple' ':apple' +Match: Guava 'apple::cherry' 'apple::cherry' +Match: Hawthorn 'apple:' 'apple:' +---- slist_test_separator ---------------------------------- +---- set_list ---------------------------------------------- +slist Apple = apple +slist Banana = apple,banana +slist Cherry = apple,banana,cherry +slist Damson = apple,banana +slist Elderberry = +slist Fig = ,apple +slist Guava = apple,,cherry +slist Hawthorn = apple, +---- test_initial_values ----------------------------------- +Apple, 1 items, 1 flags +Banana, 2 items, 1 flags +Cherry, 3 items, 1 flags +---- test_string_set --------------------------------------- +Event: Damson has been set to 'pig:quail:rhino' +Event: Elderberry has been set to 'pig:quail:rhino' +---- test_string_get --------------------------------------- +Match: Fig ',apple' ',apple' +Match: Guava 'apple,,cherry' 'apple,,cherry' +Match: Hawthorn 'apple,' 'apple,' +---- slist_test_separator ---------------------------------- +---- set_list ---------------------------------------------- +slist Apple = apple +slist Banana = apple banana +slist Cherry = apple banana cherry +slist Damson = apple banana +slist Elderberry = +slist Fig = apple +slist Guava = apple cherry +slist Hawthorn = apple +---- test_initial_values ----------------------------------- +Apple, 1 items, 0 flags +Banana, 2 items, 0 flags +Cherry, 3 items, 0 flags +---- test_string_set --------------------------------------- +Event: Damson has been set to 'pig:quail:rhino' +Event: Elderberry has been set to 'pig:quail:rhino' +---- test_string_get --------------------------------------- +Match: Fig ' apple' ' apple' +Match: Guava 'apple cherry' 'apple cherry' +Match: Hawthorn 'apple ' 'apple ' diff --git a/test/config/sort.c b/test/config/sort.c new file mode 100644 index 000000000..a8803bb61 --- /dev/null +++ b/test/config/sort.c @@ -0,0 +1,754 @@ +/** + * @file + * Test code for the Sort object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/mapping.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/set.h" +#include "config/sort.h" +#include "config/types.h" +#include "config/common.h" + +static short VarApple; +static short VarBanana; +static short VarCherry; +static short VarDamson; +static short VarElderberry; +static short VarFig; +static short VarGuava; +static short VarHawthorn; +static short VarIlama; +static short VarJackfruit; +static short VarKumquat; +static short VarLemon; +static short VarMango; +static short VarNectarine; +static short VarOlive; +static short VarPapaya; +static short VarQuince; +static short VarRaspberry; +static short VarStrawberry; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_SORT, 0, &VarApple, 1, NULL }, /* test_initial_values */ + { "Banana", DT_SORT, 0, &VarBanana, 2, NULL }, + { "Cherry", DT_SORT, 0, &VarCherry, 1, NULL }, + { "Damson", DT_SORT|DT_SORT_INDEX, 0, &VarDamson, 1, NULL }, /* test_string_set */ + { "Elderberry", DT_SORT|DT_SORT_ALIAS, 0, &VarElderberry, 11, NULL }, + { "Fig", DT_SORT|DT_SORT_BROWSER, 0, &VarFig, 1, NULL }, + { "Guava", DT_SORT|DT_SORT_KEYS, 0, &VarGuava, 1, NULL }, + { "Hawthorn", DT_SORT|DT_SORT_AUX, 0, &VarHawthorn, 1, NULL }, + { "Ilama", DT_SORT|DT_SORT_SIDEBAR, 0, &VarIlama, 17, NULL }, + { "Jackfruit", DT_SORT, 0, &VarJackfruit, 1, NULL }, /* test_string_get */ + { "Kumquat", DT_SORT, 0, &VarKumquat, 1, NULL }, /* test_native_set */ + { "Lemon", DT_SORT, 0, &VarLemon, 1, NULL }, /* test_native_get */ + { "Mango", DT_SORT, 0, &VarMango, 1, NULL }, /* test_reset */ + { "Nectarine", DT_SORT, 0, &VarNectarine, 1, validator_fail }, + { "Olive", DT_SORT, 0, &VarOlive, 1, validator_succeed }, /* test_validator */ + { "Papaya", DT_SORT, 0, &VarPapaya, 1, validator_warn }, + { "Quince", DT_SORT, 0, &VarQuince, 1, validator_fail }, + { "Strawberry", DT_SORT, 0, &VarStrawberry, 1, NULL }, /* test_inherit */ + { NULL }, +}; + +static struct ConfigDef Vars2[] = { + { "Raspberry", DT_SORT|DT_SORT_AUX|DT_SORT_ALIAS, 0, &VarRaspberry, 1, NULL }, /* test_sort_type */ + { NULL }, +}; +// clang-format on + +char *name_list[] = { + "Damson", "Elderberry", "Fig", "Guava", "Hawthorn", "Ilama", +}; + +short *var_list[] = { + &VarDamson, &VarElderberry, &VarFig, &VarGuava, &VarHawthorn, &VarIlama, +}; + +const struct Mapping *sort_maps[] = { + SortMethods, SortAliasMethods, SortBrowserMethods, + SortKeyMethods, SortAuxMethods, SortSidebarMethods, +}; + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %d\n", VarApple); + printf("Banana = %d\n", VarBanana); + + if ((VarApple != 1) || (VarBanana != 2)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "threads", err); + cs_str_string_set(cs, "Banana", "score", err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "date") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = %d\n", VarApple); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "size") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = %d\n", VarBanana); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "size", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = %s\n", mutt_map_get_name(VarCherry, SortMethods)); + printf("Cherry's initial value is %s\n", value.data); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + for (unsigned int i = 0; i < mutt_array_size(var_list); i++) + { + short *var = var_list[i]; + + *var = -1; + + const struct Mapping *map = sort_maps[i]; + + int rc; + for (int j = 0; map[j].name; j++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name_list[i], map[j].name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", map[j].name); + continue; + } + + if (*var != map[j].value) + { + printf("Value of %s wasn't changed\n", map[j].name); + return false; + } + printf("%s = %d, set by '%s'\n", name_list[i], *var, map[j].name); + } + + const char *invalid[] = { + "-1", "999", "junk", NULL, + }; + + for (unsigned int j = 0; j < mutt_array_size(invalid); j++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name_list[i], invalid[j], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%s'\n", name_list[i], *var, invalid[j]); + printf("This test should have failed\n"); + return false; + } + } + } + + const char *name = "Damson"; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "last-date-sent", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarDamson != (SORT_DATE | SORT_LAST)) + { + printf("Expected %d, got %d\n", (SORT_DATE | SORT_LAST), VarDamson); + return false; + } + + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "reverse-score", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarDamson != (SORT_SCORE | SORT_REVERSE)) + { + printf("Expected %d, got %d\n", (SORT_DATE | SORT_LAST), VarDamson); + return false; + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Jackfruit"; + + VarJackfruit = SORT_SUBJECT; + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarJackfruit, err->data); + + VarJackfruit = SORT_THREADS; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %d, %s\n", name, VarJackfruit, err->data); + + VarJackfruit = -1; + mutt_buffer_reset(err); + printf("Expect error for next test\n"); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + mutt_buffer_reset(err); + name = "Raspberry"; + printf("Expect error for next test\n"); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + int rc; + for (unsigned int i = 0; i < mutt_array_size(var_list); i++) + { + short *var = var_list[i]; + + *var = -1; + + const struct Mapping *map = sort_maps[i]; + + for (int j = 0; map[j].name; j++) + { + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name_list[i], map[j].value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", map[j].name); + continue; + } + + if (*var != map[j].value) + { + printf("Value of %s wasn't changed\n", map[j].name); + return false; + } + printf("%s = %d, set by '%s'\n", name_list[i], *var, map[j].name); + } + } + + char *name = "Kumquat"; + short value = SORT_THREADS; + VarKumquat = -1; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarKumquat != value) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("%s = %d, set to '%d'\n", name, VarKumquat, value); + + int invalid[] = { -1, 999 }; + for (unsigned int i = 0; i < mutt_array_size(invalid); i++) + { + VarKumquat = -1; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, invalid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s = %d, set by '%d'\n", name, VarKumquat, invalid[i]); + printf("This test should have failed\n"); + return false; + } + } + + name = "Damson"; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (SORT_DATE | SORT_LAST), err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarDamson != (SORT_DATE | SORT_LAST)) + { + printf("Expected %d, got %d\n", (SORT_DATE | SORT_LAST), VarDamson); + return false; + } + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (SORT_SCORE | SORT_REVERSE), err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarDamson != (SORT_SCORE | SORT_REVERSE)) + { + printf("Expected %d, got %d\n", (SORT_DATE | SORT_LAST), VarDamson); + return false; + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Lemon"; + + VarLemon = SORT_THREADS; + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (value != SORT_THREADS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = %ld\n", name, value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Mango"; + VarMango = SORT_SUBJECT; + mutt_buffer_reset(err); + + int rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (VarMango == SORT_SUBJECT) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarMango); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + name = "Nectarine"; + mutt_buffer_reset(err); + + printf("Initial: %s = %d\n", name, VarNectarine); + dont_fail = true; + rc = cs_str_string_set(cs, name, "size", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = %d\n", name, VarNectarine); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (VarNectarine != SORT_SIZE) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = %d\n", name, VarNectarine); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Olive"; + VarOlive = SORT_SUBJECT; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "threads", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarOlive); + + VarOlive = SORT_SUBJECT; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, SORT_THREADS, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarOlive); + + name = "Papaya"; + VarPapaya = SORT_SUBJECT; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "threads", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarPapaya); + + VarPapaya = SORT_SUBJECT; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, SORT_THREADS, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarPapaya); + + name = "Quince"; + VarQuince = SORT_SUBJECT; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "threads", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %d\n", name, VarQuince); + + VarQuince = SORT_SUBJECT; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, SORT_THREADS, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %d\n", name, VarQuince); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %ld\n", parent, pval); + printf("%15s = %ld\n", child, cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Strawberry"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + VarStrawberry = SORT_SUBJECT; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "threads", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "score", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +static bool test_sort_type(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *name = "Raspberry"; + char *value = "alpha"; + + mutt_buffer_reset(err); + printf("Expect error for next test\n"); + int rc = cs_str_string_set(cs, name, value, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s = %d, set by '%s'\n", name, VarRaspberry, value); + printf("This test should have failed\n"); + return false; + } + + mutt_buffer_reset(err); + printf("Expect error for next test\n"); + rc = cs_str_native_set(cs, name, SORT_THREADS, err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s = %d, set by %d\n", name, VarRaspberry, SORT_THREADS); + printf("This test should have failed\n"); + return false; + } + + return true; +} + +bool sort_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + sort_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + /* Register a broken variable separately */ + if (!cs_register_variables(cs, Vars2, 0)) + return false; + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + if (!test_sort_type(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/sort.h b/test/config/sort.h new file mode 100644 index 000000000..635a30cef --- /dev/null +++ b/test/config/sort.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the Sort object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_SORT_H +#define _TEST_SORT_H + +#include + +bool sort_test(void); + +#endif /* _TEST_SORT_H */ diff --git a/test/config/sort.txt b/test/config/sort.txt new file mode 100644 index 000000000..39fa6ba05 --- /dev/null +++ b/test/config/sort.txt @@ -0,0 +1,312 @@ +---- sort_test --------------------------------------------- +---- set_list ---------------------------------------------- +sort Apple = date +sort Banana = size +sort Cherry = date +sort Damson = date +sort Elderberry = address +sort Fig = date +sort Guava = date +sort Hawthorn = date +sort Ilama = flagged +sort Jackfruit = date +sort Kumquat = date +sort Lemon = date +sort Mango = date +sort Nectarine = date +sort Olive = date +sort Papaya = date +sort Quince = date +sort Strawberry = date +---- test_initial_values ----------------------------------- +Apple = 1 +Banana = 2 +Event: Apple has been set to 'threads' +Event: Banana has been set to 'score' +Apple = 6 +Apple's initial value is 'date' +Banana = 9 +Banana's initial value is 'size' +Event: Cherry has been initial-set to 'size' +Cherry = date +Cherry's initial value is size +---- test_string_set --------------------------------------- +Event: Damson has been set to 'date' +Damson = 1, set by 'date' +Event: Damson has been set to 'date-received' +Damson = 7, set by 'date-received' +Event: Damson has been set to 'date' +Damson = 1, set by 'date-sent' +Event: Damson has been set to 'from' +Damson = 4, set by 'from' +Event: Damson has been set to 'label' +Damson = 19, set by 'label' +Event: Damson has been set to 'mailbox-order' +Damson = 5, set by 'mailbox-order' +Event: Damson has been set to 'score' +Damson = 9, set by 'score' +Event: Damson has been set to 'size' +Damson = 2, set by 'size' +Event: Damson has been set to 'spam' +Damson = 14, set by 'spam' +Event: Damson has been set to 'subject' +Damson = 3, set by 'subject' +Event: Damson has been set to 'threads' +Damson = 6, set by 'threads' +Event: Damson has been set to 'to' +Damson = 8, set by 'to' +Expected error: Invalid sort name: -1 +Expected error: Invalid sort name: 999 +Expected error: Invalid sort name: junk +Expected error: Option Damson may not be empty +Event: Elderberry has been set to 'address' +Elderberry = 11, set by 'address' +Event: Elderberry has been set to 'alias' +Elderberry = 10, set by 'alias' +Event: Elderberry has been set to 'unsorted' +Elderberry = 5, set by 'unsorted' +Expected error: Invalid sort name: -1 +Expected error: Invalid sort name: 999 +Expected error: Invalid sort name: junk +Expected error: Option Elderberry may not be empty +Event: Fig has been set to 'alpha' +Fig = 3, set by 'alpha' +Event: Fig has been set to 'count' +Fig = 15, set by 'count' +Event: Fig has been set to 'date' +Fig = 1, set by 'date' +Event: Fig has been set to 'desc' +Fig = 20, set by 'desc' +Event: Fig has been set to 'new' +Fig = 16, set by 'new' +Value of unread wasn't changed +Event: Fig has been set to 'size' +Fig = 2, set by 'size' +Event: Fig has been set to 'unsorted' +Fig = 5, set by 'unsorted' +Expected error: Invalid sort name: -1 +Expected error: Invalid sort name: 999 +Expected error: Invalid sort name: junk +Expected error: Option Fig may not be empty +Event: Guava has been set to 'address' +Guava = 11, set by 'address' +Event: Guava has been set to 'date' +Guava = 1, set by 'date' +Event: Guava has been set to 'keyid' +Guava = 12, set by 'keyid' +Event: Guava has been set to 'trust' +Guava = 13, set by 'trust' +Expected error: Invalid sort name: -1 +Expected error: Invalid sort name: 999 +Expected error: Invalid sort name: junk +Expected error: Option Guava may not be empty +Event: Hawthorn has been set to 'date' +Hawthorn = 1, set by 'date' +Event: Hawthorn has been set to 'date-received' +Hawthorn = 7, set by 'date-received' +Event: Hawthorn has been set to 'date' +Hawthorn = 1, set by 'date-sent' +Event: Hawthorn has been set to 'from' +Hawthorn = 4, set by 'from' +Event: Hawthorn has been set to 'label' +Hawthorn = 19, set by 'label' +Event: Hawthorn has been set to 'mailbox-order' +Hawthorn = 5, set by 'mailbox-order' +Event: Hawthorn has been set to 'score' +Hawthorn = 9, set by 'score' +Event: Hawthorn has been set to 'size' +Hawthorn = 2, set by 'size' +Event: Hawthorn has been set to 'spam' +Hawthorn = 14, set by 'spam' +Event: Hawthorn has been set to 'subject' +Hawthorn = 3, set by 'subject' +Event: Hawthorn has been set to 'date' +Hawthorn = 1, set by 'threads' +Event: Hawthorn has been set to 'to' +Hawthorn = 8, set by 'to' +Expected error: Invalid sort name: -1 +Expected error: Invalid sort name: 999 +Expected error: Invalid sort name: junk +Expected error: Option Hawthorn may not be empty +Event: Ilama has been set to 'alpha' +Ilama = 18, set by 'alpha' +Event: Ilama has been set to 'count' +Ilama = 15, set by 'count' +Event: Ilama has been set to 'desc' +Ilama = 20, set by 'desc' +Event: Ilama has been set to 'flagged' +Ilama = 17, set by 'flagged' +Event: Ilama has been set to 'mailbox-order' +Ilama = 5, set by 'mailbox-order' +Event: Ilama has been set to 'alpha' +Ilama = 18, set by 'name' +Event: Ilama has been set to 'new' +Ilama = 16, set by 'new' +Event: Ilama has been set to 'alpha' +Ilama = 18, set by 'path' +Event: Ilama has been set to 'new' +Ilama = 16, set by 'unread' +Event: Ilama has been set to 'mailbox-order' +Ilama = 5, set by 'unsorted' +Expected error: Invalid sort name: -1 +Expected error: Invalid sort name: 999 +Expected error: Invalid sort name: junk +Expected error: Option Ilama may not be empty +Event: Damson has been set to 'last-date' +Event: Damson has been set to 'reverse-score' +---- test_string_get --------------------------------------- +Jackfruit = 3, subject +Jackfruit = 6, threads +Expect error for next test +Variable has an invalid value: 0/255 +Expect error for next test +Invalid sort type: 576 +---- test_native_set --------------------------------------- +Event: Damson has been set to 'date' +Damson = 1, set by 'date' +Event: Damson has been set to 'date-received' +Damson = 7, set by 'date-received' +Event: Damson has been set to 'date' +Damson = 1, set by 'date-sent' +Event: Damson has been set to 'from' +Damson = 4, set by 'from' +Event: Damson has been set to 'label' +Damson = 19, set by 'label' +Event: Damson has been set to 'mailbox-order' +Damson = 5, set by 'mailbox-order' +Event: Damson has been set to 'score' +Damson = 9, set by 'score' +Event: Damson has been set to 'size' +Damson = 2, set by 'size' +Event: Damson has been set to 'spam' +Damson = 14, set by 'spam' +Event: Damson has been set to 'subject' +Damson = 3, set by 'subject' +Event: Damson has been set to 'threads' +Damson = 6, set by 'threads' +Event: Damson has been set to 'to' +Damson = 8, set by 'to' +Event: Elderberry has been set to 'address' +Elderberry = 11, set by 'address' +Event: Elderberry has been set to 'alias' +Elderberry = 10, set by 'alias' +Event: Elderberry has been set to 'unsorted' +Elderberry = 5, set by 'unsorted' +Event: Fig has been set to 'alpha' +Fig = 3, set by 'alpha' +Event: Fig has been set to 'count' +Fig = 15, set by 'count' +Event: Fig has been set to 'date' +Fig = 1, set by 'date' +Event: Fig has been set to 'desc' +Fig = 20, set by 'desc' +Event: Fig has been set to 'new' +Fig = 16, set by 'new' +Value of unread wasn't changed +Event: Fig has been set to 'size' +Fig = 2, set by 'size' +Event: Fig has been set to 'unsorted' +Fig = 5, set by 'unsorted' +Event: Guava has been set to 'address' +Guava = 11, set by 'address' +Event: Guava has been set to 'date' +Guava = 1, set by 'date' +Event: Guava has been set to 'keyid' +Guava = 12, set by 'keyid' +Event: Guava has been set to 'trust' +Guava = 13, set by 'trust' +Event: Hawthorn has been set to 'date' +Hawthorn = 1, set by 'date' +Event: Hawthorn has been set to 'date-received' +Hawthorn = 7, set by 'date-received' +Event: Hawthorn has been set to 'date' +Hawthorn = 1, set by 'date-sent' +Event: Hawthorn has been set to 'from' +Hawthorn = 4, set by 'from' +Event: Hawthorn has been set to 'label' +Hawthorn = 19, set by 'label' +Event: Hawthorn has been set to 'mailbox-order' +Hawthorn = 5, set by 'mailbox-order' +Event: Hawthorn has been set to 'score' +Hawthorn = 9, set by 'score' +Event: Hawthorn has been set to 'size' +Hawthorn = 2, set by 'size' +Event: Hawthorn has been set to 'spam' +Hawthorn = 14, set by 'spam' +Event: Hawthorn has been set to 'subject' +Hawthorn = 3, set by 'subject' +Event: Hawthorn has been set to 'date' +Hawthorn = 1, set by 'threads' +Event: Hawthorn has been set to 'to' +Hawthorn = 8, set by 'to' +Event: Ilama has been set to 'alpha' +Ilama = 18, set by 'alpha' +Event: Ilama has been set to 'count' +Ilama = 15, set by 'count' +Event: Ilama has been set to 'desc' +Ilama = 20, set by 'desc' +Event: Ilama has been set to 'flagged' +Ilama = 17, set by 'flagged' +Event: Ilama has been set to 'mailbox-order' +Ilama = 5, set by 'mailbox-order' +Event: Ilama has been set to 'alpha' +Ilama = 18, set by 'name' +Event: Ilama has been set to 'new' +Ilama = 16, set by 'new' +Event: Ilama has been set to 'alpha' +Ilama = 18, set by 'path' +Event: Ilama has been set to 'new' +Ilama = 16, set by 'unread' +Event: Ilama has been set to 'mailbox-order' +Ilama = 5, set by 'unsorted' +Event: Kumquat has been set to 'threads' +Kumquat = 6, set to '6' +Expected error: Invalid sort type: -1 +Expected error: Invalid sort type: 999 +Event: Damson has been set to 'last-date' +Event: Damson has been set to 'reverse-score' +---- test_native_get --------------------------------------- +Lemon = 6 +---- test_reset -------------------------------------------- +Event: Mango has been reset to 'date' +Reset: Mango = 1 +Initial: Nectarine = 1 +Event: Nectarine has been set to 'size' +Set: Nectarine = 2 +Expected error: validator_fail: Nectarine, 1 +Reset: Nectarine = 2 +---- test_validator ---------------------------------------- +Event: Olive has been set to 'threads' +validator_succeed: Olive, 6 +String: Olive = 6 +Event: Olive has been set to 'threads' +validator_succeed: Olive, 6 +Native: Olive = 6 +Event: Papaya has been set to 'threads' +validator_warn: Papaya, 6 +String: Papaya = 6 +Event: Papaya has been set to 'threads' +validator_warn: Papaya, 6 +Native: Papaya = 6 +Expected error: validator_fail: Quince, 6 +String: Quince = 3 +Expected error: validator_fail: Quince, 6 +Native: Quince = 3 +---- test_inherit ------------------------------------------ +Event: Strawberry has been set to 'threads' + Strawberry = 6 +fruit:Strawberry = 6 +Event: fruit:Strawberry has been set to 'score' + Strawberry = 6 +fruit:Strawberry = 9 +Event: fruit:Strawberry has been reset to 'threads' + Strawberry = 6 +fruit:Strawberry = 6 +Event: Strawberry has been reset to 'date' + Strawberry = 1 +fruit:Strawberry = 1 +---- test_sort_type ---------------------------------------- +Expect error for next test +Invalid sort type: 576 +Expect error for next test +Invalid sort type: 576 diff --git a/test/config/string.c b/test/config/string.c new file mode 100644 index 000000000..8c4505922 --- /dev/null +++ b/test/config/string.c @@ -0,0 +1,653 @@ +/** + * @file + * Test code for the String object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/account.h" +#include "config/set.h" +#include "config/string3.h" +#include "config/types.h" +#include "config/common.h" + +static char *VarApple; +static char *VarBanana; +static char *VarCherry; +static char *VarDamson; +static char *VarElderberry; +static char *VarFig; +static char *VarGuava; +static char *VarHawthorn; +static char *VarIlama; +static char *VarJackfruit; +static char *VarKumquat; +static char *VarLemon; +static char *VarMango; +static char *VarNectarine; +static char *VarOlive; +static char *VarPapaya; +static char *VarQuince; +static char *VarRaspberry; +static char *VarStrawberry; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_STRING, 0, &VarApple, IP "apple", NULL }, /* test_initial_values */ + { "Banana", DT_STRING, 0, &VarBanana, IP "banana", NULL }, + { "Cherry", DT_STRING, 0, &VarCherry, IP "cherry", NULL }, + { "Damson", DT_STRING, 0, &VarDamson, 0, NULL }, /* test_string_set */ + { "Elderberry", DT_STRING, 0, &VarElderberry, IP "elderberry", NULL }, + { "Fig", DT_STRING|DT_NOT_EMPTY, 0, &VarFig, IP "fig", NULL }, + { "Guava", DT_STRING, 0, &VarGuava, 0, NULL }, /* test_string_get */ + { "Hawthorn", DT_STRING, 0, &VarHawthorn, IP "hawthorn", NULL }, + { "Ilama", DT_STRING, 0, &VarIlama, 0, NULL }, + { "Jackfruit", DT_STRING, 0, &VarJackfruit, 0, NULL }, /* test_native_set */ + { "Kumquat", DT_STRING, 0, &VarKumquat, IP "kumquat", NULL }, + { "Lemon", DT_STRING|DT_NOT_EMPTY, 0, &VarLemon, IP "lemon", NULL }, + { "Mango", DT_STRING, 0, &VarMango, 0, NULL }, /* test_native_get */ + { "Nectarine", DT_STRING, 0, &VarNectarine, IP "nectarine", NULL }, /* test_reset */ + { "Olive", DT_STRING, 0, &VarOlive, IP "olive", validator_fail }, + { "Papaya", DT_STRING, 0, &VarPapaya, IP "papaya", validator_succeed }, /* test_validator */ + { "Quince", DT_STRING, 0, &VarQuince, IP "quince", validator_warn }, + { "Raspberry", DT_STRING, 0, &VarRaspberry, IP "raspberry", validator_fail }, + { "Strawberry", DT_STRING, 0, &VarStrawberry, 0, NULL }, /* test_inherit */ + { NULL }, +}; +// clang-format on + +static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + printf("Apple = %s\n", VarApple); + printf("Banana = %s\n", VarBanana); + + if ((mutt_str_strcmp(VarApple, "apple") != 0) || + (mutt_str_strcmp(VarBanana, "banana") != 0)) + { + printf("Error: initial values were wrong\n"); + return false; + } + + cs_str_string_set(cs, "Apple", "car", err); + cs_str_string_set(cs, "Banana", NULL, err); + + struct Buffer value; + mutt_buffer_init(&value); + value.data = mutt_mem_calloc(1, STRING); + value.dsize = STRING; + mutt_buffer_reset(&value); + + int rc; + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Apple", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "apple") != 0) + { + printf("Apple's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Apple = '%s'\n", VarApple); + printf("Apple's initial value is '%s'\n", value.data); + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Banana", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + if (mutt_str_strcmp(value.data, "banana") != 0) + { + printf("Banana's initial value is wrong: '%s'\n", value.data); + FREE(&value.data); + return false; + } + printf("Banana = '%s'\n", VarBanana); + printf("Banana's initial value is '%s'\n", NONULL(value.data)); + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "train", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_set(cs, "Cherry", "plane", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + mutt_buffer_reset(&value); + rc = cs_str_initial_get(cs, "Cherry", &value); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", value.data); + FREE(&value.data); + return false; + } + + printf("Cherry = '%s'\n", VarCherry); + printf("Cherry's initial value is '%s'\n", NONULL(value.data)); + + FREE(&value.data); + return true; +} + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello", "world", "world", "", NULL }; + char *name = "Damson"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarDamson, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarDamson), NONULL(valid[i])); + } + + name = "Fig"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + name = "Elderberry"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarElderberry, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarElderberry), NONULL(valid[i])); + } + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Guava"; + + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarGuava), err->data); + + name = "Hawthorn"; + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarHawthorn), err->data); + + name = "Ilama"; + rc = cs_str_string_set(cs, name, "ilama", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarIlama), err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *valid[] = { "hello", "world", "world", "", NULL }; + char *name = "Jackfruit"; + + int rc; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarJackfruit, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarJackfruit), NONULL(valid[i])); + } + + name = "Lemon"; + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) "", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + name = "Kumquat"; + for (unsigned int i = 0; i < mutt_array_size(valid); i++) + { + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, (intptr_t) valid[i], err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (rc & CSR_SUC_NO_CHANGE) + { + printf("Value of %s wasn't changed\n", name); + continue; + } + + if (mutt_str_strcmp(VarKumquat, valid[i]) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = '%s', set by '%s'\n", name, NONULL(VarKumquat), NONULL(valid[i])); + } + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + char *name = "Mango"; + + int rc = cs_str_string_set(cs, name, "mango", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (mutt_str_strcmp(VarMango, (char *) value) != 0) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, VarMango, (char *) value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Nectarine"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarNectarine); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarNectarine); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarNectarine, "nectarine") != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarNectarine); + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + name = "Olive"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, VarOlive); + dont_fail = true; + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarOlive); + dont_fail = false; + + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarOlive, "hello") != 0) + { + printf("Value of %s changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarOlive); + + return true; +} + +static bool test_validator(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Papaya"; + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %s\n", name, VarPapaya); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarPapaya); + + name = "Quince"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %s\n", name, VarQuince); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) == CSR_SUCCESS) + { + printf("%s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarQuince); + + name = "Raspberry"; + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("String: %s = %s\n", name, VarRaspberry); + + mutt_buffer_reset(err); + rc = cs_str_native_set(cs, name, IP "world", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Expected error: %s\n", err->data); + } + else + { + printf("%s\n", err->data); + return false; + } + printf("Native: %s = %s\n", name, VarRaspberry); + + return true; +} + +static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) +{ + intptr_t pval = cs_str_native_get(cs, parent, NULL); + intptr_t cval = cs_str_native_get(cs, child, NULL); + + printf("%15s = %s\n", parent, (char *) pval); + printf("%15s = %s\n", child, (char *) cval); +} + +static bool test_inherit(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + bool result = false; + + const char *account = "fruit"; + const char *parent = "Strawberry"; + char child[128]; + snprintf(child, sizeof(child), "%s:%s", account, parent); + + const char *AccountVarStr[] = { + parent, NULL, + }; + + struct Account *ac = ac_create(cs, account, AccountVarStr); + + // set parent + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, parent, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // set child + mutt_buffer_reset(err); + rc = cs_str_string_set(cs, child, "world", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset child + mutt_buffer_reset(err); + rc = cs_str_reset(cs, child, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + // reset parent + mutt_buffer_reset(err); + rc = cs_str_reset(cs, parent, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Error: %s\n", err->data); + goto ti_out; + } + dump_native(cs, parent, child); + + result = true; +ti_out: + ac_free(cs, &ac); + return result; +} + +bool string_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + string_init(cs); + dont_fail = true; + if (!cs_register_variables(cs, Vars, 0)) + return false; + dont_fail = false; + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_initial_values(cs, &err)) + return false; + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + if (!test_validator(cs, &err)) + return false; + if (!test_inherit(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/string.txt b/test/config/string.txt new file mode 100644 index 000000000..fae34c420 --- /dev/null +++ b/test/config/string.txt @@ -0,0 +1,119 @@ +---- string_test ------------------------------------------- +---- set_list ---------------------------------------------- +string Apple = apple +string Banana = banana +string Cherry = cherry +string Damson = +string Elderberry = elderberry +string Fig = fig +string Guava = +string Hawthorn = hawthorn +string Ilama = +string Jackfruit = +string Kumquat = kumquat +string Lemon = lemon +string Mango = +string Nectarine = nectarine +string Olive = olive +string Papaya = papaya +string Quince = quince +string Raspberry = raspberry +string Strawberry = +---- test_initial_values ----------------------------------- +Apple = apple +Banana = banana +Event: Apple has been set to 'car' +Event: Banana has been set to '' +Apple = 'car' +Apple's initial value is 'apple' +Banana = '(null)' +Banana's initial value is 'banana' +Event: Cherry has been initial-set to 'train' +Event: Cherry has been initial-set to 'plane' +Cherry = 'cherry' +Cherry's initial value is 'plane' +---- test_string_set --------------------------------------- +Event: Damson has been set to 'hello' +Damson = 'hello', set by 'hello' +Event: Damson has been set to 'world' +Damson = 'world', set by 'world' +Value of Damson wasn't changed +Event: Damson has been set to '' +Damson = '', set by '' +Value of Damson wasn't changed +Expected error: Option Fig may not be empty +Event: Elderberry has been set to 'hello' +Elderberry = 'hello', set by 'hello' +Event: Elderberry has been set to 'world' +Elderberry = 'world', set by 'world' +Value of Elderberry wasn't changed +Event: Elderberry has been set to '' +Elderberry = '', set by '' +Value of Elderberry wasn't changed +---- test_string_get --------------------------------------- +Guava = '', '' +Hawthorn = 'hawthorn', 'hawthorn' +Event: Ilama has been set to 'ilama' +Ilama = 'ilama', 'ilama' +---- test_native_set --------------------------------------- +Event: Jackfruit has been set to 'hello' +Jackfruit = 'hello', set by 'hello' +Event: Jackfruit has been set to 'world' +Jackfruit = 'world', set by 'world' +Value of Jackfruit wasn't changed +Event: Jackfruit has been set to '' +Jackfruit = '', set by '' +Value of Jackfruit wasn't changed +Expected error: Option Lemon may not be empty +Event: Kumquat has been set to 'hello' +Kumquat = 'hello', set by 'hello' +Event: Kumquat has been set to 'world' +Kumquat = 'world', set by 'world' +Value of Kumquat wasn't changed +Event: Kumquat has been set to '' +Kumquat = '', set by '' +Value of Kumquat wasn't changed +---- test_native_get --------------------------------------- +Event: Mango has been set to 'mango' +Mango = 'mango', 'mango' +---- test_reset -------------------------------------------- +Initial: Nectarine = 'nectarine' +Event: Nectarine has been set to 'hello' +Set: Nectarine = 'hello' +Event: Nectarine has been reset to 'nectarine' +Reset: Nectarine = 'nectarine' +Initial: Olive = 'olive' +Event: Olive has been set to 'hello' +Set: Olive = 'hello' +Expected error: validator_fail: Olive, (ptr) +Reset: Olive = 'hello' +---- test_validator ---------------------------------------- +Event: Papaya has been set to 'hello' +validator_succeed: Papaya, (ptr) +String: Papaya = hello +Event: Papaya has been set to 'world' +validator_succeed: Papaya, (ptr) +Native: Papaya = world +Event: Quince has been set to 'hello' +validator_warn: Quince, (ptr) +String: Quince = hello +Event: Quince has been set to 'world' +validator_warn: Quince, (ptr) +Native: Quince = world +Expected error: validator_fail: Raspberry, (ptr) +String: Raspberry = raspberry +Expected error: validator_fail: Raspberry, (ptr) +Native: Raspberry = raspberry +---- test_inherit ------------------------------------------ +Event: Strawberry has been set to 'hello' + Strawberry = hello +fruit:Strawberry = hello +Event: fruit:Strawberry has been set to 'world' + Strawberry = hello +fruit:Strawberry = world +Event: fruit:Strawberry has been reset to 'hello' + Strawberry = hello +fruit:Strawberry = hello +Event: Strawberry has been reset to '' + Strawberry = (null) +fruit:Strawberry = (null) diff --git a/test/config/string4.h b/test/config/string4.h new file mode 100644 index 000000000..a9286ff4f --- /dev/null +++ b/test/config/string4.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for the String object + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_STRING_H +#define _TEST_STRING_H + +#include + +bool string_test(void); + +#endif /* _TEST_STRING_H */ diff --git a/test/config/synonym.c b/test/config/synonym.c new file mode 100644 index 000000000..997bca79d --- /dev/null +++ b/test/config/synonym.c @@ -0,0 +1,227 @@ +/** + * @file + * Test code for Config Synonyms + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include +#include +#include "mutt/buffer.h" +#include "mutt/memory.h" +#include "mutt/string2.h" +#include "config/set.h" +#include "config/string3.h" +#include "config/types.h" +#include "config/common.h" + +static char *VarApple; +static char *VarCherry; +static char *VarElderberry; +static char *VarGuava; +static char *VarIlama; + +// clang-format off +static struct ConfigDef Vars[] = { + { "Apple", DT_STRING, 0, &VarApple, 0, NULL }, + { "Banana", DT_SYNONYM, 0, NULL, IP "Apple", NULL }, + { "Cherry", DT_STRING, 0, &VarCherry, IP "cherry", NULL }, + { "Damson", DT_SYNONYM, 0, NULL, IP "Cherry", NULL }, + { "Elderberry", DT_STRING, 0, &VarElderberry, 0, NULL }, + { "Fig", DT_SYNONYM, 0, NULL, IP "Elderberry", NULL }, + { "Guava", DT_STRING, 0, &VarGuava, 0, NULL }, + { "Hawthorn", DT_SYNONYM, 0, NULL, IP "Guava", NULL }, + { "Ilama", DT_STRING, 0, &VarIlama, IP "iguana", NULL }, + { "Jackfruit", DT_SYNONYM, 0, NULL, IP "Ilama", NULL }, + { NULL }, +}; + +static struct ConfigDef Vars2[] = { + { "Jackfruit", DT_SYNONYM, 0, NULL, IP "Broken", NULL }, + { NULL }, +}; +// clang-format on + +static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + const char *name = "Banana"; + const char *value = "pudding"; + + mutt_buffer_reset(err); + int rc = cs_str_string_set(cs, name, value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarApple, value) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = %s, set by '%s'\n", name, NONULL(VarApple), value); + + return true; +} + +static bool test_string_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Damson"; + + mutt_buffer_reset(err); + int rc = cs_str_string_get(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, NONULL(VarCherry), err->data); + + return true; +} + +static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Fig"; + char *value = "tree"; + + mutt_buffer_reset(err); + int rc = cs_str_native_set(cs, name, (intptr_t) value, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarElderberry, value) != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + printf("%s = %s, set by '%s'\n", name, NONULL(VarElderberry), value); + + return true; +} + +static bool test_native_get(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + const char *name = "Hawthorn"; + + int rc = cs_str_string_set(cs, name, "tree", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + + mutt_buffer_reset(err); + intptr_t value = cs_str_native_get(cs, name, err); + if (mutt_str_strcmp(VarGuava, (const char *) value) != 0) + { + printf("Get failed: %s\n", err->data); + return false; + } + printf("%s = '%s', '%s'\n", name, VarGuava, (const char *) value); + + return true; +} + +static bool test_reset(struct ConfigSet *cs, struct Buffer *err) +{ + log_line(__func__); + + char *name = "Jackfruit"; + mutt_buffer_reset(err); + + printf("Initial: %s = '%s'\n", name, NONULL(VarIlama)); + int rc = cs_str_string_set(cs, name, "hello", err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + return false; + printf("Set: %s = '%s'\n", name, VarIlama); + + mutt_buffer_reset(err); + rc = cs_str_reset(cs, name, err); + if (CSR_RESULT(rc) != CSR_SUCCESS) + { + printf("%s\n", err->data); + return false; + } + + if (mutt_str_strcmp(VarIlama, "iguana") != 0) + { + printf("Value of %s wasn't changed\n", name); + return false; + } + + printf("Reset: %s = '%s'\n", name, VarIlama); + + return true; +} + +bool synonym_test(void) +{ + log_line(__func__); + + struct Buffer err; + mutt_buffer_init(&err); + err.data = mutt_mem_calloc(1, STRING); + err.dsize = STRING; + mutt_buffer_reset(&err); + + struct ConfigSet *cs = cs_create(30); + + string_init(cs); + if (!cs_register_variables(cs, Vars, 0)) + return false; + + if (!cs_register_variables(cs, Vars2, 0)) + { + printf("Expected error\n"); + } + else + { + printf("Test should have failed\n"); + return false; + } + + cs_add_listener(cs, log_listener); + + set_list(cs); + + if (!test_string_set(cs, &err)) + return false; + if (!test_string_get(cs, &err)) + return false; + if (!test_native_set(cs, &err)) + return false; + if (!test_native_get(cs, &err)) + return false; + if (!test_reset(cs, &err)) + return false; + + cs_free(&cs); + FREE(&err.data); + + return true; +} diff --git a/test/config/synonym.h b/test/config/synonym.h new file mode 100644 index 000000000..5f4660754 --- /dev/null +++ b/test/config/synonym.h @@ -0,0 +1,30 @@ +/** + * @file + * Test code for Config Synonyms + * + * @authors + * Copyright (C) 2017 Richard Russon + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _TEST_SYNONYM_H +#define _TEST_SYNONYM_H + +#include + +bool synonym_test(void); + +#endif /* _TEST_SYNONYM_H */ diff --git a/test/config/synonym.txt b/test/config/synonym.txt new file mode 100644 index 000000000..e6bbecf29 --- /dev/null +++ b/test/config/synonym.txt @@ -0,0 +1,26 @@ +---- synonym_test ------------------------------------------ +No such variable: Broken +Expected error +---- set_list ---------------------------------------------- +string Apple = +string Cherry = cherry +string Elderberry = +string Guava = +string Ilama = iguana +---- test_string_set --------------------------------------- +Event: Apple has been set to 'pudding' +Banana = pudding, set by 'pudding' +---- test_string_get --------------------------------------- +Damson = 'cherry', 'cherry' +---- test_native_set --------------------------------------- +Event: Elderberry has been set to 'tree' +Fig = tree, set by 'tree' +---- test_native_get --------------------------------------- +Event: Guava has been set to 'tree' +Hawthorn = 'tree', 'tree' +---- test_reset -------------------------------------------- +Initial: Jackfruit = 'iguana' +Event: Ilama has been set to 'hello' +Set: Jackfruit = 'hello' +Event: Ilama has been reset to 'iguana' +Reset: Jackfruit = 'iguana'