From 14f959d7decec8d8eb9d9746cacaa997f19e83a4 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 25 Jun 2012 15:26:42 +0200 Subject: [PATCH] examples: Fix warnings of customer_database_test. --- src/example/customer_database_test.c | 34 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/example/customer_database_test.c b/src/example/customer_database_test.c index 8a95874..27e1df6 100644 --- a/src/example/customer_database_test.c +++ b/src/example/customer_database_test.c @@ -23,38 +23,54 @@ extern DatabaseConnection* connect_to_customer_database(); extern unsigned int get_customer_id_by_name( DatabaseConnection * const connection, const char * const customer_name); -// Mock query database function. -static unsigned int mock_query_database( - DatabaseConnection* const connection, const char * const query_string, - void *** const results) { - *results = (void**)((unsigned)mock()); +/* Mock query database function. */ +static unsigned int mock_query_database(DatabaseConnection* const connection, + const char * const query_string, + void *** const results) { + (void) connection; /* unused */ + (void) query_string; /* unused */ + + *results = (void**)((size_t)mock()); return (unsigned int)mock(); } -// Mock of the connect to database function. +/* Mock of the connect to database function. */ DatabaseConnection* connect_to_database(const char * const database_url, const unsigned int port) { - return (DatabaseConnection*)((unsigned)mock()); + (void) database_url; /* unused */ + (void) port; /* unused */ + + return (DatabaseConnection*)((size_t)mock()); } static void test_connect_to_customer_database(void **state) { + (void) state; /* unused */ + will_return(connect_to_database, 0x0DA7ABA53); - assert_int_equal((int)connect_to_customer_database(), 0x0DA7ABA53); + + assert_int_equal((int)(size_t)connect_to_customer_database(), 0x0DA7ABA53); } /* This test fails as the mock function connect_to_database() will have no * value to return. */ +#if 0 static void fail_connect_to_customer_database(void **state) { + (void) state; /* unused */ + assert_true(connect_to_customer_database() == (DatabaseConnection*)0x0DA7ABA53); } +#endif static void test_get_customer_id_by_name(void **state) { DatabaseConnection connection = { "somedatabase.somewhere.com", 12345678, mock_query_database }; - // Return a single customer ID when mock_query_database() is called. + /* Return a single customer ID when mock_query_database() is called. */ int customer_ids = 543; + + (void) state; /* unused */ + will_return(mock_query_database, &customer_ids); will_return(mock_query_database, 1); assert_int_equal(get_customer_id_by_name(&connection, "john doe"), 543); -- 2.34.1