8000 Added a test for #167 by os12 · Pull Request #168 · pmwkaa/sophia · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added a test for #167 #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v2.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 65 additions & 55 deletions test/generic/prefix.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,60 +34,60 @@ prefix_test0(void)

char key[] = "a";
void *o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", key, sizeof(key)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", key, sizeof(key)) == 0);
t_api(sp_set(db, o));

char keyb[] = "ab";
char keyd[] = "abac";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keyb, sizeof(keyb)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t_api(sp_setstring(o, "key", keyd, sizeof(keyd)));
t_api(sp_set(db, o));

char keyc[] = "aba";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keyc, sizeof(keyc)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", keyc, sizeof(keyc)) == 0);
t_api(sp_set(db, o));

char keyd[] = "abac";
char keyb[] = "ab";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keyd, sizeof(keyd)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", keyb, sizeof(keyb)) == 0);
t_api(sp_set(db, o));

char keye[] = "bbac";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keye, sizeof(keye)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", keye, sizeof(keye)) == 0);
t_api(sp_set(db, o));

char prefix[] = "ab";
const char *prefix = "ab";

void *c = sp_cursor(env);
t( c != NULL );
t(c != NULL);

o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "order", ">=", 0) == 0 );
t( sp_setstring(o, "prefix", prefix, sizeof(prefix) - 1) == 0 );
t(o != NULL);
t_api(sp_setstring(o, "order", ">=", 0));
t_api(sp_setstring(o, "prefix", prefix, strlen(prefix)));

o = sp_get(c, o);
t( o != NULL );
t( strcmp((char*)sp_getstring(o, "key", NULL), "ab") == 0 );
t(o != NULL);
t_string_eq((char *)sp_getstring(o, "key", NULL), "ab");

o = sp_get(c, o);
t( o != NULL );
t( strcmp((char*)sp_getstring(o, "key", NULL), "aba") == 0 );
t(o != NULL);
t_string_eq((char *)sp_getstring(o, "key", NULL), "aba");

o = sp_get(c, o);
t( o != NULL );
t( strcmp((char*)sp_getstring(o, "key", NULL), "abac") == 0 );
t(o != NULL);
t_string_eq((char *)sp_getstring(o, "key", NULL), "abac");

o = sp_get(c, o);
t( o == NULL );
t(o == NULL);

t( sp_destroy(env) == 0 );
t(sp_destroy(env) == 0);
}

static void
Expand All @@ -109,50 +109,60 @@ prefix_test1(void)

char key[] = "a";
void *o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", key, sizeof(key)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", key, strlen(key)) == 0);
t_api(sp_set(db, o));

char keyb[] = "ab";
char keyc[] = "aba";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keyb, sizeof(keyb)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", keyc, strlen(keyc)) == 0);
t_api(sp_set(db, o));

char keyc[] = "aba";
char keyb[] = "ab";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keyc, sizeof(keyc)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", keyb, strlen(keyb)) == 0);
t_api(sp_set(db, o));

char keyd[] = "abac";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keyd, sizeof(keyd)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", keyd, strlen(keyd)) == 0);
t_api(sp_set(db, o));

char keye[] = "bbac";
o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "key", keye, sizeof(keye)) == 0 );
t( sp_set(db, o) == 0 );
t(o != NULL);
t(sp_setstring(o, "key", keye, strlen(keye)) == 0);
t_api(sp_set(db, o));

char prefix[] = "ab";
const char *prefix = "ab";

void *c = sp_cursor(env);
t( c != NULL );
t(c != NULL);

o = sp_document(db);
t( o != NULL );
t( sp_setstring(o, "order", "<=", 0) == 0 );
t( sp_setstring(o, "prefix", prefix, sizeof(prefix)) == 0 );
t(o != NULL);
t_api(sp_setstring(o, "order", "<=", 0));
t_api(sp_setstring(o, "prefix", prefix, strlen(prefix)));

o = sp_get(c, o);
t(o != NULL);
t_string_eq((char *)sp_getstring(o, "key", NULL), "abac");

o = sp_get(c, o);
t( strcmp((char*)sp_getstring(o, "key", NULL), "ab") == 0 );
t(o != NULL);
t_string_eq((char *)sp_getstring(o, "key", NULL), "aba");

o = sp_get(c, o);
t(o != NULL);
t_string_eq((char *)sp_getstring(o, "key", NULL), "ab");

o = sp_get(c, o);
t( o == NULL );
t(o == NULL);

t( sp_destroy(env) == 0 );
t(sp_destroy(env) == 0);
}

stgroup *prefix_group(void)
Expand Down
59 changes: 59 additions & 0 deletions test/issues/github.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,64 @@ github_123(void)
rmrf("./abc_log");
}

static const char *_prefix = "log:";

static void
github_167()
{
void *env = sp_env();
t( env != NULL );
t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) 8000 == 0 );
t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
t( sp_setstring(env, "db", "test", 0) == 0 );
t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );

t( sp_open(env) == 0 );
void *db = sp_getobject(env, "db.test");
t( db != NULL );

// Create a few records using lexicographically ordered keys.
uint32_t i = 0;
char buffer[64];
for ( ; i < 16; ++i ) {
void *o = sp_document(db);

sprintf(buffer, "log:%08x:%08x:record%u", i, i, i);
t( sp_setstring(o, "key", buffer, strlen(buffer)) == 0 );
t( sp_setstring(o, "value", &i, sizeof(i)) == 0 );
t( sp_set(db, o) == 0 );
}

// Retrieve them in the reverse sorted order.
void *cur = sp_cursor(env);
t( cur != NULL );
void *o = sp_document(db);
t( o != NULL );
sp_setstring(o, "order", "<=", 0);

i = 0;
while ((o = sp_get(cur, o)))
i++;
t( i == 16 );
sp_destroy(cur);

// Now retrieve the same set by specifying a prefix.
cur = sp_cursor(env);
t( cur != NULL );
o = sp_document(db);
t( o != NULL );
sp_setstring(o, "order", "<=", 0);
sp_setstring(o, "prefix", _prefix, strlen(_prefix));

i = 0;
while ((o = sp_get(cur, o)))
i++;
t( i == 16 );
sp_destroy(cur);

t( sp_destroy(env) == 0 );
}

stgroup *github_group(void)
{
stgroup *group = st_group("github");
Expand All @@ -291,5 +349,6 @@ stgroup *github_group(void)
st_groupadd(group, st_test("ticket_118", github_118));
st_groupadd(group, st_test("ticket_120", github_120));
st_groupadd(group, st_test("ticket_123", github_123));
st_groupadd(group, st_test("ticket_167", github_167));
return group;
}
55 changes: 47 additions & 8 deletions test/suite/st_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,52 @@
* BSD License
*/

#define t(expr) ({ \
if (! (expr)) { \
fprintf(st_r.output, ": fail (%s:%d) %s\n", __FILE__, __LINE__, #expr); \
fflush(st_r.output); \
abort(); \
} \
st_r.stat_stmt++; \
})
#define t(expr) \
{ \
if (!(expr)) { \
fprintf(st_r.output, \
": failed (%s:%d) %s\n", \
__FILE__, \
__LINE__, \
#expr); \
fflush(st_r.output); \
abort(); \
} \
st_r.stat_stmt++; \
}

#define t_api(expr) \
{ \
int size; \
if ((expr) != 0) { \
char *error = sp_getstring(env, "sophia.error", &size); \
fprintf(st_r.output, \
": Sophia API call \"" #expr \
"\" (%s:%d) failed with error: %s\n", \
__FILE__, \
__LINE__, \
error); \
fflush(st_r.output); \
free(error); \
abort(); \
} \
st_r.stat_stmt++; \
}

#define t_string_eq(expr, value) \
{ \
const char *evaluated_value = (expr); \
if (strcmp(evaluated_value, (value)) != 0) { \
fprintf(st_r.output, \
": " #expr " failed (%s:%d) : expected=" #value \
", evaluated=\"%s\"\n", \
__FILE__, \
__LINE__, \
evaluated_value); \
fflush(st_r.output); \
abort(); \
} \
st_r.stat_stmt++; \
}

#endif
0