⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sprintf1.c

📁 ecos为实时嵌入式操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
    // Check 32    ret = sprintf(x, "hello%3.2fworld", 7.8);    my_strcpy( y, "hello7.80world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #4");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "width and precision modifier #4 return code");    // Check 33    ret = sprintf(x, "hello%05.1fworld", 6.5);    my_strcpy( y, "hello006.5world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0 modifier #1 return code");    // Check 34    ret = sprintf(x, "hello%03.0fworld", 6.2);    my_strcpy( y, "hello006world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0 modifier #2 return code");    // Check 35    ret = sprintf(x, "hello%05.*fworld",2, 7.5);    my_strcpy( y, "hello07.50world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier plus *");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "0 modifier plus * return code");    // Check 36    ret = sprintf(x, "hello%03.1fworld",-1.232);    my_strcpy( y, "hello-1.2world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "-ve number with 0 modifier #1 return code");    // Check 37    ret = sprintf(x, "hello%04.1fworld",-1.232);    my_strcpy( y, "hello-1.2world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "-ve number with 0 modifier #2 return code");    // Check 38    ret = sprintf(x, "hello%05.1fworld",-1.232);    my_strcpy( y, "hello-01.2world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #3");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "-ve number with 0 modifier #3 return code");    // Check 39    ret = sprintf(x, "hello%fworld",0.0);    my_strcpy( y, "hello0.000000world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #1 return code");    // Check 40    ret = sprintf(x, "hello%1.0fworld",0.0);    my_strcpy( y, "hello0world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #2 return code");    // Check 41    ret = sprintf(x, "hello%1.1fworld",0.0);    my_strcpy( y, "hello0.0world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #3");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #3 return code");    // Check 42    ret = sprintf(x, "hello%5.1fworld",0.0);    my_strcpy( y, "hello  0.0world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #4");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #4 return code");    // Check 43    ret = sprintf(x, "hello%fworld",-0.0);    my_strcpy( y, "hello-0.000000world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-0.0 test #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "-0.0 test #1 return code");    // Check 44    ret = sprintf(x, "hello%fworld",0.234);    my_strcpy( y, "hello0.234000world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "number less than 1 #1 return code");    // Check 45    ret = sprintf(x, "hello%02fworld",-0.234);    my_strcpy( y, "hello-0.234000world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "number less than 1 #2 return code");    // Check 46    ret = sprintf(x, "hello%02.2fworld",-0.234);    my_strcpy( y, "hello-0.23world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #3");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "number less than 1 #3 return code");    // Check 47    ret = sprintf(x, "hello%06.2fworld",-0.234);    my_strcpy( y, "hello-00.23world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #4");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "number less than 1 #4 return code");    // Check 48    ret = sprintf(x, "hello%-6.2fworld",2.345);    my_strcpy( y, "hello2.35  world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "left justification #1 return code");    // Check 49    ret = sprintf(x, "hello%-6.2fworld",2.345);    my_strcpy( y, "hello2.35  world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "left justification #2 return code");    // Check 50    ret = sprintf(x, "hello%-3.2fworld",2.345);    my_strcpy( y, "hello2.35world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #3");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "left justification #3 return code");    // Check 51    ret = sprintf(x, "hello%#1.0fworld",2.12);    my_strcpy( y, "hello2.world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "# modifier #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "# modifier #1 return code");    // Check 52    ret = sprintf(x, "hello%#1.2fworld",2.0);    my_strcpy( y, "hello2.00world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "# modifier #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "# modifier #2 return code");    // Check 53    ret = sprintf(x, "hello%eworld",2.3456);    my_strcpy( y, "hello2.345600e+00world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #1 return code");    // Check 54    ret = sprintf(x, "hello%4.3eworld",-2.3456e-1);    my_strcpy( y, "hello-2.346e-01world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #2 return code");    // Check 55    ret = sprintf(x, "hello%4.2eworld",2.56e2);    my_strcpy( y, "hello2.56e+02world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #3");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #3 return code");    // Check 56    ret = sprintf(x, "hello%09.2eworld",2.56e2);    my_strcpy( y, "hello02.56e+02world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #4");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #4 return code");    // Check 57    ret = sprintf(x, "hello%09.2Eworld",4.23e19);    my_strcpy( y, "hello04.23E+19world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #5");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #5 return code");    // Check 58    ret = sprintf(x, "hello%gworld",4.0);    my_strcpy( y, "hello4world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #1 return code");    // Check 59    ret = sprintf(x, "hello%gworld",4.56);    my_strcpy( y, "hello4.56world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #2 return code");    // Check 60    ret = sprintf(x, "hello%5.2gworld",4.56);    my_strcpy( y, "hello  4.6world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #3");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #3 return code");    // Check 61    ret = sprintf(x, "hello%gworld",0.002);    my_strcpy( y, "hello0.002world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #4");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #4 return code");    // Check 62    ret = sprintf(x, "hello%06.1gworld",0.0026);    my_strcpy( y, "hello00.003world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #5");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #5 return code");    // Check 63    ret = sprintf(x, "hello%06gworld",0.000026);    my_strcpy( y, "hello2.6e-05world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #5");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #5 return code");    // Check 64    ret = sprintf(x, "hello%06Gworld",0.000037);    my_strcpy( y, "hello3.7E-05world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #6");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #6 return code");    // Check 65    ret = sprintf(x, "hello%08Gworld",-123456.0);    my_strcpy( y, "hello-0123456world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #7");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #7 return code");    // Check 66    ret = sprintf(x, "hello%07gworld",-1234567.0);    my_strcpy( y, "hello-1.23457e+06world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #8");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #8 return code");    // Check 67    ret = sprintf(x, "hello%013Gworld",-1234567.0);    my_strcpy( y, "hello-01.23457E+06world");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #9");    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #9 return code");#else    CYG_TEST_PASS("Floating point tests skipped - not configured");#endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT    // Long string tests    ret = sprintf(x, "This is a very long string so I hope this works as "                  "otherwise I would be very, very, sad. The cat sat on the "                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "                  "blah, blah and all that jazz. Isn't he finished yet? My "                  "old man's a dustman, why do I have to think up this "                  "drivel, isn't that what summer students are for, if "                  "anything that seems thinking up mindless drivel seems to "                  "be their occupation in life. Yoof of today, eh? What, "                  "what? %s So there.",                  "And this is a middly bit.");    my_strcpy(y, "This is a very long string so I hope this works as "                  "otherwise I would be very, very, sad. The cat sat on the "                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "                  "blah, blah and all that jazz. Isn't he finished yet? My "                  "old man's a dustman, why do I have to think up this "                  "drivel, isn't that what summer students are for, if "                  "anything that seems thinking up mindless drivel seems to "                  "be their occupation in life. Yoof of today, eh? What, "                  "what? And this is a middly bit. So there.");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "long (480 char) string output #1");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "long (480 char) string output #1 return code");    ret = sprintf(x, "Boo! This %s So there.",                  "is a very long string so I hope this works as "                  "otherwise I would be very, very, sad. The cat sat on the "                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "                  "blah, blah and all that jazz. Isn't he finished yet? My "                  "old man's a dustman, why do I have to think up this "                  "drivel, isn't that what summer students are for, if "                  "anything that seems thinking up mindless drivel seems to "                  "be their occupation in life. Yoof of today, eh? What, "                  "what? And this is a middly bit.");    my_strcpy(y, "Boo! This is a very long string so I hope this works as "                  "otherwise I would be very, very, sad. The cat sat on the "                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "                  "blah, blah and all that jazz. Isn't he finished yet? My "                  "old man's a dustman, why do I have to think up this "                  "drivel, isn't that what summer students are for, if "                  "anything that seems thinking up mindless drivel seems to "                  "be their occupation in life. Yoof of today, eh? What, "                  "what? And this is a middly bit. So there.");    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "long (485 char) string output #2");    CYG_TEST_PASS_FAIL(ret == my_strlen(y),                       "long (485 char) string output #2 return code");    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "                    "sprintf() function");} // test()#endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO)intmain(int argc, char *argv[]){    CYG_TEST_INIT();    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "                  "sprintf() function");    CYG_TEST_INFO("These test individual features separately");    START_TEST( test );    CYG_TEST_NA("Testing is not applicable to this configuration");} // main()// EOF sprintf1.c

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -