+++ /dev/null
-/**
- * @file
- * Type representing a mailbox
- *
- * @authors
- * Copyright (C) 2017-2018 Richard Russon <rich@flatcap.org>
- *
- * @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 <http://www.gnu.org/licenses/>.
- */
-
-/**
- * @page config_magic Type: Mailbox types
- *
- * Type representing a mailbox.
- */
-
-#include "config.h"
-#include <stddef.h>
-#include <limits.h>
-#include <stdint.h>
-#include "mutt/mutt.h"
-#include "set.h"
-#include "types.h"
-
-/**
- * MagicValues - Valid strings for mailbox types
- *
- * These strings are case-insensitive.
- */
-const char *MagicValues[] = {
- NULL, "mbox", "MMDF", "MH", "Maildir", NULL,
-};
-
-/**
- * magic_string_set - Set a Mailbox Magic by string - Implements ::cst_string_set()
- */
-static int magic_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef,
- const char *value, struct Buffer *err)
-{
- if (!cs || !cdef)
- return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
-
- if (!value || !value[0])
- {
- mutt_buffer_printf(err, "Option %s may not be empty", cdef->name);
- return CSR_ERR_INVALID | CSR_INV_TYPE;
- }
-
- int num = -1;
- for (size_t i = 1; MagicValues[i]; i++)
- {
- if (mutt_str_strcasecmp(MagicValues[i], value) == 0)
- {
- num = i;
- break;
- }
- }
-
- if (num < 1)
- {
- mutt_buffer_printf(err, "Invalid magic value: %s", value);
- return CSR_ERR_INVALID | CSR_INV_TYPE;
- }
-
- if (var)
- {
- if (num == (*(short *) var))
- return CSR_SUCCESS | CSR_SUC_NO_CHANGE;
-
- if (cdef->validator)
- {
- int rc = cdef->validator(cs, cdef, (intptr_t) num, err);
-
- if (CSR_RESULT(rc) != CSR_SUCCESS)
- return rc | CSR_INV_VALIDATOR;
- }
-
- *(short *) var = num;
- }
- else
- {
- cdef->initial = num;
- }
-
- return CSR_SUCCESS;
-}
-
-/**
- * magic_string_get - Get a Mailbox Magic as a string - Implements ::cst_string_get()
- */
-static int magic_string_get(const struct ConfigSet *cs, void *var,
- const struct ConfigDef *cdef, struct Buffer *result)
-{
- if (!cs || !cdef)
- return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
-
- unsigned int value;
-
- if (var)
- value = *(short *) var;
- else
- value = (int) cdef->initial;
-
- if ((value < 1) || (value >= (mutt_array_size(MagicValues) - 1)))
- {
- mutt_debug(LL_DEBUG1, "Variable has an invalid value: %d\n", value);
- return CSR_ERR_INVALID | CSR_INV_TYPE;
- }
-
- mutt_buffer_addstr(result, MagicValues[value]);
- return CSR_SUCCESS;
-}
-
-/**
- * magic_native_set - Set a Mailbox Magic config item by int - Implements ::cst_native_set()
- */
-static int magic_native_set(const struct ConfigSet *cs, void *var,
- const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
-{
- if (!cs || !var || !cdef)
- return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
-
- if ((value < 1) || (value >= (mutt_array_size(MagicValues) - 1)))
- {
- mutt_buffer_printf(err, "Invalid magic value: %ld", value);
- return CSR_ERR_INVALID | CSR_INV_TYPE;
- }
-
- if (value == (*(short *) var))
- return CSR_SUCCESS | CSR_SUC_NO_CHANGE;
-
- if (cdef->validator)
- {
- int rc = cdef->validator(cs, cdef, value, err);
-
- if (CSR_RESULT(rc) != CSR_SUCCESS)
- return rc | CSR_INV_VALIDATOR;
- }
-
- *(short *) var = value;
- return CSR_SUCCESS;
-}
-
-/**
- * magic_native_get - Get an int from a Mailbox Magic config item - Implements ::cst_native_get()
- */
-static intptr_t magic_native_get(const struct ConfigSet *cs, void *var,
- const struct ConfigDef *cdef, struct Buffer *err)
-{
- if (!cs || !var || !cdef)
- return INT_MIN; /* LCOV_EXCL_LINE */
-
- return *(short *) var;
-}
-
-/**
- * magic_reset - Reset a Mailbox Magic to its initial value - Implements ::cst_reset()
- */
-static int magic_reset(const struct ConfigSet *cs, void *var,
- const struct ConfigDef *cdef, struct Buffer *err)
-{
- if (!cs || !var || !cdef)
- return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
-
- if (cdef->initial == (*(short *) var))
- return CSR_SUCCESS | CSR_SUC_NO_CHANGE;
-
- if (cdef->validator)
- {
- int rc = cdef->validator(cs, cdef, cdef->initial, err);
-
- if (CSR_RESULT(rc) != CSR_SUCCESS)
- return rc | CSR_INV_VALIDATOR;
- }
-
- *(short *) var = cdef->initial;
- return CSR_SUCCESS;
-}
-
-/**
- * magic_init - Register the Mailbox Magic config type
- * @param cs Config items
- */
-void magic_init(struct ConfigSet *cs)
-{
- const struct ConfigSetType cst_magic = {
- "magic",
- magic_string_set,
- magic_string_get,
- magic_native_set,
- magic_native_get,
- magic_reset,
- NULL,
- };
- cs_register_type(cs, DT_MAGIC, &cst_magic);
-}
static short VarMango;
static char *VarNectarine;
+// clang-format off
+static struct Mapping MagicMap[] = {
+ { "mbox", MUTT_MBOX, },
+ { "MMDF", MUTT_MMDF, },
+ { "MH", MUTT_MH, },
+ { "Maildir", MUTT_MAILDIR, },
+ { NULL, 0, },
+};
+// clang-format on
+
+struct EnumDef MagicDef = {
+ "mbox_type",
+ 4,
+ (struct Mapping *) &MagicMap,
+};
+
// clang-format off
static struct ConfigDef Vars[] = {
- { "Apple", DT_BOOL, &VarApple, false, 0, NULL },
- { "Banana", DT_BOOL, &VarBanana, true, 0, NULL },
- { "Cherry", DT_NUMBER, &VarCherry, 0, 0, NULL },
- { "Damson", DT_SYNONYM, NULL, IP "Cherry", 0, NULL },
- { "Elderberry", DT_ADDRESS, &VarElderberry, IP "elderberry@example.com", 0, NULL },
- { "Fig", DT_STRING|DT_COMMAND|DT_NOT_EMPTY, &VarFig, IP "fig", 0, NULL },
- { "Guava", DT_LONG, &VarGuava, 0, 0, NULL },
- { "Hawthorn", DT_MAGIC, &VarHawthorn, 1, 0, NULL },
- { "Ilama", DT_MBTABLE, &VarIlama, 0, 0, NULL },
- { "Jackfruit", DT_STRING|DT_PATH, &VarJackfruit, IP "/etc/passwd", 0, NULL },
- { "Kumquat", DT_QUAD, &VarKumquat, 0, 0, NULL },
- { "Lemon", DT_REGEX, &VarLemon, 0, 0, NULL },
- { "Mango", DT_SORT, &VarMango, 1, 0, NULL },
- { "Nectarine", DT_STRING|DT_SENSITIVE, &VarNectarine, IP "nectarine", 0, NULL },
+ { "Apple", DT_BOOL, &VarApple, false, 0, NULL },
+ { "Banana", DT_BOOL, &VarBanana, true, 0, NULL },
+ { "Cherry", DT_NUMBER, &VarCherry, 0, 0, NULL },
+ { "Damson", DT_SYNONYM, NULL, IP "Cherry", 0, NULL },
+ { "Elderberry", DT_ADDRESS, &VarElderberry, IP "elderberry@example.com", 0, NULL },
+ { "Fig", DT_STRING|DT_COMMAND|DT_NOT_EMPTY, &VarFig, IP "fig", 0, NULL },
+ { "Guava", DT_LONG, &VarGuava, 0, 0, NULL },
+ { "Hawthorn", DT_ENUM, &VarHawthorn, 1, IP &MagicDef, NULL },
+ { "Ilama", DT_MBTABLE, &VarIlama, 0, 0, NULL },
+ { "Jackfruit", DT_STRING|DT_PATH, &VarJackfruit, IP "/etc/passwd", 0, NULL },
+ { "Kumquat", DT_QUAD, &VarKumquat, 0, 0, NULL },
+ { "Lemon", DT_REGEX, &VarLemon, 0, 0, NULL },
+ { "Mango", DT_SORT, &VarMango, 1, 0, NULL },
+ { "Nectarine", DT_STRING|DT_SENSITIVE, &VarNectarine, IP "nectarine", 0, NULL },
{ NULL },
};
// clang-format on
address_init(cs);
bool_init(cs);
+ enum_init(cs);
long_init(cs);
- magic_init(cs);
mbtable_init(cs);
number_init(cs);
quad_init(cs);
+++ /dev/null
-/**
- * @file
- * Test code for the Magic object
- *
- * @authors
- * Copyright (C) 2017-2018 Richard Russon <rich@flatcap.org>
- *
- * @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 <http://www.gnu.org/licenses/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include "config.h"
-#include <limits.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include "mutt/mutt.h"
-#include "config/common.h"
-#include "config/lib.h"
-#include "account.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, &VarApple, 1, 0, NULL }, /* test_initial_values */
- { "Banana", DT_MAGIC, &VarBanana, 3, 0, NULL },
- { "Cherry", DT_MAGIC, &VarCherry, 1, 0, NULL },
- { "Damson", DT_MAGIC, &VarDamson, 1, 0, NULL }, /* test_string_set */
- { "Elderberry", DT_MAGIC, &VarElderberry, 1, 0, NULL }, /* test_string_get */
- { "Fig", DT_MAGIC, &VarFig, 1, 0, NULL }, /* test_native_set */
- { "Guava", DT_MAGIC, &VarGuava, 1, 0, NULL }, /* test_native_get */
- { "Hawthorn", DT_MAGIC, &VarHawthorn, 1, 0, NULL }, /* test_reset */
- { "Ilama", DT_MAGIC, &VarIlama, 1, 0, validator_fail },
- { "Jackfruit", DT_MAGIC, &VarJackfruit, 1, 0, validator_succeed }, /* test_validator */
- { "Kumquat", DT_MAGIC, &VarKumquat, 1, 0, validator_warn },
- { "Lemon", DT_MAGIC, &VarLemon, 1, 0, validator_fail },
- { "Mango", DT_MAGIC, &VarMango, 1, 0, NULL }, /* test_inherit */
- { NULL },
-};
-// clang-format on
-
-static bool test_initial_values(struct ConfigSet *cs, struct Buffer *err)
-{
- log_line(__func__);
- TEST_MSG("Apple = %d\n", VarApple);
- TEST_MSG("Banana = %d\n", VarBanana);
-
- if (!TEST_CHECK(VarApple == 1))
- {
- TEST_MSG("Expected: %d\n", 1);
- TEST_MSG("Actual : %d\n", VarApple);
- }
-
- if (!TEST_CHECK(VarBanana == 3))
- {
- TEST_MSG("Expected: %d\n", 3);
- TEST_MSG("Actual : %d\n", VarBanana);
- }
-
- cs_str_string_set(cs, "Apple", "MMDF", err);
- cs_str_string_set(cs, "Banana", "Maildir", err);
-
- struct Buffer value;
- mutt_buffer_init(&value);
- value.dsize = 256;
- value.data = mutt_mem_calloc(1, value.dsize);
- mutt_buffer_reset(&value);
-
- int rc;
-
- mutt_buffer_reset(&value);
- rc = cs_str_initial_get(cs, "Apple", &value);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", value.data);
- FREE(&value.data);
- return false;
- }
-
- if (!TEST_CHECK(mutt_str_strcmp(value.data, "mbox") == 0))
- {
- TEST_MSG("Apple's initial value is wrong: '%s'\n", value.data);
- FREE(&value.data);
- return false;
- }
- TEST_MSG("Apple = %d\n", VarApple);
- TEST_MSG("Apple's initial value is %s\n", value.data);
-
- mutt_buffer_reset(&value);
- rc = cs_str_initial_get(cs, "Banana", &value);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", value.data);
- FREE(&value.data);
- return false;
- }
-
- if (!TEST_CHECK(mutt_str_strcmp(value.data, "MH") == 0))
- {
- TEST_MSG("Banana's initial value is wrong: %s\n", value.data);
- FREE(&value.data);
- return false;
- }
- TEST_MSG("Banana = %d\n", VarBanana);
- TEST_MSG("Banana's initial value is %s\n", NONULL(value.data));
-
- mutt_buffer_reset(&value);
- rc = cs_str_initial_set(cs, "Cherry", "mmdf", &value);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", value.data);
- FREE(&value.data);
- return false;
- }
-
- mutt_buffer_reset(&value);
- rc = cs_str_initial_get(cs, "Cherry", &value);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", value.data);
- FREE(&value.data);
- return false;
- }
-
- TEST_MSG("Cherry = %s\n", MagicValues[VarCherry]);
- TEST_MSG("Cherry's initial value is %s\n", value.data);
-
- FREE(&value.data);
- log_line(__func__);
- 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 };
- const 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 (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
-
- if (!TEST_CHECK(VarDamson != (((i + 1) % 4) + 1)))
- {
- TEST_MSG("Value of %s wasn't changed\n", name);
- return false;
- }
- TEST_MSG("%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)
- {
- TEST_MSG("Value of %s wasn't changed\n", name);
- }
- else
- {
- TEST_MSG("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 (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS))
- {
- TEST_MSG("Expected error: %s\n", err->data);
- }
- else
- {
- TEST_MSG("%s = %d, set by '%s'\n", name, VarDamson, invalid[i]);
- TEST_MSG("This test should have failed\n");
- return false;
- }
- }
-
- log_line(__func__);
- 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 (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("Get failed: %s\n", err->data);
- return false;
- }
- TEST_MSG("%s = %d, %s\n", name, VarElderberry, err->data);
- }
-
- VarElderberry = 5;
- mutt_buffer_reset(err);
- TEST_MSG("Expect error for next test\n");
- rc = cs_str_string_get(cs, name, err);
- if (!TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
-
- log_line(__func__);
- return true;
-}
-
-static bool test_native_set(struct ConfigSet *cs, struct Buffer *err)
-{
- log_line(__func__);
- const 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 (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
-
- if (!TEST_CHECK(VarFig == value))
- {
- TEST_MSG("Value of %s wasn't changed\n", name);
- return false;
- }
-
- TEST_MSG("%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)
- {
- TEST_MSG("Value of %s wasn't changed\n", name);
- }
- else
- {
- TEST_MSG("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 (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS))
- {
- TEST_MSG("Expected error: %s\n", err->data);
- }
- else
- {
- TEST_MSG("%s = %d, set by '%d'\n", name, VarFig, invalid[i]);
- TEST_MSG("This test should have failed\n");
- return false;
- }
- }
-
- log_line(__func__);
- return true;
-}
-
-static bool test_native_get(struct ConfigSet *cs, struct Buffer *err)
-{
- log_line(__func__);
- const char *name = "Guava";
-
- VarGuava = MUTT_MAILDIR;
- mutt_buffer_reset(err);
- intptr_t value = cs_str_native_get(cs, name, err);
- if (!TEST_CHECK(value != INT_MIN))
- {
- TEST_MSG("Get failed: %s\n", err->data);
- return false;
- }
- TEST_MSG("%s = %ld\n", name, value);
-
- log_line(__func__);
- return true;
-}
-
-static bool test_reset(struct ConfigSet *cs, struct Buffer *err)
-{
- log_line(__func__);
-
- const char *name = "Hawthorn";
- VarHawthorn = MUTT_MAILDIR;
- mutt_buffer_reset(err);
-
- int rc = cs_str_reset(cs, name, err);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
-
- if (!TEST_CHECK(VarHawthorn != MUTT_MAILDIR))
- {
- TEST_MSG("Value of %s wasn't changed\n", name);
- return false;
- }
-
- TEST_MSG("Reset: %s = %d\n", name, VarHawthorn);
-
- mutt_buffer_reset(err);
- rc = cs_str_reset(cs, name, err);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
-
- name = "Ilama";
- mutt_buffer_reset(err);
-
- TEST_MSG("Initial: %s = %d\n", name, VarIlama);
- dont_fail = true;
- rc = cs_str_string_set(cs, name, "maildir", err);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- return false;
- TEST_MSG("Set: %s = %d\n", name, VarIlama);
- dont_fail = false;
-
- rc = cs_str_reset(cs, name, err);
- if (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS))
- {
- TEST_MSG("Expected error: %s\n", err->data);
- }
- else
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
-
- if (!TEST_CHECK(VarIlama == MUTT_MAILDIR))
- {
- TEST_MSG("Value of %s changed\n", name);
- return false;
- }
-
- TEST_MSG("Reset: %s = %d\n", name, VarIlama);
-
- log_line(__func__);
- return true;
-}
-
-static bool test_validator(struct ConfigSet *cs, struct Buffer *err)
-{
- log_line(__func__);
-
- const char *name = "Jackfruit";
- VarJackfruit = MUTT_MBOX;
- mutt_buffer_reset(err);
- int rc = cs_str_string_set(cs, name, "maildir", err);
- if (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- }
- else
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
- TEST_MSG("String: %s = %d\n", name, VarJackfruit);
-
- VarJackfruit = MUTT_MBOX;
- mutt_buffer_reset(err);
- rc = cs_str_native_set(cs, name, MUTT_MAILDIR, err);
- if (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- }
- else
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
- TEST_MSG("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 (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- }
- else
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
- TEST_MSG("String: %s = %d\n", name, VarKumquat);
-
- VarKumquat = MUTT_MBOX;
- mutt_buffer_reset(err);
- rc = cs_str_native_set(cs, name, MUTT_MAILDIR, err);
- if (TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("%s\n", err->data);
- }
- else
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
- TEST_MSG("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 (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS))
- {
- TEST_MSG("Expected error: %s\n", err->data);
- }
- else
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
- TEST_MSG("String: %s = %d\n", name, VarLemon);
-
- VarLemon = MUTT_MBOX;
- mutt_buffer_reset(err);
- rc = cs_str_native_set(cs, name, MUTT_MAILDIR, err);
- if (TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS))
- {
- TEST_MSG("Expected error: %s\n", err->data);
- }
- else
- {
- TEST_MSG("%s\n", err->data);
- return false;
- }
- TEST_MSG("Native: %s = %d\n", name, VarLemon);
-
- log_line(__func__);
- 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);
-
- TEST_MSG("%15s = %ld\n", parent, pval);
- TEST_MSG("%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 *a = account_new();
- account_add_config(a, cs, account, AccountVarStr);
-
- // set parent
- mutt_buffer_reset(err);
- int rc = cs_str_string_set(cs, parent, "maildir", err);
- if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("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 (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("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 (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("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 (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS))
- {
- TEST_MSG("Error: %s\n", err->data);
- goto ti_out;
- }
- dump_native(cs, parent, child);
-
- log_line(__func__);
- result = true;
-ti_out:
- account_free(&a);
- return result;
-}
-
-void config_magic(void)
-{
- struct Buffer err;
- mutt_buffer_init(&err);
- err.dsize = 256;
- err.data = mutt_mem_calloc(1, err.dsize);
- mutt_buffer_reset(&err);
-
- struct ConfigSet *cs = cs_new(30);
-
- magic_init(cs);
- dont_fail = true;
- if (!cs_register_variables(cs, Vars, 0))
- return;
- dont_fail = false;
-
- notify_observer_add(cs->notify, NT_CONFIG, 0, log_observer, 0);
-
- set_list(cs);
-
- TEST_CHECK(test_initial_values(cs, &err));
- TEST_CHECK(test_string_set(cs, &err));
- TEST_CHECK(test_string_get(cs, &err));
- TEST_CHECK(test_native_set(cs, &err));
- TEST_CHECK(test_native_get(cs, &err));
- TEST_CHECK(test_reset(cs, &err));
- TEST_CHECK(test_validator(cs, &err));
- TEST_CHECK(test_inherit(cs, &err));
-
- cs_free(&cs);
- FREE(&err.data);
-}