| 1240 | } |
| 1241 | |
| 1242 | int sdsTest(int argc, char **argv, int accurate) { |
| 1243 | UNUSED(argc); |
| 1244 | UNUSED(argv); |
| 1245 | UNUSED(accurate); |
| 1246 | |
| 1247 | { |
| 1248 | sds x = sdsnew("foo"), y; |
| 1249 | |
| 1250 | test_cond("Create a string and obtain the length", |
| 1251 | sdslen(x) == 3 && memcmp(x,"foo\0",4) == 0); |
| 1252 | |
| 1253 | sdsfree(x); |
| 1254 | x = sdsnewlen("foo",2); |
| 1255 | test_cond("Create a string with specified length", |
| 1256 | sdslen(x) == 2 && memcmp(x,"fo\0",3) == 0); |
| 1257 | |
| 1258 | x = sdscat(x,"bar"); |
| 1259 | test_cond("Strings concatenation", |
| 1260 | sdslen(x) == 5 && memcmp(x,"fobar\0",6) == 0); |
| 1261 | |
| 1262 | x = sdscpy(x,"a"); |
| 1263 | test_cond("sdscpy() against an originally longer string", |
| 1264 | sdslen(x) == 1 && memcmp(x,"a\0",2) == 0); |
| 1265 | |
| 1266 | x = sdscpy(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk"); |
| 1267 | test_cond("sdscpy() against an originally shorter string", |
| 1268 | sdslen(x) == 33 && |
| 1269 | memcmp(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0",33) == 0); |
| 1270 | |
| 1271 | sdsfree(x); |
| 1272 | x = sdscatprintf(sdsempty(),"%d",123); |
| 1273 | test_cond("sdscatprintf() seems working in the base case", |
| 1274 | sdslen(x) == 3 && memcmp(x,"123\0",4) == 0); |
| 1275 | |
| 1276 | sdsfree(x); |
| 1277 | x = sdscatprintf(sdsempty(),"a%cb",0); |
| 1278 | test_cond("sdscatprintf() seems working with \\0 inside of result", |
| 1279 | sdslen(x) == 3 && memcmp(x,"a\0""b\0",4) == 0); |
| 1280 | |
| 1281 | { |
| 1282 | sdsfree(x); |
| 1283 | char etalon[1024*1024]; |
| 1284 | for (size_t i = 0; i < sizeof(etalon); i++) { |
| 1285 | etalon[i] = '0'; |
| 1286 | } |
| 1287 | x = sdscatprintf(sdsempty(),"%0*d",(int)sizeof(etalon),0); |
| 1288 | test_cond("sdscatprintf() can print 1MB", |
| 1289 | sdslen(x) == sizeof(etalon) && memcmp(x,etalon,sizeof(etalon)) == 0); |
| 1290 | } |
| 1291 | |
| 1292 | sdsfree(x); |
| 1293 | x = sdsnew("--"); |
| 1294 | x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN,LLONG_MAX); |
| 1295 | test_cond("sdscatfmt() seems working in the base case", |
| 1296 | sdslen(x) == 60 && |
| 1297 | memcmp(x,"--Hello Hi! World -9223372036854775808," |
| 1298 | "9223372036854775807--",60) == 0); |
| 1299 | printf("[%s]\n",x); |
nothing calls this directly
no test coverage detected