forked from github/server
03c247c788
Lots of files are moving to a new location in src/ Some intersting CMake changes.
68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
#include <CuTest.h>
|
|
#include "bsdstring.h"
|
|
#include <string.h>
|
|
|
|
static void test_strlcat(CuTest * tc)
|
|
{
|
|
char buffer[32];
|
|
|
|
memset(buffer, -2, sizeof(buffer));
|
|
|
|
buffer[0] = '\0';
|
|
CuAssertIntEquals(tc, 4, strlcat(buffer, "herp", 4));
|
|
CuAssertStrEquals(tc, "her", buffer);
|
|
|
|
buffer[0] = '\0';
|
|
CuAssertIntEquals(tc, 4, strlcat(buffer, "herp", 8));
|
|
CuAssertStrEquals(tc, "herp", buffer);
|
|
CuAssertIntEquals(tc, (char)-2, buffer[5]);
|
|
|
|
CuAssertIntEquals(tc, 8, strlcat(buffer, "derp", 8));
|
|
CuAssertStrEquals(tc, "herpder", buffer);
|
|
CuAssertIntEquals(tc, (char)-2, buffer[8]);
|
|
}
|
|
|
|
static void test_strlcpy(CuTest * tc)
|
|
{
|
|
char buffer[32];
|
|
|
|
memset(buffer, -2, sizeof(buffer));
|
|
|
|
CuAssertIntEquals(tc, 4, strlcpy(buffer, "herp", 4));
|
|
CuAssertStrEquals(tc, "her", buffer);
|
|
|
|
CuAssertIntEquals(tc, 4, strlcpy(buffer, "herp", 8));
|
|
CuAssertStrEquals(tc, "herp", buffer);
|
|
CuAssertIntEquals(tc, (char)-2, buffer[5]);
|
|
|
|
CuAssertIntEquals(tc, 8, strlcpy(buffer, "herpderp", 8));
|
|
CuAssertStrEquals(tc, "herpder", buffer);
|
|
CuAssertIntEquals(tc, (char)-2, buffer[8]);
|
|
}
|
|
|
|
static void test_slprintf(CuTest * tc)
|
|
{
|
|
char buffer[32];
|
|
|
|
memset(buffer, -2, sizeof(buffer));
|
|
|
|
CuAssertTrue(tc, slprintf(buffer, 4, "%s", "herpderp")>3);
|
|
CuAssertStrEquals(tc, "her", buffer);
|
|
|
|
CuAssertIntEquals(tc, 4, slprintf(buffer, 8, "%s", "herp"));
|
|
CuAssertStrEquals(tc, "herp", buffer);
|
|
CuAssertIntEquals(tc, (char)-2, buffer[5]);
|
|
|
|
CuAssertIntEquals(tc, 8, slprintf(buffer, 8, "%s", "herpderp"));
|
|
CuAssertStrEquals(tc, "herpder", buffer);
|
|
CuAssertIntEquals(tc, (char)-2, buffer[8]);
|
|
}
|
|
|
|
CuSuite *get_bsdstring_suite(void)
|
|
{
|
|
CuSuite *suite = CuSuiteNew();
|
|
SUITE_ADD_TEST(suite, test_strlcat);
|
|
SUITE_ADD_TEST(suite, test_strlcpy);
|
|
SUITE_ADD_TEST(suite, test_slprintf);
|
|
return suite;
|
|
}
|