mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Prohibit setting budget values greater than num_periods
* Add unit test to verify changes * gnc_budget_set_account_period_value returns without doing anything if requested period value is greater than num_periods * Add warning message when setting invalid period Author: R Ratliff <ratliff.bobby@gmail.com> git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23335 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
1c20648c42
commit
5f9a9489ed
@ -507,6 +507,11 @@ gnc_budget_set_account_period_value(GncBudget *budget, const Account *account,
|
|||||||
gchar path[BUF_SIZE];
|
gchar path[BUF_SIZE];
|
||||||
gchar *bufend;
|
gchar *bufend;
|
||||||
|
|
||||||
|
if (period_num >= GET_PRIVATE(budget)->num_periods) {
|
||||||
|
PWARN("Period %i does not exist", period_num);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
gnc_budget_begin_edit(budget);
|
gnc_budget_begin_edit(budget);
|
||||||
frame = qof_instance_get_slots(QOF_INSTANCE(budget));
|
frame = qof_instance_get_slots(QOF_INSTANCE(budget));
|
||||||
guid = xaccAccountGetGUID(account);
|
guid = xaccAccountGetGUID(account);
|
||||||
|
@ -2545,6 +2545,42 @@ test_gnc_set_budget_recurrence()
|
|||||||
gnc_budget_destroy(budget);
|
gnc_budget_destroy(budget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_gnc_set_budget_account_period_value()
|
||||||
|
{
|
||||||
|
QofBook *book = qof_book_new();
|
||||||
|
GncBudget* budget = gnc_budget_new(book);
|
||||||
|
Account *acc;
|
||||||
|
gnc_numeric val;
|
||||||
|
|
||||||
|
guint log_level = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL;
|
||||||
|
gchar *log_domain = "gnc.engine";
|
||||||
|
gchar *msg = "[gnc_budget_set_account_period_value()] Period 12 does not exist";
|
||||||
|
guint hdlr;
|
||||||
|
TestErrorStruct check = { log_level, log_domain, msg, 0 };
|
||||||
|
GLogFunc oldlogger;
|
||||||
|
|
||||||
|
acc = gnc_account_create_root(book);
|
||||||
|
|
||||||
|
g_assert(!gnc_budget_is_account_period_value_set(budget, acc, 0));
|
||||||
|
gnc_budget_set_account_period_value(budget, acc, 0, gnc_numeric_create(100,1));
|
||||||
|
g_assert(gnc_budget_is_account_period_value_set(budget, acc, 0));
|
||||||
|
val = gnc_budget_get_account_period_value(budget, acc, 0);
|
||||||
|
g_assert (gnc_numeric_equal (val, gnc_numeric_create (100, 1)));
|
||||||
|
|
||||||
|
/* Budget has 12 periods by default, numbered from 0 to 11. Setting
|
||||||
|
* period 12 should throw an error. */
|
||||||
|
oldlogger = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);
|
||||||
|
g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_checked_handler, &check);
|
||||||
|
gnc_budget_set_account_period_value(budget, acc, 12, gnc_numeric_create(100,1));
|
||||||
|
g_assert_cmpint (check.hits, ==, 1);
|
||||||
|
g_log_set_default_handler (oldlogger, NULL);
|
||||||
|
|
||||||
|
g_object_unref(book);
|
||||||
|
g_object_unref(acc);
|
||||||
|
gnc_budget_destroy(budget);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_suite_budget(void)
|
test_suite_budget(void)
|
||||||
{
|
{
|
||||||
@ -2553,6 +2589,7 @@ test_suite_budget(void)
|
|||||||
GNC_TEST_ADD_FUNC(suitename, "gnc_budget_set_description()", test_gnc_set_budget_description);
|
GNC_TEST_ADD_FUNC(suitename, "gnc_budget_set_description()", test_gnc_set_budget_description);
|
||||||
GNC_TEST_ADD_FUNC(suitename, "gnc_budget_set_num_periods()", test_gnc_set_budget_num_periods);
|
GNC_TEST_ADD_FUNC(suitename, "gnc_budget_set_num_periods()", test_gnc_set_budget_num_periods);
|
||||||
GNC_TEST_ADD_FUNC(suitename, "gnc_budget_set_recurrence()", test_gnc_set_budget_recurrence);
|
GNC_TEST_ADD_FUNC(suitename, "gnc_budget_set_recurrence()", test_gnc_set_budget_recurrence);
|
||||||
|
GNC_TEST_ADD_FUNC(suitename, "gnc_budget_set_account_period_value()", test_gnc_set_budget_account_period_value);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
GNC_TEST_ADD_FUNC (suitename, "gnc set account separator", test_gnc_set_account_separator);
|
GNC_TEST_ADD_FUNC (suitename, "gnc set account separator", test_gnc_set_account_separator);
|
||||||
|
Loading…
Reference in New Issue
Block a user