| | #include "sqliteInt.h" |
| | #include "unity.h" |
| | #include <string.h> |
| | #include <stdlib.h> |
| | #include <stdio.h> |
| |
|
| | |
| | |
| | |
| | |
| | int test_getConstraint(const u8 *z); |
| |
|
| | void setUp(void) { |
| | |
| | } |
| |
|
| | void tearDown(void) { |
| | |
| | } |
| |
|
| | |
| | static void check_len(const unsigned char *z, int expected){ |
| | int got = test_getConstraint((const u8*)z); |
| | TEST_ASSERT_EQUAL_INT_MESSAGE(expected, got, (const char*)z); |
| | } |
| |
|
| | |
| | void test_getConstraint_notnull_default(void){ |
| | const unsigned char s[] = "NULL DEFAULT 5"; |
| | check_len(s, 4); |
| | } |
| |
|
| | |
| | void test_getConstraint_whitespace_and_comment_before_unique(void){ |
| | const unsigned char s[] = "BINARY /*comment*/ UNIQUE"; |
| | check_len(s, 6); |
| | } |
| |
|
| | |
| | void test_getConstraint_parentheses_then_primary(void){ |
| | const unsigned char s[] = "(a + b) PRIMARY KEY"; |
| | check_len(s, 7); |
| | } |
| |
|
| | |
| | void test_getConstraint_terminated_by_comma(void){ |
| | const unsigned char s[] = "NULL , CONSTRAINT c1 UNIQUE"; |
| | check_len(s, 4); |
| | } |
| |
|
| | |
| | void test_getConstraint_terminated_by_rparen(void){ |
| | const unsigned char s[] = "NULL )"; |
| | check_len(s, 4); |
| | } |
| |
|
| | |
| | void test_getConstraint_terminated_by_as(void){ |
| | const unsigned char s[] = "xyz AS (1+2)"; |
| | check_len(s, 3); |
| | } |
| |
|
| | |
| | |
| | void test_getConstraint_nested_parentheses_then_default(void){ |
| | const unsigned char s[] = "( (a) + func(b, c) ) DEFAULT 0"; |
| | |
| | |
| | check_len(s, 20); |
| | } |
| |
|
| | |
| | void test_getConstraint_terminated_by_foreign(void){ |
| | const unsigned char s[] = "ref FOREIGN KEY"; |
| | check_len(s, 3); |
| | } |
| |
|
| | |
| | void test_getConstraint_terminated_by_constraint(void){ |
| | const unsigned char s[] = "name CONSTRAINT c1 CHECK(x>0)"; |
| | check_len(s, 4); |
| | } |
| |
|
| | |
| | void test_getConstraint_terminated_by_generated(void){ |
| | const unsigned char s[] = "abc GENERATED ALWAYS AS (x+y)"; |
| | check_len(s, 3); |
| | } |
| |
|
| | int main(void){ |
| | UNITY_BEGIN(); |
| | RUN_TEST(test_getConstraint_notnull_default); |
| | RUN_TEST(test_getConstraint_whitespace_and_comment_before_unique); |
| | RUN_TEST(test_getConstraint_parentheses_then_primary); |
| | RUN_TEST(test_getConstraint_terminated_by_comma); |
| | RUN_TEST(test_getConstraint_terminated_by_rparen); |
| | RUN_TEST(test_getConstraint_terminated_by_as); |
| | RUN_TEST(test_getConstraint_nested_parentheses_then_default); |
| | RUN_TEST(test_getConstraint_terminated_by_foreign); |
| | RUN_TEST(test_getConstraint_terminated_by_constraint); |
| | RUN_TEST(test_getConstraint_terminated_by_generated); |
| | return UNITY_END(); |
| | } |