Skip to content

Commit

Permalink
Add test cases with where clause with boolean conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Feb 28, 2024
1 parent fe902c9 commit 3608bec
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,32 @@ START_TEST(test_hoel_json_select)
json_decref(j_query);
json_decref(j_result);
h_free(str_query);

j_query = json_pack("{sss{so}}",
"table",
"test_table",
"where",
"integer_col",
json_true());
ck_assert_int_eq(h_select(conn, j_query, &j_result, &str_query), H_OK);
ck_assert_int_eq(o_strlen(str_query), o_strlen("SELECT * FROM test_table WHERE integer_col=1"));
ck_assert_int_eq(json_array_size(j_result), 1);
json_decref(j_query);
json_decref(j_result);
h_free(str_query);

j_query = json_pack("{sss{so}}",
"table",
"test_table",
"where",
"integer_col",
json_false());
ck_assert_int_eq(h_select(conn, j_query, &j_result, &str_query), H_OK);
ck_assert_int_eq(o_strlen(str_query), o_strlen("SELECT * FROM test_table WHERE integer_col=0"));
ck_assert_int_eq(json_array_size(j_result), 0);
json_decref(j_query);
json_decref(j_result);
h_free(str_query);

str_query = NULL;
j_result = NULL;
Expand Down
26 changes: 26 additions & 0 deletions test/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,32 @@ START_TEST(test_hoel_json_select)
json_decref(j_result);
h_free(str_query);

j_query = json_pack("{sss{so}}",
"table",
"test_table",
"where",
"integer_col",
json_true());
ck_assert_int_eq(h_select(conn, j_query, &j_result, &str_query), H_OK);
ck_assert_int_eq(o_strlen(str_query), o_strlen("SELECT * FROM test_table WHERE integer_col=1"));
ck_assert_int_eq(json_array_size(j_result), 1);
json_decref(j_query);
json_decref(j_result);
h_free(str_query);

j_query = json_pack("{sss{so}}",
"table",
"test_table",
"where",
"integer_col",
json_false());
ck_assert_int_eq(h_select(conn, j_query, &j_result, &str_query), H_OK);
ck_assert_int_eq(o_strlen(str_query), o_strlen("SELECT * FROM test_table WHERE integer_col=0"));
ck_assert_int_eq(json_array_size(j_result), 0);
json_decref(j_query);
json_decref(j_result);
h_free(str_query);

str_query = NULL;
j_result = NULL;
j_query = json_pack("{sss{s{sss[ii]}}}",
Expand Down

0 comments on commit 3608bec

Please sign in to comment.