1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
* Copyright (c) 2002-2018 Balabit
* Copyright (c) 2013 Viktor Juhasz
* Copyright (c) 2013 Viktor Tusa
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#include <criterion/criterion.h>
#include "libtest/persist_lib.h"
#include "apphook.h"
#include "rcptid.h"
#include <unistd.h>
static PersistState *
setup_persist_id_test(const gchar *persist_file)
{
PersistState *state;
state = clean_and_create_persist_state_for_test(persist_file);
rcptid_init(state, TRUE);
return state;
}
static void
teardown_persist_id_test(PersistState *state)
{
commit_and_destroy_persist_state(state);
rcptid_deinit();
}
static void
setup(void)
{
app_startup();
}
static void
teardown(void)
{
app_shutdown();
}
TestSuite(rcptid, .init = setup, .fini = teardown);
Test(rcptid, test_rcptid_is_persistent_across_persist_backend_reinits)
{
guint64 rcptid;
PersistState *state = setup_persist_id_test("test_values.backend_reinits");
rcptid_set_id(0xFFFFFFFFFFFFFFFE);
rcptid = rcptid_generate_id();
cr_assert_eq(rcptid, 0xFFFFFFFFFFFFFFFE, "Rcptid initialization to specific value failed!");
state = restart_persist_state(state);
rcptid_deinit();
rcptid_init(state, TRUE);
rcptid = rcptid_generate_id();
cr_assert_eq(rcptid, 0xFFFFFFFFFFFFFFFF, "Rcptid did not persisted across persist backend reinit!");
teardown_persist_id_test(state);
}
Test(rcptid, test_rcptid_overflows_at_64bits_and_is_reset_to_one)
{
guint64 rcptid;
PersistState *state = setup_persist_id_test("test_values.reset_to_one");
rcptid_set_id(0xFFFFFFFFFFFFFFFF);
rcptid = rcptid_generate_id();
rcptid = rcptid_generate_id();
cr_assert_eq(rcptid, (guint64) 1, "Rcptid counter overflow handling did not work!");
teardown_persist_id_test(state);
}
Test(rcptid, test_rcptid_is_formatted_as_a_number_when_nonzero)
{
PersistState *state = setup_persist_id_test("test_values.nonzero");
GString *formatted_rcptid = g_string_sized_new(0);
rcptid_append_formatted_id(formatted_rcptid, 1);
cr_assert_str_eq(formatted_rcptid->str, "1", "RCPTID macro formatting for non-zero number failed!");
g_string_free(formatted_rcptid, TRUE);
teardown_persist_id_test(state);
}
Test(rcptid, test_rcptid_is_an_empty_string_when_zero)
{
PersistState *state = setup_persist_id_test("test_values.zero");
GString *formatted_rcptid = g_string_sized_new(0);
rcptid_append_formatted_id(formatted_rcptid, 0);
cr_assert_str_eq(formatted_rcptid->str, "", "RCPTID macro formatting for zero value failed!");
g_string_free(formatted_rcptid, TRUE);
teardown_persist_id_test(state);
}
|