Skip to content

Add unit tests for ENetPacket creation, copy, and resize behavior #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ikpil
Copy link
Contributor

@ikpil ikpil commented Jun 8, 2025

This PR introduces a set of focused unit tests that strengthen the coverage of ENetPacket behavior, specifically around its lifecycle (creation, copy, and resize). The goal is to ensure correctness and stability for fundamental packet operations.

Comment on lines +69 to +85
// // Test inserting the same node multiple times
// {
// enet_list_clear(&list);
//
// // First insert
// enet_list_insert(enet_list_end(&list), &node0);
// ASSERT_EQ(enet_list_size(&list), 1);
//
// // Try to insert the same node again
// enet_list_insert(enet_list_end(&list), &node0);
// ASSERT_EQ(enet_list_size(&list), 1); // Size should not change
//
// // Verify list integrity
// ENetListIterator current = enet_list_begin(&list);
// ENetListIterator next = enet_list_next(current);
// ASSERT_EQ(next, enet_list_end(&list)); // Should be the only node
// }

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.
Comment on lines +87 to +102
// // Test inserting the same node in different lists
// {
// ENetList list1, list2;
// enet_list_clear(&list1);
// enet_list_clear(&list2);
//
// // Insert into first list
// enet_list_insert(enet_list_end(&list1), &node0);
// ASSERT_EQ(enet_list_size(&list1), 1);
// ASSERT_EQ(enet_list_size(&list2), 0);
//
// // Try to insert into second list
// enet_list_insert(enet_list_end(&list2), &node0);
// ASSERT_EQ(enet_list_size(&list1), 0); // Should be removed from first list
// ASSERT_EQ(enet_list_size(&list2), 1); // Should be in second list
// }

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.
Comment on lines +216 to +224
// // Verify node order in list2
// int expected_values2[] = {5, 9};
// i = 0;
// for (ENetListNode *current = enet_list_begin(&list2);
// current != enet_list_end(&list2);
// current = enet_list_next(current)) {
// TestNode *node = (TestNode *) current;
// ASSERT_EQ(node->value, expected_values2[i++]);
// }

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.
Comment on lines +226 to +244
// // Test 2: Move node to beginning of list
// enet_list_move(enet_list_begin(&list1), &nodes[8].node);
// ASSERT_EQ(enet_list_size(&list1), 5);
// ASSERT_EQ(enet_list_size(&list2), 5);
//
// // Test 3: Move node to middle of list
// enet_list_move(enet_list_next(enet_list_begin(&list1)), &nodes[5].node);
// ASSERT_EQ(enet_list_size(&list1), 6);
// ASSERT_EQ(enet_list_size(&list2), 4);
//
// // Test 4: Move multiple nodes at once
// enet_list_move(enet_list_end(&list2), &nodes[0].node, &nodes[3].node);
// ASSERT_EQ(enet_list_size(&list1), 3);
// ASSERT_EQ(enet_list_size(&list2), 7);
//
// // Test 5: Move node to its current position (should not change anything)
// enet_list_move(enet_list_next(enet_list_begin(&list1)), &nodes[8].node);
// ASSERT_EQ(enet_list_size(&list1), 3);
// ASSERT_EQ(enet_list_size(&list2), 7);

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.
}

TEST(enet_list_empty) {
ENetList list;

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable list is not used.
TEST(enet_packet_copy) {
int userData = 1;
ENetPacket *p1 = enet_packet_create("bar", strlen("bar"), ENET_PACKET_FLAG_RELIABLE);
p1->userData = &userData;

Check warning

Code scanning / CodeQL

Local variable address stored in non-local memory Warning test

A stack address (
source
) may be assigned to a non-local variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant