00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <unistd.h>
00031 #include <macros.h>
00032 #include "../tester.h"
00033
00034 #define BUFFER_SIZE 32
00035
00036 const char *test_print3(void)
00037 {
00038 char buffer[BUFFER_SIZE];
00039 int retval;
00040
00041 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n");
00042 TPRINTF("Expected result: retval=30 buffer=\"Short text without parameters.\"\n");
00043 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
00044 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
00045
00046 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n");
00047 TPRINTF("Expected result: retval=44 buffer=\"Very very very long text withou\"\n");
00048 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
00049 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
00050
00051 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n");
00052 TPRINTF("Expected result: retval=11 buffer=\"Short text.\"\n");
00053 retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text");
00054 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
00055
00056 TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very long %%s. This text's length is more than %%d. We are interested in the result.\", \"text\", " STRING(BUFFER_SIZE) "):\n");
00057 TPRINTF("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n");
00058 retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text's length is more than %d. We are interested in the result.", "text", BUFFER_SIZE);
00059 TPRINTF("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer);
00060
00061 return NULL;
00062 }