Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add test logic and some test cases. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | quota-stdio |
Files: | files | file ages | folders |
SHA1: |
a4730586cc1f686ead956ccd1cc218b5 |
User & Date: | drh 2011-12-01 20:48:15.803 |
Context
2011-12-01
| ||
22:07 | Progress toward getting things to work better on windows. (check-in: 253dd7072e user: drh tags: quota-stdio) | |
20:48 | Add test logic and some test cases. (check-in: a4730586cc user: drh tags: quota-stdio) | |
18:44 | Add stdio-like I/O interfaces to the test_quota VFS. This is a prototype change for discussion and is mostly untested. This is an alternative to adding stdio-like I/O interfaces in the core. There is no guarantee that this code will make it into the trunk. If it does get to trunk, there could be many changes to the interface first. (check-in: bd3ce723f1 user: drh tags: quota-stdio) | |
Changes
Changes to src/test_quota.c.
︙ | |||
233 234 235 236 237 238 239 240 241 242 243 244 245 246 | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | + + | ** '?' Matches exactly one character. ** ** [...] Matches one character from the enclosed list of ** characters. ** ** [^...] Matches one character not in the enclosed list. ** ** / Matches "/" or "\\" ** */ static int quotaStrglob(const char *zGlob, const char *z){ int c, c2; int invert; int seen; while( (c = (*(zGlob++)))!=0 ){ |
︙ | |||
291 292 293 294 295 296 297 298 299 300 301 302 303 304 | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | + + + | seen = 1; } prior_c = c2; } c2 = *(zGlob++); } if( c2==0 || (seen ^ invert)==0 ) return 0; }else if( c=='/' ){ if( z[0]!='/' && z[0]!='\\' ) return 0; z++; }else{ if( c!=(*(z++)) ) return 0; } } return *z==0; } |
︙ | |||
346 347 348 349 350 351 352 353 354 355 356 357 358 359 | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | pFile->ppPrev = &pGroup->pFiles; pGroup->pFiles = pFile; pFile->pGroup = pGroup; } } return pFile; } /* ** Figure out if we are dealing with Unix, Windows, or some other ** operating system. After the following block of preprocess macros, ** all of SQLITE_OS_UNIX, SQLITE_OS_WIN, SQLITE_OS_OS2, and SQLITE_OS_OTHER ** will defined to either 1 or 0. One of the four will be 1. The other ** three will be 0. */ #if defined(SQLITE_OS_OTHER) # if SQLITE_OS_OTHER==1 # undef SQLITE_OS_UNIX # define SQLITE_OS_UNIX 0 # undef SQLITE_OS_WIN # define SQLITE_OS_WIN 0 # undef SQLITE_OS_OS2 # define SQLITE_OS_OS2 0 # else # undef SQLITE_OS_OTHER # endif #endif #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) # define SQLITE_OS_OTHER 0 # ifndef SQLITE_OS_WIN # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) \ || defined(__MINGW32__) || defined(__BORLANDC__) # define SQLITE_OS_WIN 1 # define SQLITE_OS_UNIX 0 # define SQLITE_OS_OS2 0 # elif defined(__EMX__) || defined(_OS2) || defined(OS2) \ || defined(_OS2_) || defined(__OS2__) # define SQLITE_OS_WIN 0 # define SQLITE_OS_UNIX 0 # define SQLITE_OS_OS2 1 # else # define SQLITE_OS_WIN 0 # define SQLITE_OS_UNIX 1 # define SQLITE_OS_OS2 0 # endif # else # define SQLITE_OS_UNIX 0 # define SQLITE_OS_OS2 0 # endif #else # ifndef SQLITE_OS_WIN # define SQLITE_OS_WIN 0 # endif #endif /* ** Translate UTF8 to MBCS for use in fopen() calls. Return a pointer to the ** translated text.. Call quota_mbcs_free() to deallocate any memory ** used to store the returned pointer when done. */ static char *quota_utf8_to_mbcs(const char *zUtf8){ #if SQLITE_OS_WIN extern char *sqlite3_win32_utf8_to_mbcs(const char*); return sqlite3_win32_utf8_to_mbcs(zUtf8); #else return (char*)zUtf8; /* No-op on unix */ #endif } /* ** Deallocate any memory allocated by quota_utf8_to_mbcs(). */ static void quota_mbcs_free(char *zOld){ #if SQLITE_OS_WIN free(zOld); #else /* No-op on unix */ #endif } /************************* VFS Method Wrappers *****************************/ /* ** This is the xOpen method used for the "quota" VFS. ** ** Most of the work is done by the underlying original VFS. This method ** simply links the new file into the appropriate quota group if it is a |
︙ | |||
852 853 854 855 856 857 858 859 860 861 862 | 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | + - - + + - + + - + + | /* ** Open a potentially quotaed file for I/O. */ quota_FILE *sqlite3_quota_fopen(const char *zFilename, const char *zMode){ quota_FILE *p = 0; char *zFull = 0; char *zFullTranslated; int rc; quotaGroup *pGroup; quotaFile *pFile; |
︙ | |||
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + | } Tcl_ListObjAppendElement(interp, pResult, pGroupTerm); } quotaLeave(); Tcl_SetObjResult(interp, pResult); return TCL_OK; } /* ** tclcmd: sqlite3_quota_fopen FILENAME MODE */ static int test_quota_fopen( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ const char *zFilename; /* File pattern to configure */ const char *zMode; /* Mode string */ quota_FILE *p; /* Open string object */ char zReturn[50]; /* Name of pointer to return */ /* Process arguments */ if( objc!=3 ){ Tcl_WrongNumArgs(interp, 1, objv, "FILENAME MODE"); return TCL_ERROR; } zFilename = Tcl_GetString(objv[1]); zMode = Tcl_GetString(objv[2]); p = sqlite3_quota_fopen(zFilename, zMode); sqlite3_snprintf(sizeof(zReturn), zReturn, "%p", p); Tcl_SetResult(interp, zReturn, TCL_VOLATILE); return TCL_OK; } /* Defined in test1.c */ extern void *sqlite3TestTextToPtr(const char*); /* ** tclcmd: sqlite3_quota_fread HANDLE SIZE NELEM */ static int test_quota_fread( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ quota_FILE *p; char *zBuf; int sz; int nElem; int got; if( objc!=4 ){ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE SIZE NELEM"); return TCL_ERROR; } p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); if( Tcl_GetIntFromObj(interp, objv[2], &sz) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[3], &nElem) ) return TCL_ERROR; zBuf = sqlite3_malloc( sz*nElem + 1 ); if( zBuf==0 ){ Tcl_SetResult(interp, "out of memory", TCL_STATIC); return TCL_ERROR; } got = sqlite3_quota_fread(zBuf, sz, nElem, p); if( got<0 ) got = 0; zBuf[got*sz] = 0; Tcl_SetResult(interp, zBuf, TCL_VOLATILE); sqlite3_free(zBuf); return TCL_OK; } /* ** tclcmd: sqlite3_quota_fwrite HANDLE SIZE NELEM CONTENT */ static int test_quota_fwrite( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ quota_FILE *p; char *zBuf; int sz; int nElem; int got; if( objc!=5 ){ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE SIZE NELEM CONTENT"); return TCL_ERROR; } p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); if( Tcl_GetIntFromObj(interp, objv[2], &sz) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[3], &nElem) ) return TCL_ERROR; zBuf = Tcl_GetString(objv[4]); got = sqlite3_quota_fwrite(zBuf, sz, nElem, p); Tcl_SetObjResult(interp, Tcl_NewIntObj(got)); return TCL_OK; } /* ** tclcmd: sqlite3_quota_fclose HANDLE */ static int test_quota_fclose( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ quota_FILE *p; int rc; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); return TCL_ERROR; } p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); rc = sqlite3_quota_fclose(p); Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_OK; } /* ** tclcmd: sqlite3_quota_fseek HANDLE OFFSET WHENCE */ static int test_quota_fseek( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ quota_FILE *p; int ofst; const char *zWhence; int whence; int rc; if( objc!=4 ){ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE OFFSET WHENCE"); return TCL_ERROR; } p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); if( Tcl_GetIntFromObj(interp, objv[2], &ofst) ) return TCL_ERROR; zWhence = Tcl_GetString(objv[3]); if( strcmp(zWhence, "SEEK_SET")==0 ){ whence = SEEK_SET; }else if( strcmp(zWhence, "SEEK_CUR")==0 ){ whence = SEEK_CUR; }else if( strcmp(zWhence, "SEEK_END")==0 ){ whence = SEEK_END; }else{ Tcl_AppendResult(interp, "WHENCE should be SEEK_SET, SEEK_CUR, or SEEK_END", (char*)0); return TCL_ERROR; } rc = sqlite3_quota_fseek(p, ofst, whence); Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_OK; } /* ** tclcmd: sqlite3_quota_rewind HANDLE */ static int test_quota_rewind( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ quota_FILE *p; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); return TCL_ERROR; } p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); sqlite3_quota_rewind(p); return TCL_OK; } /* ** tclcmd: sqlite3_quota_ftell HANDLE */ static int test_quota_ftell( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ quota_FILE *p; sqlite3_int64 x; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE"); return TCL_ERROR; } p = sqlite3TestTextToPtr(Tcl_GetString(objv[1])); x = sqlite3_quota_ftell(p); Tcl_SetObjResult(interp, Tcl_NewWideIntObj(x)); return TCL_OK; } /* ** tclcmd: sqlite3_quota_remove FILENAME */ static int test_quota_remove( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ const char *zFilename; /* File pattern to configure */ int rc; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "FILENAME"); return TCL_ERROR; } zFilename = Tcl_GetString(objv[1]); rc = sqlite3_quota_remove(zFilename); Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_OK; } /* ** This routine registers the custom TCL commands defined in this ** module. This should be the only procedure visible from outside ** of this module. */ int Sqlitequota_Init(Tcl_Interp *interp){ static struct { char *zName; Tcl_ObjCmdProc *xProc; } aCmd[] = { { "sqlite3_quota_initialize", test_quota_initialize }, |
Changes to test/quota.test.
︙ | |||
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | + | # quota-2.4.*: Try to shutdown the quota system before closing the db # file. Check that this fails and the quota system still works # afterwards. Then close the database and successfully shut # down the quota system. # sqlite3_quota_initialize "" 1 unset -nocomplain quota_request_ok proc quota_check {filename limitvar size} { upvar $limitvar limit lappend ::quota [set limit] $size if {[info exists ::quota_request_ok]} { set limit $size } } |
︙ |
Added test/quota2.test.