| #include "sqliteInt.h" |
| #include "unity.h" |
| #include <string.h> |
| #include <stdlib.h> |
|
|
| |
| extern int test_quotedCompare(sqlite3_context *ctx, int t, |
| const u8 *zQuote, int nQuote, |
| const u8 *zCmp, int *pRes); |
|
|
| void setUp(void) { |
| |
| } |
|
|
| void tearDown(void) { |
| |
| } |
|
|
| |
| static int call_quotedCompare(int t, const char *zFrag, int nFrag, const char *zCmp, int *pRes){ |
| return test_quotedCompare(NULL, t, |
| (const u8*)zFrag, nFrag, |
| (const u8*)zCmp, pRes); |
| } |
|
|
| void test_quotedCompare_tk_illegal_sets_res_and_returns_ok(void) { |
| int res = -12345; |
| |
| const char *frag = "Anything"; |
| int rc = call_quotedCompare(TK_ILLEGAL, frag, (int)strlen(frag), "anything", &res); |
| TEST_ASSERT_EQUAL_INT(SQLITE_OK, rc); |
| TEST_ASSERT_EQUAL_INT(1, res); |
| } |
|
|
| void test_quotedCompare_unquoted_case_insensitive_equal(void) { |
| int res = -1; |
| const char *frag = "AbC"; |
| const char *cmp = "aBc"; |
| int rc = call_quotedCompare(TK_ID, frag, (int)strlen(frag), cmp, &res); |
| TEST_ASSERT_EQUAL_INT(SQLITE_OK, rc); |
| TEST_ASSERT_EQUAL_INT(0, res); |
| } |
|
|
| void test_quotedCompare_double_quoted_with_escaped_quotes_equal(void) { |
| int res = -1; |
| |
| const char frag[] = "\"He\"\"llo\""; |
| const char *cmp = "He\"llo"; |
| int rc = call_quotedCompare(TK_ID, frag, (int)strlen(frag), cmp, &res); |
| TEST_ASSERT_EQUAL_INT(SQLITE_OK, rc); |
| TEST_ASSERT_EQUAL_INT(0, res); |
| } |
|
|
| void test_quotedCompare_bracket_quoted_identifier_equal(void) { |
| int res = -1; |
| const char frag[] = "[MyName]"; |
| const char *cmp = "myname"; |
| int rc = call_quotedCompare(TK_ID, frag, (int)strlen(frag), cmp, &res); |
| TEST_ASSERT_EQUAL_INT(SQLITE_OK, rc); |
| TEST_ASSERT_EQUAL_INT(0, res); |
| } |
|
|
| void test_quotedCompare_single_quoted_with_doubled_quote_equal(void) { |
| int res = -1; |
| |
| const char frag[] = "'O''Reilly'"; |
| const char *cmp = "o'reilly"; |
| int rc = call_quotedCompare(TK_ID, frag, (int)strlen(frag), cmp, &res); |
| TEST_ASSERT_EQUAL_INT(SQLITE_OK, rc); |
| TEST_ASSERT_EQUAL_INT(0, res); |
| } |
|
|
| void test_quotedCompare_not_equal_sets_nonzero_result(void) { |
| int res = -1; |
| const char *frag = "abc"; |
| const char *cmp = "abd"; |
| int rc = call_quotedCompare(TK_ID, frag, (int)strlen(frag), cmp, &res); |
| TEST_ASSERT_EQUAL_INT(SQLITE_OK, rc); |
| TEST_ASSERT_NOT_EQUAL(0, res); |
| } |
|
|
| void test_quotedCompare_empty_fragment_equal_to_empty_cmp(void) { |
| int res = -1; |
| const char *frag = ""; |
| const char *cmp = ""; |
| int rc = call_quotedCompare(TK_ID, frag, 0, cmp, &res); |
| TEST_ASSERT_EQUAL_INT(SQLITE_OK, rc); |
| TEST_ASSERT_EQUAL_INT(0, res); |
| } |
|
|
| int main(void) { |
| UNITY_BEGIN(); |
| RUN_TEST(test_quotedCompare_tk_illegal_sets_res_and_returns_ok); |
| RUN_TEST(test_quotedCompare_unquoted_case_insensitive_equal); |
| RUN_TEST(test_quotedCompare_double_quoted_with_escaped_quotes_equal); |
| RUN_TEST(test_quotedCompare_bracket_quoted_identifier_equal); |
| RUN_TEST(test_quotedCompare_single_quoted_with_doubled_quote_equal); |
| RUN_TEST(test_quotedCompare_not_equal_sets_nonzero_result); |
| RUN_TEST(test_quotedCompare_empty_fragment_equal_to_empty_cmp); |
| return UNITY_END(); |
| } |