#include <assert.h>
#include <string.h>

#include <glib.h>

#include int main (int argc, char * argv[])
{
    char s1[] = "abcd";
    char s2[] = "\xE2\x82\xAC";
    char s3[] = "a\xE2\x82\xAC";
    char s4[] = "\xE2\x82\xACz";

    char dest[64];
    int ret;

    ret = g_utf8_strlcpy(dest, "", 64);
    assert(ret == 0);
    assert(strlen(dest) == 0);

    ret = g_utf8_strlcpy(dest, "abcd", 64);
    assert(ret == 4);
    assert(strlen(dest) == 4);

    ret = g_utf8_strlcpy(dest, "abcd", 2);
    assert(ret == 4);
    assert(strlen(dest) == 1);


    ret = g_utf8_strlcpy(dest, "\xE2\x82\xAC", 64);
    assert(ret == 3);
    assert(strlen(dest) == 3);

    ret = g_utf8_strlcpy(dest, "\xE2\x82\xAC", 2);
    assert(ret == 3);
    assert(strlen(dest) == 0);


    ret = g_utf8_strlcpy(dest, "a\xE2\x82\xAC", 64);
    assert(ret == 4);
    assert(strlen(dest) == 4);

    ret = g_utf8_strlcpy(dest, "a\xE2\x82\xAC", 1);
    assert(ret == 4);
    assert(strlen(dest) == 0);

    ret = g_utf8_strlcpy(dest, "a\xE2\x82\xAC", 2);
    assert(ret == 4);
    assert(strlen(dest) == 1);

    ret = g_utf8_strlcpy(dest, "a\xE2\x82\xAC", 4);
    assert(ret == 4);
    assert(strlen(dest) == 1);


    ret = g_utf8_strlcpy(dest, "\xE2\x82\xACz", 64);
    assert(ret == 4);
    assert(strlen(dest) == 4);

    ret = g_utf8_strlcpy(dest, "\xE2\x82\xACz", 4);
    assert(ret == 4);
    assert(strlen(dest) == 3);

    ret = g_utf8_strlcpy(dest, "\xE2\x82\xACz", 4);
    assert(ret == 4);
    assert(strlen(dest) == 3);
}
