AryaWu/sqlite
0
1#include "sqliteInt.h"2#include "unity.h"3#include <stdlib.h>4#include <string.h>5#include <stdio.h>6 7/* The target is static; use the provided global wrapper. */8#ifdef SQLITE_SYSTEM_MALLOC9extern int test_sqlite3MemInit(void *NotUsed);10#endif11 12void setUp(void) {13 /* Setup code here, or leave empty */14}15 16void tearDown(void) {17 /* Cleanup code here, or leave empty */18}19 20void test_sqlite3MemInit_returns_ok_with_null(void) {21#ifndef SQLITE_SYSTEM_MALLOC22 TEST_IGNORE_MESSAGE("SQLITE_SYSTEM_MALLOC not enabled; sqlite3MemInit not built in this configuration.");23#else24 int rc = test_sqlite3MemInit(NULL);25 TEST_ASSERT_EQUAL_INT_MESSAGE(SQLITE_OK, rc, "sqlite3MemInit(NULL) should return SQLITE_OK");26#endif27}28 29void test_sqlite3MemInit_returns_ok_with_nonnull_pointer(void) {30#ifndef SQLITE_SYSTEM_MALLOC31 TEST_IGNORE_MESSAGE("SQLITE_SYSTEM_MALLOC not enabled; sqlite3MemInit not built in this configuration.");32#else33 int dummy = 123;34 int rc = test_sqlite3MemInit(&dummy);35 TEST_ASSERT_EQUAL_INT_MESSAGE(SQLITE_OK, rc, "sqlite3MemInit(non-NULL) should return SQLITE_OK and ignore the argument");36#endif37}38 39void test_sqlite3MemInit_idempotent_multiple_calls(void) {40#ifndef SQLITE_SYSTEM_MALLOC41 TEST_IGNORE_MESSAGE("SQLITE_SYSTEM_MALLOC not enabled; sqlite3MemInit not built in this configuration.");42#else43 /* Call multiple times to ensure idempotency and consistent success. */44 for (int i = 0; i < 5; i++) {45 int rc = test_sqlite3MemInit(NULL);46 TEST_ASSERT_EQUAL_INT_MESSAGE(SQLITE_OK, rc, "Repeated sqlite3MemInit should continue to return SQLITE_OK");47 }48 /* Also mix with non-NULL pointers to ensure the NotUsed argument is ignored. */49 int dummy = 0;50 for (int i = 0; i < 3; i++) {51 int rc = test_sqlite3MemInit(&dummy);52 TEST_ASSERT_EQUAL_INT_MESSAGE(SQLITE_OK, rc, "sqlite3MemInit with non-NULL NotUsed should return SQLITE_OK");53 dummy++;54 }55#endif56}57 58int main(void) {59 UNITY_BEGIN();60 RUN_TEST(test_sqlite3MemInit_returns_ok_with_null);61 RUN_TEST(test_sqlite3MemInit_returns_ok_with_nonnull_pointer);62 RUN_TEST(test_sqlite3MemInit_idempotent_multiple_calls);63 return UNITY_END();64}