Skip to content

Commit

Permalink
Fix test to reflect new userlist API
Browse files Browse the repository at this point in the history
  • Loading branch information
z-dule committed Nov 5, 2024
1 parent 571aff6 commit 927c5bc
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions test/test_userlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,22 +351,23 @@ TEST_F(UserlistTest, add_from_sftlist)
uint8_t secret1[32] = "secret1 ";
char *userid_hash = NULL;
bool changed = false;
bool self_changed = false;
bool missing = false;

ASSERT_EQ(userlist_get_count(list), 0);

InitSftList(&sftlist1, 0, 1, secret1, sizeof(secret1));
InitSftList(&sftlist3, 0, 3, secret1, sizeof(secret1));

userlist_update_from_sftlist(list, &sftlist1, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist1, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 1);

hash_user(secret1, sizeof(secret1), "user_00000", "client_00000", &userid_hash);
const struct userinfo *u = userlist_find_by_hash(list, userid_hash, "_");
ASSERT_TRUE(u != NULL);
ASSERT_TRUE(strcmp(u->userid_hash, userid_hash) == 0);

userlist_update_from_sftlist(list, &sftlist3, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist3, &changed, &self_changed, &missing);

ASSERT_EQ(userlist_get_count(list), 3);

Expand All @@ -379,6 +380,7 @@ TEST_F(UserlistTest, merge_sftlist_into_selist)
char *userid_hash = NULL;
const struct userinfo *u;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -394,7 +396,7 @@ TEST_F(UserlistTest, merge_sftlist_into_selist)
ASSERT_EQ(userlist_get_count(list), 3);

/* sftlist: [user_00000] */
userlist_update_from_sftlist(list, &sftlist1, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist1, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

u = userlist_find_by_real(list, "user_00000", "client_00000");
Expand Down Expand Up @@ -423,7 +425,7 @@ TEST_F(UserlistTest, merge_sftlist_into_selist)
users_synced = false;

/* sftlist: [user_00000,user_00001,user_00002] */
userlist_update_from_sftlist(list, &sftlist3, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist3, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

u = userlist_find_by_real(list, "user_00001", "client_00001");
Expand All @@ -450,6 +452,7 @@ TEST_F(UserlistTest, merge_selist_into_sftlist)
char *userid_hash = NULL;
const struct userinfo *u;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -460,7 +463,7 @@ TEST_F(UserlistTest, merge_selist_into_sftlist)
ASSERT_EQ(userlist_get_count(list), 0);

/* sftlist: [user_00000] */
userlist_update_from_sftlist(list, &sftlist1, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist1, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 1);

ASSERT_TRUE(!users[0].added);
Expand Down Expand Up @@ -514,6 +517,7 @@ TEST_F(UserlistTest, kg_change)
uint8_t secret1[32] = "secret1 ";
const struct userinfo *u;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -529,7 +533,7 @@ TEST_F(UserlistTest, kg_change)
ASSERT_EQ(userlist_get_count(list), 3);

/* sftlist: [user_00000] */
userlist_update_from_sftlist(list, &sftlist1, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist1, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

/* incall: [user_00000] kg: user_00000 */
Expand All @@ -541,7 +545,7 @@ TEST_F(UserlistTest, kg_change)
users_synced = false;

/* sftlist: [user_00000,user_00001,user_00002] */
userlist_update_from_sftlist(list, &sftlist3, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist3, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

/* incall: [user_00000,user_00001,user_00002] kg: user_00000 */
Expand All @@ -555,7 +559,7 @@ TEST_F(UserlistTest, kg_change)
users_synced = false;

/* sftlist: [user_0001,user_0002] */
userlist_update_from_sftlist(list, &sftlist2, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist2, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

/* incall: [user_00001,user_00002] kg: user_00001 */
Expand Down Expand Up @@ -657,6 +661,7 @@ TEST_F(UserlistTest, keysync_breakout)
uint8_t secret1[32] = "secret1 ";
const struct userinfo *u;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -667,7 +672,7 @@ TEST_F(UserlistTest, keysync_breakout)

SetInSubconv(&selist3, 1);
userlist_update_from_selist(list, &selist3, 1, secret1, sizeof(secret1), &changed, &removed);
userlist_update_from_sftlist(list, &sftlist3, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist3, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

userlist_set_latest_epoch(list, 1);
Expand Down Expand Up @@ -699,6 +704,7 @@ TEST_F(UserlistTest, keysync_newclient)
uint8_t secret1[32] = "secret1 ";
const struct userinfo *u;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -709,7 +715,7 @@ TEST_F(UserlistTest, keysync_newclient)

SetInSubconv(&selist1, 1);
userlist_update_from_selist(list, &selist1, 1, secret1, sizeof(secret1), &changed, &removed);
userlist_update_from_sftlist(list, &sftlist3, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist3, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

userlist_set_latest_epoch(list, 5);
Expand All @@ -731,6 +737,7 @@ TEST_F(UserlistTest, keysync_sftlist)
uint8_t secret1[32] = "secret1 ";
const struct userinfo *u;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -750,7 +757,7 @@ TEST_F(UserlistTest, keysync_sftlist)
userlist_set_latest_epoch_for_client(list, "user_00001", "client_00001", 3);
userlist_set_latest_epoch_for_client(list, "user_00002", "client_00002", 2);

userlist_update_from_sftlist(list, &sftlist1, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist1, &changed, &self_changed, &missing);

/* key = 1 (self) */
ASSERT_EQ(1, userlist_get_key_index(list));
Expand All @@ -759,11 +766,11 @@ TEST_F(UserlistTest, keysync_sftlist)
/* key = 4 (user_00000) */
ASSERT_EQ(4, userlist_get_key_index(list));

userlist_update_from_sftlist(list, &sftlist3, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist3, &changed, &self_changed, &missing);
/* key = 2 (user_00002) */
ASSERT_EQ(2, userlist_get_key_index(list));

userlist_update_from_sftlist(list, &sftlist2, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist2, &changed, &self_changed, &missing);
/* key = 3 (user_00001) */
ASSERT_EQ(3, userlist_get_key_index(list));

Expand All @@ -779,6 +786,7 @@ TEST_F(UserlistTest, get_members)
const struct userinfo *u;
struct wcall_members *members = NULL;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -791,7 +799,7 @@ TEST_F(UserlistTest, get_members)
userlist_update_from_selist(list, &selist2, 1, secret1, sizeof(secret1), &changed, &removed);
ASSERT_EQ(userlist_get_count(list), 2);

userlist_update_from_sftlist(list, &sftlist2, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist2, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

ASSERT_EQ(0, userlist_get_members(list,
Expand Down Expand Up @@ -828,6 +836,7 @@ TEST_F(UserlistTest, get_members_mute_state)
struct list levell = LIST_INIT;
struct wcall_members *members = NULL;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -841,7 +850,7 @@ TEST_F(UserlistTest, get_members_mute_state)
ASSERT_EQ(userlist_get_count(list), 3);

SetMuted(&sftlist3, 2);
userlist_update_from_sftlist(list, &sftlist3, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist3, &changed, &self_changed, &missing);

InitAudioLevelList(&levell, 0, 3, 1);
userlist_update_audio_level(list, &levell, &changed);
Expand Down Expand Up @@ -882,6 +891,7 @@ TEST_F(UserlistTest, get_partlist)
struct econn_group_part *p = NULL;
char *userid_hash = NULL;
bool changed = false;
bool self_changed = false;
bool missing = false;
bool removed = false;

Expand All @@ -895,7 +905,7 @@ TEST_F(UserlistTest, get_partlist)
userlist_update_from_selist(list, &selist2, 1, secret1, sizeof(secret1), &changed, &removed);
ASSERT_EQ(userlist_get_count(list), 2);

userlist_update_from_sftlist(list, &sftlist2, &changed, &missing);
userlist_update_from_sftlist(list, &sftlist2, &changed, &self_changed, &missing);
ASSERT_EQ(userlist_get_count(list), 3);

ASSERT_EQ(0, userlist_get_partlist(list, &partlist, false));
Expand Down

0 comments on commit 927c5bc

Please sign in to comment.