Ejemplo n.º 1
0
//Miscellaneous tests
void Test3()
	{
	sqlite3_vfs* vfs = sqlite3_vfs_find(KSymbianVfsNameZ);
	TEST(vfs != NULL);
	//Full path name - the full file name is specified
	char fname[KMaxFileName];
	const char* testFileName1 = "c:\\test\\abv.db";
	int err = sqlite3OsFullPathname(vfs, testFileName1, KMaxFileName, fname);
	TEST2(err, SQLITE_OK);
	err = strncasecmp(fname, testFileName1, strlen(testFileName1));
	TEST2(err, 0);
	//Full path name - no drive, the full file name is not specified
	const char* testFileName2 = "abv.db";
	const char* expectedFileName2 = "c:\\private\\21F12127\\abv.db";//"21F12127", the UID of the current test app
	err = sqlite3OsFullPathname(vfs, testFileName2, KMaxFileName, fname);
	TEST2(err, SQLITE_OK);
	err = strncasecmp(fname, expectedFileName2, strlen(expectedFileName2));
	TEST2(err, 0);
	//Full path name - drive present, the full file name is not specified
	const char* testFileName3 = "z:abv.db";
	const char* expectedFileName3 = "z:\\private\\21F12127\\abv.db";//"21F12127", the UID of the current test app
	err = sqlite3OsFullPathname(vfs, testFileName3, KMaxFileName, fname);
	TEST2(err, SQLITE_OK);
	err = strncasecmp(fname, expectedFileName3, strlen(expectedFileName3));
	TEST2(err, 0);
	//Is directory writable - test 1
	int res = 0;
	err = sqlite3OsAccess(vfs, "c:\\test", SQLITE_ACCESS_READWRITE, &res);
	TEST2(err, SQLITE_OK);
	TEST2(res, 1);
	//Is directory writable - test 2
	err = sqlite3OsAccess(vfs, "c:\\test\\", SQLITE_ACCESS_READWRITE, &res);
	TEST2(err, SQLITE_OK);
	TEST2(res, 1);
	//Is directory writable - test 3
	//Not a valid test. It is the media that's read only, not the directory.
	//err = sqlite3OsAccess(vfs, "z:\\test\\", SQLITE_ACCESS_READWRITE, &res);
	//TEST2(err, SQLITE_OK);
	//TEST2(res, 0);
	//Random seed
	const int KBufLen = 100;
	char buf[KBufLen];
	err = sqlite3OsRandomness(vfs, KBufLen, buf);
	TEST2(err, KBufLen);
	//Sleep
	TUint32 start = User::FastCounter();
	const TInt KSleepTime = 200000;//us
	(void)sqlite3OsSleep(vfs, KSleepTime);
	TUint32 end = User::FastCounter();
	TInt ms = CalcMs(start, end);
	TheTest.Printf(_L(" === sqlite3OsSleep() time=%d ms\r\n"), ms);
	//TEST(ms >= 80 && ms <= 320);// -60%..+60%
	}
Ejemplo n.º 2
0
/*
** Get a single 8-bit random value from the RC4 PRNG.  The Mutex
** must be held while executing this routine.
**
** Why not just use a library random generator like lrand48() for this?
** Because the OP_NewRowid opcode in the VDBE depends on having a very
** good source of random numbers.  The lrand48() library function may
** well be good enough.  But maybe not.  Or maybe lrand48() has some
** subtle problems on some systems that could cause problems.  It is hard
** to know.  To minimize the risk of problems due to bad lrand48()
** implementations, SQLite uses this random number generator based
** on RC4, which we know works very well.
**
** (Later):  Actually, OP_NewRowid does not depend on a good source of
** randomness any more.  But we will leave this code in all the same.
*/
static int randomByte(void){
  unsigned char t;


  /* Initialize the state of the random number generator once,
  ** the first time this routine is called.  The seed value does
  ** not need to contain a lot of randomness since we are not
  ** trying to do secure encryption or anything like that...
  **
  ** Nothing in this file or anywhere else in SQLite does any kind of
  ** encryption.  The RC4 algorithm is being used as a PRNG (pseudo-random
  ** number generator) not as an encryption device.
  */
  if( !sqlite3Prng.isInit ){
    int i;
    char k[256];
    sqlite3Prng.j = 0;
    sqlite3Prng.i = 0;
    sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k);
    for(i=0; i<256; i++){
      sqlite3Prng.s[i] = i;
    }
    for(i=0; i<256; i++){
      sqlite3Prng.j += sqlite3Prng.s[i] + k[i];
      t = sqlite3Prng.s[sqlite3Prng.j];
      sqlite3Prng.s[sqlite3Prng.j] = sqlite3Prng.s[i];
      sqlite3Prng.s[i] = t;
    }
    sqlite3Prng.isInit = 1;
  }

  /* Generate and return single random byte
  */
  sqlite3Prng.i++;
  t = sqlite3Prng.s[sqlite3Prng.i];
  sqlite3Prng.j += t;
  sqlite3Prng.s[sqlite3Prng.i] = sqlite3Prng.s[sqlite3Prng.j];
  sqlite3Prng.s[sqlite3Prng.j] = t;
  t += sqlite3Prng.s[sqlite3Prng.i];
  return sqlite3Prng.s[t];
}
Ejemplo n.º 3
0
/*
** Populate the buffer pointed to by zBufOut with nByte bytes of 
** random data.
*/
static int devsymRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
  return sqlite3OsRandomness(g.pVfs, nByte, zBufOut);
}
Ejemplo n.º 4
0
/*
** Populate the buffer pointed to by zBufOut with nByte bytes of 
** random data.
*/
static int tvfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
  return sqlite3OsRandomness(PARENTVFS(pVfs), nByte, zBufOut);
}