string.c

00001 #include <string.h>
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 #include <sys/stat.h>
00005 #include <sys/time.h>
00006 #include <sys/types.h>
00007 #include <fcntl.h>
00008 #include <signal.h>
00009 #include <u/libu.h>
00010 
00011 int test_suite_string_register (u_test_t *t);
00012 
00013 static int test_u_str (u_test_case_t *tc);
00014 
00015 static int test_u_str (u_test_case_t *tc)
00016 {
00017     u_string_t *s = NULL;
00018 
00019     u_test_err_if (u_string_create("0", 1, &s));
00020 
00021     u_test_err_if (strcmp(u_string_c(s), "0"));
00022 
00023     u_test_err_if (u_string_sprintf(s, "%s", "1"));
00024     u_test_err_if (strcmp(u_string_c(s), "1"));
00025 
00026     u_test_err_if (u_string_aprintf(s, "%s", "23"));
00027     u_test_err_if (strcmp(u_string_c(s), "123"));
00028 
00029     u_test_err_if (u_string_cat(s, "45"));
00030     u_test_err_if (strcmp(u_string_c(s), "12345"));
00031 
00032     u_test_err_if (u_string_ncat(s, "6777", 2));
00033     u_test_err_if (strcmp(u_string_c(s), "1234567"));
00034 
00035     u_test_err_if (u_string_sprintf(s, "%s", "reset"));
00036     u_test_err_if (strcmp(u_string_c(s), "reset"));
00037 
00038     u_string_free(s);
00039 
00040     return U_TEST_SUCCESS;
00041 err:
00042     return U_TEST_FAILURE;
00043 }
00044 
00045 int test_suite_string_register (u_test_t *t)
00046 {
00047     u_test_suite_t *ts = NULL;
00048 
00049     con_err_if (u_test_suite_new("Strings", &ts));
00050 
00051     con_err_if (u_test_case_register("Various functions", test_u_str, ts));
00052 
00053     return u_test_suite_add(ts, t);
00054 err:
00055     u_test_suite_free(ts);
00056     return ~0;
00057 }

←Products
© 2005-2012 - KoanLogic S.r.l. - All rights reserved