Skip to content

The Arduino library replaces EEPROM library methods with mock methods. In theory, in an accidental loop, one can burn out a memory cell in a few minutes. With mocking methodology, the focus is on avoiding `logical human errors` in the overall design flow of the program.

License

berrak/MockEEPROM

Repository files navigation

GitHub license GitHub version GitHub issues Documentation Installation instructions Badge Hit Counter

Arduino library MockEEPROM

Replace the Arduino library EEPROM with the mocked version and let you develop code without the hardware. The mocked functions return immediately or return zero. Run parallel hardware and system development for greater efficiency. Arduino's command line tool, such as arduino-cli, frees you from Arduino IDE for tests and uploads.

Why try mocking Arduino C++ speak and and it's libraries?

  • Develop software independently of any related parallel hardware project.
  • Use any development environment or your favorite editor with arduino-cli and library MockEEPROM.
  • Use existing well-known tools for debugging.
  • Reach set time goals faster in any Arduino microcontroller project.

The purpose of this library is to be a practical eye-opener on mocked object usage, at least for some early phases of the project development cycle. Another objective of mocking is to focus on avoiding logical human errors in the overall design flow of the program. Unfortunately, this problem in the code tends to be less well-tested and may end up as an end-user complaint.

Usage

Add the include path to the MockEEPROM source directory for the IDE. For example, in the Eclipse IDE, open. Project->Properties->C++ General->Paths and Symbols->Includes->Languages: Gnu C++, Include Directories: /home/bekr/Arduino/libraries/MockEEPROM/src.

At the beginning of the main.cpp file, add.

#include <MockEEPROM.h>
using namespace mock;

Pre-pend all Arduino's EEPROM library calls with 'MockEEPROM::', like this.

MockEEPROM::put(0, value);

The mocked functions return immediately or return zero. To remove all mocking fragments, use either search/replace in the IDE, or run the make-demock.sh (recommended method) shell script on the file to erase all added mock -fragments. If replacing Arduino language constructs, add the include path for Mock in the IDE. See library Mock for information.

Examples

In Arduino IDE scroll down the long list below File->Examples and find MockEEPROM. An example run may look like the following screen output. Note that the mocked methods return zero or return immediately.

Mocked Arduino methods returns zero, or returns directly.
Setup done.
Adr:0, try to put PI to EEPROM: 3.14156
Adr:0, get from EEPROM: 0.00
Adr:4, try to write hex 'FF' to EEPROM: FF
Adr:4, read byte from EEPROM: 0
Adr:4, try to update hex 'AA' to EEPROM: AA
Adr:4, read byte after update from EEPROM: 0
length(): 0
begin(): 0
end(): 0

Documentation (GitHub Pages - Doxygen)

Library documentation.

How to Install

Click on the green Library Manager badge above for instructions, or use the alternative manual installation procedure.

  1. Navigate to the Releases page.
  2. Download the latest released ZIP-archive in ~/Arduino/libraries.
  3. Unzip the archive.
  4. Rename the new directory. Remove version-code, or master in the name like this for MockEEPROM.
  5. Restart Arduino IDE.
  6. In Arduino IDE scroll down the long list below Sketch->Include Library and find MockEEPROM.

Ensure any mock-fragments are removed in the build process

In the Mock script folder is the canonical make-demock.sh shell script for removing any mock fragments in the released code. Ensure that your Arduino installation uses the latest version of Mock. The script will remove mock fragments and ensure that, e.g., MockEEPROM is replaced with EEPROM. Finally, add the #include <EEPROM.h> to the source; now, the actual Arduino library works as expected.

Run the script with the file name, as the argument, like so.

make-demock.sh sketch.ino
make-demock.sh other.cpp
make-demock.sh other.h

Planned Improvements/Changes

For planned changes, improvements, and known bugs, please visit the Github issues tracker.

About

The Arduino library replaces EEPROM library methods with mock methods. In theory, in an accidental loop, one can burn out a memory cell in a few minutes. With mocking methodology, the focus is on avoiding `logical human errors` in the overall design flow of the program.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages