00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00038
00039
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
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
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
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
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
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
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
00076 rc = curl_msnprintf(output, 4, "%d", 10240);
00077
00078 fail_unless(rc == 4, "return code should be 4");
00079 fail_unless(!strcmp(output, "102"), "wrong output");
00080
00081
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
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