Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a0f8b53

Browse filesBrowse files
committed
Add example
1 parent 97f5b5f commit a0f8b53
Copy full SHA for a0f8b53

File tree

Expand file treeCollapse file tree

8 files changed

+214
-2
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+214
-2
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+28-2Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,36 @@ You should include the following header in your test file:
1717
### Stubbing
1818

1919
Assuming we have the following arduino code:
20+
```c++
21+
// src/main.cpp
22+
void loop()
23+
{
24+
// turn the LED on (HIGH is the voltage level)
25+
digitalWrite(LED_BUILTIN, HIGH);
26+
// wait for a second
27+
delay(100);
28+
// turn the LED off by making the voltage LOW
29+
digitalWrite(LED_BUILTIN, LOW);
30+
// wait for a second
31+
delay(100);
32+
}
33+
```
2034

35+
It can be tested using `ArduinoFake`:
2136
```c++
22-
void setup()
37+
// test/test_main.cpp
38+
void test_loop(void)
2339
{
40+
When(Method(ArduinoFake(), digitalWrite)).AlwaysReturn();
41+
When(Method(ArduinoFake(), delay)).AlwaysReturn();
2442

43+
loop();
44+
45+
Verify(Method(ArduinoFake(), digitalWrite).Using(LED_BUILTIN, HIGH)).Once();
46+
Verify(Method(ArduinoFake(), digitalWrite).Using(LED_BUILTIN, LOW)).Once();
47+
Verify(Method(ArduinoFake(), delay).Using(100)).Exactly(2_Times);
2548
}
26-
```
49+
```
50+
51+
Checkout the [examples](./examples) for many more examples!
52+
Or take a look at the [tests](./test)

‎examples/wiring-blink/.gitignore

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.pioenvs
2+
.clang_complete
3+
.gcc-flags.json

‎examples/wiring-blink/.travis.yml

Copy file name to clipboard
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Continuous Integration (CI) is the practice, in software
2+
# engineering, of merging all developer working copies with a shared mainline
3+
# several times a day < http://docs.platformio.org/page/ci/index.html >
4+
#
5+
# Documentation:
6+
#
7+
# * Travis CI Embedded Builds with PlatformIO
8+
# < https://docs.travis-ci.com/user/integration/platformio/ >
9+
#
10+
# * PlatformIO integration with Travis CI
11+
# < http://docs.platformio.org/page/ci/travis.html >
12+
#
13+
# * User Guide for `platformio ci` command
14+
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
15+
#
16+
#
17+
# Please choose one of the following templates (proposed below) and uncomment
18+
# it (remove "# " before each line) or use own configuration according to the
19+
# Travis CI documentation (see above).
20+
#
21+
22+
23+
#
24+
# Template #1: General project. Test it using existing `platformio.ini`.
25+
#
26+
27+
# language: python
28+
# python:
29+
# - "2.7"
30+
#
31+
# sudo: false
32+
# cache:
33+
# directories:
34+
# - "~/.platformio"
35+
#
36+
# install:
37+
# - pip install -U platformio
38+
#
39+
# script:
40+
# - platformio run
41+
42+
43+
#
44+
# Template #2: The project is intended to by used as a library with examples
45+
#
46+
47+
# language: python
48+
# python:
49+
# - "2.7"
50+
#
51+
# sudo: false
52+
# cache:
53+
# directories:
54+
# - "~/.platformio"
55+
#
56+
# env:
57+
# - PLATFORMIO_CI_SRC=path/to/test/file.c
58+
# - PLATFORMIO_CI_SRC=examples/file.ino
59+
# - PLATFORMIO_CI_SRC=path/to/test/directory
60+
#
61+
# install:
62+
# - pip install -U platformio
63+
#
64+
# script:
65+
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

‎examples/wiring-blink/README.rst

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ArduinoFake example
2+
3+
### Testing
4+
5+
```bash
6+
pio test
7+
```

‎examples/wiring-blink/lib/readme.txt

Copy file name to clipboard
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
This directory is intended for the project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link to executable file.
4+
5+
The source code of each library should be placed in separate directory, like
6+
"lib/private_lib/[here are source files]".
7+
8+
For example, see how can be organized `Foo` and `Bar` libraries:
9+
10+
|--lib
11+
| |--Bar
12+
| | |--docs
13+
| | |--examples
14+
| | |--src
15+
| | |- Bar.c
16+
| | |- Bar.h
17+
| |--Foo
18+
| | |- Foo.c
19+
| | |- Foo.h
20+
| |- readme.txt --> THIS FILE
21+
|- platformio.ini
22+
|--src
23+
|- main.c
24+
25+
Then in `src/main.c` you should use:
26+
27+
#include <Foo.h>
28+
#include <Bar.h>
29+
30+
// rest H/C/CPP code
31+
32+
PlatformIO will find your libraries automatically, configure preprocessor's
33+
include paths and build them.
34+
35+
More information about PlatformIO Library Dependency Finder
36+
- http://docs.platformio.org/page/librarymanager/ldf.html

‎examples/wiring-blink/platformio.ini

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[env:native]
2+
platform = native
3+
build_flags = -std=gnu++11

‎examples/wiring-blink/src/main.cpp

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Blink
3+
* Turns on an LED on for one second,
4+
* then off for one second, repeatedly.
5+
*/
6+
7+
#ifdef UNIT_TEST
8+
#include "ArduinoFake.h"
9+
#else
10+
#include "Arduino.h"
11+
#endif
12+
13+
void setup()
14+
{
15+
// initialize LED digital pin as an output.
16+
pinMode(LED_BUILTIN, OUTPUT);
17+
}
18+
19+
void loop()
20+
{
21+
// turn the LED on (HIGH is the voltage level)
22+
digitalWrite(LED_BUILTIN, HIGH);
23+
// wait for a second
24+
delay(100);
25+
// turn the LED off by making the voltage LOW
26+
digitalWrite(LED_BUILTIN, LOW);
27+
// wait for a second
28+
delay(100);
29+
}
30+
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <ArduinoFake.h>
2+
#include <unity.h>
3+
4+
using namespace fakeit;
5+
6+
void test_setup(void)
7+
{
8+
When(Method(ArduinoFake(), pinMode)).Return();
9+
10+
setup();
11+
12+
Verify(Method(ArduinoFake(), pinMode).Using(LED_BUILTIN, OUTPUT)).Once();
13+
}
14+
15+
void test_loop(void)
16+
{
17+
When(Method(ArduinoFake(), digitalWrite)).AlwaysReturn();
18+
When(Method(ArduinoFake(), delay)).AlwaysReturn();
19+
20+
loop();
21+
22+
Verify(Method(ArduinoFake(), digitalWrite).Using(LED_BUILTIN, HIGH)).Once();
23+
Verify(Method(ArduinoFake(), digitalWrite).Using(LED_BUILTIN, LOW)).Once();
24+
Verify(Method(ArduinoFake(), delay).Using(100)).Exactly(2_Times);
25+
}
26+
27+
void setUp(void)
28+
{
29+
ArduinoFakeReset();
30+
}
31+
32+
int main(int argc, char **argv)
33+
{
34+
UNITY_BEGIN();
35+
36+
RUN_TEST(test_setup);
37+
RUN_TEST(test_loop);
38+
39+
UNITY_END();
40+
41+
return 0;
42+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.