aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2012-10-20 01:01:53 +0200
committerAndreas Schneider <asn@cryptomilk.org>2012-10-20 01:01:53 +0200
commita6e84045ca6fbde6db9a90ba52060319bc638bc3 (patch)
treefc6466e98291a570daa4e8ef9637564dd2c5b058 /example
parent5f857da3867f57132614d3c4259fc38fae33de49 (diff)
downloadcmocka-a6e84045ca6fbde6db9a90ba52060319bc638bc3.tar.gz
cmocka-a6e84045ca6fbde6db9a90ba52060319bc638bc3.tar.xz
cmocka-a6e84045ca6fbde6db9a90ba52060319bc638bc3.zip
example: Use C style comments.
Diffstat (limited to 'example')
-rw-r--r--example/assert_module.c4
-rw-r--r--example/calculator.c40
-rw-r--r--example/calculator_test.c32
-rw-r--r--example/customer_database.c4
-rw-r--r--example/database.h4
-rw-r--r--example/key_value.c6
-rw-r--r--example/product_database.c2
7 files changed, 46 insertions, 46 deletions
diff --git a/example/assert_module.c b/example/assert_module.c
index 4d206dd..bb75aaa 100644
--- a/example/assert_module.c
+++ b/example/assert_module.c
@@ -17,14 +17,14 @@
#include "assert_module.h"
-// If unit testing is enabled override assert with mock_assert().
+/* If unit testing is enabled override assert with mock_assert(). */
#if UNIT_TESTING
extern void mock_assert(const int result, const char* const expression,
const char * const file, const int line);
#undef assert
#define assert(expression) \
mock_assert(((expression) ? 1 : 0), #expression, __FILE__, __LINE__);
-#endif // UNIT_TESTING
+#endif /* UNIT_TESTING */
void increment_value(int * const value) {
assert(value);
diff --git a/example/calculator.c b/example/calculator.c
index 5e0b359..684fb9b 100644
--- a/example/calculator.c
+++ b/example/calculator.c
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-// A calculator example used to demonstrate the cmocka testing library.
+/* A calculator example used to demonstrate the cmocka testing library. */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -27,14 +27,14 @@
#include <stdlib.h>
#include <string.h>
-// If this is being built for a unit test.
+/* If this is being built for a unit test. */
#if UNIT_TESTING
/* Redirect printf to a function in the test application so it's possible to
* test the standard output. */
#ifdef printf
#undef printf
-#endif // printf
+#endif /* printf */
extern int example_test_printf(const char *format, ...);
#define printf example_test_printf
@@ -44,15 +44,15 @@ extern void print_message(const char *format, ...);
* test error messages. */
#ifdef fprintf
#undef fprintf
-#endif // fprintf
+#endif /* fprintf */
#define fprintf example_test_fprintf
extern int example_test_fprintf(FILE * const file, const char *format, ...);
-// Redirect assert to mock_assert() so assertions can be caught by cmocka.
+/* Redirect assert to mock_assert() so assertions can be caught by cmocka. */
#ifdef assert
#undef assert
-#endif // assert
+#endif /* assert */
#define assert(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__)
void mock_assert(const int result, const char* expression, const char *file,
@@ -62,11 +62,11 @@ void mock_assert(const int result, const char* expression, const char *file,
* check for memory leaks. */
#ifdef calloc
#undef calloc
-#endif // calloc
+#endif /* calloc */
#define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
#ifdef free
#undef free
-#endif // free
+#endif /* free */
#define free(ptr) _test_free(ptr, __FILE__, __LINE__)
void* _test_calloc(const size_t number_of_elements, const size_t size,
const char* file, const int line);
@@ -81,13 +81,13 @@ int example_main(int argc, char *argv[]);
* so redefine static to nothing. */
#define static
-#endif // UNIT_TESTING
+#endif /* UNIT_TESTING */
-// A binary arithmetic integer operation (add, subtract etc.)
+/* A binary arithmetic integer operation (add, subtract etc.) */
typedef int (*BinaryOperator)(int a, int b);
-// Structure which maps operator strings to functions.
+/* Structure which maps operator strings to functions. */
typedef struct OperatorFunction {
const char* operator;
BinaryOperator function;
@@ -111,7 +111,7 @@ static int subtract(int a, int b);
static int multiply(int a, int b);
static int divide(int a, int b);
-// Associate operator strings to functions.
+/* Associate operator strings to functions. */
static OperatorFunction operator_function_map[] = {
{"+", add},
{"-", subtract},
@@ -132,7 +132,7 @@ static int multiply(int a, int b) {
}
static int divide(int a, int b) {
- assert(b); // Check for divide by zero.
+ assert(b); /* Check for divide by zero. */
return a / b;
}
@@ -193,17 +193,17 @@ int perform_operation(
if (!number_of_arguments)
return 0;
- // Parse the first value.
+ /* Parse the first value. */
value = (int)strtol(arguments[0], &end_of_integer, 10);
if (end_of_integer == arguments[0]) {
- // If an error occurred while parsing the integer.
+ /* If an error occurred while parsing the integer. */
fprintf(stderr, "Unable to parse integer from argument %s\n",
arguments[0]);
*error_occurred = 1;
return 0;
}
- // Allocate an array for the output values.
+ /* Allocate an array for the output values. */
*intermediate_values = calloc(((number_of_arguments - 1) / 2),
sizeof(**intermediate_values));
@@ -234,7 +234,7 @@ int perform_operation(
other_value = (int)strtol(arguments[i], &end_of_integer, 10);
if (end_of_integer == arguments[i]) {
- // If an error occurred while parsing the integer.
+ /* If an error occurred while parsing the integer. */
fprintf(stderr, "Unable to parse integer %s of argument %d\n",
arguments[i], i);
*error_occurred = 1;
@@ -242,7 +242,7 @@ int perform_operation(
}
i ++;
- // Perform the operation and store the intermediate value.
+ /* Perform the operation and store the intermediate value. */
*intermediate_value = function(value, other_value);
value = *intermediate_value;
}
@@ -259,14 +259,14 @@ int main(int argc, char *argv[]) {
int return_value;
int number_of_intermediate_values;
int *intermediate_values;
- // Peform the operation.
+ /* Peform the operation. */
const int result = perform_operation(
argc - 1, &argv[1],
sizeof(operator_function_map) / sizeof(operator_function_map[0]),
operator_function_map, &number_of_intermediate_values,
&intermediate_values, &return_value);
- // If no errors occurred display the result.
+ /* If no errors occurred display the result. */
if (!return_value && argc > 1) {
int i;
int intermediate_value_index = 0;
diff --git a/example/calculator_test.c b/example/calculator_test.c
index a568025..fc2bca0 100644
--- a/example/calculator_test.c
+++ b/example/calculator_test.c
@@ -20,9 +20,9 @@
#include <stdio.h>
#ifdef _WIN32
-// Compatibility with the Windows standard C library.
+/* Compatibility with the Windows standard C library. */
#define vsnprintf _vsnprintf
-#endif // _WIN32
+#endif /* _WIN32 */
#define array_length(x) (sizeof(x) / sizeof((x)[0]))
@@ -86,7 +86,7 @@ int example_test_printf(const char *format, ...) {
return return_value;
}
-// A mock binary operator function.
+/* A mock binary operator function. */
static int binary_operator(int a, int b) {
check_expected(a);
check_expected(b);
@@ -94,7 +94,7 @@ static int binary_operator(int a, int b) {
}
-// Ensure add() adds two integers correctly.
+/* Ensure add() adds two integers correctly. */
static void test_add(void **state) {
(void) state; /* unused */
@@ -102,7 +102,7 @@ static void test_add(void **state) {
assert_int_equal(add(3, -3), 0);
}
-// Ensure subtract() subtracts two integers correctly.
+/* Ensure subtract() subtracts two integers correctly. */
static void test_subtract(void **state) {
(void) state; /* unused */
@@ -110,7 +110,7 @@ static void test_subtract(void **state) {
assert_int_equal(subtract(3, -3), 6);
}
-// Ensure multiple() mulitplies two integers correctly.
+/* Ensure multiple() mulitplies two integers correctly. */
static void test_multiply(void **state) {
(void) state; /* unused */
@@ -118,7 +118,7 @@ static void test_multiply(void **state) {
assert_int_equal(multiply(3, 0), 0);
}
-// Ensure divide() divides one integer by another correctly.
+/* Ensure divide() divides one integer by another correctly. */
static void test_divide(void **state) {
(void) state; /* unused */
@@ -126,7 +126,7 @@ static void test_divide(void **state) {
assert_int_equal(divide(2, 10), 0);
}
-// Ensure divide() asserts when trying to divide by zero.
+/* Ensure divide() asserts when trying to divide by zero. */
static void test_divide_by_zero(void **state) {
(void) state; /* unused */
@@ -194,7 +194,7 @@ static void test_find_operator_function_by_string_found(void **state) {
0xDEADBEEF);
}
-// Ensure perform_operation() asserts when a NULL arguments array is specified.
+/* Ensure perform_operation() asserts when a NULL arguments array is specified. */
static void test_perform_operation_null_args(void **state) {
const OperatorFunction operator_functions[] = {
{"+", binary_operator},
@@ -267,7 +267,7 @@ static void test_perform_operation_null_intermediate_values(void **state) {
&error_occurred));
}
-// Ensure perform_operation() returns 0 when no arguments are specified.
+/* Ensure perform_operation() returns 0 when no arguments are specified. */
static void test_perform_operation_no_arguments(void **state) {
int number_of_intermediate_values;
int *intermediate_values;
@@ -382,7 +382,7 @@ static void test_perform_operation_no_integer_after_operator(void **state) {
}
-// Ensure perform_operation() succeeds given valid input parameters.
+/* Ensure perform_operation() succeeds given valid input parameters. */
static void test_perform_operation(void **state) {
const OperatorFunction operator_functions[] = {
{"+", binary_operator},
@@ -397,13 +397,13 @@ static void test_perform_operation(void **state) {
(void) state; /* unused */
- // Setup return values of mock operator functions.
- // Addition.
+ /* Setup return values of mock operator functions. */
+ /* Addition. */
expect_value(binary_operator, a, 1);
expect_value(binary_operator, b, 3);
will_return(binary_operator, 4);
- // Multiplication.
+ /* Multiplication. */
expect_value(binary_operator, a, 4);
expect_value(binary_operator, b, 10);
will_return(binary_operator, 40);
@@ -421,7 +421,7 @@ static void test_perform_operation(void **state) {
}
-// Ensure main() in example.c succeeds given no arguments.
+/* Ensure main() in example.c succeeds given no arguments. */
static void test_example_main_no_args(void **state) {
const char *args[] = {
"example",
@@ -434,7 +434,7 @@ static void test_example_main_no_args(void **state) {
-// Ensure main() in example.c succeeds given valid input arguments.
+/* Ensure main() in example.c succeeds given valid input arguments. */
static void test_example_main(void **state) {
const char *args[] = {
"example", "1", "+", "3", "*", "10",
diff --git a/example/customer_database.c b/example/customer_database.c
index 1fe425e..bd6fcdf 100644
--- a/example/customer_database.c
+++ b/example/customer_database.c
@@ -18,14 +18,14 @@
#include <database.h>
#ifdef _WIN32
#define snprintf _snprintf
-#endif // _WIN32
+#endif /* _WIN32 */
DatabaseConnection* connect_to_customer_database(void);
unsigned int get_customer_id_by_name(
DatabaseConnection * const connection,
const char * const customer_name);
-// Connect to the database containing customer information.
+/* Connect to the database containing customer information. */
DatabaseConnection* connect_to_customer_database(void) {
return connect_to_database("customers.abcd.org", 321);
}
diff --git a/example/database.h b/example/database.h
index 26b4009..880db3c 100644
--- a/example/database.h
+++ b/example/database.h
@@ -24,14 +24,14 @@ typedef unsigned int (*QueryDatabase)(
DatabaseConnection* const connection, const char * const query_string,
void *** const results);
-// Connection to a database.
+/* Connection to a database. */
struct DatabaseConnection {
const char *url;
unsigned int port;
QueryDatabase query_database;
};
-// Connect to a database.
+/* Connect to a database. */
DatabaseConnection* connect_to_database(const char * const url,
const unsigned int port);
diff --git a/example/key_value.c b/example/key_value.c
index 46f0d25..057274a 100644
--- a/example/key_value.c
+++ b/example/key_value.c
@@ -28,12 +28,12 @@ void set_key_values(KeyValue * const new_key_values,
number_of_key_values = new_number_of_key_values;
}
-// Compare two key members of KeyValue structures.
+/* Compare two key members of KeyValue structures. */
static int key_value_compare_keys(const void *a, const void *b) {
return (int)((KeyValue*)a)->key - (int)((KeyValue*)b)->key;
}
-// Search an array of key value pairs for the item with the specified value.
+/* Search an array of key value pairs for the item with the specified value. */
KeyValue* find_item_by_value(const char * const value) {
unsigned int i;
for (i = 0; i < number_of_key_values; i++) {
@@ -44,7 +44,7 @@ KeyValue* find_item_by_value(const char * const value) {
return NULL;
}
-// Sort an array of key value pairs by key.
+/* Sort an array of key value pairs by key. */
void sort_items_by_key(void) {
qsort(key_values, number_of_key_values, sizeof(*key_values),
key_value_compare_keys);
diff --git a/example/product_database.c b/example/product_database.c
index 3fb9641..980b7e5 100644
--- a/example/product_database.c
+++ b/example/product_database.c
@@ -17,7 +17,7 @@
DatabaseConnection* connect_to_product_database(void);
-// Connect to the database containing customer information.
+/* Connect to the database containing customer information. */
DatabaseConnection* connect_to_product_database(void) {
return connect_to_database("products.abcd.org", 322);
}