summaryrefslogtreecommitdiffstats
path: root/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example
diff options
context:
space:
mode:
Diffstat (limited to 'tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example')
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/project.yml71
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/rakefile.rb7
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.c1
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.h14
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/custom_types.h6
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.c7
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.h16
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.c93
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.h11
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.c16
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.h8
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.c1
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.h6
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_event_processor.c155
-rwxr-xr-xtinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_foo.c47
15 files changed, 459 insertions, 0 deletions
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/project.yml b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/project.yml
new file mode 100755
index 00000000..6bda2229
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/project.yml
@@ -0,0 +1,71 @@
+---
+
+# Notes:
+# Sample project C code is not presently written to produce a release artifact.
+# As such, release build options are disabled.
+# This sample, therefore, only demonstrates running a collection of unit tests.
+
+:project:
+ :use_exceptions: FALSE
+ :use_test_preprocessor: TRUE
+ :use_auxiliary_dependencies: TRUE
+ :build_root: build
+# :release_build: TRUE
+ :test_file_prefix: test_
+
+#:release_build:
+# :output: MyApp.out
+# :use_assembly: FALSE
+
+:environment:
+
+:extension:
+ :executable: .out
+
+:paths:
+ :test:
+ - +:test/**
+ :source:
+ - src/**
+ :support:
+
+:defines:
+ # in order to add common defines:
+ # 1) remove the trailing [] from the :common: section
+ # 2) add entries to the :common: section (e.g. :test: has TEST defined)
+ :commmon: &common_defines []
+ :test:
+ - *common_defines
+ - TEST
+ :test_preprocess:
+ - *common_defines
+ - TEST
+
+:cmock:
+ :mock_prefix: mock_
+ :when_no_prototypes: :warn
+ :enforce_strict_ordering: TRUE
+ :plugins:
+ - :ignore
+ - :callback
+ :treat_as:
+ uint8: HEX8
+ uint16: HEX16
+ uint32: UINT32
+ int8: INT8
+ bool: UINT8
+
+#:tools:
+# Ceedling defaults to using gcc for compiling, linking, etc.
+# As [:tools] is blank, gcc will be used (so long as it's in your system path)
+# See documentation to configure a given toolchain for use
+
+:plugins:
+ :load_paths:
+ # This change from the default is for running Ceedling out of another folder.
+ - ../../../../plugins
+ :enabled:
+ - stdout_pretty_tests_report
+ - module_generator
+ - fake_function_framework
+...
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/rakefile.rb b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/rakefile.rb
new file mode 100755
index 00000000..e484d5fb
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/rakefile.rb
@@ -0,0 +1,7 @@
+# This change from the default is for running Ceedling out of another folder.
+PROJECT_CEEDLING_ROOT = "../../../.."
+load "#{PROJECT_CEEDLING_ROOT}/lib/ceedling.rb"
+
+Ceedling.load_project
+
+task :default => %w[ test:all release ]
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.c b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.c
new file mode 100755
index 00000000..6a403234
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.c
@@ -0,0 +1 @@
+#include "bar.h"
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.h b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.h
new file mode 100755
index 00000000..febc5865
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/bar.h
@@ -0,0 +1,14 @@
+#ifndef bar_H
+#define bar_H
+
+#include "custom_types.h"
+
+void bar_turn_on(void);
+void bar_print_message(const char * message);
+void bar_print_message_formatted(const char * format, ...);
+void bar_numbers(int one, int two, char three);
+void bar_const_test(const char * a, char * const b, const int c);
+custom_t bar_needs_custom_type(void);
+const char * bar_return_const_ptr(int one);
+
+#endif // bar_H
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/custom_types.h b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/custom_types.h
new file mode 100755
index 00000000..b426b32c
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/custom_types.h
@@ -0,0 +1,6 @@
+#ifndef custom_types_H
+#define custom_types_H
+
+typedef int custom_t;
+
+#endif
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.c b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.c
new file mode 100755
index 00000000..2f03449b
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include "display.h"
+
+void display_turnOffStatusLed(void)
+{
+ printf("Display: Status LED off");
+} \ No newline at end of file
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.h b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.h
new file mode 100755
index 00000000..def29960
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/display.h
@@ -0,0 +1,16 @@
+#include <stdbool.h>
+
+void display_turnOffStatusLed(void);
+void display_turnOnStatusLed(void);
+void display_setVolume(int level);
+void display_setModeToMinimum(void);
+void display_setModeToMaximum(void);
+void display_setModeToAverage(void);
+bool display_isError(void);
+void display_powerDown(void);
+void display_updateData(int data, void(*updateCompleteCallback)(void));
+
+/*
+ The entry is returned (up to `length` bytes) in the provided `entry` buffer.
+*/
+void display_getKeyboardEntry(char * entry, int length);
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.c b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.c
new file mode 100755
index 00000000..916a9236
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.c
@@ -0,0 +1,93 @@
+/*
+ This module implements some business logic to test.
+
+ Signal events by calling the functions on the module.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include "event_processor.h"
+#include "display.h"
+
+void event_deviceReset(void)
+{
+ //printf ("Device reset\n");
+ display_turnOffStatusLed();
+}
+
+void event_volumeKnobMaxed(void)
+{
+ display_setVolume(11);
+}
+
+void event_powerReadingUpdate(int powerReading)
+{
+ if (powerReading >= 5)
+ {
+ display_turnOnStatusLed();
+ }
+}
+
+void event_modeSelectButtonPressed(void)
+{
+ static int mode = 0;
+
+ if (mode == 0)
+ {
+ display_setModeToMinimum();
+ mode++;
+ }
+ else if (mode == 1)
+ {
+ display_setModeToMaximum();
+ mode++;
+ }
+ else if (mode == 2)
+ {
+ display_setModeToAverage();
+ mode++;
+ }
+ else
+ {
+ mode = 0;
+ }
+}
+
+void event_devicePoweredOn(void)
+{
+ if (display_isError())
+ {
+ display_powerDown();
+ }
+}
+
+void event_keyboardCheckTimerExpired(void)
+{
+ char userEntry[100];
+
+ display_getKeyboardEntry(userEntry, 100);
+
+ if (strcmp(userEntry, "sleep") == 0)
+ {
+ display_powerDown();
+ }
+}
+
+static bool event_lastComplete = false;
+
+/* Function called when the display update is complete. */
+static void displayUpdateComplete(void)
+{
+ event_lastComplete = true;
+}
+
+void event_newDataAvailable(int data)
+{
+ event_lastComplete = false;
+ display_updateData(data, displayUpdateComplete);
+}
+
+bool eventProcessor_isLastEventComplete(void)
+{
+ return event_lastComplete;
+}
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.h b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.h
new file mode 100755
index 00000000..a79e68c5
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/event_processor.h
@@ -0,0 +1,11 @@
+#include <stdbool.h>
+
+void event_deviceReset(void);
+void event_volumeKnobMaxed(void);
+void event_powerReadingUpdate(int powerReading);
+void event_modeSelectButtonPressed(void);
+void event_devicePoweredOn(void);
+void event_keyboardCheckTimerExpired(void);
+void event_newDataAvailable(int data);
+
+bool eventProcessor_isLastEventComplete(void);
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.c b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.c
new file mode 100755
index 00000000..c05b1154
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.c
@@ -0,0 +1,16 @@
+#include "foo.h"
+#include "bar.h"
+#include "subfolder/zzz.h"
+
+void foo_turn_on(void) {
+ bar_turn_on();
+ zzz_sleep(1, "sleepy");
+}
+
+void foo_print_message(const char * message) {
+ bar_print_message(message);
+}
+
+void foo_print_special_message(void) {
+ bar_print_message_formatted("The numbers are %d, %d and %d", 1, 2, 3);
+}
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.h b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.h
new file mode 100755
index 00000000..3fea6994
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/foo.h
@@ -0,0 +1,8 @@
+#ifndef foo_H
+#define foo_H
+
+void foo_turn_on(void);
+void foo_print_message(const char * message);
+void foo_print_special_message(void);
+
+#endif // foo_H
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.c b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.c
new file mode 100755
index 00000000..85f370e1
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.c
@@ -0,0 +1 @@
+#include "zzz.h"
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.h b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.h
new file mode 100755
index 00000000..32c52940
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/src/subfolder/zzz.h
@@ -0,0 +1,6 @@
+#ifndef zzz_H
+#define zzz_H
+
+int zzz_sleep(int time, char * name);
+
+#endif // zzz_H
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_event_processor.c b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_event_processor.c
new file mode 100755
index 00000000..9f999443
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_event_processor.c
@@ -0,0 +1,155 @@
+#include "unity.h"
+#include "event_processor.h"
+#include "mock_display.h"
+#include <string.h>
+
+void setUp (void)
+{
+}
+
+void tearDown (void)
+{
+}
+/*
+ Test that a single function was called.
+*/
+void
+test_whenTheDeviceIsReset_thenTheStatusLedIsTurnedOff()
+{
+ // When
+ event_deviceReset();
+
+ // Then
+ TEST_ASSERT_EQUAL(1, display_turnOffStatusLed_fake.call_count);
+ // or use the helper macro...
+ TEST_ASSERT_CALLED(display_turnOffStatusLed);
+}
+
+/*
+ Test that a single function is NOT called.
+*/
+void
+test_whenThePowerReadingIsLessThan5_thenTheStatusLedIsNotTurnedOn(void)
+{
+ // When
+ event_powerReadingUpdate(4);
+
+ // Then
+ TEST_ASSERT_EQUAL(0, display_turnOnStatusLed_fake.call_count);
+ // or use the helper macro...
+ TEST_ASSERT_NOT_CALLED(display_turnOffStatusLed);
+}
+
+/*
+ Test that a single function was called with the correct arugment.
+*/
+void
+test_whenTheVolumeKnobIsMaxed_thenVolumeDisplayIsSetTo11(void)
+{
+ // When
+ event_volumeKnobMaxed();
+
+ // Then
+ TEST_ASSERT_EQUAL(1, display_setVolume_fake.call_count);
+ // or use the helper macro...
+ TEST_ASSERT_CALLED(display_setVolume);
+ TEST_ASSERT_EQUAL(11, display_setVolume_fake.arg0_val);
+}
+
+/*
+ Test a sequence of calls.
+*/
+
+void
+test_whenTheModeSelectButtonIsPressed_thenTheDisplayModeIsCycled(void)
+{
+ // When
+ event_modeSelectButtonPressed();
+ event_modeSelectButtonPressed();
+ event_modeSelectButtonPressed();
+
+ // Then
+ TEST_ASSERT_EQUAL_PTR((void *)display_setModeToMinimum, fff.call_history[0]);
+ TEST_ASSERT_EQUAL_PTR((void *)display_setModeToMaximum, fff.call_history[1]);
+ TEST_ASSERT_EQUAL_PTR((void *)display_setModeToAverage, fff.call_history[2]);
+ // or use the helper macros...
+ TEST_ASSERT_CALLED_IN_ORDER(0, display_setModeToMinimum);
+ TEST_ASSERT_CALLED_IN_ORDER(1, display_setModeToMaximum);
+ TEST_ASSERT_CALLED_IN_ORDER(2, display_setModeToAverage);
+}
+
+/*
+ Mock a return value from a function.
+*/
+void
+test_givenTheDisplayHasAnError_whenTheDeviceIsPoweredOn_thenTheDisplayIsPoweredDown(void)
+{
+ // Given
+ display_isError_fake.return_val = true;
+
+ // When
+ event_devicePoweredOn();
+
+ // Then
+ TEST_ASSERT_EQUAL(1, display_powerDown_fake.call_count);
+ // or use the helper macro...
+ TEST_ASSERT_CALLED(display_powerDown);
+}
+
+/*
+ Mock a sequence of calls with return values.
+*/
+
+/*
+ Mocking a function with a value returned by reference.
+*/
+void
+test_givenTheUserHasTypedSleep_whenItIsTimeToCheckTheKeyboard_theDisplayIsPoweredDown(void)
+{
+ // Given
+ char mockedEntry[] = "sleep";
+ void return_mock_value(char * entry, int length)
+ {
+ if (length > strlen(mockedEntry))
+ {
+ strncpy(entry, mockedEntry, length);
+ }
+ }
+ display_getKeyboardEntry_fake.custom_fake = return_mock_value;
+
+ // When
+ event_keyboardCheckTimerExpired();
+
+ // Then
+ TEST_ASSERT_EQUAL(1, display_powerDown_fake.call_count);
+ // or use the helper macro...
+ TEST_ASSERT_CALLED(display_powerDown);
+}
+
+/*
+ Mock a function with a function pointer parameter.
+*/
+void
+test_givenNewDataIsAvailable_whenTheDisplayHasUpdated_thenTheEventIsComplete(void)
+{
+ // A mock function for capturing the callback handler function pointer.
+ void(*registeredCallback)(void) = 0;
+ void mock_display_updateData(int data, void(*callback)(void))
+ {
+ //Save the callback function.
+ registeredCallback = callback;
+ }
+ display_updateData_fake.custom_fake = mock_display_updateData;
+
+ // Given
+ event_newDataAvailable(10);
+
+ // When
+ if (registeredCallback != 0)
+ {
+ registeredCallback();
+ }
+
+ // Then
+ TEST_ASSERT_EQUAL(true, eventProcessor_isLastEventComplete());
+}
diff --git a/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_foo.c b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_foo.c
new file mode 100755
index 00000000..12dd61a1
--- /dev/null
+++ b/tinyusb/test/vendor/ceedling/plugins/fake_function_framework/examples/fff_example/test/test_foo.c
@@ -0,0 +1,47 @@
+#include "unity.h"
+#include "foo.h"
+#include "mock_bar.h"
+#include "mock_zzz.h"
+
+void setUp(void)
+{
+}
+
+void tearDown(void)
+{
+}
+
+void test_foo(void)
+{
+ //When
+ foo_turn_on();
+
+ //Then
+ TEST_ASSERT_EQUAL(1, bar_turn_on_fake.call_count);
+ TEST_ASSERT_EQUAL(1, zzz_sleep_fake.call_count);
+ TEST_ASSERT_EQUAL_STRING("sleepy", zzz_sleep_fake.arg1_val);
+}
+
+void test_foo_again(void)
+{
+ //When
+ foo_turn_on();
+
+ //Then
+ TEST_ASSERT_EQUAL(1, bar_turn_on_fake.call_count);
+}
+
+void test_foo_mock_with_const(void)
+{
+ foo_print_message("123");
+
+ TEST_ASSERT_EQUAL(1, bar_print_message_fake.call_count);
+ TEST_ASSERT_EQUAL_STRING("123", bar_print_message_fake.arg0_val);
+}
+
+void test_foo_mock_with_variable_args(void)
+{
+ foo_print_special_message();
+ TEST_ASSERT_EQUAL(1, bar_print_message_formatted_fake.call_count);
+ TEST_ASSERT_EQUAL_STRING("The numbers are %d, %d and %d", bar_print_message_formatted_fake.arg0_val);
+}