int main(void) { /* * Test BaseString::snprintf */ if(test_snprintf("test", 1, 4)) return -1; if(test_snprintf("test", 0, 4)) return -1; if(test_snprintf("test", 100, 4)) return -1; /* * Test UintPtr */ if (sizeof(UintPtr) != sizeof(Uint32*)) { printf("sizeof(UintPtr)=%d != sizeof(Uint32*)=%d\n", (int) sizeof(UintPtr), (int) sizeof(Uint32*)); return -1; } return 0; }
void file_t() { int fd = open("/tmp/file_test_a", O_WRONLY | O_CREAT); char a[] = "data"; write(fd, a, sizeof(a)); close(fd); // char *source, *dest; source = "this is string"; dest = (char *)malloc(sizeof(char)*6); copy_string(source, dest, 5); printf("\n<-------------copy string function----------------->\n"); printf("source string is : %s, \ndest string copied is : %s", source, dest); // char buffer[10]; fd = open("/tmp/file_test_a", O_RDONLY); read(fd, buffer, 3); close(fd); printf("\n%s\n", buffer); // test_const(); test_enum(); test_snprintf(); test_if_likely(); test_define(); }
bool torture_local_replace(struct torture_context *ctx) { bool ret = true; ret &= test_ftruncate(); ret &= test_strlcpy(); ret &= test_strlcat(); ret &= test_mktime(); ret &= test_initgroups(); ret &= test_memmove(); ret &= test_strdup(); ret &= test_setlinebuf(); ret &= test_vsyslog(); ret &= test_timegm(); ret &= test_setenv(); ret &= test_strndup(); ret &= test_strnlen(); ret &= test_waitpid(); ret &= test_seteuid(); ret &= test_setegid(); ret &= test_asprintf(); ret &= test_snprintf(); ret &= test_vasprintf(); ret &= test_vsnprintf(); ret &= test_opendir(); ret &= test_readdir(); ret &= test_telldir(); ret &= test_seekdir(); ret &= test_dlopen(); ret &= test_chroot(); ret &= test_bzero(); ret &= test_strerror(); ret &= test_errno(); ret &= test_mkdtemp(); ret &= test_mkstemp(); ret &= test_pread(); ret &= test_pwrite(); ret &= test_getpass(); ret &= test_inet_ntoa(); ret &= test_strtoll(); ret &= test_strtoull(); ret &= test_va_copy(); ret &= test_FUNCTION(); ret &= test_MIN(); ret &= test_MAX(); ret &= test_socketpair(); ret &= test_strptime(); ret &= test_getifaddrs(); ret &= test_utime(); ret &= test_utimes(); ret &= test_memmem(); return ret; }
int main(int argc, char** argv){ #ifdef USE_SECURE_LIB printf("USE secure lib\n"); #else printf("NOT USE secure lib\n"); #endif test_strncpy(); test_strncat(); test_strlen(); test_snprintf(); test_popen(); test_usleep(); return 0; }
static int run_test_snprintf( void ) { return( test_snprintf( 0, "xxxxxxxxx", -1 ) != 0 || test_snprintf( 1, "", -1 ) != 0 || test_snprintf( 2, "1", -1 ) != 0 || test_snprintf( 3, "12", -1 ) != 0 || test_snprintf( 4, "123", 3 ) != 0 || test_snprintf( 5, "123", 3 ) != 0 ); }
int main(int argc, char *argv[]) { __u64 a = 0x1; __u32 b = 2; printf("%u, %u, %u\n", a, b); printf("%u, %u\n", sizeof(__u32), sizeof(__u64)); a <<= 2; printf("a=%llu\n", a); printf("%04d\n", 123); test_snprintf(); // printf("%*.*Lx\n", sizeof(a)*2, sizeof(a)*2, a); return 0; }
int main(int argc, char *argv[]) { char fmt[FMT_LEN_MAX + 1]; char arg[ARG_LEN_MAX + 1]; size_t x, y; int errors = 0; program = raptor_basename(argv[0]); for(x = 2; x < FMT_LEN_MAX; x++) { for(y = 0; y < ARG_LEN_MAX; y++) { size_t len_ref = x + y - 2; /* fmt = "xxxxxxxx%s" * (number of 'x' characters varies) */ memset(fmt, 'x', x - 2); fmt[x - 2] = '%'; fmt[x - 1] = 's'; fmt[x] = '\0'; /* arg = "yyyyyyyy" * (number of 'y' characters varies) */ memset(arg, 'y', y); arg[y] = '\0'; /* assert(strlen(fmt) == x); */ /* assert(strlen(arg) == y); */ /* len_ref = sprintf(buf_ref, fmt, arg); assert((size_t)len_ref == x + y - 2); */ IGNORE_FORMAT_NONLITERAL_START if(test_snprintf(len_ref, fmt, arg)) errors++; IGNORE_FORMAT_NONLITERAL_END } } return errors; }
void setup(void) { // // HAL will start serial port at 115200. // // // Test printing things // hal.console->println("Utility String Library Test"); hal.console->println("Test snprintf:"); test_snprintf(); hal.console->println("Test snprintf_P:"); test_snprintf_P(); hal.console->println("done"); }
int main(void){ test_snprintf(); return 0; }
void run_test () { // normal(); test_snprintf(); }
int main(void) { int i, count; unsigned int j; long lcount; char lgbuf[128]; plan(8 + (18 + (ARRAY_SIZE(fp_formats) - 1) * ARRAY_SIZE(fp_nums) + (ARRAY_SIZE(int_formats) - 1) * ARRAY_SIZE(int_nums) + (ARRAY_SIZE(uint_formats) - 1) * ARRAY_SIZE(uint_nums) + (ARRAY_SIZE(llong_formats) - 1) * ARRAY_SIZE(llong_nums) + (ARRAY_SIZE(ullong_formats) - 1) * ARRAY_SIZE(ullong_nums)) * 2); is_int(4, test_snprintf(NULL, 0, "%s", "abcd"), "simple string length"); is_int(2, test_snprintf(NULL, 0, "%d", 20), "number length"); is_int(7, test_snprintf(NULL, 0, "Test %.2s", "abcd"), "limited string"); is_int(1, test_snprintf(NULL, 0, "%c", 'a'), "character length"); is_int(0, test_snprintf(NULL, 0, ""), "empty format length"); test_format(true, "abcd", 4, "%s", "abcd"); test_format(true, "20", 2, "%d", 20); test_format(true, "Test ab", 7, "Test %.2s", "abcd"); test_format(true, "a", 1, "%c", 'a'); test_format(true, "", 0, ""); test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%s", string); test_format(true, "abcdefghij", 10, "%.10s", string); test_format(true, " abcdefghij", 12, "%12.10s", string); test_format(true, " abcdefghijklmnopqrstuvwxyz0", 40, "%40s", string); test_format(true, "abcdefghij ", 14, "%-14.10s", string); test_format(true, " abcdefghijklmnopq", 50, "%50s", string); test_format(true, "%abcd%", 6, "%%%0s%%", "abcd"); test_format(true, "", 0, "%.0s", string); test_format(true, "abcdefghijklmnopqrstuvwxyz 444", 32, "%.26s %d", string, 4444); test_format(true, "abcdefghijklmnopqrstuvwxyz -2.", 32, "%.26s %.1f", string, -2.5); test_format(true, "abcdefghij4444", 14, "%.10s%n%d", string, &count, 4444); is_int(10, count, "correct output from %%n"); test_format(true, "abcdefghijklmnopqrstuvwxyz01234", 36, "%n%s%ln", &count, string, &lcount); is_int(0, count, "correct output from two %%n"); is_int(31, lcount, "correct output from long %%ln"); test_format(true, "(null)", 6, "%s", NULL); for (i = 0; fp_formats[i] != NULL; i++) for (j = 0; j < ARRAY_SIZE(fp_nums); j++) { count = sprintf(lgbuf, fp_formats[i], fp_nums[j]); test_format(false, lgbuf, count, fp_formats[i], fp_nums[j]); } for (i = 0; int_formats[i] != NULL; i++) for (j = 0; j < ARRAY_SIZE(int_nums); j++) { count = sprintf(lgbuf, int_formats[i], int_nums[j]); test_format(false, lgbuf, count, int_formats[i], int_nums[j]); } for (i = 0; uint_formats[i] != NULL; i++) for (j = 0; j < ARRAY_SIZE(uint_nums); j++) { count = sprintf(lgbuf, uint_formats[i], uint_nums[j]); test_format(false, lgbuf, count, uint_formats[i], uint_nums[j]); } for (i = 0; llong_formats[i] != NULL; i++) for (j = 0; j < ARRAY_SIZE(llong_nums); j++) { count = sprintf(lgbuf, llong_formats[i], llong_nums[j]); test_format(false, lgbuf, count, llong_formats[i], llong_nums[j]); } for (i = 0; ullong_formats[i] != NULL; i++) for (j = 0; j < ARRAY_SIZE(ullong_nums); j++) { count = sprintf(lgbuf, ullong_formats[i], ullong_nums[j]); test_format(false, lgbuf, count, ullong_formats[i], ullong_nums[j]); } return 0; }