17 void testDatasourceEntry(
20 void **ppKey
, int *pnKey
,
21 void **ppVal
, int *pnVal
23 assert( (ppKey
==0)==(pnKey
==0) );
24 assert( (ppVal
==0)==(pnVal
==0) );
29 case TEST_DATASOURCE_RANDOM
: {
30 int nRange
= (1 + p
->nMaxKey
- p
->nMinKey
);
31 nKey
= (int)( testPrngValue((u32
)iData
) % nRange
) + p
->nMinKey
;
32 testPrngString((u32
)iData
, p
->aKey
, nKey
);
35 case TEST_DATASOURCE_SEQUENCE
:
36 nKey
= sprintf(p
->aKey
, "%012d", iData
);
43 u32 nVal
= testPrngValue((u32
)iData
)%(1+p
->nMaxVal
-p
->nMinVal
)+p
->nMinVal
;
44 testPrngString((u32
)~iData
, p
->aVal
, (int)nVal
);
50 void testDatasourceFree(Datasource
*p
){
55 ** Return a pointer to a nul-terminated string that corresponds to the
56 ** contents of the datasource-definition passed as the first argument.
57 ** The caller should eventually free the returned pointer using testFree().
59 char *testDatasourceName(const DatasourceDefn
*p
){
61 zRet
= testMallocPrintf("%s.(%d-%d).(%d-%d)",
62 (p
->eType
==TEST_DATASOURCE_SEQUENCE
? "seq" : "rnd"),
63 p
->nMinKey
, p
->nMaxKey
,
64 p
->nMinVal
, p
->nMaxVal
69 Datasource
*testDatasourceNew(const DatasourceDefn
*pDefn
){
76 if( pDefn
->eType
==TEST_DATASOURCE_SEQUENCE
){
80 nMinKey
= MAX(0, pDefn
->nMinKey
);
81 nMaxKey
= MAX(nMinKey
, pDefn
->nMaxKey
);
83 nMinVal
= MAX(0, pDefn
->nMinVal
);
84 nMaxVal
= MAX(nMinVal
, pDefn
->nMaxVal
);
86 p
= (Datasource
*)testMalloc(sizeof(Datasource
) + nMaxKey
+ nMaxVal
+ 1);
87 p
->eType
= pDefn
->eType
;
93 p
->aKey
= (char *)&p
[1];
94 p
->aVal
= &p
->aKey
[nMaxKey
];