libei/test/test-eis.c
Peter Hutterer 8cdbcda7a7 test: add EIS integration tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-12 14:42:09 +10:00

97 lines
2.8 KiB
C

/*
* Copyright © 2020 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include <munit.h>
#include "eierpecken.h"
static MunitResult
eistest_ref_unref(const MunitParameter params[], void *user_data)
{
struct eis *eis = eis_new(NULL);
struct eis *refd = eis_ref(eis);
munit_assert_ptr_equal(eis, refd);
struct eis *unrefd = eis_unref(eis);
munit_assert_ptr_null(unrefd);
unrefd = eis_unref(eis);
munit_assert_ptr_null(unrefd);
/* memleak only shows up in valgrind */
return MUNIT_OK;
}
static MunitResult
eistest_name(const MunitParameter params[], void *user_data)
{
_cleanup_peck_ struct peck *peck = peck_new();
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_NONE);
peck_enable_ei_behavior(peck, PECK_EI_BEHAVIOR_NONE);
/* The name is set by peck_new() and immutable after the
* backend was set, which peck_new() does for us as well.
* So the name we should see is the one hardcoded in peck_new()
*/
with_client(peck) {
ei_configure_name(ei, "this name should not be used");
}
peck_dispatch_ei(peck);
peck_dispatch_eis(peck);
with_server(peck) {
_cleanup_eis_event_ struct eis_event *event = eis_get_event(eis);
munit_assert_ptr_not_null(event);
munit_assert_int(eis_event_get_type(event), ==, EIS_EVENT_CLIENT_CONNECT);
struct eis_client *client = eis_event_get_client(event);
munit_assert_string_equal(eis_client_get_name(client), "eierpecken test context");
}
return MUNIT_OK;
}
static MunitTest eis_tests[] = {
{ .name = "/ref", .test = eistest_ref_unref },
{ .name = "/name", .test = eistest_name },
};
static const MunitSuite eis_suite = {
"/eis",
eis_tests,
NULL,
1,
MUNIT_SUITE_OPTION_NONE,
};
int
main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)])
{
return munit_suite_main(&eis_suite, NULL, argc, argv);
}