From: stewartamiles
Date: Thu, 23 Jul 2009 16:37:13 +0000 (+0000)
Subject: * Added bash (awk / sed) script to convert cmockery's html docs to a googlecode.com...
X-Git-Tag: cmocka-1.1.1~365
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=85f3cedf3f9b5cad3d69083d3b6ff4cb2049929b;p=platform%2Fupstream%2Fcmocka.git
* Added bash (awk / sed) script to convert cmockery's html docs to a googlecode.com wiki.
* Modified index.html slightly to make the conversion from html to wiki easier.
git-svn-id: http://cmockery.googlecode.com/svn/trunk@39 40f4469a-5155-0410-be90-2de3f0bae501
---
diff --git a/doc/html2wiki.sh b/doc/html2wiki.sh
new file mode 100644
index 0000000..a7892ce
--- /dev/null
+++ b/doc/html2wiki.sh
@@ -0,0 +1,151 @@
+#!/bin/bash
+#
+# Translate really simple html to googlecode.com wiki.
+#
+# Usage: cat input.html | html2wiki.sh > outputwiki.txt
+#
+# Most of this script is simple sed substitutions with an awk script to handle
+# hierarchical lists.
+
+# Awk program to escape all instances of * outside of
+awk '
+BEGIN { in_listing = 0; }
+/<[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 1; }
+/<\/[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 0; }
+/.*/ {
+ if (in_listing) {
+ print $0;
+ } else {
+ print gensub("*", "`*`", "g", $0)
+ }
+}' | \
+# Awk program to convert hierachical unordered and ordered lists into
+# googlecode wiki list markup. This is limited to converting very simple
+# html lists in the form:
+#
+#
+# - item 1
+# ...
+# - item N
+#
+#
+# This script also removes leading spaces from all lines outside of
+# sections.
+awk '
+BEGIN {
+ list_type_none = 0;
+ list_type_ordered = 1;
+ list_type_unordered = 2;
+ # Number of nested lists.
+ list_depth = 0;
+ # Number of items in the list.
+ list_items[list_depth] = 0;
+ # Type of list.
+ list_type[list_depth] = list_type_none;
+ # Do nott strip whitespace from listing sections.
+ in_listing = 0;
+}
+
+# Generate a string of indent spaces.
+function list_indent(indent) {
+ format = sprintf("%%%ds", indent);
+ return sprintf(format, "");
+}
+
+/<[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 1; }
+/<\/[Ll][Ii][Ss][Tt][Ii][Nn][Gg]>/ { in_listing = 0; }
+
+# Process all lines non-blank lines.
+/^.*$/ {
+ # Remove leading white space.
+ if (!in_listing) {
+ output_string = gensub(/^ */, "", 1, $0);
+ } else {
+ output_string = $0;
+ }
+ search_string = output_string
+
+ # Replace list tags with googlecode wiki markup.
+ while (match(search_string, /<[^>]*>/, matches)) {
+ tag = matches[0];
+ search_string = substr(search_string,
+ matches[0, "start"] + matches[0, "length"]);
+ if (match(tag, /^<[Uu][Ll]>$/)) {
+ list_depth++;
+ list_type[list_depth] = list_type_unordered;
+ list_items[list_depth] = 0;
+ output_string = gensub(tag, "", 1, output_string);
+ } else if (match(tag, /^[Oo][Ll]>$/)) {
+ list_depth++;
+ list_type[list_depth] = list_type_ordered;
+ list_items[list_depth] = 0;
+ output_string = gensub(tag, "", 1, output_string);
+ } else if (match(tag, /^<\/[Ll][Ii]>$/)) {
+ output_string = gensub(tag, "", 1, output_string);
+ } else if (list_depth) {
+ if (match(tag, /^<[Ll][Ii]>$/)) {
+ if (list_type[list_depth] == list_type_unordered) {
+ output_string = gensub(tag, list_indent(list_depth) "* ", 1,
+ output_string);
+ } else if (list_type[list_depth] == list_type_ordered) {
+ output_string = gensub(tag, list_indent(list_depth) "# ", 1,
+ output_string);
+ }
+ } else if (match(tag, /^<\/[Uu][Ll]>$/) ||
+ match(tag, /^<\/[Ou][Ll]>$/)) {
+ output_string = gensub(tag, "", 1, output_string);
+ list_depth --;
+ }
+ }
+ }
+ # If a list is being parsed then filter blank lines.
+ if (list_depth == 0 || length(output_string)) {
+ print output_string
+ }
+}
+' | \
+# This sed program translates really simple html into wiki suitable for
+# googlecode.com.
+#
+# Supported tags:
+#
+#
+#
Using run_tests()
-
run_tests.c
--------------------------------------------------------------------------------
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -117,10 +116,8 @@ failure...
Mismatched setup and tear down functions
Missing mock return values
Unused mock return values
- Missing expected parameter
- values
- Unused expected parameter
- values
+ Missing expected parameter values
+ Unused expected parameter values
@@ -135,9 +132,8 @@ calls to mock_assert() occur during the function called via
expect_assert_failure() a test failure is signalled.
Using mock_assert()
-
assert_module.c
--------------------------------------------------------------------------------
+
#include <assert.h>
// If unit testing is enabled override assert with mock_assert().
@@ -159,9 +155,9 @@ void decrement_value(int * const value) {
*value --;
}
}
-
+
assert_module_test.c
--------------------------------------------------------------------------------
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -210,9 +206,8 @@ caused the assertion failure which increases data visibility aiding
debugging of failing test cases.
Using assert_{type}_equal() macros
-
assert_macro.c
--------------------------------------------------------------------------------
+
#include <string.h>
static const char* status_code_strings[] = {
@@ -235,9 +230,9 @@ unsigned int string_to_status_code(const char* const status_code_string) {
}
return ~0U;
}
-
+
assert_macro_test.c
--------------------------------------------------------------------------------
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -286,9 +281,8 @@ which means memory corruption from a single test case could potentially cause
the test application to exit prematurely.
Using Cmockery's Allocators
-
allocate_module.c
--------------------------------------------------------------------------------
+
#include <malloc.h>
#if UNIT_TESTING
@@ -318,10 +312,9 @@ void buffer_underflow() {
memory[-1] = '!';
free(memory);
}
-
-
+
allocate_module_test.c
--------------------------------------------------------------------------------
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -381,9 +374,8 @@ return value. In addition this allows the specification of return values for
multiple calls to a mock function.
Using will_return()
-
database.h
--------------------------------------------------------------------------------
+
typedef struct DatabaseConnection DatabaseConnection;
/* Function that takes an SQL query string and sets results to an array of
@@ -405,13 +397,12 @@ struct DatabaseConnection {
// Connect to a database.
DatabaseConnection* connect_to_database(const char * const url,
const unsigned int port);
-
-
+
customer_database.c
--------------------------------------------------------------------------------
+
#include <stddef.h>
#include <stdio.h>
-#include <database.h>
+#include <database.h>
#ifdef _WIN32
#define snprintf _snprintf
#endif // _WIN32
@@ -438,15 +429,14 @@ unsigned int get_customer_id_by_name(
}
return (unsigned int)results[0];
}
-
-
+
customer_database_test.c
--------------------------------------------------------------------------------
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmockery.h>
-#include <database.h>
+#include <database.h>
extern DatabaseConnection* connect_to_customer_database();
@@ -515,23 +505,22 @@ test failure is signalled. In addition if check_expected() is called and
no more parameter values are queued a test failure occurs.
Using expect_*()
-
product_database.c
--------------------------------------------------------------------------------
-#include <database.h>
+
+#include <database.h>
// Connect to the database containing customer information.
DatabaseConnection* connect_to_product_database() {
return connect_to_database("products.abcd.org", 322);
}
-
+
product_database_test.c
--------------------------------------------------------------------------------
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmockery.h>
-#include <database.h>
+#include <database.h>
extern DatabaseConnection* connect_to_product_database();
@@ -591,9 +580,8 @@ specified by the unit_test_teardown() or
executed for a test case even when it fails.
Using unit_test_setup_teardown()
-
key_value.c
--------------------------------------------------------------------------------
+
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -633,9 +621,9 @@ void sort_items_by_key() {
qsort(key_values, number_of_key_values, sizeof(*key_values),
key_value_compare_keys);
}
-
+
key_value_test.c
--------------------------------------------------------------------------------
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -714,5 +702,5 @@ are provided as an example of Cmockery's features discussed in this document.
- Last modified: Mon Jul 6 12:21:30 PDT 2009
+ Last modified: Mon Jul 20 15:57:27 PDT 2009