projekt z testami od ceedling. Dodatkowo skonfigurowany pugin do vscode do testowania. Dziala tez debug testow.
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
build/
|
||||||
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/unity/src/",
|
||||||
|
"/var/lib/gems/2.7.0/gems/ceedling-0.30.0/vendor/cmock/src"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/gcc",
|
||||||
|
"cStandard": "c99",
|
||||||
|
"cppStandard": "gnu++14",
|
||||||
|
"intelliSenseMode": "gcc-x64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
28
.vscode/launch.json
vendored
Normal file
28
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Ceedling Test Explorer Debug",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/build/test/out/${command:ceedlingExplorer.debugTestExecutable}",
|
||||||
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"miDebuggerPath": "/usr/bin/gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"ceedlingExplorer.debugConfiguration": "Ceedling Test Explorer Debug"
|
||||||
|
}
|
||||||
102
project.yml
Normal file
102
project.yml
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
# 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_
|
||||||
|
:which_ceedling: gem
|
||||||
|
:ceedling_version: 0.30.0
|
||||||
|
:default_tasks:
|
||||||
|
- test:all
|
||||||
|
|
||||||
|
#:test_build:
|
||||||
|
# :use_assembly: TRUE
|
||||||
|
|
||||||
|
#:release_build:
|
||||||
|
# :output: MyApp.out
|
||||||
|
# :use_assembly: FALSE
|
||||||
|
|
||||||
|
:environment:
|
||||||
|
|
||||||
|
:extension:
|
||||||
|
:executable: .out
|
||||||
|
|
||||||
|
:paths:
|
||||||
|
:test:
|
||||||
|
- +:test/**
|
||||||
|
- -:test/support
|
||||||
|
:source:
|
||||||
|
- src/**
|
||||||
|
:support:
|
||||||
|
- test/support
|
||||||
|
:libraries: []
|
||||||
|
|
||||||
|
: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)
|
||||||
|
:common: &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
|
||||||
|
|
||||||
|
# Add -gcov to the plugins list to make sure of the gcov plugin
|
||||||
|
# You will need to have gcov and gcovr both installed to make it work.
|
||||||
|
# For more information on these options, see docs in plugins/gcov
|
||||||
|
:gcov:
|
||||||
|
:reports:
|
||||||
|
- HtmlDetailed
|
||||||
|
:gcovr:
|
||||||
|
:html_medium_threshold: 75
|
||||||
|
:html_high_threshold: 90
|
||||||
|
|
||||||
|
#: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
|
||||||
|
|
||||||
|
# LIBRARIES
|
||||||
|
# These libraries are automatically injected into the build process. Those specified as
|
||||||
|
# common will be used in all types of builds. Otherwise, libraries can be injected in just
|
||||||
|
# tests or releases. These options are MERGED with the options in supplemental yaml files.
|
||||||
|
:libraries:
|
||||||
|
:placement: :end
|
||||||
|
:flag: "-l${1}"
|
||||||
|
:path_flag: "-L ${1}"
|
||||||
|
:system: [] # for example, you might list 'm' to grab the math library
|
||||||
|
:test: []
|
||||||
|
:release: []
|
||||||
|
|
||||||
|
:plugins:
|
||||||
|
:load_paths:
|
||||||
|
- "#{Ceedling.load_path}"
|
||||||
|
:enabled:
|
||||||
|
- stdout_pretty_tests_report
|
||||||
|
- module_generator
|
||||||
|
- xml_tests_report
|
||||||
|
...
|
||||||
7
src/i2c.h
Normal file
7
src/i2c.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef i2c_H
|
||||||
|
#define i2c_H
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint16_t i2c_readRegister(uint8_t registerAddress);
|
||||||
|
|
||||||
|
#endif // i2c_H
|
||||||
19
src/lights.c
Normal file
19
src/lights.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "lights.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
static bool areLightsOn = false;
|
||||||
|
|
||||||
|
void lights_SetHeadlightSwitchOff(void)
|
||||||
|
{
|
||||||
|
areLightsOn = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lights_SetHeadlightSwitchOn(void)
|
||||||
|
{
|
||||||
|
areLightsOn = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lights_AreHeadlightsOn(void)
|
||||||
|
{
|
||||||
|
return areLightsOn;
|
||||||
|
}
|
||||||
10
src/lights.h
Normal file
10
src/lights.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef LIGHTS_H
|
||||||
|
#define LIGHTS_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
void lights_SetHeadlightSwitchOff(void);
|
||||||
|
void lights_SetHeadlightSwitchOn(void);
|
||||||
|
bool lights_AreHeadlightsOn(void);
|
||||||
|
|
||||||
|
#endif // LIGHTS_H
|
||||||
9
src/tempSensor.c
Normal file
9
src/tempSensor.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "tempSensor.h"
|
||||||
|
#include "i2c.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
float tempSensor_getTemperature(void)
|
||||||
|
{
|
||||||
|
uint16_t rawValue = i2c_readRegister(0x03);
|
||||||
|
return -100.0f + (0.2f * (float)rawValue);
|
||||||
|
}
|
||||||
6
src/tempSensor.h
Normal file
6
src/tempSensor.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef TEMPSENSOR_H
|
||||||
|
#define TEMPSENSOR_H
|
||||||
|
|
||||||
|
float tempSensor_getTemperature(void);
|
||||||
|
|
||||||
|
#endif // TEMPSENSOR_H
|
||||||
0
test/support/.gitkeep
Normal file
0
test/support/.gitkeep
Normal file
32
test/test_lights.c
Normal file
32
test/test_lights.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
#include "lights.h"
|
||||||
|
|
||||||
|
void setUp(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// void test_lights_NeedToImplement(void)
|
||||||
|
// {
|
||||||
|
// TEST_IGNORE_MESSAGE("Need to Implement lights");
|
||||||
|
// }
|
||||||
|
|
||||||
|
void test_WhenTheHeadlightSwitchIsOff_ThenTheHeadLightsAreOff(void)
|
||||||
|
{
|
||||||
|
// When the headlight switch is off...
|
||||||
|
lights_SetHeadlightSwitchOff();
|
||||||
|
// then the headlights are off.
|
||||||
|
TEST_ASSERT_EQUAL(false, lights_AreHeadlightsOn());
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_WhenTheHeadlightSwitchIsOn_ThenTheHeadLightsAreOn(void)
|
||||||
|
{
|
||||||
|
// When the headlight switch is on...
|
||||||
|
lights_SetHeadlightSwitchOn();
|
||||||
|
// then the headlights are on.
|
||||||
|
TEST_ASSERT_EQUAL(true, lights_AreHeadlightsOn());
|
||||||
|
}
|
||||||
29
test/test_tempSensor.c
Normal file
29
test/test_tempSensor.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
#include "tempSensor.h"
|
||||||
|
#include "mock_i2c.h"
|
||||||
|
|
||||||
|
void setUp(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// void test_tempSensor_NeedToImplement(void)
|
||||||
|
// {
|
||||||
|
// TEST_IGNORE_MESSAGE("Need to Implement tempSensor");
|
||||||
|
// }
|
||||||
|
|
||||||
|
void test_whenTempRegisterReadsMaxValue_thenTheTempIsTheMaxValue(void)
|
||||||
|
{
|
||||||
|
uint8_t tempRegisterAddress = 0x03;
|
||||||
|
float expectedTemperature = 104.6f;
|
||||||
|
float tolerance = 0.1f;
|
||||||
|
//When
|
||||||
|
i2c_readRegister_ExpectAndReturn(tempRegisterAddress, 0x3ff);
|
||||||
|
//Then
|
||||||
|
float actualTemperature = tempSensor_getTemperature();
|
||||||
|
TEST_ASSERT_FLOAT_WITHIN(tolerance, expectedTemperature, actualTemperature);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user