2007-11-29 14:18:54 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
2008-01-24 15:10:32 +00:00
|
|
|
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
|
2007-11-29 14:18:54 +00:00
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
#include "test.h"
|
|
|
|
|
2013-04-16 23:57:21 -04:00
|
|
|
#include "includes.h"
|
2007-07-13 19:37:47 +00:00
|
|
|
|
2013-04-16 23:57:41 -04:00
|
|
|
static void
|
|
|
|
cleanup_and_free(struct simple_dbt *v) {
|
|
|
|
if (v->data) toku_free(v->data);
|
|
|
|
v->data = NULL;
|
|
|
|
v->len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup(struct simple_dbt *v) {
|
|
|
|
v->data = NULL;
|
|
|
|
v->len = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-29 15:17:46 +00:00
|
|
|
static void ybt_test0 (void) {
|
2013-04-16 23:57:41 -04:00
|
|
|
struct simple_dbt v0 = {0,0}, v1 = {0,0};
|
2007-07-13 19:37:47 +00:00
|
|
|
DBT t0,t1;
|
2007-11-29 15:17:46 +00:00
|
|
|
toku_init_dbt(&t0);
|
|
|
|
toku_init_dbt(&t1);
|
2008-05-27 11:29:33 +00:00
|
|
|
{
|
2008-05-27 14:47:23 +00:00
|
|
|
bytevec temp1 = "hello";
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_dbt_set(6, temp1, &t0, &v0);
|
2008-05-27 11:29:33 +00:00
|
|
|
}
|
|
|
|
{
|
2008-05-27 14:47:23 +00:00
|
|
|
bytevec temp2 = "foo";
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_dbt_set( 4, temp2, &t1, &v1);
|
2008-05-27 11:29:33 +00:00
|
|
|
}
|
2007-07-13 19:37:47 +00:00
|
|
|
assert(t0.size==6);
|
|
|
|
assert(strcmp(t0.data, "hello")==0);
|
|
|
|
assert(t1.size==4);
|
|
|
|
assert(strcmp(t1.data, "foo")==0);
|
|
|
|
|
2008-05-27 11:29:33 +00:00
|
|
|
{
|
2008-05-27 14:47:23 +00:00
|
|
|
bytevec temp3 = "byebye";
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_dbt_set(7, temp3, &t1, &v0); /* Use v0, not v1 */
|
2008-05-27 11:29:33 +00:00
|
|
|
}
|
2007-07-31 21:40:30 +00:00
|
|
|
// This assertion would be wrong, since v0 may have been realloc'd, and t0.data may now point
|
|
|
|
// at the wrong place
|
|
|
|
//assert(strcmp(t0.data, "byebye")==0); /* t0's data should be changed too, since it used v0 */
|
2007-07-13 19:37:47 +00:00
|
|
|
assert(strcmp(t1.data, "byebye")==0);
|
|
|
|
|
2013-04-16 23:57:41 -04:00
|
|
|
cleanup_and_free(&v0);
|
|
|
|
cleanup_and_free(&v1);
|
2013-04-16 23:59:22 -04:00
|
|
|
|
2007-07-13 19:37:47 +00:00
|
|
|
|
|
|
|
/* See if we can probe to find out how big something is by setting ulen=0 with YBT_USERMEM */
|
2007-11-29 15:17:46 +00:00
|
|
|
toku_init_dbt(&t0);
|
2007-07-13 19:37:47 +00:00
|
|
|
t0.flags = DB_DBT_USERMEM;
|
|
|
|
t0.ulen = 0;
|
2008-05-27 11:29:33 +00:00
|
|
|
{
|
2008-05-27 14:47:23 +00:00
|
|
|
bytevec temp4 = "hello";
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_dbt_set(6, temp4, &t0, 0);
|
2008-05-27 11:29:33 +00:00
|
|
|
}
|
2007-07-13 19:37:47 +00:00
|
|
|
assert(t0.data==0);
|
|
|
|
assert(t0.size==6);
|
|
|
|
|
|
|
|
/* Check realloc. */
|
2007-11-29 15:17:46 +00:00
|
|
|
toku_init_dbt(&t0);
|
2007-07-13 19:37:47 +00:00
|
|
|
t0.flags = DB_DBT_REALLOC;
|
2013-04-16 23:57:41 -04:00
|
|
|
cleanup(&v0);
|
2008-05-27 11:29:33 +00:00
|
|
|
{
|
2008-05-27 14:47:23 +00:00
|
|
|
bytevec temp5 = "internationalization";
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_dbt_set(21, temp5, &t0, &v0);
|
2008-05-27 11:29:33 +00:00
|
|
|
}
|
2013-04-16 23:57:41 -04:00
|
|
|
assert(v0.data==0); /* Didn't change v0 */
|
2007-07-13 19:37:47 +00:00
|
|
|
assert(t0.size==21);
|
|
|
|
assert(strcmp(t0.data, "internationalization")==0);
|
|
|
|
|
2008-05-27 11:29:33 +00:00
|
|
|
{
|
2008-05-27 14:47:23 +00:00
|
|
|
bytevec temp6 = "provincial";
|
2013-04-16 23:57:41 -04:00
|
|
|
toku_dbt_set(11, temp6, &t0, &v0);
|
2008-05-27 11:29:33 +00:00
|
|
|
}
|
2007-07-13 19:37:47 +00:00
|
|
|
assert(t0.size==11);
|
|
|
|
assert(strcmp(t0.data, "provincial")==0);
|
|
|
|
|
2007-07-20 18:00:14 +00:00
|
|
|
toku_free(t0.data);
|
2013-04-16 23:59:22 -04:00
|
|
|
|
2007-07-13 19:37:47 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
int
|
|
|
|
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
|
2007-07-13 19:37:47 +00:00
|
|
|
ybt_test0();
|
|
|
|
return 0;
|
|
|
|
}
|