Ignore:
Timestamp:
2014-09-19T12:41:34Z (10 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6019983
Parents:
bf45993
Message:

Uncomment scanf() tests from libposix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/source/stdio/scanf.c

    rbf45993 r6b646dc  
    12201220}
    12211221
    1222 // FIXME: put the testcases to the app/tester after scanf is included into libc
    1223 
    1224 #if 0
    1225 
    1226 //#include <stdio.h>
    1227 //#include <malloc.h>
    1228 //#include <string.h>
    1229 
    1230 #define test_val(fmt, exp_val, act_val) \
    1231         if (exp_val == act_val) { \
    1232                 printf("succ, expected "fmt", actual "fmt"\n", exp_val, act_val); \
    1233         } else { \
    1234                 printf("fail, expected "fmt", actual "fmt"\n", exp_val, act_val); \
    1235                 ++fail; \
    1236         }
    1237 
    1238 #define test_str(fmt, exp_str, act_str) \
    1239         if (posix_strcmp(exp_str, act_str) == 0) { \
    1240                 printf("succ, expected "fmt", actual "fmt"\n", exp_str, act_str); \
    1241         } else { \
    1242                 printf("fail, expected "fmt", actual "fmt"\n", exp_str, act_str); \
    1243                 ++fail; \
    1244         }
    1245 
    1246 void __posix_scanf_test(void);
    1247 void __posix_scanf_test(void)
    1248 {
    1249         int fail = 0;
    1250 
    1251         int ret;
    1252 
    1253         unsigned char uhh;
    1254         signed char shh;
    1255         unsigned short uh;
    1256         short sh;
    1257         unsigned udef;
    1258         int sdef;
    1259         unsigned long ul;
    1260         long sl;
    1261         unsigned long long ull;
    1262         long long sll;
    1263         void *p;
    1264        
    1265         float f;
    1266         double d;
    1267         long double ld;
    1268 
    1269         char str[20];
    1270         char seq[20];
    1271         char scanset[20];
    1272 
    1273         char *pstr;
    1274         char *pseq;
    1275         char *pscanset;
    1276        
    1277         ret = posix_sscanf(
    1278             "\n j tt % \t -121314 98765 aqw 0765 0x77 0xABCDEF88 -99 884",
    1279             " j tt %%%3hhd%1hhu%3hd %3hu%u aqw%n %lo%llx %p %li %lld",
    1280             &shh, &uhh, &sh, &uh, &udef, &sdef, &ul, &ull, &p, &sl, &sll);
    1281         test_val("%d", -12, shh);
    1282         test_val("%u", 1, uhh);
    1283         test_val("%d", 314, sh);
    1284         test_val("%u", 987, uh);
    1285         test_val("%u", 65, udef);
    1286         test_val("%d", 28, sdef);
    1287         test_val("%lo", (unsigned long) 0765, ul);
    1288         test_val("%llx", (unsigned long long) 0x77, ull);
    1289         test_val("%p", (void *) 0xABCDEF88, p);
    1290         test_val("%ld", (long) -99, sl);
    1291         test_val("%lld", (long long) 884, sll);
    1292         test_val("%d", 10, ret);
    1293 
    1294         ret = posix_sscanf(
    1295             "\n \t\t1.0 -0x555.AP10 1234.5678e12",
    1296             "%f %lf %Lf",
    1297             &f, &d, &ld);
    1298         test_val("%f", 1.0, f);
    1299         test_val("%lf", (double) -0x555.AP10, d);
    1300         test_val("%Lf", (long double) 1234.5678e12, ld);
    1301         test_val("%d", 3, ret);
    1302          
    1303         ret = posix_sscanf(
    1304             "\n\n\thello world    \n",
    1305             "%5s %ms",
    1306             str, &pstr);
    1307         test_str("%s", "hello", str);
    1308         test_str("%s", "world", pstr);
    1309         test_val("%d", 2, ret);
    1310         free(pstr);
    1311 
    1312         ret = posix_sscanf(
    1313             "\n\n\thello world    \n",
    1314             " %5c %mc",
    1315             seq, &pseq);
    1316         seq[5] = '\0';
    1317         pseq[1] = '\0';
    1318         test_str("%s", "hello", seq);
    1319         test_str("%s", "w", pseq);
    1320         test_val("%d", 2, ret);
    1321         free(pseq);
    1322 
    1323         ret = posix_sscanf(
    1324             "\n\n\th-e-l-l-o world-]    \n",
    1325             " %9[-eh-o] %m[^]-]",
    1326             scanset, &pscanset);
    1327         test_str("%s", "h-e-l-l-o", scanset);
    1328         test_str("%s", "world", pscanset);
    1329         test_val("%d", 2, ret);
    1330         free(pscanset);
    1331 
    1332         printf("Failed: %d\n", fail);
    1333 }
    1334 
    1335 #endif
    1336 
    13371222/** @}
    13381223 */
Note: See TracChangeset for help on using the changeset viewer.