1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-01 19:24:15 -04:00
profanity/tests/unittests/test_muc.c
ike08 d35a7a7f7e Refactor tests to use the new cmocka test runner
## Summary

Fixes https://github.com/profanity-im/profanity/issues/1907  

Update functional and unit test code to comply with the current cmocka test runner.  

## Changes

- `UnitTest` struct to `CMUnitTest` struct
- `unit_test()` macro to `cmocka_unit_test(f)` macro
- `unit_test_setup_teardown()` macro to `cmocka_unit_test_setup_teardown` macro
- `run_tests()` macro to `cmocka_run_group_tests()` function
- Setup and teardown functions return `int` instead of `void`

## Testing

### Unit Tests

`make check`

### Functional Tests

I did not compile or run functional tests because they are *shelved* for now.

### Valgrind

I'm not entirely sure how to fun Valgrind in this case. I did not do fancy memory management, so it should be fine.
2023-11-01 18:30:08 -06:00

89 lines
1.6 KiB
C

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include "xmpp/muc.h"
int
muc_before_test(void** state)
{
muc_init();
return 0;
}
int
muc_after_test(void** state)
{
muc_close();
return 0;
}
void
test_muc_invites_add(void** state)
{
char* room = "room@conf.server";
muc_invites_add(room, NULL);
gboolean invite_exists = muc_invites_contain(room);
assert_true(invite_exists);
}
void
test_muc_remove_invite(void** state)
{
char* room = "room@conf.server";
muc_invites_add(room, NULL);
muc_invites_remove(room);
gboolean invite_exists = muc_invites_contain(room);
assert_false(invite_exists);
}
void
test_muc_invites_count_0(void** state)
{
int invite_count = muc_invites_count();
assert_true(invite_count == 0);
}
void
test_muc_invites_count_5(void** state)
{
muc_invites_add("room1@conf.server", NULL);
muc_invites_add("room2@conf.server", NULL);
muc_invites_add("room3@conf.server", NULL);
muc_invites_add("room4@conf.server", NULL);
muc_invites_add("room5@conf.server", NULL);
int invite_count = muc_invites_count();
assert_true(invite_count == 5);
}
void
test_muc_room_is_not_active(void** state)
{
char* room = "room@server.org";
gboolean room_is_active = muc_active(room);
assert_false(room_is_active);
}
void
test_muc_active(void** state)
{
char* room = "room@server.org";
char* nick = "bob";
muc_join(room, nick, NULL, FALSE);
gboolean room_is_active = muc_active(room);
assert_true(room_is_active);
}