unit1398.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 
00024 #include "curl/mprintf.h"
00025 
00026 static CURLcode unit_setup(void) {return CURLE_OK;}
00027 static void unit_stop(void) {}
00028 
00029 UNITTEST_START
00030 
00031 int rc;
00032 char buf[3] = {'b', 'u', 'g'};
00033 const char *str="bug";
00034 int width = 3;
00035 char output[24];
00036 
00037 /*#define curl_msnprintf snprintf */
00038 
00039 /* without a trailing zero */
00040 rc = curl_msnprintf(output, 4, "%.*s", width, buf);
00041 fail_unless(rc == 3, "return code should be 3");
00042 fail_unless(!strcmp(output, "bug"), "wrong output");
00043 
00044 /* with a trailing zero */
00045 rc = curl_msnprintf(output, 4, "%.*s", width, str);
00046 fail_unless(rc == 3, "return code should be 3");
00047 fail_unless(!strcmp(output, "bug"), "wrong output");
00048 
00049 width = 2;
00050 /* one byte less */
00051 rc = curl_msnprintf(output, 4, "%.*s", width, buf);
00052 fail_unless(rc == 2, "return code should be 2");
00053 fail_unless(!strcmp(output, "bu"), "wrong output");
00054 
00055 /* string with larger precision */
00056 rc = curl_msnprintf(output, 8, "%.8s", str);
00057 fail_unless(rc == 3, "return code should be 3");
00058 fail_unless(!strcmp(output, "bug"), "wrong output");
00059 
00060 /* longer string with precision */
00061 rc = curl_msnprintf(output, 8, "%.3s", "0123456789");
00062 fail_unless(rc == 3, "return code should be 3");
00063 fail_unless(!strcmp(output, "012"), "wrong output");
00064 
00065 /* negative width */
00066 rc = curl_msnprintf(output, 8, "%-8s", str);
00067 fail_unless(rc == 8, "return code should be 8");
00068 fail_unless(!strcmp(output, "bug    "), "wrong output");
00069 
00070 /* larger width that string length */
00071 rc = curl_msnprintf(output, 8, "%8s", str);
00072 fail_unless(rc == 8, "return code should be 8");
00073 fail_unless(!strcmp(output, "     bu"), "wrong output");
00074 
00075 /* output a number in a limited output */
00076 rc = curl_msnprintf(output, 4, "%d", 10240);
00077 /* TODO: this should return 5 to be POSIX/snprintf compliant! */
00078 fail_unless(rc == 4, "return code should be 4");
00079 fail_unless(!strcmp(output, "102"), "wrong output");
00080 
00081 /* padded strings */
00082 rc = curl_msnprintf(output, 16, "%8s%8s", str, str);
00083 fail_unless(rc == 16, "return code should be 16");
00084 fail_unless(!strcmp(output, "     bug     bu"), "wrong output");
00085 
00086 /* padded numbers */
00087 rc = curl_msnprintf(output, 16, "%8d%8d", 1234, 5678);
00088 fail_unless(rc == 16, "return code should be 16");
00089 fail_unless(!strcmp(output, "    1234    567"), "wrong output");
00090 
00091 UNITTEST_STOP


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07