Skip to content

Commit

Permalink
added tests for strncpy
Browse files Browse the repository at this point in the history
  • Loading branch information
itzandroidtab committed Jun 16, 2024
1 parent 888f067 commit a92a64f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions klib/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ TEST_CASE("klib strcpy", "[klib::string]") {
REQUIRE(std::string(buffer) == "hello world");
}

TEST_CASE("klib strncpy", "[klib::string]") {
char buffer[32];
klib::string::strncpy(buffer, "", sizeof(buffer));
REQUIRE(std::string(buffer) == "");

klib::string::strncpy(buffer, "hello world", sizeof(buffer));
REQUIRE(std::string(buffer) == "hello world");

std::fill_n(buffer, sizeof(buffer), 0x00);
klib::string::strncpy(buffer, "hello world", 0);
REQUIRE(std::string(buffer) == "");

buffer[0] = 'a';
buffer[1] = 'b';
buffer[2] = 'c';

klib::string::strncpy(buffer, "hello world", 0);
REQUIRE(buffer[0] == 'a');
REQUIRE(buffer[1] == 'b');
REQUIRE(buffer[2] == 'c');
}

TEST_CASE("klib strcat", "[klib::string]") {
char buffer[32] = "hello";
klib::string::strcat(buffer, "");
Expand Down

0 comments on commit a92a64f

Please sign in to comment.